Search in sources :

Example 1 with SMARTSQueryTool

use of org.openscience.cdk.smiles.smarts.SMARTSQueryTool in project MetFragRelaunched by ipb-halle.

the class SmartsGroup method removeDuplicates.

public void removeDuplicates() {
    java.util.ArrayList<Object> newList = new java.util.ArrayList<Object>();
    java.util.ArrayList<String> newSmiles = new java.util.ArrayList<String>();
    for (int i = 0; i < this.list.size(); i++) {
        String current = ((SMARTSQueryTool) this.list.get(i)).getSmarts();
        if (!newList.contains(current)) {
            newList.add(current);
            newSmiles.add(this.smiles.get(i));
        }
    }
    this.list = new java.util.ArrayList<Object>();
    for (int i = 0; i < newList.size(); i++) {
        SMARTSQueryTool sqt = new SMARTSQueryTool((String) newList.get(i), DefaultChemObjectBuilder.getInstance());
        this.list.add(sqt);
    }
    this.smiles = newSmiles;
}
Also used : ArrayList(java.util.ArrayList) SMARTSQueryTool(org.openscience.cdk.smiles.smarts.SMARTSQueryTool)

Example 2 with SMARTSQueryTool

use of org.openscience.cdk.smiles.smarts.SMARTSQueryTool in project MetFragRelaunched by ipb-halle.

the class SmartsSubstructureExclusionScoreInitialiser method initScoreParameters.

@Override
public void initScoreParameters(Settings settings) {
    String[] excludedSmarts = (String[]) settings.get(VariableNames.SCORE_SMARTS_EXCLUSION_LIST_NAME);
    SMARTSQueryTool[] smartsQuerytools = null;
    if (excludedSmarts != null && excludedSmarts.length != 0) {
        smartsQuerytools = new SMARTSQueryTool[excludedSmarts.length];
        for (int i = 0; i < excludedSmarts.length; i++) {
            smartsQuerytools[i] = new SMARTSQueryTool(excludedSmarts[i], DefaultChemObjectBuilder.getInstance());
        }
        settings.set(VariableNames.SMARTS_SUBSTRUCTURE_EXCLUSION_SCORE_LIST_NAME, smartsQuerytools);
    }
}
Also used : SMARTSQueryTool(org.openscience.cdk.smiles.smarts.SMARTSQueryTool)

Example 3 with SMARTSQueryTool

use of org.openscience.cdk.smiles.smarts.SMARTSQueryTool in project MetFragRelaunched by ipb-halle.

the class SmartsSubstructureInclusionScoreInitialiser method initScoreParameters.

@Override
public void initScoreParameters(Settings settings) {
    String[] excludedSmarts = (String[]) settings.get(VariableNames.SCORE_SMARTS_INCLUSION_LIST_NAME);
    SMARTSQueryTool[] smartsQuerytools = null;
    if (excludedSmarts != null && excludedSmarts.length != 0) {
        smartsQuerytools = new SMARTSQueryTool[excludedSmarts.length];
        for (int i = 0; i < excludedSmarts.length; i++) {
            smartsQuerytools[i] = new SMARTSQueryTool(excludedSmarts[i], DefaultChemObjectBuilder.getInstance());
        }
        settings.set(VariableNames.SMARTS_SUBSTRUCTURE_INCLUSION_SCORE_LIST_NAME, smartsQuerytools);
    }
}
Also used : SMARTSQueryTool(org.openscience.cdk.smiles.smarts.SMARTSQueryTool)

Example 4 with SMARTSQueryTool

use of org.openscience.cdk.smiles.smarts.SMARTSQueryTool 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 SMARTSQueryTool

use of org.openscience.cdk.smiles.smarts.SMARTSQueryTool in project cdk by cdk.

the class RecursiveTest method testBasicAmineOnDrugs_cdkAromaticModel.

@Category(SlowTest.class)
@Test
public void testBasicAmineOnDrugs_cdkAromaticModel() throws Exception {
    String filename = "drugs.smi";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    IteratingSMILESReader reader = new IteratingSMILESReader(ins, DefaultChemObjectBuilder.getInstance());
    SMARTSQueryTool sqt = new SMARTSQueryTool("[NX3;H2,H1;!$(NC=O)]", DefaultChemObjectBuilder.getInstance());
    sqt.setAromaticity(new Aromaticity(ElectronDonation.cdk(), Cycles.cdkAromaticSet()));
    int nmatch = 0;
    int nmol = 0;
    READ: while (reader.hasNext()) {
        IAtomContainer container = reader.next();
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(container);
        // model
        for (IAtom atom : container.atoms()) {
            if (atom.getAtomTypeName() == null) {
                continue READ;
            }
        }
        if (sqt.matches(container)) {
            nmatch++;
        }
        nmol++;
    }
    reader.close();
    Assert.assertEquals(141, nmol);
    Assert.assertEquals(4, nmatch);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) Aromaticity(org.openscience.cdk.aromaticity.Aromaticity) IteratingSMILESReader(org.openscience.cdk.io.iterator.IteratingSMILESReader) InputStream(java.io.InputStream) SMARTSQueryTool(org.openscience.cdk.smiles.smarts.SMARTSQueryTool) IAtom(org.openscience.cdk.interfaces.IAtom) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) SlowTest(org.openscience.cdk.test.SlowTest)

Aggregations

SMARTSQueryTool (org.openscience.cdk.smiles.smarts.SMARTSQueryTool)26 Test (org.junit.Test)17 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)17 SlowTest (org.openscience.cdk.test.SlowTest)10 Aromaticity (org.openscience.cdk.aromaticity.Aromaticity)6 SmilesParser (org.openscience.cdk.smiles.SmilesParser)5 FastBitArray (de.ipbhalle.metfraglib.FastBitArray)3 InputStream (java.io.InputStream)3 List (java.util.List)3 IAtom (org.openscience.cdk.interfaces.IAtom)3 InputStreamReader (java.io.InputStreamReader)2 Ignore (org.junit.Ignore)2 Category (org.junit.experimental.categories.Category)2 CDKException (org.openscience.cdk.exception.CDKException)2 RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)1 ISmartsPattern (ambit2.smarts.query.ISmartsPattern)1 BitArrayNeutralLoss (de.ipbhalle.metfraglib.fragment.BitArrayNeutralLoss)1 HighlightSubStructureImageGenerator (de.ipbhalle.metfraglib.imagegenerator.HighlightSubStructureImageGenerator)1 CandidateList (de.ipbhalle.metfraglib.list.CandidateList)1 ChemicalDatabase (de.unijena.bioinf.chemdb.ChemicalDatabase)1