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;
27
import java.util.List;
29
import org.openscience.cdk.CDKConstants;
30
import org.openscience.cdk.DefaultChemObjectBuilder;
31
import org.openscience.cdk.SingleElectron;
32
import org.openscience.cdk.exception.CDKException;
33
import org.openscience.cdk.graph.ConnectivityChecker;
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.IMoleculeSet;
40
import org.openscience.cdk.interfaces.IReaction;
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;
48
* <p>IReactionProcess which participate mass spectrum process. Homolitic dissocitation.
49
* This reaction could be represented as A-B-[c*] => [A*] + B=C.</p>
50
* <p>Make sure that the molecule has the corresponend lone pair electrons
51
* for each atom. You can use the method: <pre> LonePairElectronChecker </pre>
54
* IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
55
* setOfReactants.addMolecule(new Molecule());
56
* IReactionProcess type = new RadicalSiteInitiationReaction();
57
* Object[] params = {Boolean.FALSE};
58
type.setParameters(params);
59
* IReactionSet setOfReactions = type.initiate(setOfReactants, null);
62
* <p>We have the possibility to localize the reactive center. Good method if you
63
* want to localize the reaction in a fixed point</p>
64
* <pre>atoms[0].setFlag(CDKConstants.REACTIVE_CENTER,true);</pre>
65
* <p>Moreover you must put the parameter Boolean.TRUE</p>
66
* <p>If the reactive center is not localized then the reaction process will
67
* try to find automatically the posible reactive center.</p>
70
* @author Miguel Rojas
72
* @cdk.created 2006-05-05
73
* @cdk.module reaction
74
* @cdk.set reaction-types
77
public class RadicalSiteInitiationReaction implements IReactionProcess{
78
private LoggingTool logger;
79
private boolean hasActiveCenter;
80
private static final int BONDTOFLAG = 8;
83
* Constructor of the RadicalSiteInitiationReaction object
86
public RadicalSiteInitiationReaction(){
87
logger = new LoggingTool(this);
90
* Gets the specification attribute of the RadicalSiteInitiationReaction object
92
*@return The specification value
94
public ReactionSpecification getSpecification() {
95
return new ReactionSpecification(
96
"http://almost.cubic.uni-koeln.de/jrg/Members/mrc/reactionDict/reactionDict#RearrangementRadical3Reaction",
97
this.getClass().getName(),
98
"$Id: RadicalSiteInitiationReaction.java,v 1.6 2006/04/01 08:26:47 mrc Exp $",
99
"The Chemistry Development Kit");
103
* Sets the parameters attribute of the RadicalSiteInitiationReaction object
105
*@param params The parameter is if the molecule has already fixed the center active or not. It
106
* should be set before to inize the reaction with a setFlag: CDKConstants.REACTIVE_CENTER
107
*@exception CDKException Description of the Exception
109
public void setParameters(Object[] params) throws CDKException {
110
if (params.length > 1) {
111
throw new CDKException("RadicalSiteInitiationReaction only expects one parameter");
113
if (!(params[0] instanceof Boolean)) {
114
throw new CDKException("The parameter 1 must be of type boolean");
116
hasActiveCenter = ((Boolean) params[0]).booleanValue();
121
* Gets the parameters attribute of the RadicalSiteInitiationReaction object
123
*@return The parameters value
125
public Object[] getParameters() {
126
Object[] params = new Object[1];
127
params[0] = new Boolean (hasActiveCenter);
134
*@param reactants reactants of the reaction.
135
*@param agents agents of the reaction (Must be in this case null).
137
*@exception CDKException Description of the Exception
139
public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws CDKException{
140
logger.debug("initiate reaction: RadicalSiteInitiationReaction");
142
if (reactants.getMoleculeCount() != 1) {
143
throw new CDKException("RadicalSiteInitiationReaction only expects one reactant");
145
if (agents != null) {
146
throw new CDKException("RadicalSiteInitiationReaction don't expects agents");
149
IReactionSet setOfReactions = reactants.getBuilder().newReactionSet();
150
IMolecule reactant = reactants.getMolecule(0);
152
/* if the parameter hasActiveCenter is not fixed yet, set the active centers*/
153
if(!hasActiveCenter){
154
setActiveCenters(reactant);
157
IMolecule reactant0 = reactants.getMolecule(0);
161
for(int i = 0 ; i < reactant0.getAtomCount() ; i++){
162
atomi = reactant0.getAtom(i);
163
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER)&& reactant.getConnectedSingleElectronsCount(atomi) == 1 ){
165
java.util.List bonds = reactant.getConnectedBondsList(atomi);
167
for(int j = 0 ; j < bonds.size() ; j++){
168
bondj = (IBond)bonds.get(j);
169
if(bondj.getFlag(CDKConstants.REACTIVE_CENTER)&& bondj.getOrder() < 3.0 ){
170
IAtom atom = bondj.getConnectedAtom(reactant.getAtom(i));
171
if(atom.getFormalCharge() != 0)
173
java.util.List bondsI = reactant.getConnectedBondsList(atom);
174
for(int k = 0 ; k < bondsI.size() ; k++){
175
bondk = (IBond)bondsI.get(k);
176
if(bondk.getFlag(CDKConstants.REACTIVE_CENTER) && bondk.getOrder() == 1.0 && !bondk.equals(bondj)){
177
IAtom atomConn = bondk.getConnectedAtom(atom);
178
if(atomConn.getFlag(CDKConstants.REACTIVE_CENTER) && atomConn.getFormalCharge() == 0
179
&& !atomConn.equals(atomi) && !atomConn.getSymbol().equals("H")){
181
IReaction reaction = DefaultChemObjectBuilder.getInstance().newReaction();
182
reaction.addReactant(reactant);
184
cleanFlagBOND(reactants.getMolecule(0));
185
/* positions atoms and bonds */
186
int atom0P = reactant.getAtomNumber(atomi);
187
bondj.setFlag(BONDTOFLAG, true);
188
int bond2P = reactant.getBondNumber(bondk);
189
int atom1P = reactant.getAtomNumber(atom);
190
int atom2P = reactant.getAtomNumber(atomConn);
194
acCloned = (IMolecule) reactant.clone();
195
} catch (CloneNotSupportedException e) {
196
throw new CDKException("Could not clone IMolecule!", e);
199
acCloned.removeBond(bond2P);
201
List selectron = acCloned.getConnectedSingleElectronsList(acCloned.getAtom(atom0P));
202
acCloned.removeSingleElectron((ISingleElectron)selectron.get(selectron.size() -1));
203
selectron = acCloned.getConnectedSingleElectronsList(acCloned.getAtom(atom0P));
205
acCloned.addSingleElectron(new SingleElectron(acCloned.getAtom(atom2P)));
209
IBond bondjClon = null;
210
for(int l = 0 ; l < acCloned.getBondCount();l++){
211
if(acCloned.getBond(l).getFlag(BONDTOFLAG)){
212
order = acCloned.getBond(l).getOrder();
213
acCloned.getBond(l).setOrder(order+1);
214
bondjClon = acCloned.getBond(l);
221
IMapping mapping = atom.getBuilder().newMapping(atomi, acCloned.getAtom(atom0P));
222
reaction.addMapping(mapping);
223
mapping = atom.getBuilder().newMapping(atom, acCloned.getAtom(atom1P));
224
reaction.addMapping(mapping);
225
mapping = atom.getBuilder().newMapping(atomConn, acCloned.getAtom(atom2P));
226
reaction.addMapping(mapping);
227
mapping = atom.getBuilder().newMapping(bondj, bondjClon);
228
reaction.addMapping(mapping);
230
// mapping = atom.getBuilder().newMapping(bondk, acCloned.getBond(bond2P));
231
// reaction.addMapping(mapping);
233
IMoleculeSet moleculeSet = ConnectivityChecker.partitionIntoMolecules(acCloned);
234
for(int z = 0; z < moleculeSet.getAtomContainerCount() ; z++){
235
reaction.addProduct(moleculeSet.getMolecule(z));
238
setOfReactions.addReaction(reaction);
240
bondj.setFlag(BONDTOFLAG, false);
248
return setOfReactions;
252
* set the active center for this molecule.
253
* The active center will be those which correspond with A-B-[C*].
259
* C: Atom with single electron
262
* @param reactant The molecule to set the activity
263
* @throws CDKException
265
private void setActiveCenters(IMolecule reactant) throws CDKException {
269
for(int i = 0 ; i < reactant.getAtomCount() ; i++) {
270
atomi = reactant.getAtom(i);
271
if(reactant.getConnectedSingleElectronsCount(atomi) == 1 ){
272
java.util.List bonds = reactant.getConnectedBondsList(atomi);
273
for(int j = 0 ; j < bonds.size() ; j++){
274
bondj = (IBond)bonds.get(j);
275
if(bondj.getOrder() < 3.0){
276
IAtom atom = bondj.getConnectedAtom(atomi);
277
if(atom.getFormalCharge() != 0)
279
java.util.List bondsI = reactant.getConnectedBondsList(atom);
280
for(int k = 0 ; k < bondsI.size() ; k++){
281
bondk = (IBond)bondsI.get(k);
282
if(bondk.getOrder() == 1 && !bondk.equals(bondj)){
283
IAtom atomConn = bondk.getConnectedAtom(atom);
284
if(atomConn.getFormalCharge() == 0 && !atomConn.getSymbol().equals("H")){
285
atomi.setFlag(CDKConstants.REACTIVE_CENTER,true);
286
atom.setFlag(CDKConstants.REACTIVE_CENTER,true);
287
atomConn.setFlag(CDKConstants.REACTIVE_CENTER,true);
288
bondj.setFlag(CDKConstants.REACTIVE_CENTER,true);
289
bondk.setFlag(CDKConstants.REACTIVE_CENTER,true);
299
* Gets the parameterNames attribute of the RadicalSiteInitiationReaction object
301
*@return The parameterNames value
303
public String[] getParameterNames() {
304
String[] params = new String[1];
305
params[0] = "hasActiveCenter";
311
* Gets the parameterType attribute of the RadicalSiteInitiationReaction object
313
*@param name Description of the Parameter
314
*@return The parameterType value
316
public Object getParameterType(String name) {
317
return new Boolean(false);
320
* clean the flags BONDTOFLAG from the molecule
324
public void cleanFlagBOND(IAtomContainer ac){
325
for(int j = 0 ; j < ac.getBondCount(); j++)
326
ac.getBond(j).setFlag(BONDTOFLAG, false);