3
* $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
6
* Copyright (C) 1997-2007 The Chemistry Development Kit (CDK) project
8
* Contact: cdk-devel@lists.sourceforge.net
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public License
12
* as published by the Free Software Foundation; either version 2.1
13
* of the License, or (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25
package org.openscience.cdk.graph.invariant;
27
import org.openscience.cdk.AtomContainer;
28
import org.openscience.cdk.graph.PathTools;
29
import org.openscience.cdk.graph.invariant.exception.BadMatrixFormatException;
30
import org.openscience.cdk.graph.invariant.exception.IndexOutOfBoundsException;
31
import org.openscience.cdk.graph.matrix.ConnectionMatrix;
32
import org.openscience.cdk.interfaces.IBond;
33
import org.openscience.cdk.tools.LoggingTool;
35
import java.util.Iterator;
38
* Collection of methods for the calculation of topological indices of a
41
public class HuLuIndexTool
43
private final static LoggingTool logger = new LoggingTool(HuLuIndexTool.class);
46
* Calculates the extended adjacency matrix index.
47
* An implementation of the algorithm published in {@cdk.cite HU96}.
49
* @cdk.keyword EAID number
51
public static double getEAIDNumber(AtomContainer atomContainer) throws org.openscience.cdk.exception.NoSuchAtomException,
52
BadMatrixFormatException,IndexOutOfBoundsException
54
boolean debug = false;
56
GIMatrix matrix = new GIMatrix(getExtendedAdjacenyMatrix(atomContainer));
58
GIMatrix tempMatrix = matrix;
59
GIMatrix fixedMatrix = matrix;
60
for (int i = 2; i < atomContainer.getAtomCount(); i++)
62
tempMatrix = tempMatrix.multiply(fixedMatrix);
63
matrix = matrix.add(tempMatrix);
66
for (int i = 0; i < atomContainer.getAtomCount(); i++)
68
matrix.setValueAt(i,i,matrix.getValueAt(i,i)+1);
70
double eaid = matrix.trace();
72
logger.debug("final matrix - the sum of the powers of EA matrix: ");
73
displayMatrix(matrix.getArrayValue());
74
logger.debug("eaid number: "+ eaid);
80
public static double[][] getExtendedAdjacenyMatrix(AtomContainer atomContainer)
81
throws org.openscience.cdk.exception.NoSuchAtomException
83
boolean debug = false;
84
double[][] adjaMatrix = ConnectionMatrix.getMatrix(atomContainer);
86
logger.debug("adjacency matrix: ");
87
displayMatrix(adjaMatrix);
89
double[] atomWeights = getAtomWeights(atomContainer);
92
for (int i = 0; i < adjaMatrix.length; i++)
94
for (int j = 0; j < adjaMatrix.length; j++)
98
if (atomContainer.getAtom(i).getSymbol()=="O")
100
adjaMatrix[i][j] = Math.sqrt(0.74)/6;
104
adjaMatrix[i][j] = Math.sqrt(0.74)/6;
109
adjaMatrix[i][j] = (Math.sqrt(atomWeights[i]/atomWeights[j]) + Math.sqrt(atomWeights[j]/atomWeights[i])) * Math.sqrt(adjaMatrix[i][j])/6;
114
logger.debug("extended adjacency matrix: ");
115
displayMatrix(adjaMatrix);
120
public static double[] getAtomWeights(AtomContainer atomContainer) throws org.openscience.cdk.exception.NoSuchAtomException
122
boolean debug = false;
123
org.openscience.cdk.interfaces.IAtom atom,headAtom,endAtom;
124
int headAtomPosition,endAtomPosition;
127
double[] weightArray = new double[atomContainer.getAtomCount()];
128
double[][] adjaMatrix = ConnectionMatrix.getMatrix(atomContainer);
130
int[][] apspMatrix = PathTools.computeFloydAPSP(adjaMatrix);
131
int[] atomLayers = getAtomLayers(apspMatrix);
134
int[] interLayerBondSum;
136
logger.debug("adjacency matrix: ");
137
displayMatrix(adjaMatrix);
138
logger.debug("all-pairs-shortest-path matrix: ");
139
displayMatrix(apspMatrix);
140
logger.debug("atom layers: ");
141
displayArray(atomLayers);
143
for (int i = 0; i < atomContainer.getAtomCount(); i++)
145
atom = atomContainer.getAtom(i);
147
valenceSum = new int[atomLayers[i]];
148
for (int v = 0; v < valenceSum.length; v++)
153
interLayerBondSum = new int[atomLayers[i]-1];
154
for (int v = 0; v < interLayerBondSum.length; v++)
156
interLayerBondSum[v] = 0;
160
//weightArray[k] = atom.getValenceElectronsCount() - atom.getHydrogenCount(); // method unfinished
161
if(atom.getSymbol()=="O")
162
weightArray[i] = 6 - atom.getHydrogenCount();
164
weightArray[i] = 4 - atom.getHydrogenCount();
168
for (int j = 0; j < apspMatrix.length; j++)
170
if(atomContainer.getAtom(j).getSymbol()=="O")
171
valenceSum[apspMatrix[j][i]] += 6 - atomContainer.getAtom(j).getHydrogenCount();
173
valenceSum[apspMatrix[j][i]] += 4 - atomContainer.getAtom(j).getHydrogenCount();
176
Iterator bonds = atomContainer.bonds();
177
while (bonds.hasNext()) {
178
IBond bond = (IBond) bonds.next();
180
headAtom = bond.getAtom(0);
181
endAtom = bond.getAtom(1);
184
headAtomPosition = atomContainer.getAtomNumber(headAtom);
185
endAtomPosition = atomContainer.getAtomNumber(endAtom);
190
if (Math.abs(apspMatrix[i][headAtomPosition] - apspMatrix[i][endAtomPosition]) == 1)
192
int min = Math.min(apspMatrix[i][headAtomPosition],apspMatrix[i][endAtomPosition]);
193
interLayerBondSum[min] += bond.getOrder();
198
for (int j = 0; j < interLayerBondSum.length; j++)
200
weightArray[i] += interLayerBondSum[j] * valenceSum[j+1] * Math.pow(10, -(j+1));
203
logger.debug("valence sum: ");
204
displayArray(valenceSum);
205
logger.debug("inter-layer bond sum: ");
206
displayArray(interLayerBondSum);
209
logger.debug("weight array: ");
210
displayArray(weightArray);
215
public static int[] getAtomLayers(int[][]apspMatrix)
217
int[] atomLayers = new int[apspMatrix.length];
218
for(int i = 0; i < apspMatrix.length; i++)
221
for(int j = 0; j < apspMatrix.length; j++)
223
if(atomLayers[i] < 1+ apspMatrix[j][i] )
224
atomLayers[i] = 1+ apspMatrix[j][i];
231
/** Lists a 2D double matrix to the System console */
232
public static void displayMatrix(double[][] matrix){
234
for (int f = 0; f < matrix.length; f++)
237
for (int g = 0; g < matrix.length; g++)
239
line += matrix[g][f] + " | ";
245
/** Lists a 2D int matrix to the System console */
246
public static void displayMatrix(int[][] matrix){
248
for (int f = 0; f < matrix.length; f++)
251
for (int g = 0; g < matrix.length; g++)
253
line += matrix[g][f] + " | ";
259
/** Lists a 1D array to the System console */
260
public static void displayArray(int[] array){
262
for (int f = 0; f < array.length; f++)
264
line += array[f] + " | ";
269
/** Lists a 1D array to the System console */
270
public static void displayArray(double[] array){
272
for (int f = 0; f < array.length; f++)
274
line += array[f] + " | ";