1
/*! \file read_scf_opdm.cc
3
\brief Enter brief description of file here
8
#include <libciomr/libciomr.h>
9
#include <libpsio/psio.h>
10
#include <libint/libint.h>
16
#define OFFDIAG_DENS_FACTOR 0.5
18
namespace psi { namespace CINTS {
22
int i, j, ij, nao_i, nao_j, sh_i, sh_j;
24
int nstri = ioff[Symmetry.num_so];
26
double **sq_dens, **sq_denso;
29
double max_elem, temp;
30
struct shell_pair* sp;
32
psio_open(IOUnits.itapDSCF, PSIO_OPEN_OLD);
33
psio_read_entry(IOUnits.itapDSCF, "Integrals cutoff", (char *) &(UserOptions.cutoff), sizeof(double));
34
dens = init_array(nstri);
35
if (UserOptions.reftype == rohf || UserOptions.reftype == uhf)
36
denso = init_array(nstri);
38
if (UserOptions.reftype == uhf) {
39
denso = init_array(nstri);
40
psio_read_entry(IOUnits.itapDSCF, "Difference Alpha Density", (char *) dens, sizeof(double)*nstri);
41
psio_read_entry(IOUnits.itapDSCF, "Difference Beta Density", (char *) denso, sizeof(double)*nstri);
42
/*--- Form total and open-shell (spin) density matrices first ---*/
43
for(i=0;i<nstri;i++) {
44
temp = dens[i] + denso[i];
45
denso[i] = dens[i] - denso[i];
50
psio_read_entry(IOUnits.itapDSCF, "Difference Density", (char *) dens, sizeof(double)*nstri);
51
if (UserOptions.reftype == rohf) {
52
denso = init_array(nstri);
53
psio_read_entry(IOUnits.itapDSCF, "Difference Open-Shell Density", (char *) denso, sizeof(double)*nstri);
56
psio_close(IOUnits.itapDSCF, 1);
59
/*--------------------------
60
Remove after done testing
61
--------------------------*/
62
/* fprintf(outfile," Total density matrix in SO basis :\n");
63
print_array(dens,Symmetry.num_so,outfile);
64
fprintf(outfile,"\n\n");
65
if (UserOptions.reftype == rohf) {
66
fprintf(outfile," Total open-shell density matrix in SO basis :\n");
67
print_array(denso,Symmetry.num_so,outfile);
68
fprintf(outfile,"\n\n");
72
/*------------------------
73
convert to square forms
74
------------------------*/
75
sq_dens = init_matrix(BasisSet.num_ao,BasisSet.num_ao);
77
for(i=0;i<Symmetry.num_so;i++) {
79
sq_dens[i][j] = sq_dens[j][i] = OFFDIAG_DENS_FACTOR*dens[ij];
82
sq_dens[i][i] = dens[ij];
86
if (UserOptions.reftype == rohf || UserOptions.reftype == uhf) {
87
sq_denso = init_matrix(BasisSet.num_ao,BasisSet.num_ao);
89
for(i=0;i<Symmetry.num_so;i++) {
91
sq_denso[i][j] = sq_denso[j][i] = OFFDIAG_DENS_FACTOR*denso[ij];
94
sq_denso[i][i] = denso[ij];
100
/*----------------------
101
transform to AO basis
102
----------------------*/
103
tmp_mat = init_matrix(Symmetry.num_so,BasisSet.num_ao);
104
mmult(sq_dens,0,Symmetry.usotao,0,tmp_mat,0,Symmetry.num_so,Symmetry.num_so,BasisSet.num_ao,0);
105
mmult(Symmetry.usotao,1,tmp_mat,0,sq_dens,0,BasisSet.num_ao,Symmetry.num_so,BasisSet.num_ao,0);
106
if (UserOptions.reftype == rohf || UserOptions.reftype == uhf) {
107
mmult(sq_denso,0,Symmetry.usotao,0,tmp_mat,0,Symmetry.num_so,Symmetry.num_so,BasisSet.num_ao,0);
108
mmult(Symmetry.usotao,1,tmp_mat,0,sq_denso,0,BasisSet.num_ao,Symmetry.num_so,BasisSet.num_ao,0);
110
free_matrix(tmp_mat,Symmetry.num_so);
113
/*--------------------------
114
Remove after done testing
115
--------------------------*/
116
/*fprintf(outfile," Total density matrix in AO basis :\n");
117
print_mat(sq_dens,BasisSet.num_ao,BasisSet.num_ao,outfile);
118
fprintf(outfile,"\n\n");
119
if (UserOptions.reftype == rohf || UserOptions.reftype == uhf) {
120
fprintf(outfile," Total open-shell density matrix in AO basis :\n");
121
print_mat(sq_denso,BasisSet.num_ao,BasisSet.num_ao,outfile);
122
fprintf(outfile,"\n\n");
125
/*--------------------------------
126
transform to shell-blocked form
127
--------------------------------*/
128
switch (UserOptions.reftype) {
130
for(sh_i=0;sh_i<BasisSet.num_shells;sh_i++) {
131
ioffset = BasisSet.shells[sh_i].fao-1;
132
nao_i = ioff[BasisSet.shells[sh_i].am];
133
for(sh_j=0;sh_j<BasisSet.num_shells;sh_j++) {
134
sp = &(BasisSet.shell_pairs[sh_i][sh_j]);
135
joffset = BasisSet.shells[sh_j].fao-1;
136
nao_j = ioff[BasisSet.shells[sh_j].am];
137
if (sp->dmato == NULL)
138
sp->dmato = block_matrix(nao_i,nao_j);
142
for(j=0;j<nao_j;j++) {
143
temp = sp->dmato[i][j] = sq_denso[ioffset+i][joffset+j];
151
free_matrix(sq_denso,BasisSet.num_ao);
153
for(sh_i=0;sh_i<BasisSet.num_shells;sh_i++) {
154
ioffset = BasisSet.shells[sh_i].fao-1;
155
nao_i = ioff[BasisSet.shells[sh_i].am];
156
for(sh_j=0;sh_j<BasisSet.num_shells;sh_j++) {
157
sp = &(BasisSet.shell_pairs[sh_i][sh_j]);
158
joffset = BasisSet.shells[sh_j].fao-1;
159
nao_j = ioff[BasisSet.shells[sh_j].am];
160
if (sp->dmat == NULL)
161
sp->dmat = block_matrix(nao_i,nao_j);
164
for(j=0;j<nao_j;j++) {
165
temp = sp->dmat[i][j] = sq_dens[ioffset+i][joffset+j];
170
sp->Dmax = MAX(sp->Dmax,max_elem);
173
free_matrix(sq_dens,BasisSet.num_ao);
177
for(sh_i=0;sh_i<BasisSet.num_shells;sh_i++) {
178
ioffset = BasisSet.shells[sh_i].fao-1;
179
nao_i = ioff[BasisSet.shells[sh_i].am];
180
for(sh_j=0;sh_j<BasisSet.num_shells;sh_j++) {
181
sp = &(BasisSet.shell_pairs[sh_i][sh_j]);
182
joffset = BasisSet.shells[sh_j].fao-1;
183
nao_j = ioff[BasisSet.shells[sh_j].am];
184
/*--- Check if can reuse space from dmata ---*/
185
if (sp->dmato == NULL)
186
if (sp->dmata == NULL)
187
sp->dmato = block_matrix(nao_i,nao_j);
189
sp->dmato = sp->dmata;
195
for(j=0;j<nao_j;j++) {
196
temp = sp->dmato[i][j] = sq_denso[ioffset+i][joffset+j];
204
free_matrix(sq_denso,BasisSet.num_ao);
206
for(sh_i=0;sh_i<BasisSet.num_shells;sh_i++) {
207
ioffset = BasisSet.shells[sh_i].fao-1;
208
nao_i = ioff[BasisSet.shells[sh_i].am];
209
for(sh_j=0;sh_j<BasisSet.num_shells;sh_j++) {
210
sp = &(BasisSet.shell_pairs[sh_i][sh_j]);
211
joffset = BasisSet.shells[sh_j].fao-1;
212
nao_j = ioff[BasisSet.shells[sh_j].am];
213
/*--- Check if can reuse space from dmatb ---*/
214
if (sp->dmat == NULL)
215
if (sp->dmatb == NULL)
216
sp->dmat = block_matrix(nao_i,nao_j);
218
sp->dmat = sp->dmatb;
224
for(j=0;j<nao_j;j++) {
225
temp = sp->dmat[i][j] = sq_dens[ioffset+i][joffset+j];
230
sp->Dmax = MAX(sp->Dmax,max_elem);
234
free_matrix(sq_dens,BasisSet.num_ao);
238
for(sh_i=0;sh_i<BasisSet.num_shells;sh_i++) {
239
ioffset = BasisSet.shells[sh_i].fao-1;
240
nao_i = ioff[BasisSet.shells[sh_i].am];
241
for(sh_j=0;sh_j<BasisSet.num_shells;sh_j++) {
242
sp = &(BasisSet.shell_pairs[sh_i][sh_j]);
243
joffset = BasisSet.shells[sh_j].fao-1;
244
nao_j = ioff[BasisSet.shells[sh_j].am];
245
if (sp->dmat == NULL)
246
sp->dmat = block_matrix(nao_i,nao_j);
249
for(j=0;j<nao_j;j++) {
250
temp = sp->dmat[i][j] = sq_dens[ioffset+i][joffset+j];
258
free_matrix(sq_dens,BasisSet.num_ao);