Search in sources :

Example 1 with AtomEnvironmentList

use of ambit2.descriptors.processors.AtomEnvironmentList in project ambit-mirror by ideaconsult.

the class CreateAtomEnvironment method getParameters.

@Override
public List<QueryParam> getParameters(int index) throws AmbitException {
    List<QueryParam> params = new ArrayList<QueryParam>();
    params.add(new QueryParam<Integer>(Integer.class, getGroup().getIdchemical()));
    AtomEnvironment ae = ((AtomEnvironmentList) getGroup().getRecordProperty(property)).get(index);
    params.add(new QueryParam<String>(String.class, ae.getCentral_atom()));
    params.add(new QueryParam<Integer>(Integer.class, ae.getFrequency()));
    for (int i = 1; i < 7; i++) {
        String p = ae.getLevel2String(i);
        params.add(new QueryParam<String>(String.class, p == null ? "" : p));
    }
    params.add(new QueryParam<String>(String.class, "valid"));
    return params;
}
Also used : AtomEnvironment(ambit2.descriptors.AtomEnvironment) QueryParam(net.idea.modbcum.i.query.QueryParam) ArrayList(java.util.ArrayList) AtomEnvironmentList(ambit2.descriptors.processors.AtomEnvironmentList)

Example 2 with AtomEnvironmentList

use of ambit2.descriptors.processors.AtomEnvironmentList in project ambit-mirror by ideaconsult.

the class AtomEnvironmentGenerator method generateProperty.

@Override
public AtomEnvironmentList generateProperty(IAtomContainer atomContainer) throws AmbitException {
    try {
        IAtomContainer mol = (IAtomContainer) ((IAtomContainer) atomContainer).clone();
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
        // atom list - bug?
        try {
            if (hAdder == null)
                hAdder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
            hAdder.addImplicitHydrogens(mol);
        } catch (Exception x) {
        }
        CDKHueckelAromaticityDetector.detectAromaticity(mol);
        // }
        AtomEnvironmentList aeList = new AtomEnvironmentList();
        aeList.setNoDuplicates(noDuplicates);
        aeParams[AtomEnvironmentDescriptor._param.maxLevel.ordinal()] = maxLevels;
        aeDescriptor.setParameters(aeParams);
        int[][] aeResult = null;
        try {
            aeResult = aeDescriptor.doCalculation(mol);
        } catch (CDKException x) {
            throw new AmbitException(x);
        }
        for (int a = 0; a < aeResult.length; a++) {
            AtomEnvironment atomenv = new AtomEnvironment(maxLevels);
            atomenv.setTime_elapsed(System.currentTimeMillis());
            aeParams[0] = maxLevels;
            atomenv.setTime_elapsed(System.currentTimeMillis() - atomenv.getTime_elapsed());
            atomenv.setStatus(1);
            atomenv.setSublevel(maxLevels);
            // result formatting
            atomenv.setAtom_environment(aeResult[a]);
            // atomenv.setAtom_environment(aeDescriptor.atomFingerprintToString(aeResult,':'));
            atomenv.setCentral_atom(aeDescriptor.atomTypeToString(aeResult[a][1]));
            atomenv.setAtomno(a);
            aeList.add(atomenv);
            // lower level AE
            if (isCreateSubLevels())
                for (int i = 1; i < atomenv.getLevels(); i++) {
                    AtomEnvironment subae = atomenv.getSubAtomEnvironment(i);
                    subae.setSublevel(i);
                    if (!atomenv.equals(subae))
                        aeList.add(subae);
                }
        }
        return aeList;
    } catch (Exception x) {
        logger.log(Level.WARNING, x.getMessage(), x);
    }
    return null;
}
Also used : AtomEnvironment(ambit2.descriptors.AtomEnvironment) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) CDKException(org.openscience.cdk.exception.CDKException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 3 with AtomEnvironmentList

use of ambit2.descriptors.processors.AtomEnvironmentList in project ambit-mirror by ideaconsult.

the class AtomEnvironmentList method hellinger.

/**
 * Hellinger distance  between two discrete probability distributions pi and qi.
 * Range is (0,2), where 2 means equal distributions.
 * * @param hist
 * @return sum(( sqrt(Pi) + sqrt(Qi) )^2)
 */
public float hellinger(AtomEnvironmentList hist) throws Exception {
    int cq = frequency();
    if (cq == 0)
        return 0;
    int cp = hist.frequency();
    if (cp == 0) {
        logger.warning("The histogram to compare with is empty!");
        throw new Exception("The histogram to compare with is empty!");
    }
    double HD = 0;
    double[][] prob = new double[cq][2];
    int count = 0;
    int pcount = 0;
    // iterate through this map
    Iterator<AtomEnvironment> iMap = iterator();
    AtomEnvironment ae;
    double p, q;
    while (iMap.hasNext()) {
        ae = iMap.next();
        if (ae != null) {
            q = (double) ae.getFrequency() / cq;
            prob[count][0] = q;
            if (q > 0) {
                int found = hist.indexOf(ae);
                if (found >= 0) {
                    prob[count][1] = hist.get(found).getFrequency();
                    count++;
                }
                ;
            }
        }
    }
    for (int i = 0; i < count; i++) {
        prob[i][1] = prob[i][1] / ((float) cp);
        HD += Math.pow(Math.sqrt(prob[i][0]) + Math.sqrt(prob[i][1]), 2.0);
    }
    prob = null;
    // logger.debug("Hellinger \t"+HD);
    HD = Math.sqrt(HD);
    // logger.debug("Hellinger normalized \t"+HD);
    return (float) HD;
}
Also used : AtomEnvironment(ambit2.descriptors.AtomEnvironment) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 4 with AtomEnvironmentList

use of ambit2.descriptors.processors.AtomEnvironmentList in project ambit-mirror by ideaconsult.

the class MySelector method displayAE.

public void displayAE(final IAtomContainer mol1, AtomEnvironmentList aelist1, final IAtomContainer mol2, AtomEnvironmentList aelist2) {
    AEComparator aec = new AEComparator();
    Collections.sort(aelist1, aec);
    Collections.sort(aelist2, aec);
    final AtomEnvironmentListTableModel m1 = new AtomEnvironmentListTableModel(aelist1);
    final AtomEnvironmentListTableModel m2 = new AtomEnvironmentListTableModel(aelist2);
    final MySelector s1 = new MySelector();
    final MySelector s2 = new MySelector();
    final CompoundImageTools tools = new CompoundImageTools();
    final JLabel p1 = new JLabel();
    p1.setIcon(new ImageIcon(tools.getImage(mol1, s1, true, false)));
    p1.setPreferredSize(new Dimension(100, 100));
    /*
		 * 
		 * p1.r2dm.setColorAtomsByType(true);
		 * p1.r2dm.setHighlightedAtom(mol1.getAtom(0));
		 * p1.r2dm.setShowAromaticity(true); p1.setPreferredSize(new
		 * Dimension(100,100));
		 */
    final JLabel p2 = new JLabel();
    p2.setIcon(new ImageIcon(tools.getImage(mol2, s2, true, false)));
    p2.setPreferredSize(new Dimension(100, 100));
    final JTable t1 = new JTable(m1);
    t1.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            int row = t1.rowAtPoint(e.getPoint());
            int natom = ((Integer) m1.getValueAt(row, 0)).intValue() - 1;
            s1.setSelected(natom);
            p1.setIcon(new ImageIcon(tools.getImage(mol1, s1, true, true)));
        }
    });
    final JTable t2 = new JTable(m2);
    t2.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            int row = t2.rowAtPoint(e.getPoint());
            int natom = ((Integer) m2.getValueAt(row, 0)).intValue() - 1;
            s2.setSelected(natom);
            p2.setIcon(new ImageIcon(tools.getImage(mol2, s2, true, true)));
        }
    });
    JOptionPane.showMessageDialog(null, new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JSplitPane(JSplitPane.VERTICAL_SPLIT, p1, new JScrollPane(t1)), new JSplitPane(JSplitPane.VERTICAL_SPLIT, p2, new JScrollPane(t2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS))));
}
Also used : JScrollPane(javax.swing.JScrollPane) ImageIcon(javax.swing.ImageIcon) AtomEnvironmentListTableModel(ambit2.model.AtomEnvironmentListTableModel) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) CompoundImageTools(ambit2.rendering.CompoundImageTools) JTable(javax.swing.JTable) JSplitPane(javax.swing.JSplitPane)

Example 5 with AtomEnvironmentList

use of ambit2.descriptors.processors.AtomEnvironmentList in project ambit-mirror by ideaconsult.

the class MySelector method testHellinger.

@Test
public void testHellinger() throws Exception {
    AtomEnvironmentList ae1 = getAE(g, MoleculeFactory.makeAlkane(3));
    Assert.assertTrue(ae1.size() > 1);
    AtomEnvironmentList ae = getAE(g, MoleculeFactory.makeAlkane(1));
    Assert.assertEquals(2.0, ae.hellinger(ae), 1E-6);
    Assert.assertEquals(2.0, ae1.hellinger(ae1), 1E-6);
    // System.out.println(ae);
    // System.out.println(ae1);
    float f = ae1.hellinger(ae);
    System.out.println(f);
    Assert.assertEquals(f, ae.hellinger(ae1));
    Assert.assertTrue(f < 2.0);
    Assert.assertTrue(f > 0.0);
}
Also used : AtomEnvironmentList(ambit2.descriptors.processors.AtomEnvironmentList) Test(org.junit.Test)

Aggregations

AtomEnvironmentList (ambit2.descriptors.processors.AtomEnvironmentList)7 AtomEnvironment (ambit2.descriptors.AtomEnvironment)5 Test (org.junit.Test)4 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)4 SmilesParserWrapper (ambit2.core.smiles.SmilesParserWrapper)3 AtomEnvironmentGenerator (ambit2.descriptors.processors.AtomEnvironmentGenerator)3 AtomEnvironmentsDistance (ambit2.similarity.measure.AtomEnvironmentsDistance)2 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)1 AtomEnvironmentDescriptor (ambit2.descriptors.AtomEnvironmentDescriptor)1 AtomEnvironmentListTableModel (ambit2.model.AtomEnvironmentListTableModel)1 CompoundImageTools (ambit2.rendering.CompoundImageTools)1 Dimension (java.awt.Dimension)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1