5
#include<libipv1/ip_lib.h>
6
#include<libciomr/libciomr.h>
7
#include<libpsio/psio.h>
8
#include<libint/libint.h>
18
#include"calc_den_fast.h"
20
#include"functional.h"
23
#include"free_grid_structs.h"
25
#include"init_close_shell_info.h"
26
#include"calc_close_basis.h"
29
int i,j,k,l,m,n,q,s,t,u;
37
int moff,noff,mtmp,ntmp;
38
int am2shell1,am2shell2;
39
int shell_type1,shell_type2;
50
double *Gtri; /* Total and open-shell
52
triagonal form in SO basis */
55
double rpoints_double;
64
double four_pi_div_by_rps;
76
struct coordinates geom;
77
struct den_info_s den_info;
78
struct xc_info_s xc_info;
80
struct atomic_grid_s *atm_grd;
81
struct leb_chunk_s *chnk;
86
num_ao = BasisSet.num_ao;
87
DFT_options.basis = (double *)malloc(sizeof(double)*num_ao);
89
if(UserOptions.reftype == rhf)
90
G = init_matrix(num_ao,num_ao);
92
/* ----Initialize Close shell data structure ---- */
94
DFT_options.close_shell_info = init_close_shell_info();
101
/*-------------------------------------------------------
102
Loop over symmetry-unique atoms only since integration
103
domains around symm.-unique atoms are equivalent
104
We are NOT employing the symmetry of angular grids
105
about atoms in special positions (on symm. elements)
107
-------------------------------------------------------*/
108
for(ua=0;ua<Symmetry.num_unique_atoms;ua++){
109
atm_grd = &(DFT_options.grid.atomic_grid[ua]);
111
atom = atm_grd->atom_num;
113
/*--- Cheap trick to get degeneracies of each unique atom ---*/
115
ua_deg = atm_grd->atom_degen;
116
ua_deg_d = (double) ua_deg;
118
xa = atm_grd->atom_center.x;
119
ya = atm_grd->atom_center.y;
120
za = atm_grd->atom_center.z;
122
bragg = atm_grd->Bragg_radii;
124
for(j=0;j<atm_grd->chunk_num;j++){
125
chnk = &(atm_grd->leb_chunk[j]);
126
timer_on("close basis");
128
calc_close_basis(ua,j);
130
close_shells = DFT_options.close_shell_info.num_close_shells;
131
close_aos = DFT_options.close_shell_info.num_close_aos;
132
timer_off("close basis");
133
for(k=0;k<chnk->size;k++){
135
sphr = &(chnk->spheres[k]);
141
drdq = sphr->drdq*bragg*bragg*bragg;
142
fprintf(outfile,"\nr = %e drdq = %e ang = %d",r,drdq,sphr->n_ang_points);
143
for(l=0;l<sphr->n_ang_points;l++){
144
pnt = &(sphr->points[l]);
145
/* ----------------------------------
146
Calculate the cartesian points of the point
147
relative to the center of mass
148
-------------------------------------*/
149
geom.x = bragg*pnt->p_cart.x+xa;
150
geom.y = bragg*pnt->p_cart.y+ya;
151
geom.z = bragg*pnt->p_cart.z+za;
153
/*-----------------------------------
154
Calculate the weighting funtion
155
----------------------------------*/
156
Becke_weight = weight_calc(atom,geom,3);
158
if(Becke_weight> WEIGHT_CUTOFF){
159
/*-----------------------------------
160
Get the density information for this
162
----------------------------------*/
164
den_info = DFT_options.den_calc(geom,ua);
168
if(den_info.den > DEN_CUTOFF){
169
/*-------------------------------------
171
-----------------------------------*/
173
ang_quad = 4.0*_pi*pnt->ang_weight;
175
/*------------------------------------
176
Calculate the potential functional
177
and energy functional at this
179
-----------------------------------*/
180
/*fprintf(outfile,"\nua_deg = %10.10lf",ua_deg_d);*/
181
den_val += 2.0*ua_deg_d*drdq*ang_quad
182
*Becke_weight*den_info.den;
184
xc_info.exch_info = DFT_options.
185
exchange_func(den_info);
187
xc_info.corr_info = DFT_options.
188
correlation_func(den_info);
190
exch_vval = ua_deg_d*drdq*ang_quad
191
*Becke_weight*xc_info.exch_info.dval;
192
corr_vval = ua_deg_d*drdq*ang_quad
193
*Becke_weight*xc_info.corr_info.dval;
195
vval = exch_vval+corr_vval;
197
exch_eval += ua_deg_d*drdq*ang_quad
198
*Becke_weight*xc_info.exch_info.eval;
199
corr_eval += ua_deg_d*drdq*ang_quad
200
*Becke_weight*xc_info.corr_info.eval;
201
eval += ua_deg_d*drdq*ang_quad
202
*Becke_weight*(xc_info.exch_info.eval+
203
xc_info.corr_info.eval);
205
/*------------------------------------
207
-----------------------------------*/
211
for(m=0;m<close_aos;m++){
212
bas1 = vval*DFT_options.basis[m];
213
moff = DFT_options.close_shell_info.
214
aos_close_to_chunk[m];
215
for(n=m;n<close_aos;n++){
216
bas2 = bas1*DFT_options.basis[n];
217
noff = DFT_options.close_shell_info.
218
aos_close_to_chunk[n];
220
G[moff][noff] += bas2;
222
G[noff][moff] += bas2;
236
free_close_shell_info(DFT_options.close_shell_info);
237
/*print_mat(G,num_ao,num_ao,outfile);*/
238
for(m=0;m<num_ao;m++)
239
for(n=m;n<num_ao;n++)
246
/*----------------------
247
Unsort the Fock matrix
248
back to shell ordering
249
---------------------*/
252
/*----------------------
253
Transform to SO basis
254
----------------------*/
255
if (Symmetry.nirreps > 1 || BasisSet.puream) {
256
tmpmat1 = block_matrix(Symmetry.num_so,BasisSet.num_ao);
257
mmult(Symmetry.usotao,0,G,0,tmpmat1,0,Symmetry.num_so,BasisSet.num_ao,BasisSet.num_ao,0);
258
mmult(tmpmat1,0,Symmetry.usotao,1,G,0,Symmetry.num_so,BasisSet.num_ao,Symmetry.num_so,0);
259
if (UserOptions.reftype == rohf || UserOptions.reftype == uhf) {
260
mmult(Symmetry.usotao,0,Go,0,tmpmat1,0,Symmetry.num_so,BasisSet.num_ao,BasisSet.num_ao,0);
261
mmult(tmpmat1,0,Symmetry.usotao,1,Go,0,Symmetry.num_so,BasisSet.num_ao,Symmetry.num_so,0);
266
/*-------------------------
267
Write G-matrices to disk
268
-------------------------*/
270
nstri = ioff[Symmetry.num_so];
271
Gtri = init_array(nstri);
272
sq_to_tri(G,Gtri,Symmetry.num_so);
274
fprintf(outfile,"\nDFT_energy = %10.10lf",eval);
275
fprintf(outfile,"\nX-Energy = %10.10lf",exch_eval);
276
fprintf(outfile,"\nC-Energy = %10.10lf",corr_eval);
277
fprintf(outfile,"\ntrace of density = %10.10lf\n",den_val);
279
psio_open(IOUnits.itapDSCF, PSIO_OPEN_OLD);
280
psio_write_entry(IOUnits.itapDSCF,"DFT X-energy",
281
(char *) &(exch_eval), sizeof(double));
282
psio_write_entry(IOUnits.itapDSCF,"DFT C-energy",
283
(char *) &(corr_eval), sizeof(double));
284
psio_write_entry(IOUnits.itapDSCF,"DFT XC-energy",
285
(char *) &(eval), sizeof(double));
286
psio_write_entry(IOUnits.itapDSCF,"DFT Den",
287
(char *) &(den_val), sizeof(double));
289
psio_write_entry(IOUnits.itapDSCF, "Total XC G-matrix"
290
, (char *) Gtri, sizeof(double)*nstri);
293
/*-- Cleanup the DFT stuff and close files --*/
294
cleanup_grid_type(DFT_options.grid);
295
psio_close(IOUnits.itapDSCF, 1);