Source code: joelib/desc/types/GraphPotentials.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Filename: $RCSfile: GraphPotentials.java,v $
3 // Purpose: Graph potentials.
4 // Language: Java
5 // Compiler: JDK 1.4
6 // Authors: Joerg K. Wegner
7 // Version: $Revision: 1.21 $
8 // $Date: 2003/08/22 15:56:16 $
9 // $Author: wegner $
10 // Original Author: ???, OpenEye Scientific Software
11 // Original Version: babel 2.0a1
12 //
13 // Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 ///////////////////////////////////////////////////////////////////////////////
24 package joelib.desc.types;
25
26
27 /*==========================================================================*
28 * IMPORTS
29 *==========================================================================*/
30 import jmat.data.Matrix;
31
32 import joelib.desc.DescriptorHelper;
33 import joelib.desc.DescriptorInfo;
34 import joelib.desc.SimpleDoubleAtomProperty;
35
36 import joelib.molecule.JOEAtom;
37 import joelib.molecule.JOEMol;
38
39 import joelib.util.iterator.AtomIterator;
40
41 import org.apache.log4j.Category;
42
43
44 /*==========================================================================*
45 * CLASS DECLARATION
46 *==========================================================================*/
47
48 /**
49 * External rotational symmetry or graph potentials.
50 *
51 * @author wegnerj
52 * @license GPL
53 * @cvsversion $Revision: 1.21 $, $Date: 2003/08/22 15:56:16 $
54 * @cite wy96
55 */
56 public class GraphPotentials extends SimpleDoubleAtomProperty
57 {
58 //~ Static fields/initializers /////////////////////////////////////////////
59
60 /**
61 * Obtain a suitable logger.
62 */
63 private static Category logger = Category.getInstance(
64 "joelib.desc.types.GraphPotentials");
65 public static final String DESC_KEY = "Graph_potentials";
66
67 //~ Constructors ///////////////////////////////////////////////////////////
68
69 /*-------------------------------------------------------------------------*
70 * private variables
71 *-------------------------------------------------------------------------*/
72 /*-------------------------------------------------------------------------*
73 * constructor
74 *-------------------------------------------------------------------------*/
75 public GraphPotentials()
76 {
77 if (logger.isDebugEnabled())
78 {
79 logger.debug("Initialize " + this.getClass().getName());
80 }
81
82 descInfo = DescriptorHelper.generateDescInfo(DESC_KEY, this.getClass(),
83 DescriptorInfo.TYPE_NO_COORDINATES, null,
84 "joelib.desc.result.AtomDoubleResult");
85 }
86
87 //~ Methods ////////////////////////////////////////////////////////////////
88
89 /*-------------------------------------------------------------------------*
90 * public methods
91 *------------------------------------------------------------------------- */
92 public double[] getDoubleAtomProperties(JOEMol mol)
93 {
94 // get graph potentials for all atoms
95 double[] grPot = graphPotentials(mol);
96
97 return grPot;
98 }
99
100 /**
101 * Calculate the Graph Potentials of a molecule based on V.E. Rozenblit, A.B.
102 * Golender Logical and Combinatorial Algorithms for Drug Design for an
103 * example see:<br>
104 * W.P. Walters, S. H. Yalkowsky, 'ESCHER-A Computer Program for the
105 * Determination of External Rotational Symmetry Numbers from Molecular
106 * Topology', J. Chem. Inf. Comput. Sci., 1996, 36(5), 1015-1017
107 *
108 * @param mol Description of the Parameter
109 * @return Description of the Return Value
110 */
111 public static double[] graphPotentials(JOEMol mol)
112 {
113 Matrix g = gMatrix(mol);
114
115 // System.out.println("G-matrix"+MathHelper.matrixToString(g));
116 Matrix inverseG = g.inverse();
117
118 // System.out.println("inverse G-matrix"+MathHelper.matrixToString(inverseG));
119 Matrix c = cMatrix(mol);
120
121 // System.out.println("C-matrix"+MathHelper.matrixToString(c));
122 Matrix h = inverseG.times(c);
123
124 int nAtoms = mol.numAtoms();
125 double[] graphPotentials = new double[nAtoms];
126
127 for (int i = 0; i < nAtoms; i++)
128 {
129 graphPotentials[i] = h.get(i, 0);
130
131 // System.out.println("H("+i+"):"+h.get(i,0) );
132 }
133
134 return graphPotentials;
135 }
136
137 /**
138 * Construct the matrix C, which is simply a column vector consisting of the
139 * valence for each atom
140 *
141 * @param mol Description of the Parameter
142 * @return Description of the Return Value
143 */
144 private static Matrix cMatrix(JOEMol mol)
145 {
146 Matrix c = new Matrix(mol.numAtoms(), 1);
147 JOEAtom atom;
148 AtomIterator ait = mol.atomIterator();
149 int i = 0;
150
151 while (ait.hasNext())
152 {
153 atom = ait.nextAtom();
154 c.set(i, 0, atom.getValence());
155 i++;
156 }
157
158 // ByteArrayOutputStream baos = new ByteArrayOutputStream(10000);
159 // PrintWriter pw = new PrintWriter(baos);
160 // c.print(pw, 5,2);
161 // System.out.println("TEST"+baos.toString());
162 return c;
163 }
164
165 /*-------------------------------------------------------------------------*
166 * private methods
167 *-------------------------------------------------------------------------*/
168
169 /**
170 * Construct the matrix G, which puts each atoms valence+1 on the diagonal
171 * and and -1 on the off diagonal if two atoms are connected.
172 *
173 * @param mol Description of the Parameter
174 * @return Description of the Return Value
175 */
176 private static Matrix gMatrix(JOEMol mol)
177 {
178 JOEAtom atom1;
179 JOEAtom atom2;
180 Matrix g = new Matrix(mol.numAtoms(), mol.numAtoms());
181 AtomIterator ait1 = mol.atomIterator();
182 AtomIterator ait2 = mol.atomIterator();
183 int i;
184 int j;
185
186 i = 0;
187
188 double value;
189
190 while (ait1.hasNext())
191 {
192 atom1 = ait1.nextAtom();
193 ait2.reset();
194 j = 0;
195
196 while (ait2.hasNext())
197 {
198 atom2 = ait2.nextAtom();
199
200 if (atom1 == atom2)
201 {
202 value = (atom1.getValence() + 1);
203 value += ((double) atom1.getAtomicNum() / 10.0);
204 value += ((double) atom1.getHyb() / 100.0);
205 g.set(i, j, value);
206 }
207 else
208 {
209 if (atom1.isConnected(atom2))
210 {
211 g.set(i, j, -1.0);
212 }
213 else
214 {
215 g.set(i, j, 0.0);
216 }
217 }
218
219 j++;
220 }
221
222 i++;
223 }
224
225 return g;
226 }
227 }
228 ///////////////////////////////////////////////////////////////////////////////
229 // END OF FILE.
230 ///////////////////////////////////////////////////////////////////////////////