Search in sources :

Example 11 with Aromaticity

use of org.openscience.cdk.aromaticity.Aromaticity in project cdk by cdk.

the class SMARTSSearchTest method testLogicalOrLowAnd6_cdkAromaticity.

@Test
public void testLogicalOrLowAnd6_cdkAromaticity() throws Exception {
    SMARTSQueryTool sqt = smarts("[#7,C;+0,+1]");
    IAtomContainer smi = smiles("[Na+].[Na+].[O-]C(=O)c1ccccc1c2c3ccc([O-])cc3oc4cc(=O)ccc24");
    sqt.setAromaticity(new Aromaticity(ElectronDonation.cdk(), Cycles.cdkAromaticSet()));
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(smi);
    int[] results = match(sqt, smi);
    Assert.assertEquals(8, results[0]);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) Aromaticity(org.openscience.cdk.aromaticity.Aromaticity) SMARTSQueryTool(org.openscience.cdk.smiles.smarts.SMARTSQueryTool) Test(org.junit.Test)

Example 12 with Aromaticity

use of org.openscience.cdk.aromaticity.Aromaticity in project ErtlFunctionalGroupsFinder by zielesny.

the class ErtlFunctionalGroupsFinderEvaluationTest method testCycleFinderDependency.

/**
 * Test for analyzing molecules in an SD file for six different CycleFinder settings supplied by the cdk: all(),
 * vertexShort(), relevant(), essential(), tripleShort() and cdkAromaticSet().
 * <p>
 * (Functional groups occurring multiple times in the same molecule are counted multiple times)
 *
 * @throws java.lang.Exception if initializeWithFileOperations() throws an exception or an unexpected exception occurs
 */
@Test
public void testCycleFinderDependency() throws Exception {
    this.initializeWithFileOperations(ErtlFunctionalGroupsFinderEvaluationTest.SD_FILE_PATH, ErtlFunctionalGroupsFinderEvaluationTest.CYCLE_FINDER_TEST_IDENTIFIER);
    Assume.assumeTrue(this.isTestAbleToRun);
    System.out.println("\nLoading file with path: " + ErtlFunctionalGroupsFinderEvaluationTest.SD_FILE_PATH);
    File tmpSDFile = new File(ErtlFunctionalGroupsFinderEvaluationTest.SD_FILE_PATH);
    int tmpRequiredNumberOfReaders = 6;
    IteratingSDFReader[] tmpReaders = new IteratingSDFReader[tmpRequiredNumberOfReaders];
    try {
        for (int i = 0; i < tmpRequiredNumberOfReaders; i++) {
            IteratingSDFReader tmpReader = new IteratingSDFReader(new FileInputStream(tmpSDFile), DefaultChemObjectBuilder.getInstance(), true);
            tmpReaders[i] = tmpReader;
        }
    } catch (FileNotFoundException aFileNotFoundException) {
        System.out.println("\nSD file could not be found. Test is ignored.");
        Assume.assumeTrue(false);
        return;
    }
    Aromaticity tmpDaylightModelAll = new Aromaticity(ElectronDonation.daylight(), Cycles.all());
    Aromaticity tmpDaylightModelVertexShort = new Aromaticity(ElectronDonation.daylight(), Cycles.vertexShort());
    Aromaticity tmpDaylightModelRelevant = new Aromaticity(ElectronDonation.daylight(), Cycles.relevant());
    Aromaticity tmpDaylightModelEssential = new Aromaticity(ElectronDonation.daylight(), Cycles.essential());
    Aromaticity tmpDaylightModelTripleShort = new Aromaticity(ElectronDonation.daylight(), Cycles.tripletShort());
    Aromaticity tmpDaylightModelCdkAromaticSet = new Aromaticity(ElectronDonation.daylight(), Cycles.cdkAromaticSet());
    boolean tmpAreMultiplesCounted = false;
    this.calculateAbsoluteFGFrequencies(tmpReaders[0], "all", tmpDaylightModelAll, tmpAreMultiplesCounted);
    this.calculateAbsoluteFGFrequencies(tmpReaders[1], "vertexShort", tmpDaylightModelVertexShort, tmpAreMultiplesCounted);
    this.calculateAbsoluteFGFrequencies(tmpReaders[2], "relevant", tmpDaylightModelRelevant, tmpAreMultiplesCounted);
    this.calculateAbsoluteFGFrequencies(tmpReaders[3], "essential", tmpDaylightModelEssential, tmpAreMultiplesCounted);
    this.calculateAbsoluteFGFrequencies(tmpReaders[4], "tripletShort", tmpDaylightModelTripleShort, tmpAreMultiplesCounted);
    this.calculateAbsoluteFGFrequencies(tmpReaders[5], "cdkAromaticSet", tmpDaylightModelCdkAromaticSet, tmpAreMultiplesCounted);
    System.out.println("\nAll analyses are done!");
    for (IteratingSDFReader tmpReader : tmpReaders) {
        tmpReader.close();
    }
    this.saveData();
    System.out.println("\nFinished!");
    System.out.println("\nNumber of occured exceptions: " + this.exceptionsCounter);
}
Also used : Aromaticity(org.openscience.cdk.aromaticity.Aromaticity) FileNotFoundException(java.io.FileNotFoundException) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 13 with Aromaticity

use of org.openscience.cdk.aromaticity.Aromaticity in project ambit-mirror by ideaconsult.

the class AutomaticSmirksTestUtilities method applySmirks.

public List<String> applySmirks(String smrk, String smi) {
    try {
        SMIRKSManager smrkMan = new SMIRKSManager(SilentChemObjectBuilder.getInstance());
        smrkMan.setFlagSSMode(SmartsConst.SSM_MODE.SSM_NON_IDENTICAL_FIRST);
        smrkMan.setFlagProcessResultStructures(true);
        smrkMan.setFlagClearHybridizationBeforeResultProcess(true);
        smrkMan.setFlagClearImplicitHAtomsBeforeResultProcess(true);
        smrkMan.setFlagClearAromaticityBeforeResultProcess(true);
        smrkMan.setFlagAddImplicitHAtomsOnResultProcess(true);
        smrkMan.setFlagConvertAddedImplicitHToExplicitOnResultProcess(false);
        smrkMan.setFlagConvertExplicitHToImplicitOnResultProcess(true);
        smrkMan.getSmartsParser().mSupportDoubleBondAromaticityNotSpecified = false;
        smrkMan.setFlagApplyStereoTransformation(true);
        SMIRKSReaction reaction = smrkMan.parse(smrk);
        if (!smrkMan.getErrors().equals(""))
            throw new RuntimeException("Invalid SMIRKS: " + smrkMan.getErrors());
        IAtomContainer target = smilesParser.parseSmiles(smi);
        for (IAtom atom : target.atoms()) if (atom.getFlag(CDKConstants.ISAROMATIC))
            atom.setFlag(CDKConstants.ISAROMATIC, false);
        for (IBond bond : target.bonds()) if (bond.getFlag(CDKConstants.ISAROMATIC))
            bond.setFlag(CDKConstants.ISAROMATIC, false);
        // do not add Hs: https://sourceforge.net/p/cdk/mailman/message/34608714/
        // AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(target);
        // CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
        // adder.addImplicitHydrogens(target);
        MoleculeTools.convertImplicitToExplicitHydrogens(target);
        // for our project, we want to use daylight aromaticity
        // CDKHueckelAromaticityDetector.detectAromaticity(target);
        Aromaticity aromaticity = new Aromaticity(ElectronDonation.daylight(), Cycles.or(Cycles.all(), Cycles.edgeShort()));
        aromaticity.apply(target);
        IAtomContainerSet resSet2 = smrkMan.applyTransformationWithSingleCopyForEachPos(target, null, reaction, SmartsConst.SSM_MODE.SSM_ALL);
        List<String> result = new ArrayList<String>();
        if (resSet2 != null)
            for (int i = 0; i < resSet2.getAtomContainerCount(); i++) {
                IAtomContainer mol = resSet2.getAtomContainer(i);
                AtomContainerManipulator.suppressHydrogens(mol);
                String smiles = SmilesGenerator.absolute().create(mol);
                result.add(smiles);
            }
        return result;
    } catch (Exception e) {
        System.err.println(e.getMessage());
        System.err.println("SMIRKS " + smrk);
        System.err.println("SMILES " + smi);
        // e.printStackTrace();
        return null;
    }
}
Also used : SMIRKSReaction(ambit2.smarts.SMIRKSReaction) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SMIRKSManager(ambit2.smarts.SMIRKSManager) Aromaticity(org.openscience.cdk.aromaticity.Aromaticity) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) IAtom(org.openscience.cdk.interfaces.IAtom) CDKException(org.openscience.cdk.exception.CDKException)

Example 14 with Aromaticity

use of org.openscience.cdk.aromaticity.Aromaticity in project MORTAR by FelixBaensch.

the class ErtlFunctionalGroupsFinderFragmenter method setAromaticityInstance.

// </editor-fold>
// 
// <editor-fold desc="Private methods">
/**
 * Sets only the instance, not the property! So it is safe for the property to call this method when overriding set().
 */
private void setAromaticityInstance(ElectronDonation anElectronDonation, CycleFinder aCycleFinder) throws NullPointerException {
    Objects.requireNonNull(anElectronDonation, "Given electron donation model is null.");
    Objects.requireNonNull(aCycleFinder, "Given cycle finder algorithm is null.");
    this.aromaticityModelInstance = new Aromaticity(anElectronDonation, aCycleFinder);
}
Also used : Aromaticity(org.openscience.cdk.aromaticity.Aromaticity)

Example 15 with Aromaticity

use of org.openscience.cdk.aromaticity.Aromaticity in project cdk by cdk.

the class SMARTSQueryToolTest method setAromaticity.

@Test
public void setAromaticity() throws Exception {
    SMARTSQueryTool sqt = new SMARTSQueryTool("[a]", DefaultChemObjectBuilder.getInstance());
    IAtomContainer furan = smiles("O1C=CC=C1");
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(furan);
    sqt.setAromaticity(new Aromaticity(ElectronDonation.cdk(), Cycles.mcb()));
    assertTrue(sqt.matches(furan, true));
    sqt.setAromaticity(new Aromaticity(ElectronDonation.piBonds(), Cycles.mcb()));
    assertFalse(sqt.matches(furan, true));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) Aromaticity(org.openscience.cdk.aromaticity.Aromaticity) Test(org.junit.Test)

Aggregations

Aromaticity (org.openscience.cdk.aromaticity.Aromaticity)23 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)15 Test (org.junit.Test)10 CDKException (org.openscience.cdk.exception.CDKException)10 IBond (org.openscience.cdk.interfaces.IBond)7 SMARTSQueryTool (org.openscience.cdk.smiles.smarts.SMARTSQueryTool)6 SlowTest (org.openscience.cdk.test.SlowTest)5 FastBitArray (de.ipbhalle.metfraglib.FastBitArray)4 IAtom (org.openscience.cdk.interfaces.IAtom)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)3 IteratingSDFReader (org.openscience.cdk.io.iterator.IteratingSDFReader)3 ExplicitHydrogenRepresentationException (de.ipbhalle.metfraglib.exceptions.ExplicitHydrogenRepresentationException)2 IOException (java.io.IOException)2 BitSetFingerprint (org.openscience.cdk.fingerprint.BitSetFingerprint)2 IBitFingerprint (org.openscience.cdk.fingerprint.IBitFingerprint)2 SmilesParser (org.openscience.cdk.smiles.SmilesParser)2 SMIRKSManager (ambit2.smarts.SMIRKSManager)1