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

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/qsar/descriptors/atomic/InductiveAtomicSoftnessDescriptor.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-04-16 10:40:19 +0200 (Mon, 16 Apr 2007) $
 
5
 *  $Revision: 8201 $
 
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.atomic;
 
26
 
 
27
import java.io.IOException;
 
28
 
 
29
import javax.vecmath.Point3d;
 
30
 
 
31
import org.openscience.cdk.config.AtomTypeFactory;
 
32
import org.openscience.cdk.exception.CDKException;
 
33
import org.openscience.cdk.interfaces.IAtom;
 
34
import org.openscience.cdk.interfaces.IAtomContainer;
 
35
import org.openscience.cdk.interfaces.IAtomType;
 
36
import org.openscience.cdk.qsar.DescriptorSpecification;
 
37
import org.openscience.cdk.qsar.DescriptorValue;
 
38
import org.openscience.cdk.qsar.IAtomicDescriptor;
 
39
import org.openscience.cdk.qsar.result.DoubleResult;
 
40
import org.openscience.cdk.tools.LoggingTool;
 
41
/**
 
42
 *  Inductive atomic softness of an atom in a polyatomic system can be defined
 
43
 *  as charge delocalizing ability. Only works with 3D coordinates, which must be calculated beforehand. <p>
 
44
 *
 
45
 *  This descriptor uses these parameters:
 
46
 *  <tableborder="1">
 
47
 *
 
48
 *    <tr>
 
49
 *
 
50
 *      <td>
 
51
 *        Name
 
52
 *      </td>
 
53
 *
 
54
 *      <td>
 
55
 *        Default
 
56
 *      </td>
 
57
 *
 
58
 *      <td>
 
59
 *        Description
 
60
 *      </td>
 
61
 *
 
62
 *    </tr>
 
63
 *
 
64
 *    <tr>
 
65
 *
 
66
 *      <td>
 
67
 *        
 
68
 *      </td>
 
69
 *
 
70
 *      <td>
 
71
 *        
 
72
 *      </td>
 
73
 *
 
74
 *      <td>
 
75
 *        no parameters
 
76
 *      </td>
 
77
 *
 
78
 *    </tr>
 
79
 *
 
80
 *  </table>
 
81
 *
 
82
 *
 
83
 *@author         mfe4
 
84
 *@cdk.created    2004-11-03
 
85
 *@cdk.module     qsar
 
86
 *@cdk.set        qsar-descriptors
 
87
 * @cdk.dictref qsar-descriptors:atomicSoftness
 
88
 */
 
89
public class InductiveAtomicSoftnessDescriptor implements IAtomicDescriptor {
 
90
 
 
91
        private LoggingTool logger;
 
92
        private AtomTypeFactory factory = null;
 
93
 
 
94
 
 
95
        /**
 
96
         *  Constructor for the InductiveAtomicSoftnessDescriptor object
 
97
         *
 
98
         *@exception  IOException             Description of the Exception
 
99
         *@exception  ClassNotFoundException  Description of the Exception
 
100
         */
 
101
        public InductiveAtomicSoftnessDescriptor() throws IOException, ClassNotFoundException {
 
102
                logger = new LoggingTool(this);
 
103
        }
 
104
 
 
105
 
 
106
        /**
 
107
         *  Gets the specification attribute of the InductiveAtomicSoftnessDescriptor
 
108
         *  object
 
109
         *
 
110
         *@return    The specification value
 
111
         */
 
112
        public DescriptorSpecification getSpecification() {
 
113
                return new DescriptorSpecification(
 
114
                                "http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#atomicSoftness",
 
115
                                this.getClass().getName(),
 
116
                                "$Id: InductiveAtomicSoftnessDescriptor.java 8201 2007-04-16 08:40:19Z egonw $",
 
117
                                "The Chemistry Development Kit");
 
118
        }
 
119
 
 
120
 
 
121
        /**
 
122
     * This descriptor does have any parameter.
 
123
     */
 
124
    public void setParameters(Object[] params) throws CDKException {
 
125
    }
 
126
 
 
127
 
 
128
        /**
 
129
         *  Gets the parameters attribute of the InductiveAtomicSoftnessDescriptor
 
130
         *  object
 
131
         *
 
132
         * @return    The parameters value
 
133
     * @see #setParameters
 
134
     */
 
135
    public Object[] getParameters() {
 
136
        return null;
 
137
    }
 
138
 
 
139
 
 
140
        /**
 
141
         *  It is needed to call the addExplicitHydrogensToSatisfyValency method from
 
142
         *  the class tools.HydrogenAdder, and 3D coordinates.
 
143
         *
 
144
         *@param  atom              The IAtom for which the DescriptorValue is requested
 
145
     *@param  ac                AtomContainer
 
146
         *@return                   a double with polarizability of the heavy atom
 
147
         *@exception  CDKException  if any atom in the supplied AtomContainer has no 3D coordinates
 
148
         */
 
149
        public DescriptorValue calculate(IAtom atom, IAtomContainer ac) throws CDKException {
 
150
                if (factory == null)
 
151
            try {
 
152
                factory = AtomTypeFactory.getInstance(
 
153
                    "org/openscience/cdk/config/data/jmol_atomtypes.txt", 
 
154
                    ac.getBuilder()
 
155
                );
 
156
            } catch (Exception exception) {
 
157
                throw new CDKException("Could not instantiate AtomTypeFactory!", exception);
 
158
            }
 
159
 
 
160
 
 
161
                java.util.Iterator allAtoms = ac.atoms();
 
162
            IAtom target = atom;
 
163
            double atomicSoftness = 0;
 
164
            double radiusTarget = 0;
 
165
            
 
166
            atomicSoftness = 0;
 
167
            double partial = 0;
 
168
            double radius = 0;
 
169
            String symbol = null;
 
170
            IAtomType type = null;
 
171
            try {
 
172
                symbol = target.getSymbol();
 
173
                type = factory.getAtomType(symbol);
 
174
                radiusTarget = type.getCovalentRadius();
 
175
            } catch (Exception ex1) {
 
176
                logger.debug(ex1);
 
177
                throw new CDKException("Problems with AtomTypeFactory due to " + ex1.toString(), ex1);
 
178
            }
 
179
 
 
180
            while (allAtoms.hasNext()) {
 
181
                IAtom curAtom = (IAtom)allAtoms.next();
 
182
                if (target.getPoint3d() == null || curAtom.getPoint3d() == null) {
 
183
                    throw new CDKException("The target atom or current atom had no 3D coordinates. These are required");
 
184
                }
 
185
                if (!target.equals(curAtom)) {
 
186
                    partial = 0;
 
187
                    symbol = curAtom.getSymbol();
 
188
                    try {
 
189
                        type = factory.getAtomType(symbol);
 
190
                    } catch (Exception ex1) {
 
191
                        logger.debug(ex1);
 
192
                        throw new CDKException("Problems with AtomTypeFactory due to " + ex1.toString(), ex1);
 
193
                    }
 
194
 
 
195
                    radius = type.getCovalentRadius();
 
196
                    partial += radius * radius;
 
197
                    partial += (radiusTarget * radiusTarget);
 
198
                    partial = partial / (calculateSquareDistanceBetweenTwoAtoms(curAtom, target));
 
199
                    //logger.debug("SOFT: atom "+symbol+", radius "+radius+", distance "+calculateSquareDistanceBetweenTwoAtoms(allAtoms[i], target));
 
200
                    atomicSoftness += partial;
 
201
                }
 
202
            }
 
203
 
 
204
            atomicSoftness = 2 * atomicSoftness;
 
205
            atomicSoftness = atomicSoftness * 0.172;
 
206
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(atomicSoftness));
 
207
        }
 
208
 
 
209
        private double calculateSquareDistanceBetweenTwoAtoms(org.openscience.cdk.interfaces.IAtom atom1, org.openscience.cdk.interfaces.IAtom atom2) {
 
210
                double distance = 0;
 
211
                double tmp = 0;
 
212
                Point3d firstPoint = atom1.getPoint3d();
 
213
                Point3d secondPoint = atom2.getPoint3d();
 
214
                tmp = firstPoint.distance(secondPoint);
 
215
                distance = tmp * tmp;
 
216
                return distance;
 
217
        }
 
218
 
 
219
 
 
220
        /**
 
221
         *  Gets the parameterNames attribute of the InductiveAtomicSoftnessDescriptor  object.
 
222
         *
 
223
         * @return    The parameterNames value
 
224
         */
 
225
        public String[] getParameterNames() {
 
226
        return new String[0];
 
227
    }
 
228
 
 
229
 
 
230
        /**
 
231
         *  Gets the parameterType attribute of the InductiveAtomicSoftnessDescriptor object.
 
232
         *
 
233
         * @param  name  Description of the Parameter
 
234
     * @return       An Object of class equal to that of the parameter being requested
 
235
     */
 
236
    public Object getParameterType(String name) {
 
237
        return null;
 
238
    }
 
239
}
 
240