Skip to content

Commit

Permalink
added tests for different ring detection methods;
Browse files Browse the repository at this point in the history
  • Loading branch information
Mila1004 committed Jul 6, 2024
1 parent 7bca034 commit 4d4f007
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
import org.junit.jupiter.api.Test;
import org.openscience.cdk.AtomContainerSet;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.exception.Intractable;
import org.openscience.cdk.graph.CycleFinder;
import org.openscience.cdk.graph.Cycles;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.io.iterator.IteratingSDFReader;
import org.openscience.cdk.ringsearch.RingSearch;
import org.openscience.cdk.silent.SilentChemObjectBuilder;

import java.io.File;
Expand Down Expand Up @@ -108,8 +112,8 @@ public class AlkylStructureFragmenterTest extends AlkylStructureFragmenter{
public AlkylStructureFragmenterTest() throws FileNotFoundException, URISyntaxException {
this.basicAlkylStructureFragmenter = new AlkylStructureFragmenter();
this.testStructuresACSet = new AtomContainerSet();
this.testStructuresACSet = readStructureToACSet("ASF_Test_Structures.sdf");
this.testExpectedFragmentsACSet = readStructureToACSet("ASF_Expected_Fragments.sdf");
this.testStructuresACSet = readStructuresToACSet("de.unijena.cheminf.mortar.model.fragmentation.algorithm.ASF/ASF_Test_Structures.sdf");
this.testExpectedFragmentsACSet = readStructuresToACSet("de.unijena.cheminf.mortar.model.fragmentation.algorithm.ASF/ASF_Expected_Fragments.sdf");
this.testExpectedFragmentsACList = new ArrayList<>(this.testExpectedFragmentsACSet.getAtomContainerCount());
//this.testAtomArray = this.basicAlkylStructureFragmenter.fillAtomArray(tmpAC);
this.testAtomArray = this.basicAlkylStructureFragmenter.fillAtomArray(this.testStructuresACSet.getAtomContainer(0));
Expand Down Expand Up @@ -149,9 +153,6 @@ public void markRingsTest() throws NoSuchMethodException, InvocationTargetExcept
this.testAtomArray = this.basicAlkylStructureFragmenter.fillAtomArray(tmpRingsAC);
this.testBondArray = this.basicAlkylStructureFragmenter.fillBondArray(tmpRingsAC);


//protected methods & variables -> test class extends origin class
//problem: marking on local(ASF) private variables
//ToDo: write test structure in fragmenter arrays; create array for comparison with expected markings
this.basicAlkylStructureFragmenter.markRings(tmpRingsAC, this.testAtomArray, this.testBondArray);
//ToDo: find way to compare structures without extracting tested substructures
Expand Down Expand Up @@ -277,7 +278,63 @@ public void defaultFragmentationTest() throws Exception {
}
//</editor-fold>

//<editor-fold desc="@Test Custom Methods">
@Test
public void detectRingsWithMCBTest() {
CycleFinder tmpCycleFinder = Cycles.mcb();
IAtomContainerSet tmpACSet;
try {
tmpACSet = this.readStructuresToACSet("de.unijena.cheminf.mortar.model.fragmentation.algorithm.ASF/ASF_Spiro_Test_Structure1.mol");
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
for (IAtomContainer tmpAC: tmpACSet.atomContainers()) {
try {
Cycles tmpMCBCycles = tmpCycleFinder.find(tmpAC);
System.out.println("MCB number of detected Cycles: " + tmpMCBCycles.numberOfCycles());
System.out.println("MCB detected ring atomcontainer below:");
System.out.println(tmpAC);
System.out.println("-----");
} catch (Intractable e) {
throw new RuntimeException(e);
}
}

}
@Test
public void detectRingsWithRingSearchTest() {
IAtomContainerSet tmpACSet;
try {
tmpACSet = this.readStructuresToACSet("de.unijena.cheminf.mortar.model.fragmentation.algorithm.ASF/ASF_Spiro_Test_Structure1.mol");
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
for (IAtomContainer tmpAC: tmpACSet.atomContainers()) {
RingSearch tmpRingSearch = new RingSearch(tmpAC);
List<IAtomContainer> tmpACList = tmpRingSearch.isolatedRingFragments();
int i = 0;
System.out.println("RingSearch isolated ring count from List " + i + ": " + tmpACList.size());
System.out.println("RingSearch detected ring atomcontainer below:");
System.out.println(tmpAC);
System.out.println("-----");
i++;
}
}
//</editor-fold>

//<editor-fold desc="Private Methods">

/**
* Compares two provided lists on equality while ignoring the lists' orders.
*
* @param aList1 First given list to compare
* @param aList2 Second given list to compare
* @return boolean whether given lists are equal
*/
private boolean compareListsIgnoringOrder(ArrayList aList1, ArrayList aList2) {
if (aList1 == null || aList2 == null) {
return false;
Expand Down Expand Up @@ -306,7 +363,15 @@ private List<String> generateSMILESFromACSet(IAtomContainerSet anACSet) throws C
return tmpSmilesList;
}

private IAtomContainerSet readStructureToACSet(String aFileName) throws FileNotFoundException, URISyntaxException {
/**
* Private method to read a given structure file to a CDK atomcontainer set.
*
* @param aFileName Name of the file to read from
* @return IAtomContainerSet with the read structures as AtomContainers
* @throws FileNotFoundException if no file with the given name can be located
* @throws URISyntaxException if given name of file cannot be parsed as URI reference
*/
private IAtomContainerSet readStructuresToACSet(String aFileName) throws FileNotFoundException, URISyntaxException {
URL tmpURL = this.getClass().getResource("/" + aFileName);
File tmpResourceFile = Paths.get(tmpURL.toURI()).toFile();
IteratingSDFReader tmpSDFReader = new IteratingSDFReader(new FileReader(tmpResourceFile), new SilentChemObjectBuilder());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

ACD/LABS07042411542D

11 12 0 0 0 0 0 0 0 0 1 V2000
16.5519 -6.5317 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
17.2169 -7.6836 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
15.2219 -6.5317 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
16.5519 -8.8354 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
14.5569 -7.6836 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
15.2219 -8.8354 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
14.0701 -8.8354 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
14.0701 -6.5317 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
12.7401 -8.8354 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
12.7401 -6.5317 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
12.0751 -7.6836 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
1 3 1 0 0 0 0
2 4 1 0 0 0 0
3 5 1 0 0 0 0
4 6 1 0 0 0 0
5 6 1 0 0 0 0
5 7 1 0 0 0 0
5 8 1 0 0 0 0
7 9 1 0 0 0 0
8 10 1 0 0 0 0
9 11 1 0 0 0 0
10 11 1 0 0 0 0
M END
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4d4f007

Please sign in to comment.