1
/* $Revision: 7894 $ $Author: egonw $ $Date: 2007-02-07 23:15:58 +0100 (Wed, 07 Feb 2007) $
3
* Copyright (C) 2004-2007 Matteo Floris <mfe4@users.sf.net>
5
* Contact: cdk-devel@lists.sourceforge.net
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public License
9
* as published by the Free Software Foundation; either version 2.1
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
package org.openscience.cdk.qsar.descriptors.molecular;
23
import org.openscience.cdk.exception.CDKException;
24
import org.openscience.cdk.interfaces.IAtomContainer;
25
import org.openscience.cdk.interfaces.IBond;
26
import org.openscience.cdk.qsar.DescriptorSpecification;
27
import org.openscience.cdk.qsar.DescriptorValue;
28
import org.openscience.cdk.qsar.IMolecularDescriptor;
29
import org.openscience.cdk.qsar.result.IDescriptorResult;
30
import org.openscience.cdk.qsar.result.IntegerResult;
32
import java.util.Iterator;
35
* IDescriptor based on the number of bonds of a certain bond order.
37
* <p>This descriptor uses these parameters:
42
* <td>Description</td>
47
* <td>The bond order</td>
51
* Returns a single value with name <i>nBX</i> where <i>X</i> can be
53
* <li>s for single bonds
54
* <li>d for double bonds
55
* <li>t for triple bonds
56
* <li>a for aromatic bonds
57
* <li>"" for all bonds
61
* @cdk.created 2004-11-13
63
* @cdk.set qsar-descriptors
64
* @cdk.dictref qsar-descriptors:bondCount
66
public class BondCountDescriptor implements IMolecularDescriptor {
68
/** defaults to -1.0, which means: count all bonds **/
69
private double order = -1.0;
72
* Constructor for the BondCountDescriptor object
74
public BondCountDescriptor() { }
78
* Gets the specification attribute of the BondCountDescriptor object
80
*@return The specification value
82
public DescriptorSpecification getSpecification() {
83
return new DescriptorSpecification(
84
"http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#bondCount",
85
this.getClass().getName(),
86
"$Id: BondCountDescriptor.java 7894 2007-02-07 22:15:58Z egonw $",
87
"The Chemistry Development Kit");
92
* Sets the parameters attribute of the BondCountDescriptor object
94
*@param params The new parameters value
95
*@exception CDKException Description of the Exception
97
public void setParameters(Object[] params) throws CDKException {
98
if (params.length > 1) {
99
throw new CDKException("BondCount only expects one parameter");
101
if (!(params[0] instanceof Double)) {
102
throw new CDKException("The parameter must be of type Double");
104
// ok, all should be fine
105
order = ((Double) params[0]).doubleValue();
110
* Gets the parameters attribute of the BondCountDescriptor object
112
*@return The parameters value
114
public Object[] getParameters() {
115
// return the parameters as used for the descriptor calculation
116
Object[] params = new Object[1];
117
params[0] = new Double(order);
123
* This method calculate the number of bonds of a given type in an atomContainer
125
*@param container AtomContainer
126
*@return The number of bonds of a certain type.
128
public DescriptorValue calculate(IAtomContainer container) {
130
// the special case: just count them all
131
return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(),
132
new IntegerResult(container.getBondCount()), new String[]{"nB"});
136
Iterator bonds = container.bonds();
137
while (bonds.hasNext()) {
138
IBond bond = (IBond) bonds.next();
139
if (bond.getOrder() == order) {
145
if (order == 1) name += "s";
146
else if (order == 2) name += "d";
147
else if (order == 3) name += "t";
148
else if (order == 1.5) name += "a";
150
return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(),
151
new IntegerResult(bondCount), new String[]{name});
155
* Returns the specific type of the DescriptorResult object.
157
* The return value from this method really indicates what type of result will
158
* be obtained from the {@link org.openscience.cdk.qsar.DescriptorValue} object. Note that the same result
159
* can be achieved by interrogating the {@link org.openscience.cdk.qsar.DescriptorValue} object; this method
160
* allows you to do the same thing, without actually calculating the descriptor.
162
* @return an object that implements the {@link org.openscience.cdk.qsar.result.IDescriptorResult} interface indicating
163
* the actual type of values returned by the descriptor in the {@link org.openscience.cdk.qsar.DescriptorValue} object
165
public IDescriptorResult getDescriptorResultType() {
166
return new IntegerResult(1);
171
* Gets the parameterNames attribute of the BondCountDescriptor object
173
*@return The parameterNames value
175
public String[] getParameterNames() {
176
String[] params = new String[1];
183
* Gets the parameterType attribute of the BondCountDescriptor object
185
*@param name Description of the Parameter
186
*@return The parameterType value
188
public Object getParameterType(String name) {
189
return new Double(0.0);