-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_hess.c
102 lines (82 loc) · 2.56 KB
/
example_hess.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*! \file example_hess.c
* \brief This file provides and example of the usage of the functions
* that calculate the Hessian of the Lennard Jones potential energy
* surface and the eigenvalue routines provided by GSL.
*
* Input: To execute the program the following arguments must be
* passed in the command line:
* 1. Number of atoms.
* 2. Name of the file with the geometry.
*
* The geometry files are plain text files with 3
* columns for the x-y-z coordinates of the n atoms.
*
* example:
* ./example_grad.out 13 geometry.xyz
*
* Output: The program will print to the standard output the
* eigenvalues of the Hessian matrix and will also
* print in the last line the value of the Geometric Mean
* of such values.
* It is assumed that all the eigenvalues of the Hessian
* matrix are positive up to plus or minus 0.0001, if
* there negative eigenvalues the Geometric Mean
* might be complex and an error will occur in its
* calculation.
*
* If the reader wants to know more about the
* eigenvalue routines should consult the GSL Reference
* Manual.
*/
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_eigen.h>
#include"lj_hess.h"
int
main (int argc, char *argv[])
{
double *x, *y, *z, *data;
int i,gg;
int n = atoi (argv[1]);
FILE *pf;
x = (double *) malloc (n * sizeof (double));
y = (double *) malloc (n * sizeof (double));
z = (double *) malloc (n * sizeof (double));
data = (double *) malloc (9 * n * n * sizeof (double));
pf = fopen (argv[2], "r");
for (i = 0; i < n; i++)
{
gg = fscanf (pf, "%lf %lf %lf", &x[i], &y[i], &z[i]);
}
lj_hessian (n, x, y, z, data);
gsl_matrix_view m = gsl_matrix_view_array (data, 3 * n, 3 * n);
gsl_vector *eval = gsl_vector_alloc (3 * n);
gsl_matrix *evec = gsl_matrix_alloc (3 * n, 3 * n);
gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc (3 * n);
gsl_eigen_symmv (&m.matrix, eval, evec, w);
gsl_eigen_symmv_free (w);
gsl_eigen_symmv_sort (eval, evec, GSL_EIGEN_SORT_ABS_ASC);
{
int i;
double prod = 0;
int count = 0;
for (i = 0; i < 3 * n; i++)
{
double eval_i = gsl_vector_get (eval, i);
gsl_vector_view evec_i = gsl_matrix_column (evec, i);
printf ("%g\n", eval_i);
if (eval_i > 0.0001)//Only eigenvalues gretaer than 0.0001
{
prod += log (eval_i);
count++;
}
}
fprintf (stdout, "\n GM=%lf \n", exp ( prod / count));
}
gsl_vector_free (eval);
gsl_matrix_free (evec);
free (x);
free (y);
free (z);
return 0;
}