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.exception.CDKException;
33
import org.openscience.cdk.interfaces.IAtom;
34
import org.openscience.cdk.interfaces.IAtomContainer;
35
import org.openscience.cdk.interfaces.IBond;
36
import org.openscience.cdk.interfaces.ILonePair;
37
import org.openscience.cdk.interfaces.IMapping;
38
import org.openscience.cdk.interfaces.IMolecule;
39
import org.openscience.cdk.interfaces.IMoleculeSet;
40
import org.openscience.cdk.interfaces.IReaction;
41
import org.openscience.cdk.interfaces.IReactionSet;
42
import org.openscience.cdk.interfaces.IRingSet;
43
import org.openscience.cdk.reaction.IReactionProcess;
44
import org.openscience.cdk.reaction.ReactionSpecification;
45
import org.openscience.cdk.ringsearch.AllRingsFinder;
46
import org.openscience.cdk.tools.LoggingTool;
47
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
50
* <p>IReactionProcess which participate in movement resonance.
51
* This reaction could be represented as [A+]-B| => A=[B+]. Due to
52
* deficiency of charge of the atom A, the lone pair electron of the atom A is
54
* <p>Make sure that the molecule has the corresponend lone pair electrons
55
* for each atom. You can use the method: <pre> LonePairElectronChecker </pre>
58
* IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
59
* setOfReactants.addMolecule(new Molecule());
60
* IReactionProcess type = new RearrangementCation1Reaction();
61
* Object[] params = {Boolean.FALSE};
62
type.setParameters(params);
63
* IReactionSet setOfReactions = type.initiate(setOfReactants, null);
66
* <p>We have the possibility to localize the reactive center. Good method if you
67
* want to localize the reaction in a fixed point</p>
68
* <pre>atoms[0].setFlag(CDKConstants.REACTIVE_CENTER,true);</pre>
69
* <p>Moreover you must put the parameter Boolean.TRUE</p>
70
* <p>If the reactive center is not localized then the reaction process will
71
* try to find automatically the posible reactive center.</p>
74
* @author Miguel Rojas
76
* @cdk.created 2006-05-05
77
* @cdk.module reaction
78
* @cdk.set reaction-types
81
public class RearrangementCation1Reaction implements IReactionProcess{
82
private LoggingTool logger;
83
private boolean hasActiveCenter;
84
private static final int BONDTOFLAG1 = 8;
87
* Constructor of the RearrangementCation1Reaction object
90
public RearrangementCation1Reaction(){
91
logger = new LoggingTool(this);
94
* Gets the specification attribute of the RearrangementCation1Reaction 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#RearrangementCation1Reaction",
101
this.getClass().getName(),
102
"$Id: RearrangementCation1Reaction.java,v 1.6 2006/04/01 08:26:47 mrc Exp $",
103
"The Chemistry Development Kit");
107
* Sets the parameters attribute of the RearrangementCation1Reaction 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("RearrangementCation1Reaction 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 RearrangementCation1Reaction 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: RearrangementCation1Reaction");
149
if (reactants.getMoleculeCount() != 1) {
150
throw new CDKException("RearrangementCation1Reaction only expects one reactant");
152
if (agents != null) {
153
throw new CDKException("RearrangementCation1Reaction don't expects agents");
156
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newReactionSet();
157
IMolecule reactant = reactants.getMolecule(0);
158
/* if the parameter hasActiveCenter is not fixed yet, set the active centers*/
159
if(!hasActiveCenter){
160
setActiveCenters(reactant);
163
/*control of the volume of number of charge - it will be made possible if
164
* if the atoms[i] is the only atom with charge*/
165
int negCharge = AtomContainerManipulator.getTotalNegativeFormalCharge((IAtomContainer)reactant);
166
int posCharge = AtomContainerManipulator.getTotalPositiveFormalCharge((IAtomContainer)reactant);
167
if(posCharge > 1 || Math.abs(negCharge) > 1)
168
return setOfReactions;
172
for(int i = 0 ; i < reactant.getAtomCount() ; i++){
173
atomi = reactant.getAtom(i);
174
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER) && atomi.getFormalCharge() == 1 ){
177
java.util.List bonds = reactant.getConnectedBondsList(atomi);
179
for(int j = 0 ; j < bonds.size() ; j++){
180
bondj = (IBond)bonds.get(j);
181
if(bondj.getFlag(CDKConstants.REACTIVE_CENTER) && bondj.getOrder() == 1.0){
182
IAtom atom1 = bondj.getConnectedAtom(atomi);
183
List lp = reactant.getConnectedLonePairsList(atom1);
184
if(atom1.getFlag(CDKConstants.REACTIVE_CENTER) && lp.size() > 0 )
185
if(reactant.getConnectedSingleElectronsCount(atom1) == 0){
187
IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction();
188
reaction.addReactant(reactant);
191
cleanFlagBOND(reactants.getMolecule(0));
193
/* positions atoms and bonds */
194
int atom0P = reactant.getAtomNumber(atomi);
195
bondj.setFlag(BONDTOFLAG1, true);
196
int atom1P = reactant.getAtomNumber(atom1);
199
IAtomContainer acCloned;
201
acCloned = (IAtomContainer)reactant.clone();
202
} catch (CloneNotSupportedException e) {
203
throw new CDKException("Could not clone IMolecule!", e);
206
int charge = acCloned.getAtom(atom0P).getFormalCharge();
207
acCloned.getAtom(atom0P).setFormalCharge(charge-1);
209
IBond bondjClon = null;
210
for(int l = 0 ; l<acCloned.getBondCount();l++){
211
IBond bb = acCloned.getBond(l);
212
if(bb.getFlag(BONDTOFLAG1)){
213
double order = bb.getOrder();
214
bb.setOrder(order+1);
219
charge = acCloned.getAtom(atom1P).getFormalCharge();
220
acCloned.getAtom(atom1P).setFormalCharge(charge+1);
222
List selectron = acCloned.getConnectedLonePairsList(acCloned.getAtom(atom1P));
223
acCloned.removeLonePair((ILonePair)selectron.get(selectron.size() -1));
226
IMapping mapping = DefaultChemObjectBuilder.getInstance().newMapping(atomi, acCloned.getAtom(atom0P));
227
reaction.addMapping(mapping);
228
mapping = DefaultChemObjectBuilder.getInstance().newMapping(atom1, acCloned.getAtom(atom1P));
229
reaction.addMapping(mapping);
230
mapping = DefaultChemObjectBuilder.getInstance().newMapping(bondj, bondjClon);
231
reaction.addMapping(mapping);
233
reaction.addProduct((IMolecule) acCloned);
234
setOfReactions.addReaction(reaction);
235
bondj.setFlag(BONDTOFLAG1, false);
242
return setOfReactions;
247
* set the active center for this molecule.
248
* The active center will be those which correspond with [A+]-B|.
250
* A: Atom with positive charge
252
* B: Atom with lone pair electrons
255
* @param reactant The molecule to set the activity
256
* @throws CDKException
258
private void setActiveCenters(IMolecule reactant) throws CDKException {
259
AllRingsFinder ssrF = new AllRingsFinder();
260
IRingSet rings = ssrF.findAllRings(reactant);
263
for(int i = 0; i < reactant.getAtomCount(); i++) {
264
atomi = reactant.getAtom(i);
265
if(atomi.getFormalCharge() == 1 ){
266
java.util.List bonds = reactant.getConnectedBondsList(atomi);
267
for(int j = 0 ; j < bonds.size() ; j++){
268
bondj = (IBond)bonds.get(j);
269
if(bondj.getOrder() == 1.0){
270
IAtom atom = bondj.getConnectedAtom(atomi);
271
List lp = reactant.getConnectedLonePairsList(atom);
272
if((lp.size() > 0 )&& (atom.getFormalCharge() == 0))
273
if(reactant.getConnectedSingleElectronsCount(atom) == 0){
274
if(rings.contains(atom))
276
atomi.setFlag(CDKConstants.REACTIVE_CENTER,true);
277
atom.setFlag(CDKConstants.REACTIVE_CENTER,true);
278
bondj.setFlag(CDKConstants.REACTIVE_CENTER,true);
286
* Gets the parameterNames attribute of the RearrangementCation1Reaction object
288
*@return The parameterNames value
290
public String[] getParameterNames() {
291
String[] params = new String[1];
292
params[0] = "hasActiveCenter";
298
* Gets the parameterType attribute of the RearrangementCation1Reaction object
300
*@param name Description of the Parameter
301
*@return The parameterType value
303
public Object getParameterType(String name) {
304
return new Boolean(false);
307
* clean the flags BONDTOFLAG from the molecule
311
public void cleanFlagBOND(IAtomContainer ac){
312
for(int j = 0 ; j < ac.getBondCount(); j++){
313
ac.getBond(j).setFlag(BONDTOFLAG1, false);