4
** Check the MO rotation performed in rotate_vector() to make sure that
5
** columns of the C matrix haven't swapped. If so, swap them (and their
6
** eigenvalues) back to the correct ordering.
8
** David Sherrill and Daniel Crawford, July 1995
13
#include <libciomr/libciomr.h>
18
void swap_vectors(double **c, int nn, int j, int i);
20
void check_rot(int nn, int num_mo, double **cold, double **cnew, double *smat_pac,
21
double *fock_evals, int irrep)
23
int i,j,jmaxcoeff,swapped;
24
double maxcoeff=0.0, tval;
26
double **tmp1, **tmp2;
30
smat = init_matrix(nn,nn);
31
tmp1 = init_matrix(nn,nn);
32
tmp2 = init_matrix(nn,nn);
34
tri_to_sq(smat_pac,smat,nn);
38
/* mxmb(cnew,nn,1,smat,1,nn,tmp1,1,nn,nn,nn,nn);
39
mxmb(tmp1,1,nn,cold,1,nn,tmp2,1,nn,nn,nn,nn);*/
40
mmult(cnew,1,smat,0,tmp1,0,num_mo,nn,nn,0);
41
mmult(tmp1,0,cold,0,tmp2,0,num_mo,nn,num_mo,0);
43
/* fprintf(outfile, "C_New Matrix:\n");
44
print_mat(cnew,nn,nn,outfile);
45
fprintf(outfile, "C_New * S * C_old:\n");
46
print_mat(tmp2,nn,nn,outfile); */
49
for(i=0; i < num_mo; i++) {
51
for(j=0; j < num_mo; j++) {
52
if(fabs(tmp2[j][i]) > maxcoeff) {
53
maxcoeff = fabs(tmp2[j][i]);
57
if (maxcoeff < 0.75) {
58
fprintf(outfile, "\n Warning! Diagonality check C'SC gives ");
59
fprintf(outfile, "a maximum element of\n %lf for (%d,%d)\n",
60
maxcoeff, jmaxcoeff+1, i+1);
61
fprintf(outfile, " Won't perform MO swapping for this column\n");
63
else if (jmaxcoeff != i) {
64
swap_vectors(cnew,nn,jmaxcoeff,i);
65
tval = fock_evals[jmaxcoeff];
66
fock_evals[jmaxcoeff] = fock_evals[i];
71
"\n Warning! MO rotation swapped columns of C matrix\n");
75
" Swapping back columns %d and %d for irrep %d\n",
76
jmaxcoeff+1,i+1,irrep+1);
80
} while(swapped && count < 50);
83
fprintf(outfile, "(check_rot): This is bad. Tried 50 swaps for ");
84
fprintf(outfile, "irrep %d!\n", irrep+1);
85
fprintf(outfile, " You may want to set check_rot = false\n");
93
fprintf(outfile, "C_New Matrix(after phase change):\n");
94
print_mat(cnew,nn,nn,outfile);
99
void swap_vectors(double **c, int nn, int j, int i)
104
for(k=0; k < nn; k++) {