From: <mig...@us...> - 2006-05-04 12:47:01
|
Revision: 6158 Author: miguelrojasch Date: 2006-05-04 05:46:46 -0700 (Thu, 04 May 2006) ViewCVS: http://svn.sourceforge.net/cdk/?rev=6158&view=rev Log Message: ----------- adding new resonance type in resonanceGenerator. More tests Modified Paths: -------------- trunk/cdk/src/org/openscience/cdk/test/tools/StructureResonanceGeneratorTest.java trunk/cdk/src/org/openscience/cdk/tools/StructureResonanceGenerator.java Modified: trunk/cdk/src/org/openscience/cdk/test/tools/StructureResonanceGeneratorTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/tools/StructureResonanceGeneratorTest.java 2006-05-04 12:44:30 UTC (rev 6157) +++ trunk/cdk/src/org/openscience/cdk/test/tools/StructureResonanceGeneratorTest.java 2006-05-04 12:46:46 UTC (rev 6158) @@ -81,8 +81,9 @@ ILonePair[] selectron = molecule.getLonePairs(atom); molecule.removeElectronContainer(selectron[0]); - ISetOfAtomContainers setOfMolecules = gR.getAllStructures(molecule); - + StructureResonanceGenerator gRI = new StructureResonanceGenerator(true,true,true,false,false); + ISetOfAtomContainers setOfMolecules = gRI.getAllStructures(molecule); + Assert.assertEquals(8,setOfMolecules.getAtomContainerCount()); /*1*/ @@ -160,7 +161,8 @@ ILonePair[] selectron = molecule.getLonePairs(atom); molecule.removeElectronContainer(selectron[0]); - ISetOfAtomContainers setOfMolecules = gR.getStructures(molecule); + StructureResonanceGenerator gRI = new StructureResonanceGenerator(true,true,true,false,false); + ISetOfAtomContainers setOfMolecules = gRI.getStructures(molecule); Assert.assertEquals(2,setOfMolecules.getAtomContainerCount()); @@ -197,7 +199,8 @@ ILonePair[] selectron = molecule.getLonePairs(atom); molecule.removeElectronContainer(selectron[0]); - ISetOfAtomContainers setOfMolecules = gR.getStructures(molecule); + StructureResonanceGenerator gRI = new StructureResonanceGenerator(true,true,true,false,false); + ISetOfAtomContainers setOfMolecules = gRI.getStructures(molecule); Assert.assertEquals(2,setOfMolecules.getAtomContainerCount()); @@ -232,7 +235,7 @@ molecule.getBondAt(2).setFlag(CDKConstants.REACTIVE_CENTER,true); molecule.getAtomAt(3).setFlag(CDKConstants.REACTIVE_CENTER,true); - StructureResonanceGenerator gRI = new StructureResonanceGenerator(true,true,true,true); + StructureResonanceGenerator gRI = new StructureResonanceGenerator(true,true,true,true,true); ISetOfAtomContainers setOfMolecules = gRI.getStructures(molecule); Assert.assertEquals(2,setOfMolecules.getAtomContainerCount()); @@ -263,4 +266,39 @@ QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(molecule2); Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(setOfMolecules.getAtomContainer(1),qAC)); } + /** + * A unit test suite for JUnit: Resonance Formic acid C(=O)O <=> [C-](-[O+])O <=> [C+](-[O-])O <=> C([O-])=[O+] + * + * @return The test suite + */ + public void testResonanceFormicAcid() throws ClassNotFoundException, CDKException, java.lang.Exception { + Molecule molecule = (new SmilesParser()).parseSmiles("C(=O)O"); + HydrogenAdder adder = new HydrogenAdder(); + adder.addImplicitHydrogensToSatisfyValency(molecule); + LonePairElectronChecker lpcheck = new LonePairElectronChecker(); + lpcheck.newSaturate(molecule); + + ISetOfAtomContainers setOfMolecules = gR.getAllStructures(molecule); + + Assert.assertEquals(4,setOfMolecules.getAtomContainerCount()); + + Molecule molecule1 = (new SmilesParser()).parseSmiles("[C-](-[O+])O"); + adder.addImplicitHydrogensToSatisfyValency(molecule1); + lpcheck.newSaturate(molecule1); + QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(molecule1); + Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(setOfMolecules.getAtomContainer(1),qAC)); + + Molecule molecule2 = (new SmilesParser()).parseSmiles("[C+](-[O-])O"); + adder.addImplicitHydrogensToSatisfyValency(molecule2); + lpcheck.newSaturate(molecule2); + qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(molecule2); + Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(setOfMolecules.getAtomContainer(2),qAC)); + + Molecule molecule3 = (new SmilesParser()).parseSmiles("C([O-])=[O+]"); + adder.addImplicitHydrogensToSatisfyValency(molecule3); + lpcheck.newSaturate(molecule3); + + qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(molecule3); + Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(setOfMolecules.getAtomContainer(3),qAC)); + } } Modified: trunk/cdk/src/org/openscience/cdk/tools/StructureResonanceGenerator.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/tools/StructureResonanceGenerator.java 2006-05-04 12:44:30 UTC (rev 6157) +++ trunk/cdk/src/org/openscience/cdk/tools/StructureResonanceGenerator.java 2006-05-04 12:46:46 UTC (rev 6158) @@ -11,6 +11,7 @@ import org.openscience.cdk.isomorphism.matchers.QueryAtomContainer; import org.openscience.cdk.isomorphism.matchers.QueryAtomContainerCreator; import org.openscience.cdk.reaction.IReactionProcess; +import org.openscience.cdk.reaction.type.DisplacementChargeReaction; import org.openscience.cdk.reaction.type.RearrangementAnion1Reaction; import org.openscience.cdk.reaction.type.RearrangementAnion2Reaction; import org.openscience.cdk.reaction.type.RearrangementAnion3Reaction; @@ -43,6 +44,7 @@ * @cdk.created 2006-5-05 * @cdk.module experimental * + * @see DisplacementChargeReaction * @see RearrangementAnion1Reaction * @see RearrangementAnion2Reaction * @see RearrangementAnion3Reaction @@ -59,14 +61,15 @@ private boolean cationR; private boolean anionR; private boolean radicalR; + private boolean bondR; private boolean hasActiveCenter; /** * Constructor of StructureResonanceGenerator object * - * Default: all possible search (Aromatic,Cation,Anion), not specified the active center + * Default: all possible search (Aromatic,Cation,Anion,Bond), not specified the active center */ public StructureResonanceGenerator(){ - this(true,true,true,false); + this(true,true,true,true,false); } /** * Constructor of StructureResonanceGenerator object @@ -74,16 +77,19 @@ * @param cationR True, search of Cation. * @param anionR True, search of Anion. * @param radicalR True, search of Radical. + * @param bondR True, search of Bond. * @param hasActiveCenter False, search of active Center. */ public StructureResonanceGenerator( boolean cationR, boolean anionR, boolean radicalR, + boolean bondR, boolean hasActiveCenter){ this.cationR = cationR; this.anionR = anionR; this.radicalR = radicalR; + this.bondR = bondR; this.hasActiveCenter = hasActiveCenter; } @@ -142,6 +148,7 @@ for(int k = 0 ; k < setOfReactions.getReactionCount() ; k++) for(int j = 0 ; j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount() ; j++){ IAtomContainer set = setOfReactions.getReaction(k).getProducts().getAtomContainer(j); + System.out.println("RearrangementCation1Reaction"); if(!existAC(setOfAtomContainer,set)) setOfAtomContainer.addAtomContainer(setOfReactions.getReaction(k).getProducts().getAtomContainer(j)); } @@ -156,6 +163,7 @@ for(int k = 0 ; k < setOfReactions.getReactionCount() ; k++) for(int j = 0 ; j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount() ; j++){ IAtomContainer set = setOfReactions.getReaction(k).getProducts().getAtomContainer(j); + System.out.println("RearrangementCation2Reaction"); if(!existAC(setOfAtomContainer,set)) setOfAtomContainer.addAtomContainer(setOfReactions.getReaction(k).getProducts().getAtomContainer(j)); } @@ -170,6 +178,7 @@ for(int k = 0 ; k < setOfReactions.getReactionCount() ; k++) for(int j = 0 ; j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount() ; j++){ IAtomContainer set = setOfReactions.getReaction(k).getProducts().getAtomContainer(j); + System.out.println("RearrangementCation3Reaction"); if(!existAC(setOfAtomContainer,set)) setOfAtomContainer.addAtomContainer(setOfReactions.getReaction(k).getProducts().getAtomContainer(j)); } @@ -185,6 +194,7 @@ for(int k = 0 ; k < setOfReactions.getReactionCount() ; k++) for(int j = 0 ; j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount() ; j++){ IAtomContainer set = setOfReactions.getReaction(k).getProducts().getAtomContainer(j); + System.out.println("RearrangementAnion1Reaction"); if(!existAC(setOfAtomContainer,set)) setOfAtomContainer.addAtomContainer(setOfReactions.getReaction(k).getProducts().getAtomContainer(j)); } @@ -199,6 +209,7 @@ for(int k = 0 ; k < setOfReactions.getReactionCount() ; k++) for(int j = 0 ; j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount() ; j++){ IAtomContainer set = setOfReactions.getReaction(k).getProducts().getAtomContainer(j); + System.out.println("RearrangementAnion2Reaction"); if(!existAC(setOfAtomContainer,set)) setOfAtomContainer.addAtomContainer(setOfReactions.getReaction(k).getProducts().getAtomContainer(j)); } @@ -213,6 +224,7 @@ for(int k = 0 ; k < setOfReactions.getReactionCount() ; k++) for(int j = 0 ; j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount() ; j++){ IAtomContainer set = setOfReactions.getReaction(k).getProducts().getAtomContainer(j); + System.out.println("RearrangementAnion3Reaction"); if(!existAC(setOfAtomContainer,set)) setOfAtomContainer.addAtomContainer(setOfReactions.getReaction(k).getProducts().getAtomContainer(j)); } @@ -228,6 +240,7 @@ for(int k = 0 ; k < setOfReactions.getReactionCount() ; k++) for(int j = 0 ; j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount() ; j++){ IAtomContainer set = setOfReactions.getReaction(k).getProducts().getAtomContainer(j); + System.out.println("RearrangementRadical1Reaction"); if(!existAC(setOfAtomContainer,set)) setOfAtomContainer.addAtomContainer(setOfReactions.getReaction(k).getProducts().getAtomContainer(j)); } @@ -242,6 +255,7 @@ for(int k = 0 ; k < setOfReactions.getReactionCount() ; k++) for(int j = 0 ; j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount() ; j++){ IAtomContainer set = setOfReactions.getReaction(k).getProducts().getAtomContainer(j); + System.out.println("RearrangementRadical2Reaction"); if(!existAC(setOfAtomContainer,set)) setOfAtomContainer.addAtomContainer(setOfReactions.getReaction(k).getProducts().getAtomContainer(j)); } @@ -256,10 +270,28 @@ for(int k = 0 ; k < setOfReactions.getReactionCount() ; k++) for(int j = 0 ; j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount() ; j++){ IAtomContainer set = setOfReactions.getReaction(k).getProducts().getAtomContainer(j); + System.out.println("RearrangementRadical3Reaction"); if(!existAC(setOfAtomContainer,set)) setOfAtomContainer.addAtomContainer(setOfReactions.getReaction(k).getProducts().getAtomContainer(j)); } } + if(bondR){ + /* DisplacementChargeReaction*/ + IReactionProcess type = new DisplacementChargeReaction(); + type.setParameters(params); + + ISetOfReactions setOfReactions = type.initiate(setOfReactants, null); + + if(setOfReactions.getReactionCount() != 0) + for(int k = 0 ; k < setOfReactions.getReactionCount() ; k++) + for(int j = 0 ; j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount() ; j++){ + IAtomContainer set = setOfReactions.getReaction(k).getProducts().getAtomContainer(j); + System.out.println("DisplacementChargeReaction"); + if(!existAC(setOfAtomContainer,set)) + setOfAtomContainer.addAtomContainer(setOfReactions.getReaction(k).getProducts().getAtomContainer(j)); + } + } + } } catch (CDKException e) { // TODO Auto-generated catch block @@ -280,6 +312,7 @@ QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(ac); try { if(UniversalIsomorphismTester.isIsomorph(atomContainer,qAC)){ + System.out.println("exist"); return true; } } catch (CDKException e1) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |