4
* $Date: 2007-10-14 20:35:55 +0200 (Sun, 14 Oct 2007) $
7
* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project
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.qsar.descriptors.molecular;
27
import org.openscience.cdk.CDKConstants;
28
import org.openscience.cdk.aromaticity.HueckelAromaticityDetector;
29
import org.openscience.cdk.exception.CDKException;
30
import org.openscience.cdk.interfaces.IAtomContainer;
31
import org.openscience.cdk.interfaces.IBond;
32
import org.openscience.cdk.interfaces.IRingSet;
33
import org.openscience.cdk.qsar.DescriptorSpecification;
34
import org.openscience.cdk.qsar.DescriptorValue;
35
import org.openscience.cdk.qsar.IMolecularDescriptor;
36
import org.openscience.cdk.qsar.result.IDescriptorResult;
37
import org.openscience.cdk.qsar.result.IntegerResult;
38
import org.openscience.cdk.ringsearch.AllRingsFinder;
40
import java.util.Iterator;
43
* This Class contains a method that returns the number of aromatic atoms in an AtomContainer.
45
* <p>This descriptor uses these parameters:
50
* <td>Description</td>
53
* <td>checkAromaticity</td>
55
* <td>True is the aromaticity has to be checked</td>
59
* Returns a single value with name <i>nAromBond</i>
62
* @cdk.created 2004-11-03
64
* @cdk.set qsar-descriptors
65
* @cdk.dictref qsar-descriptors:aromaticBondsCount
67
public class AromaticBondsCountDescriptor implements IMolecularDescriptor {
68
private boolean checkAromaticity = false;
72
* Constructor for the AromaticBondsCountDescriptor object.
74
public AromaticBondsCountDescriptor() { }
77
* Returns a <code>Map</code> which specifies which descriptor
78
* is implemented by this class.
80
* These fields are used in the map:
82
* <li>Specification-Reference: refers to an entry in a unique dictionary
83
* <li>Implementation-Title: anything
84
* <li>Implementation-Identifier: a unique identifier for this version of
86
* <li>Implementation-Vendor: CDK, JOELib, or anything else
89
* @return An object containing the descriptor specification
92
public DescriptorSpecification getSpecification() {
93
return new DescriptorSpecification(
94
"http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#aromaticBondsCount",
95
this.getClass().getName(),
96
"$Id: AromaticBondsCountDescriptor.java 9057 2007-10-14 18:35:55Z egonw $",
97
"The Chemistry Development Kit");
102
* Sets the parameters attribute of the AromaticBondsCountDescriptor object.
104
* This descriptor takes one parameter, which should be Boolean to indicate whether
105
* aromaticity has been checked (TRUE) or not (FALSE).
107
* @param params The new parameters value
108
* @exception CDKException if more than one parameter or a non-Boolean parameter is specified
111
public void setParameters(Object[] params) throws CDKException {
112
if (params.length != 1) {
113
throw new CDKException("AromaticBondsCountDescriptor expects one parameter");
115
if (!(params[0] instanceof Boolean)) {
116
throw new CDKException("The first parameter must be of type Boolean");
118
// ok, all should be fine
119
checkAromaticity = ((Boolean) params[0]).booleanValue();
124
* Gets the parameters attribute of the AromaticBondsCountDescriptor object.
126
*@return The parameters value
129
public Object[] getParameters() {
130
// return the parameters as used for the descriptor calculation
131
Object[] params = new Object[1];
132
params[0] = new Boolean(checkAromaticity);
138
* Calculate the count of aromatic atoms in the supplied {@link IAtomContainer}.
140
* The method take a boolean checkAromaticity: if the boolean is true, it means that
141
* aromaticity has to be checked.
143
*@param atomContainer The {@link IAtomContainer} for which this descriptor is to be calculated
144
*@return the number of aromatic atoms of this AtomContainer
145
*@throws CDKException if there is a problem in atomaticity detection
148
public DescriptorValue calculate(IAtomContainer atomContainer) throws CDKException {
151
ac = (IAtomContainer) atomContainer.clone();
152
} catch (CloneNotSupportedException e) {
153
throw new CDKException("Error during clone");
157
int aromaticBondsCount = 0;
158
if (checkAromaticity) {
159
IRingSet rs = (new AllRingsFinder()).findAllRings(ac);
160
HueckelAromaticityDetector.detectAromaticity(ac, rs, true);
162
Iterator bonds = ac.bonds();
163
while (bonds.hasNext()) {
164
IBond bond = (IBond) bonds.next();
165
if (bond.getFlag(CDKConstants.ISAROMATIC)) {
166
aromaticBondsCount += 1;
169
return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(),
170
new IntegerResult(aromaticBondsCount), new String[] {"nAromBond"});
174
* Returns the specific type of the DescriptorResult object.
176
* The return value from this method really indicates what type of result will
177
* be obtained from the {@link org.openscience.cdk.qsar.DescriptorValue} object. Note that the same result
178
* can be achieved by interrogating the {@link org.openscience.cdk.qsar.DescriptorValue} object; this method
179
* allows you to do the same thing, without actually calculating the descriptor.
181
* @return an object that implements the {@link org.openscience.cdk.qsar.result.IDescriptorResult} interface indicating
182
* the actual type of values returned by the descriptor in the {@link org.openscience.cdk.qsar.DescriptorValue} object
184
public IDescriptorResult getDescriptorResultType() {
185
return new IntegerResult(1);
190
* Gets the parameterNames attribute of the AromaticBondsCountDescriptor object.
192
*@return The parameterNames value
194
public String[] getParameterNames() {
195
String[] params = new String[1];
196
params[0] = "checkAromaticity";
203
* Gets the parameterType attribute of the AromaticBondsCountDescriptor object.
205
*@param name Description of the Parameter
206
*@return An Object of class equal to that of the parameter being requested
208
public Object getParameterType(String name) {
209
return new Boolean(true);