From: <mig...@us...> - 2006-08-09 13:23:10
|
Revision: 6767 Author: miguelrojasch Date: 2006-08-09 06:22:44 -0700 (Wed, 09 Aug 2006) ViewCVS: http://svn.sourceforge.net/cdk/?rev=6767&view=rev Log Message: ----------- more flexibility for the search of resonance structures. Modified Paths: -------------- trunk/cdk/src/org/openscience/cdk/charges/GasteigerMarsiliPartialCharges.java trunk/cdk/src/org/openscience/cdk/reaction/type/BreakingBondReaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/DisplacementChargeFromAcceptorReaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/DisplacementChargeFromDonorReaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/ElectronImpactNBEReaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/ElectronImpactPDBReaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/HyperconjugationReaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion1Reaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion2Reaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion3Reaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation1Reaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation2Reaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation3Reaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical1Reaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical2Reaction.java trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical3Reaction.java trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/atomic/SigmaElectronegativityDescriptorTest.java trunk/cdk/src/org/openscience/cdk/test/reaction/type/BreakingBondReactionTest.java trunk/cdk/src/org/openscience/cdk/test/reaction/type/DisplacementChargeFromAcceptorReactionTest.java trunk/cdk/src/org/openscience/cdk/test/reaction/type/DisplacementChargeFromDonorReactionTest.java trunk/cdk/src/org/openscience/cdk/test/reaction/type/HyperconjugationReactionTest.java trunk/cdk/src/org/openscience/cdk/test/reaction/type/RearrangementAnion2ReactionTest.java 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/charges/GasteigerMarsiliPartialCharges.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/charges/GasteigerMarsiliPartialCharges.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/charges/GasteigerMarsiliPartialCharges.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -101,13 +101,13 @@ *@exception Exception Possible Exceptions */ public IAtomContainer assignGasteigerMarsiliSigmaPartialCharges(IAtomContainer ac, boolean setCharge) throws Exception { - if (setCharge) { - atomTypeCharges.setCharges(ac); - } + +// if (setCharge) { +// atomTypeCharges.setCharges(ac); // not necessary initial charge +// } /*add the initial charge to 0. According results of Gasteiger*/ for(int i = 0; i < ac.getAtomCount(); i++) ac.getAtom(i).setCharge(0.0); - double[] gasteigerFactors = assignGasteigerSigmaMarsiliFactors(ac);//a,b,c,deoc,chi,q double alpha = 1.0; double q; @@ -217,13 +217,14 @@ factors[1] = 9.45;/*9.45*/ factors[2] = 0.73; } - } else if ((AtomSymbol.equals("N"))&& - (ac.getAtom(i).getFormalCharge() != -1)) { - if (ac.getMaximumBondOrder(ac.getAtom(i)) == 1) { + } else if(AtomSymbol.equals("N")){ + if((ac.getMaximumBondOrder(ac.getAtom(i)) == 1) && + (ac.getAtom(i).getFormalCharge() != -1)) { factors[0] = 11.54; factors[1] = 10.82; factors[2] = 1.36; - } else if (ac.getMaximumBondOrder(ac.getAtom(i)) > 1 && ac.getMaximumBondOrder(ac.getAtom(i)) < 3) { + } else if ((ac.getMaximumBondOrder(ac.getAtom(i)) > 1 && ac.getMaximumBondOrder(ac.getAtom(i)) < 3) + ||((ac.getMaximumBondOrder(ac.getAtom(i)) == 1)&& ac.getAtom(i).getFormalCharge() == -1)) { factors[0] = 12.87; factors[1] = 11.15; factors[2] = 0.85; Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/BreakingBondReaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/BreakingBondReaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/BreakingBondReaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -1,24 +1,30 @@ package org.openscience.cdk.reaction.type; +import java.io.IOException; import java.util.ArrayList; 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.geometry.GeometryTools; import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IAtomContainerSet; 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.IMoleculeSet; import org.openscience.cdk.interfaces.IReactionSet; +import org.openscience.cdk.isomorphism.UniversalIsomorphismTester; +import org.openscience.cdk.isomorphism.matchers.QueryAtomContainer; +import org.openscience.cdk.isomorphism.matchers.QueryAtomContainerCreator; import org.openscience.cdk.layout.StructureDiagramGenerator; import org.openscience.cdk.reaction.IReactionProcess; import org.openscience.cdk.reaction.ReactionSpecification; import org.openscience.cdk.tools.LoggingTool; +import org.openscience.cdk.tools.ValencyChecker; /** * <p>IReactionProcess which a bond that is being broken to generate charges. @@ -26,7 +32,7 @@ * each bond is investigated twice:</p> * <pre>A-B => [A+] + |[B-]</pre> * <pre>A-B => [A-] + |[B+]</pre> - * + * <pre> It will not be created structures no possible, for example; C=O => [C-][O+]. * <pre> * ISetOfMolecules setOfReactants = DefaultChemObjectBuilder.getInstance().newSetOfMolecules(); * setOfReactants.addMolecule(new Molecule()); @@ -54,6 +60,7 @@ public class BreakingBondReaction implements IReactionProcess{ private LoggingTool logger; private boolean hasActiveCenter; + private ValencyChecker valChecker; /** * Constructor of the BreakingBondReaction object @@ -61,6 +68,13 @@ */ public BreakingBondReaction(){ logger = new LoggingTool(this); + try{ + valChecker = new ValencyChecker(); + }catch(IOException e){ + e.printStackTrace(); + }catch(ClassNotFoundException e){ + e.printStackTrace(); + } } /** * Gets the specification attribute of the BreakingBondReaction object @@ -106,6 +120,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). @@ -130,18 +146,16 @@ if(!hasActiveCenter){ setActiveCenters(reactant); } - + IAtomContainerSet acSet = reactant.getBuilder().newAtomContainerSet(); IBond[] bonds = reactants.getMolecule(0).getBonds(); for(int i = 0 ; i < bonds.length ; i++){ if(bonds[i].getFlag(CDKConstants.REACTIVE_CENTER)){ - - int atom1 = reactants.getMolecule(0).getAtomNumber(bonds[i].getAtoms()[0]); int atom2 = reactants.getMolecule(0).getAtomNumber(bonds[i].getAtoms()[1]); int bond = reactants.getMolecule(0).getBondNumber(bonds[i]); + /**/ - for (int j = 0; j < 2; j++) - { + for (int j = 0; j < 2; j++){ IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction(); reaction.addReactant(reactants.getMolecule(0)); @@ -164,7 +178,10 @@ charge = reactantCloned.getAtom(atom2).getFormalCharge(); reactantCloned.getAtom(atom2).setFormalCharge(charge-1); reactantCloned.addElectronContainer(new SingleElectron(reactantCloned.getAtom(atom2))); - if(order == 1) + /* an acceptor atom cannot be charged positive*/ + if(!valChecker.isSaturated(reactantCloned.getAtom(atom1),reactantCloned)) + continue; + if(order == 1)/*break molecule*/ setOfMolecules = fragmentMolecule(reactantCloned,bond); } else{ @@ -173,8 +190,11 @@ charge = reactantCloned.getAtom(atom1).getFormalCharge(); reactantCloned.getAtom(atom1).setFormalCharge(-1); reactantCloned.addElectronContainer(new SingleElectron(reactantCloned.getAtom(atom1))); - if(order == 1) - setOfMolecules = fragmentMolecule(reactantCloned,bond); + /* an acceptor atom cannot be charged positive*/ + if(!valChecker.isSaturated(reactantCloned.getAtom(atom2),reactantCloned)) + continue; + if(order == 1)/*break molecule*/ + setOfMolecules = fragmentMolecule(reactantCloned,bond);// TODO- better method } /* mapping */ @@ -186,28 +206,54 @@ reaction.addMapping(mapping); if(setOfMolecules != null) - for(int z = 0 ; z < setOfMolecules.getAtomContainerCount(); z++) - reaction.addProduct(setOfMolecules.getMolecule(z)); + for(int z = 0 ; z < setOfMolecules.getAtomContainerCount(); z++){ + IMolecule ac = setOfMolecules.getMolecule(z); + /* the fragmentation of Hydrogens can be produc duplicates*/ + if(existAC(acSet,ac)) + continue; + reaction.addProduct(ac); + acSet.addAtomContainer(ac); + } else reaction.addProduct(reactantCloned); - setOfReactions.addReaction(reaction); + + /*adding only that contains product*/ + if(reaction.getProductCount() != 0) + setOfReactions.addReaction(reaction); } } } return setOfReactions; - - } /** + * controll if the new product was already found before + * @param acSet + * @param fragment + * @return True, if it contains + */ + private boolean existAC(IAtomContainerSet acSet, IMolecule fragment) { + QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(fragment); + for(int i = 0; i < acSet.getAtomContainerCount(); i++){ + IAtomContainer ac = acSet.getAtomContainer(i); + try { + if(UniversalIsomorphismTester.isIsomorph(ac, qAC)) + return true; + } catch (CDKException e) { + e.printStackTrace(); + } + } + return false; + } + /** * fragment a molecule in two. It search where don't exist a connection between two atoms * @param reactantCloned IMolecule to fragment * @param bond Bond to remove * @return The ISetOfMolecules */ private IMoleculeSet fragmentMolecule(IMolecule molecule, int bond) throws CDKException{ - if(!GeometryTools.has2DCoordinates(molecule)){ +// if(!GeometryTools.has2DCoordinates(molecule)){ StructureDiagramGenerator sdg = new StructureDiagramGenerator(); sdg.setMolecule(molecule); molecule = sdg.getMolecule(); @@ -216,7 +262,7 @@ } catch (Exception e) { e.printStackTrace(); } - } +// } IMoleculeSet setOfFragments = molecule.getBuilder().newMoleculeSet(); IMolecule molecule1,molecule2; try { @@ -282,7 +328,8 @@ } /** * set the active center for this molecule. - * The active center will be those which correspond with A-B. + * The active center will be those which correspond with A-B. If + * the bond is simple, it will be breaked forming two fragments * <pre> * A: Atom * #/=/-: bond @@ -301,7 +348,6 @@ atom2.setFlag(CDKConstants.REACTIVE_CENTER,true); bonds[i].setFlag(CDKConstants.REACTIVE_CENTER,true); } - } /** * Gets the parameterNames attribute of the BreakingBondReaction object Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/DisplacementChargeFromAcceptorReaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/DisplacementChargeFromAcceptorReaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/DisplacementChargeFromAcceptorReaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -21,8 +21,8 @@ /** * <p>IReactionProcess which participate in movement resonance. * This reaction could be represented as two forms</p> - * <pre>X=A => [X-]-[A+]. X represents an acceptor atomType</pre> - * + * <pre>X=A => [X-]-[A+]. X represents an acceptor atomType. + * It is a case specific of the method BreakingBondReaction</pre> * <pre> * ISetOfMolecules setOfReactants = DefaultChemObjectBuilder.getInstance().newSetOfMolecules(); * setOfReactants.addMolecule(new Molecule()); @@ -102,6 +102,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). @@ -194,7 +196,8 @@ * set the active center for this molecule. * The active center will be those which correspond with A=B. * <pre> - * A: Atom with lone pair electrons + * A: Atom with lone pair electrons // TODO- not only the atoms with + * lone electrons are acceptor atoms. * =: Double bond * B: Atom * </pre> Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/DisplacementChargeFromDonorReaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/DisplacementChargeFromDonorReaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/DisplacementChargeFromDonorReaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -103,6 +103,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/ElectronImpactNBEReaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/ElectronImpactNBEReaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/ElectronImpactNBEReaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -100,6 +100,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/ElectronImpactPDBReaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/ElectronImpactPDBReaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/ElectronImpactPDBReaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -99,6 +99,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). @@ -126,12 +128,8 @@ IBond[] bonds = reactants.getMolecule(0).getBonds(); for(int i = 0 ; i < bonds.length ; i++){ if(bonds[i].getFlag(CDKConstants.REACTIVE_CENTER) && bonds[i].getOrder() == 2){ - - - /**/ - for (int j = 0; j < 2; j++) - { + for (int j = 0; j < 2; j++){ IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction(); reaction.addReactant(reactants.getMolecule(0)); IMolecule reactant = reaction.getReactants().getMolecule(0); @@ -149,13 +147,11 @@ double order = reactantCloned.getBond(posB1).getOrder(); reactantCloned.getBond(posB1).setOrder(order - 1); - if (j == 0) - { + if (j == 0){ reactantCloned.getAtom(posA1).setFormalCharge(1); reactantCloned.addElectronContainer( new SingleElectron(reactantCloned.getAtom(posA2))); - } else - { + } else{ reactantCloned.getAtom(posA2).setFormalCharge(1); reactantCloned.addElectronContainer( new SingleElectron(reactantCloned.getAtom(posA1))); Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/HyperconjugationReaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/HyperconjugationReaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/HyperconjugationReaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -5,14 +5,20 @@ import org.openscience.cdk.DefaultChemObjectBuilder; 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.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.IMoleculeSet; import org.openscience.cdk.interfaces.IReactionSet; +import org.openscience.cdk.isomorphism.UniversalIsomorphismTester; +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.ReactionSpecification; +import org.openscience.cdk.smiles.SmilesGenerator; import org.openscience.cdk.tools.LoggingTool; /** @@ -103,6 +109,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). @@ -127,68 +135,69 @@ if(!hasActiveCenter){ setActiveCenters(reactant); } + IAtomContainerSet acSet = reactant.getBuilder().newAtomContainerSet(); - IBond[] bonds = reactants.getMolecule(0).getBonds(); - for(int i = 0 ; i < bonds.length ; i++){ - if(bonds[i].getFlag(CDKConstants.REACTIVE_CENTER)){ + IAtom[] atoms = reactant.getAtoms(); + for(int i = 0 ; i < atoms.length ; i++) + if(atoms[i].getFlag(CDKConstants.REACTIVE_CENTER)&& atoms[i].getFormalCharge() == 1&& !(atoms[i].getSymbol().equals("H"))){ + IAtom[] atoms1 = reactant.getConnectedAtoms(atoms[i]); + for(int j = 0; j < atoms1.length; j++) + if(atoms1[j].getFlag(CDKConstants.REACTIVE_CENTER)&& !(atoms1[j].getSymbol().equals("H"))){ + IBond bond = reactant.getBond(atoms[i], atoms1[j]); + if(bond.getOrder() == 1) + if(bond.getFlag(CDKConstants.REACTIVE_CENTER)){ + IAtom[] atoms2 = reactant.getConnectedAtoms(atoms1[j]); + for(int k = 0; k < atoms2.length ; k++){ + if(atoms2[k].getSymbol().equals("H")){ - int atom1; - int atom2; - if(bonds[i].getAtoms()[0].getFormalCharge() == 1){ - atom1 = reactants.getMolecule(0).getAtomNumber(bonds[i].getAtoms()[0]); - atom2 = reactants.getMolecule(0).getAtomNumber(bonds[i].getAtoms()[1]); - }else{ - atom2 = reactants.getMolecule(0).getAtomNumber(bonds[i].getAtoms()[0]); - atom1 = reactants.getMolecule(0).getAtomNumber(bonds[i].getAtoms()[1]); - } - - int bond = reactants.getMolecule(0).getBondNumber(bonds[i]); + int atom1 = reactants.getMolecule(0).getAtomNumber(atoms[i]); + int atom2 = reactants.getMolecule(0).getAtomNumber(atoms1[j]); + int atomH = reactants.getMolecule(0).getAtomNumber(atoms2[k]); + int bond1 = reactants.getMolecule(0).getBondNumber(bond); - IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction(); - reaction.addReactant(reactants.getMolecule(0)); - - IMolecule reactantCloned; - try { - reactantCloned = (IMolecule) reactant.clone(); - } catch (CloneNotSupportedException e) { - throw new CDKException("Could not clone IMolecule!", e); + IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction(); + reaction.addReactant(reactants.getMolecule(0)); + + IMolecule reactantCloned; + try { + reactantCloned = (IMolecule) reactant.clone(); + } catch (CloneNotSupportedException e) { + throw new CDKException("Could not clone IMolecule!", e); + } + + double order = reactantCloned.getBond(bond1).getOrder(); + reactantCloned.getBond(bond1).setOrder(order + 1); + + int charge = reactantCloned.getAtom(atom1).getFormalCharge(); + reactantCloned.getAtom(atom1).setFormalCharge(charge-1); + + reactantCloned.removeAtomAndConnectedElectronContainers(reactantCloned.getAtom(atomH)); + + + /* mapping */ + IMapping mapping = DefaultChemObjectBuilder.getInstance().newMapping(bond, reactantCloned.getBond(bond1)); + reaction.addMapping(mapping); + mapping = DefaultChemObjectBuilder.getInstance().newMapping(atoms[i], reactantCloned.getAtom(atom1)); + reaction.addMapping(mapping); + mapping = DefaultChemObjectBuilder.getInstance().newMapping(atoms2[j], reactantCloned.getAtom(atom2)); + reaction.addMapping(mapping); + + if(existAC(acSet,reactantCloned)) + continue; + acSet.addAtomContainer(reactantCloned); + + reaction.addProduct(reactantCloned); + + IAtom hydrogen = reactants.getBuilder().newAtom("H"); + hydrogen.setFormalCharge(1); + IMolecule proton = reactants.getBuilder().newMolecule(); + proton.addAtom(hydrogen); + reaction.addProduct(proton); + + setOfReactions.addReaction(reaction); + } + } } - - double order = reactantCloned.getBond(bond).getOrder(); - reactantCloned.getBond(bond).setOrder(order + 1); - - int charge = reactantCloned.getAtom(atom1).getFormalCharge(); - reactantCloned.getAtom(atom1).setFormalCharge(charge-1); - - int numbH = reactantCloned.getAtom(atom2).getHydrogenCount(); - if(numbH != 0) - reactantCloned.getAtom(atom2).setHydrogenCount(numbH-1); - else{ - IAtom hyd = getHydrogenConnected(reactantCloned,reactantCloned.getAtom(atom2)); - if(hyd == null) - continue; - reactantCloned.removeAtomAndConnectedElectronContainers(hyd); - } - - - /* mapping */ - IMapping mapping = DefaultChemObjectBuilder.getInstance().newMapping(bonds[i], reactantCloned.getBond(bond)); - reaction.addMapping(mapping); - mapping = DefaultChemObjectBuilder.getInstance().newMapping(bonds[i].getAtoms()[0], reactantCloned.getAtom(atom1)); - reaction.addMapping(mapping); - mapping = DefaultChemObjectBuilder.getInstance().newMapping(bonds[i].getAtoms()[1], reactantCloned.getAtom(atom2)); - reaction.addMapping(mapping); - - - reaction.addProduct(reactantCloned); - - IAtom hydrogen = reactants.getBuilder().newAtom("H"); - hydrogen.setFormalCharge(1); - IMolecule proton = reactants.getBuilder().newMolecule(); - proton.addAtom(hydrogen); - reaction.addProduct(proton); - - setOfReactions.addReaction(reaction); } } @@ -199,7 +208,7 @@ } /** * set the active center for this molecule. - * The active center will be those which correspond with [A+]-B. + * The active center will be those which correspond with [A+]-B([H]). * <pre> * A: Atom with charge * -: Singlebond @@ -210,36 +219,45 @@ * @throws CDKException */ private void setActiveCenters(IMolecule reactant) throws CDKException { - IBond[] bonds = reactant.getBonds(); - for(int i = 0 ; i < bonds.length ; i++){ - IAtom atom1 = bonds[i].getAtoms()[0]; - IAtom atom2 = bonds[i].getAtoms()[1]; - if(bonds[i].getOrder() == 1 && - ((atom1.getFormalCharge() == 1 && atom2.getFormalCharge() == 0 && reactant.getSingleElectron(atom2).length == 0 && - (atom2.getHydrogenCount() != 0 || getHydrogenConnected(reactant, atom2) != null))|| - (atom2.getFormalCharge() == 1 && atom1.getFormalCharge() == 0 && reactant.getSingleElectron(atom1).length == 0 && - (atom1.getHydrogenCount() != 0 || getHydrogenConnected(reactant, atom1) != null)))){ - atom1.setFlag(CDKConstants.REACTIVE_CENTER,true); - atom2.setFlag(CDKConstants.REACTIVE_CENTER,true); - bonds[i].setFlag(CDKConstants.REACTIVE_CENTER,true); + IAtom[] atoms = reactant.getAtoms(); + for(int i = 0 ; i < atoms.length ; i++) + if(!atoms[i].getSymbol().equals("H")&& atoms[i].getFormalCharge() == 1){ + IAtom[] atoms1 = reactant.getConnectedAtoms(atoms[i]); + for(int j = 0; j < atoms1.length; j++) + if(!atoms1[j].getSymbol().equals("H")){ + IBond bond = reactant.getBond(atoms[i], atoms1[j]); + if(bond.getOrder() == 1){ + IAtom[] atoms2 = reactant.getConnectedAtoms(atoms1[j]); + for(int k = 0; k < atoms2.length ; k++){ + if(atoms2[k].getSymbol().equals("H")){ + atoms[i].setFlag(CDKConstants.REACTIVE_CENTER,true); + atoms1[j].setFlag(CDKConstants.REACTIVE_CENTER,true); + bond.setFlag(CDKConstants.REACTIVE_CENTER,true); + } + } + } + } - } } /** - * get the hydrogen atom which is connected for this atom - * - * @param molecule - * @param atom - * @return The IAtom hydrogen. + * controll if the new product was already found before + * @param acSet + * @param fragment + * @return True, if it contains */ - private IAtom getHydrogenConnected(IMolecule molecule, IAtom atom){ - IAtom[] atomsCo = molecule.getConnectedAtoms(atom); - IAtom atomH = null; - for(int i = 0 ; i < atomsCo.length ; i++) - if(atomsCo[i].getSymbol().equals("H")) - return atomsCo[i]; - return atomH; + private boolean existAC(IAtomContainerSet acSet, IMolecule fragment) { + QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(fragment); + for(int i = 0; i < acSet.getAtomContainerCount(); i++){ + IAtomContainer ac = acSet.getAtomContainer(i); + try { + if(UniversalIsomorphismTester.isIsomorph(ac, qAC)) + return true; + } catch (CDKException e) { + e.printStackTrace(); + } + } + return false; } /** * Gets the parameterNames attribute of the HyperconjugationReaction object Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion1Reaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion1Reaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion1Reaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -106,6 +106,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). @@ -140,7 +142,7 @@ IAtom[] atoms = reactants.getMolecule(0).getAtoms(); for(int i = 0 ; i < atoms.length ; i++){ if(atoms[i].getFlag(CDKConstants.REACTIVE_CENTER) && atoms[i].getFormalCharge() == -1 - && reactant.getLonePairCount(atoms[i]) > 1 ){ + && reactant.getLonePairCount(atoms[i]) > 0 ){ IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction(); reaction.addReactant(reactant); @@ -211,7 +213,7 @@ private void setActiveCenters(IMolecule reactant) throws CDKException { IAtom[] atoms = reactant.getAtoms(); for(int i = 0 ; i < atoms.length ; i++) - if(atoms[i].getFormalCharge() == -1 && reactant.getLonePairCount(atoms[i]) > 1 ){ + if(atoms[i].getFormalCharge() == -1 && reactant.getLonePairCount(atoms[i]) > 0 ){ IBond[] bonds = reactant.getConnectedBonds(atoms[i]); for(int j = 0 ; j < bonds.length ; j++){ if(bonds[j].getOrder() == 1.0){ Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion2Reaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion2Reaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion2Reaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -103,6 +103,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). @@ -137,9 +139,8 @@ IAtom[] atoms = reactants.getMolecule(0).getAtoms(); for(int i = 0 ; i < atoms.length ; i++){ if(atoms[i].getFlag(CDKConstants.REACTIVE_CENTER)&& atoms[i].getFormalCharge() == -1 ){ - IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction(); - reaction.addReactant(reactant); + IBond[] bonds = reactant.getConnectedBonds(atoms[i]); for(int j = 0 ; j < bonds.length ; j++){ @@ -147,7 +148,9 @@ IAtom atom = bonds[j].getConnectedAtom(reactant.getAtom(i)); IBond[] bondsI = reactant.getConnectedBonds(atom); for(int k = 0 ; k < bondsI.length ; k++){ - if(bondsI[k].getFlag(CDKConstants.REACTIVE_CENTER) && bondsI[k].getOrder() == 2.0 && bondsI[k].getConnectedAtom(atom).getFormalCharge() == 0){ + if(bondsI[k].getFlag(CDKConstants.REACTIVE_CENTER) && bondsI[k].getOrder() == 2.0 && bondsI[k].getConnectedAtom(atom).getFormalCharge() >= 0){ + IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction(); + reaction.addReactant(reactant); /* positions atoms and bonds */ int atom0P = reactant.getAtomNumber(atoms[i]); int bond1P = reactant.getBondNumber(bonds[j]); @@ -225,7 +228,7 @@ continue; IBond[] bondsI = reactant.getConnectedBonds(atom); for(int k = 0 ; k < bondsI.length ; k++){ - if(bondsI[k].getOrder() == 2.0 && bondsI[k].getConnectedAtom(atom).getFormalCharge() == 0){ + if(bondsI[k].getOrder() == 2.0 && bondsI[k].getConnectedAtom(atom).getFormalCharge() >= 0){ atoms[i].setFlag(CDKConstants.REACTIVE_CENTER,true); atom.setFlag(CDKConstants.REACTIVE_CENTER,true); bondsI[k].getConnectedAtom(atom).setFlag(CDKConstants.REACTIVE_CENTER,true); Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion3Reaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion3Reaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementAnion3Reaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -105,6 +105,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation1Reaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation1Reaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation1Reaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -107,6 +107,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation2Reaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation2Reaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation2Reaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -104,6 +104,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). @@ -219,8 +221,8 @@ * @throws CDKException */ private void setActiveCenters(IMolecule reactant) throws CDKException { - if(AtomContainerManipulator.getTotalNegativeFormalCharge(reactant) != 0) - return; +// if(AtomContainerManipulator.getTotalNegativeFormalCharge(reactant) != 0) +// return; IAtom[] atoms = reactant.getAtoms(); for(int i = 0 ; i < atoms.length ; i++) if(atoms[i].getFormalCharge() == 1 ){ @@ -229,17 +231,19 @@ for(int j = 0 ; j < bonds.length ; j++){ if(bonds[j].getOrder() == 1.0){ IAtom atom = bonds[j].getConnectedAtom(reactant.getAtom(i)); - IBond[] bondsI = reactant.getConnectedBonds(atom); - for(int k = 0 ; k < bondsI.length ; k++){ - if(bondsI[k].getOrder() == 2.0){ - IAtom atomConn = bondsI[k].getConnectedAtom(atom); - ILonePair[] lp = reactant.getLonePairs(atomConn); - if(lp.length == 0){ - atoms[i].setFlag(CDKConstants.REACTIVE_CENTER,true); - atom.setFlag(CDKConstants.REACTIVE_CENTER,true); - atomConn.setFlag(CDKConstants.REACTIVE_CENTER,true); - bonds[j].setFlag(CDKConstants.REACTIVE_CENTER,true); - bondsI[k].setFlag(CDKConstants.REACTIVE_CENTER,true); + if(atom.getFormalCharge() == 0){ + IBond[] bondsI = reactant.getConnectedBonds(atom); + for(int k = 0 ; k < bondsI.length ; k++){ + if(bondsI[k].getOrder() == 2.0){ + IAtom atomConn = bondsI[k].getConnectedAtom(atom); + ILonePair[] lp = reactant.getLonePairs(atomConn); + if(lp.length == 0 && atomConn.getFormalCharge() == 0){ + atoms[i].setFlag(CDKConstants.REACTIVE_CENTER,true); + atom.setFlag(CDKConstants.REACTIVE_CENTER,true); + atomConn.setFlag(CDKConstants.REACTIVE_CENTER,true); + bonds[j].setFlag(CDKConstants.REACTIVE_CENTER,true); + bondsI[k].setFlag(CDKConstants.REACTIVE_CENTER,true); + } } } } Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation3Reaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation3Reaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementCation3Reaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -104,6 +104,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical1Reaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical1Reaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical1Reaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -107,6 +107,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical2Reaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical2Reaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical2Reaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -106,6 +106,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). Modified: trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical3Reaction.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical3Reaction.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/reaction/type/RearrangementRadical3Reaction.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -105,6 +105,8 @@ /** * Initiate process. + * It is needed to call the addExplicitHydrogensToSatisfyValency + * from the class tools.HydrogenAdder. * *@param reactants reactants of the reaction. *@param agents agents of the reaction (Must be in this case null). Modified: trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/atomic/SigmaElectronegativityDescriptorTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/atomic/SigmaElectronegativityDescriptorTest.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/atomic/SigmaElectronegativityDescriptorTest.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -177,7 +177,7 @@ for (int i = 0 ; i < 4 ; i++){ double result= ((DoubleResult)descriptor.calculate(mol.getAtom(i),mol).getValue()).doubleValue(); - assertEquals(testResult[i],result,0.005); + assertEquals(testResult[i],result,0.01); } } } Modified: trunk/cdk/src/org/openscience/cdk/test/reaction/type/BreakingBondReactionTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/reaction/type/BreakingBondReactionTest.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/test/reaction/type/BreakingBondReactionTest.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -5,6 +5,7 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.openscience.cdk.Atom; import org.openscience.cdk.CDKConstants; import org.openscience.cdk.DefaultChemObjectBuilder; import org.openscience.cdk.Molecule; @@ -48,7 +49,8 @@ } /** - * A unit test suite for JUnit. Reaction: C=O => [C+]-[O-] + [C-]-[O+] + * A unit test suite for JUnit. Reaction: + * C(H)(H)=O => [C+](H)(H)-[O-] + [C+](H)=O + * Automatic sarch of the centre active. * * @return The test suite @@ -59,7 +61,7 @@ /*C=O*/ Molecule molecule = (new SmilesParser()).parseSmiles("C=O"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); @@ -71,34 +73,41 @@ /* iniciate */ IReactionSet setOfReactions = type.initiate(setOfReactants, null); - Assert.assertEquals(2, setOfReactions.getReactionCount()); + Assert.assertEquals(3, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); - Assert.assertEquals(1, setOfReactions.getReaction(1).getProductCount()); + Assert.assertEquals(2, setOfReactions.getReaction(1).getProductCount()); - IMolecule product = setOfReactions.getReaction(1).getProducts().getMolecule(0); + IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0); /*[C+]-[O-]*/ Molecule molecule2 = (new SmilesParser()).parseSmiles("[C+]-[O-]"); - adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule2); - lpcheck.newSaturate(molecule2); - setOfReactants.addMolecule(molecule2); - + molecule2.addAtom(new Atom("H")); + molecule2.addAtom(new Atom("H")); + molecule2.addBond(0, 2, 1); + molecule2.addBond(0, 3, 1); QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,qAC)); - product = setOfReactions.getReaction(0).getProducts().getMolecule(0); - /*[C+]-[O-]*/ - molecule2 = (new SmilesParser()).parseSmiles("[C-]-[O+]"); - adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule2); - lpcheck.newSaturate(molecule2); - setOfReactants.addMolecule(molecule2); - + product = setOfReactions.getReaction(1).getProducts().getMolecule(1); + /*[H-] + [C+](H)=O*/ + molecule2 = (new SmilesParser()).parseSmiles("C=O"); + molecule2.getAtom(0).setFormalCharge(+1); + molecule2.addAtom(new Atom("H")); + molecule2.addBond(0, 2, 1); qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,qAC)); + + product = setOfReactions.getReaction(2).getProducts().getMolecule(1); + /*[H+] + [C-](H)=O*/ + molecule2 = (new SmilesParser()).parseSmiles("C=O"); + molecule2.getAtom(0).setFormalCharge(-1); + molecule2.addAtom(new Atom("H")); + molecule2.addBond(0, 2, 1); + qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); + Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,qAC)); + } /** - * A unit test suite for JUnit. Reaction: C=O => [C+]-[O-] + [C-]-[O+] + * A unit test suite for JUnit. Reaction: C=O => [C+]-[O-] * Manually put of the centre active. * * @return The test suite @@ -108,7 +117,7 @@ /*C=O*/ Molecule molecule = (new SmilesParser()).parseSmiles("C=O"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); @@ -124,10 +133,19 @@ /* iniciate */ IReactionSet setOfReactions = type.initiate(setOfReactants, null); - Assert.assertEquals(2, setOfReactions.getReactionCount()); + Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); - + IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0); + /*[C+]-[O-]*/ + Molecule molecule2 = (new SmilesParser()).parseSmiles("[C+]-[O-]"); + molecule2.addAtom(new Atom("H")); + molecule2.addAtom(new Atom("H")); + molecule2.addBond(0, 2, 1); + molecule2.addBond(0, 3, 1); + QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); + Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,qAC)); + } /** @@ -141,7 +159,7 @@ /*C=O*/ Molecule molecule = (new SmilesParser()).parseSmiles("C=O"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); @@ -163,5 +181,59 @@ IAtom mappedProductA2 = (IAtom)ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(1)); assertEquals(mappedProductA2, product.getAtom(1)); } + /** + * A unit test suite for JUnit. Reaction: + * F-CC => [F-] + [C+]C + * + * @return The test suite + */ + public void testBB_1() throws ClassNotFoundException, CDKException, java.lang.Exception { + IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet(); + + /*FCC*/ + Molecule molecule = (new SmilesParser()).parseSmiles("FCC"); + HydrogenAdder adder = new HydrogenAdder(); + adder.addExplicitHydrogensToSatisfyValency(molecule); + LonePairElectronChecker lpcheck = new LonePairElectronChecker(); + lpcheck.newSaturate(molecule); + setOfReactants.addMolecule(molecule); + + /*manually put the centre active*/ + molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER,true); + molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER,true); + molecule.getBond(0).setFlag(CDKConstants.REACTIVE_CENTER,true); + + Object[] params = {Boolean.TRUE}; + type.setParameters(params); + + /* iniciate */ + IReactionSet setOfReactions = type.initiate(setOfReactants, null); + + Assert.assertEquals(1, setOfReactions.getReactionCount()); + Assert.assertEquals(2, setOfReactions.getReaction(0).getProductCount()); + IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0); + /*[C+]C*/ + Molecule molecule2 = (new SmilesParser()).parseSmiles("[C+]C"); + molecule2.addAtom(new Atom("H")); + molecule2.addAtom(new Atom("H")); + molecule2.addBond(0, 2, 1); + molecule2.addBond(0, 3, 1); + molecule2.addAtom(new Atom("H")); + molecule2.addAtom(new Atom("H")); + molecule2.addAtom(new Atom("H")); + molecule2.addBond(1, 4, 1); + molecule2.addBond(1, 5, 1); + molecule2.addBond(1, 6, 1); + + QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); + Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,qAC)); + + product = setOfReactions.getReaction(0).getProducts().getMolecule(1); + /*F-]*/ + molecule2 = (new SmilesParser()).parseSmiles("[F-]"); + qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); + Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,qAC)); + + } } Modified: trunk/cdk/src/org/openscience/cdk/test/reaction/type/DisplacementChargeFromAcceptorReactionTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/reaction/type/DisplacementChargeFromAcceptorReactionTest.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/test/reaction/type/DisplacementChargeFromAcceptorReactionTest.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -5,6 +5,7 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.openscience.cdk.Atom; import org.openscience.cdk.CDKConstants; import org.openscience.cdk.DefaultChemObjectBuilder; import org.openscience.cdk.Molecule; @@ -59,7 +60,7 @@ /*C=O*/ Molecule molecule = (new SmilesParser()).parseSmiles("C=O"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); @@ -78,9 +79,12 @@ /*[C+]-[O-]*/ Molecule molecule2 = (new SmilesParser()).parseSmiles("[C+]-[O-]"); - adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule2); - lpcheck.newSaturate(molecule2); + molecule2.addAtom(new Atom("H")); + molecule2.addAtom(new Atom("H")); + molecule2.addBond(0, 2, 1); + molecule2.addBond(0, 3, 1); + + lpcheck.newSaturate(molecule2); setOfReactants.addMolecule(molecule2); QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); @@ -97,7 +101,7 @@ /*C=O*/ Molecule molecule = (new SmilesParser()).parseSmiles("C=O"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); @@ -115,9 +119,6 @@ Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); - - - } /** * A unit test suite for JUnit. Reaction: C=O => [C+]-[O-] @@ -130,7 +131,7 @@ /*C=O*/ Molecule molecule = (new SmilesParser()).parseSmiles("C=O"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); @@ -154,7 +155,6 @@ } /** * A unit test suite for JUnit. Reaction: N=CC => [N-]-[C+]C - * Test of mapped between the reactant and product. Only is mapped the centre active. * * @return The test suite */ @@ -163,7 +163,7 @@ /*C=O*/ Molecule molecule = (new SmilesParser()).parseSmiles("N=CC"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); @@ -176,18 +176,21 @@ IReactionSet setOfReactions = type.initiate(setOfReactants, null); IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0); - + Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); /*[N-]-[C+]C*/ Molecule molecule2 = (new SmilesParser()).parseSmiles("[N-]-[C+]C"); - adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule2); - lpcheck.newSaturate(molecule2); - setOfReactants.addMolecule(molecule2); - - QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); + for(int i = 0; i < 5; i++) + molecule2.addAtom(new Atom("H")); + molecule2.addBond(0, 3, 1); + molecule2.addBond(1, 4, 1); + molecule2.addBond(2, 5, 1); + molecule2.addBond(2, 6, 1); + molecule2.addBond(2, 7, 1); + + QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,qAC)); } Modified: trunk/cdk/src/org/openscience/cdk/test/reaction/type/DisplacementChargeFromDonorReactionTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/reaction/type/DisplacementChargeFromDonorReactionTest.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/test/reaction/type/DisplacementChargeFromDonorReactionTest.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -5,6 +5,7 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.openscience.cdk.Atom; import org.openscience.cdk.CDKConstants; import org.openscience.cdk.DefaultChemObjectBuilder; import org.openscience.cdk.Molecule; @@ -59,7 +60,7 @@ /*O-C=C*/ Molecule molecule = (new SmilesParser()).parseSmiles("O-C=C"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); @@ -78,9 +79,14 @@ /*[O+]=C-[C+]*/ Molecule molecule2 = (new SmilesParser()).parseSmiles("[O+]=C-[C-]"); - adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule2); - lpcheck.newSaturate(molecule2); + for(int i = 0; i < 4; i++) + molecule2.addAtom(new Atom("H")); + molecule2.addBond(0, 3, 1); + molecule2.addBond(1, 4, 1); + molecule2.addBond(2, 5, 1); + molecule2.addBond(2, 6, 1); + + lpcheck.newSaturate(molecule2); setOfReactants.addMolecule(molecule2); QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); @@ -97,7 +103,7 @@ /*O-C=C*/ Molecule molecule = (new SmilesParser()).parseSmiles("O-C=C"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); @@ -117,8 +123,6 @@ Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); - - } /** @@ -132,7 +136,7 @@ /*O-C=C*/ Molecule molecule = (new SmilesParser()).parseSmiles("O-C=C"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); @@ -163,10 +167,10 @@ */ public void testN() throws ClassNotFoundException, CDKException, java.lang.Exception { IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet(); - /*O-C=C*/ + /*C=N-C=C*/ Molecule molecule = (new SmilesParser()).parseSmiles("C=N-C=C"); HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); + adder.addExplicitHydrogensToSatisfyValency(molecule); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.newSaturate(molecule); setOfReactants.addMolecule(molecule); Modified: trunk/cdk/src/org/openscience/cdk/test/reaction/type/HyperconjugationReactionTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/reaction/type/HyperconjugationReactionTest.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/test/reaction/type/HyperconjugationReactionTest.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -5,6 +5,7 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.openscience.cdk.Atom; import org.openscience.cdk.DefaultChemObjectBuilder; import org.openscience.cdk.Molecule; import org.openscience.cdk.exception.CDKException; @@ -53,9 +54,16 @@ /*[C+]CC*/ Molecule molecule = (new SmilesParser()).parseSmiles("[C+]CC"); - HydrogenAdder adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule); - setOfReactants.addMolecule(molecule); + for(int i = 0; i < 7 ; i++) + molecule.addAtom(new Atom("H")); + molecule.addBond(0, 3, 1); + molecule.addBond(0, 4, 1); + molecule.addBond(1, 5, 1); + molecule.addBond(1, 6, 1); + molecule.addBond(2, 7, 1); + molecule.addBond(2, 8, 1); + molecule.addBond(2, 9, 1); + setOfReactants.addMolecule(molecule); /*automatic search of the centre active*/ Object[] params = {Boolean.FALSE}; @@ -70,17 +78,15 @@ IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0); /*C=CC*/ Molecule molecule2 = (new SmilesParser()).parseSmiles("C=CC"); - adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule2); - + HydrogenAdder hAdder = new HydrogenAdder(); + hAdder.addExplicitHydrogensToSatisfyValency(molecule2); + QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,qAC)); product = setOfReactions.getReaction(0).getProducts().getMolecule(1); /*[H+]*/ molecule2 = (new SmilesParser()).parseSmiles("[H+]"); - adder = new HydrogenAdder(); - adder.addImplicitHydrogensToSatisfyValency(molecule2); qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2,qAC)); Modified: trunk/cdk/src/org/openscience/cdk/test/reaction/type/RearrangementAnion2ReactionTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/reaction/type/RearrangementAnion2ReactionTest.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/test/reaction/type/RearrangementAnion2ReactionTest.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -18,6 +18,7 @@ import org.openscience.cdk.isomorphism.matchers.QueryAtomContainerCreator; import org.openscience.cdk.reaction.IReactionProcess; import org.openscience.cdk.reaction.type.RearrangementAnion2Reaction; +import org.openscience.cdk.smiles.SmilesGenerator; import org.openscience.cdk.smiles.SmilesParser; import org.openscience.cdk.test.CDKTestCase; import org.openscience.cdk.tools.HydrogenAdder; @@ -203,11 +204,11 @@ type.setParameters(params); IReactionSet setOfReactions = type.initiate(setOfReactants, null); - Assert.assertEquals(1, setOfReactions.getReactionCount()); + Assert.assertEquals(2, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0); - + /*[F+]=C1-[C=]-C-[C-]-C=C1*/ Molecule molecule2 = (new SmilesParser()).parseSmiles("[F+]=C1-C=C-[C-]-C=C1"); adder.addImplicitHydrogensToSatisfyValency(molecule2); Modified: trunk/cdk/src/org/openscience/cdk/test/tools/StructureResonanceGeneratorTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/tools/StructureResonanceGeneratorTest.java 2006-08-09 13:01:59 UTC (rev 6766) +++ trunk/cdk/src/org/openscience/cdk/test/tools/StructureResonanceGeneratorTest.java 2006-08-09 13:22:44 UTC (rev 6767) @@ -5,21 +5,22 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.openscience.cdk.Atom; import org.openscience.cdk.CDKConstants; import org.openscience.cdk.Molecule; import org.openscience.cdk.SingleElectron; import org.openscience.cdk.exception.CDKException; import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainerSet; import org.openscience.cdk.interfaces.ILonePair; -import org.openscience.cdk.interfaces.IAtomContainerSet; import org.openscience.cdk.isomorphism.UniversalIsomorphismTester; import org.openscience.cdk.isomorphism.matchers.QueryAtomContainer; import org.openscience.cdk.isomorphism.matchers.QueryAtomContainerCreator; import org.openscience.cdk.smiles.SmilesParser; import org.openscience.cdk.test.CDKTestCase; import org.openscience.cdk.tools.HydrogenAdder; +import org.openscience.cdk.tools.LonePairElectronChecker; import org.opens... [truncated message content] |