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

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/qsar/descriptors/atomic/RDFProtonDescriptor_G3R.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
/* $Revision: 7895 $ $Author: egonw $ $Date: 2007-02-07 23:20:44 +0100 (Wed, 07 Feb 2007) $
 
2
 *
 
3
 * Copyright (C) 2004-2007  Matteo Floris <mfe4@users.sf.net>
 
4
 * Copyright (C) 2006-2007  Federico
 
5
 *
 
6
 * Contact: cdk-devel@lists.sourceforge.net
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public License
 
10
 * as published by the Free Software Foundation; either version 2.1
 
11
 * of the License, or (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
21
 */
 
22
package org.openscience.cdk.qsar.descriptors.atomic;
 
23
 
 
24
import org.openscience.cdk.AtomContainerSet;
 
25
import org.openscience.cdk.CDKConstants;
 
26
import org.openscience.cdk.Molecule;
 
27
import org.openscience.cdk.Ring;
 
28
import org.openscience.cdk.aromaticity.HueckelAromaticityDetector;
 
29
import org.openscience.cdk.charges.GasteigerMarsiliPartialCharges;
 
30
import org.openscience.cdk.exception.CDKException;
 
31
import org.openscience.cdk.graph.invariant.ConjugatedPiSystemsDetector;
 
32
import org.openscience.cdk.interfaces.IAtom;
 
33
import org.openscience.cdk.interfaces.IAtomContainer;
 
34
import org.openscience.cdk.interfaces.IBond;
 
35
import org.openscience.cdk.interfaces.IRingSet;
 
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.DoubleArrayResult;
 
40
import org.openscience.cdk.ringsearch.AllRingsFinder;
 
41
import org.openscience.cdk.tools.LoggingTool;
 
42
 
 
43
import javax.vecmath.Point3d;
 
44
import javax.vecmath.Vector3d;
 
45
import java.util.ArrayList;
 
46
import java.util.Iterator;
 
47
import java.util.List;
 
48
 
 
49
/**
 
50
 * This class calculates G3R proton descriptors used in neural networks for H1
 
51
 * NMR shift.
 
52
 * 
 
53
 * <p>
 
54
 * This descriptor uses these parameters: <table border="1">
 
55
 * <tr>
 
56
 * <td>Name</td>
 
57
 * <td>Default</td>
 
58
 * <td>Description</td>
 
59
 * </tr>
 
60
 * <tr>
 
61
 * <td>checkAromaticity</td>
 
62
 * <td>false</td>
 
63
 * <td>True is the aromaticity has to be checked</td>
 
64
 * </tr>
 
65
 * </table>
 
66
 * 
 
67
 * @author      Federico
 
68
 * @cdk.created 2006-12-11
 
69
 * @cdk.module  qsar
 
70
 * @cdk.set     qsar-descriptors
 
71
 * @cdk.dictref qsar-descriptors:rdfProtonCalculatedValues
 
72
 * @cdk.bug     1632419
 
73
 */
 
74
public class RDFProtonDescriptor_G3R implements IAtomicDescriptor {
 
75
 
 
76
        private boolean checkAromaticity = false;
 
77
 
 
78
        private IAtomContainer acold = null;
 
79
 
 
80
        private IRingSet varRingSet = null;
 
81
 
 
82
        private AtomContainerSet varAtomContainerSet = null;
 
83
        
 
84
    private final static LoggingTool logger = new LoggingTool(RDFProtonDescriptor_G3R.class);
 
85
 
 
86
        private static String[] descriptorNames;
 
87
 
 
88
        /**
 
89
         * Constructor for the RDFProtonDescriptor object
 
90
         */
 
91
        public RDFProtonDescriptor_G3R() {
 
92
        }
 
93
 
 
94
        /**
 
95
         * Gets the specification attribute of the RDFProtonDescriptor_G3R object
 
96
         * 
 
97
         * @return The specification value
 
98
         */
 
99
        public DescriptorSpecification getSpecification() {
 
100
                return new DescriptorSpecification(
 
101
                                "http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#rdfProtonCalculatedValues",
 
102
                                this.getClass().getName(),
 
103
                                "$Id: RDFProtonDescriptor.java 7032 2006-09-22 15:26:48 +0000 (ven, 22 set 2006) kaihartmann $",
 
104
                                "The Chemistry Development Kit");
 
105
        }
 
106
 
 
107
        /**
 
108
         * Sets the parameters attribute of the RDFProtonDescriptor object
 
109
         * 
 
110
         * @param params
 
111
         *            Parameters are the proton position and a boolean (true if you
 
112
         *            need to detect aromaticity)
 
113
         * @exception CDKException
 
114
         *                Possible Exceptions
 
115
         */
 
116
        public void setParameters(Object[] params) throws CDKException {
 
117
                if (params.length > 1) {
 
118
                        throw new CDKException(
 
119
                                        "RDFProtonDescriptor only expects one parameters");
 
120
                }
 
121
                if (!(params[0] instanceof Boolean)) {
 
122
                        throw new CDKException(
 
123
                                        "The second parameter must be of type Boolean");
 
124
                }
 
125
                checkAromaticity = ((Boolean) params[0]).booleanValue();
 
126
        }
 
127
 
 
128
        /**
 
129
         * Gets the parameters attribute of the RDFProtonDescriptor object
 
130
         * 
 
131
         * @return The parameters value
 
132
         */
 
133
        public Object[] getParameters() {
 
134
                // return the parameters as used for the descriptor calculation
 
135
                Object[] params = new Object[1];
 
136
                params[0] = Boolean.valueOf(checkAromaticity);
 
137
                return params;
 
138
        }
 
139
 
 
140
        public DescriptorValue calculate(IAtom atom,
 
141
                        IAtomContainer varAtomContainerSet) throws CDKException {
 
142
                return (calculate(atom, varAtomContainerSet, null));
 
143
        }
 
144
 
 
145
        public DescriptorValue calculate(IAtom atom,
 
146
                        IAtomContainer atomContainer, IRingSet precalculatedringset)
 
147
                        throws CDKException {
 
148
 
 
149
        IAtomContainer varAtomContainer;
 
150
        try {
 
151
            varAtomContainer = (IAtomContainer) atomContainer.clone();
 
152
        } catch (CloneNotSupportedException e) {
 
153
            throw new CDKException("Error during clone");
 
154
        }
 
155
 
 
156
        int atomPosition = atomContainer.getAtomNumber(atom);
 
157
        IAtom clonedAtom = varAtomContainer.getAtom(atomPosition);
 
158
 
 
159
                final int g3r_desc_length = 13;
 
160
 
 
161
                DoubleArrayResult rdfProtonCalculatedValues = new DoubleArrayResult(
 
162
                                g3r_desc_length);
 
163
                if (!atom.getSymbol().equals("H")) {
 
164
                        throw new CDKException("You tried calculation on a "
 
165
                                        + atom.getSymbol()
 
166
                                        + " atom. This is not allowed! Atom must be a H atom.");
 
167
                }
 
168
 
 
169
                // ///////////////////////FIRST SECTION OF MAIN METHOD: DEFINITION OF
 
170
                // MAIN VARIABLES
 
171
                // ///////////////////////AND AROMATICITY AND PI-SYSTEM AND RINGS
 
172
                // DETECTION
 
173
 
 
174
                Molecule mol = new Molecule(varAtomContainer);
 
175
                if (varAtomContainer != acold) {
 
176
                        acold = varAtomContainer;
 
177
                        // DETECTION OF pi SYSTEMS
 
178
                        varAtomContainerSet = ConjugatedPiSystemsDetector.detect(mol);
 
179
                        if (precalculatedringset == null)
 
180
                                varRingSet = (new AllRingsFinder())
 
181
                                                .findAllRings(varAtomContainer);
 
182
                        else
 
183
                                varRingSet = precalculatedringset;
 
184
                        try {
 
185
                                GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges();
 
186
                                peoe.assignGasteigerMarsiliSigmaPartialCharges(mol, true);
 
187
                        } catch (Exception ex1) {
 
188
                                throw new CDKException(
 
189
                                                "Problems with assignGasteigerMarsiliPartialCharges due to "
 
190
                                                                + ex1.toString(), ex1);
 
191
                        }
 
192
                }
 
193
                if (checkAromaticity) {
 
194
                        HueckelAromaticityDetector.detectAromaticity(varAtomContainer,
 
195
                                        varRingSet, true);
 
196
                }
 
197
                List rsAtom;
 
198
                Ring ring;
 
199
                List ringsWithThisBond;
 
200
                // SET ISINRING FLAGS FOR BONDS
 
201
//              org.openscience.cdk.interfaces.IBond[] bondsInContainer = varAtomContainer.getBonds();
 
202
 
 
203
        Iterator bondsInContainer = varAtomContainer.bonds();
 
204
        while (bondsInContainer.hasNext()) {
 
205
            IBond bond = (IBond) bondsInContainer.next();                    
 
206
                        ringsWithThisBond = varRingSet.getRings(bond);
 
207
                        if (ringsWithThisBond.size() > 0) {
 
208
                                bond.setFlag(CDKConstants.ISINRING, true);
 
209
                        }
 
210
                }
 
211
                // SET ISINRING FLAGS FOR ATOMS
 
212
                org.openscience.cdk.interfaces.IRingSet ringsWithThisAtom;
 
213
 
 
214
                for (int w = 0; w < varAtomContainer.getAtomCount(); w++) {
 
215
                        ringsWithThisAtom = varRingSet
 
216
                                        .getRings(varAtomContainer.getAtom(w));
 
217
                        if (ringsWithThisAtom.getAtomContainerCount() > 0) {
 
218
                                varAtomContainer.getAtom(w)
 
219
                                                .setFlag(CDKConstants.ISINRING, true);
 
220
                        }
 
221
                }
 
222
 
 
223
                IAtomContainer detected = varAtomContainerSet.getAtomContainer(0);
 
224
 
 
225
                // neighboors[0] is the atom joined to the target proton:
 
226
                java.util.List neighboors = mol.getConnectedAtomsList(clonedAtom);
 
227
                IAtom neighbour0 = (IAtom) neighboors.get(0);
 
228
 
 
229
                // 2', 3', 4', 5', 6', and 7' atoms up to the target are detected:
 
230
                List atomsInSecondSphere = mol.getConnectedAtomsList(neighbour0);
 
231
                List atomsInThirdSphere = null;
 
232
                List atomsInFourthSphere = null;
 
233
                List atomsInFifthSphere = null;
 
234
                List atomsInSixthSphere = null;
 
235
                List atomsInSeventhSphere = null;
 
236
 
 
237
                // SOME LISTS ARE CREATED FOR STORING OF INTERESTING ATOMS AND BONDS
 
238
                // DURING DETECTION
 
239
                ArrayList singles = new ArrayList(); // list of any bond not
 
240
                                                                                                // rotatable
 
241
                ArrayList doubles = new ArrayList(); // list with only double bonds
 
242
                ArrayList atoms = new ArrayList(); // list with all the atoms in
 
243
                                                                                        // spheres
 
244
                // atoms.add( new Integer( mol.getAtomNumber(neighboors[0]) ) );
 
245
                ArrayList bondsInCycloex = new ArrayList(); // list for bonds in
 
246
                                                                                                        // cycloexane-like rings
 
247
 
 
248
                // 2', 3', 4', 5', 6', and 7' bonds up to the target are detected:
 
249
                IBond secondBond; // (remember that first bond is proton bond)
 
250
                IBond thirdBond; //
 
251
                IBond fourthBond; //
 
252
                IBond fifthBond; //
 
253
                IBond sixthBond; //
 
254
                IBond seventhBond; //
 
255
 
 
256
                // definition of some variables used in the main FOR loop for detection
 
257
                // of interesting atoms and bonds:
 
258
                boolean theBondIsInA6MemberedRing; // this is like a flag for bonds
 
259
                                                                                        // which are in cycloexane-like
 
260
                                                                                        // rings (rings with more than 4
 
261
                                                                                        // at.)
 
262
                double bondOrder;
 
263
                int bondNumber;
 
264
                int sphere;
 
265
 
 
266
                // THIS MAIN FOR LOOP DETECT RIGID BONDS IN 7 SPHERES:
 
267
                for (int a = 0; a < atomsInSecondSphere.size(); a++) {
 
268
                        IAtom curAtomSecond = (IAtom) atomsInSecondSphere.get(a);
 
269
                        secondBond = mol.getBond(neighbour0, curAtomSecond);
 
270
                        if (mol.getAtomNumber(curAtomSecond) != atomPosition
 
271
                                        && getIfBondIsNotRotatable(mol, secondBond, detected)) {
 
272
                                sphere = 2;
 
273
                                bondOrder = secondBond.getOrder();
 
274
                                bondNumber = mol.getBondNumber(secondBond);
 
275
                                theBondIsInA6MemberedRing = false;
 
276
                                checkAndStore(bondNumber, bondOrder, singles, doubles,
 
277
                                                bondsInCycloex, mol.getAtomNumber(curAtomSecond),
 
278
                                                atoms, sphere, theBondIsInA6MemberedRing);
 
279
                                atomsInThirdSphere = mol.getConnectedAtomsList(curAtomSecond);
 
280
                                if (atomsInThirdSphere.size() > 0) {
 
281
                                        for (int b = 0; b < atomsInThirdSphere.size(); b++) {
 
282
                                                IAtom curAtomThird = (IAtom) atomsInThirdSphere.get(b);
 
283
                                                thirdBond = mol.getBond(curAtomThird, curAtomSecond);
 
284
                                                // IF THE ATOMS IS IN THE THIRD SPHERE AND IN A
 
285
                                                // CYCLOEXANE-LIKE RING, IT IS STORED IN THE PROPER
 
286
                                                // LIST:
 
287
                                                if (mol.getAtomNumber(curAtomThird) != atomPosition
 
288
                                                                && getIfBondIsNotRotatable(mol, thirdBond,
 
289
                                                                                detected)) {
 
290
                                                        sphere = 3;
 
291
                                                        bondOrder = thirdBond.getOrder();
 
292
                                                        bondNumber = mol.getBondNumber(thirdBond);
 
293
                                                        theBondIsInA6MemberedRing = false;
 
294
 
 
295
                                                        // if the bond is in a cyclohexane-like ring (a ring
 
296
                                                        // with 5 or more atoms, not aromatic)
 
297
                                                        // the boolean "theBondIsInA6MemberedRing" is set to
 
298
                                                        // true
 
299
                                                        if (!thirdBond.getFlag(CDKConstants.ISAROMATIC)) {
 
300
                                                                if (!curAtomThird.equals(neighbour0)) {
 
301
                                                                        rsAtom = varRingSet.getRings(thirdBond);
 
302
                                                                        for (int f = 0; f < rsAtom.size(); f++) {
 
303
                                                                                ring = (Ring) rsAtom.get(f);
 
304
                                                                                if (ring.getRingSize() > 4
 
305
                                                                                                && ring.contains(thirdBond)) {
 
306
                                                                                        theBondIsInA6MemberedRing = true;
 
307
                                                                                }
 
308
                                                                        }
 
309
                                                                }
 
310
                                                        }
 
311
                                                        checkAndStore(bondNumber, bondOrder, singles,
 
312
                                                                        doubles, bondsInCycloex, mol
 
313
                                                                                        .getAtomNumber(curAtomThird),
 
314
                                                                        atoms, sphere, theBondIsInA6MemberedRing);
 
315
                                                        theBondIsInA6MemberedRing = false;
 
316
                                                        atomsInFourthSphere = mol
 
317
                                                                        .getConnectedAtomsList(curAtomThird);
 
318
                                                        if (atomsInFourthSphere.size() > 0) {
 
319
                                                                for (int c = 0; c < atomsInFourthSphere.size(); c++) {
 
320
                                                                        IAtom curAtomFourth = (IAtom) atomsInFourthSphere
 
321
                                                                                        .get(c);
 
322
                                                                        fourthBond = mol.getBond(curAtomThird,
 
323
                                                                                        curAtomFourth);
 
324
                                                                        if (mol.getAtomNumber(curAtomFourth) != atomPosition
 
325
                                                                                        && getIfBondIsNotRotatable(mol,
 
326
                                                                                                        fourthBond, detected)) {
 
327
                                                                                sphere = 4;
 
328
                                                                                bondOrder = fourthBond.getOrder();
 
329
                                                                                bondNumber = mol
 
330
                                                                                                .getBondNumber(fourthBond);
 
331
                                                                                theBondIsInA6MemberedRing = false;
 
332
                                                                                checkAndStore(
 
333
                                                                                                bondNumber,
 
334
                                                                                                bondOrder,
 
335
                                                                                                singles,
 
336
                                                                                                doubles,
 
337
                                                                                                bondsInCycloex,
 
338
                                                                                                mol
 
339
                                                                                                                .getAtomNumber(curAtomFourth),
 
340
                                                                                                atoms, sphere,
 
341
                                                                                                theBondIsInA6MemberedRing);
 
342
                                                                                atomsInFifthSphere = mol
 
343
                                                                                                .getConnectedAtomsList(curAtomFourth);
 
344
                                                                                if (atomsInFifthSphere.size() > 0) {
 
345
                                                                                        for (int d = 0; d < atomsInFifthSphere
 
346
                                                                                                        .size(); d++) {
 
347
                                                                                                IAtom curAtomFifth = (IAtom) atomsInFifthSphere
 
348
                                                                                                                .get(d);
 
349
                                                                                                fifthBond = mol.getBond(
 
350
                                                                                                                curAtomFifth,
 
351
                                                                                                                curAtomFourth);
 
352
                                                                                                if (mol
 
353
                                                                                                                .getAtomNumber(curAtomFifth) != atomPosition
 
354
                                                                                                                && getIfBondIsNotRotatable(
 
355
                                                                                                                                mol, fifthBond,
 
356
                                                                                                                                detected)) {
 
357
                                                                                                        sphere = 5;
 
358
                                                                                                        bondOrder = fifthBond
 
359
                                                                                                                        .getOrder();
 
360
                                                                                                        bondNumber = mol
 
361
                                                                                                                        .getBondNumber(fifthBond);
 
362
                                                                                                        theBondIsInA6MemberedRing = false;
 
363
                                                                                                        checkAndStore(
 
364
                                                                                                                        bondNumber,
 
365
                                                                                                                        bondOrder,
 
366
                                                                                                                        singles,
 
367
                                                                                                                        doubles,
 
368
                                                                                                                        bondsInCycloex,
 
369
                                                                                                                        mol
 
370
                                                                                                                                        .getAtomNumber(curAtomFifth),
 
371
                                                                                                                        atoms, sphere,
 
372
                                                                                                                        theBondIsInA6MemberedRing);
 
373
                                                                                                        atomsInSixthSphere = mol
 
374
                                                                                                                        .getConnectedAtomsList(curAtomFifth);
 
375
                                                                                                        if (atomsInSixthSphere
 
376
                                                                                                                        .size() > 0) {
 
377
                                                                                                                for (int e = 0; e < atomsInSixthSphere
 
378
                                                                                                                                .size(); e++) {
 
379
                                                                                                                        IAtom curAtomSixth = (IAtom) atomsInSixthSphere
 
380
                                                                                                                                        .get(e);
 
381
                                                                                                                        sixthBond = mol
 
382
                                                                                                                                        .getBond(
 
383
                                                                                                                                                        curAtomFifth,
 
384
                                                                                                                                                        curAtomSixth);
 
385
                                                                                                                        if (mol
 
386
                                                                                                                                        .getAtomNumber(curAtomSixth) != atomPosition
 
387
                                                                                                                                        && getIfBondIsNotRotatable(
 
388
                                                                                                                                                        mol,
 
389
                                                                                                                                                        sixthBond,
 
390
                                                                                                                                                        detected)) {
 
391
                                                                                                                                sphere = 6;
 
392
                                                                                                                                bondOrder = sixthBond
 
393
                                                                                                                                                .getOrder();
 
394
                                                                                                                                bondNumber = mol
 
395
                                                                                                                                                .getBondNumber(sixthBond);
 
396
                                                                                                                                theBondIsInA6MemberedRing = false;
 
397
                                                                                                                                checkAndStore(
 
398
                                                                                                                                                bondNumber,
 
399
                                                                                                                                                bondOrder,
 
400
                                                                                                                                                singles,
 
401
                                                                                                                                                doubles,
 
402
                                                                                                                                                bondsInCycloex,
 
403
                                                                                                                                                mol
 
404
                                                                                                                                                                .getAtomNumber(curAtomSixth),
 
405
                                                                                                                                                atoms,
 
406
                                                                                                                                                sphere,
 
407
                                                                                                                                                theBondIsInA6MemberedRing);
 
408
                                                                                                                                atomsInSeventhSphere = mol
 
409
                                                                                                                                                .getConnectedAtomsList(curAtomSixth);
 
410
                                                                                                                                if (atomsInSeventhSphere
 
411
                                                                                                                                                .size() > 0) {
 
412
                                                                                                                                        for (int f = 0; f < atomsInSeventhSphere
 
413
                                                                                                                                                        .size(); f++) {
 
414
                                                                                                                                                IAtom curAtomSeventh = (IAtom) atomsInSeventhSphere
 
415
                                                                                                                                                                .get(f);
 
416
                                                                                                                                                seventhBond = mol
 
417
                                                                                                                                                                .getBond(
 
418
                                                                                                                                                                                curAtomSeventh,
 
419
                                                                                                                                                                                curAtomSixth);
 
420
                                                                                                                                                if (mol
 
421
                                                                                                                                                                .getAtomNumber(curAtomSeventh) != atomPosition
 
422
                                                                                                                                                                && getIfBondIsNotRotatable(
 
423
                                                                                                                                                                                mol,
 
424
                                                                                                                                                                                seventhBond,
 
425
                                                                                                                                                                                detected)) {
 
426
                                                                                                                                                        sphere = 7;
 
427
                                                                                                                                                        bondOrder = seventhBond
 
428
                                                                                                                                                                        .getOrder();
 
429
                                                                                                                                                        bondNumber = mol
 
430
                                                                                                                                                                        .getBondNumber(seventhBond);
 
431
                                                                                                                                                        theBondIsInA6MemberedRing = false;
 
432
                                                                                                                                                        checkAndStore(
 
433
                                                                                                                                                                        bondNumber,
 
434
                                                                                                                                                                        bondOrder,
 
435
                                                                                                                                                                        singles,
 
436
                                                                                                                                                                        doubles,
 
437
                                                                                                                                                                        bondsInCycloex,
 
438
                                                                                                                                                                        mol
 
439
                                                                                                                                                                                        .getAtomNumber(curAtomSeventh),
 
440
                                                                                                                                                                        atoms,
 
441
                                                                                                                                                                        sphere,
 
442
                                                                                                                                                                        theBondIsInA6MemberedRing);
 
443
                                                                                                                                                }
 
444
                                                                                                                                        }
 
445
                                                                                                                                }
 
446
                                                                                                                        }
 
447
                                                                                                                }
 
448
                                                                                                        }
 
449
                                                                                                }
 
450
                                                                                        }
 
451
                                                                                }
 
452
                                                                        }
 
453
                                                                }
 
454
                                                        }
 
455
                                                }
 
456
                                        }
 
457
                                }
 
458
                        }
 
459
                }
 
460
 
 
461
                // Variables
 
462
                double distance;
 
463
                double sum;
 
464
                double smooth = -20;
 
465
                double partial;
 
466
                int position;
 
467
                double limitInf;
 
468
                double limitSup;
 
469
                double step;
 
470
 
 
471
                // ////////////////////////LAST DESCRIPTOR IS g3(r), FOR PROTONS BONDED
 
472
                // TO LIKE-CYCLOEXANE RINGS:
 
473
 
 
474
                Vector3d a_a = new Vector3d();
 
475
                Vector3d a_b = new Vector3d();
 
476
                Vector3d b_a = new Vector3d();
 
477
                Vector3d b_b = new Vector3d();
 
478
                double angle = 0;
 
479
 
 
480
                if (bondsInCycloex.size() > 0) {
 
481
                        IAtom cycloexBondAtom0;
 
482
                        IAtom cycloexBondAtom1;
 
483
                        org.openscience.cdk.interfaces.IBond theInCycloexBond;
 
484
                        distance = 0;
 
485
                        limitInf = 0;
 
486
                        limitSup = Math.PI;
 
487
                        step = (limitSup - limitInf) / 13;
 
488
                        position = 0;
 
489
                        smooth = -2.86;
 
490
                        angle = 0;
 
491
                        int ya_counter = 0;
 
492
                        List connAtoms;
 
493
                        for (double g3r = 0; g3r < limitSup; g3r = g3r + step) {
 
494
                                sum = 0;
 
495
                                for (int cyc = 0; cyc < bondsInCycloex.size(); cyc++) {
 
496
                                        ya_counter = 0;
 
497
                                        angle = 0;
 
498
                                        partial = 0;
 
499
                                        Integer thisInCycloexBond = (Integer) bondsInCycloex
 
500
                                                        .get(cyc);
 
501
                                        position = thisInCycloexBond.intValue();
 
502
                                        theInCycloexBond = mol.getBond(position);
 
503
                                        cycloexBondAtom0 = theInCycloexBond.getAtom(0);
 
504
                                        cycloexBondAtom1 = theInCycloexBond.getAtom(1);
 
505
 
 
506
                                        connAtoms = mol.getConnectedAtomsList(cycloexBondAtom0);
 
507
                                        for (int g = 0; g < connAtoms.size(); g++) {
 
508
                                                if (((IAtom) connAtoms.get(g)).equals(neighbour0))
 
509
                                                        ya_counter += 1;
 
510
                                        }
 
511
 
 
512
                                        if (ya_counter > 0) {
 
513
                                                a_a.set(cycloexBondAtom1.getPoint3d().x,
 
514
                                                                cycloexBondAtom1.getPoint3d().y,
 
515
                                                                cycloexBondAtom1.getPoint3d().z);
 
516
                                                a_b.set(cycloexBondAtom0.getPoint3d().x,
 
517
                                                                cycloexBondAtom0.getPoint3d().y,
 
518
                                                                cycloexBondAtom0.getPoint3d().z);
 
519
                                        } else {
 
520
                                                a_a.set(cycloexBondAtom0.getPoint3d().x,
 
521
                                                                cycloexBondAtom0.getPoint3d().y,
 
522
                                                                cycloexBondAtom0.getPoint3d().z);
 
523
                                                a_b.set(cycloexBondAtom1.getPoint3d().x,
 
524
                                                                cycloexBondAtom1.getPoint3d().y,
 
525
                                                                cycloexBondAtom1.getPoint3d().z);
 
526
                                        }
 
527
                                        b_a.set(neighbour0.getPoint3d().x,
 
528
                                                        neighbour0.getPoint3d().y,
 
529
                                                        neighbour0.getPoint3d().z);
 
530
                                        b_b.set(atom.getPoint3d().x, atom.getPoint3d().y, atom
 
531
                                                        .getPoint3d().z);
 
532
 
 
533
                                        angle = calculateAngleBetweenTwoLines(a_a, a_b, b_a, b_b);
 
534
 
 
535
                                        // logger.debug("gcycr ANGLE: " + angle + " "
 
536
                                        // +mol.getAtomNumber(cycloexBondAtom0) + "
 
537
                                        // "+mol.getAtomNumber(cycloexBondAtom1));
 
538
 
 
539
                                        partial = Math.exp(smooth * (Math.pow((g3r - angle), 2)));
 
540
                                        sum += partial;
 
541
                                }
 
542
                                // g3r_function.add(new Double(sum));
 
543
                                rdfProtonCalculatedValues.add(sum);
 
544
                                logger.debug("RDF g3r prob.: "+sum+ " at distance "+g3r);
 
545
                        }
 
546
                }
 
547
                else {
 
548
                        for (int i=0; i<g3r_desc_length; i++) rdfProtonCalculatedValues.add(Double.NaN);
 
549
                }
 
550
                return new DescriptorValue(
 
551
                        getSpecification(), getParameterNames(), 
 
552
                        getParameters(), rdfProtonCalculatedValues,
 
553
                        descriptorNames
 
554
                );
 
555
        }
 
556
 
 
557
        // Others definitions
 
558
 
 
559
        private boolean getIfBondIsNotRotatable(Molecule mol,
 
560
                        org.openscience.cdk.interfaces.IBond bond, IAtomContainer detected) {
 
561
                boolean isBondNotRotatable = false;
 
562
                int counter = 0;
 
563
                IAtom atom0 = bond.getAtom(0);
 
564
                IAtom atom1 = bond.getAtom(1);
 
565
                if (detected != null) {
 
566
                        if (detected.contains(bond))
 
567
                                counter += 1;
 
568
                }
 
569
                if (atom0.getFlag(CDKConstants.ISINRING)) {
 
570
                        if (atom1.getFlag(CDKConstants.ISINRING)) {
 
571
                                counter += 1;
 
572
                        } else {
 
573
                                if (atom1.getSymbol().equals("H"))
 
574
                                        counter += 1;
 
575
                                else
 
576
                                        counter += 0;
 
577
                        }
 
578
                }
 
579
                if (atom0.getSymbol().equals("N") && atom1.getSymbol().equals("C")) {
 
580
                        if (getIfACarbonIsDoubleBondedToAnOxygen(mol, atom1))
 
581
                                counter += 1;
 
582
                }
 
583
                if (atom0.getSymbol().equals("C") && atom1.getSymbol().equals("N")) {
 
584
                        if (getIfACarbonIsDoubleBondedToAnOxygen(mol, atom0))
 
585
                                counter += 1;
 
586
                }
 
587
                if (counter > 0)
 
588
                        isBondNotRotatable = true;
 
589
                return isBondNotRotatable;
 
590
        }
 
591
 
 
592
        private boolean getIfACarbonIsDoubleBondedToAnOxygen(Molecule mol,
 
593
                        IAtom carbonAtom) {
 
594
                boolean isDoubleBondedToOxygen = false;
 
595
                java.util.List neighToCarbon = mol.getConnectedAtomsList(carbonAtom);
 
596
                org.openscience.cdk.interfaces.IBond tmpBond;
 
597
                int counter = 0;
 
598
                for (int nei = 0; nei < neighToCarbon.size(); nei++) {
 
599
                        IAtom neighbour = (IAtom) neighToCarbon.get(nei);
 
600
                        if (neighbour.getSymbol().equals("O")) {
 
601
                                tmpBond = mol.getBond(neighbour, carbonAtom);
 
602
                                if (tmpBond.getOrder() == 2.0)
 
603
                                        counter += 1;
 
604
                        }
 
605
                }
 
606
                if (counter > 0)
 
607
                        isDoubleBondedToOxygen = true;
 
608
                return isDoubleBondedToOxygen;
 
609
        }
 
610
 
 
611
        // this method calculates the angle between two bonds given coordinates of
 
612
        // their atoms
 
613
 
 
614
        public double calculateAngleBetweenTwoLines(Vector3d a, Vector3d b,
 
615
                        Vector3d c, Vector3d d) {
 
616
                Vector3d firstLine = new Vector3d();
 
617
                firstLine.sub(a, b);
 
618
                Vector3d secondLine = new Vector3d();
 
619
                secondLine.sub(c, d);
 
620
                Vector3d firstVec = new Vector3d(firstLine);
 
621
                Vector3d secondVec = new Vector3d(secondLine);
 
622
                return firstVec.angle(secondVec);
 
623
        }
 
624
 
 
625
        // this method store atoms and bonds in proper lists:
 
626
        private void checkAndStore(int bondToStore, double bondOrder,
 
627
                        ArrayList singleVec, ArrayList doubleVec, ArrayList cycloexVec,
 
628
                        int a1, ArrayList atomVec, int sphere, boolean isBondInCycloex) {
 
629
                if (!atomVec.contains(new Integer(a1))) {
 
630
                        if (sphere < 6)
 
631
                                atomVec.add(new Integer(a1));
 
632
                }
 
633
                if (!cycloexVec.contains(new Integer(bondToStore))) {
 
634
                        if (isBondInCycloex) {
 
635
                                cycloexVec.add(new Integer(bondToStore));
 
636
                        }
 
637
                }
 
638
                if (bondOrder == 2.0) {
 
639
                        if (!doubleVec.contains(new Integer(bondToStore)))
 
640
                                doubleVec.add(new Integer(bondToStore));
 
641
                }
 
642
                if (bondOrder == 1.0) {
 
643
                        if (!singleVec.contains(new Integer(bondToStore)))
 
644
                                singleVec.add(new Integer(bondToStore));
 
645
                }
 
646
        }
 
647
 
 
648
        // generic method for calculation of distance btw 2 atoms
 
649
        private double calculateDistanceBetweenTwoAtoms(IAtom atom1, IAtom atom2) {
 
650
                double distance;
 
651
                Point3d firstPoint = atom1.getPoint3d();
 
652
                Point3d secondPoint = atom2.getPoint3d();
 
653
                distance = firstPoint.distance(secondPoint);
 
654
                return distance;
 
655
        }
 
656
 
 
657
        // given a double bond
 
658
        // this method returns a bond bonded to this double bond
 
659
        private int getNearestBondtoAGivenAtom(Molecule mol, IAtom atom,
 
660
                        org.openscience.cdk.interfaces.IBond bond) {
 
661
                int nearestBond = 0;
 
662
                double[] values;
 
663
                double distance = 0;
 
664
                IAtom atom0 = bond.getAtom(0);
 
665
                IAtom atom1 = bond.getAtom(1);
 
666
                List bondsAtLeft = mol.getConnectedBondsList(atom0);
 
667
                int partial;
 
668
                for (int i = 0; i < bondsAtLeft.size(); i++) {
 
669
                        IBond curBond = (IBond) bondsAtLeft.get(i);
 
670
                        values = calculateDistanceBetweenAtomAndBond(atom, curBond);
 
671
                        partial = mol.getBondNumber(curBond);
 
672
                        if (i == 0) {
 
673
                                nearestBond = mol.getBondNumber(curBond);
 
674
                                distance = values[0];
 
675
                        } else {
 
676
                                if (values[0] < distance) {
 
677
                                        nearestBond = partial;
 
678
                                }
 
679
                                /*
 
680
                                 * XXX commented this out, because is has no effect
 
681
                                 * 
 
682
                                 * else { nearestBond = nearestBond; }
 
683
                                 */
 
684
                        }
 
685
                }
 
686
                return nearestBond;
 
687
 
 
688
        }
 
689
 
 
690
        // method which calculated distance btw an atom and the middle point of a
 
691
        // bond
 
692
        // and returns distance and coordinates of middle point
 
693
        private double[] calculateDistanceBetweenAtomAndBond(IAtom proton,
 
694
                        org.openscience.cdk.interfaces.IBond theBond) {
 
695
                Point3d middlePoint = theBond.get3DCenter();
 
696
                Point3d protonPoint = proton.getPoint3d();
 
697
                double[] values = new double[4];
 
698
                values[0] = middlePoint.distance(protonPoint);
 
699
                values[1] = middlePoint.x;
 
700
                values[2] = middlePoint.y;
 
701
                values[3] = middlePoint.z;
 
702
                return values;
 
703
        }
 
704
 
 
705
        /**
 
706
         * Gets the parameterNames attribute of the RDFProtonDescriptor object
 
707
         * 
 
708
         * @return The parameterNames value
 
709
         */
 
710
        public String[] getParameterNames() {
 
711
                String[] params = new String[2];
 
712
                params[0] = "atomPosition";
 
713
                params[1] = "checkAromaticity";
 
714
                return params;
 
715
        }
 
716
 
 
717
        /**
 
718
         * Gets the parameterType attribute of the RDFProtonDescriptor object
 
719
         * 
 
720
         * @param name
 
721
         *            Description of the Parameter
 
722
         * @return The parameterType value
 
723
         */
 
724
        public Object getParameterType(String name) {
 
725
                if (name.equals("atomPosition"))
 
726
                        return new Integer(0);
 
727
                return Boolean.TRUE;
 
728
        }
 
729
}