Source code: joelib/algo/morgan/types/SingleTieResolverDistance.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Filename: $RCSfile: SingleTieResolverDistance.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 import joelib.algo.morgan.AtomDoubleParent;
25 import joelib.algo.morgan.SingleTieResolver;
26
27 import joelib.desc.DescResult;
28 import joelib.desc.DescriptorException;
29 import joelib.desc.DescriptorHelper;
30
31 import joelib.desc.result.IntMatrixResult;
32
33 import joelib.molecule.JOEMol;
34
35 /*==========================================================================*
36 * IMPORTS
37 *========================================================================== */
38 import org.apache.log4j.Category;
39
40
41 /*==========================================================================*
42 * CLASS DECLARATION
43 *========================================================================== */
44
45 /**
46 * Interface for resolving renumbering ties.
47 *
48 * @author wegnerj
49 * @license GPL
50 * @cvsversion $Revision: 1.3 $, $Date: 2003/08/22 15:56:15 $
51 */
52 public class SingleTieResolverDistance implements SingleTieResolver
53 {
54 //~ Static fields/initializers /////////////////////////////////////////////
55
56 // Obtain a suitable logger.
57 private static Category logger = Category.getInstance(
58 "joelib.algo.morgan.types.SingleTieResolverDistance");
59
60 //~ Instance fields ////////////////////////////////////////////////////////
61
62 private int[] maxDistances;
63 private boolean initialized = false;
64
65 //~ Methods ////////////////////////////////////////////////////////////////
66
67 /*-------------------------------------------------------------------------*
68 * public member methods
69 *------------------------------------------------------------------------- */
70 public double getResolvingValue(AtomDoubleParent ap, JOEMol mol)
71 {
72 // initialize atom properties
73 if (!initialized)
74 {
75 return 0.0;
76 }
77
78 //System.out.println("dist:"+maxDistances[ap.atomIdx - 1]);
79 //System.out.println("distP:"+maxDistances[mol.getAtom(ap.parent).getIdx() - 1]);
80 return maxDistances[ap.atomIdx - 1];
81 }
82
83 public boolean init(JOEMol mol)
84 {
85 initialized = false;
86
87 // get distance matrix or calculate if not already available
88 DescResult tmpResult = null;
89 String distanceMatrixKey = "Distance_matrix";
90
91 try
92 {
93 tmpResult = DescriptorHelper.instance().descFromMol(mol,
94 distanceMatrixKey);
95 }
96 catch (DescriptorException ex)
97 {
98 logger.error(ex.toString());
99 logger.error("Can not calculate distance matrix.");
100
101 return false;
102 }
103
104 if (!(tmpResult instanceof IntMatrixResult))
105 {
106 logger.error("Needed descriptor '" + distanceMatrixKey +
107 "' should be of type " + IntMatrixResult.class.getName() + ".");
108
109 return false;
110 }
111
112 IntMatrixResult distResult = (IntMatrixResult) tmpResult;
113 int[][] distances = distResult.value;
114
115 maxDistances = new int[mol.numAtoms()];
116
117 for (int i = 0; i < distances.length; i++)
118 {
119 maxDistances[i] = 0;
120
121 for (int ii = 0; ii < i; ii++)
122 {
123 if (maxDistances[i] < distances[i][ii])
124 {
125 maxDistances[i] = distances[i][ii];
126 }
127 }
128 }
129
130 initialized = true;
131
132 return true;
133 }
134 }
135 ///////////////////////////////////////////////////////////////////////////////
136 // END OF FILE.
137 ///////////////////////////////////////////////////////////////////////////////