Search in sources :

Example 1 with AtomEnvironmentDescriptor

use of ambit2.descriptors.AtomEnvironmentDescriptor 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 2 with AtomEnvironmentDescriptor

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

the class AtomEnvironmentDescriptorTest method testAtomEnvironmentDescriptor.

@Test
public void testAtomEnvironmentDescriptor() throws Exception {
    AtomEnvironmentDescriptor descriptor = new AtomEnvironmentDescriptor();
    int maxLevel = 1;
    Object[] params = { new Integer(maxLevel) };
    SmilesParserWrapper sp = SmilesParserWrapper.getInstance();
    // IAtomContainer mol = sp.parseSmiles("CCCCCC=CCC=CCCCCCCCC(=O)NCCO");
    IAtomContainer mol = sp.parseSmiles("C#N");
    // IAtomContainer mol = sp.parseSmiles("CCCC(CCC(CCCC(CCCCCCC(CCCCCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CC(CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CC)CCC)CCC(CCCCC)CCC)CCC)CCC)CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CC)CCC)CCC(CCCCC)CCCCC)CCC)CCC(CC(CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CC)CCC)CCC(CCCCC)CCC)CCC)CCC)CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CC)CCC)CCC(CCCCC)CCC");
    AtomConfigurator typer = new AtomConfigurator();
    typer.process(mol);
    // AtomContainer mol = sp.parseSmiles("N#CC(=Cc1ccc(O)c(O)c1)C(=O)NCCCNC(=O)C(C#N)=Cc2ccc(O)c(O)c2");
    CDKHydrogenAdder hAdder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
    hAdder.addImplicitHydrogens(mol);
    descriptor.setParameters(params);
    IntegerArrayResult r = (IntegerArrayResult) descriptor.calculate(mol).getValue();
    for (int i = 0; i < mol.getAtomCount(); i++) {
        if (i == 0) {
            // just for test
            Object[] parameters = descriptor.getParameters();
            AtomTypeFactory factory = (AtomTypeFactory) parameters[AtomEnvironmentDescriptor._param.atomTypeFactory.ordinal()];
            IAtomType[] at = factory.getAllAtomTypes();
            /*
			    	System.out.print("Sum\tAtomType\t");
					for (int j=0; j < factory.getSize(); j++) {
						System.out.print(j);
						System.out.print(".");
				    	System.out.print(at[j].getAtomTypeName());
				    	System.out.print("\t");
				    }			  
				    */
            // System.out.println("");
            Assert.assertTrue(factory.getSize() > 0);
            // System.out.println(r.toString());
            Assert.assertEquals(mol.getAtomCount() * (maxLevel * (factory.getSize() + 1) + 2), r.length());
        }
    }
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) AtomTypeFactory(org.openscience.cdk.config.AtomTypeFactory) AtomEnvironmentDescriptor(ambit2.descriptors.AtomEnvironmentDescriptor) CDKHydrogenAdder(org.openscience.cdk.tools.CDKHydrogenAdder) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator) SmilesParserWrapper(ambit2.core.smiles.SmilesParserWrapper) Test(org.junit.Test)

Example 3 with AtomEnvironmentDescriptor

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

the class MySelector method testCH3difference.

public void testCH3difference(boolean display) throws Exception {
    IMolecularDescriptor descriptor = new AtomEnvironmentDescriptor();
    int maxLevel = 3;
    Object[] params = { null, new Integer(maxLevel), new Boolean(true), new Boolean(true) };
    SmilesParserWrapper sp = SmilesParserWrapper.getInstance();
    // IAtomContainer mol = sp.parseSmiles("O=N(=O)c1ccc(O)c(N)c1");
    // Amino-2nitro-3.4-5 hydroxy-methyl benzene (ANMB)
    // IAtomContainer mol1 = sp.parseSmiles("Cc1c(C)c(cc(N)c1(O))N(=O)=O");
    IAtomContainer molecule1 = sp.parseSmiles("Nc1c(C)cccc1");
    // Amino-2nitro-3.4-5 hydroxy-methyl benzene (ANMB)
    IAtomContainer molecule2 = sp.parseSmiles("Nc1c(O)cccc1");
    // Amino-2nitro-3.4-5 hydroxy-methyl benzene (ANMB)
    AtomEnvironmentGenerator g = new AtomEnvironmentGenerator();
    g.setNoDuplicates(false);
    g.setUseHydrogens(true);
    g.setMaxLevels(maxLevel);
    AtomEnvironmentList ae = g.generateProperty(molecule1);
    AtomEnvironmentList ae1 = g.generateProperty(molecule2);
    Collections.sort(ae);
    Collections.sort(ae1);
    AtomEnvironmentsDistance d = new AtomEnvironmentsDistance();
    System.out.println("distance " + d.getDistance(ae, ae1));
    Set<AtomEnvironment> set = new TreeSet<AtomEnvironment>();
    Set<AtomEnvironment> set1 = new TreeSet<AtomEnvironment>();
    for (int i = 0; i < ae.size(); i++) set.add(ae.get(i));
    for (int i = 0; i < ae1.size(); i++) set1.add(ae1.get(i));
    System.out.println(set);
    System.out.println();
    System.out.println(set1);
    Assert.assertNotSame(set, set1);
    Set intersection = (Set) ((TreeSet) set1).clone();
    intersection.retainAll(set);
    System.out.println("Intersection\t" + intersection.size());
    System.out.println(intersection);
    if (display)
        displayAE(molecule1, ae, molecule2, ae1);
    Assert.assertNotNull(ae);
    Assert.assertNotNull(ae1);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) TreeSet(java.util.TreeSet) Set(java.util.Set) AtomEnvironmentGenerator(ambit2.descriptors.processors.AtomEnvironmentGenerator) IMolecularDescriptor(org.openscience.cdk.qsar.IMolecularDescriptor) AtomEnvironment(ambit2.descriptors.AtomEnvironment) AtomEnvironmentsDistance(ambit2.similarity.measure.AtomEnvironmentsDistance) TreeSet(java.util.TreeSet) AtomEnvironmentDescriptor(ambit2.descriptors.AtomEnvironmentDescriptor) AtomEnvironmentList(ambit2.descriptors.processors.AtomEnvironmentList) SmilesParserWrapper(ambit2.core.smiles.SmilesParserWrapper)

Aggregations

IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)3 SmilesParserWrapper (ambit2.core.smiles.SmilesParserWrapper)2 AtomEnvironment (ambit2.descriptors.AtomEnvironment)2 AtomEnvironmentDescriptor (ambit2.descriptors.AtomEnvironmentDescriptor)2 AtomConfigurator (ambit2.core.processors.structure.AtomConfigurator)1 AtomEnvironmentGenerator (ambit2.descriptors.processors.AtomEnvironmentGenerator)1 AtomEnvironmentList (ambit2.descriptors.processors.AtomEnvironmentList)1 AtomEnvironmentsDistance (ambit2.similarity.measure.AtomEnvironmentsDistance)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 Test (org.junit.Test)1 AtomTypeFactory (org.openscience.cdk.config.AtomTypeFactory)1 CDKException (org.openscience.cdk.exception.CDKException)1 IAtomType (org.openscience.cdk.interfaces.IAtomType)1 IMolecularDescriptor (org.openscience.cdk.qsar.IMolecularDescriptor)1 IntegerArrayResult (org.openscience.cdk.qsar.result.IntegerArrayResult)1 CDKHydrogenAdder (org.openscience.cdk.tools.CDKHydrogenAdder)1