Source code: joelib/desc/types/HeavyBonds.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Filename: $RCSfile: HeavyBonds.java,v $
3 // Purpose: Number of heavy bonds.
4 // Language: Java
5 // Compiler: JDK 1.4
6 // Authors: Joerg K. Wegner
7 // Version: $Revision: 1.6 $
8 // $Date: 2003/08/19 13:11:25 $
9 // $Author: wegner $
10 //
11 // Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
12 //
13 // This program is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation version 2 of the License.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 ///////////////////////////////////////////////////////////////////////////////
22 package joelib.desc.types;
23
24 import joelib.desc.DescDescription;
25 import joelib.desc.DescResult;
26 import joelib.desc.Descriptor;
27 import joelib.desc.DescriptorException;
28 import joelib.desc.DescriptorHelper;
29 import joelib.desc.DescriptorInfo;
30 import joelib.desc.ResultFactory;
31
32 import joelib.desc.result.IntResult;
33
34 import joelib.molecule.JOEBond;
35 import joelib.molecule.JOEMol;
36
37 import joelib.util.JOEProperty;
38
39 import joelib.util.iterator.BondIterator;
40
41 /*
42 * ==========================================================================*
43 * IMPORTS
44 * ==========================================================================
45 */
46 import java.util.Map;
47
48 import org.apache.log4j.Category;
49
50
51 /*
52 * ==========================================================================*
53 * CLASS DECLARATION
54 * ==========================================================================
55 */
56
57 /**
58 * Number of heavy bonds.
59 *
60 * @author wegner
61 * @license GPL
62 * @cvsversion $Revision: 1.6 $, $Date: 2003/08/19 13:11:25 $
63 */
64 public class HeavyBonds implements Descriptor
65 {
66 //~ Static fields/initializers /////////////////////////////////////////////
67
68 /*
69 * -------------------------------------------------------------------------*
70 * public static member variables
71 * -------------------------------------------------------------------------
72 */
73
74 /**
75 * Obtain a suitable logger.
76 */
77 private static Category logger = Category.getInstance(
78 "joelib.desc.types.HeavyBonds");
79 public static final String DESC_KEY = "Number_of_heavy_bonds";
80
81 //~ Instance fields ////////////////////////////////////////////////////////
82
83 /*
84 * -------------------------------------------------------------------------*
85 * private variables
86 * -------------------------------------------------------------------------
87 */
88 private DescriptorInfo descInfo;
89
90 //~ Constructors ///////////////////////////////////////////////////////////
91
92 /*
93 * -------------------------------------------------------------------------*
94 * constructor
95 * -------------------------------------------------------------------------
96 */
97
98 /**
99 * Constructor for the KierShape1 object
100 */
101 public HeavyBonds()
102 {
103 if (logger.isDebugEnabled())
104 {
105 logger.debug("Initialize " + this.getClass().getName());
106 }
107
108 descInfo = DescriptorHelper.generateDescInfo(DESC_KEY, this.getClass(),
109 DescriptorInfo.TYPE_NO_COORDINATES, null,
110 "joelib.desc.result.IntResult");
111 }
112
113 //~ Methods ////////////////////////////////////////////////////////////////
114
115 /*
116 * -------------------------------------------------------------------------*
117 * public methods
118 * -------------------------------------------------------------------------
119 */
120
121 /**
122 * Description of the Method
123 *
124 *@return Description of the Return Value
125 */
126 public DescriptorInfo getDescInfo()
127 {
128 return descInfo;
129 }
130
131 /**
132 * Sets the descriptionFile attribute of the Descriptor object
133 *
134 *@param _descInfo The new descInfo value
135 */
136
137 // public void setDescInfo(DescriptorInfo _descInfo) {
138 // descInfo = _descInfo;
139 // }
140
141 /**
142 * Gets the description attribute of the Descriptor object
143 *
144 *@return The description value
145 */
146 public DescDescription getDescription()
147 {
148 return new DescDescription(descInfo.getDescriptionFile());
149 }
150
151 public JOEProperty[] acceptedProperties()
152 {
153 return null;
154 }
155
156 /**
157 * Description of the Method
158 *
159 *@param mol Description of the Parameter
160 *@return Description of the Return Value
161 *@exception DescriptorException Description of the Exception
162 */
163 public DescResult calculate(JOEMol mol) throws DescriptorException
164 {
165 DescResult result = ResultFactory.instance().getDescResult(descInfo.getName());
166
167 return calculate(mol, result, null);
168 }
169
170 /**
171 * Description of the Method
172 *
173 *@param mol Description of the Parameter
174 *@param initData Description of the Parameter
175 *@return Description of the Return Value
176 *@exception DescriptorException Description of the Exception
177 */
178 public DescResult calculate(JOEMol mol, Map properties)
179 throws DescriptorException
180 {
181 DescResult result = ResultFactory.instance().getDescResult(descInfo.getName());
182
183 return calculate(mol, result, properties);
184 }
185
186 /**
187 * Description of the Method
188 *
189 *@param mol Description of the Parameter
190 *@param descResult Description of the Parameter
191 *@return Description of the Return Value
192 *@exception DescriptorException Description of the Exception
193 */
194 public DescResult calculate(JOEMol mol, DescResult descResult)
195 throws DescriptorException
196 {
197 return calculate(mol, descResult, null);
198 }
199
200 /**
201 * Description of the Method
202 *
203 *@param mol Description of the Parameter
204 *@param initData Description of the Parameter
205 *@param descResult Description of the Parameter
206 *@return Description of the Return Value
207 *@exception DescriptorException Description of the Exception
208 */
209 public DescResult calculate(JOEMol mol, DescResult descResult,
210 Map properties) throws DescriptorException
211 {
212 if (!(descResult instanceof IntResult))
213 {
214 logger.error(descInfo.getName() + " result should be of type " +
215 IntResult.class.getName() + " but it's of type " +
216 descResult.getClass().toString());
217 }
218
219 int heavyBonds = 0;
220
221 BondIterator bit = mol.bondIterator();
222 JOEBond bond;
223
224 while (bit.hasNext())
225 {
226 //Molecule graph must be H-Atom depleted
227 bond = bit.nextBond();
228
229 if (!bond.getBeginAtom().isHydrogen() &&
230 !bond.getEndAtom().isHydrogen())
231 {
232 heavyBonds++;
233 }
234 }
235
236 IntResult result = (IntResult) descResult;
237 result.setInt(heavyBonds);
238
239 return result;
240 }
241
242 /**
243 * Description of the Method
244 */
245 public void clear()
246 {
247 }
248
249 /**
250 * Description of the Method
251 *
252 *@param initData Description of the Parameter
253 *@return Description of the Return Value
254 */
255 public boolean initialize(Map properties)
256 {
257 return true;
258 }
259
260 /**
261 * Test the implementation of this descriptor.
262 *
263 * @return <tt>true</tt> if the implementation is correct
264 */
265 public boolean testDescriptor()
266 {
267 return true;
268 }
269 }
270 ///////////////////////////////////////////////////////////////////////////////
271 // END OF FILE.
272 ///////////////////////////////////////////////////////////////////////////////