Skip to content

Commit

Permalink
Added getExampleReactants and getExpectedProducts method for all reac…
Browse files Browse the repository at this point in the history
…tion.type test.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
Miguel Rojas Cherto authored and egonw committed Feb 1, 2010
1 parent 0fa7350 commit 4f5e8a1
Show file tree
Hide file tree
Showing 33 changed files with 1,556 additions and 1,300 deletions.
Expand Up @@ -87,25 +87,20 @@ public AdductionProtonLPReactionTest() throws Exception {

IReactionProcess type = new AdductionProtonLPReaction();

IMolecule molecule = getAcetaldehyde();

IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
setOfReactants.addMolecule(molecule);

/* initiate */
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
IParameterReact param = new SetReactionCenter();
param.setParameter(Boolean.FALSE);
paramList.add(param);
type.setParameterList(paramList);
IReactionSet setOfReactions = type.initiate(setOfReactants, null);
IReactionSet setOfReactions = type.initiate(getExampleReactants(), null);

Assert.assertEquals(1, setOfReactions.getReactionCount());
Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount());

IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0);

IMolecule molecule2 = getExpected();
IMolecule molecule2 = getExpectedProducts().getMolecule(0);

IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product);
Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,queryAtom));
Expand All @@ -122,13 +117,10 @@ public AdductionProtonLPReactionTest() throws Exception {
*/
@Test public void testManuallyCentreActive() throws Exception {
IReactionProcess type = new AdductionProtonLPReaction();
IMolecule molecule = getAcetaldehyde();
IMoleculeSet setOfReactants = getExampleReactants();

IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
setOfReactants.addMolecule(molecule);

/*manually putting the active center*/
molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER,true);
setOfReactants.getMolecule(0).getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER,true);

/* initiate */
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
Expand All @@ -143,7 +135,7 @@ public AdductionProtonLPReactionTest() throws Exception {

IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0);

IMolecule molecule2 = getExpected();
IMolecule molecule2 = getExpectedProducts().getMolecule(0);

IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product);
Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,queryAtom));
Expand All @@ -158,10 +150,10 @@ public AdductionProtonLPReactionTest() throws Exception {
*/
@Test public void testCDKConstants_REACTIVE_CENTER() throws Exception {
IReactionProcess type = new AdductionProtonLPReaction();
IMoleculeSet setOfReactants = builder.newMoleculeSet();
IMolecule molecule = getAcetaldehyde();
IMoleculeSet setOfReactants = getExampleReactants();

/*manually putting the active center*/
IMolecule molecule = setOfReactants.getMolecule(0);
molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER,true);
molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER,true);
molecule.getAtom(2).setFlag(CDKConstants.REACTIVE_CENTER,true);
Expand All @@ -170,7 +162,6 @@ public AdductionProtonLPReactionTest() throws Exception {
molecule.getBond(1).setFlag(CDKConstants.REACTIVE_CENTER,true);
molecule.getBond(3).setFlag(CDKConstants.REACTIVE_CENTER,true);

setOfReactants.addMolecule(molecule);
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
IParameterReact param = new SetReactionCenter();
param.setParameter(Boolean.TRUE);
Expand Down Expand Up @@ -205,12 +196,7 @@ public AdductionProtonLPReactionTest() throws Exception {
*/
@Test public void testMapping() throws Exception {
IReactionProcess type = new AdductionProtonLPReaction();

IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
IMolecule molecule = getAcetaldehyde();

setOfReactants.addMolecule(molecule);

/*automatic looking for active center*/
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
IParameterReact param = new SetReactionCenter();
Expand All @@ -219,14 +205,14 @@ public AdductionProtonLPReactionTest() throws Exception {
type.setParameterList(paramList);

/* initiate */

IMoleculeSet setOfReactants = getExampleReactants();
IReactionSet setOfReactions = type.initiate(setOfReactants, null);

IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0);

Assert.assertEquals(2,setOfReactions.getReaction(0).getMappingCount());

IAtom mappedProductA1 = (IAtom)ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(0));
IAtom mappedProductA1 = (IAtom)ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), setOfReactants.getMolecule(0).getAtom(0));
Assert.assertEquals(mappedProductA1, product.getAtom(0));


Expand All @@ -236,10 +222,10 @@ public AdductionProtonLPReactionTest() throws Exception {
*
* @cdk.inchi InChI=1/C2H4O/c1-2-3/h2H,1H3
*
* @return The IMolecule
* @throws CDKException
* @return The IMoleculeSet
*/
private IMolecule getAcetaldehyde() throws Exception {
private IMoleculeSet getExampleReactants() {
IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
IMolecule molecule = builder.newMolecule();
molecule.addAtom(builder.newAtom("O"));
molecule.addAtom(builder.newAtom("C"));
Expand All @@ -254,20 +240,27 @@ private IMolecule getAcetaldehyde() throws Exception {
molecule.addBond(2, 4, IBond.Order.SINGLE);
molecule.addBond(2, 5, IBond.Order.SINGLE);
molecule.addBond(2, 6, IBond.Order.SINGLE);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);

try {
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);

LonePairElectronChecker lpcheck = new LonePairElectronChecker();
lpcheck.saturate(molecule);
} catch (CDKException e) {
e.printStackTrace();
}

LonePairElectronChecker lpcheck = new LonePairElectronChecker();
lpcheck.saturate(molecule);
return molecule;
setOfReactants.addMolecule(molecule);
return setOfReactants;
}

/**
* Get the expected structure.
* Get the expected set of molecules.
*
* @return The IMolecule
* @throws CDKException
* @return The IMoleculeSet
*/
private IMolecule getExpected() throws Exception {
private IMoleculeSet getExpectedProducts() {
IMoleculeSet setOfProducts = builder.newMoleculeSet();
IMolecule molecule = builder.newMolecule();
molecule.addAtom(builder.newAtom("O"));
molecule.getAtom(0).setFormalCharge(1);
Expand All @@ -285,10 +278,16 @@ private IMolecule getExpected() throws Exception {
molecule.addBond(2, 5, IBond.Order.SINGLE);
molecule.addBond(2, 6, IBond.Order.SINGLE);
molecule.addBond(0, 7, IBond.Order.SINGLE);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
try {
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);

LonePairElectronChecker lpcheck = new LonePairElectronChecker();
lpcheck.saturate(molecule);
} catch (CDKException e) {
e.printStackTrace();
}

LonePairElectronChecker lpcheck = new LonePairElectronChecker();
lpcheck.saturate(molecule);
return molecule;
setOfProducts.addMolecule(molecule);
return setOfProducts;
}
}
Expand Up @@ -87,11 +87,8 @@ public AdductionProtonPBReactionTest() throws Exception {

IReactionProcess type = new AdductionProtonPBReaction();

IMolecule molecule = getEthene();

IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
setOfReactants.addMolecule(molecule);

IMoleculeSet setOfReactants = getExampleReactants();

/* initiate */
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
IParameterReact param = new SetReactionCenter();
Expand All @@ -104,8 +101,8 @@ public AdductionProtonPBReactionTest() throws Exception {
Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount());

IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0);
IMolecule molecule2 = getExpected();

IMolecule molecule2 = getExpectedProducts().getMolecule(0);

IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product);
Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,queryAtom));
Expand All @@ -122,10 +119,9 @@ public AdductionProtonPBReactionTest() throws Exception {
*/
@Test public void testManuallyCentreActive() throws Exception {
IReactionProcess type = new AdductionProtonPBReaction();
IMolecule molecule = getEthene();

IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
setOfReactants.addMolecule(molecule);

IMoleculeSet setOfReactants = getExampleReactants();
IMolecule molecule = setOfReactants.getMolecule(0);

/*manually putting the active center*/
molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER,true);
Expand All @@ -145,7 +141,7 @@ public AdductionProtonPBReactionTest() throws Exception {

IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0);

IMolecule molecule2 = getExpected();
IMolecule molecule2 = getExpectedProducts().getMolecule(0);

IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product);
Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,queryAtom));
Expand All @@ -161,15 +157,15 @@ public AdductionProtonPBReactionTest() throws Exception {
*/
@Test public void testCDKConstants_REACTIVE_CENTER() throws Exception {
IReactionProcess type = new AdductionProtonPBReaction();
IMoleculeSet setOfReactants = builder.newMoleculeSet();
IMolecule molecule = getEthene();

IMoleculeSet setOfReactants = getExampleReactants();
IMolecule molecule = setOfReactants.getMolecule(0);

/*manually putting the active center*/
molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER,true);
molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER,true);
molecule.getBond(0).setFlag(CDKConstants.REACTIVE_CENTER,true);

setOfReactants.addMolecule(molecule);
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
IParameterReact param = new SetReactionCenter();
param.setParameter(Boolean.TRUE);
Expand Down Expand Up @@ -198,11 +194,9 @@ public AdductionProtonPBReactionTest() throws Exception {
@Test public void testMapping() throws Exception {
IReactionProcess type = new AdductionProtonPBReaction();

IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
IMolecule molecule = getEthene();

setOfReactants.addMolecule(molecule);

IMoleculeSet setOfReactants = getExampleReactants();
IMolecule molecule = setOfReactants.getMolecule(0);

/*automatic looking for active center*/
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
IParameterReact param = new SetReactionCenter();
Expand Down Expand Up @@ -233,7 +227,8 @@ public AdductionProtonPBReactionTest() throws Exception {
* @return The IMolecule
* @throws CDKException
*/
private IMolecule getEthene() throws Exception {
private IMoleculeSet getExampleReactants() {
IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
IMolecule molecule = builder.newMolecule();
molecule.addAtom(builder.newAtom("C"));
molecule.addAtom(builder.newAtom("C"));
Expand All @@ -246,20 +241,25 @@ private IMolecule getEthene() throws Exception {
molecule.addBond(0, 3, IBond.Order.SINGLE);
molecule.addBond(1, 4, IBond.Order.SINGLE);
molecule.addBond(1, 5, IBond.Order.SINGLE);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
try {
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);

LonePairElectronChecker lpcheck = new LonePairElectronChecker();
lpcheck.saturate(molecule);
return molecule;
LonePairElectronChecker lpcheck = new LonePairElectronChecker();
lpcheck.saturate(molecule);
} catch (CDKException e) {
e.printStackTrace();
}
setOfReactants.addMolecule(molecule);
return setOfReactants;
}

/**
* Get the expected structure.
* Get the expected set of molecules.
*
* @return The IMolecule
* @throws CDKException
* @return The IMoleculeSet
*/
private IMolecule getExpected() throws Exception {
private IMoleculeSet getExpectedProducts() {
IMoleculeSet setOfProducts = builder.newMoleculeSet();
IMolecule molecule = builder.newMolecule();
molecule.addAtom(builder.newAtom("C"));
molecule.getAtom(0).setFormalCharge(1);
Expand All @@ -275,10 +275,16 @@ private IMolecule getExpected() throws Exception {
molecule.addBond(1, 4, IBond.Order.SINGLE);
molecule.addBond(1, 5, IBond.Order.SINGLE);
molecule.addBond(1, 6, IBond.Order.SINGLE);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
try {
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);

LonePairElectronChecker lpcheck = new LonePairElectronChecker();
lpcheck.saturate(molecule);
return molecule;
LonePairElectronChecker lpcheck = new LonePairElectronChecker();
lpcheck.saturate(molecule);
} catch (CDKException e) {
e.printStackTrace();
}

setOfProducts.addMolecule(molecule);
return setOfProducts;
}
}

0 comments on commit 4f5e8a1

Please sign in to comment.