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.List;
30
import org.openscience.cdk.CDKConstants;
31
import org.openscience.cdk.DefaultChemObjectBuilder;
32
import org.openscience.cdk.SingleElectron;
33
import org.openscience.cdk.exception.CDKException;
34
import org.openscience.cdk.interfaces.IAtom;
35
import org.openscience.cdk.interfaces.IAtomContainer;
36
import org.openscience.cdk.interfaces.IBond;
37
import org.openscience.cdk.interfaces.IMapping;
38
import org.openscience.cdk.interfaces.IMolecule;
39
import org.openscience.cdk.interfaces.IReaction;
40
import org.openscience.cdk.interfaces.IMoleculeSet;
41
import org.openscience.cdk.interfaces.IReactionSet;
42
import org.openscience.cdk.interfaces.ISingleElectron;
43
import org.openscience.cdk.reaction.IReactionProcess;
44
import org.openscience.cdk.reaction.ReactionSpecification;
45
import org.openscience.cdk.tools.LoggingTool;
46
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
49
* <p>IReactionProcess which participate in movement resonance.
50
* This reaction could be represented as [A*]-B=C => A=B-[c*]. Due to
51
* excess of charge of the atom B, the sinble electron of the atom A is
52
* desplaced through the double bond.</p>
53
* <p>Make sure that the molecule has the corresponend lone pair electrons
54
* for each atom. You can use the method: <pre> LonePairElectronChecker </pre>
57
* IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
58
* setOfReactants.addMolecule(new Molecule());
59
* IReactionProcess type = new RearrangementRadical2Reaction();
60
* Object[] params = {Boolean.FALSE};
61
type.setParameters(params);
62
* IReactionSet setOfReactions = type.initiate(setOfReactants, null);
65
* <p>We have the possibility to localize the reactive center. Good method if you
66
* want to localize the reaction in a fixed point</p>
67
* <pre>atoms[0].setFlag(CDKConstants.REACTIVE_CENTER,true);</pre>
68
* <p>Moreover you must put the parameter Boolean.TRUE</p>
69
* <p>If the reactive center is not localized then the reaction process will
70
* try to find automatically the posible reactive center.</p>
73
* @author Miguel Rojas
75
* @cdk.created 2006-05-05
76
* @cdk.module reaction
77
* @cdk.set reaction-types
80
public class RearrangementRadical2Reaction implements IReactionProcess{
81
private LoggingTool logger;
82
private boolean hasActiveCenter;
83
private static final int BONDTOFLAG1 = 8;
84
private static final int BONDTOFLAG2 = 9;
87
* Constructor of the RearrangementRadical2Reaction object
90
public RearrangementRadical2Reaction(){
91
logger = new LoggingTool(this);
94
* Gets the specification attribute of the RearrangementRadical2Reaction object
96
*@return The specification value
98
public ReactionSpecification getSpecification() {
99
return new ReactionSpecification(
100
"http://almost.cubic.uni-koeln.de/jrg/Members/mrc/reactionDict/reactionDict#RearrangementRadical2Reaction",
101
this.getClass().getName(),
102
"$Id: RearrangementRadical2Reaction.java,v 1.6 2006/04/01 08:26:47 mrc Exp $",
103
"The Chemistry Development Kit");
107
* Sets the parameters attribute of the RearrangementRadical2Reaction object
109
*@param params The parameter is if the molecule has already fixed the center active or not. It
110
* should be set before to inize the reaction with a setFlag: CDKConstants.REACTIVE_CENTER
111
*@exception CDKException Description of the Exception
113
public void setParameters(Object[] params) throws CDKException {
114
if (params.length > 1) {
115
throw new CDKException("RearrangementRadical2Reaction only expects one parameter");
117
if (!(params[0] instanceof Boolean)) {
118
throw new CDKException("The parameter 1 must be of type boolean");
120
hasActiveCenter = ((Boolean) params[0]).booleanValue();
125
* Gets the parameters attribute of the RearrangementRadical2Reaction object
127
*@return The parameters value
129
public Object[] getParameters() {
130
Object[] params = new Object[1];
131
params[0] = new Boolean (hasActiveCenter);
137
* It is needed to call the addExplicitHydrogensToSatisfyValency
138
* from the class tools.HydrogenAdder.
140
*@param reactants reactants of the reaction.
141
*@param agents agents of the reaction (Must be in this case null).
143
*@exception CDKException Description of the Exception
145
public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws CDKException{
147
logger.debug("initiate reaction: RearrangementRadical2Reaction");
149
if (reactants.getMoleculeCount() != 1) {
150
throw new CDKException("RearrangementRadical2Reaction only expects one reactant");
152
if (agents != null) {
153
throw new CDKException("RearrangementRadical2Reaction don't expects agents");
156
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newReactionSet();
157
IMolecule reactant = reactants.getMolecule(0);
159
/* if the parameter hasActiveCenter is not fixed yet, set the active centers*/
160
if(!hasActiveCenter){
161
setActiveCenters(reactant);
167
for(int i = 0 ; i < reactant.getAtomCount() ; i++){
168
atomi = reactant.getAtom(i);
169
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER)&& reactant.getConnectedSingleElectronsCount(atomi) == 1){
171
java.util.List bonds = reactant.getConnectedBondsList(atomi);
173
for(int j = 0 ; j < bonds.size() ; j++){
174
bondj = (IBond)bonds.get(j);
175
if(bondj.getFlag(CDKConstants.REACTIVE_CENTER)&& bondj.getOrder() == 1.0){
176
IAtom atom = bondj.getConnectedAtom(reactant.getAtom(i));
177
java.util.List bondsI = reactant.getConnectedBondsList(atom);
178
for(int k = 0 ; k < bondsI.size() ; k++){
179
bondk = (IBond)bondsI.get(k);
180
if(bondk.getFlag(CDKConstants.REACTIVE_CENTER) && bondk.getOrder() == 2.0){
181
IAtom atom1 = bondk.getConnectedAtom(atom);
182
if(atom1.getFlag(CDKConstants.REACTIVE_CENTER)&& atom1.getFormalCharge() == 0 ){
183
IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction();
184
reaction.addReactant(reactant);
186
cleanFlagBOND(reactants.getMolecule(0));
187
/* positions atoms and bonds */
188
int atom0P = reactant.getAtomNumber(atomi);
189
bondj.setFlag(BONDTOFLAG1, true);
190
bondk.setFlag(BONDTOFLAG2, true);
191
int atom1P = reactant.getAtomNumber(atom);
192
int atom2P = reactant.getAtomNumber(atom1);
195
IAtomContainer acCloned;
197
acCloned = (IAtomContainer)reactant.clone();
198
} catch (CloneNotSupportedException e) {
199
throw new CDKException("Could not clone IMolecule!", e);
202
List selectron = acCloned.getConnectedSingleElectronsList(acCloned.getAtom(atom0P));
203
acCloned.removeSingleElectron((ISingleElectron)selectron.get(selectron.size() -1));
205
acCloned.addSingleElectron(new SingleElectron(acCloned.getAtom(atom2P)));
207
IBond bondjClon = null, bondkClon = null;
208
for(int l = 0 ; l<acCloned.getBondCount();l++){
209
IBond bb = acCloned.getBond(l);
210
if(bb.getFlag(BONDTOFLAG1)){
212
double order = bb.getOrder();
213
bb.setOrder(order+1);
216
}else if(acCloned.getBond(l).getFlag(BONDTOFLAG2)){
217
double order = bb.getOrder();
218
bb.setOrder(order-1);
225
IMapping mapping = DefaultChemObjectBuilder.getInstance().newMapping(atomi, acCloned.getAtom(atom0P));
226
reaction.addMapping(mapping);
227
mapping = DefaultChemObjectBuilder.getInstance().newMapping(atom, acCloned.getAtom(atom1P));
228
reaction.addMapping(mapping);
229
mapping = DefaultChemObjectBuilder.getInstance().newMapping(atom1, acCloned.getAtom(atom2P));
230
reaction.addMapping(mapping);
231
mapping = DefaultChemObjectBuilder.getInstance().newMapping(bondj, bondjClon);
232
reaction.addMapping(mapping);
233
mapping = DefaultChemObjectBuilder.getInstance().newMapping(bondk, bondkClon);
234
reaction.addMapping(mapping);
236
reaction.addProduct((IMolecule) acCloned);
237
setOfReactions.addReaction(reaction);
240
bondj.setFlag(BONDTOFLAG1, false);
241
bondk.setFlag(BONDTOFLAG2, false);
249
return setOfReactions;
254
* set the active center for this molecule.
255
* The active center will be those which correspond with [A*]-B=C .
257
* A: Atom with single electron
264
* @param reactant The molecule to set the activity
265
* @throws CDKException
267
private void setActiveCenters(IMolecule reactant) throws CDKException {
268
if(AtomContainerManipulator.getTotalNegativeFormalCharge(reactant) != 0 /*|| AtomContainerManipulator.getTotalPositiveFormalCharge(reactant) != 0*/)
273
for(int i = 0; i < reactant.getAtomCount(); i++) {
274
atomi = reactant.getAtom(i);
275
if(reactant.getConnectedSingleElectronsCount(atomi) == 1 ){
276
java.util.List bonds = reactant.getConnectedBondsList(atomi);
277
for(int j = 0 ; j < bonds.size() ; j++){
278
bondj = (IBond)bonds.get(j);
279
if(bondj.getOrder() == 1.0){
280
IAtom atom = bondj.getConnectedAtom(reactant.getAtom(i));
281
java.util.List bondsI = reactant.getConnectedBondsList(atom);
282
for(int k = 0 ; k < bondsI.size() ; k++){
283
bondk = (IBond)bondsI.get(k);
284
if(bondk.getOrder() == 2.0){
285
IAtom atom1 = bondk.getConnectedAtom(atom);
286
if(atom1.getFormalCharge() == 0 ){
287
atomi.setFlag(CDKConstants.REACTIVE_CENTER,true);
288
atom.setFlag(CDKConstants.REACTIVE_CENTER,true);
289
atom1.setFlag(CDKConstants.REACTIVE_CENTER,true);
290
bondk.getConnectedAtom(atom).setFlag(CDKConstants.REACTIVE_CENTER,true);
291
bondj.setFlag(CDKConstants.REACTIVE_CENTER,true);
292
bondk.setFlag(CDKConstants.REACTIVE_CENTER,true);
302
* Gets the parameterNames attribute of the RearrangementRadical2Reaction object
304
*@return The parameterNames value
306
public String[] getParameterNames() {
307
String[] params = new String[1];
308
params[0] = "hasActiveCenter";
314
* Gets the parameterType attribute of the RearrangementRadical2Reaction object
316
*@param name Description of the Parameter
317
*@return The parameterType value
319
public Object getParameterType(String name) {
320
return new Boolean(false);
324
* clean the flags BONDTOFLAG from the molecule
328
public void cleanFlagBOND(IAtomContainer ac){
329
for(int j = 0 ; j < ac.getBondCount(); j++){
330
ac.getBond(j).setFlag(BONDTOFLAG1, false);
331
ac.getBond(j).setFlag(BONDTOFLAG2, false);