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

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/qsar/descriptors/molecular/RuleOfFiveDescriptor.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
/*  $RCSfile$
 
2
 *  $Author: rajarshi $
 
3
 *  $Date: 2007-02-01 20:46:29 +0100 (Thu, 01 Feb 2007) $
 
4
 *  $Revision: 7844 $
 
5
 *
 
6
 *  Copyright (C) 2004-2007  The Chemistry Development Kit (CDK) project
 
7
 *
 
8
 *  Contact: cdk-devel@lists.sourceforge.net
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or
 
11
 *  modify it under the terms of the GNU Lesser General Public License
 
12
 *  as published by the Free Software Foundation; either version 2.1
 
13
 *  of the License, or (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU Lesser General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU Lesser General Public License
 
21
 *  along with this program; if not, write to the Free Software
 
22
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
23
 */
 
24
package org.openscience.cdk.qsar.descriptors.molecular;
 
25
 
 
26
import org.openscience.cdk.exception.CDKException;
 
27
import org.openscience.cdk.interfaces.IAtomContainer;
 
28
import org.openscience.cdk.qsar.DescriptorSpecification;
 
29
import org.openscience.cdk.qsar.DescriptorValue;
 
30
import org.openscience.cdk.qsar.IMolecularDescriptor;
 
31
import org.openscience.cdk.qsar.result.DoubleResult;
 
32
import org.openscience.cdk.qsar.result.IDescriptorResult;
 
33
import org.openscience.cdk.qsar.result.IntegerResult;
 
34
 
 
35
/**
 
36
 * This Class contains a method that returns the number failures of the
 
37
 * Lipinski's Rule Of 5.
 
38
 * See <a href="http://www.lifechemicals.com/eng/services/HTS/five/">http://www.lifechemicals.com/eng/services/HTS/five/</a>.
 
39
 *
 
40
  * <p>This descriptor uses these parameters:
 
41
 * <table border="1">
 
42
 *   <tr>
 
43
 *     <td>Name</td>
 
44
 *     <td>Default</td>
 
45
 *     <td>Description</td>
 
46
 *   </tr>
 
47
 *   <tr>
 
48
 *     <td>checkAromaticity</td>
 
49
 *     <td>false</td>
 
50
 *     <td>True is the aromaticity has to be checked</td>
 
51
 *   </tr>
 
52
 * </table>
 
53
 *
 
54
 * Returns a single value named <i>LipinskiFailures</i>.
 
55
 *
 
56
 * @author      mfe4
 
57
 * @cdk.created 2004-11-03
 
58
 * @cdk.module  qsar
 
59
 * @cdk.set     qsar-descriptors
 
60
 * @cdk.dictref qsar-descriptors:lipinskifailures
 
61
 * 
 
62
 * @cdk.keyword Lipinski
 
63
 * @cdk.keyword rule-of-five
 
64
 * @cdk.keyword descriptor
 
65
 */
 
66
public class RuleOfFiveDescriptor implements IMolecularDescriptor {
 
67
    private boolean checkAromaticity = false;
 
68
 
 
69
 
 
70
    /**
 
71
     *  Constructor for the RuleOfFiveDescriptor object.
 
72
     */
 
73
    public RuleOfFiveDescriptor() { }
 
74
 
 
75
    /**
 
76
     * Returns a <code>Map</code> which specifies which descriptor
 
77
     * is implemented by this class. 
 
78
     *
 
79
     * These fields are used in the map:
 
80
     * <ul>
 
81
     * <li>Specification-Reference: refers to an entry in a unique dictionary
 
82
     * <li>Implementation-Title: anything
 
83
     * <li>Implementation-Identifier: a unique identifier for this version of
 
84
     *  this class
 
85
     * <li>Implementation-Vendor: CDK, JOELib, or anything else
 
86
     * </ul>
 
87
     *
 
88
     * @return An object containing the descriptor specification
 
89
     */
 
90
    public DescriptorSpecification getSpecification() {
 
91
        return new DescriptorSpecification(
 
92
            "http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#lipinskifailures",
 
93
            this.getClass().getName(),
 
94
            "$Id: RuleOfFiveDescriptor.java 7844 2007-02-01 19:46:29Z rajarshi $",
 
95
            "The Chemistry Development Kit");
 
96
    }
 
97
 
 
98
 
 
99
    /**
 
100
     *  Sets the parameters attribute of the RuleOfFiveDescriptor object.
 
101
         *
 
102
         *  There is only one parameter, which should be a Boolean indicating whether
 
103
         *  aromaticity should be checked or has already been checked. The name of the paramete
 
104
         *  is checkAromaticity.
 
105
     *
 
106
     *@param  params            Parameter is only one: a boolean.
 
107
     *@throws  CDKException  if more than 1 parameter or a non-Boolean parameter is specified
 
108
         *@see #getParameters
 
109
     */
 
110
    public void setParameters(Object[] params) throws CDKException {
 
111
        if (params.length != 1) {
 
112
            throw new CDKException("RuleOfFiveDescriptor expects one parameter");
 
113
        }
 
114
        if (!(params[0] instanceof Boolean)) {
 
115
            throw new CDKException("The first parameter must be of type Boolean");
 
116
        }
 
117
        // ok, all should be fine
 
118
        checkAromaticity = ((Boolean) params[0]).booleanValue();
 
119
    }
 
120
 
 
121
 
 
122
    /**
 
123
     *  Gets the parameters attribute of the RuleOfFiveDescriptor object.
 
124
     *
 
125
     *@return    The parameters value
 
126
         *@see #setParameters
 
127
     */
 
128
    public Object[] getParameters() {
 
129
        // return the parameters as used for the descriptor calculation
 
130
        Object[] params = new Object[1];
 
131
        params[0] = new Boolean(checkAromaticity);
 
132
        return params;
 
133
    }
 
134
 
 
135
 
 
136
    /**
 
137
     *  the method take a boolean checkAromaticity: if the boolean is true, it means that
 
138
     *  aromaticity has to be checked.
 
139
     *
 
140
     *@param  mol   AtomContainer for which this descriptor is to be calculated
 
141
     *@return    The number of failures of the Lipinski rule
 
142
     *@throws  CDKException  if the following descriptors throw an exception:
 
143
         * {@link org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor},  {@link HBondAcceptorCountDescriptor}, {@link HBondDonorCountDescriptor},
 
144
         * {@link org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor}, {@link org.openscience.cdk.qsar.descriptors.molecular.RotatableBondsCountDescriptor},
 
145
     */
 
146
    public DescriptorValue calculate(IAtomContainer mol) throws CDKException {
 
147
 
 
148
        int lipinskifailures = 0;
 
149
 
 
150
        IMolecularDescriptor xlogP = new XLogPDescriptor();
 
151
        Object[] xlogPparams = {
 
152
            new Boolean(checkAromaticity),
 
153
            Boolean.TRUE,
 
154
        };
 
155
        xlogP.setParameters(xlogPparams);
 
156
        double xlogPvalue = ((DoubleResult)xlogP.calculate(mol).getValue()).doubleValue();
 
157
 
 
158
        IMolecularDescriptor acc = new HBondAcceptorCountDescriptor();
 
159
        Object[] hBondparams = { new Boolean(checkAromaticity) };
 
160
        acc.setParameters(hBondparams);
 
161
        int acceptors = ((IntegerResult)acc.calculate(mol).getValue()).intValue();
 
162
 
 
163
        IMolecularDescriptor don = new HBondDonorCountDescriptor();
 
164
        don.setParameters(hBondparams);
 
165
        int donors = ((IntegerResult)don.calculate(mol).getValue()).intValue();
 
166
 
 
167
        IMolecularDescriptor mw = new WeightDescriptor();
 
168
        Object[] mwparams = {new String("")};
 
169
        mw.setParameters(mwparams);
 
170
        double mwvalue = ((DoubleResult)mw.calculate(mol).getValue()).doubleValue();
 
171
 
 
172
        IMolecularDescriptor rotata = new RotatableBondsCountDescriptor();
 
173
        rotata.setParameters(hBondparams);
 
174
        int rotatablebonds = ((IntegerResult)rotata.calculate(mol).getValue()).intValue();
 
175
 
 
176
        if(xlogPvalue > 5.0) { lipinskifailures += 1; }
 
177
        if(acceptors > 10) { lipinskifailures += 1; }
 
178
        if(donors > 5) { lipinskifailures += 1; }
 
179
        if(mwvalue > 500.0) { lipinskifailures += 1; }
 
180
        if(rotatablebonds > 10.0) { lipinskifailures += 1; }
 
181
 
 
182
 
 
183
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult(lipinskifailures),
 
184
                new String[] {"LipinksiFailures"});
 
185
    }
 
186
 
 
187
    /**
 
188
     * Returns the specific type of the DescriptorResult object.
 
189
     * <p/>
 
190
     * The return value from this method really indicates what type of result will
 
191
     * be obtained from the {@link org.openscience.cdk.qsar.DescriptorValue} object. Note that the same result
 
192
     * can be achieved by interrogating the {@link org.openscience.cdk.qsar.DescriptorValue} object; this method
 
193
     * allows you to do the same thing, without actually calculating the descriptor.
 
194
     *
 
195
     * @return an object that implements the {@link org.openscience.cdk.qsar.result.IDescriptorResult} interface indicating
 
196
     *         the actual type of values returned by the descriptor in the {@link org.openscience.cdk.qsar.DescriptorValue} object
 
197
     */
 
198
    public IDescriptorResult getDescriptorResultType() {
 
199
        return new IntegerResult(1);
 
200
    }
 
201
 
 
202
 
 
203
    /**
 
204
     *  Gets the parameterNames attribute of the RuleOfFiveDescriptor object.
 
205
     *
 
206
     *@return    The parameterNames value
 
207
     */
 
208
    public String[] getParameterNames() {
 
209
        String[] params = new String[1];
 
210
        params[0] = "checkAromaticity";
 
211
        return params;
 
212
    }
 
213
 
 
214
 
 
215
 
 
216
    /**
 
217
     *  Gets the parameterType attribute of the RuleOfFiveDescriptor object.
 
218
     *
 
219
     *@param  name  The name of the parameter. In this case it is 'checkAromaticity'.
 
220
     *@return       An Object of class equal to that of the parameter being requested
 
221
     */
 
222
    public Object getParameterType(String name) {
 
223
        return new Boolean(true);
 
224
    }
 
225
}
 
226