~ubuntu-branches/ubuntu/trusty/cdk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/qsar/descriptors/molecular/HBondAcceptorCountDescriptor.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 21:39:12 +0200 (Sun, 14 Oct 2007) $
 
5
 *  $Revision: 9058 $
 
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.IAtom;
 
31
import org.openscience.cdk.interfaces.IAtomContainer;
 
32
import org.openscience.cdk.qsar.DescriptorSpecification;
 
33
import org.openscience.cdk.qsar.DescriptorValue;
 
34
import org.openscience.cdk.qsar.IMolecularDescriptor;
 
35
import org.openscience.cdk.qsar.result.IDescriptorResult;
 
36
import org.openscience.cdk.qsar.result.IntegerResult;
 
37
 
 
38
/**
 
39
 * This descriptor calculates the number of hydrogen bond acceptors using a slightly simplified version of the
 
40
 * <a href="http://www.chemie.uni-erlangen.de/model2001/abstracts/rester.html">PHACIR atom types</a>.
 
41
 * The following groups are counted as hydrogen bond acceptors:
 
42
 * <ul>
 
43
 * <li>any oxygen where the formal charge of the oxygen is non-positive (i.e. formal charge <= 0) <b>except</b></li>
 
44
 * <ol>
 
45
 * <li>an aromatic ether oxygen (i.e. an ether oxygen that is adjacent to at least one aromatic carbon)</li>
 
46
 * <li>an oxygen that is adjacent to a nitrogen</li>
 
47
 * </ol>
 
48
 * <li>any nitrogen where the formal charge of the nitrogen is non-positive (i.e. formal charge <= 0) <b>except</b></li>
 
49
 * <ol>
 
50
 * <li>a nitrogen that is adjacent to an oxygen</li>
 
51
 * </ol>
 
52
 * </ul>
 
53
 *
 
54
 * Returns a single value named <i>nHBAcc</i>.
 
55
 *
 
56
 * <p>This descriptor uses these parameters:
 
57
 * <table>
 
58
 *   <tr>
 
59
 *     <td>Name</td>
 
60
 *     <td>Default</td>
 
61
 *     <td>Description</td>
 
62
 *   </tr>
 
63
 *   <tr>
 
64
 *     <td>checkAromaticity</td>
 
65
 *     <td>false</td>
 
66
 *     <td>true if the aromaticity has to be checked</td>
 
67
 *   </tr>
 
68
 * </table>
 
69
 * <p>
 
70
 * This descriptor works properly with AtomContainers whose atoms contain <b>implicit hydrogens</b> or <b>explicit
 
71
 * hydrogens</b>.
 
72
 * 
 
73
 * @author      ulif
 
74
 * @cdk.created 2005-22-07
 
75
 * @cdk.module  qsar
 
76
 * @cdk.set     qsar-descriptors
 
77
 * @cdk.dictref qsar-descriptors:hBondacceptors
 
78
 */
 
79
public class HBondAcceptorCountDescriptor implements IMolecularDescriptor {
 
80
    // only parameter of this descriptor; true if aromaticity has to be checked prior to descriptor calculation, false otherwise
 
81
    private boolean checkAromaticity = false;
 
82
 
 
83
  /**
 
84
     *  Constructor for the HBondAcceptorCountDescriptor object
 
85
     */
 
86
    public HBondAcceptorCountDescriptor() { }
 
87
 
 
88
    /**
 
89
     * Gets the specification attribute of the HBondAcceptorCountDescriptor object.
 
90
     *
 
91
     * @return    The specification value
 
92
     */
 
93
    public DescriptorSpecification getSpecification() {
 
94
        return new DescriptorSpecification(
 
95
            "http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#hBondacceptors",
 
96
            this.getClass().getName(),
 
97
            "$Id: HBondAcceptorCountDescriptor.java 9058 2007-10-14 19:39:12Z egonw $",
 
98
            "The Chemistry Development Kit");
 
99
    }
 
100
 
 
101
    /**
 
102
     * Sets the parameters attribute of the HBondAcceptorCountDescriptor object.
 
103
     *
 
104
     * @param  params            a boolean true means that aromaticity has to be checked
 
105
     * @exception  CDKException  Description of the Exception
 
106
     */
 
107
    public void setParameters(Object[] params) throws CDKException {
 
108
        if (params.length != 1) {
 
109
            throw new CDKException("HBondAcceptorCountDescriptor expects a single parameter");
 
110
        }
 
111
        if (!(params[0] instanceof Boolean)) {
 
112
            throw new CDKException("The parameter must be of type Boolean");
 
113
        }
 
114
        // ok, all should be fine
 
115
        checkAromaticity = ((Boolean)params[0]).booleanValue();
 
116
    }
 
117
 
 
118
    /**
 
119
     * Gets the parameters attribute of the HBondAcceptorCountDescriptor object.
 
120
     *
 
121
     * @return    The parameters value
 
122
     */
 
123
    public Object[] getParameters() {
 
124
        // return the parameters as used for the descriptor calculation
 
125
        Object[] params = new Object[1];
 
126
        params[0] = new Boolean(checkAromaticity);
 
127
        return params;
 
128
    }
 
129
 
 
130
    /**
 
131
     *  Calculates the number of H bond acceptors.
 
132
     *
 
133
     * @param  atomContainer             AtomContainer
 
134
     * @return                   number of H bond acceptors
 
135
     * @exception  CDKException  Possible Exceptions
 
136
     */
 
137
    public DescriptorValue calculate(IAtomContainer atomContainer) throws CDKException {
 
138
        int hBondAcceptors = 0;
 
139
 
 
140
        IAtomContainer ac;
 
141
        try {
 
142
            ac = (IAtomContainer) atomContainer.clone();
 
143
        } catch (CloneNotSupportedException e) {
 
144
            throw new CDKException("Error during clone");
 
145
        }
 
146
 
 
147
        // aromaticity is detected prior to descriptor calculation if the respective parameter is set to true
 
148
        if (checkAromaticity)
 
149
            HueckelAromaticityDetector.detectAromaticity(ac);
 
150
 
 
151
        //org.openscience.cdk.interfaces.IAtom[] atoms = ac.getAtoms();
 
152
    // labelled for loop to allow for labelled continue statements within the loop
 
153
    atomloop:
 
154
        for (int atomIndex = 0; atomIndex < ac.getAtomCount(); atomIndex++)
 
155
    {
 
156
      // looking for suitable nitrogen atoms
 
157
      if(ac.getAtom(atomIndex).getSymbol().equals("N") && ac.getAtom(atomIndex).getFormalCharge() <= 0)
 
158
      {
 
159
        // excluding nitrogens that are adjacent to an oxygen
 
160
          java.util.List neighbours = ac.getConnectedAtomsList(ac.getAtom(atomIndex));
 
161
        for(int neighbourIndex = 0; neighbourIndex < neighbours.size(); neighbourIndex++)
 
162
          if(((IAtom)neighbours.get(neighbourIndex)).getSymbol().equals("O"))
 
163
            continue atomloop;
 
164
        hBondAcceptors++;
 
165
      }
 
166
      // looking for suitable oxygen atoms
 
167
      if(ac.getAtom(atomIndex).getSymbol().equals("O") && ac.getAtom(atomIndex).getFormalCharge() <= 0)
 
168
      {
 
169
        //excluding oxygens that are adjacent to a nitrogen or to an aromatic carbon
 
170
          java.util.List neighbours = ac.getConnectedAtomsList(ac.getAtom(atomIndex));
 
171
        for(int neighbourIndex = 0; neighbourIndex < neighbours.size(); neighbourIndex++)
 
172
          if(((IAtom)neighbours.get(neighbourIndex)).getSymbol().equals("N") ||
 
173
              (((IAtom)neighbours.get(neighbourIndex)).getSymbol().equals("C") && ((IAtom)neighbours.get(neighbourIndex)).getFlag(CDKConstants.ISAROMATIC)))
 
174
            continue atomloop;
 
175
        hBondAcceptors++;
 
176
      }
 
177
        }
 
178
 
 
179
    return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(),
 
180
            new IntegerResult(hBondAcceptors), new String[] {"nHBAcc"});
 
181
    }
 
182
 
 
183
    /**
 
184
     * Returns the specific type of the DescriptorResult object.
 
185
     * <p/>
 
186
     * The return value from this method really indicates what type of result will
 
187
     * be obtained from the {@link org.openscience.cdk.qsar.DescriptorValue} object. Note that the same result
 
188
     * can be achieved by interrogating the {@link org.openscience.cdk.qsar.DescriptorValue} object; this method
 
189
     * allows you to do the same thing, without actually calculating the descriptor.
 
190
     *
 
191
     * @return an object that implements the {@link org.openscience.cdk.qsar.result.IDescriptorResult} interface indicating
 
192
     *         the actual type of values returned by the descriptor in the {@link org.openscience.cdk.qsar.DescriptorValue} object
 
193
     */
 
194
    public IDescriptorResult getDescriptorResultType() {
 
195
        return new IntegerResult(1);
 
196
    }
 
197
 
 
198
    /**
 
199
     * Gets the parameterNames attribute of the HBondAcceptorCountDescriptor object.
 
200
     *
 
201
     * @return    The parameterNames value
 
202
     */
 
203
    public String[] getParameterNames() {
 
204
        String[] params = new String[1];
 
205
        params[0] = "checkAromaticity";
 
206
        return params;
 
207
    }
 
208
 
 
209
    /**
 
210
     * Gets the parameterType attribute of the HBondAcceptorCountDescriptor object.
 
211
     *
 
212
     * @param  name  Description of the Parameter
 
213
     * @return       The parameterType value
 
214
     */
 
215
    public Object getParameterType(String name) {
 
216
        return Boolean.FALSE;
 
217
    }
 
218
}
 
219