4
* $Date: 2006-03-29 10:27:08 +0200 (Wed, 29 Mar 2006) $
7
* Copyright (C) 2006-2007 Miguel Rojas <miguel.rojas@uni-koeln.de>
9
* Contact: cdk-devel@lists.sourceforge.net
11
* This program is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU Lesser General Public License
13
* as published by the Free Software Foundation; either version 2.1
14
* of the License, or (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
21
* You should have received a copy of the GNU Lesser General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25
package org.openscience.cdk.reaction.type;
28
import java.util.Iterator;
29
import java.util.List;
31
import org.openscience.cdk.CDKConstants;
32
import org.openscience.cdk.DefaultChemObjectBuilder;
33
import org.openscience.cdk.Molecule;
34
import org.openscience.cdk.Ring;
35
import org.openscience.cdk.SingleElectron;
36
import org.openscience.cdk.aromaticity.HueckelAromaticityDetector;
37
import org.openscience.cdk.exception.CDKException;
38
import org.openscience.cdk.interfaces.IAtom;
39
import org.openscience.cdk.interfaces.IAtomContainer;
40
import org.openscience.cdk.interfaces.IMapping;
41
import org.openscience.cdk.interfaces.IMolecule;
42
import org.openscience.cdk.interfaces.IMoleculeSet;
43
import org.openscience.cdk.interfaces.IReaction;
44
import org.openscience.cdk.interfaces.IReactionSet;
45
import org.openscience.cdk.interfaces.IRingSet;
46
import org.openscience.cdk.interfaces.ISingleElectron;
47
import org.openscience.cdk.reaction.IReactionProcess;
48
import org.openscience.cdk.reaction.ReactionSpecification;
49
import org.openscience.cdk.ringsearch.AllRingsFinder;
50
import org.openscience.cdk.tools.HOSECodeGenerator;
51
import org.openscience.cdk.tools.LoggingTool;
55
* This reaction could be represented as [A*]-(C)_4-C5[H] => A([H])-(C_4)-[C5*]. Due to
56
* the single electron of atom A.</p>
57
* <p>Make sure that the molecule has the corresponend lone pair electrons
58
* for each atom. You can use the method: <pre> LonePairElectronChecker </pre>
61
* IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
62
* setOfReactants.addMolecule(new Molecule());
63
* IReactionProcess type = new HydrogenRearrangementDeltaReaction();
64
* Object[] params = {Boolean.FALSE};
65
type.setParameters(params);
66
* IReactionSet setOfReactions = type.initiate(setOfReactants, null);
69
* <p>We have the possibility to localize the reactive center. Good method if you
70
* want to localize the reaction in a fixed point</p>
71
* <pre>atoms[0].setFlag(CDKConstants.REACTIVE_CENTER,true);</pre>
72
* <p>Moreover you must put the parameter Boolean.TRUE</p>
73
* <p>If the reactive center is not localized then the reaction process will
74
* try to find automatically the posible reactive center.</p>
77
* @author Miguel Rojas
79
* @cdk.created 2006-10-20
80
* @cdk.module reaction
81
* @cdk.set reaction-types
84
public class HydrogenRearrangementDeltaReaction implements IReactionProcess{
85
private LoggingTool logger;
86
private boolean hasActiveCenter;
89
* Constructor of the HydrogenRearrangementDeltaReaction object
92
public HydrogenRearrangementDeltaReaction(){
93
logger = new LoggingTool(this);
96
* Gets the specification attribute of the HydrogenRearrangementDeltaReaction object
98
*@return The specification value
100
public ReactionSpecification getSpecification() {
101
return new ReactionSpecification(
102
"http://almost.cubic.uni-koeln.de/jrg/Members/mrc/reactionDict/reactionDict#HydrogenRearrangementDeltaReaction",
103
this.getClass().getName(),
104
"$Id: HydrogenRearrangementDeltaReaction.java,v 1.6 2006/04/01 08:26:47 mrc Exp $",
105
"The Chemistry Development Kit");
109
* Sets the parameters attribute of the HydrogenRearrangementDeltaReaction object
111
*@param params The parameter is if the molecule has already fixed the center active or not. It
112
* should be set before to inize the reaction with a setFlag: CDKConstants.REACTIVE_CENTER
113
*@exception CDKException Description of the Exception
115
public void setParameters(Object[] params) throws CDKException {
116
if (params.length > 1) {
117
throw new CDKException("HydrogenRearrangementDeltaReaction only expects one parameter");
119
if (!(params[0] instanceof Boolean)) {
120
throw new CDKException("The parameter 1 must be of type boolean");
122
hasActiveCenter = ((Boolean) params[0]).booleanValue();
127
* Gets the parameters attribute of the HydrogenRearrangementDeltaReaction object
129
*@return The parameters value
131
public Object[] getParameters() {
132
Object[] params = new Object[1];
133
params[0] = new Boolean (hasActiveCenter);
139
* It is needed to call the addExplicitHydrogensToSatisfyValency
140
* from the class tools.HydrogenAdder.
142
*@param reactants reactants of the reaction.
143
*@param agents agents of the reaction (Must be in this case null).
145
*@exception CDKException Description of the Exception
147
public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws CDKException{
149
logger.debug("initiate reaction: HydrogenRearrangementDeltaReaction");
151
if (reactants.getMoleculeCount() != 1) {
152
throw new CDKException("HydrogenRearrangementDeltaReaction only expects one reactant");
154
if (agents != null) {
155
throw new CDKException("HydrogenRearrangementDeltaReaction don't expects agents");
158
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newReactionSet();
159
IMolecule reactant = reactants.getMolecule(0);
161
/* if the parameter hasActiveCenter is not fixed yet, set the active centers*/
162
if(!hasActiveCenter){
163
setActiveCenters(reactant);
166
HOSECodeGenerator hcg = new HOSECodeGenerator();
167
for(int i = 0; i < reactant.getAtomCount(); i++) {
168
IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction();
169
reaction.addReactant(reactant);
171
IAtom atomi = reactant.getAtom(i);
172
if(reactant.getConnectedSingleElectronsCount(atomi) == 1 && atomi.getFlag(CDKConstants.REACTIVE_CENTER)) {
173
hcg.getSpheres((Molecule) reactant, atomi, 5, true);
174
List atoms = hcg.getNodesInSphere(5);
175
for(int j = 0 ; j < atoms.size() ; j++){
176
IAtom atom4 = (IAtom)atoms.get(j);
178
if(atom4.getFormalCharge() == 0 && !atom4.equals("H") &&
179
reactant.getMaximumBondOrder(atom4) == 1 && atom4.getFlag(CDKConstants.REACTIVE_CENTER)){
180
Iterator iterat = reactant.getConnectedAtomsList(atom4).iterator();
181
while(iterat.hasNext()){
182
IAtom hydrogen = (IAtom) iterat.next();
183
if(hydrogen.getSymbol().equals("H") && hydrogen.getFlag(CDKConstants.REACTIVE_CENTER)){
184
/* positions atoms and bonds */
185
int atom0P = reactant.getAtomNumber(atomi);
186
int atom4P = reactant.getAtomNumber(atom4);
187
int atomHP = reactant.getAtomNumber(hydrogen);
190
IAtomContainer acCloned;
192
acCloned = (IAtomContainer)reactant.clone();
193
} catch (CloneNotSupportedException e) {
194
throw new CDKException("Could not clone IMolecule!", e);
198
List selectron = acCloned.getConnectedSingleElectronsList(acCloned.getAtom(atom0P));
199
acCloned.removeSingleElectron((ISingleElectron)selectron.get(selectron.size() -1));
200
acCloned.addBond(atom0P,atomHP, 1);
201
acCloned.removeBond(acCloned.getAtom(atom4P), acCloned.getAtom(atomHP));
203
acCloned.addSingleElectron(new SingleElectron(acCloned.getAtom(atom4P)));
207
IMapping mapping = DefaultChemObjectBuilder.getInstance().newMapping(atomi, acCloned.getAtom(atom0P));
208
reaction.addMapping(mapping);
209
mapping = DefaultChemObjectBuilder.getInstance().newMapping(atom4, acCloned.getAtom(atom4P));
210
reaction.addMapping(mapping);
211
mapping = DefaultChemObjectBuilder.getInstance().newMapping(hydrogen, acCloned.getAtom(atomHP));
212
reaction.addMapping(mapping);
214
reaction.addProduct((IMolecule) acCloned);
215
setOfReactions.addReaction(reaction);
224
return setOfReactions;
227
* set the active center for this molecule.
228
* The active center will be those which correspond with [A*]-(C)_4-C5[H]
230
* C: Atom with single electron
231
* C5: Atom with Hydrogen
234
* @param reactant The molecule to set the activity
235
* @throws CDKException
237
private void setActiveCenters(IMolecule reactant) throws CDKException {
238
HOSECodeGenerator hcg = new HOSECodeGenerator();
239
IRingSet ringSet = null;
240
AllRingsFinder arf = new AllRingsFinder();
241
for(int i = 0; i < reactant.getAtomCount(); i++) {
242
IAtom atomi = reactant.getAtom(i);
243
if(reactant.getConnectedSingleElectronsCount(atomi) == 1) {
244
HueckelAromaticityDetector.detectAromaticity(reactant);
245
hcg.getSpheres((Molecule) reactant, atomi, 5, true);
247
/* no rearrangement if H belongs to ring*/
248
ringSet = arf.findAllRings((Molecule) reactant);
249
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
250
Ring ring = (Ring)ringSet.getAtomContainer(ir);
251
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
252
IAtom aring = ring.getAtom(jr);
253
aring.setFlag(CDKConstants.ISINRING, true);
256
List atoms = hcg.getNodesInSphere(5);
257
for(int j = 0 ; j < atoms.size() ; j++){
258
IAtom atom4 = (IAtom)atoms.get(j);
261
if(!atom4.getFlag(CDKConstants.ISINRING))
262
if(atom4.getFormalCharge() == 0 && !atom4.equals("H") &&
263
reactant.getMaximumBondOrder(atom4) == 1){
264
Iterator iterat = reactant.getConnectedAtomsList(atom4).iterator();
265
while(iterat.hasNext()){
266
IAtom hydrogen = (IAtom) iterat.next();
267
if(hydrogen.getSymbol().equals("H")){
268
atomi.setFlag(CDKConstants.REACTIVE_CENTER,true);
269
atom4.setFlag(CDKConstants.REACTIVE_CENTER,true);
270
hydrogen.setFlag(CDKConstants.REACTIVE_CENTER,true);
271
break; /*is only necessary one hydrogen */
280
* Gets the parameterNames attribute of the HydrogenRearrangementDeltaReaction object
282
*@return The parameterNames value
284
public String[] getParameterNames() {
285
String[] params = new String[1];
286
params[0] = "hasActiveCenter";
292
* Gets the parameterType attribute of the HydrogenRearrangementDeltaReaction object
294
*@param name Description of the Parameter
295
*@return The parameterType value
297
public Object getParameterType(String name) {
298
return new Boolean(false);