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*]-C1-C2-C3[H] => A([H])-C1-C2-[C3*]. 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 HydrogenRearrangementGammaReaction();
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 HydrogenRearrangementGammaReaction implements IReactionProcess{
85
private LoggingTool logger;
86
private boolean hasActiveCenter;
89
* Constructor of the HydrogenRearrangementGammaReaction object
92
public HydrogenRearrangementGammaReaction(){
93
logger = new LoggingTool(this);
96
* Gets the specification attribute of the HydrogenRearrangementGammaReaction 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#RearrangementRadical3Reaction",
103
this.getClass().getName(),
104
"$Id: HydrogenRearrangementGammaReaction.java,v 1.6 2006/04/01 08:26:47 mrc Exp $",
105
"The Chemistry Development Kit");
109
* Sets the parameters attribute of the HydrogenRearrangementGammaReaction 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("HydrogenRearrangementGammaReaction 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 HydrogenRearrangementGammaReaction 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: HydrogenRearrangementGammaReaction");
151
if (reactants.getMoleculeCount() != 1) {
152
throw new CDKException("HydrogenRearrangementGammaReaction only expects one reactant");
154
if (agents != null) {
155
throw new CDKException("HydrogenRearrangementGammaReaction 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)) {
174
hcg.getSpheres((Molecule) reactant, atomi, 4, true);
175
List atoms = hcg.getNodesInSphere(4);
176
for(int j = 0 ; j < atoms.size() ; j++){
177
IAtom atom4 = (IAtom)atoms.get(j);
179
if(atom4.getFormalCharge() == 0 && !atom4.equals("H") &&
180
reactant.getMaximumBondOrder(atom4) == 1 && atom4.getFlag(CDKConstants.REACTIVE_CENTER)){
181
if(atomi.getSymbol().equals("C") && reactant.getMaximumBondOrder(atom4) != 1)
183
Iterator iterat = reactant.getConnectedAtomsList(atom4).iterator();
184
while(iterat.hasNext()){
185
IAtom hydrogen = (IAtom) iterat.next();
186
if(hydrogen.getSymbol().equals("H") && hydrogen.getFlag(CDKConstants.REACTIVE_CENTER)){
187
/* positions atoms and bonds */
188
int atom0P = reactant.getAtomNumber(atomi);
189
int atom4P = reactant.getAtomNumber(atom4);
190
int atomHP = reactant.getAtomNumber(hydrogen);
193
IAtomContainer acCloned;
195
acCloned = (IAtomContainer)reactant.clone();
196
} catch (CloneNotSupportedException e) {
197
throw new CDKException("Could not clone IMolecule!", e);
201
List selectron = acCloned.getConnectedSingleElectronsList(acCloned.getAtom(atom0P));
202
acCloned.removeSingleElectron((ISingleElectron)selectron.get(selectron.size() -1));
203
acCloned.addBond(atom0P,atomHP, 1);
204
acCloned.removeBond(acCloned.getAtom(atom4P), acCloned.getAtom(atomHP));
206
acCloned.addSingleElectron(new SingleElectron(acCloned.getAtom(atom4P)));
210
IMapping mapping = DefaultChemObjectBuilder.getInstance().newMapping(atomi, acCloned.getAtom(atom0P));
211
reaction.addMapping(mapping);
212
mapping = DefaultChemObjectBuilder.getInstance().newMapping(atom4, acCloned.getAtom(atom4P));
213
reaction.addMapping(mapping);
214
mapping = DefaultChemObjectBuilder.getInstance().newMapping(hydrogen, acCloned.getAtom(atomHP));
215
reaction.addMapping(mapping);
217
reaction.addProduct((IMolecule) acCloned);
218
setOfReactions.addReaction(reaction);
227
return setOfReactions;
230
* set the active center for this molecule.
231
* The active center will be those which correspond with [A*]=B.
233
* C: Atom with single electron
234
* C3: Atom with Hydrogen
237
* @param reactant The molecule to set the activity
238
* @throws CDKException
240
private void setActiveCenters(IMolecule reactant) throws CDKException {
241
HOSECodeGenerator hcg = new HOSECodeGenerator();
242
IRingSet ringSet = null;
243
AllRingsFinder arf = new AllRingsFinder();
244
for(int i = 0; i < reactant.getAtomCount(); i++) {
245
IAtom atomi = reactant.getAtom(i);
246
if(reactant.getConnectedSingleElectronsCount(atomi) == 1) {
247
HueckelAromaticityDetector.detectAromaticity(reactant);
248
hcg.getSpheres((Molecule) reactant, atomi, 4, true);
249
/* no rearrangement if H belongs to ring*/
250
ringSet = arf.findAllRings((Molecule) reactant);
251
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
252
Ring ring = (Ring)ringSet.getAtomContainer(ir);
253
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
254
IAtom aring = ring.getAtom(jr);
255
aring.setFlag(CDKConstants.ISINRING, true);
258
List atoms = hcg.getNodesInSphere(4);
259
for(int j = 0 ; j < atoms.size() ; j++){
260
IAtom atom4 = (IAtom)atoms.get(j);
262
if(!atom4.getFlag(CDKConstants.ISINRING))
263
if(atom4.getFormalCharge() == 0 && !atom4.equals("H") &&
264
reactant.getMaximumBondOrder(atom4) == 1){
266
if(atomi.getSymbol().equals("C") && reactant.getMaximumBondOrder(atom4) != 1)
269
Iterator iterat = reactant.getConnectedAtomsList(atom4).iterator();
270
while(iterat.hasNext()){
271
IAtom hydrogen = (IAtom) iterat.next();
272
if(hydrogen.getSymbol().equals("H")){
273
atomi.setFlag(CDKConstants.REACTIVE_CENTER,true);
274
atom4.setFlag(CDKConstants.REACTIVE_CENTER,true);
275
hydrogen.setFlag(CDKConstants.REACTIVE_CENTER,true);
276
break; /*is only necessary one hydrogen */
285
* Gets the parameterNames attribute of the HydrogenRearrangementGammaReaction object
287
*@return The parameterNames value
289
public String[] getParameterNames() {
290
String[] params = new String[1];
291
params[0] = "hasActiveCenter";
297
* Gets the parameterType attribute of the HydrogenRearrangementGammaReaction object
299
*@param name Description of the Parameter
300
*@return The parameterType value
302
public Object getParameterType(String name) {
303
return new Boolean(false);