Skip to content

Commit

Permalink
Added a method to all Ring Finders to add the detected ring set to th…
Browse files Browse the repository at this point in the history
…e respective AtomContainer as a property.

The relevant variables have been added to CDKConstants.


git-svn-id: https://cdk.svn.sourceforge.net/svnroot/cdk/trunk/cdk@5704 eb4e18e3-b210-0410-a6ab-dec725e4b171
  • Loading branch information
steinbeck committed Feb 11, 2006
1 parent 6e04e94 commit ec3ced2
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 10 deletions.
Binary file not shown.
Binary file not shown.
Binary file added jar/jmolApis.jar
Binary file not shown.
Binary file added jar/jmolIO.jar
Binary file not shown.
11 changes: 11 additions & 0 deletions src/org/openscience/cdk/CDKConstants.java
Expand Up @@ -232,7 +232,18 @@ public class CDKConstants {
/** A smallest set of smallest rings computed for this molecule. */
public static final String SMALLEST_RINGS = "SmallestRings";

/** The essential rings computed for this molecule.
* The concept of Essential Rings is defined in
* SSSRFinder
*/
public static final String ESSENTIAL_RINGS = "EssentialRings";

/** The relevant rings computed for this molecule.
* The concept of relevant Rings is defined in
* SSSRFinder
*/
public static final String RELEVANT_RINGS = "RelevantRings";


/****************************************
* Some predefined property names for *
Expand Down
3 changes: 1 addition & 2 deletions src/org/openscience/cdk/io/JMEReader.java
Expand Up @@ -37,10 +37,9 @@

import org.jmol.adapter.smarter.SmarterJmolAdapter;
import org.jmol.api.JmolAdapter;
import org.openscience.cdk.interfaces.AtomContainer;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IChemObject;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.io.formats.IChemFormat;
import org.openscience.cdk.io.formats.JMEFormat;
import org.openscience.cdk.io.setting.IOSetting;
Expand Down
109 changes: 107 additions & 2 deletions src/org/openscience/cdk/isomorphism/UniversalIsomorphismTester.java
Expand Up @@ -117,7 +117,8 @@ public class UniversalIsomorphismTester {
* @return true if the 2 molecule are isomorph
*/
public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2) throws CDKException{
return (getIsomorphMap(g1, g2) != null);
if (g2.getAtomCount() != g1.getAtomCount()) return false;
return (getIsomorphMap(g1, g2) != null);
}


Expand Down Expand Up @@ -237,7 +238,9 @@ public static List getSubgraphAtomsMap(IAtomContainer g1, IAtomContainer g2) th
* @return true if g2 a subgraph on g1
*/
public static boolean isSubgraph(IAtomContainer g1, IAtomContainer g2) throws CDKException{
return (getSubgraphMap(g1, g2) != null);
if (g2.getAtomCount() > g1.getAtomCount()) return false;
if (!testSubgraphHeuristics(g1, g2)) return false;
return (getSubgraphMap(g1, g2) != null);
}


Expand Down Expand Up @@ -785,5 +788,107 @@ private static boolean queryAdjacency(IBond a1, IBond b1, IBond a2, IBond b2) {

}

/**
* Checks some simple heuristics for whether the subgraph query can
* realistically be a subgraph of the supergraph. If, for example, the
* number of nitrogen atoms in the query is larger than that of the supergraph
* it cannot be part of it.
*
* @param ac1 the supergraph to be checked
* @param ac2 the subgraph to be tested for
* @return true if the subgraph ac2 has a chance to be a subgraph of ac1
*
*/

private static boolean testSubgraphHeuristics(IAtomContainer ac1, IAtomContainer ac2)
{
int ac1SingleBondCount = 0;
int ac1DoubleBondCount = 0;
int ac1TripleBondCount = 0;
int ac1AromaticBondCount = 0;
int ac2SingleBondCount = 0;
int ac2DoubleBondCount = 0;
int ac2TripleBondCount = 0;
int ac2AromaticBondCount = 0;
int ac1SCount = 0;
int ac1OCount = 0;
int ac1NCount = 0;
int ac1FCount = 0;
int ac1ClCount = 0;
int ac1BrCount = 0;
int ac1ICount = 0;
int ac1CCount = 0;

int ac2SCount = 0;
int ac2OCount = 0;
int ac2NCount = 0;
int ac2FCount = 0;
int ac2ClCount = 0;
int ac2BrCount = 0;
int ac2ICount = 0;
int ac2CCount = 0;

IBond bond = null;
IAtom atom = null;
for (int i = 0; i < ac1.getBondCount(); i++)
{
bond = ac1.getBondAt(i);
if (bond.getFlag(CDKConstants.ISAROMATIC)) ac1AromaticBondCount ++;
else if (bond.getOrder() == 1) ac1SingleBondCount ++;
else if (bond.getOrder() == 2) ac1DoubleBondCount ++;
else if (bond.getOrder() == 3) ac1TripleBondCount ++;
}
for (int i = 0; i < ac2.getBondCount(); i++)
{
bond = ac2.getBondAt(i);
if (bond.getFlag(CDKConstants.ISAROMATIC)) ac2AromaticBondCount ++;
else if (bond.getOrder() == 1) ac2SingleBondCount ++;
else if (bond.getOrder() == 2) ac2DoubleBondCount ++;
else if (bond.getOrder() == 3) ac2TripleBondCount ++;
}

if (ac2SingleBondCount > ac1SingleBondCount) return false;
if (ac2AromaticBondCount > ac1AromaticBondCount) return false;
if (ac2DoubleBondCount > ac1DoubleBondCount) return false;
if (ac2TripleBondCount > ac1TripleBondCount) return false;

for (int i = 0; i < ac1.getAtomCount(); i++)
{
atom = ac1.getAtomAt(i);
if (atom.getSymbol().equals("S")) ac1SCount ++;
else if (atom.getSymbol().equals("N")) ac1NCount ++;
else if (atom.getSymbol().equals("O")) ac1OCount ++;
else if (atom.getSymbol().equals("F")) ac1FCount ++;
else if (atom.getSymbol().equals("Cl")) ac1ClCount ++;
else if (atom.getSymbol().equals("Br")) ac1BrCount ++;
else if (atom.getSymbol().equals("I")) ac1ICount ++;
else if (atom.getSymbol().equals("C")) ac1CCount ++;
}
for (int i = 0; i < ac2.getAtomCount(); i++)
{
atom = ac2.getAtomAt(i);
if (atom.getSymbol().equals("S")) ac2SCount ++;
else if (atom.getSymbol().equals("N")) ac2NCount ++;
else if (atom.getSymbol().equals("O")) ac2OCount ++;
else if (atom.getSymbol().equals("F")) ac2FCount ++;
else if (atom.getSymbol().equals("Cl")) ac2ClCount ++;
else if (atom.getSymbol().equals("Br")) ac2BrCount ++;
else if (atom.getSymbol().equals("I")) ac2ICount ++;
else if (atom.getSymbol().equals("C")) ac2CCount ++;
}

if (ac1SCount < ac2SCount) return false;
if (ac1NCount < ac2NCount) return false;
if (ac1OCount < ac2OCount) return false;
if (ac1FCount < ac2FCount) return false;
if (ac1ClCount < ac2ClCount) return false;
if (ac1BrCount < ac2BrCount) return false;
if (ac1ICount < ac2ICount) return false;
if (ac1CCount < ac2CCount) return false;


return true;
}

}

6 changes: 4 additions & 2 deletions src/org/openscience/cdk/ringsearch/AllRingsFinder.java
Expand Up @@ -32,13 +32,14 @@
import java.util.Enumeration;
import java.util.Vector;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.graph.SpanningTree;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IRing;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.graph.SpanningTree;

/**
* Finds the Set of all Rings. This is an implementation of the algorithm
Expand Down Expand Up @@ -141,6 +142,7 @@ public IRingSet findAllRings(IAtomContainer atomContainer, boolean useSSSR) thro
{
doSearch(ac, pathes, ringSet);
}
atomContainer.setProperty(CDKConstants.ALL_RINGS, ringSet);
return ringSet;
}

Expand Down
4 changes: 3 additions & 1 deletion src/org/openscience/cdk/ringsearch/FiguerasSSSRFinder.java
Expand Up @@ -31,10 +31,11 @@
import java.util.Vector;

import org.openscience.cdk.Atom;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.Ring;
import org.openscience.cdk.RingSet;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.tools.LoggingTool;

/**
Expand Down Expand Up @@ -189,6 +190,7 @@ else if (smallestDegree == 3)
logger.debug("fullSet.size(): " + fullSet.size());
logger.debug("trimSet.size(): " + trimSet.size());
logger.debug("trimCounter: " + trimCounter);
molecule.setProperty(CDKConstants.SMALLEST_RINGS, sssr);
return sssr;
}

Expand Down
11 changes: 9 additions & 2 deletions src/org/openscience/cdk/ringsearch/SSSRFinder.java
Expand Up @@ -34,11 +34,12 @@
import java.util.List;

import org._3pq.jgrapht.UndirectedGraph;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.graph.MoleculeGraphs;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IRing;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.graph.MoleculeGraphs;
import org.openscience.cdk.ringsearch.cyclebasis.CycleBasis;
import org.openscience.cdk.ringsearch.cyclebasis.SimpleCycle;

Expand Down Expand Up @@ -94,7 +95,8 @@ public IRingSet findSSSR() {
if (atomContainer==null) {
return null;
}

IRingSet ringSet = toRingSet(atomContainer, cycleBasis().cycles());
atomContainer.setProperty(CDKConstants.SMALLEST_RINGS, ringSet);
return toRingSet(atomContainer, cycleBasis().cycles());

}
Expand All @@ -110,6 +112,8 @@ public IRingSet findEssentialRings() {
if (atomContainer==null) {
return null;
}
IRingSet ringSet = toRingSet(atomContainer, cycleBasis().cycles());
atomContainer.setProperty(CDKConstants.ESSENTIAL_RINGS, ringSet);

return toRingSet(atomContainer, cycleBasis().essentialCycles());

Expand All @@ -127,6 +131,9 @@ public IRingSet findRelevantRings() {
return null;
}

IRingSet ringSet = toRingSet(atomContainer, cycleBasis().cycles());
atomContainer.setProperty(CDKConstants.RELEVANT_RINGS, ringSet);

return toRingSet(atomContainer, cycleBasis().relevantCycles().keySet());

}
Expand Down
Expand Up @@ -66,7 +66,7 @@ public class SingleStructureRandomGenerator
{
AtomContainer atomContainer;
SaturationChecker satCheck;
final static boolean debug = false;
final static boolean debug = true;
Random random = null;

/**
Expand Down Expand Up @@ -125,15 +125,18 @@ public Molecule generate() throws CDKException
if (partner != null)
{
cmax1 = satCheck.getCurrentMaxBondOrder(atom, atomContainer);

cmax2 = satCheck.getCurrentMaxBondOrder(partner, atomContainer);
max = Math.min(cmax1, cmax2);
order = Math.min(Math.max(1.0, random.nextInt((int)Math.round(max))), 3.0);
if (debug) System.out.println("Forming bond of order " + order);
atomContainer.addBond(new Bond(atom, partner, order));
bondFormed = true;
}
}
}
} while (bondFormed);
//System.out.println("Blaeh");
if (ConnectivityChecker.isConnected(atomContainer) && satCheck.allSaturated(atomContainer))
{
structureFound = true;
Expand Down
48 changes: 48 additions & 0 deletions src/org/openscience/cdk/templates/MoleculeFactory.java
Expand Up @@ -458,6 +458,54 @@ public static Molecule makeEthylPropylPhenantren()
return mol;
}

public static Molecule makeSteran()
{
Molecule mol = new Molecule();
mol.addAtom(new Atom("C")); // 0
mol.addAtom(new Atom("C")); // 1
mol.addAtom(new Atom("C")); // 2
mol.addAtom(new Atom("C")); // 3
mol.addAtom(new Atom("C")); // 4
mol.addAtom(new Atom("C")); // 5
mol.addAtom(new Atom("C")); // 6
mol.addAtom(new Atom("C")); // 7
mol.addAtom(new Atom("C")); // 8
mol.addAtom(new Atom("C")); // 9
mol.addAtom(new Atom("C")); // 10
mol.addAtom(new Atom("C")); // 11
mol.addAtom(new Atom("C")); // 12
mol.addAtom(new Atom("C")); // 13
mol.addAtom(new Atom("C")); // 14
mol.addAtom(new Atom("C")); // 15
mol.addAtom(new Atom("C")); // 16


mol.addBond(0, 1, 1.0); // 1
mol.addBond(1, 2,1.0); // 2
mol.addBond(2, 3, 1.0); // 3
mol.addBond(3, 4,1.0); // 4
mol.addBond(4, 5, 1.0); // 5
mol.addBond(5, 6,1.0); // 6
mol.addBond(6, 7, 1.0); // 8
mol.addBond(7, 8,1.0); // 9
mol.addBond(8, 9, 1.0); // 10
mol.addBond(9, 0,1.0); // 11
mol.addBond(9, 4, 1.0); // 12
mol.addBond(8, 10, 1.0); // 13
mol.addBond(10, 11,1.0); // 14
mol.addBond(11, 12, 1.0); // 15
mol.addBond(12, 13,1.0); // 16
mol.addBond(13, 7, 1.0); // 17
mol.addBond(13, 14, 1.0); // 18
mol.addBond(14, 15, 1.0); // 19
mol.addBond(15, 16, 1.0); // 20
mol.addBond(16, 12, 1.0); // 21

configureAtoms(mol);
return mol;
}


public static Molecule makeAzulene()
{
Molecule mol = new Molecule();
Expand Down

0 comments on commit ec3ced2

Please sign in to comment.