Source code: joelib/desc/types/GeometricalShapeCoefficient.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Filename: $RCSfile: GeometricalShapeCoefficient.java,v $
3 // Purpose: Calculates the geometrical shape coefficient.
4 // Language: Java
5 // Compiler: JDK 1.4
6 // Authors: Joerg K. Wegner
7 // Version: $Revision: 1.7 $
8 // $Date: 2003/08/22 15:56:16 $
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
25 /*==========================================================================*
26 * IMPORTS
27 *==========================================================================*/
28 import joelib.desc.DescResult;
29 import joelib.desc.DescriptorException;
30 import joelib.desc.DescriptorHelper;
31 import joelib.desc.DescriptorInfo;
32 import joelib.desc.SimpleDoubleDesc;
33
34 import joelib.desc.result.DoubleResult;
35
36 import joelib.molecule.JOEMol;
37
38 import org.apache.log4j.Category;
39
40
41 /*==========================================================================*
42 * CLASS DECLARATION
43 *==========================================================================*/
44
45 /**
46 * Calculates the geometrical shape coefficient.
47 *
48 * @author wegnerj
49 * @license GPL
50 * @cvsversion $Revision: 1.7 $, $Date: 2003/08/22 15:56:16 $
51 */
52 public class GeometricalShapeCoefficient extends SimpleDoubleDesc
53 {
54 //~ Static fields/initializers /////////////////////////////////////////////
55
56 /*-------------------------------------------------------------------------*
57 * public static member variables
58 *------------------------------------------------------------------------- */
59
60 /**
61 * Obtain a suitable logger.
62 */
63 private static Category logger = Category.getInstance(
64 "joelib.desc.types.GeometricalShapeCoefficient");
65 public static final String DESC_KEY = "Geometrical_shape_coefficient";
66
67 //~ Constructors ///////////////////////////////////////////////////////////
68
69 /*-------------------------------------------------------------------------*
70 * constructor
71 *------------------------------------------------------------------------- */
72 public GeometricalShapeCoefficient()
73 {
74 if (logger.isDebugEnabled())
75 {
76 logger.debug("Initialize " + this.getClass().getName());
77 }
78
79 descInfo = DescriptorHelper.generateDescInfo(DESC_KEY, this.getClass(),
80 DescriptorInfo.TYPE_GEOMETRICAL, null,
81 "joelib.desc.result.DoubleResult");
82 }
83
84 //~ Methods ////////////////////////////////////////////////////////////////
85
86 /*-------------------------------------------------------------------------*
87 * public methods
88 *------------------------------------------------------------------------- */
89
90 /**
91 * Gets the defaultAtoms attribute of the NumberOfC object
92 *
93 * @return The defaultAtoms value
94 */
95 public double getDoubleValue(JOEMol mol)
96 {
97 // get topological diameter or calculate if not already available
98 DescResult tmpResult = null;
99 String diameterKey = "Geometrical_diameter";
100
101 try
102 {
103 tmpResult = DescriptorHelper.instance().descFromMol(mol, diameterKey);
104 }
105 catch (DescriptorException ex)
106 {
107 logger.error(ex.toString());
108 logger.error(
109 "Can not calculate geometrical diameter for geometrical shape coefficient.");
110
111 return 0;
112 }
113
114 if (!(tmpResult instanceof DoubleResult))
115 {
116 logger.error("Needed descriptor '" + diameterKey +
117 "' should be of type " + DoubleResult.class.getName() +
118 ". Geometrical shape coefficient can not be calculated.");
119
120 return 0;
121 }
122
123 DoubleResult diameterResult = (DoubleResult) tmpResult;
124 double diameter = (double) diameterResult.value;
125
126 // get topological radius or calculate if not already available
127 //DescResult tmpResult=null;
128 String radiusKey = "Geometrical_radius";
129
130 try
131 {
132 tmpResult = DescriptorHelper.instance().descFromMol(mol, radiusKey);
133 }
134 catch (DescriptorException ex)
135 {
136 logger.error(ex.toString());
137 logger.error("Can not calculate geometrical radius for " +
138 DESC_KEY + ".");
139
140 return 0;
141 }
142
143 if (!(tmpResult instanceof DoubleResult))
144 {
145 logger.error("Needed descriptor '" + radiusKey +
146 "' should be of type " + DoubleResult.class.getName() + ". " +
147 DESC_KEY + " can not be calculated.");
148
149 return 0;
150 }
151
152 DoubleResult radiusResult = (DoubleResult) tmpResult;
153 double radius = (double) radiusResult.value;
154
155 double shape = (diameter - radius) / radius;
156
157 return shape;
158 }
159 }
160 ///////////////////////////////////////////////////////////////////////////////
161 // END OF FILE.
162 ///////////////////////////////////////////////////////////////////////////////