Skip to content

Commit

Permalink
Updated IReactionMechanism to use IAtomContainerSet. Also fixed some …
Browse files Browse the repository at this point in the history
…castings.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
rajarshi authored and egonw committed Dec 10, 2011
1 parent c9847d2 commit 738eece
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 150 deletions.
11 changes: 6 additions & 5 deletions src/main/org/openscience/cdk/reaction/IReactionMechanism.java
Expand Up @@ -24,14 +24,14 @@
*/
package org.openscience.cdk.reaction;

import java.util.ArrayList;

import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;

import java.util.ArrayList;

/**
* Classes that implement this interface are reaction mechanisms.
*
Expand All @@ -45,14 +45,15 @@ public interface IReactionMechanism {
* Initiates the process for the given mechanism. The atoms to apply are mapped between
* reactants and products.
*
* @param moleculeSet The IMoleculeSet to apply the mechanism
*
* @param atomContainerSet
* @param atomList The list of atoms taking part in the mechanism
* @param bondList The list of bonds taking part in the mechanism
* @return The Reaction mechanism
*
* @throws CDKException if an error occurs during the reaction process.
* See documentation for individual reaction processes
*/
public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList, ArrayList<IBond> bondList) throws CDKException;
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList, ArrayList<IBond> bondList) throws CDKException;

}
Expand Up @@ -20,26 +20,25 @@
*/
package org.openscience.cdk.reaction.mechanism;

import java.util.ArrayList;
import java.util.List;

import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.atomtype.CDKAtomTypeMatcher;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.interfaces.IAtomType;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.ILonePair;
import org.openscience.cdk.interfaces.IMapping;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.reaction.IReactionMechanism;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;

import java.util.ArrayList;
import java.util.List;

/**
* <p>This mechanism adduct together two fragments. The second fragment will be deficient in charge.
* It returns the reaction mechanism which has been cloned the IMolecule.</p>
Expand All @@ -58,17 +57,18 @@ public class AdductionLPMechanism implements IReactionMechanism{
* Initiates the process for the given mechanism. The atoms and bonds to apply are mapped between
* reactants and products.
*
* @param moleculeSet The IMolecule to apply the mechanism
*
* @param atomContainerSet
* @param atomList The list of atoms taking part in the mechanism. Only allowed two atoms.
* @param bondList The list of bonds taking part in the mechanism. not allowed bonds.
*
*
* @return The Reaction mechanism
*
*/
@TestMethod(value="testInitiate_IMoleculeSet_ArrayList_ArrayList")
public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,ArrayList<IBond> bondList) throws CDKException {
CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(moleculeSet.getBuilder());
if (moleculeSet.getAtomContainerCount() != 2) {
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList,ArrayList<IBond> bondList) throws CDKException {
CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder());
if (atomContainerSet.getAtomContainerCount() != 2) {
throw new CDKException("AdductionLPMechanism expects two IMolecule's");
}
if (atomList.size() != 2) {
Expand All @@ -77,13 +77,13 @@ public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,Ar
if (bondList != null) {
throw new CDKException("AdductionLPMechanism don't expect bonds in the ArrayList");
}
IMolecule molecule1 = moleculeSet.getMolecule(0);
IMolecule molecule2 = moleculeSet.getMolecule(1);
IAtomContainer molecule1 = atomContainerSet.getAtomContainer(0);
IAtomContainer molecule2 = atomContainerSet.getAtomContainer(1);

IMolecule reactantCloned;
IAtomContainer reactantCloned;
try {
reactantCloned = (IMolecule) moleculeSet.getMolecule(0).clone();
reactantCloned.add((IAtomContainer) moleculeSet.getMolecule(1).clone());
reactantCloned = (IAtomContainer) atomContainerSet.getAtomContainer(0).clone();
reactantCloned.add((IAtomContainer) atomContainerSet.getAtomContainer(1).clone());
} catch (CloneNotSupportedException e) {
throw new CDKException("Could not clone IMolecule!", e);
}
Expand Down
Expand Up @@ -20,25 +20,24 @@
*/
package org.openscience.cdk.reaction.mechanism;

import java.util.ArrayList;

import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.atomtype.CDKAtomTypeMatcher;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.interfaces.IAtomType;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IMapping;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.reaction.IReactionMechanism;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.tools.manipulator.BondManipulator;

import java.util.ArrayList;

/**
* <p>This mechanism adduct together two fragments due to a double bond.
* The second fragment will be deficient in charge.
Expand All @@ -58,17 +57,18 @@ public class AdductionPBMechanism implements IReactionMechanism{
* Initiates the process for the given mechanism. The atoms and bonds to apply are mapped between
* reactants and products.
*
* @param moleculeSet The IMolecule to apply the mechanism
*
* @param atomContainerSet
* @param atomList The list of atoms taking part in the mechanism. Only allowed three atoms
* @param bondList The list of bonds taking part in the mechanism. Only allowed one bond
*
*
* @return The Reaction mechanism
*
*/
@TestMethod(value="testInitiate_IMoleculeSet_ArrayList_ArrayList")
public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,ArrayList<IBond> bondList) throws CDKException {
CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(moleculeSet.getBuilder());
if (moleculeSet.getAtomContainerCount() != 2) {
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList,ArrayList<IBond> bondList) throws CDKException {
CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder());
if (atomContainerSet.getAtomContainerCount() != 2) {
throw new CDKException("AdductionPBMechanism expects two IMolecule's");
}
if (atomList.size() != 3) {
Expand All @@ -77,13 +77,13 @@ public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,Ar
if (bondList.size() != 1) {
throw new CDKException("AdductionPBMechanism don't expect bonds in the ArrayList");
}
IMolecule molecule1 = moleculeSet.getMolecule(0);
IMolecule molecule2 = moleculeSet.getMolecule(1);
IAtomContainer molecule1 = atomContainerSet.getAtomContainer(0);
IAtomContainer molecule2 = atomContainerSet.getAtomContainer(1);

IMolecule reactantCloned;
IAtomContainer reactantCloned;
try {
reactantCloned = (IMolecule) moleculeSet.getMolecule(0).clone();
reactantCloned.add((IAtomContainer) moleculeSet.getMolecule(1).clone());
reactantCloned = (IAtomContainer) atomContainerSet.getAtomContainer(0).clone();
reactantCloned.add((IAtomContainer) atomContainerSet.getAtomContainer(1).clone());
} catch (CloneNotSupportedException e) {
throw new CDKException("Could not clone IMolecule!", e);
}
Expand All @@ -94,7 +94,7 @@ public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,Ar
IAtom atom3 = atomList.get(2);// Atom 2: deficient in charge
IAtom atom3C = reactantCloned.getAtom(molecule1.getAtomCount() + molecule2.getAtomNumber(atom3));
IBond bond1 = bondList.get(0);
int posBond1 = moleculeSet.getMolecule(0).getBondNumber(bond1);
int posBond1 = atomContainerSet.getAtomContainer(0).getBondNumber(bond1);

BondManipulator.decreaseBondOrder(reactantCloned.getBond(posBond1));
IBond newBond = molecule1.getBuilder().newInstance(IBond.class,atom2C, atom3C, IBond.Order.SINGLE);
Expand Down
Expand Up @@ -20,8 +20,6 @@
*/
package org.openscience.cdk.reaction.mechanism;

import java.util.ArrayList;

import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.LonePair;
import org.openscience.cdk.annotations.TestClass;
Expand All @@ -35,13 +33,13 @@
import org.openscience.cdk.interfaces.IAtomType;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IMapping;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.reaction.IReactionMechanism;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.tools.manipulator.BondManipulator;

import java.util.ArrayList;

/**
* This mechanism displaces the chemical bond to an Atom. Generating one with
* excess charge and the other with deficiency.
Expand All @@ -59,18 +57,19 @@ public class HeterolyticCleavageMechanism implements IReactionMechanism{
* Initiates the process for the given mechanism. The atoms to apply are mapped between
* reactants and products.
*
* @param moleculeSet The IMolecule to apply the mechanism
*
* @param atomContainerSet
* @param atomList The list of atoms taking part in the mechanism. Only allowed two atoms.
* The first atom receives the positive charge charge and the second
* The first atom receives the positive charge charge and the second
* negative charge
* @param bondList The list of bonds taking part in the mechanism. Only allowed one bond
* @return The Reaction mechanism
*
*/
@TestMethod(value="testInitiate_IMoleculeSet_ArrayList_ArrayList")
public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,ArrayList<IBond> bondList) throws CDKException {
CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(moleculeSet.getBuilder(), CDKAtomTypeMatcher.REQUIRE_EXPLICIT_HYDROGENS);
if (moleculeSet.getAtomContainerCount() != 1) {
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList,ArrayList<IBond> bondList) throws CDKException {
CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder(), CDKAtomTypeMatcher.REQUIRE_EXPLICIT_HYDROGENS);
if (atomContainerSet.getAtomContainerCount() != 1) {
throw new CDKException("TautomerizationMechanism only expects one IMolecule");
}
if (atomList.size() != 2) {
Expand All @@ -79,10 +78,10 @@ public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,Ar
if (bondList.size() != 1) {
throw new CDKException("HeterolyticCleavageMechanism only expect one bond in the ArrayList");
}
IMolecule molecule = moleculeSet.getMolecule(0);
IMolecule reactantCloned;
IAtomContainer molecule = atomContainerSet.getAtomContainer(0);
IAtomContainer reactantCloned;
try {
reactantCloned = (IMolecule) molecule.clone();
reactantCloned = (IAtomContainer) molecule.clone();
} catch (CloneNotSupportedException e) {
throw new CDKException("Could not clone IMolecule!", e);
}
Expand Down
Expand Up @@ -20,8 +20,6 @@
*/
package org.openscience.cdk.reaction.mechanism;

import java.util.ArrayList;

import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.SingleElectron;
import org.openscience.cdk.annotations.TestClass;
Expand All @@ -35,13 +33,13 @@
import org.openscience.cdk.interfaces.IAtomType;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IMapping;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.reaction.IReactionMechanism;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.tools.manipulator.BondManipulator;

import java.util.ArrayList;

/**
* This mechanism breaks the chemical bond between atoms. Generating two atoms with
* attached radicals.
Expand All @@ -59,17 +57,18 @@ public class HomolyticCleavageMechanism implements IReactionMechanism{
* Initiates the process for the given mechanism. The atoms to apply are mapped between
* reactants and products.
*
* @param moleculeSet The IMolecule to apply the mechanism
*
* @param atomContainerSet
* @param atomList The list of atoms taking part in the mechanism. Only allowed two atoms.
* Both atoms acquire a ISingleElectron
* @param bondList The list of bonds taking part in the mechanism. Only allowed one bond
* @return The Reaction mechanism
*
*/
@TestMethod(value="testInitiate_IMoleculeSet_ArrayList_ArrayList")
public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,ArrayList<IBond> bondList) throws CDKException {
CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(moleculeSet.getBuilder());
if (moleculeSet.getAtomContainerCount() != 1) {
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList,ArrayList<IBond> bondList) throws CDKException {
CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder());
if (atomContainerSet.getAtomContainerCount() != 1) {
throw new CDKException("TautomerizationMechanism only expects one IMolecule");
}
if (atomList.size() != 2) {
Expand All @@ -78,10 +77,10 @@ public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,Ar
if (bondList.size() != 1) {
throw new CDKException("HomolyticCleavageMechanism only expect one bond in the ArrayList");
}
IMolecule molecule = moleculeSet.getMolecule(0);
IMolecule reactantCloned;
IAtomContainer molecule = atomContainerSet.getAtomContainer(0);
IAtomContainer reactantCloned;
try {
reactantCloned = (IMolecule) molecule.clone();
reactantCloned = (IAtomContainer) molecule.clone();
} catch (CloneNotSupportedException e) {
throw new CDKException("Could not clone IMolecule!", e);
}
Expand Down
Expand Up @@ -20,9 +20,6 @@
*/
package org.openscience.cdk.reaction.mechanism;

import java.util.ArrayList;
import java.util.List;

import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.SingleElectron;
import org.openscience.cdk.annotations.TestClass;
Expand All @@ -36,14 +33,15 @@
import org.openscience.cdk.interfaces.IAtomType;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IMapping;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.interfaces.ISingleElectron;
import org.openscience.cdk.reaction.IReactionMechanism;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.tools.manipulator.BondManipulator;

import java.util.ArrayList;
import java.util.List;

/**
* <p>This mechanism extracts an atom because of the stabilization of a radical.
* It returns the reaction mechanism which has been cloned the IMolecule.</p>
Expand All @@ -61,20 +59,21 @@ public class RadicalSiteIonizationMechanism implements IReactionMechanism{
* Initiates the process for the given mechanism. The atoms to apply are mapped between
* reactants and products.
*
* @param moleculeSet The IMolecule to apply the mechanism
*
* @param atomContainerSet
* @param atomList The list of atoms taking part in the mechanism. Only allowed two atoms.
* The first atom is the atom which contains the ISingleElectron and the second
* third is the atom which will be removed
* The first atom is the atom which contains the ISingleElectron and the second
* third is the atom which will be removed
* the first atom
* @param bondList The list of bonds taking part in the mechanism. Only allowed one bond.
* It is the bond which is moved
* @return The Reaction mechanism
*
*/
@TestMethod(value="testInitiate_IMoleculeSet_ArrayList_ArrayList")
public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,ArrayList<IBond> bondList) throws CDKException {
CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(moleculeSet.getBuilder());
if (moleculeSet.getAtomContainerCount() != 1) {
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList,ArrayList<IBond> bondList) throws CDKException {
CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder());
if (atomContainerSet.getAtomContainerCount() != 1) {
throw new CDKException("RadicalSiteIonizationMechanism only expects one IMolecule");
}
if (atomList.size() != 3) {
Expand All @@ -83,10 +82,10 @@ public IReaction initiate(IMoleculeSet moleculeSet, ArrayList<IAtom> atomList,Ar
if (bondList.size() != 2) {
throw new CDKException("RadicalSiteIonizationMechanism only expect one bond in the ArrayList");
}
IMolecule molecule = moleculeSet.getMolecule(0);
IMolecule reactantCloned;
IAtomContainer molecule = atomContainerSet.getAtomContainer(0);
IAtomContainer reactantCloned;
try {
reactantCloned = (IMolecule) molecule.clone();
reactantCloned = (IAtomContainer) molecule.clone();
} catch (CloneNotSupportedException e) {
throw new CDKException("Could not clone IMolecule!", e);
}
Expand Down

0 comments on commit 738eece

Please sign in to comment.