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

Quick Search    Search Deep

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


1   ///////////////////////////////////////////////////////////////////////////////
2   //  Filename: $RCSfile: KierShape3.java,v $
3   //  Purpose:  Calculates the Kier Shape for paths with length three.
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.DescriptorHelper;
29  import joelib.desc.DescriptorInfo;
30  import joelib.desc.SimpleDoubleDesc;
31  
32  import joelib.molecule.JOEAtom;
33  import joelib.molecule.JOEMol;
34  
35  import joelib.util.iterator.AtomIterator;
36  import joelib.util.iterator.NbrAtomIterator;
37  
38  import org.apache.log4j.Category;
39  
40  
41  /*==========================================================================*
42   * CLASS DECLARATION
43   *==========================================================================     */
44  
45  /**
46   *  Calculates the Kier Shape for paths with length three.
47   *
48   * @author    Jan Bruecker
49   * @author     wegnerj
50   * @license GPL
51   * @cvsversion    $Revision: 1.7 $, $Date: 2003/08/22 15:56:16 $
52   */
53  public class KierShape3 extends SimpleDoubleDesc
54  {
55      //~ Static fields/initializers /////////////////////////////////////////////
56  
57      /*-------------------------------------------------------------------------*
58       * public static member variables
59       *-------------------------------------------------------------------------         */
60  
61      /**
62       *  Obtain a suitable logger.
63       */
64      private static Category logger = Category.getInstance(
65              "joelib.desc.types.KierShape3");
66      public static final String DESC_KEY = "Kier_shape_3";
67  
68      //~ Constructors ///////////////////////////////////////////////////////////
69  
70      /*-------------------------------------------------------------------------*
71       * private variables
72       *-------------------------------------------------------------------------     */
73      /*-------------------------------------------------------------------------*
74       * constructor
75       *-------------------------------------------------------------------------     */
76  
77      /**
78       *  Constructor for the KierShape3 object
79       */
80      public KierShape3()
81      {
82          if (logger.isDebugEnabled())
83          {
84              logger.debug("Initialize " + this.getClass().getName());
85          }
86  
87          descInfo = DescriptorHelper.generateDescInfo(DESC_KEY, this.getClass(),
88                  DescriptorInfo.TYPE_NO_COORDINATES, null,
89                  "joelib.desc.result.DoubleResult");
90      }
91  
92      //~ Methods ////////////////////////////////////////////////////////////////
93  
94      /*-------------------------------------------------------------------------*
95       * public methods
96       *-------------------------------------------------------------------------     */
97  
98      /**
99       * Gets the doubleValue attribute of the KierShape3 object
100      *
101      * @param mol  Description of the Parameter
102      * @return     The doubleValue value
103      */
104     public double getDoubleValue(JOEMol mol)
105     {
106         double nodes = 0;
107         double paths = 0;
108         AtomIterator ait = mol.atomIterator();
109         NbrAtomIterator nbrait;
110         NbrAtomIterator nbrait2;
111         NbrAtomIterator nbrait3;
112         JOEAtom atom;
113         JOEAtom nbrAtom;
114         JOEAtom nbrAtom2;
115         JOEAtom nbrAtom3;
116         double kier;
117 
118         while (ait.hasNext())
119         {
120             //Iterates over all nodes
121             atom = ait.nextAtom();
122 
123             //"node" is the current node of the Iteration
124             if (!atom.isHydrogen())
125             {
126                 //Graph should be H-Atom depleted
127                 nodes++;
128                 nbrait = atom.nbrAtomIterator();
129 
130                 while (nbrait.hasNext())
131                 {
132                     //Iterates over all edges of the current "node"
133                     nbrAtom = nbrait.nextNbrAtom();
134 
135                     if (!nbrAtom.isHydrogen())
136                     {
137                         nbrait2 = nbrAtom.nbrAtomIterator();
138 
139                         while (nbrait2.hasNext())
140                         {
141                             nbrAtom2 = nbrait2.nextNbrAtom();
142 
143                             if ((!nbrAtom2.isHydrogen()) &&
144                                     (nbrAtom2.getIdx() != atom.getIdx()))
145                             {
146                                 nbrait3 = nbrAtom2.nbrAtomIterator();
147 
148                                 while (nbrait3.hasNext())
149                                 {
150                                     nbrAtom3 = nbrait3.nextNbrAtom();
151 
152                                     if ((!nbrAtom3.isHydrogen()) &&
153                                             (nbrAtom3.getIdx() != nbrAtom.getIdx()))
154                                     {
155                                         paths++;
156                                     }
157                                 }
158                             }
159                         }
160                     }
161                 }
162             }
163         }
164 
165         paths = paths / 2;
166 
167         //each path has been counted twice, so divide by two
168         //System.out.println("Kier 3 paths: " +paths +"\n Knoten: " +nodes);
169         if (paths > 0)
170         {
171             if ((nodes % 2) == 0)
172             {
173                 kier = (((nodes - 3) * ((nodes - 2) * (nodes - 2))) / (paths * paths));
174             }
175             else
176             {
177                 kier = (((nodes - 1) * ((nodes - 3) * (nodes - 3))) / (paths * paths));
178             }
179         }
180         else
181         {
182             return 0.0;
183         }
184 
185         return kier;
186     }
187 }
188 ///////////////////////////////////////////////////////////////////////////////
189 //  END OF FILE.
190 ///////////////////////////////////////////////////////////////////////////////