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

Quick Search    Search Deep

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


1   ///////////////////////////////////////////////////////////////////////////////
2   //  Filename: $RCSfile: KierShape2.java,v $
3   //  Purpose:  Calculates the Kier Shape for paths with length two.
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 two.
47   *
48   * @author     wegnerj
49   * @license    GPL
50   * @cvsversion    $Revision: 1.7 $, $Date: 2003/08/22 15:56:16 $
51   */
52  public class KierShape2 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.KierShape2");
65      public static final String DESC_KEY = "Kier_shape_2";
66  
67      //~ Constructors ///////////////////////////////////////////////////////////
68  
69      /*-------------------------------------------------------------------------*
70       * private variables
71       *-------------------------------------------------------------------------     */
72      /*-------------------------------------------------------------------------*
73       * constructor
74       *-------------------------------------------------------------------------     */
75  
76      /**
77       *  Constructor for the KierShape2 object
78       */
79      public KierShape2()
80      {
81          if (logger.isDebugEnabled())
82          {
83              logger.debug("Initialize " + this.getClass().getName());
84          }
85  
86          descInfo = DescriptorHelper.generateDescInfo(DESC_KEY, this.getClass(),
87                  DescriptorInfo.TYPE_NO_COORDINATES, null,
88                  "joelib.desc.result.DoubleResult");
89      }
90  
91      //~ Methods ////////////////////////////////////////////////////////////////
92  
93      /*-------------------------------------------------------------------------*
94       * public methods
95       *-------------------------------------------------------------------------     */
96  
97      /**
98       * Gets the doubleValue attribute of the KierShape2 object
99       *
100      * @param mol  Description of the Parameter
101      * @return     The doubleValue value
102      */
103     public double getDoubleValue(JOEMol mol)
104     {
105         double nodes = 0;
106         AtomIterator ait = mol.atomIterator();
107         NbrAtomIterator nbrait;
108         NbrAtomIterator nbrait2;
109         JOEAtom node;
110         JOEAtom nbrNode;
111         JOEAtom nbrNode2;
112         double p = 0;
113         double kier;
114 
115         while (ait.hasNext())
116         {
117             node = ait.nextAtom();
118 
119             //Iteration over all nodes, "node" is the current node of the Iteration
120             if (!node.isHydrogen())
121             {
122                 //Graph should be Hydrogens depleted
123                 nodes++;
124                 nbrait = node.nbrAtomIterator();
125 
126                 //Iteration over all NeighborAtoms of the current node
127                 while (nbrait.hasNext())
128                 {
129                     nbrNode = nbrait.nextNbrAtom();
130                     nbrait2 = nbrNode.nbrAtomIterator();
131 
132                     while (nbrait2.hasNext())
133                     {
134                         //Iteration over all Neighbor Atoms form current NeighborAtom
135                         nbrNode2 = nbrait2.nextNbrAtom();
136 
137                         if ((!nbrNode2.isHydrogen()) &&
138                                 (nbrNode2.getIdx() != node.getIdx()))
139                         {
140                             p++;
141                         }
142                     }
143                 }
144             }
145         }
146 
147         p = (p / 2);
148 
149         //each path has been counted twice, so divide by two
150         if (p > 0)
151         {
152             kier = (((nodes - 1) * ((nodes - 2) * (nodes - 2))) / (p * p));
153         }
154         else
155         {
156             return 0.0;
157         }
158 
159         //System.out.println("Kier2 paths: " +p +"\nNodes: " +nodes);
160         return kier;
161     }
162 }
163 ///////////////////////////////////////////////////////////////////////////////
164 //  END OF FILE.
165 ///////////////////////////////////////////////////////////////////////////////