/
IsProtonInConjugatedPiSystemDescriptor.java
216 lines (196 loc) · 7.72 KB
/
IsProtonInConjugatedPiSystemDescriptor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* $RCSfile$
* $Author$
* $Date$
* $Revision$
*
* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.qsar.descriptors.atomic;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.graph.invariant.ConjugatedPiSystemsDetector;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.qsar.DescriptorSpecification;
import org.openscience.cdk.qsar.DescriptorValue;
import org.openscience.cdk.qsar.IAtomicDescriptor;
import org.openscience.cdk.qsar.result.BooleanResult;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
/**
* This class evaluates if a proton is joined to a conjugated system.
*
* <p>This descriptor uses these parameters:
* <table>
* <tr>
* <td>Name</td>
* <td>Default</td>
* <td>Description</td>
* </tr>
* <tr>
* <td>checkAromaticity</td>
* <td>false</td>
* <td>True is the aromaticity has to be checked</td>
* </tr>
* </table>
*
* @author mfe4
* @cdk.created 2004-11-03
* @cdk.module qsaratomic
* @cdk.githash
* @cdk.set qsar-descriptors
* @cdk.dictref qsar-descriptors:isProtonInConjugatedPiSystem
*/
@TestClass(value="org.openscience.cdk.qsar.descriptors.atomic.IsProtonInConjugatedPiSystemDescriptorTest")
public class IsProtonInConjugatedPiSystemDescriptor implements IAtomicDescriptor {
private static final String[] names = {"protonInConjSystem"};
private boolean checkAromaticity = false;
private IAtomContainer acold=null;
private IAtomContainerSet acSet=null;
/**
* Constructor for the IsProtonInConjugatedPiSystemDescriptor object
*/
public IsProtonInConjugatedPiSystemDescriptor() { }
/**
* Gets the specification attribute of the
* IsProtonInConjugatedPiSystemDescriptor object
*
*@return The specification value
*/
@TestMethod(value="testGetSpecification")
public DescriptorSpecification getSpecification() {
return new DescriptorSpecification(
"http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#isProtonInConjugatedPiSystem",
this.getClass().getName(),
"$Id$",
"The Chemistry Development Kit");
}
/**
* Sets the parameters attribute of the IsProtonInConjugatedPiSystemDescriptor
* object
*
*@param params Parameters are an integer (heavy atom position) and a boolean (true if is needed a checkAromaticity)
*@exception CDKException Description of the Exception
*/
@TestMethod(value="testSetParameters_arrayObject")
public void setParameters(Object[] params) throws CDKException {
if (params.length > 1) {
throw new CDKException("IsProtonInConjugatedPiSystemDescriptor only expects one parameters");
}
if (!(params[0] instanceof Boolean)) {
throw new CDKException("The parameter must be of type Boolean");
}
checkAromaticity = (Boolean) params[0];
}
/**
* Gets the parameters attribute of the IsProtonInConjugatedPiSystemDescriptor
* object
*
*@return The parameters value
*/
@TestMethod(value="testGetParameters")
public Object[] getParameters() {
// return the parameters as used for the descriptor calculation
Object[] params = new Object[1];
params[0] = checkAromaticity;
return params;
}
@TestMethod(value="testNamesConsistency")
public String[] getDescriptorNames() {
return names;
}
/**
* The method is a proton descriptor that evaluates if a proton is joined to a conjugated system.
*
*@param atom The IAtom for which the DescriptorValue is requested
*@param atomContainer AtomContainer
*@return true if the proton is bonded to a conjugated system
*/
@TestMethod(value="testCalculate_IAtomContainer")
public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer) {
IAtomContainer clonedAtomContainer;
try {
clonedAtomContainer = (IAtomContainer) atomContainer.clone();
} catch (CloneNotSupportedException e) {
return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(),
new BooleanResult(false),
names, e);
}
IAtom clonedAtom = clonedAtomContainer.getAtom(atomContainer.getAtomNumber(atom));
boolean isProtonInPiSystem = false;
Molecule mol = new Molecule(clonedAtomContainer);
if (checkAromaticity) {
try {
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
CDKHueckelAromaticityDetector.detectAromaticity(mol);
} catch (CDKException e) {
return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(),
new BooleanResult(false),
names, e);
}
}
if(atom.getSymbol().equals("H")) {
if(acold!=clonedAtomContainer){
acold=clonedAtomContainer;
acSet = ConjugatedPiSystemsDetector.detect(mol);
}
java.util.Iterator<IAtomContainer> detected = acSet.atomContainers().iterator();
java.util.List neighboors = mol.getConnectedAtomsList(clonedAtom);
for (Object neighboor : neighboors) {
while (detected.hasNext()) {
IAtomContainer detectedAC = (IAtomContainer) detected.next();
if ((detectedAC != null) && (detectedAC.contains((IAtom) neighboor))) {
isProtonInPiSystem = true;
break;
}
}
}
}
return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(),
new BooleanResult(isProtonInPiSystem),
names);
}
/**
* Gets the parameterNames attribute of the
* IsProtonInConjugatedPiSystemDescriptor object
*
*@return The parameterNames value
*/
@TestMethod(value="testGetParameterNames")
public String[] getParameterNames() {
String[] params = new String[1];
params[0] = "checkAromaticity";
return params;
}
/**
* Gets the parameterType attribute of the
* IsProtonInConjugatedPiSystemDescriptor object
*
*@param name Description of the Parameter
*@return The parameterType value
*/
@TestMethod(value="testGetParameterType_String")
public Object getParameterType(String name) {
return true;
}
}