1
/* $Revision: 8201 $ $Author: egonw $ $Date: 2007-04-16 10:40:19 +0200 (Mon, 16 Apr 2007) $
3
* Copyright (C) 2005-2007 Violeta Labarta <vlabarta@users.sf.net>
5
* Contact: cdk-devel@lists.sourceforge.net
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public License
9
* as published by the Free Software Foundation; either version 2.1
10
* of the License, or (at your option) any later version.
11
* All we ask is that proper credit is given for our work, which includes
12
* - but is not limited to - adding the above copyright notice to the beginning
13
* of your source code files, and to any copyright notice that you may distribute
14
* with programs based on this work.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
21
* You should have received a copy of the GNU Lesser General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25
package org.openscience.cdk.modeling.forcefield;
27
import javax.vecmath.GMatrix;
28
import javax.vecmath.GVector;
30
import org.openscience.cdk.tools.LoggingTool;
35
* Methods of Newton-Raphson approach.
38
* @cdk.created 2005-06-01
39
* @cdk.module forcefield
41
* @cdk.keyword Newton-Raphson
43
public class NewtonRaphsonMethod {
44
GVector gradientPerInverseHessianVector = null;
45
Matrix matrixForDeterminatCalculation = null;
46
private LoggingTool logger;
50
* Constructor for the NR object
52
public NewtonRaphsonMethod() {
53
logger = new LoggingTool(this);
58
* Calculate the eigen values for the hessian matrix.
60
*@param forMatrix Hessian matrix
61
*@param size coordinates dimension
63
public void hessianEigenValues(double[] forMatrix, int size) {
64
Matrix A = new Matrix(forMatrix, size);
65
Matrix As = A.plus(A.transpose()); // Simetric matrix: As = 1/2 * (A + AT);
67
//logger.debug("Simetric matrix Hs = 1/2 * (H + HT) = ");
68
//As.print(As.getRowDimension(), As.getColumnDimension());
69
double[] realEigenvalues = As.eig().getRealEigenvalues();
70
double[] imagEigenvalues = As.eig().getImagEigenvalues();
71
System.out.println(" ");
72
System.out.println("Hs EigenValues :");
73
for (int i=0; i < As.getColumnDimension(); i++) {
74
System.out.println("Eigen value " + i + ": real part = " + realEigenvalues[i]);
75
System.out.println(", imaginary part = " + imagEigenvalues[i]);
80
public void determinat(GVector gradientk, GMatrix hessiank) {
82
//logger.debug("calculate hessian determinat: ");
83
double[][] forDeterminatCalculation = new double[gradientk.getSize()][];
84
for (int i = 0; i < gradientk.getSize(); i++) {
85
forDeterminatCalculation[i] = new double[gradientk.getSize()];
86
for (int j = 0; j < forDeterminatCalculation[i].length; j++) {
87
forDeterminatCalculation[i][j] = hessiank.getElement(i, j);
91
//logger.debug("gradientk.getSize() = " + gradientk.getSize());
93
* if (gradientk.getSize() == 36) {
95
* for (int i = 0; i < forDeterminatCalculation.length; i++) {
96
* for (int j = 0; j < forDeterminatCalculation[i].length; j++) {
97
* logger.debug(forDeterminatCalculation[i][j] + " ");
103
matrixForDeterminatCalculation = new Matrix(forDeterminatCalculation);
104
//matrixForDeterminatCalculation.print(gradientk.getSize(), gradientk.getSize());
106
//logger.debug("matrixForDeterminatCalculation.det() = " + matrixForDeterminatCalculation.det());
111
public void gradientPerInverseHessian(GVector gradientk, GMatrix hessiank) {
112
this.determinat(gradientk, hessiank);
113
if (matrixForDeterminatCalculation.det() != 0) {
115
//logger.debug("hessiank.invert() = " + hessiank);
116
gradientPerInverseHessianVector = new GVector(gradientk.getSize());
117
gradientPerInverseHessianVector.mul(gradientk, hessiank);
119
logger.debug("The Newton-Raphson method can't be execute because the hessian can't be inverted");
126
* Gets the gradientPerInverseHessian attribute of the NewtonRaphsonMethod
129
*@return The gradientPerInverseHessian value
131
public GVector getGradientPerInverseHessian() {
132
return gradientPerInverseHessianVector;