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

Quick Search    Search Deep

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


1   ///////////////////////////////////////////////////////////////////////////////
2   //  Filename: $RCSfile: ZagrebIndex2.java,v $
3   //  Purpose:  Calculates the Zagreb Group Index 2.
4   //  Language: Java
5   //  Compiler: JDK 1.4
6   //  Authors:  Joerg K. Wegner
7   //  Version:  $Revision: 1.6 $
8   //            $Date: 2003/08/19 13:11:25 $
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.JOEBond;
34  import joelib.molecule.JOEMol;
35  
36  import joelib.util.iterator.BondIterator;
37  
38  import org.apache.log4j.Category;
39  
40  
41  /*==========================================================================*
42   * CLASS DECLARATION
43   *==========================================================================*/
44  
45  /**
46   *  Calculates the Zagreb Group Index 2.
47   *
48   * @author     wegnerj
49   * @license    GPL
50   * @cvsversion    $Revision: 1.6 $, $Date: 2003/08/19 13:11:25 $
51   */
52  public class ZagrebIndex2 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.ZagrebIndex2");
65      public static final String DESC_KEY = "Zagreb_group_index_2";
66  
67      //~ Constructors ///////////////////////////////////////////////////////////
68  
69      /*-------------------------------------------------------------------------*
70       * private variables
71       *-------------------------------------------------------------------------*/
72      /*-------------------------------------------------------------------------*
73       * constructor
74       *-------------------------------------------------------------------------    */
75  
76      /**
77       *  Constructor for the ZagrebIndex2 object
78       */
79      public ZagrebIndex2()
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      public double getDoubleValue(JOEMol mol)
97      {
98          double counter = 0;
99          double atomDegree1;
100         double atomDegree2;
101         JOEAtom node1;
102         JOEAtom node2;
103         JOEBond bond;
104         BondIterator bit = mol.bondIterator();
105 
106         while (bit.hasNext())
107         {
108             bond = bit.nextBond();
109             node1 = bond.getBeginAtom();
110             node2 = bond.getEndAtom();
111 
112             if ((!node1.isHydrogen()) && (!node2.isHydrogen())) //Graph must be H Atom depleted
113             {
114                 atomDegree1 = node1.getBonds().size();
115                 atomDegree2 = node2.getBonds().size();
116                 counter += (atomDegree1 * atomDegree2);
117             }
118         }
119 
120         return counter;
121     }
122 }
123 ///////////////////////////////////////////////////////////////////////////////
124 //  END OF FILE.
125 ///////////////////////////////////////////////////////////////////////////////