4
#include <libciomr/libciomr.h>
5
#include <libdpd/dpd.h>
12
/* build_Z_UHF(): Solve the orbital Z-vector equations for UHF refs:
14
** A(AI,BJ) D(orb)(B,J) = -X(A,I)
16
** where A(AI,EM) is the orbital Hessian computed in build_A(), X(A,I)
17
** is the orbital rotation gradient computed in build_X(), and
18
** D(orb)(E,M) is the final Z-vector we want.
22
void build_Z_UHF(void)
24
dpdbuf4 A_AA, A_BB, A_AB;
27
int num_ai, a, i, ai, bj;
28
int h, nirreps, count, dim_A, dim_B;
30
int *avirtpi, *aoccpi;
31
int *bvirtpi, *boccpi;
33
nirreps = moinfo.nirreps;
34
aoccpi = moinfo.aoccpi; avirtpi = moinfo.avirtpi;
35
boccpi = moinfo.boccpi; bvirtpi = moinfo.bvirtpi;
37
/* compute the number of ai pairs */
39
for(h=0; h < nirreps; h++) {
40
num_ai += avirtpi[h] * aoccpi[h];
41
num_ai += bvirtpi[h] * boccpi[h];
44
/* Place all the elements of the orbital rotation gradient, X, into a
46
Z = init_array(num_ai);
48
dpd_file2_init(&X, CC_OEI, 0, 1, 0, "XAI");
49
dpd_file2_mat_init(&X);
51
for(h=0,count=0; h < nirreps; h++)
52
for(a=0; a < X.params->rowtot[h]; a++)
53
for(i=0; i < X.params->coltot[h]; i++)
54
Z[count++] = -X.matrix[h][a][i];
55
dpd_file2_mat_close(&X);
58
dpd_file2_init(&X, CC_OEI, 0, 3, 2, "Xai");
59
dpd_file2_mat_init(&X);
61
for(h=0; h < nirreps; h++)
62
for(a=0; a < X.params->rowtot[h]; a++)
63
for(i=0; i < X.params->coltot[h]; i++)
64
Z[count++] = -X.matrix[h][a][i];
65
dpd_file2_mat_close(&X);
68
/* Now, build the full MO Hessian */
69
dpd_buf4_init(&A_AA, CC_MISC, 0, 21, 21, 21, 21, 0, "A(AI,BJ)");
70
dpd_buf4_init(&A_BB, CC_MISC, 0, 31, 31, 31, 31, 0, "A(ai,bj)");
71
dpd_buf4_init(&A_AB, CC_MISC, 0, 21, 31, 21, 31, 0, "A(AI,bj)");
74
dim_A = A_AA.params->rowtot[0];
75
dim_B = A_BB.params->rowtot[0];
77
if(num_ai != dim_A + dim_B) { /* error */
78
fprintf(outfile, "Problem: num_ai(%d) != dim_A + dim_b (%d)\n", num_ai,
80
exit(PSI_RETURN_FAILURE);
83
A = block_matrix(num_ai, num_ai);
85
dpd_buf4_mat_irrep_init(&A_AA, 0);
86
dpd_buf4_mat_irrep_rd(&A_AA, 0);
87
for(ai=0; ai < dim_A; ai++)
88
for(bj=0; bj < dim_A; bj++)
89
A[ai][bj] = A_AA.matrix[0][ai][bj];
90
dpd_buf4_mat_irrep_close(&A_AA, 0);
92
dpd_buf4_mat_irrep_init(&A_BB, 0);
93
dpd_buf4_mat_irrep_rd(&A_BB, 0);
94
for(ai=0; ai < dim_B; ai++)
95
for(bj=0; bj < dim_B; bj++)
96
A[ai+dim_A][bj+dim_A] = A_BB.matrix[0][ai][bj];
97
dpd_buf4_mat_irrep_close(&A_BB, 0);
99
dpd_buf4_mat_irrep_init(&A_AB, 0);
100
dpd_buf4_mat_irrep_rd(&A_AB, 0);
101
for(ai=0; ai < dim_A; ai++)
102
for(bj=0; bj < dim_B; bj++)
103
A[ai][bj+dim_A] = A[bj+dim_A][ai] = A_AB.matrix[0][ai][bj];
104
dpd_buf4_mat_irrep_close(&A_AB, 0);
106
dpd_buf4_close(&A_AA);
107
dpd_buf4_close(&A_BB);
108
dpd_buf4_close(&A_AB);
111
ipiv = init_int_array(num_ai);
112
info = C_DGESV(num_ai, 1, &(A[0][0]), num_ai, &(ipiv[0]), &(Z[0]), num_ai);
114
fprintf(outfile, "\nError in DGESV return in build_Z_UHF: %d.\n", info);
115
exit(PSI_RETURN_FAILURE);
121
pople(A, Z, num_ai, 1, 1e-12, outfile, 0);
124
for(ai=0; ai < num_ai; ai++) fprintf(outfile, "Z[%d] = %20.15f\n", ai, Z[ai]);
127
dpd_file2_init(&D, CC_OEI, 0, 1, 0, "D(orb)(A,I)");
128
dpd_file2_scm(&D, 0.0);
129
dpd_file2_mat_init(&D);
130
for(h=0,count=0; h < nirreps; h++)
131
for(a=0; a < D.params->rowtot[h]; a++)
132
for(i=0; i < D.params->coltot[h]; i++) {
133
if(fabs(Z[count]) > 1e3) D.matrix[h][a][i] = 0.0;
134
else D.matrix[h][a][i] = Z[count];
137
dpd_file2_mat_wrt(&D);
138
dpd_file2_mat_close(&D);
141
dpd_file2_init(&D, CC_OEI, 0, 3, 2, "D(orb)(a,i)");
142
dpd_file2_scm(&D, 0.0);
143
dpd_file2_mat_init(&D);
144
for(h=0; h < nirreps; h++)
145
for(a=0; a < D.params->rowtot[h]; a++)
146
for(i=0; i < D.params->coltot[h]; i++) {
147
if(fabs(Z[count]) > 1e3) D.matrix[h][a][i] = 0.0;
148
else D.matrix[h][a][i] = Z[count];
151
dpd_file2_mat_wrt(&D);
152
dpd_file2_mat_close(&D);
155
/* We're done with Z */