Search in sources :

Example 1 with CycleFinder

use of org.openscience.cdk.graph.CycleFinder 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)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Aromaticity (org.openscience.cdk.aromaticity.Aromaticity)1 CycleFinder (org.openscience.cdk.graph.CycleFinder)1 IteratingSDFReader (org.openscience.cdk.io.iterator.IteratingSDFReader)1