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);
}
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");
}
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;
}
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;
}
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;
}
Aggregations