Search in sources :

Example 1 with Aromaticity

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

the class ErtlFunctionalGroupsFinderEvaluationTest method analyzeElectronDonationDependency.

// </editor-fold>
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Private methods">
/**
 * Analyzes molecules in an SD file for all four different electron donation models supplied by the cdk:
 * daylight, cdk, piBonds, cdkAllowingExocyclic and the aromaticity model cdkLegacy.
 *
 * @param anSDFilePath absolute path of the SD file to analyze
 * @param aTestIdentifier a folder with this name will be created in the output directory and it will be added to
 * the output and log files' names for association of test and files; may be null or empty
 * @param anAreMultiplesCounted if false, functional groups that occur multiple times in the same molecule will
 * only be counted once
 * @throws java.lang.Exception if initializeWithFileOperations() throws an exception or an unexpected exception occurs
 */
private void analyzeElectronDonationDependency(String anSDFilePath, String aTestIdentifier, boolean anAreMultiplesCounted) throws Exception {
    this.initializeWithFileOperations(anSDFilePath, aTestIdentifier);
    Assume.assumeTrue(this.isTestAbleToRun);
    System.out.println("\nLoading file with path: " + anSDFilePath);
    File tmpSDFile = new File(anSDFilePath);
    int tmpRequiredNumberOfReaders = 5;
    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;
    }
    // If the 'all' CycleFinder produces an Intractable exception the 'vertexShort' CycleFinder is used
    CycleFinder tmpCycleFinder = Cycles.or(Cycles.all(), Cycles.vertexShort());
    Aromaticity tmpDaylightModel = new Aromaticity(ElectronDonation.daylight(), tmpCycleFinder);
    Aromaticity tmpCdkModel = new Aromaticity(ElectronDonation.cdk(), tmpCycleFinder);
    Aromaticity tmpPiBondsModel = new Aromaticity(ElectronDonation.piBonds(), tmpCycleFinder);
    Aromaticity tmpCdkAllowingExocyclicModel = new Aromaticity(ElectronDonation.cdkAllowingExocyclic(), tmpCycleFinder);
    Aromaticity tmpCDKLegacyModel = Aromaticity.cdkLegacy();
    this.calculateAbsoluteFGFrequencies(tmpReaders[0], ErtlFunctionalGroupsFinderEvaluationTest.DAYLIGHT_MODEL_SETTINGS_KEY, tmpDaylightModel, anAreMultiplesCounted);
    this.calculateAbsoluteFGFrequencies(tmpReaders[1], ErtlFunctionalGroupsFinderEvaluationTest.CDK_MODEL_SETTINGS_KEY, tmpCdkModel, anAreMultiplesCounted);
    this.calculateAbsoluteFGFrequencies(tmpReaders[2], ErtlFunctionalGroupsFinderEvaluationTest.PIBONDS_MODEL_SETTINGS_KEY, tmpPiBondsModel, anAreMultiplesCounted);
    this.calculateAbsoluteFGFrequencies(tmpReaders[3], ErtlFunctionalGroupsFinderEvaluationTest.CDK_EXOCYCLIC_MODEL_SETTINGS_KEY, tmpCdkAllowingExocyclicModel, anAreMultiplesCounted);
    this.calculateAbsoluteFGFrequencies(tmpReaders[4], ErtlFunctionalGroupsFinderEvaluationTest.CDK_LEGACY_MODEL_SETTINGS_KEY, tmpCDKLegacyModel, anAreMultiplesCounted);
    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) CycleFinder(org.openscience.cdk.graph.CycleFinder) FileNotFoundException(java.io.FileNotFoundException) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with Aromaticity

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

the class ErtlFunctionalGroupsFinderEvaluationTest method testPerformance.

/**
 * Testing the ErtlFunctionalGroupsFinder.find() method's performance on the given SD file.
 *
 * @throws java.lang.Exception if initializeWithFileOperations() throws an exception or the IteratingSDFReader
 * can not be closed or an unexpectedException occurs
 */
@Test
public void testPerformance() throws Exception {
    this.initialize(true, "PerformanceTest");
    // First, check if the SD file is present and ignore test if it is not
    String tmpPathToSDFile = ErtlFunctionalGroupsFinderEvaluationTest.SD_FILE_PATH;
    System.out.println("\nLoading file with path: " + tmpPathToSDFile);
    File tmpSDFile = new File(tmpPathToSDFile);
    if (!tmpSDFile.canRead()) {
        System.out.println("\n\tUnable to find or read a file with path \"" + tmpPathToSDFile + "\".");
        System.out.println("\nTest is ignored.");
        Assume.assumeTrue(false);
        return;
    }
    IteratingSDFReader tmpReader;
    try {
        tmpReader = new IteratingSDFReader(new FileInputStream(tmpSDFile), DefaultChemObjectBuilder.getInstance(), true);
    } catch (FileNotFoundException aFileNotFoundException) {
        System.out.println("\nSD file could not be found. Test is ignored.");
        Assume.assumeTrue(false);
        return;
    }
    List<IAtomContainer> tmpMoleculesList = new LinkedList<>();
    Aromaticity tmpCdkLegacyModel = new Aromaticity(ElectronDonation.daylight(), Cycles.or(Cycles.all(), Cycles.vertexShort()));
    while (tmpReader.hasNext()) {
        try {
            IAtomContainer tmpMolecule = (IAtomContainer) tmpReader.next();
            tmpMolecule = this.applyFiltersAndPreprocessing(tmpMolecule);
            if (tmpMolecule.getProperty(ErtlFunctionalGroupsFinderEvaluationTest.MOLECULE_MUST_BE_FILTERED_PROPERTY_KEY)) {
                /*No logging required here, it is a simple performance test*/
                continue;
            }
            tmpCdkLegacyModel.apply(tmpMolecule);
            tmpMoleculesList.add(tmpMolecule);
        } catch (Exception anException) {
        /*No logging required here, it is a simple performance test*/
        }
    }
    tmpReader.close();
    IAtomContainer[] tmpMoleculesArray = new IAtomContainer[tmpMoleculesList.size()];
    tmpMoleculesArray = tmpMoleculesList.toArray(tmpMoleculesArray);
    System.out.println("\nDone Loading database. Found and processed " + tmpMoleculesArray.length + " valid molecules.");
    long tmpStartTime = System.currentTimeMillis();
    for (IAtomContainer tmpMolecule : tmpMoleculesArray) {
        this.ertlFGFinderGenOn.find(tmpMolecule, false);
    }
    long tmpEndTime = System.currentTimeMillis();
    System.out.println("\nExtraction of functional groups from these molecules took " + (tmpEndTime - tmpStartTime) + " ms.\n");
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) 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) LinkedList(java.util.LinkedList) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 3 with Aromaticity

use of org.openscience.cdk.aromaticity.Aromaticity in project MetFragRelaunched by ipb-halle.

the class InChIDeuteriumGeneration method getAromaticAtoms.

/**
 * @param molecule
 * @return
 */
public static FastBitArray getAromaticAtoms(IAtomContainer molecule) {
    Aromaticity arom = new Aromaticity(ElectronDonation.cdk(), Cycles.cdkAromaticSet());
    FastBitArray aromaticAtoms = new FastBitArray(molecule.getAtomCount());
    try {
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
        arom.apply(molecule);
        Set<IBond> aromaticBonds = arom.findBonds(molecule);
        Iterator<IBond> it = aromaticBonds.iterator();
        while (it.hasNext()) {
            IBond bond = it.next();
            for (int k = 0; k < bond.getAtomCount(); k++) aromaticAtoms.set(molecule.indexOf(bond.getAtom(k)));
        }
    } catch (CDKException e) {
        e.printStackTrace();
    }
    return aromaticAtoms;
}
Also used : Aromaticity(org.openscience.cdk.aromaticity.Aromaticity) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) FastBitArray(de.ipbhalle.metfraglib.FastBitArray)

Example 4 with Aromaticity

use of org.openscience.cdk.aromaticity.Aromaticity in project MetFragRelaunched by ipb-halle.

the class SDFDeuteriumGeneration method getAromaticAtoms.

/**
 * @param molecule
 * @return
 */
public static FastBitArray getAromaticAtoms(IAtomContainer molecule) {
    Aromaticity arom = new Aromaticity(ElectronDonation.cdk(), Cycles.cdkAromaticSet());
    FastBitArray aromaticAtoms = new FastBitArray(molecule.getAtomCount());
    try {
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
        arom.apply(molecule);
        Set<IBond> aromaticBonds = arom.findBonds(molecule);
        Iterator<IBond> it = aromaticBonds.iterator();
        while (it.hasNext()) {
            IBond bond = it.next();
            for (int k = 0; k < bond.getAtomCount(); k++) aromaticAtoms.set(molecule.indexOf(bond.getAtom(k)));
        }
    } catch (CDKException e) {
        e.printStackTrace();
    }
    return aromaticAtoms;
}
Also used : Aromaticity(org.openscience.cdk.aromaticity.Aromaticity) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) FastBitArray(de.ipbhalle.metfraglib.FastBitArray)

Example 5 with Aromaticity

use of org.openscience.cdk.aromaticity.Aromaticity in project MetFragRelaunched by ipb-halle.

the class SmilesDeuteriumGeneration method getAromaticAtoms.

/**
 * @param molecule
 * @return
 */
public static FastBitArray getAromaticAtoms(IAtomContainer molecule) {
    Aromaticity arom = new Aromaticity(ElectronDonation.cdk(), Cycles.cdkAromaticSet());
    FastBitArray aromaticAtoms = new FastBitArray(molecule.getAtomCount());
    try {
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
        arom.apply(molecule);
        Set<IBond> aromaticBonds = arom.findBonds(molecule);
        Iterator<IBond> it = aromaticBonds.iterator();
        while (it.hasNext()) {
            IBond bond = it.next();
            for (int k = 0; k < bond.getAtomCount(); k++) aromaticAtoms.set(molecule.indexOf(bond.getAtom(k)));
        }
    } catch (CDKException e) {
        e.printStackTrace();
    }
    return aromaticAtoms;
}
Also used : Aromaticity(org.openscience.cdk.aromaticity.Aromaticity) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) FastBitArray(de.ipbhalle.metfraglib.FastBitArray)

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