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

Quick Search    Search Deep

Source code: joelib/algo/morgan/types/SingleTieResolverGraphPot.java


1   ///////////////////////////////////////////////////////////////////////////////
2   //  Filename: $RCSfile: SingleTieResolverGraphPot.java,v $
3   //  Purpose:  Helper class for resolving renumbering ties.
4   //  Language: Java
5   //  Compiler: JDK 1.4
6   //  Authors:  Joerg K. Wegner
7   //  Version:  $Revision: 1.3 $
8   //            $Date: 2003/08/22 15:56:15 $
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.algo.morgan.types;
23  
24  
25  /*==========================================================================*
26   * IMPORTS
27   *========================================================================== */
28  import joelib.algo.morgan.AtomDoubleParent;
29  import joelib.algo.morgan.SingleTieResolver;
30  
31  import joelib.desc.DescResult;
32  import joelib.desc.DescriptorException;
33  import joelib.desc.DescriptorHelper;
34  
35  import joelib.desc.types.GraphPotentials;
36  
37  import joelib.molecule.JOEMol;
38  
39  import joelib.molecule.types.AtomProperties;
40  
41  import joelib.util.JOEHelper;
42  
43  import org.apache.log4j.Category;
44  
45  
46  /*==========================================================================*
47   * CLASS DECLARATION
48   *========================================================================== */
49  
50  /**
51   * Interface for resolving renumbering ties.
52   *
53   * @author     wegnerj
54   * @license    GPL
55   * @cvsversion    $Revision: 1.3 $, $Date: 2003/08/22 15:56:15 $
56   */
57  public class SingleTieResolverGraphPot implements SingleTieResolver
58  {
59      //~ Static fields/initializers /////////////////////////////////////////////
60  
61      // Obtain a suitable logger.
62      private static Category logger = Category.getInstance(
63              "joelib.algo.morgan.types.SingleTieResolverGraphPot");
64  
65      //~ Instance fields ////////////////////////////////////////////////////////
66  
67      private AtomProperties atomProperties;
68      private boolean initialized = false;
69  
70      //~ Methods ////////////////////////////////////////////////////////////////
71  
72      /*-------------------------------------------------------------------------*
73       * public member methods
74       *------------------------------------------------------------------------- */
75      public double getResolvingValue(AtomDoubleParent ap, JOEMol mol)
76      {
77          // initialize atom properties
78          if (!initialized)
79          {
80              return 0.0;
81          }
82  
83          //System.out.println("gp:"+atomProperties.getDoubleValue(ap.atomIdx));
84          //System.out.println("gpP:"+atomProperties.getDoubleValue(mol.getAtom(ap.parent).getIdx()));
85          return atomProperties.getDoubleValue(ap.atomIdx);
86      }
87  
88      public boolean init(JOEMol mol)
89      {
90          initialized = false;
91  
92          String propertyName = GraphPotentials.DESC_KEY;
93  
94          // get atom properties or calculate if not already available
95          DescResult tmpPropResult = null;
96  
97          try
98          {
99              tmpPropResult = DescriptorHelper.instance().descFromMol(mol,
100                     propertyName);
101         }
102          catch (DescriptorException e)
103         {
104             logger.error("Atom property " + propertyName + " does not exist.");
105 
106             return false;
107         }
108 
109         if (JOEHelper.hasInterface(tmpPropResult, "AtomProperties"))
110         {
111             atomProperties = (AtomProperties) tmpPropResult;
112         }
113         else
114         {
115             logger.error("Property '" + propertyName +
116                 "' must be an atom type.");
117 
118             return false;
119         }
120 
121         initialized = true;
122 
123         return true;
124     }
125 }
126 ///////////////////////////////////////////////////////////////////////////////
127 //  END OF FILE.
128 ///////////////////////////////////////////////////////////////////////////////