Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new reaction type class which contains reaction processes

git-svn-id: https://cdk.svn.sourceforge.net/svnroot/cdk/trunk/cdk@5885 eb4e18e3-b210-0410-a6ab-dec725e4b171
  • Loading branch information...
commit 41766aea08f16ab2ba14b0731cc72631de8a7fec 1 parent 0446879
miguelrojasch authored
View
3  build.xml
@@ -603,6 +603,7 @@
<antcall target="compile-module"><param name="module" value="qsar-pdb"/></antcall>
<antcall target="compile-module"><param name="module" value="builder3d"/></antcall>
<antcall target="compile-module"><param name="module" value="applications"/></antcall>
+ <antcall target="compile-module"><param name="module" value="reaction"/></antcall>
</target>
<target id="test-dist-all" name="test-dist-all" description="test-dist-all">
@@ -631,6 +632,7 @@
<includesfile name="${metainf}/io-jmol.libdepends"/>
<includesfile name="${metainf}/libio-cml.libdepends"/>
<includesfile name="${metainf}/qsar.libdepends"/>
+ <includesfile name="${metainf}/reaction.libdepends"/>
<includesfile name="${metainf}/render.libdepends"/>
<includesfile name="${metainf}/standard.libdepends"/>
<includesfile name="${metainf}/swing.libdepends"/>
@@ -651,6 +653,7 @@
<include name="cdk-qsar-cml.jar"/>
<include name="cdk-pdb.jar"/>
<include name="cdk-pdb-cml.jar"/>
+ <include name="cdk-reaction.jar"/>
<include name="cdk-render.jar"/>
<include name="cdk-standard.jar"/>
<include name="cdk-swing.jar"/>
View
6 src/META-INF/reaction.cdkdepends
@@ -0,0 +1,6 @@
+cdk-interfaces.jar
+cdk-data.jar
+cdk-core.jar
+cdk-standard.jar
+cdk-extra.jar
+
View
2  src/META-INF/reaction.datafiles
@@ -0,0 +1,2 @@
+reaction-types.set
+
View
6 src/META-INF/reaction.libdepends
@@ -0,0 +1,6 @@
+Jama-1.0.1.jar
+jgrapht-0.5.3.jar
+sjava-0.68.jar
+vecmath1.2-1.14.jar
+xom-1.0.jar
+
View
8 src/org/openscience/cdk/CDKConstants.java
@@ -172,11 +172,15 @@
public final static int IS_HYDROGENBOND_DONOR = 6;
public final static int IS_HYDROGENBOND_ACCEPTOR = 7;
-
+
+ /** Flag is set if a chemobject has reactive center.
+ * It is used for example in reaction.
+ */
+ public static final int REACTIVE_CENTER = 8;
/**
* Maximum flags array index.
*/
- public final static int MAX_FLAG_INDEX = 7;
+ public final static int MAX_FLAG_INDEX = 8;
/**
* Flag used for JUnit testing the pointer functionality.
View
79 src/org/openscience/cdk/reaction/IReactionProcess.java
@@ -0,0 +1,79 @@
+package org.openscience.cdk.reaction;
+
+import org.openscience.cdk.exception.CDKException;
+import org.openscience.cdk.interfaces.ISetOfMolecules;
+import org.openscience.cdk.interfaces.ISetOfReactions;
+
+/**
+ * Classes that implement this interface are Reactions types.
+ *
+ * @cdk.module reaction
+ */
+public interface IReactionProcess {
+
+
+ /**
+ * Returns a <code>Map</code> which specifies which reaction
+ * is implemented by this class.
+ *
+ * These fields are used in the map:
+ * <ul>
+ * <li>Specification-Reference: refers to an entry in a unique dictionary or web page
+ * <li>Implementation-Title: anything
+ * <li>Implementation-Identifier: a unique identifier for this version of
+ * this class
+ * <li>Implementation-Vendor: CDK, JOELib, or anything else
+ * </ul>
+ *
+ * @return An object containing the reaction specification
+ */
+ public ReactionSpecification getSpecification();
+ /**
+ * Returns the names of the parameters for this reaction.
+ *
+ * @return An array of String containing the names of the paraneters
+ * that this reaction can accept
+ */
+ public String[] getParameterNames();
+ /**
+ * Returns a class matching that of the parameter with the given name.
+ *
+ * @param name The name of the parameter whose type is requested
+ * @return An Object of the class corresponding to the parameter with the supplied name
+ */
+ public Object getParameterType(String name);
+
+ /**
+ * Sets the parameters for this reaction.
+ *
+ * Must be done before calling
+ * calculate as the parameters influence the calculation outcome.
+ *
+ * @param params An array of Object containing the parameters for this reaction
+ * @throws CDKException if invalid number of type of parameters are passed to it
+ *
+ * @see #getParameters
+ */
+ public void setParameters(Object[] params) throws CDKException;
+
+ /**
+ * Returns the current parameter values.
+ *
+ * @return An array of Object containing the parameter values
+ * @see #setParameters
+ * */
+ public Object[] getParameters();
+ /**
+ * Initiates the process for the given Reaction.
+ *
+ * Optionally, parameters may be set which can affect the course of the process.
+ *
+ * @param reactants An {@link ISetOfMolecules} for which this process should be initiate.
+ * @param agents An {@link ISetOfMolecules} for which this process should be initiate.
+ *
+ * @throws CDKException if an error occurs during the reaction process.
+ * See documentation for individual reaction processes
+ */
+ public ISetOfReactions initiate(ISetOfMolecules reactants, ISetOfMolecules agents) throws CDKException;
+
+}
View
57 src/org/openscience/cdk/reaction/ReactionSpecification.java
@@ -0,0 +1,57 @@
+package org.openscience.cdk.reaction;
+
+/**
+ * Class that is used to distribute reactions specifications.
+ *
+ * @cdk.module reaction
+ */
+public class ReactionSpecification {
+
+ private String specificationReference;
+ private String implementationTitle;
+ private String implementationIdentifier;
+ private String implementationVendor;
+
+ /**
+ * Container for specifying the type of reaction.
+ *
+ * @param specificationReference Reference to a formal definition in a
+ * dictionary (e.g. in STMML format) of the descriptor, preferably
+ * refering to the original article. The format of the content is
+ * expected to be &lt;dictionaryNameSpace&gt;:&lt;entryID&gt;.
+ * @param implementationTitle Title for the reaction process.
+ * @param implementationIdentifier Unique identifier for the actual
+ * implementation, preferably including the exact version number of
+ * the source code. E.g. $Id: ReactionSpecification.java,v 1.8 2006/03/29 08:26:47 egonw Exp $ can be used when the source code is
+ * in a CVS repository.
+ * @param implementationVendor Name of the organisation/person/program/whatever
+ * who wrote/packaged the implementation.
+ */
+ public ReactionSpecification(
+ String specificationReference,
+ String implementationTitle,
+ String implementationIdentifier,
+ String implementationVendor) {
+ this.specificationReference = specificationReference;
+ this.implementationTitle = implementationTitle;
+ this.implementationIdentifier = implementationIdentifier;
+ this.implementationVendor = implementationVendor;
+ }
+
+ public String getSpecificationReference() {
+ return this.specificationReference;
+ };
+
+ public String getImplementationTitle() {
+ return this.implementationTitle;
+ };
+
+ public String getImplementationIdentifier() {
+ return this.implementationIdentifier;
+ };
+
+ public String getImplementationVendor() {
+ return this.implementationVendor;
+ };
+
+}
View
173 src/org/openscience/cdk/reaction/type/ElectronImpactNBEReaction.java
@@ -0,0 +1,173 @@
+package org.openscience.cdk.reaction.type;
+
+
+import org.openscience.cdk.CDKConstants;
+import org.openscience.cdk.DefaultChemObjectBuilder;
+import org.openscience.cdk.SingleElectron;
+import org.openscience.cdk.exception.CDKException;
+import org.openscience.cdk.interfaces.IAtom;
+import org.openscience.cdk.interfaces.ILonePair;
+import org.openscience.cdk.interfaces.IMolecule;
+import org.openscience.cdk.interfaces.IReaction;
+import org.openscience.cdk.interfaces.ISetOfMolecules;
+import org.openscience.cdk.interfaces.ISetOfReactions;
+import org.openscience.cdk.reaction.IReactionProcess;
+import org.openscience.cdk.reaction.ReactionSpecification;
+import org.openscience.cdk.tools.LoggingTool;
+
+/**
+ * IReactionProcess which make an alectron impact for for Non-Bondind Electron Lost
+ *
+ * @author Miguel Rojas
+ *
+ * @cdk.created 2006-04-01
+ * @cdk.module reaction
+ * @cdk.set reaction-types
+ *
+ **/
+public class ElectronImpactNBEReaction implements IReactionProcess{
+ private LoggingTool logger;
+ private boolean hasActiveCenter;
+
+ /**
+ * Constructor of the ElectronImpactNBEReaction object
+ *
+ */
+ public ElectronImpactNBEReaction(){
+ logger = new LoggingTool(this);
+ }
+ /**
+ * Gets the specification attribute of the ElectronImpactNBEReaction object
+ *
+ *@return The specification value
+ */
+ public ReactionSpecification getSpecification() {
+ return new ReactionSpecification(
+ "http://gold.zvon.org/E01999.html",
+ this.getClass().getName(),
+ "$Id: ElectronImpactNBEReaction.java,v 1.6 2006/04/01 08:26:47 mrc Exp $",
+ "The Chemistry Development Kit");
+ }
+
+ /**
+ * Sets the parameters attribute of the ElectronImpactNBEReaction object
+ *
+ *@param params The parameter is the the molecule has center acitve or not
+ *@exception CDKException Description of the Exception
+ */
+ public void setParameters(Object[] params) throws CDKException {
+ if (params.length > 1) {
+ throw new CDKException("ElectronImpactNBEReaction only expects one parameter");
+ }
+ if (!(params[0] instanceof Boolean)) {
+ throw new CDKException("The parameter must be of type boolean");
+ }
+ hasActiveCenter = ((Boolean) params[0]).booleanValue();
+ }
+
+
+ /**
+ * Gets the parameters attribute of the ElectronImpactNBEReaction object
+ *
+ *@return The parameters value
+ */
+ public Object[] getParameters() {
+ Object[] params = new Object[1];
+ params[0] = new Boolean (hasActiveCenter);
+ return params;
+ }
+
+ /**
+ * Initiate process.
+ *
+ *@param reactants reactants to initiate.
+ *@param agents agents to initiate.
+ *
+ *@exception CDKException Description of the Exception
+ */
+
+ public ISetOfReactions initiate(ISetOfMolecules reactants, ISetOfMolecules agents) throws CDKException{
+
+ logger.debug("initiate reaction: ElectronImpactNBEReaction");
+
+ if (reactants.getMoleculeCount() != 1) {
+ throw new CDKException("ElectronImpactNBEReaction only expects one reactant");
+ }
+ if (agents != null) {
+ throw new CDKException("ElectronImpactNBEReaction don't expects agents");
+ }
+
+ ISetOfReactions setOfReactions = DefaultChemObjectBuilder.getInstance().newSetOfReactions();
+
+ if(!hasActiveCenter){
+ setActiveCenters(reactants.getMolecule(0));
+ }
+
+ IAtom[] atoms = reactants.getMolecule(0).getAtoms();
+ for(int i = 0 ; i < atoms.length ; i++){
+ if(atoms[i].getFlag(CDKConstants.REACTIVE_CENTER)){
+
+ IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction();
+ reaction.addReactant(reactants.getMolecule(0));
+ IMolecule reactant = reaction.getReactants().getMolecule(0);
+
+ int posA = reactant.getAtomNumber(atoms[i]);
+
+ IMolecule reactantCloned = (IMolecule) reactants.getMolecule(0).clone();
+
+ ILonePair[] lps = reactantCloned.getLonePairs(reactantCloned.getAtomAt(posA));
+ reactantCloned.removeElectronContainer(lps[0]);
+
+ reactantCloned.addElectronContainer(new SingleElectron(reactantCloned.getAtomAt(posA)));
+
+ reaction.addProduct(reactantCloned);
+
+
+ setOfReactions.addReaction(reaction);
+ }
+ }
+ return setOfReactions;
+
+
+ }
+ /**
+ * set the active center for this molecule. The active center will be double bonds.
+ *
+ * @param reactant The molecule to set the activity
+ * @throws CDKException
+ */
+ private void setActiveCenters(IMolecule reactant) throws CDKException {
+ boolean foundAC = false;
+ IAtom[] atoms = reactant.getAtoms();
+ for(int i = 0 ; i < atoms.length ; i++){
+ if(reactant.getLonePairs(atoms[i]).length > 0){
+ atoms[i].setFlag(CDKConstants.REACTIVE_CENTER,true);
+ foundAC = true;
+ }
+ }
+ if(!foundAC)
+ throw new CDKException("it wasn't possible to find active center for this reactant: "+reactant);
+
+ }
+ /**
+ * Gets the parameterNames attribute of the ElectronImpactNBEReaction object
+ *
+ *@return The parameterNames value
+ */
+ public String[] getParameterNames() {
+ String[] params = new String[1];
+ params[0] = "hasActiveCenter";
+ return params;
+ }
+
+
+ /**
+ * Gets the parameterType attribute of the ElectronImpactNBEReaction object
+ *
+ *@param name Description of the Parameter
+ *@return The parameterType value
+ */
+ public Object getParameterType(String name) {
+ return new Boolean(false);
+ }
+}
View
181 src/org/openscience/cdk/reaction/type/ElectronImpactPDBReaction.java
@@ -0,0 +1,181 @@
+package org.openscience.cdk.reaction.type;
+
+
+import org.openscience.cdk.CDKConstants;
+import org.openscience.cdk.DefaultChemObjectBuilder;
+import org.openscience.cdk.SingleElectron;
+import org.openscience.cdk.exception.CDKException;
+import org.openscience.cdk.interfaces.IBond;
+import org.openscience.cdk.interfaces.IMolecule;
+import org.openscience.cdk.interfaces.IReaction;
+import org.openscience.cdk.interfaces.ISetOfMolecules;
+import org.openscience.cdk.interfaces.ISetOfReactions;
+import org.openscience.cdk.reaction.IReactionProcess;
+import org.openscience.cdk.reaction.ReactionSpecification;
+import org.openscience.cdk.tools.LoggingTool;
+
+/**
+ * IReactionProcess which make an alectron impact for pi-Bond Dissociation
+ *
+ * @author Miguel Rojas
+ *
+ * @cdk.created 2006-04-01
+ * @cdk.module reaction
+ * @cdk.set reaction-types
+ *
+ **/
+public class ElectronImpactPDBReaction implements IReactionProcess{
+ private LoggingTool logger;
+ private boolean hasActiveCenter;
+
+ /**
+ * Constructor of the ElectronImpactPDBReaction object
+ *
+ */
+ public ElectronImpactPDBReaction(){
+ logger = new LoggingTool(this);
+ }
+ /**
+ * Gets the specification attribute of the ElectronImpactPDBReaction object
+ *
+ *@return The specification value
+ */
+ public ReactionSpecification getSpecification() {
+ return new ReactionSpecification(
+ "http://gold.zvon.org/E01999.html",
+ this.getClass().getName(),
+ "$Id: ElectronImpactPDBReaction.java,v 1.6 2006/04/01 08:26:47 mrc Exp $",
+ "The Chemistry Development Kit");
+ }
+
+ /**
+ * Sets the parameters attribute of the ElectronImpactPDBReaction object
+ *
+ *@param params The parameter is the the molecule has center acitve or not
+ *@exception CDKException Description of the Exception
+ */
+ public void setParameters(Object[] params) throws CDKException {
+ if (params.length > 1) {
+ throw new CDKException("ElectronImpactPDBReaction only expects one parameter");
+ }
+ if (!(params[0] instanceof Boolean)) {
+ throw new CDKException("The parameter must be of type boolean");
+ }
+ hasActiveCenter = ((Boolean) params[0]).booleanValue();
+ }
+
+
+ /**
+ * Gets the parameters attribute of the ElectronImpactPDBReaction object
+ *
+ *@return The parameters value
+ */
+ public Object[] getParameters() {
+ Object[] params = new Object[1];
+ params[0] = new Boolean (hasActiveCenter);
+ return params;
+ }
+
+ /**
+ * Initiate process.
+ *
+ *@param reactants reactants to initiate.
+ *@param agents agents to initiate.
+ *
+ *@exception CDKException Description of the Exception
+ */
+
+ public ISetOfReactions initiate(ISetOfMolecules reactants, ISetOfMolecules agents) throws CDKException{
+
+ logger.debug("initiate reaction: ElectronImpactPDBReaction");
+
+ if (reactants.getMoleculeCount() != 1) {
+ throw new CDKException("ElectronImpactPDBReaction only expects one reactant");
+ }
+ if (agents != null) {
+ throw new CDKException("ElectronImpactPDBReaction don't expects agents");
+ }
+
+ ISetOfReactions setOfReactions = DefaultChemObjectBuilder.getInstance().newSetOfReactions();
+
+ if(!hasActiveCenter){
+ setActiveCenters(reactants.getMolecule(0));
+ }
+
+ IBond[] bonds = reactants.getMolecule(0).getBonds();
+ for(int i = 0 ; i < bonds.length ; i++){
+ if(bonds[i].getFlag(CDKConstants.REACTIVE_CENTER)){
+
+ IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction();
+ reaction.addReactant(reactants.getMolecule(0));
+ IMolecule reactant = reaction.getReactants().getMolecule(0);
+ int posA1 = reactant.getAtomNumber(bonds[i].getAtoms()[0]);
+ int posA2 = reactant.getAtomNumber(bonds[i].getAtoms()[1]);
+
+ for (int j = 0; j < 2; j++)
+ {
+ IMolecule reactantCloned = (IMolecule) reactant.clone();
+ double order = reactant.getBondAt(i).getOrder();
+ reactantCloned.getBondAt(i).setOrder(order - 1);
+
+ if (j == 0)
+ {
+ reactantCloned.getAtomAt(posA1).setFormalCharge(1);
+ reactantCloned.addElectronContainer(
+ new SingleElectron(reactantCloned.getAtomAt(posA2)));
+ } else
+ {
+ reactantCloned.getAtomAt(posA2).setFormalCharge(1);
+ reactantCloned.addElectronContainer(
+ new SingleElectron(reactantCloned.getAtomAt(posA1)));
+ }
+ reaction.addProduct(reactantCloned);
+ }
+ setOfReactions.addReaction(reaction);
+ }
+ }
+ return setOfReactions;
+
+
+ }
+ /**
+ * set the active center for this molecule. The active center will be double bonds.
+ *
+ * @param reactant The molecule to set the activity
+ * @throws CDKException
+ */
+ private void setActiveCenters(IMolecule reactant) throws CDKException {
+ boolean foundAC = false;
+ IBond[] bonds = reactant.getBonds();
+ for(int i = 0 ; i < bonds.length ; i++){
+ if(bonds[i].getOrder() == 2){
+ bonds[i].setFlag(CDKConstants.REACTIVE_CENTER,true);
+ foundAC = true;
+ }
+ }
+ if(!foundAC)
+ throw new CDKException("it wasn't possible to find active center for this reactant: "+reactant);
+
+ }
+ /**
+ * Gets the parameterNames attribute of the ElectronImpactPDBReaction object
+ *
+ *@return The parameterNames value
+ */
+ public String[] getParameterNames() {
+ String[] params = new String[1];
+ params[0] = "hasActiveCenter";
+ return params;
+ }
+
+
+ /**
+ * Gets the parameterType attribute of the ElectronImpactPDBReaction object
+ *
+ *@param name Description of the Parameter
+ *@return The parameterType value
+ */
+ public Object getParameterType(String name) {
+ return new Boolean(false);
+ }
+}
View
4 src/org/openscience/cdk/test/MextraTests.java
@@ -72,7 +72,7 @@
import org.openscience.cdk.test.modeling.forcefield.ForceFieldTests;
import org.openscience.cdk.test.qsar.descriptors.QSARDescriptorTests;
import org.openscience.cdk.test.qsar.model.QSARRModelTests;
-import org.openscience.cdk.test.reaction.ReactionBalancerTest;
+import org.openscience.cdk.test.reaction.type.ReactionTypeTest;
import org.openscience.cdk.test.ringsearch.AllRingsFinderTest;
import org.openscience.cdk.test.ringsearch.RingPartitionerTest;
import org.openscience.cdk.test.ringsearch.RingSearchTest;
@@ -159,7 +159,7 @@ public static Test suite( )
// from cdk.test.qsar
suite.addTest(QSARDescriptorTests.suite());
// from cdk.test.reaction
- suite.addTest(ReactionBalancerTest.suite());
+ suite.addTest(ReactionTypeTest.suite());
// from cdk.test.ringsearch
suite.addTest(AllRingsFinderTest.suite());
suite.addTest(RingSearchTest.suite());
View
4 src/org/openscience/cdk/test/OpenSourceJVMTestSuiteTests.java
@@ -55,7 +55,7 @@
import org.openscience.cdk.test.layout.TemplateHandlerTest;
import org.openscience.cdk.test.math.MathToolsTest;
import org.openscience.cdk.test.qsar.descriptors.QSARDescriptorTests;
-import org.openscience.cdk.test.reaction.ReactionBalancerTest;
+import org.openscience.cdk.test.reaction.type.ReactionTypeTest;
import org.openscience.cdk.test.similarity.TanimotoTest;
import org.openscience.cdk.test.smiles.SmilesGeneratorTest;
import org.openscience.cdk.test.smiles.SmilesParserTest;
@@ -133,7 +133,7 @@ public static Test suite() {
suite.addTest(OverlapResolverTest.suite());
suite.addTest(TemplateHandlerTest.suite());
// from cdk.test.reaction
- suite.addTest(ReactionBalancerTest.suite());
+ suite.addTest(ReactionTypeTest.suite());
// from cdk.test.similarity
suite.addTest(TanimotoTest.suite());
// from cdk.test.smiles
View
98 src/org/openscience/cdk/test/reaction/type/ElectronImpactNBEReactionTest.java
@@ -0,0 +1,98 @@
+package org.openscience.cdk.test.reaction.type;
+
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.openscience.cdk.CDKConstants;
+import org.openscience.cdk.DefaultChemObjectBuilder;
+import org.openscience.cdk.Molecule;
+import org.openscience.cdk.exception.CDKException;
+import org.openscience.cdk.interfaces.IAtom;
+import org.openscience.cdk.interfaces.IMolecule;
+import org.openscience.cdk.interfaces.ISetOfMolecules;
+import org.openscience.cdk.interfaces.ISetOfReactions;
+import org.openscience.cdk.reaction.IReactionProcess;
+import org.openscience.cdk.reaction.type.ElectronImpactNBEReaction;
+import org.openscience.cdk.smiles.SmilesParser;
+import org.openscience.cdk.test.CDKTestCase;
+import org.openscience.cdk.tools.LonePairElectronChecker;
+
+/**
+ * TestSuite that runs a test for the ElectronImpactNBEReactionTest.
+ *
+ * @cdk.module test-extra
+ */
+
+public class ElectronImpactNBEReactionTest extends CDKTestCase {
+
+ public ElectronImpactNBEReactionTest() {}
+
+ public static Test suite() {
+ return new TestSuite(ElectronImpactNBEReactionTest.class);
+ }
+ /**
+ * A unit test for JUnit
+ *
+ *@return Description of the Return Value
+ */
+ public void test1_5_Hexen_3_one() throws ClassNotFoundException, CDKException, java.lang.Exception {
+ /* ionize(>C=O): C=CCC(=O)CC -> C=CCC(=O*)CC , set the reactive center*/
+ Molecule reactant = (new SmilesParser()).parseSmiles("C=CCC(=O)CC");
+ LonePairElectronChecker lpeCheck = new LonePairElectronChecker();
+ lpeCheck.newSaturate(reactant);
+
+ IAtom[] atoms = reactant.getAtoms();
+ for(int i = 0 ; i < atoms.length ; i++){
+ if(reactant.getLonePairs(atoms[i]).length > 0){
+ atoms[i].setFlag(CDKConstants.REACTIVE_CENTER,true);
+ }
+ }
+
+ ISetOfMolecules setOfReactants = DefaultChemObjectBuilder.getInstance().newSetOfMolecules();
+ setOfReactants.addMolecule(reactant);
+
+ IReactionProcess type = new ElectronImpactNBEReaction();
+ Object[] params = {true};
+ type.setParameters(params);
+ ISetOfReactions setOfReactions = type.initiate(setOfReactants, null);
+
+ Assert.assertEquals(1, setOfReactions.getReactionCount());
+ Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount());
+
+ IMolecule molecule = setOfReactions.getReaction(0).getProducts().getMolecule(0);
+ Assert.assertEquals(0, molecule.getAtomAt(4).getFormalCharge());
+ Assert.assertEquals(1, molecule.getSingleElectronSum(molecule.getAtomAt(4)));
+
+
+ }
+ /**
+ * A unit test for JUnit
+ *
+ *@return Description of the Return Value
+ */
+ public void test2_5_Hexen_3_one() throws ClassNotFoundException, CDKException, java.lang.Exception {
+ /* ionize(>C=O): C=CCC(=O)CC -> C=CCC(=O*)CC, without setting the reactive center*/
+ Molecule reactant = (new SmilesParser()).parseSmiles("C=CCC(=O)CC");
+ LonePairElectronChecker lpeCheck = new LonePairElectronChecker();
+ lpeCheck.newSaturate(reactant);
+
+
+ ISetOfMolecules setOfReactants = DefaultChemObjectBuilder.getInstance().newSetOfMolecules();
+ setOfReactants.addMolecule(reactant);
+
+ IReactionProcess type = new ElectronImpactNBEReaction();
+// Object[] params = {false};
+// type.setParameters(params);
+ ISetOfReactions setOfReactions = type.initiate(setOfReactants, null);
+
+ Assert.assertEquals(1, setOfReactions.getReactionCount());
+ Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount());
+
+ IMolecule molecule = setOfReactions.getReaction(0).getProducts().getMolecule(0);
+ Assert.assertEquals(0, molecule.getAtomAt(4).getFormalCharge());
+ Assert.assertEquals(1, molecule.getSingleElectronSum(molecule.getAtomAt(4)));
+
+ }
+}
View
103 src/org/openscience/cdk/test/reaction/type/ElectronImpactPDBReactionTest.java
@@ -0,0 +1,103 @@
+package org.openscience.cdk.test.reaction.type;
+
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.openscience.cdk.CDKConstants;
+import org.openscience.cdk.DefaultChemObjectBuilder;
+import org.openscience.cdk.Molecule;
+import org.openscience.cdk.exception.CDKException;
+import org.openscience.cdk.interfaces.IAtom;
+import org.openscience.cdk.interfaces.IBond;
+import org.openscience.cdk.interfaces.IMolecule;
+import org.openscience.cdk.interfaces.ISetOfMolecules;
+import org.openscience.cdk.interfaces.ISetOfReactions;
+import org.openscience.cdk.reaction.IReactionProcess;
+import org.openscience.cdk.reaction.type.ElectronImpactPDBReaction;
+import org.openscience.cdk.smiles.SmilesParser;
+import org.openscience.cdk.test.CDKTestCase;
+
+/**
+ * TestSuite that runs a test for the ElectronImpactPDBReactionTest.
+ *
+ * @cdk.module test-extra
+ */
+
+public class ElectronImpactPDBReactionTest extends CDKTestCase {
+
+ public ElectronImpactPDBReactionTest() {}
+
+ public static Test suite() {
+ return new TestSuite(ElectronImpactPDBReactionTest.class);
+ }
+ /**
+ * A unit test for JUnit
+ *
+ *@return Description of the Return Value
+ */
+ public void test1_5_Hexen_3_one() throws ClassNotFoundException, CDKException, java.lang.Exception {
+ /* ionize >C=C< , set the reactive center*/
+ Molecule reactant = (new SmilesParser()).parseSmiles("C=CCC(=O)CC");
+
+ IBond[] bonds = reactant.getBonds();
+ for(int i = 0 ; i < bonds.length ; i++){
+ IAtom[] atoms = bonds[i].getAtoms();
+ if(bonds[i].getOrder() == 2 &&
+ atoms[0].getSymbol().equals("C")&&
+ atoms[1].getSymbol().equals("C")){
+ bonds[i].setFlag(CDKConstants.REACTIVE_CENTER,true);
+ }
+ }
+
+ ISetOfMolecules setOfReactants = DefaultChemObjectBuilder.getInstance().newSetOfMolecules();
+ setOfReactants.addMolecule(reactant);
+
+ IReactionProcess type = new ElectronImpactPDBReaction();
+ Object[] params = {true};
+ type.setParameters(params);
+ ISetOfReactions setOfReactions = type.initiate(setOfReactants, null);
+
+ Assert.assertEquals(1, setOfReactions.getReactionCount());
+
+ IMolecule molecule = setOfReactions.getReaction(0).getProducts().getMolecule(0);
+ Assert.assertEquals(1, molecule.getAtomAt(1).getFormalCharge());
+ Assert.assertEquals(1, molecule.getSingleElectronSum(molecule.getAtomAt(0)));
+
+ molecule = setOfReactions.getReaction(0).getProducts().getMolecule(1);
+ Assert.assertEquals(1, molecule.getAtomAt(0).getFormalCharge());
+ Assert.assertEquals(1, molecule.getSingleElectronSum(molecule.getAtomAt(1)));
+
+ }
+ /**
+ * A unit test for JUnit
+ *
+ *@return Description of the Return Value
+ */
+ public void test_Propene() throws ClassNotFoundException, CDKException, java.lang.Exception {
+ /* ionize all possible double bonds */
+ Molecule reactant = (new SmilesParser()).parseSmiles("C=CC");
+
+
+ ISetOfMolecules setOfReactants = DefaultChemObjectBuilder.getInstance().newSetOfMolecules();
+ setOfReactants.addMolecule(reactant);
+
+ IReactionProcess type = new ElectronImpactPDBReaction();
+// Object[] params = {false};
+// type.setParameters(params);
+ ISetOfReactions setOfReactions = type.initiate(setOfReactants, null);
+
+ Assert.assertEquals(1, setOfReactions.getReactionCount());
+
+
+ IMolecule molecule = setOfReactions.getReaction(0).getProducts().getMolecule(0);
+ Assert.assertEquals(1, molecule.getAtomAt(1).getFormalCharge());
+ Assert.assertEquals(1, molecule.getSingleElectronSum(molecule.getAtomAt(0)));
+
+ molecule = setOfReactions.getReaction(0).getProducts().getMolecule(1);
+ Assert.assertEquals(1, molecule.getAtomAt(0).getFormalCharge());
+ Assert.assertEquals(1, molecule.getSingleElectronSum(molecule.getAtomAt(1)));
+
+ }
+}
View
26 src/org/openscience/cdk/test/reaction/type/ReactionTypeTest.java
@@ -0,0 +1,26 @@
+package org.openscience.cdk.test.reaction.type;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.openscience.cdk.applications.swing.MoleculeListViewer;
+
+/**
+ * TestSuite that runs all reactions tests.
+ *
+ * @cdk.module test-extra
+ */
+
+public class ReactionTypeTest {
+
+ static MoleculeListViewer moleculeListViewer = null;
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("All Reaction Type Tests");
+ suite.addTest(ElectronImpactPDBReactionTest.suite());
+ suite.addTest(ElectronImpactNBEReactionTest.suite());
+
+ return suite;
+ }
+
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.