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

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/qsar/descriptors/atomic/BondsToAtomDescriptor.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: egonw $
 
3
 *  $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
 
4
 *  $Revision: 7636 $
 
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.atomic;
 
25
 
 
26
import org.openscience.cdk.Molecule;
 
27
import org.openscience.cdk.exception.CDKException;
 
28
import org.openscience.cdk.graph.BFSShortestPath;
 
29
import org.openscience.cdk.graph.MoleculeGraphs;
 
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.IAtomicDescriptor;
 
35
import org.openscience.cdk.qsar.result.IntegerResult;
 
36
 
 
37
/**
 
38
 *  This class returns the number of bonds on the shortest path between two atoms.
 
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>focusPosition</td>
 
49
 *     <td>0</td>
 
50
 *     <td>The position of the second atom</td>
 
51
 *   </tr>
 
52
 * </table>
 
53
 *
 
54
 * @author         mfe4
 
55
 * @cdk.created    2004-11-13
 
56
 * @cdk.module     qsar
 
57
 * @cdk.set        qsar-descriptors
 
58
 * @cdk.dictref    qsar-descriptors:bondsToAtom
 
59
 */
 
60
public class BondsToAtomDescriptor implements IAtomicDescriptor {
 
61
 
 
62
    private int focusPosition = 0;
 
63
    private org._3pq.jgrapht.Graph mygraph = null;
 
64
    java.util.List mylist = null;
 
65
    Object startVertex = null;
 
66
    Object endVertex = null;
 
67
 
 
68
    /**
 
69
     *  Constructor for the BondsToAtomDescriptor object
 
70
     */
 
71
    public BondsToAtomDescriptor() {}
 
72
 
 
73
 
 
74
    /**
 
75
     *  Gets the specification attribute of the BondsToAtomDescriptor object
 
76
     *
 
77
     *@return    The specification value
 
78
     */
 
79
    public DescriptorSpecification getSpecification() {
 
80
        return new DescriptorSpecification(
 
81
                "http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#bondsToAtom",
 
82
                this.getClass().getName(),
 
83
                "$Id: BondsToAtomDescriptor.java 7636 2007-01-04 17:46:10Z egonw $",
 
84
                "The Chemistry Development Kit");
 
85
    }
 
86
 
 
87
 
 
88
    /**
 
89
     *  Sets the parameters attribute of the BondsToAtomDescriptor object
 
90
     *
 
91
     * @param  params            The parameter is the position to focus
 
92
     * @exception  CDKException  Description of the Exception
 
93
     */
 
94
    public void setParameters(Object[] params) throws CDKException {
 
95
        if (params.length > 1) {
 
96
            throw new CDKException("BondsToAtomDescriptor only expects one parameters");
 
97
        }
 
98
        if (!(params[0] instanceof Integer)) {
 
99
            throw new CDKException("The parameter must be of type Integer");
 
100
        }
 
101
        focusPosition = ((Integer) params[0]).intValue();
 
102
    }
 
103
 
 
104
 
 
105
    /**
 
106
     *  Gets the parameters attribute of the BondsToAtomDescriptor object
 
107
     *
 
108
     *@return    The parameters value 
 
109
     */
 
110
    public Object[] getParameters() {
 
111
        Object[] params = new Object[1];
 
112
        params[0] = new Integer(focusPosition);
 
113
        return params;
 
114
    }
 
115
 
 
116
 
 
117
    /**
 
118
     *  This method calculate the number of bonds on the shortest path between two atoms.
 
119
     *
 
120
     *@param  atom              The IAtom for which the DescriptorValue is requested
 
121
     *@param  container         Parameter is the atom container.
 
122
     *@return                   The number of bonds on the shortest path between two atoms
 
123
     *@exception  CDKException  Description of the Exception
 
124
     */
 
125
 
 
126
    public DescriptorValue calculate(IAtom atom, IAtomContainer container) throws CDKException {
 
127
        mygraph = MoleculeGraphs.getMoleculeGraph((Molecule)container);
 
128
        int bondsToAtom = 0;
 
129
        
 
130
        IAtom target = atom;
 
131
        IAtom focus = container.getAtom(focusPosition);
 
132
        
 
133
        startVertex = target;
 
134
        endVertex = focus;
 
135
        
 
136
        mylist = BFSShortestPath.findPathBetween(mygraph,startVertex,endVertex);
 
137
        
 
138
        bondsToAtom = mylist.size();
 
139
        
 
140
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult(bondsToAtom));
 
141
 
 
142
    }
 
143
 
 
144
 
 
145
    /**
 
146
     *  Gets the parameterNames attribute of the BondsToAtomDescriptor object
 
147
     *
 
148
     *@return    The parameterNames value
 
149
     */
 
150
    public String[] getParameterNames() {
 
151
        String[] params = new String[1];
 
152
        params[0] = "focusPosition";
 
153
        return params;
 
154
    }
 
155
 
 
156
 
 
157
    /**
 
158
     *  Gets the parameterType attribute of the BondsToAtomDescriptor object
 
159
     *
 
160
     *@param  name  Description of the Parameter
 
161
     *@return       The parameterType value
 
162
     */
 
163
    public Object getParameterType(String name) {
 
164
        return new Integer(0);
 
165
    }
 
166
}
 
167