~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/bin/cscf/formg_direct.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-09-10 14:01:33 UTC
  • Revision ID: james.westby@ubuntu.com-20060910140133-ib2j86trekykfsfv
Tags: upstream-3.2.3
ImportĀ upstreamĀ versionĀ 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
static char *rcsid = "$Id: formg_direct.c,v 1.8 2002/12/06 15:50:32 crawdad Exp $";
 
2
 
 
3
#define EXTERN
 
4
#include <libpsio/psio.h>
 
5
#include "includes.h"
 
6
#include "common.h"
 
7
 
 
8
void formg_direct()
 
9
{
 
10
   double *gtmp;
 
11
   int stat;
 
12
   int i,j,k,jj,kk,l,off,joff,nn,max;      
 
13
   int ntri = ioff[nbasis];
 
14
   double den_percent;
 
15
 
 
16
   /*-----------------------------------
 
17
     Call CINTS to do all the dirty job
 
18
     Check if it ran fine
 
19
    -----------------------------------*/
 
20
   if(exitflag)
 
21
       exit(PSI_RETURN_FAILURE);
 
22
   
 
23
   stat = system("cints --fock");
 
24
   
 
25
   switch (stat) {
 
26
   case 0:
 
27
       /* everything is OK */
 
28
       break;
 
29
       
 
30
   default:
 
31
       /* Something went wrong */
 
32
       fprintf(outfile,"  formg_direct: System call to CINTS failed. Check to see if it's in your PATH\n");
 
33
       fprintf(stderr,"System call to CINTS failed. Check to see if it's in your PATH.\n");
 
34
       exit(PSI_RETURN_FAILURE);
 
35
   }
 
36
   
 
37
   gtmp = (double *) init_array(ntri);
 
38
 
 
39
   /*----------------------------------------------------
 
40
     Zero-out ERI-dependent portions of the Fock matrix
 
41
     if ERI accuracy has just been switched (see dmat.c)
 
42
    ----------------------------------------------------*/
 
43
   if(acc_switch) {
 
44
       if (uhf) {
 
45
           for(k=0; k < num_ir ; k++) {
 
46
               if(nn=scf_info[k].num_so) {
 
47
                   for(i=0; i < nn ; i++) {
 
48
                       for(j=0; j <= i ; j++) {
 
49
                           spin_info[0].scf_spin[k].gmat[ioff[i]+j] = 0.0;
 
50
                           spin_info[1].scf_spin[k].gmat[ioff[i]+j] = 0.0;
 
51
                       }
 
52
                   }
 
53
               }
 
54
           }
 
55
       }
 
56
       else if (iopen) {
 
57
           for(k=joff=0; k < num_ir ; k++) {
 
58
               if(nn=scf_info[k].num_so) {
 
59
                   for(i=0; i < nn ; i++) {
 
60
                       for(j=0; j <= i ; j++) {
 
61
                           scf_info[k].gmat[ioff[i]+j] = 0.0;
 
62
                           scf_info[k].gmato[ioff[i]+j] = 0.0;
 
63
                       }
 
64
                   }
 
65
               }
 
66
           }
 
67
       }
 
68
       else {
 
69
           for(i=0;i<num_ir;i++) {
 
70
               max = scf_info[i].num_so;
 
71
               for(j=0;j<max;j++) {
 
72
                   for(k=0;k<=j;k++) {
 
73
                       scf_info[i].gmat[ioff[j]+k] = 0.0;
 
74
                   }
 
75
               }
 
76
           }
 
77
       }
 
78
   }
 
79
   
 
80
   psio_open(itapDSCF, PSIO_OPEN_OLD);
 
81
   if (ksdft) {
 
82
     psio_read_entry(itapDSCF, "DFT XC-energy", 
 
83
                     (char *) &(exc), sizeof(double));
 
84
    psio_read_entry(itapDSCF, "DFT X-energy", 
 
85
                    (char *) &(exch_energy), sizeof(double));
 
86
    psio_read_entry(itapDSCF, "DFT C-energy", 
 
87
                    (char *) &(corr_energy), sizeof(double));
 
88
    psio_read_entry(itapDSCF, "DFT Den", 
 
89
                    (char *) &(den_trace), sizeof(double));
 
90
    
 
91
    /* Check for consistency of the numrical integration */
 
92
    
 
93
    den_percent = 100*fabs((double) nelec-den_trace)/(double) nelec;
 
94
    
 
95
    if(den_percent > 1E-3){
 
96
        fprintf(outfile,"\nWarning, Numerically Integrated Density Inaccurate");
 
97
        fprintf(outfile,"\nNum of Electrons = %d",nelec);
 
98
        fprintf(outfile,"\nNum from Trace   = %5.5lf",den_trace);
 
99
        fprintf(outfile,"\nAbsolute Error   = %%%5.5lf\n\n",den_percent);
 
100
    }
 
101
   }
 
102
   
 
103
   
 
104
   if (uhf) {
 
105
     psio_read_entry(itapDSCF, "Alpha JX G-matrix", (char *) gtmp, sizeof(double)*ntri);
 
106
     for(k=joff=0; k < num_ir ; k++) {
 
107
       if(nn=scf_info[k].num_so) {
 
108
         for(i=0; i < nn ; i++) {
 
109
           for(j=0; j <= i ; j++) {
 
110
             spin_info[0].scf_spin[k].gmat[ioff[i]+j] += gtmp[ioff[i+joff]+j+joff];
 
111
           }
 
112
         }
 
113
       }
 
114
       joff += nn;
 
115
     }
 
116
     
 
117
     psio_read_entry(itapDSCF, "Beta JX G-matrix", (char *) gtmp, sizeof(double)*ntri);
 
118
     for(k=joff=0; k < num_ir ; k++) {
 
119
       if(nn=scf_info[k].num_so) {
 
120
         for(i=0; i < nn ; i++) {
 
121
           for(j=0; j <= i ; j++) {
 
122
             spin_info[1].scf_spin[k].gmat[ioff[i]+j] += gtmp[ioff[i+joff]+j+joff];
 
123
           }
 
124
         }
 
125
       }
 
126
       joff += nn;
 
127
     }
 
128
 
 
129
     if (ksdft) {
 
130
         psio_read_entry(itapDSCF, "Alpha XC G-matrix", (char *) gtmp, sizeof(double)*ntri);
 
131
         for(k=joff=0; k < num_ir ; k++) {
 
132
             if(nn=scf_info[k].num_so) {
 
133
                 for(i=0; i < nn ; i++) {
 
134
                     for(j=0; j <= i ; j++) {
 
135
                         spin_info[0].scf_spin[k].xcmat[ioff[i]+j] = gtmp[ioff[i+joff]+j+joff];
 
136
                     }
 
137
                 }
 
138
             }
 
139
             joff += nn;
 
140
         }
 
141
         
 
142
         psio_read_entry(itapDSCF, "Beta XC G-matrix", (char *) gtmp, sizeof(double)*ntri);
 
143
         for(k=joff=0; k < num_ir ; k++) {
 
144
             if(nn=scf_info[k].num_so) {
 
145
                 for(i=0; i < nn ; i++) {
 
146
                     for(j=0; j <= i ; j++) {
 
147
                         spin_info[1].scf_spin[k].xcmat[ioff[i]+j] = gtmp[ioff[i+joff]+j+joff];
 
148
                     }
 
149
                 }
 
150
             }
 
151
             joff += nn;
 
152
         }
 
153
     }
 
154
   }
 
155
   else {
 
156
     psio_read_entry(itapDSCF, "Total JX G-matrix", (char *) gtmp, sizeof(double)*ntri);
 
157
     for(k=joff=0; k < num_ir ; k++) {
 
158
       if(nn=scf_info[k].num_so) {
 
159
         for(i=0; i < nn ; i++) {
 
160
           for(j=0; j <= i ; j++) {
 
161
             scf_info[k].gmat[ioff[i]+j] += gtmp[ioff[i+joff]+j+joff];
 
162
           }
 
163
         }
 
164
       }
 
165
       joff += nn;
 
166
     }
 
167
 
 
168
     if (ksdft) {
 
169
         psio_read_entry(itapDSCF, "Total XC G-matrix", (char *) gtmp, sizeof(double)*ntri);
 
170
         for(k=joff=0; k < num_ir ; k++) {
 
171
             if(nn=scf_info[k].num_so) {
 
172
                 for(i=0; i < nn ; i++) {
 
173
                     for(j=0; j <= i ; j++) {
 
174
                         scf_info[k].xcmat[ioff[i]+j] = gtmp[ioff[i+joff]+j+joff];
 
175
             }
 
176
                 }
 
177
             }
 
178
             joff += nn;
 
179
         }
 
180
     }
 
181
 
 
182
     if (iopen) {
 
183
       psio_read_entry(itapDSCF, "Open-shell JX G-matrix", (char *) gtmp, sizeof(double)*ntri);
 
184
       for(k=joff=0; k < num_ir ; k++) {
 
185
         if(nn=scf_info[k].num_so) {
 
186
           for(i=0; i < nn ; i++) {
 
187
             for(j=0; j <= i ; j++) {
 
188
               scf_info[k].gmato[ioff[i]+j] += gtmp[ioff[i+joff]+j+joff];
 
189
             }
 
190
           }
 
191
         }
 
192
         joff += nn;
 
193
       }
 
194
     }
 
195
   }
 
196
   psio_close(itapDSCF, 1);
 
197
   
 
198
   free(gtmp);
 
199
   return;
 
200
}
 
201