1
#include <libdpd/dpd.h>
3
#include <libciomr/libciomr.h>
8
/* build_Z_ROHF(): Solve the orbital Z-vector equations for ROHF refs:
10
** sum E,M A(AI,EM) D(orb)(E,M) = -X(A,I)
12
** where A(AI,EM) is the orbital Hessian computed in build_A(), X(A,I)
13
** is the orbital rotation gradient computed in build_X(), and
14
** D(orb)(E,M) is the final Z-vector we want.
18
void build_Z_ROHF(void)
22
double **X, **T, **Y, **Z;
23
int num_ai, h, nirreps, a, i, count, lastcol, rank, ai;
24
int *virtpi, *occpi, *openpi;
26
nirreps = moinfo.nirreps;
27
occpi = moinfo.occpi; openpi = moinfo.openpi; virtpi = moinfo.virtpi;
29
/*** Construct the ai transformation matrix which places all singly
30
occupied orbital combinations at the end of the vector ***/
32
/* First compute the number of ai pairs */
34
for(h=0; h < nirreps; h++)
35
num_ai += virtpi[h] * occpi[h];
37
/* fprintf(outfile, "num_ai = %d\n", num_ai); */
39
/* Malloc space for the transformation matrix */
40
T = block_matrix(num_ai,num_ai);
42
/* Now compute the row/column swaps we need and the number of zero
44
for(h=0,count=0,rank=0; h < nirreps; h++)
45
for(a=0; a < virtpi[h]; a++)
46
for(i=0; i < occpi[h]; i++) {
47
if((a >= (virtpi[h] - openpi[h])) &&
48
(i >= (occpi[h] - openpi[h])) )
49
T[count][count] = 0.0;
51
T[count][count] = 1.0;
58
for(h=0; h < nirreps; h++)
59
for(a=0; a < virtpi[h]; a++)
60
for(i=0; i < occpi[h] && lastcol > count; i++,count++) {
61
if(T[count][count] == 0.0) {
62
while (T[lastcol][lastcol] == 0.0) lastcol--;
64
T[count][lastcol] = T[lastcol][count] = 1.0;
65
T[lastcol][lastcol] = 0.0;
70
/* print_mat(T, num_ai, num_ai, outfile); */
72
/*** Finished building the transformation matrix ***/
74
/* Place all the elements of the orbital rotation gradient, X into a
76
dpd_file2_init(&X1, CC_MISC, 0, 1, 0, "X(A,I)");
77
dpd_file2_mat_init(&X1);
78
dpd_file2_mat_rd(&X1);
80
for(h=0; h < nirreps; h++)
81
num_ai += X1.params->rowtot[h]*X1.params->coltot[h];
83
Z = block_matrix(1,num_ai);
84
for(h=0,count=0; h < nirreps; h++)
85
for(a=0; a < X1.params->rowtot[h]; a++)
86
for(i=0; i < X1.params->coltot[h]; i++)
87
Z[0][count++] = -X1.matrix[h][a][i];
90
dpd_file2_mat_close(&X1);
93
/* Push the zero elements of X to the end of the vector */
94
X = block_matrix(1,num_ai);
95
/* newmm(T,0,Z,0,X,num_ai,num_ai,1,1.0,0.0); */
97
C_DGEMV('n',num_ai, num_ai, 1.0, &(T[0][0]), num_ai, &(Z[0][0]), 1, 0.0, &(X[0][0]), 1);
99
/* Now, grab only irrep 0 of the orbital Hessian */
100
dpd_buf4_init(&A, CC_MISC, 0, 11, 11, 11, 11, 0, "A(EM,AI)");
101
dpd_buf4_mat_irrep_init(&A, 0);
102
dpd_buf4_mat_irrep_rd(&A, 0);
104
/* Move the zero rows and columns of the Hessian to the bottom.
105
Note that as long as we won't be writing A back to disk, it's OK
106
to put the product back in A.matrix[0]. */
107
Y = block_matrix(num_ai,num_ai);
108
/* newmm(A.matrix[0],0,T,0,Y,num_ai,num_ai,num_ai,1.0,0.0); */
110
C_DGEMM('n','n',num_ai,num_ai,num_ai,1.0,&(A.matrix[0][0][0]),num_ai,
111
&(T[0][0]),num_ai,0.0,&(Y[0][0]),num_ai);
112
/* newmm(T,0,Y,0,A.matrix[0],num_ai,num_ai,num_ai,1.0,0.0); */
114
C_DGEMM('n','n',num_ai,num_ai,num_ai,1.0,&(T[0][0]),num_ai,&(Y[0][0]),num_ai,
115
0.0,&(A.matrix[0][0][0]),num_ai);
118
/* Trying out Matt's Pople code --- way to go, Matt! */
119
pople(A.matrix[0], X[0], rank, 1, 1e-12, outfile, 0);
121
dpd_buf4_mat_irrep_close(&A, 0);
124
/* Now re-order the elements of X back to the DPD format */
125
/* newmm(T,0,X,0,Z,num_ai,num_ai,1,1.0,0.0); */
127
C_DGEMV('n',num_ai, num_ai, 1.0, &(T[0][0]), num_ai, &(X[0][0]), 1, 0.0, &(Z[0][0]), 1);
130
/* We don't need the transformation matrix anymore */
134
for(ai=0; ai < num_ai; ai++) fprintf(outfile, "Z[%d] = %20.15f\n", ai, Z[0][ai]);
137
/* Build the orbital component of Dai --- we'll build these as separate
138
spin cases for future simplicity (e.g., UHF-based codes)*/
139
dpd_file2_init(&D, CC_OEI, 0, 1, 0, "D(orb)(A,I)");
140
dpd_file2_mat_init(&D);
141
for(h=0,count=0; h < nirreps; h++)
142
for(a=0; a < D.params->rowtot[h]; a++)
143
for(i=0; i < D.params->coltot[h]; i++) {
144
D.matrix[h][a][i] = Z[0][count++];
146
if(a >= (virtpi[h] - openpi[h])) D.matrix[h][a][i] = 0.0;
148
dpd_file2_mat_wrt(&D);
149
dpd_file2_mat_close(&D);
152
dpd_file2_init(&D, CC_OEI, 0, 1, 0, "D(orb)(a,i)");
153
dpd_file2_mat_init(&D);
154
for(h=0,count=0; h < nirreps; h++)
155
for(a=0; a < D.params->rowtot[h]; a++)
156
for(i=0; i < D.params->coltot[h]; i++) {
157
D.matrix[h][a][i] = Z[0][count++];
159
if(i >= (occpi[h] - openpi[h])) D.matrix[h][a][i] = 0.0;
161
dpd_file2_mat_wrt(&D);
162
dpd_file2_mat_close(&D);
165
/* We're done with Z */