Search in sources :

Example 1 with UniversalIsomorphismTester

use of org.openscience.cdk.isomorphism.UniversalIsomorphismTester in project ambit-mirror by ideaconsult.

the class BalloonShellTest method testRunBalloon.

@Test
public void testRunBalloon() throws Exception {
    IAtomContainer mol = MoleculeFactory.makeAlkane(3);
    IAtomContainer newmol = shell.runShell(mol);
    Assert.assertNotNull(newmol);
    IAtomContainer c = AtomContainerManipulator.removeHydrogensPreserveMultiplyBonded(newmol);
    UniversalIsomorphismTester uit = new UniversalIsomorphismTester();
    Assert.assertTrue(uit.isIsomorph(mol, c));
    for (int i = 0; i < newmol.getAtomCount(); i++) {
        Assert.assertNotNull(newmol.getAtom(i).getPoint3d());
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) UniversalIsomorphismTester(org.openscience.cdk.isomorphism.UniversalIsomorphismTester) Test(org.junit.Test)

Example 2 with UniversalIsomorphismTester

use of org.openscience.cdk.isomorphism.UniversalIsomorphismTester in project ambit-mirror by ideaconsult.

the class CommandShellTest method testOpenBabel.

@Test
public void testOpenBabel() throws Exception {
    String testfile = "babel_test.sdf";
    OpenBabelShell babel = new OpenBabelShell();
    babel.setOutputFile(testfile);
    IAtomContainer newmol = babel.runShell("c1ccccc1");
    IAtomContainer c = AtomContainerManipulator.removeHydrogensPreserveMultiplyBonded(newmol);
    IAtomContainer mol = MoleculeFactory.makeBenzene();
    UniversalIsomorphismTester uit = new UniversalIsomorphismTester();
    Assert.assertTrue(uit.isIsomorph(mol, c));
    new File(babel.getOutputFile()).delete();
}
Also used : OpenBabelShell(ambit2.core.smiles.OpenBabelShell) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) UniversalIsomorphismTester(org.openscience.cdk.isomorphism.UniversalIsomorphismTester) File(java.io.File) Test(org.junit.Test)

Example 3 with UniversalIsomorphismTester

use of org.openscience.cdk.isomorphism.UniversalIsomorphismTester in project ambit-mirror by ideaconsult.

the class MopacShellTest method runShell.

public void runShell(String smiles) throws Exception {
    // "[H]C1=C([H])C([H])=C([H])C([H])=C1([H])";
    IAtomContainer mol = parser.parseSmiles(smiles);
    mol.setProperty("SMILES", smiles);
    mol.setProperty("TITLE", smiles);
    IAtomContainer newmol = (IAtomContainer) shell.runShell(mol);
    // Assert.assertEquals(mol.getAtomCount(),newmol.getAtomCount());
    // Assert.assertEquals(mol.getBondCount(),newmol.getBondCount());
    Assert.assertNotNull("ELUMO not found", newmol.getProperty("ELUMO"));
    Assert.assertNotNull("EHOMO not found", newmol.getProperty("EHOMO"));
    Assert.assertNotNull("ELECTRONIC ENERGY not found", newmol.getProperty("ELECTRONIC ENERGY"));
    for (int i = 0; i < newmol.getAtomCount(); i++) {
        Assert.assertNotNull(newmol.getAtom(i).getPoint3d());
    }
    SmilesGenerator g = new SmilesGenerator();
    // String newsmiles = g.createSMILES(newmol);
    // assertEquals(smiles,newsmiles);
    // isisomorph returns false if createSmiles was not run before; perhaps
    // smth to do with atom types configuration
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(newmol);
    CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
    adder.addImplicitHydrogens(mol);
    MoleculeTools.convertImplicitToExplicitHydrogens(mol);
    UniversalIsomorphismTester uit = new UniversalIsomorphismTester();
    Assert.assertTrue("Isomorphism check", uit.isIsomorph(mol, newmol));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) UniversalIsomorphismTester(org.openscience.cdk.isomorphism.UniversalIsomorphismTester) CDKHydrogenAdder(org.openscience.cdk.tools.CDKHydrogenAdder) SmilesGenerator(org.openscience.cdk.smiles.SmilesGenerator)

Example 4 with UniversalIsomorphismTester

use of org.openscience.cdk.isomorphism.UniversalIsomorphismTester in project ambit-mirror by ideaconsult.

the class StructureKeysBitSetGeneratorTest method testBiphenyl4CDK.

@Test
public void testBiphenyl4CDK() throws Exception {
    IteratingSDFReader reader = new IteratingSDFReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("biphenyl.sdf")), SilentChemObjectBuilder.getInstance());
    IAtomContainer biphenyl_kekule = null;
    while (reader.hasNext()) {
        IChemObject o = reader.next();
        Assert.assertTrue(o instanceof IAtomContainer);
        biphenyl_kekule = (IAtomContainer) o;
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(biphenyl_kekule);
        // well, Hydrogens are already in the file, but we need to mimic the
        // generic read/processing workflow
        CDKHydrogenAdder hAdder = CDKHydrogenAdder.getInstance(biphenyl_kekule.getBuilder());
        hAdder.addImplicitHydrogens(biphenyl_kekule);
        CDKHueckelAromaticityDetector.detectAromaticity(biphenyl_kekule);
        MoleculeTools.convertImplicitToExplicitHydrogens(biphenyl_kekule);
        biphenyl_kekule.setID("biphenyl_kekule");
        break;
    }
    reader.close();
    Assert.assertNotNull(biphenyl_kekule);
    // get the biphenyl as aromatic smiles
    SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer biphenyl_aromaticsmiles = parser.parseSmiles("c1ccccc1c2ccccc2");
    biphenyl_aromaticsmiles.setID("biphenyl_aromatic");
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(biphenyl_aromaticsmiles);
    CDKHydrogenAdder hAdder = CDKHydrogenAdder.getInstance(biphenyl_aromaticsmiles.getBuilder());
    hAdder.addImplicitHydrogens(biphenyl_aromaticsmiles);
    CDKHueckelAromaticityDetector.detectAromaticity(biphenyl_aromaticsmiles);
    MoleculeTools.convertImplicitToExplicitHydrogens(biphenyl_aromaticsmiles);
    // get the biphenyl as Kekule smiles
    IAtomContainer biphenyl_kekulesmiles = parser.parseSmiles("C1=C(C=CC=C1)C2=CC=CC=C2");
    biphenyl_kekulesmiles.setID("biphenyl_kekulesmiles");
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(biphenyl_kekulesmiles);
    hAdder = CDKHydrogenAdder.getInstance(biphenyl_kekulesmiles.getBuilder());
    hAdder.addImplicitHydrogens(biphenyl_kekulesmiles);
    CDKHueckelAromaticityDetector.detectAromaticity(biphenyl_kekulesmiles);
    MoleculeTools.convertImplicitToExplicitHydrogens(biphenyl_kekulesmiles);
    UniversalIsomorphismTester uit = new UniversalIsomorphismTester();
    Assert.assertTrue(uit.isIsomorph(biphenyl_aromaticsmiles, biphenyl_kekule));
    Assert.assertTrue(uit.isIsomorph(biphenyl_aromaticsmiles, biphenyl_kekulesmiles));
    Assert.assertTrue(uit.isIsomorph(biphenyl_kekulesmiles, biphenyl_kekule));
    // #1 with the latest fix, we'll not find double bonds :)
    ISmartsPattern smartsPattern_ambit = SmartsPatternFactory.createSmartsPattern(SmartsParser.smarts_nk, "[#6]=[#6]", false);
    Assert.assertTrue(smartsPattern_ambit.match(biphenyl_aromaticsmiles) == 0);
    Assert.assertTrue(smartsPattern_ambit.match(biphenyl_kekule) == 0);
    Assert.assertTrue(smartsPattern_ambit.match(biphenyl_kekulesmiles) == 0);
    // #1 with the latest fix, we'll not find double bonds :)
    ISmartsPattern smartsPattern_fast = SmartsPatternFactory.createSmartsPattern(SmartsParser.smarts_fast, "[#6]=[#6]", false);
    Assert.assertTrue(smartsPattern_fast.match(biphenyl_aromaticsmiles) == 0);
    Assert.assertTrue(smartsPattern_fast.match(biphenyl_kekule) == 0);
    Assert.assertTrue(smartsPattern_fast.match(biphenyl_kekulesmiles) == 0);
    // #3 cdk does find double bonds in kekule representation
    ISmartsPattern smartsPattern_cdk = SmartsPatternFactory.createSmartsPattern(SmartsParser.smarts_cdk, "[#6]=[#6]", false);
    Assert.assertTrue(smartsPattern_cdk.match(biphenyl_aromaticsmiles) == 0);
    // this is fixed in cdk 1.4.4
    Assert.assertTrue(smartsPattern_cdk.match(biphenyl_kekule) == 0);
    Assert.assertTrue(smartsPattern_cdk.match(biphenyl_kekulesmiles) == 0);
    // same as #3 but using CDK code only
    SMARTSQueryTool sqt = new SMARTSQueryTool("[#6]=[#6]", SilentChemObjectBuilder.getInstance());
    // there is no any double bond in biphenyl, created via aromatic smiles
    // Fixed in cdk 1.4.4
    Assert.assertFalse(sqt.matches(biphenyl_aromaticsmiles));
    // there is at least one :) double bond in the biphenyl , read from SDF
    Assert.assertFalse(sqt.matches(biphenyl_kekule));
    // there is at least one :) double bond in the biphenyl , read from SDF
    Assert.assertFalse(sqt.matches(biphenyl_kekulesmiles));
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStreamReader(java.io.InputStreamReader) IChemObject(org.openscience.cdk.interfaces.IChemObject) UniversalIsomorphismTester(org.openscience.cdk.isomorphism.UniversalIsomorphismTester) SMARTSQueryTool(org.openscience.cdk.smiles.smarts.SMARTSQueryTool) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) CDKHydrogenAdder(org.openscience.cdk.tools.CDKHydrogenAdder) ISmartsPattern(ambit2.smarts.query.ISmartsPattern) Test(org.junit.Test)

Example 5 with UniversalIsomorphismTester

use of org.openscience.cdk.isomorphism.UniversalIsomorphismTester in project ambit-mirror by ideaconsult.

the class AutomaticTestUtilities method sss_SingleDBStrStat.

// -----------------------------------------------------
int sss_SingleDBStrStat(String line) {
    // Performs statistics for each structure from the DB
    // It is applied for several algorithms simultaneously
    UniversalIsomorphismTester uit = new UniversalIsomorphismTester();
    long startTime, endTime;
    long timeAmbit = 0;
    long timeCDK = 0;
    long timeAmbitCDK = 0;
    long timeCDKAmbit = 0;
    // long timeAmbitSMSD = 0;
    // long timeCDKSMSD = 0;
    // Ambit parser
    IQueryAtomContainer query_ambit = spAmbit.parse(line);
    spAmbit.setNeededDataFlags();
    String errorMsg = spAmbit.getErrorMessages();
    if (!errorMsg.equals("")) {
        System.out.println("Smarts Parser errors:\n" + errorMsg);
        return -1;
    }
    // CDK parser
    QueryAtomContainer query_CDK = null;
    try {
        query_CDK = SMARTSParser.parse(line, SilentChemObjectBuilder.getInstance());
    } catch (Exception e) {
        System.out.println("CDK parsing error: " + e.toString());
        return -1;
    }
    // Initial line in the output
    output("###test  Ambit  CDK  AmbitCDK  CDKAmbit  AmbitSMSD CDKSMSD " + endLine);
    int sssResult = 0;
    boolean bondSensitive = true;
    boolean removeHydrogen = true;
    // Isomorphism comparisonSMSD = new Isomorphism(Algorithm.SubStructure,
    // bondSensitive);
    output("###  " + query_ambit.getAtomCount() + "   " + line + endLine);
    try {
        IChemObjectBuilder b = SilentChemObjectBuilder.getInstance();
        IteratingSDFReader reader = new IteratingSDFReader(new FileReader(dbFileName), b);
        int record = 0;
        while (reader.hasNext()) {
            record++;
            if (record > this.nDBStr)
                break;
            if (record % 100 == 0)
                System.out.println("db-rec " + record);
            Object o = reader.next();
            if (o instanceof IAtomContainer) {
                IAtomContainer mol = (IAtomContainer) o;
                if (mol.getAtomCount() == 0)
                    continue;
                AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
                CDKHueckelAromaticityDetector.detectAromaticity(mol);
                if (FlagStat_SingleDBStr_Ambit) {
                    isoTester.setQuery(query_ambit);
                    if (FlagGarbCollector)
                        callGarbCollector();
                    startTime = System.nanoTime();
                    spAmbit.setSMARTSData(mol);
                    boolean hasIso = isoTester.hasIsomorphism(mol);
                    endTime = System.nanoTime();
                    timeAmbit = endTime - startTime;
                    if (hasIso)
                        sssResult = 1;
                    else
                        sssResult = 0;
                // System.out.println("record " + record+ "  " + hasIso
                // + "   " + startTime + "  " + endTime);
                }
                if (FlagStat_SingleDBStr_CDK) {
                    if (FlagGarbCollector)
                        callGarbCollector();
                    startTime = System.nanoTime();
                    boolean res = uit.isSubgraph(mol, query_CDK);
                    endTime = System.nanoTime();
                    timeCDK = endTime - startTime;
                }
                if (FlagStat_SingleDBStr_Ambit_CDK) {
                    if (FlagGarbCollector)
                        callGarbCollector();
                    startTime = System.nanoTime();
                    spAmbit.setSMARTSData(mol);
                    boolean res = uit.isSubgraph(mol, query_ambit);
                    endTime = System.nanoTime();
                    timeAmbitCDK = endTime - startTime;
                }
                if (FlagStat_SingleDBStr_CDK_Ambit) {
                    if (FlagGarbCollector)
                        callGarbCollector();
                    isoTester.setQuery(query_CDK);
                    startTime = System.nanoTime();
                    boolean hasIso = isoTester.hasIsomorphism(mol);
                    endTime = System.nanoTime();
                    timeCDKAmbit = endTime - startTime;
                }
                /*
					 * if (FlagStat_SingleDBStr_Ambit_SMSD) { try { if
					 * (FlagGarbCollector) callGarbCollector(); startTime =
					 * System.nanoTime(); spAmbit.setSMARTSData(mol);
					 * comparisonSMSD.init(query_ambit,mol,
					 * removeHydrogen,true);
					 * //comparisonSMSD.setChemFilters(false, false, false);
					 * //boolean res = comparisonSMSD.isSubgraph(); endTime =
					 * System.nanoTime(); timeAmbitSMSD = endTime - startTime;
					 * //System.out.println("record " + record+ "  " + res +
					 * "   " + startTime + "  " + endTime); } catch(Exception e)
					 * { System.out.println("SMSD error: " );
					 * //e.printStackTrace(); continue; } }
					 * 
					 * if (FlagStat_SingleDBStr_CDK_SMSD) { try { startTime =
					 * System.nanoTime(); comparisonSMSD.init(query_CDK,mol,
					 * removeHydrogen,true); endTime = System.nanoTime();
					 * timeCDKSMSD = endTime - startTime;
					 * //System.out.println("record " + record+ "  " + res +
					 * "   " + startTime + "  " + endTime); } catch(Exception e)
					 * { System.out.println("SMSD error: " ); continue; } }
					 */
                output("db-" + record + "  " + mol.getAtomCount() + "  " + sssResult + "       " + timeAmbit + "  " + timeCDK + "  " + timeAmbitCDK + "  " + timeCDKAmbit + "  " + // timeAmbitSMSD + "  " + timeCDKSMSD +
                endLine);
            // System.out.println("record " + record+ "  " +
            // mol.getAtomCount());
            }
        }
    } catch (Exception e) {
        System.out.println(e.toString());
        return (-1);
    }
    return (0);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) EmptyMoleculeException(ambit2.base.exceptions.EmptyMoleculeException) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) UniversalIsomorphismTester(org.openscience.cdk.isomorphism.UniversalIsomorphismTester) FileReader(java.io.FileReader)

Aggregations

UniversalIsomorphismTester (org.openscience.cdk.isomorphism.UniversalIsomorphismTester)69 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)68 Test (org.junit.Test)50 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)36 ArrayList (java.util.ArrayList)33 IReactionProcess (org.openscience.cdk.reaction.IReactionProcess)31 IParameterReact (org.openscience.cdk.reaction.type.parameters.IParameterReact)30 SetReactionCenter (org.openscience.cdk.reaction.type.parameters.SetReactionCenter)30 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)29 ReactionProcessTest (org.openscience.cdk.reaction.ReactionProcessTest)29 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)26 IAtom (org.openscience.cdk.interfaces.IAtom)24 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)15 CDKException (org.openscience.cdk.exception.CDKException)14 SmilesParser (org.openscience.cdk.smiles.SmilesParser)7 SlowTest (org.openscience.cdk.test.SlowTest)7 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)5 SmilesGenerator (org.openscience.cdk.smiles.SmilesGenerator)4 AtomConfigurator (ambit2.core.processors.structure.AtomConfigurator)3 HydrogenAdderProcessor (ambit2.core.processors.structure.HydrogenAdderProcessor)3