Search in sources :

Example 1 with ISmartsPattern

use of ambit2.smarts.query.ISmartsPattern 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)

Aggregations

RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)1 ISmartsPattern (ambit2.smarts.query.ISmartsPattern)1 InputStreamReader (java.io.InputStreamReader)1 Test (org.junit.Test)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IChemObject (org.openscience.cdk.interfaces.IChemObject)1 IteratingSDFReader (org.openscience.cdk.io.iterator.IteratingSDFReader)1 UniversalIsomorphismTester (org.openscience.cdk.isomorphism.UniversalIsomorphismTester)1 SmilesParser (org.openscience.cdk.smiles.SmilesParser)1 SMARTSQueryTool (org.openscience.cdk.smiles.smarts.SMARTSQueryTool)1 CDKHydrogenAdder (org.openscience.cdk.tools.CDKHydrogenAdder)1