~ubuntu-branches/ubuntu/maverick/cdk/maverick

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/qsar/descriptors/molecular/AromaticBondsCountDescriptor.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  $RCSfile$
 
3
 *  $Author: egonw $
 
4
 *  $Date: 2007-10-14 20:35:55 +0200 (Sun, 14 Oct 2007) $
 
5
 *  $Revision: 9057 $
 
6
 *
 
7
 *  Copyright (C) 2004-2007  The Chemistry Development Kit (CDK) project
 
8
 *
 
9
 *  Contact: cdk-devel@lists.sourceforge.net
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 *
 
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.
 
24
 */
 
25
package org.openscience.cdk.qsar.descriptors.molecular;
 
26
 
 
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;
 
39
 
 
40
import java.util.Iterator;
 
41
 
 
42
/**
 
43
 * This Class contains a method that returns the number of aromatic atoms in an AtomContainer.
 
44
 *
 
45
 * <p>This descriptor uses these parameters:
 
46
 * <table border="1">
 
47
 *   <tr>
 
48
 *     <td>Name</td>
 
49
 *     <td>Default</td>
 
50
 *     <td>Description</td>
 
51
 *   </tr>
 
52
 *   <tr>
 
53
 *     <td>checkAromaticity</td>
 
54
 *     <td>false</td>
 
55
 *     <td>True is the aromaticity has to be checked</td>
 
56
 *   </tr>
 
57
 * </table>
 
58
 *
 
59
 * Returns a single value with name <i>nAromBond</i>
 
60
 *
 
61
 * @author      mfe4
 
62
 * @cdk.created 2004-11-03
 
63
 * @cdk.module  qsar
 
64
 * @cdk.set     qsar-descriptors
 
65
 * @cdk.dictref qsar-descriptors:aromaticBondsCount
 
66
 */
 
67
public class AromaticBondsCountDescriptor implements IMolecularDescriptor {
 
68
    private boolean checkAromaticity = false;
 
69
 
 
70
 
 
71
    /**
 
72
     *  Constructor for the AromaticBondsCountDescriptor object.
 
73
     */
 
74
    public AromaticBondsCountDescriptor() { }
 
75
 
 
76
    /**
 
77
     * Returns a <code>Map</code> which specifies which descriptor
 
78
     * is implemented by this class. 
 
79
     *
 
80
     * These fields are used in the map:
 
81
     * <ul>
 
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
 
85
     *  this class
 
86
     * <li>Implementation-Vendor: CDK, JOELib, or anything else
 
87
     * </ul>
 
88
     *
 
89
     * @return An object containing the descriptor specification
 
90
     */
 
91
 
 
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");
 
98
    }
 
99
 
 
100
 
 
101
    /**
 
102
     *  Sets the parameters attribute of the AromaticBondsCountDescriptor object.
 
103
     *
 
104
     * This descriptor takes one parameter, which should be Boolean to indicate whether
 
105
     * aromaticity has been checked (TRUE) or not (FALSE).
 
106
     * 
 
107
     * @param  params            The new parameters value
 
108
     * @exception  CDKException if more than one parameter or a non-Boolean parameter is specified
 
109
     *@see #getParameters
 
110
     */
 
111
    public void setParameters(Object[] params) throws CDKException {
 
112
        if (params.length != 1) {
 
113
            throw new CDKException("AromaticBondsCountDescriptor expects one parameter");
 
114
        }
 
115
        if (!(params[0] instanceof Boolean)) {
 
116
            throw new CDKException("The first parameter must be of type Boolean");
 
117
        }
 
118
        // ok, all should be fine
 
119
        checkAromaticity = ((Boolean) params[0]).booleanValue();
 
120
    }
 
121
 
 
122
 
 
123
    /**
 
124
     *  Gets the parameters attribute of the AromaticBondsCountDescriptor object.
 
125
     *
 
126
     *@return    The parameters value
 
127
     *@see #setParameters
 
128
     */
 
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);
 
133
        return params;
 
134
    }
 
135
 
 
136
 
 
137
    /**
 
138
     * Calculate the count of aromatic atoms in the supplied {@link IAtomContainer}.
 
139
     *
 
140
     *  The method take a boolean checkAromaticity: if the boolean is true, it means that
 
141
     *  aromaticity has to be checked.
 
142
     *
 
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
 
146
     *@see #setParameters
 
147
     */
 
148
    public DescriptorValue calculate(IAtomContainer atomContainer) throws CDKException {
 
149
        IAtomContainer ac;
 
150
        try {
 
151
            ac = (IAtomContainer) atomContainer.clone();
 
152
        } catch (CloneNotSupportedException e) {
 
153
            throw new CDKException("Error during clone");
 
154
        }
 
155
 
 
156
 
 
157
        int aromaticBondsCount = 0;
 
158
        if (checkAromaticity) {
 
159
            IRingSet rs = (new AllRingsFinder()).findAllRings(ac);
 
160
            HueckelAromaticityDetector.detectAromaticity(ac, rs, true);
 
161
        }
 
162
        Iterator bonds = ac.bonds();
 
163
        while (bonds.hasNext()) {
 
164
            IBond bond = (IBond) bonds.next();
 
165
            if (bond.getFlag(CDKConstants.ISAROMATIC)) {
 
166
                aromaticBondsCount += 1;
 
167
            }
 
168
        }
 
169
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(),
 
170
                new IntegerResult(aromaticBondsCount), new String[] {"nAromBond"});
 
171
    }
 
172
 
 
173
    /**
 
174
     * Returns the specific type of the DescriptorResult object.
 
175
     * <p/>
 
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.
 
180
     *
 
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
 
183
     */
 
184
    public IDescriptorResult getDescriptorResultType() {
 
185
        return new IntegerResult(1);
 
186
    }
 
187
 
 
188
 
 
189
    /**
 
190
     *  Gets the parameterNames attribute of the AromaticBondsCountDescriptor object.
 
191
     *
 
192
     *@return    The parameterNames value
 
193
     */
 
194
    public String[] getParameterNames() {
 
195
        String[] params = new String[1];
 
196
        params[0] = "checkAromaticity";
 
197
        return params;
 
198
    }
 
199
 
 
200
 
 
201
 
 
202
    /**
 
203
     *  Gets the parameterType attribute of the AromaticBondsCountDescriptor object.
 
204
     *
 
205
     *@param  name  Description of the Parameter
 
206
     *@return       An Object of class equal to that of the parameter being requested
 
207
     */
 
208
    public Object getParameterType(String name) {
 
209
        return new Boolean(true);
 
210
    }
 
211
}
 
212