Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use interfaces instead of implementations
Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Nov 7, 2011
1 parent 76dcdf7 commit 434c9b1
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 82 deletions.
Expand Up @@ -29,7 +29,6 @@
import java.util.Iterator;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
Expand Down Expand Up @@ -134,7 +133,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
throw new CDKException("HeterolyticCleavagePBReaction don't expects agents");
}

IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
IMolecule reactant = reactants.getMolecule(0);

/* if the parameter hasActiveCenter is not fixed yet, set the active centers*/
Expand Down
Expand Up @@ -28,8 +28,6 @@
import java.util.Iterator;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
Expand Down Expand Up @@ -131,7 +129,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
throw new CDKException("PiBondingMovementReaction don't expects agents");
}

IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
IMolecule reactant = reactants.getMolecule(0);

AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
Expand All @@ -145,7 +143,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
// }

AllRingsFinder arf = new AllRingsFinder();
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
IRing ring = (IRing) ringSet.getAtomContainer(ir);

Expand Down Expand Up @@ -174,7 +172,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
continue;


IReaction reaction = DefaultChemObjectBuilder.getInstance().newInstance(IReaction.class);
IReaction reaction = reactants.getBuilder().newInstance(IReaction.class);
reaction.addReactant(reactant);

IMolecule reactantCloned;
Expand Down Expand Up @@ -216,7 +214,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
*/
private void setActiveCenters(IMolecule reactant) throws CDKException {
AllRingsFinder arf = new AllRingsFinder();
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
IRing ring = (IRing) ringSet.getAtomContainer(ir);
//only rings with even number of atoms
Expand Down
Expand Up @@ -28,7 +28,6 @@
import java.util.Iterator;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
Expand Down Expand Up @@ -124,7 +123,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
throw new CDKException("RadicalChargeSiteInitiationReaction don't expects agents");
}

IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
IMolecule reactant = reactants.getMolecule(0);

/* if the parameter hasActiveCenter is not fixed yet, set the active centers*/
Expand Down
Expand Up @@ -29,9 +29,6 @@
import java.util.Iterator;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.Ring;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
Expand All @@ -42,6 +39,7 @@
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.interfaces.IReactionSet;
import org.openscience.cdk.interfaces.IRing;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.reaction.IReactionProcess;
import org.openscience.cdk.reaction.ReactionEngine;
Expand Down Expand Up @@ -133,15 +131,15 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
throw new CDKException("RadicalSiteHrAlphaReaction don't expects agents");
}

IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
IMolecule reactant = reactants.getMolecule(0);

AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
AllRingsFinder arf = new AllRingsFinder();
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
Ring ring = (Ring)ringSet.getAtomContainer(ir);
IRing ring = (IRing)ringSet.getAtomContainer(ir);
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
IAtom aring = ring.getAtom(jr);
aring.setFlag(CDKConstants.ISINRING, true);
Expand All @@ -159,7 +157,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER)
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {

hcg.getSpheres((Molecule) reactant, atomi, 2, true);
hcg.getSpheres((IMolecule) reactant, atomi, 2, true);
Iterator<IAtom> atomls = hcg.getNodesInSphere(2).iterator();
while(atomls.hasNext()){
IAtom atoml = atomls.next();
Expand Down Expand Up @@ -216,7 +214,7 @@ private void setActiveCenters(IMolecule reactant) throws CDKException {
IAtom atomi = atomis.next();
if(reactant.getConnectedSingleElectronsCount(atomi) == 1) {

hcg.getSpheres((Molecule) reactant, atomi, 2, true);
hcg.getSpheres((IMolecule) reactant, atomi, 2, true);
Iterator<IAtom> atomls = hcg.getNodesInSphere(2).iterator();
while(atomls.hasNext()){
IAtom atoml = atomls.next();
Expand Down
Expand Up @@ -29,9 +29,6 @@
import java.util.Iterator;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.Ring;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
Expand All @@ -42,6 +39,7 @@
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.interfaces.IReactionSet;
import org.openscience.cdk.interfaces.IRing;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.reaction.IReactionProcess;
import org.openscience.cdk.reaction.ReactionEngine;
Expand Down Expand Up @@ -134,15 +132,15 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
throw new CDKException("RadicalSiteHrBetaReaction don't expects agents");
}

IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
IMolecule reactant = reactants.getMolecule(0);

AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
AllRingsFinder arf = new AllRingsFinder();
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
Ring ring = (Ring)ringSet.getAtomContainer(ir);
IRing ring = (IRing)ringSet.getAtomContainer(ir);
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
IAtom aring = ring.getAtom(jr);
aring.setFlag(CDKConstants.ISINRING, true);
Expand All @@ -160,7 +158,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER)
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {

hcg.getSpheres((Molecule) reactant, atomi, 3, true);
hcg.getSpheres((IMolecule) reactant, atomi, 3, true);
Iterator<IAtom> atomls = hcg.getNodesInSphere(3).iterator();
while(atomls.hasNext()){
IAtom atoml = atomls.next();
Expand Down Expand Up @@ -217,7 +215,7 @@ private void setActiveCenters(IMolecule reactant) throws CDKException {
IAtom atomi = atomis.next();
if(reactant.getConnectedSingleElectronsCount(atomi) == 1) {

hcg.getSpheres((Molecule) reactant, atomi, 3, true);
hcg.getSpheres((IMolecule) reactant, atomi, 3, true);
Iterator<IAtom> atomls = hcg.getNodesInSphere(3).iterator();
while(atomls.hasNext()){
IAtom atoml = atomls.next();
Expand Down
Expand Up @@ -29,9 +29,6 @@
import java.util.Iterator;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.Ring;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
Expand All @@ -42,6 +39,7 @@
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.interfaces.IReactionSet;
import org.openscience.cdk.interfaces.IRing;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.reaction.IReactionProcess;
import org.openscience.cdk.reaction.ReactionEngine;
Expand Down Expand Up @@ -135,15 +133,15 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
throw new CDKException("RadicalSiteHrDeltaReaction don't expects agents");
}

IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
IMolecule reactant = reactants.getMolecule(0);

AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
AllRingsFinder arf = new AllRingsFinder();
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
Ring ring = (Ring)ringSet.getAtomContainer(ir);
IRing ring = (IRing)ringSet.getAtomContainer(ir);
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
IAtom aring = ring.getAtom(jr);
aring.setFlag(CDKConstants.ISINRING, true);
Expand All @@ -161,7 +159,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER)
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {

hcg.getSpheres((Molecule) reactant, atomi, 5, true);
hcg.getSpheres((IMolecule) reactant, atomi, 5, true);
Iterator<IAtom> atomls = hcg.getNodesInSphere(5).iterator();
while(atomls.hasNext()){
IAtom atoml = atomls.next();
Expand Down Expand Up @@ -218,7 +216,7 @@ private void setActiveCenters(IMolecule reactant) throws CDKException {
IAtom atomi = atomis.next();
if(reactant.getConnectedSingleElectronsCount(atomi) == 1) {

hcg.getSpheres((Molecule) reactant, atomi, 5, true);
hcg.getSpheres((IMolecule) reactant, atomi, 5, true);
Iterator<IAtom> atomls = hcg.getNodesInSphere(5).iterator();
while(atomls.hasNext()){
IAtom atoml = atomls.next();
Expand Down
Expand Up @@ -29,9 +29,6 @@
import java.util.Iterator;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.Ring;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
Expand All @@ -42,6 +39,7 @@
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.interfaces.IReactionSet;
import org.openscience.cdk.interfaces.IRing;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.reaction.IReactionProcess;
import org.openscience.cdk.reaction.ReactionEngine;
Expand Down Expand Up @@ -134,15 +132,15 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
throw new CDKException("RadicalSiteHrGammaReaction don't expects agents");
}

IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
IMolecule reactant = reactants.getMolecule(0);

AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
AllRingsFinder arf = new AllRingsFinder();
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
Ring ring = (Ring)ringSet.getAtomContainer(ir);
IRing ring = (IRing)ringSet.getAtomContainer(ir);
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
IAtom aring = ring.getAtom(jr);
aring.setFlag(CDKConstants.ISINRING, true);
Expand All @@ -160,7 +158,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER) && atomi.getSymbol().equals("C")
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {

hcg.getSpheres((Molecule) reactant, atomi, 4, true);
hcg.getSpheres((IMolecule) reactant, atomi, 4, true);
Iterator<IAtom> atomls = hcg.getNodesInSphere(4).iterator();
while(atomls.hasNext()){
IAtom atoml = atomls.next();
Expand Down Expand Up @@ -218,7 +216,7 @@ private void setActiveCenters(IMolecule reactant) throws CDKException {
if(atomi.getSymbol().equals("C")
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {

hcg.getSpheres((Molecule) reactant, atomi, 4, true);
hcg.getSpheres((IMolecule) reactant, atomi, 4, true);
Iterator<IAtom> atomls = hcg.getNodesInSphere(4).iterator();
while(atomls.hasNext()){
IAtom atoml = atomls.next();
Expand Down
Expand Up @@ -30,9 +30,6 @@
import java.util.List;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.Ring;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
Expand All @@ -43,6 +40,7 @@
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.interfaces.IReactionSet;
import org.openscience.cdk.interfaces.IRing;
import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.reaction.IReactionProcess;
import org.openscience.cdk.reaction.ReactionEngine;
Expand Down Expand Up @@ -135,15 +133,15 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
throw new CDKException("RadicalSiteRrAlphaReaction don't expects agents");
}

IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
IMolecule reactant = reactants.getMolecule(0);

AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
AllRingsFinder arf = new AllRingsFinder();
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
Ring ring = (Ring)ringSet.getAtomContainer(ir);
IRing ring = (IRing)ringSet.getAtomContainer(ir);
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
IAtom aring = ring.getAtom(jr);
aring.setFlag(CDKConstants.ISINRING, true);
Expand All @@ -161,10 +159,10 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER)
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {

hcg.getSpheres((Molecule) reactant, atomi, 1, true);
hcg.getSpheres((IMolecule) reactant, atomi, 1, true);
List<IAtom> atom1s = hcg.getNodesInSphere(1);

hcg.getSpheres((Molecule) reactant, atomi, 2, true);
hcg.getSpheres((IMolecule) reactant, atomi, 2, true);
Iterator<IAtom> atomls = hcg.getNodesInSphere(2).iterator();
while(atomls.hasNext()){
IAtom atoml = atomls.next();
Expand Down Expand Up @@ -224,10 +222,10 @@ private void setActiveCenters(IMolecule reactant) throws CDKException {
IAtom atomi = atomis.next();
if(reactant.getConnectedSingleElectronsCount(atomi) == 1) {

hcg.getSpheres((Molecule) reactant, atomi, 1, true);
hcg.getSpheres((IMolecule) reactant, atomi, 1, true);
List<IAtom> atom1s = hcg.getNodesInSphere(1);

hcg.getSpheres((Molecule) reactant, atomi, 2, true);
hcg.getSpheres((IMolecule) reactant, atomi, 2, true);
Iterator<IAtom> atomls = hcg.getNodesInSphere(2).iterator();
while(atomls.hasNext()){
IAtom atoml = atomls.next();
Expand Down

0 comments on commit 434c9b1

Please sign in to comment.