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 org.openscience.cdk.CDKConstants;
29
import org.openscience.cdk.DefaultChemObjectBuilder;
30
import org.openscience.cdk.LonePair;
31
import org.openscience.cdk.exception.CDKException;
32
import org.openscience.cdk.interfaces.*;
33
import org.openscience.cdk.reaction.IReactionProcess;
34
import org.openscience.cdk.reaction.ReactionSpecification;
35
import org.openscience.cdk.tools.LoggingTool;
36
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
38
import java.util.Iterator;
41
* <p>IReactionProcess which participate in movement resonance.
42
* This reaction could be represented as two forms</p>
43
* <pre>X=A => |[X-]-[A+]. X represents an acceptor atomType.
44
* It is a case specific of the method BreakingBondReaction</pre>
46
* IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
47
* setOfReactants.addMolecule(new Molecule());
48
* IReactionProcess type = new DisplacementChargeFromAcceptorReaction();
49
* Object[] params = {Boolean.FALSE};
50
type.setParameters(params);
51
* IReactionSet setOfReactions = type.initiate(setOfReactants, null);
54
* <p>We have the possibility to localize the reactive center. Good method if you
55
* want to localize the reaction in a fixed point</p>
56
* <pre>atoms[0].setFlag(CDKConstants.REACTIVE_CENTER,true);</pre>
57
* <p>Moreover you must put the parameter Boolean.TRUE</p>
58
* <p>If the reactive center is not localized then the reaction process will
59
* try to find automatically the posible reactive center.</p>
62
* @author Miguel Rojas
64
* @cdk.created 2006-05-05
65
* @cdk.module reaction
66
* @cdk.set reaction-types
69
public class DisplacementChargeFromAcceptorReaction implements IReactionProcess{
70
private LoggingTool logger;
71
private boolean hasActiveCenter;
72
private static final int BONDTOFLAG1 = 8;
75
* Constructor of the DisplacementChargeFromAcceptorReaction object
78
public DisplacementChargeFromAcceptorReaction(){
79
logger = new LoggingTool(this);
82
* Gets the specification attribute of the DisplacementChargeFromAcceptorReaction object
84
*@return The specification value
86
public ReactionSpecification getSpecification() {
87
return new ReactionSpecification(
88
"http://almost.cubic.uni-koeln.de/jrg/Members/mrc/reactionDict/reactionDict#DisplacementChargeFromAcceptorReaction",
89
this.getClass().getName(),
90
"$Id: DisplacementChargeReaction.java,v 1.6 2006/04/01 08:26:47 mrc Exp $",
91
"The Chemistry Development Kit");
95
* Sets the parameters attribute of the DisplacementChargeFromAcceptorReaction object
97
*@param params The parameter is if the molecule has already fixed the center active or not. It
98
* should be set before to inize the reaction with a setFlag: CDKConstants.REACTIVE_CENTER
99
*@exception CDKException Description of the Exception
101
public void setParameters(Object[] params) throws CDKException {
102
if (params.length > 1) {
103
throw new CDKException("DisplacementChargeFromAcceptorReaction only expects one parameter");
105
if (!(params[0] instanceof Boolean)) {
106
throw new CDKException("The parameter 1 must be of type boolean");
108
hasActiveCenter = ((Boolean) params[0]).booleanValue();
113
* Gets the parameters attribute of the DisplacementChargeFromAcceptorReaction object
115
*@return The parameters value
117
public Object[] getParameters() {
118
Object[] params = new Object[1];
119
params[0] = new Boolean (hasActiveCenter);
125
* It is needed to call the addExplicitHydrogensToSatisfyValency
126
* from the class tools.HydrogenAdder.
128
*@param reactants reactants of the reaction.
129
*@param agents agents of the reaction (Must be in this case null).
131
*@exception CDKException Description of the Exception
133
public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws CDKException{
135
logger.debug("initiate reaction: DisplacementChargeFromAcceptorReaction");
137
if (reactants.getMoleculeCount() != 1) {
138
throw new CDKException("DisplacementChargeFromAcceptorReaction only expects one reactant");
140
if (agents != null) {
141
throw new CDKException("DisplacementChargeFromAcceptorReaction don't expects agents");
144
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newReactionSet();
145
IMolecule reactant = reactants.getMolecule(0);
147
/* if the parameter hasActiveCenter is not fixed yet, set the active centers*/
148
if(!hasActiveCenter){
149
setActiveCenters(reactant);
152
Iterator bonds = reactants.getMolecule(0).bonds();
153
while (bonds.hasNext()) {
154
IBond bond = (IBond) bonds.next();
156
if(bond.getFlag(CDKConstants.REACTIVE_CENTER) && bond.getOrder() == 2.0){
157
IAtom atom1 = bond.getAtom(0);
158
IAtom atom2 = bond.getAtom(1);
159
if((((atom1.getFormalCharge() == 0 && reactant.getConnectedSingleElectronsCount(atom1) == 0 && reactant.getConnectedLonePairsCount(atom1) > 0 && !atom1.getSymbol().equals("C")))
160
&&(atom2.getFormalCharge() == 0 && reactant.getConnectedSingleElectronsCount(atom2) == 0))
161
|| (((atom2.getFormalCharge() == 0 && reactant.getConnectedSingleElectronsCount(atom2) == 0 && reactant.getConnectedLonePairsCount(atom2) > 0 && !atom2.getSymbol().equals("C")))
162
&&(atom1.getFormalCharge() == 0 && reactant.getConnectedSingleElectronsCount(atom1) == 0))){
164
cleanFlagBOND(reactants.getMolecule(0));
165
/* positions atoms and bonds */
166
int atom0P = reactant.getAtomNumber(bond.getAtom(0));
167
bond.setFlag(BONDTOFLAG1, true);
168
int atom1P = reactant.getAtomNumber(bond.getAtom(1));
171
IAtomContainer acCloned;
173
acCloned = (IAtomContainer)reactant.clone();
174
} catch (CloneNotSupportedException e) {
175
throw new CDKException("Could not clone reactant", e);
178
IBond bondClon = null;
179
for(int l = 0 ; l<acCloned.getBondCount();l++){
180
if(acCloned.getBond(l).getFlag(BONDTOFLAG1)){
181
double order = acCloned.getBond(l).getOrder();
182
acCloned.getBond(l).setOrder(order - 1);
183
bondClon = acCloned.getBond(l);
188
IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction();
189
reaction.addReactant(reactant);
192
if(reactant.getConnectedLonePairsCount(atom1) > 0){
193
acCloned.getAtom(atom0P).setFormalCharge(-1);
194
acCloned.addLonePair(new LonePair(acCloned.getAtom(atom0P)));
196
acCloned.getAtom(atom1P).setFormalCharge(1);
198
acCloned.getAtom(atom0P).setFormalCharge(1);
200
acCloned.getAtom(atom1P).setFormalCharge(-1);
201
acCloned.addLonePair(new LonePair(acCloned.getAtom(atom1P)));
206
IMapping mapping = DefaultChemObjectBuilder.getInstance().newMapping(bond, bondClon);
207
reaction.addMapping(mapping);
208
mapping = DefaultChemObjectBuilder.getInstance().newMapping(bond.getAtom(0), acCloned.getAtom(atom0P));
209
reaction.addMapping(mapping);
210
mapping = DefaultChemObjectBuilder.getInstance().newMapping(bond.getAtom(1), acCloned.getAtom(atom1P));
211
reaction.addMapping(mapping);
214
reaction.addProduct((IMolecule) acCloned);
215
setOfReactions.addReaction(reaction);
218
bond.setFlag(BONDTOFLAG1, false);
223
return setOfReactions;
228
* set the active center for this molecule.
229
* The active center will be those which correspond with A=B.
231
* A: Atom with lone pair electrons // TODO- not only the atoms with
232
* lone electrons are acceptor atoms.
237
* @param reactant The molecule to set the activity
238
* @throws CDKException
240
private void setActiveCenters(IMolecule reactant) throws CDKException {
241
Iterator bonds = reactant.bonds();
243
if (AtomContainerManipulator.getTotalNegativeFormalCharge(reactant) != 0 || AtomContainerManipulator.getTotalPositiveFormalCharge(reactant) != 0)
246
while (bonds.hasNext()) {
247
IBond bond = (IBond) bonds.next();
248
if (bond.getOrder() == 2.0) {
249
IAtom atom1 = bond.getAtom(0);
250
IAtom atom2 = bond.getAtom(1);/* TODO - not controll from lone pair electrons*/
251
if ((((atom1.getFormalCharge() == 0 && reactant.getConnectedSingleElectronsCount(atom1) == 0 && reactant.getConnectedLonePairsCount(atom1) > 0 && !atom1.getSymbol().equals("C")))
252
&& (atom2.getFormalCharge() == 0 && reactant.getConnectedSingleElectronsCount(atom2) == 0))
253
|| (((atom2.getFormalCharge() == 0 && reactant.getConnectedSingleElectronsCount(atom2) == 0 && reactant.getConnectedLonePairsCount(atom2) > 0 && !atom2.getSymbol().equals("C")))
254
&& (atom1.getFormalCharge() == 0 && reactant.getConnectedSingleElectronsCount(atom1) == 0))) {
255
atom1.setFlag(CDKConstants.REACTIVE_CENTER, true);
256
atom2.setFlag(CDKConstants.REACTIVE_CENTER, true);
257
bond.setFlag(CDKConstants.REACTIVE_CENTER, true);
263
* Gets the parameterNames attribute of the DisplacementChargeFromAcceptorReaction object
265
*@return The parameterNames value
267
public String[] getParameterNames() {
268
String[] params = new String[1];
269
params[0] = "hasActiveCenter";
275
* Gets the parameterType attribute of the DisplacementChargeFromAcceptorReaction object
277
*@param name Description of the Parameter
278
*@return The parameterType value
280
public Object getParameterType(String name) {
281
return Boolean.FALSE;
284
* clean the flags CDKConstants.REACTIVE_CENTER from the molecule
288
public void cleanFlagBOND(IAtomContainer ac){
289
for(int j = 0 ; j < ac.getBondCount(); j++){
290
ac.getBond(j).setFlag(BONDTOFLAG1, false);