2
* Revision 1.5 2007/04/05 15:45:25 crawdad
3
* Fixed a few memory leaks identified by valgrind. -TDC
5
/* Revision 1.4 2004/05/03 04:32:40 crawdad
6
/* Major mods based on merge with stable psi-3-2-1 release. Note that this
7
/* version has not been fully tested and some scf-optn test cases do not run
8
/* correctly beccause of changes in mid-March 2004 to optking.
11
/* Revision 1.3.6.4 2004/04/21 15:45:07 evaleev
12
/* Modified DIIS algorithm for RHF and ROHF to work in OSO basis rather than in
13
/* AO basis, to avoid difficulties of transforming between MO and AO bases
14
/* when linear dependencies are present.
16
/* Revision 1.3.6.3 2004/04/10 19:41:32 crawdad
17
/* Fixed the DIIS code for UHF cases. The new version uses the Pulay scheme of
18
/* building the error vector in the AO basis as FDS-SDF, followed by xformation
19
/* into the orthogonal AO basis. This code converges faster for test cases
20
/* like cc8, but fails for linearly dependent basis sets for unknown reasons.
23
/* Revision 1.3.6.2 2004/04/09 00:16:29 evaleev
24
/* Added messages explaining why DGETRF and DGETRI most likely fail.
26
/* Revision 1.3.6.1 2004/04/06 21:29:05 crawdad
27
/* Corrections to the RHF/ROHF DIIS algorithm, which was simply incorrect.
28
/* The backtransformation of the DIIS error vectors to the AO basis was not
29
/* mathematically right.
32
/* Revision 1.3 2002/11/24 22:52:17 crawdad
33
/* Merging the gbye-file30 branch into the main trunk.
36
/* Revision 1.2.6.1 2002/11/23 21:54:45 crawdad
37
/* Removal of mxcoef stuff for chkpt runs.
40
/* Revision 1.2 2000/10/13 19:51:22 evaleev
41
/* Cleaned up a lot of stuff in order to get CSCF working with the new "Mo-projection-capable" INPUT.
43
/* Revision 1.1.1.1 2000/02/04 22:52:33 evaleev
44
/* Started PSI 3 repository
46
/* Revision 1.3 1999/08/17 19:04:18 evaleev
47
/* Changed the default symmetric orthogonalization to the canonical
48
/* orthogonalization. Now, if near-linear dependencies in the basis are found,
49
/* eigenvectors of the overlap matrix with eigenvalues less than 1E-6 will be
50
/* left out. This will lead to num_mo != num_so, i.e. SCF eigenvector is no
51
/* longer a square matrix. Had to rework some routines in libfile30, and add some.
52
/* The progrem prints out a warning if near-linear dependencies are found. TRANSQT
53
/* and a whole bunch of other codes has to be fixed to work with such basis sets.
55
/* Revision 1.2 1999/08/11 18:39:03 evaleev
56
/* Added some checks on the lowest eigenvalue of the overlap matrix.
58
/* Revision 1.1.1.1 1999/04/12 16:59:28 evaleev
59
/* Added a version of CSCF that can work with CINTS.
63
static char *rcsid = "$Id: shalf.c 3324 2007-04-05 15:45:25Z crawdad $";
65
/* construct S-1/2 matrix 'sahalf' using CANONICAL orthogonalization */
75
double *eig_vals, **eig_vecs;
78
double min_eval = 100000.0;
80
int info, lwork, *ipiv;
81
double *work, **P, **T, **X;
83
eig_vals = (double *) init_array(nsfmax);
84
eig_vecs = (double **) init_matrix(nsfmax,nsfmax);
85
shalf = block_matrix(nsfmax,nsfmax);
93
/* diagonalize smat to get eigenvalues and eigenvectors */
95
for (i=0; i < num_ir ; i++) {
99
rsp(nn,nn,ioff[nn],s->smat,eig_vals,1,eig_vecs,tol);
101
/*--- Find the lowest eigenvalue ---*/
102
for(ii=0; ii < nn ; ii++)
103
if (eig_vals[ii] < min_eval)
104
min_eval = eig_vals[ii];
107
fprintf(outfile,"\noverlap eigenstuff\n");
108
eivout(eig_vecs,eig_vals,nn,nn,outfile);
111
/*--- Go through the eigenvalues and "throw away"
112
the dangerously small ones ---*/
114
for(ii=0; ii < nn ; ii++)
115
if (eig_vals[ii] >= LINDEP_CUTOFF) {
116
eig_vals[ii] = 1.0/sqrt(eig_vals[ii]);
121
mxcoef += num_mo * nn;
126
fprintf(outfile,"\n In symblk %d %d eigenvectors of S with eigenvalues < %lf are thrown away",
127
i,nn-num_mo,LINDEP_CUTOFF);
129
/* form 'sahalf' matrix sahalf = U*(s-1/2) */
131
for (ii=0; ii < nn ; ii++)
132
for (jj=0; jj < num_mo ; jj++)
133
s->sahalf[ii][jj] += eig_vecs[ii][jj+nn-num_mo]*eig_vals[jj+nn-num_mo];
135
/* form 'shalf' matrix shalf = U*(s^1/2) */
137
for (ii=0; ii < nn ; ii++)
138
for (jj=0; jj < num_mo ; jj++)
139
shalf[ii][jj] = eig_vecs[ii][jj+nn-num_mo]*(1.0/eig_vals[jj+nn-num_mo]);
142
fprintf(outfile, "S^-1/2 Original:\n");
143
print_mat(s->sahalf, nn, num_mo, outfile);
146
/* new transformation matrix for the DIIS error vectors: P^-1 = S^{1/2} * (S^{1/2})^+ */
147
C_DGEMM('n', 't', nn, nn, num_mo, 1.0, shalf[0], nsfmax, shalf[0], nsfmax,
148
0.0, s->pinv[0], nn);
154
free_matrix(eig_vecs,nsfmax);
156
fprintf(outfile,"\n The lowest eigenvalue of the overlap matrix was %e\n\n",