3
\brief Enter brief description of file here
6
* Revision 1.3 2003/08/09 17:39:56 crawdad
7
* I added the ability to determine frozen core orbitals for UHF references to
8
* cleanup.c. I also commented out ip_cwk_clear and ip_cwk_add calls in
9
* cleanup.c, guess.c, scf_input.c and scf_iter_2.c. These calls were (1) poor
10
* design and (2) interfering with default ip_tree behavior needed to simplify
11
* the format of input.dat.
14
/* Revision 1.2 2002/03/25 02:17:36 janssen
15
/* Get rid of tmpl. Use new naming scheme for libipv1 includes.
17
/* Revision 1.1.1.1 2000/02/04 22:52:32 evaleev
18
/* Started PSI 3 repository
20
/* Revision 1.2 1999/08/17 19:04:17 evaleev
21
/* Changed the default symmetric orthogonalization to the canonical
22
/* orthogonalization. Now, if near-linear dependencies in the basis are found,
23
/* eigenvectors of the overlap matrix with eigenvalues less than 1E-6 will be
24
/* left out. This will lead to num_mo != num_so, i.e. SCF eigenvector is no
25
/* longer a square matrix. Had to rework some routines in libfile30, and add some.
26
/* The progrem prints out a warning if near-linear dependencies are found. TRANSQT
27
/* and a whole bunch of other codes has to be fixed to work with such basis sets.
29
/* Revision 1.1.1.1 1999/04/12 16:59:28 evaleev
30
/* Added a version of CSCF that can work with CINTS.
37
#include <libipv1/ip_lib.h>
39
namespace psi { namespace cscf {
41
/* scf procedure for two-configuration scf */
54
double ciconv = 10.0e-9; // FAE it was 10.0e-9
56
double eci1,eci2,eci3;
57
double ci1,ci2,ci1old,term,hoff,amax,cn,sn;
58
double cimax,cimin,incr;
59
double occi, occj, occ0, den;
62
double **fock_c, **fock_o;
63
double **fock_ct,**fock_eff;
69
/* optest = (int *) init_array(ioff[nbasis]/2); */
70
optest = (int *) init_int_array(ioff[nbasis]);
71
scr = (double **) init_matrix(nsfmax,nsfmax);
72
fock_c = (double **) init_matrix(nsfmax,nsfmax);
73
fock_ct = (double **) init_matrix(nsfmax,nsfmax);
74
ctrans = (double **) init_matrix(nsfmax,nsfmax);
75
c1 = (double *) init_array(num_ir);
76
c2 = (double *) init_array(num_ir);
77
fock_o = (double **) init_matrix(nsfmax,nsfmax);
79
for (i=0; i < num_ir ; i++) {
83
s->ucmat = block_matrix(num_mo, num_mo);
84
for(j=0; j<num_mo; j++)
92
ip_cwk_add(":DEFAULT");
97
errcod = ip_data("INCR","%lf",&incr,0);
98
fprintf(outfile,"\n tcscf increment = %f\n",incr);
101
/* find open shells */
103
for (i=0; i < num_ir ; i++) {
104
iju += scf_info[i].num_mo;
105
if(scf_info[i].nopen) {
111
for (i=0; i < num_ir ; i++) {
115
for (j=0; j < num_mo ; j++) {
116
if (s->occ_num[j] == 1.0) {
131
/* set up array of flags indicating open shells */
133
for (k=joff=0; k < num_ir ; k++) {
136
for (i=0; i < nn ; i++)
137
for (j=0; j <= i ; j++)
138
if(s->nopen) optest[ioff[i+joff]+j+joff] = 1;
143
/* set up c1 and c2 */
144
for (i=0; i < num_ir ; i++) {
148
for (j=0; j < num_mo ; j++) {
149
if(s->occ_num[j]==2.0) c1[i]=2.0;
150
if(s->occ_num[j]==1.0) c2[i]=1.0;
152
if(i == opblk1) c1i=c1[i];
153
if(i == opblk2) c1ii=c1[i];
162
ci1old = 0.0; // FAE Give it some arbitrary value
167
fprintf(outfile, "Warning: Finding second root of TCSCF\n\n");
169
for (iter=0; iter < itmax ; ) {
170
if(iter==stop_lshift){
172
fprintf(outfile,"Setting level shift to %lf\n",lshift);
176
if(!newci || fabs(ci1old-ci1) < ciconv && iter) goto L2;
178
/* do some funky stuff to get coeffs ? */
183
for (i=0; i < num_ir ; i++) {
187
for (j=0; j < ioff[nn] ; j++) {
191
s->pmato2[j] = d1-d2;
198
eci1 = eci2 = eci3 = 0.0;
199
for (i=0; i < num_ir ; i++) {
202
for (j=0; j < ioff[nn] ; j++) {
203
eci1 += s->pmato2[j]*s->hmat[j];
204
eci2 += s->pmato2[j]*s->dpmat[j];
205
eci3 += s->pmato2[j]*s->dpmato[j];
210
term = 0.5*(eci1+0.5*eci2);
212
amax = term*term + hoff*hoff;
214
if(term < 0.0) amax = -(amax);
215
cn = (amax+term)/(2*amax);
217
sn = hoff/(cn*(amax+amax));
244
scf_info[opblk1].occ_num[opshl1] = ci1*ci1*2.0;
245
scf_info[opblk2].occ_num[opshl2] = ci2*ci2*2.0;
246
den = c1i-scf_info[opblk1].occ_num[opshl1];
247
c1[opblk1] = c1i/den;
248
c2[opblk1] = scf_info[opblk1].occ_num[opshl1]/den;
249
den = c1ii-scf_info[opblk2].occ_num[opshl2];
250
c1[opblk2] = c1ii/den;
251
c2[opblk2] = scf_info[opblk2].occ_num[opshl2]/den;
252
alpha1 = 1.0 - 2.0/scf_info[opblk1].occ_num[opshl1];
253
alpha2 = -1.0/(ci1*ci2);
254
alpha3 = 1.0 - 2.0/scf_info[opblk2].occ_num[opshl2];
256
cimax = MAX0(ci1,ci2);
257
cimin = MIN0(ci1,ci2);
258
cimax = 1.0/(cimax*cimax+dampsv);
259
if(fabs(cimin) >= 0.1) cimax = 1.0;
261
fprintf(outfile," ci coeffs %14.10f %14.10f\n",ci1,ci2);
265
/* form density matrix */
271
formg_two(iju,optest);
273
for (m=0; m < num_ir ; m++) {
275
if (nn = s->num_so) {
277
/* form fock matrix = h+g */
278
add_arr(s->hmat,s->gmat,s->fock_pac,ioff[nn]);
280
/* form fock_open = h+g-q */
282
for (i=0; i < ioff[nn] ; i++)
283
s->fock_open[i]=s->fock_pac[i]-s->gmato[i];
289
/* create new fock matrix in fock_eff */
290
if(!diisflg) diis(scr,fock_c,fock_ct,c1,c2,cimax,newci);
292
for (m=0; m < num_ir ; m++) {
296
/* transform fock_pac to mo basis */
297
tri_to_sq(s->fock_pac,fock_ct,nn);
298
/* mxmb(s->cmat,nn,1,fock_ct,1,nn,scr,1,nn,nn,nn,nn);
299
mxmb(scr,1,nn,s->cmat,1,nn,fock_c,1,nn,nn,nn,nn);*/
300
mmult(s->cmat,1,fock_ct,0,scr,0,num_mo,nn,nn,0);
301
mmult(scr,0,s->cmat,0,fock_c,0,num_mo,nn,num_mo,0);
303
/* transform fock_open to mo basis */
304
tri_to_sq(s->fock_open,fock_ct,nn);
305
/* mxmb(s->cmat,nn,1,fock_ct,1,nn,scr,1,nn,nn,nn,nn);
306
mxmb(scr,1,nn,s->cmat,1,nn,fock_o,1,nn,nn,nn,nn);*/
307
mmult(s->cmat,1,fock_ct,0,scr,0,num_mo,nn,nn,0);
308
mmult(scr,0,s->cmat,0,fock_o,0,num_mo,nn,num_mo,0);
310
/* form effective fock matrix in mo basis */
312
occ0 = s->occ_num[0];
313
for (i=ij=0; i < num_mo; i++) {
314
for (j=0; j <= i; j++,ij++) {
315
occi = s->occ_num[i];
316
occj = s->occ_num[j];
318
/* default: Guest & Saunders general form */
319
if(iter < itmax-1 && !converged && !fock_typ) {
321
s->fock_eff[ij] = fock_c[i][j];
324
cimax*(c1[m]*fock_c[i][j]-c2[m]*fock_o[i][j]);
327
s->fock_eff[ij] = cimax*fock_c[i][j];
329
s->fock_eff[ij] = cimax*fock_o[i][j];
333
/* Guest & Saunders' form for high spin */
334
else if(iter < itmax-1 && !converged && fock_typ == 1) {
335
if (occi == occj || occi)
336
s->fock_eff[ij] = c1[m]*fock_c[i][j]-c2[m]*fock_o[i][j];
337
else if (occj == 2.0) s->fock_eff[ij] = fock_c[i][j];
338
else s->fock_eff[ij] = fock_o[i][j];
341
/* test form (fo fo fo) */
342
else if(iter < itmax-1 && !converged && fock_typ == 2) {
343
if (occi == occj) s->fock_eff[ij] = fock_o[i][j];
345
s->fock_eff[ij] = c1[m]*fock_c[i][j]-c2[m]*fock_o[i][j];
347
s->fock_eff[ij] = fock_c[i][j];
348
else s->fock_eff[ij] = fock_o[i][j];
351
/* test form a*(fc fc fc) */
352
else if(iter < itmax-1 && !converged && fock_typ == 3) {
353
if (occi == occj) s->fock_eff[ij] = dampd*fock_c[i][j];
356
dampo*(c1[m]*fock_c[i][j]-c2[m]*fock_o[i][j]);
358
s->fock_eff[ij] = dampo*fock_c[i][j];
359
else s->fock_eff[ij] = dampo*fock_o[i][j];
362
/* test form a*(fo fo fo) */
363
else if(iter < itmax-1 && !converged && fock_typ == 4) {
364
if (occi == occj) s->fock_eff[ij] = dampd*fock_o[i][j];
367
dampo*(c1[m]*fock_c[i][j]-c2[m]*fock_o[i][j]);
369
s->fock_eff[ij] = dampo*fock_c[i][j];
370
else s->fock_eff[ij] = dampo*fock_o[i][j];
373
/* test form a*(2fc-fo 2fc-fo 2fc-fo) */
374
else if(iter < itmax-1 && !converged && fock_typ == 5) {
377
dampd*(c1[m]*fock_c[i][j]-c2[m]*fock_o[i][j]);
380
dampo*(c1[m]*fock_c[i][j]-c2[m]*fock_o[i][j]);
382
s->fock_eff[ij] = dampo*fock_c[i][j];
383
else s->fock_eff[ij] = dampo*fock_o[i][j];
386
/* form for converged wavefunction */
388
if (occi == 2.0) s->fock_eff[ij]=fock_c[i][j];
390
s->fock_eff[ij]=fock_o[i][j];
394
c1[m]*fock_c[i][j]-c2[m]*fock_o[i][j];
395
else s->fock_eff[ij]=fock_c[i][j];
400
if (occi == occ0 && occi) s->fock_eff[ij] -= lshift;
401
else if (occi) s->fock_eff[ij] -= 0.5*lshift;
408
for (m=0; m < num_ir ; m++) {
412
occ0 = s->occ_num[0];
414
rsp(num_mo,num_mo,ioff[num_mo],s->fock_eff,s->fock_evals,1,ctrans,tol);
416
/* mxmb(s->cmat,1,nn,ctrans,1,nn,scr,1,nn,nn,nn,nn);*/
417
mmult(s->cmat,0,ctrans,0,scr,0,nn,num_mo,num_mo,0);
419
for (i=0; i < num_mo; i++) {
420
occi = s->occ_num[i];
421
if (occi == occ0 && occi) s->fock_evals[i] += lshift;
422
else if (occi) s->fock_evals[i] += 0.5*lshift;
425
for(i=0; i < nn; i++)
426
for (j=0; j < num_mo; j++)
427
s->cmat[i][j] = scr[i][j];
432
free_matrix(scr,nsfmax);
433
free_matrix(fock_c,nsfmax);
434
free_matrix(fock_ct,nsfmax);
435
free_matrix(ctrans,nsfmax);
436
free_matrix(fock_o,nsfmax);
441
for(i=0; i < num_ir ; i++) {
444
free_block(s->ucmat);
451
}} // namespace psi::cscf