Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
made logging in the AllRingsFinder optional, this helps with performa…
…nce.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
Stefan Kuhn authored and egonw committed Mar 17, 2010
1 parent 421375b commit 758c733
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions src/main/org/openscience/cdk/ringsearch/AllRingsFinder.java
Expand Up @@ -70,8 +70,7 @@
@TestClass("org.openscience.cdk.ringsearch.AllRingsFinderTest")
public class AllRingsFinder
{
private final ILoggingTool logger =
LoggingToolFactory.createLoggingTool(AllRingsFinder.class);
private ILoggingTool logger=null;

public boolean debug = false;
private long timeout = 5000;
Expand All @@ -86,8 +85,25 @@ public class AllRingsFinder
List<Path> potentialRings = new ArrayList<Path>();
List<Path> removePaths = new ArrayList<Path>();


/**
* Constructor for the AllRingsFinder.
*
* @param logging true=logging will be done (slower), false = no logging.
*/
public AllRingsFinder(boolean logging){
if(logging)
logger =
LoggingToolFactory.createLoggingTool(AllRingsFinder.class);
}

/**
* Constructor for the AllRingsFinder with logging.
*/
public AllRingsFinder(){
this(true);
}

/**
* Returns a ringset containing all rings in the given AtomContainer
* Calls {@link #findAllRings(IAtomContainer, Integer)} with max ring size argument set to null (=unlimited ring sizes)
*
Expand Down Expand Up @@ -174,8 +190,10 @@ private void doSearch(IAtomContainer ac, List<Path> paths, IRingSet ringSet, Int
* creating a set of two membered paths from all the bonds in the molecule
*/
initPathGraph(ac, paths);
logger.debug("BondCount: ", ac.getBondCount());
logger.debug("PathCount: ", paths.size());
if(logger!=null){
logger.debug("BondCount: ", ac.getBondCount());
logger.debug("PathCount: ", paths.size());
}
do
{
atom = selectAtom(ac);
Expand All @@ -184,8 +202,10 @@ private void doSearch(IAtomContainer ac, List<Path> paths, IRingSet ringSet, Int
remove(atom, ac, paths, ringSet, maxPathLen);
}
} while (paths.size() > 0 && atom != null);
logger.debug("paths.size(): ", paths.size());
logger.debug("ringSet.size(): ", ringSet.getAtomContainerCount());
if(logger!=null){
logger.debug("paths.size(): ", paths.size());
logger.debug("ringSet.size(): ", ringSet.getAtomContainerCount());
}
}


Expand All @@ -210,7 +230,8 @@ private void remove(IAtom atom, IAtomContainer ac, List<Path> paths, IRingSet ri
newPaths.clear();
removePaths.clear();
potentialRings.clear();
logger.debug("*** Removing atom " + originalAc.getAtomNumber(atom) + " ***");
if(logger!=null)
logger.debug("*** Removing atom " + originalAc.getAtomNumber(atom) + " ***");

for (int i = 0; i < paths.size(); i++)
{
Expand All @@ -226,7 +247,9 @@ private void remove(IAtom atom, IAtomContainer ac, List<Path> paths, IRingSet ri
intersectionSize = path1.getIntersectionSize(path2);
if (intersectionSize < 3)
{
logger.debug("Joining " + path1.toString(originalAc) + " and " + path2.toString(originalAc));
if(logger!=null){
logger.debug("Joining " + path1.toString(originalAc) + " and " + path2.toString(originalAc));
}
union = Path.join(path1, path2, atom);
if (intersectionSize == 1)
{
Expand All @@ -238,7 +261,9 @@ private void remove(IAtom atom, IAtomContainer ac, List<Path> paths, IRingSet ri
}
}
//logger.debug("Intersection Size: " + intersectionSize);
logger.debug("Union: ", union.toString(originalAc));
if(logger!=null){
logger.debug("Union: ", union.toString(originalAc));
}
/*
* Now we know that path1 and
* path2 share the Atom atom.
Expand All @@ -261,7 +286,8 @@ private void remove(IAtom atom, IAtomContainer ac, List<Path> paths, IRingSet ri
}
detectRings(potentialRings, rings, originalAc);
ac.removeAtomAndConnectedElectronContainers(atom);
logger.debug("\n" + paths.size() + " paths and " + ac.getAtomCount() + " atoms left.");
if(logger!=null)
logger.debug("\n" + paths.size() + " paths and " + ac.getAtomCount() + " atoms left.");
}


Expand All @@ -279,7 +305,8 @@ private void detectRings(List<Path> paths, IRingSet ringSet, IAtomContainer ac)
IAtom a1, a2 = null;
for (Path path : paths) {
if (path.size() > 3 && path.lastElement() == path.firstElement()) {
logger.debug("Removing path " + path.toString(originalAc) + " which is a ring.");
if(logger!=null)
logger.debug("Removing path " + path.toString(originalAc) + " which is a ring.");
path.removeElementAt(0);
ring = ac.getBuilder().newRing();
for (int g = 0; g < path.size() - 1; g++) {
Expand Down Expand Up @@ -333,7 +360,8 @@ private void initPathGraph(IAtomContainer ac, List<Path> paths)
IBond bond = (IBond) bonds.next();
path = new Path(bond.getAtom(0), bond.getAtom(1));
paths.add(path);
logger.debug("initPathGraph: " + path.toString(originalAc));
if(logger!=null)
logger.debug("initPathGraph: " + path.toString(originalAc));
}
}

Expand Down

0 comments on commit 758c733

Please sign in to comment.