Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: joelib/desc/types/GraphShapeCoefficient.java


1   ///////////////////////////////////////////////////////////////////////////////
2   //  Filename: $RCSfile: GraphShapeCoefficient.java,v $
3   //  Purpose:  Calculates the graph shape coefficient.
4   //  Language: Java
5   //  Compiler: JDK 1.4
6   //  Authors:  Joerg K. Wegner
7   //  Version:  $Revision: 1.8 $
8   //            $Date: 2003/12/03 18:15:32 $
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.IntResult;
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 graph shape coefficient.
47   *
48   * @author     wegnerj
49   * @license GPL
50   * @cvsversion    $Revision: 1.8 $, $Date: 2003/12/03 18:15:32 $
51   */
52  public class GraphShapeCoefficient 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.GraphShapeCoefficient");
65      public static final String DESC_KEY = "Graph_shape_coefficient";
66  
67      //~ Constructors ///////////////////////////////////////////////////////////
68  
69      /*-------------------------------------------------------------------------*
70       * constructor
71       *------------------------------------------------------------------------- */
72      public GraphShapeCoefficient()
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_NO_COORDINATES, 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 = "Topological_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("Can not calculate " + diameterKey + " for " +
109                 DESC_KEY + ".");
110 
111             return 0;
112         }
113 
114         if (!(tmpResult instanceof IntResult))
115         {
116             logger.error("Needed descriptor '" + diameterKey +
117                 "' should be of type " + IntResult.class.getName() + ". " +
118                 DESC_KEY + " can not be calculated.");
119 
120             return 0;
121         }
122 
123         IntResult diameterResult = (IntResult) tmpResult;
124         double diameter = diameterResult.getDoubleNV();
125 
126         // get topological radius or calculate if not already available
127         //DescResult tmpResult=null;
128         String radiusKey = "Topological_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 " + radiusKey + " for " + DESC_KEY +
138                 ".");
139 
140             return 0;
141         }
142 
143         if (!(tmpResult instanceof IntResult))
144         {
145             logger.error("Needed descriptor '" + radiusKey +
146                 "' should be of type " + IntResult.class.getName() + ". " +
147                 DESC_KEY + " can not be calculated.");
148 
149             return 0;
150         }
151 
152         IntResult radiusResult = (IntResult) tmpResult;
153         double radius = radiusResult.getDoubleNV();
154 
155         double shape = (diameter - radius) / radius;
156 
157         return shape;
158     }
159 }
160 ///////////////////////////////////////////////////////////////////////////////
161 //  END OF FILE.
162 ///////////////////////////////////////////////////////////////////////////////