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

Quick Search    Search Deep

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


1   ///////////////////////////////////////////////////////////////////////////////
2   //  Filename: $RCSfile: GeometricalDiameter.java,v $
3   //  Purpose:  Calculates the geometrical diameter.
4   //  Language: Java
5   //  Compiler: JDK 1.4
6   //  Authors:  Joerg K. Wegner
7   //  Version:  $Revision: 1.8 $
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.DoubleMatrixResult;
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 diameter.
47   *
48   * @author     wegnerj
49   * @license GPL
50   * @cvsversion    $Revision: 1.8 $, $Date: 2003/08/22 15:56:16 $
51   */
52  public class GeometricalDiameter 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.GeometricalDiameter");
65      public static final String DESC_KEY = "Geometrical_diameter";
66  
67      //~ Constructors ///////////////////////////////////////////////////////////
68  
69      /*-------------------------------------------------------------------------*
70       * constructor
71       *------------------------------------------------------------------------- */
72      public GeometricalDiameter()
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          if (mol.empty())
98          {
99              logger.warn("Empty molecule '" + mol.getTitle() + "'. " +
100                 this.DESC_KEY + " was set to 0.");
101 
102             return 0.0;
103         }
104 
105         // get distance matrix or calculate if not already available
106         DescResult tmpResult = null;
107         String geomDistanceMatrixKey = GeomDistanceMatrix.DESC_KEY;
108 
109         try
110         {
111             tmpResult = DescriptorHelper.instance().descFromMol(mol,
112                     geomDistanceMatrixKey);
113         }
114          catch (DescriptorException ex)
115         {
116             logger.error(ex.toString());
117             logger.error("Can not calculate distance matrix for " + DESC_KEY +
118                 ".");
119 
120             return 0;
121         }
122 
123         if (!(tmpResult instanceof DoubleMatrixResult))
124         {
125             logger.error("Needed descriptor '" + geomDistanceMatrixKey +
126                 "' should be of type " + DoubleMatrixResult.class.getName() +
127                 ". " + DESC_KEY + " can not be calculated.");
128 
129             return 0;
130         }
131 
132         DoubleMatrixResult distResult = (DoubleMatrixResult) tmpResult;
133         double[][] distances = distResult.value;
134 
135         double geometricalDiameter = -Double.MAX_VALUE;
136 
137         for (int i = 0; i < distances.length; i++)
138         {
139             for (int ii = 0; ii < i; ii++)
140             {
141                 if (geometricalDiameter < distances[i][ii])
142                 {
143                     geometricalDiameter = distances[i][ii];
144                 }
145             }
146         }
147 
148         return geometricalDiameter;
149     }
150 }
151 ///////////////////////////////////////////////////////////////////////////////
152 //  END OF FILE.
153 ///////////////////////////////////////////////////////////////////////////////