~ubuntu-branches/ubuntu/saucy/nwchem/saucy

« back to all changes in this revision

Viewing changes to .pc/09_backported_6.1.1_fixes.patch/src/nwdft/xc/xc_hcth.F

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2012-09-13 14:35:37 UTC
  • Revision ID: package-import@ubuntu.com-20120913143537-5gkt1l68rxrprgnl
Tags: 6.1-4
[ Michael Banck ]
* debian/patches/09_backported_6.1.1_fixes.patch: New patch, backports the
  source code changes of the nwchem-6.1.1 bugfix release:
  + PW: Fixed backspace issues on file I/O that caused I/O errors.
  + DFT: Removed dummy and bq centers from the Grimme dispersion
    corrections.
  + DFT: Fixed a race condition in the density fitting code.
  + DFT: Added a check for singularities in the HCTH functionals.
  + DFT: Fixed a problem with the DFT grids which caused strange behaviors
    if the number of cores is so large that some cores do not get any grid
    points.
  + HF&DFT: Fixed rolling back to distributed memory Fock-builder if not
    enough memory is available to use the replicated data one. Previously
    the code would crash trying to use non-existing GAs.
  + HF&DFT: Fixed clashes between MPI and GA communication when using OpenIB
    which enhances the stability.
  + MP2&DFT: On systems with limited I/O capabilities some quantities like
    2-electron integrals and DFT grids are now stored in memory rather than
    on disk.
  + CASSCF: Added ga_sync to fix race conditions that can cause the Davidson
    diagonalizer to fail.
  + CASSCF: Fixed a problem with the phase in the Lagrangian that caused
    problems with the gradient evaluation.
  + RAMAN: A number of problems with static polarizabilities were fixed.
  + Property: Fixed an issue with add_patch that caused unexpected results
    with dynamic polarizabilities.
  + DRDY: Removed system calls to copy files avoiding forking from NWChem
    processes which is relatively likely to fail due to the resources
    attached to such a process.
  + Input: Fixed some issues with GEOM LOAD that caused the selection of
    centers to fail in some cases.
  + Geometry: Dummy centers are no longer removed from a geometry so that
    constraints involving those centers remain valid.
  + Memory: All shared memory (global memory region) is now allocated at the
    start.

[ Daniel Leidert ]
* debian/control: Added X-Python-Version.
  (Build-Depends): Added python-dev. Use texlive to fix manual build.
  (Standards-Version): Bumped to recent 3.9.3.
* debian/nwchem.1: Added.
* debian/nwchem.doc-base: Ditto.
* debian/nwchem.lintian-overrides: Ditto.
* debian/nwchem.manpages: Ditto.
* debian/nwchem-data.lintian-overrides: Ditto.
* debian/rules: Added PYTHONVERSION, PYTHONHOME. Enable parallel building.
  (NWCHEM_MODULES): Build with python support (pnnl).
* debian/patches/02_makefile_flags.patch: Adjusted.
  - src/config/makefile.h: Fix linker flags building with python support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
      Subroutine xc_hcth(tol_rho, xfac, lxfac, nlxfac,
 
2
     ,                    cfac, lcfac, nlcfac,rho, delrho, 
 
3
     &                    Amat, Cmat, nq, ipol, Ex, Ec,  qwght,
 
4
     &                    ldew,func,funcname)     
 
5
c
 
6
c$Id: xc_hcth.F 20247 2011-04-28 18:58:49Z d3y133 $
 
7
c
 
8
      Implicit none
 
9
c
 
10
#include "dft2drv.fh"
 
11
c
 
12
      logical ldew ! [input]
 
13
      logical lcfac, nlcfac,  lxfac, nlxfac ! [input]
 
14
      double precision func(*) ![input/output]
 
15
      double precision cfac, xfac ![input]
 
16
      character*4 funcname ! functional name [input]
 
17
c
 
18
      integer ipol  ! no. of spin states [input]
 
19
      integer nq    ! no. of quadrature pts [input]
 
20
      double precision tol_rho! [input]!threshold on density
 
21
      double precision Ec ! Correlation energy [input/output] 
 
22
      double precision Ex ! Exchange    energy [input/output] 
 
23
      double precision rho(nq,ipol*(ipol+1)/2)! Charge Density [input] 
 
24
      double precision delrho(nq,3,ipol) ! Charge Density Gradient[input] 
 
25
      double precision qwght(nq) ! Quadrature Weights [input]
 
26
      double precision Amat(nq,ipol)  !Sampling Matrices for the XC [output]
 
27
      double precision Cmat(nq,*)!Potential & Energy [output]
 
28
c     
 
29
c References:
 
30
c    F.A.Hamprecht, A.J.Cohen, D.J.Tozer and N.C.Handy, 
 
31
c    J. Chem. Phys. 109, 6264-6271 (1998)
 
32
c    subroutine supplied by Fred Hamprecht fah@igc.phys.chem.ethz.ch
 
33
c
 
34
      integer n
 
35
      double precision gammaval
 
36
c to hcth
 
37
      double precision rhoa 
 
38
      double precision rhob 
 
39
      double precision za   
 
40
      double precision zb   
 
41
      double precision hE_x, hE_c 
 
42
      double precision dfdrax, dfdrac
 
43
      double precision dfdrbx, dfdrbc
 
44
      double precision dfdzac,dfdzax,dfdza
 
45
      double precision dfdzbc,dfdzbx,dfdzb
 
46
c
 
47
      if(ipol.eq.1) then
 
48
        do n=1,nq
 
49
          if(rho(n,1).gt.tol_rho) then 
 
50
            rhoa=0.d0
 
51
            rhoa=0.5d0*rho(n,1)
 
52
            rhob=0.d0
 
53
            rhob=rhoa
 
54
            za=0.d0
 
55
            gammaval=0.25d0*(delrho(n,1,1)*delrho(n,1,1) +
 
56
     &           delrho(n,2,1)*delrho(n,2,1) +
 
57
     &           delrho(n,3,1)*delrho(n,3,1))
 
58
            if(gammaval.gt.tol_rho)  za=sqrt(gammaval)
 
59
            zb=za
 
60
            call hcth(ipol,funcname,
 
61
     *           dfdrax,dfdrac, dfdzax,dfdzac, 
 
62
     *           dfdrbx,dfdrbc, dfdzbx,dfdzbc, 
 
63
     .           rhoa, rhob, 
 
64
     &           za, zb, hE_x, hE_c, tol_rho)
 
65
            if(ldew) func(n)=func(n)+hE_c*cfac+hE_x*xfac
 
66
            Ec=Ec+hE_c*qwght(n)*cfac
 
67
            Ex=Ex+hE_x*qwght(n)*xfac
 
68
            Amat(n,1) = Amat(n,1)+dfdrac*cfac+dfdrax*xfac
 
69
            dfdza=(dfdzac*cfac+dfdzax*xfac)*0.5d0 
 
70
            Cmat(n,D1_GAA) = Cmat(n,D1_GAA) + dfdza
 
71
          endif
 
72
        enddo
 
73
      else
 
74
        do n=1,nq
 
75
          if(rho(n,1).gt.tol_rho) then
 
76
          rhoa=rho(n,2)
 
77
          rhob=rho(n,3)
 
78
            za=0.d0
 
79
            gammaval=delrho(n,1,1)*delrho(n,1,1) +
 
80
     &           delrho(n,2,1)*delrho(n,2,1) +
 
81
     &           delrho(n,3,1)*delrho(n,3,1)
 
82
            if(gammaval.gt.tol_rho) za=sqrt(gammaval)
 
83
            zb=0.d0
 
84
            gammaval=delrho(n,1,2)*delrho(n,1,2) +
 
85
     &           delrho(n,2,2)*delrho(n,2,2) +
 
86
     &           delrho(n,3,2)*delrho(n,3,2) 
 
87
            if(gammaval.gt.tol_rho) zb=sqrt(gammaval)
 
88
            call hcth(ipol,funcname,
 
89
     *           dfdrax,dfdrac, dfdzax,dfdzac, 
 
90
     *           dfdrbx,dfdrbc, dfdzbx,dfdzbc, 
 
91
     .           rhoa, rhob, 
 
92
     &           za, zb, hE_x, hE_c, tol_rho)
 
93
            if(ldew) func(n)=func(n)+hE_c*cfac+hE_x*xfac 
 
94
            Ec=Ec+hE_c*qwght(n)*cfac
 
95
            Ex=Ex+hE_x*qwght(n)*xfac
 
96
            Amat(n,1) = Amat(n,1)+dfdrac*cfac+dfdrax*xfac
 
97
            Amat(n,2) = Amat(n,2)+dfdrbc*cfac+dfdrbx*xfac
 
98
            dfdza=dfdzac*cfac+dfdzax*xfac
 
99
            dfdzb=dfdzbc*cfac+dfdzbx*xfac
 
100
            Cmat(n,D1_GAA) = Cmat(n,D1_GAA) + dfdza*0.5d0
 
101
            Cmat(n,D1_GBB) = Cmat(n,D1_GBB) + dfdzb*0.5d0
 
102
          endif
 
103
        enddo
 
104
      endif
 
105
      return
 
106
      end
 
107
 
 
108
      Subroutine xc_hcth_d2(tol_rho, xfac, lxfac, nlxfac,
 
109
     &                      cfac, lcfac, nlcfac,rho, delrho,
 
110
     &                      Amat, Amat2, Cmat, Cmat2, nq, ipol,
 
111
     &                      Ex, Ec,  qwght, ldew,func,funcname)
 
112
c
 
113
c$Id: xc_hcth.F 20247 2011-04-28 18:58:49Z d3y133 $
 
114
c
 
115
      Implicit none
 
116
#include "errquit.fh"
 
117
c
 
118
#include "dft2drv.fh"
 
119
#include "mafdecls.fh"
 
120
c
 
121
      logical ldew ! [input]
 
122
      logical lcfac, nlcfac,  lxfac, nlxfac ! [input]
 
123
      double precision func(*) ![input/output]
 
124
      double precision cfac, xfac ![input]
 
125
      character*4 funcname ! functional name [input]
 
126
c
 
127
      integer ipol  ! no. of spin states [input]
 
128
      integer nq    ! no. of quadrature pts [input]
 
129
      double precision tol_rho! [input]!threshold on density
 
130
      double precision Ec ! Correlation energy [input/output] 
 
131
      double precision Ex ! Exchange    energy [input/output] 
 
132
      double precision rho(nq,ipol*(ipol+1)/2)! Charge Density [input] 
 
133
      double precision delrho(nq,3,ipol) ! Charge Density Gradient[input] 
 
134
      double precision qwght(nq) ! Quadrature Weights [input]
 
135
      double precision Amat(nq,ipol)  !Sampling Matrices for the XC [output]
 
136
      double precision Cmat(nq,*)!Potential & Energy [output]
 
137
      double precision Amat2(nq,NCOL_AMAT2) ! XC functional seconds [output]
 
138
      double precision Cmat2(nq,NCOL_CMAT2) ! XC functional seconds [output]
 
139
c
 
140
c     Local variables
 
141
c
 
142
      integer l_storage, i_prho, i_pdelrho, i_pAmat, i_pCmat, i_pfunc,
 
143
     &     i_qwght_copy, npert
 
144
      double precision ExDum, EcDum
 
145
c
 
146
c     First get the functional and first derivative values
 
147
c
 
148
      call xc_hcth(tol_rho, xfac, lxfac, nlxfac, cfac, lcfac, nlcfac,
 
149
     &     rho, delrho, Amat, Cmat, nq, ipol, Ex, Ec, qwght, ldew, func,
 
150
     &     funcname)
 
151
c
 
152
c     Compute the second derivative values by finite difference
 
153
c
 
154
      call xc_setup_fd(tol_rho, rho, delrho, qwght, nq, ipol, .true.,
 
155
     &     l_storage, i_prho, i_pdelrho, i_pAmat, i_pCmat, i_pfunc,
 
156
     &     i_qwght_copy)
 
157
c
 
158
c     Compute functional first derivatives at perturbed density parameter
 
159
c     values - note that the number of points is nq*2*npert and that the
 
160
c     routine is called as unrestricted
 
161
c
 
162
      npert = 5
 
163
      call xc_hcth(tol_rho, xfac, lxfac, nlxfac, cfac, lcfac, nlcfac,
 
164
     &     dbl_mb(i_prho), dbl_mb(i_pdelrho), dbl_mb(i_pAmat),
 
165
     &     dbl_mb(i_pCmat), nq*2*npert, ipol, ExDum, EcDum,
 
166
     &     dbl_mb(i_qwght_copy), ldew, dbl_mb(i_pfunc), funcname)
 
167
      call xc_make_fd(Amat2, Cmat2, nq, .true., dbl_mb(i_pAmat),
 
168
     &     dbl_mb(i_pCmat))
 
169
c
 
170
c     Free temporary storage allocated by xc_setup_fd
 
171
c
 
172
      if (.not.ma_free_heap(l_storage))
 
173
     &     call errquit('xc_hcth_d2: cannot pop stack',0, MA_ERR)
 
174
c
 
175
      return
 
176
      end
 
177
 
 
178
      SUBROUTINE hcth(ipol,functional,
 
179
     *     dfdrax,dfdrac, dfdzax,dfdzac, 
 
180
     *     dfdrbx,dfdrbc, dfdzbx,dfdzbc, 
 
181
     1     rhoa, rhob, za, zb, hE_x, hE_c, 
 
182
     2     tol_rho)
 
183
 
 
184
c    subroutine supplied by Fred Hamprecht fah@igc.phys.chem.ethz.ch
 
185
C    SUPPLIED TO THE ROUTINE:
 
186
C    
 
187
C    rhoa   -- value of rhoalpha at a given grid point 
 
188
C    rhob   -- value of rhobeta at a given grid point
 
189
C    za     -- zeta_alpha, as defined in the TH1 paper (JCP 108 2545), 
 
190
C              that is mod(grad(rhoalpha)), a scalar quantity.
 
191
C    zb     -- mod(grad(rhobeta)) 
 
192
C    zab    -- zeta_{alpha beta} as defined in the TH1 paper, that is
 
193
C              grad(rhoalpha).grad(rhobeta) 
 
194
C    energy -- a boolean variable deciding whether to compute the energy 
 
195
C              contribution at the point in space (true) or the
 
196
C              appropriate derivatives (false) needed for the KS matrix
 
197
C              _and_ the energy contribution.
 
198
 
 
199
C    RETURNED FROM THE ROUTINE:
 
200
 
 
201
C    hE_x --   the contribution to the energy at this point in space.
 
202
C    hE_c --   the contribution to the energy at this point in space.
 
203
C    dfdra  -- partial functional derivative of F_xc with respect to 
 
204
C              rhoalpha
 
205
C    dfdrb  -- partial functional derivative of F_xc with respect to   
 
206
C              rhobeta
 
207
C    dfdza  -- partial functional derivative of F_xc with respect to   
 
208
C              mod(grad(rhoalpha)), divided by za !!!!!!!!!
 
209
C              i.e.  1    d f 
 
210
C                   --- * ---- 
 
211
C                   za    d za
 
212
C              This is a consequence of the Cadpac implementation
 
213
C    dfdzb  -- partial functional derivative of F_xc with respect to   
 
214
C              mod(grad(rhobeta)), divided by zb !!!!!!!!!
 
215
 
 
216
 
 
217
      implicit none
 
218
#include "errquit.fh"
 
219
      
 
220
      double precision rhoa ![input]
 
221
      double precision rhob ![input]
 
222
      double precision za   ![input]
 
223
      double precision zb   ![input]
 
224
      integer ipol ![input]
 
225
      double precision hE_x ![output]
 
226
      double precision hE_c ![output]
 
227
      double precision tol_rho ![input]
 
228
      double precision dfdrax    ![output]
 
229
      double precision dfdrac    ![output]
 
230
      double precision dfdrbx    ![output]
 
231
      double precision dfdrbc    ![output]
 
232
      double precision dfdzax    ![output]
 
233
      double precision dfdzac    ![output]
 
234
      double precision dfdzbx    ![output]
 
235
      double precision dfdzbc    ![output]
 
236
      character*4 functional
 
237
      double precision pi
 
238
      PARAMETER (PI=3.1415926535898D0)
 
239
 
 
240
      integer limpow,n
 
241
      PARAMETER(limpow = 4)
 
242
Cfah limpow is equivalent to "m" in the Becke V paper, that is, the greatest 
 
243
Cfah power of u appearing in the power expansion. 
 
244
Cfah The "Becke V" paper is: 
 
245
Cfah Becke A. D.  Density-functional thermochemistry. V.
 
246
Cfah Systematic optimization of exchange-correlation functionals, 
 
247
Cfah J. Chem. Phys., 1997, 107, 8554-8560
 
248
c
 
249
c     variables passed to hcderiv
 
250
c
 
251
      integer numfunc,nofunc,max_pow_u
 
252
      parameter(numfunc=14)
 
253
      double precision sol((limpow+1)*3), F((limpow+1)*3,4), 
 
254
C     &          FF((limpow+1)*3,5,4),
 
255
     &          F_xc((limpow+1)*3)
 
256
 
 
257
Cfah sol -- contains the coefficients of the terms in F_xc
 
258
Cfah        convention: sol(1) = c_{x alpha, 0}, c_{x beta, 0}
 
259
Cfah                    sol(2) = c_{c alpha alpha, 0}, c_{c beta beta, 0} 
 
260
Cfah                    sol(3) = c_{c alpha beta, 0} 
 
261
Cfah                    sol(4) = c_{x alpha, 1}, c_{x beta, 1}
 
262
Cfah                    sol(5) = c_{c alpha alpha, 1}, c_{c beta beta, 1} 
 
263
Cfah                    sol(6) = c_{c alpha beta, 1} 
 
264
Cfah                           
 
265
Cfah                           etc.
 
266
Cfah 
 
267
Cfah f(5) -- contains the partial first functional derivatives of F_xc with 
 
268
Cfah respect to 
 
269
Cfah the four quantities (IN THIS ORDER): ra, rb, za, zb
 
270
Cfah 
 
271
Cfah ff(5,5) contains the second derivatives with
 
272
Cfah respect to the same five quantities
 
273
 
 
274
Cfah F_xa -- contains the alpha exchange bit containing the various powers 
 
275
Cfah         of u_{x alpha} (eq. (18) of Becke V paper) 
 
276
Cfah F_xb --              beta       
 
277
Cfah            u_{x beta} 
 
278
Cfah F_caa -- contains the alpha parallel spin correlation bit with the powers
 
279
Cfah          of u_{c alpha alpha} 
 
280
Cfah F_cbb --              beta 
 
281
Cfah             u_{c beta beta} 
 
282
Cfah F_cab -- contains the anti-parallel spin correlation bit with the powers 
 
283
Cfah          of u_{c alpha beta} 
 
284
 
 
285
Cfah these transformed variables u will be defined and given short-cut names 
 
286
Cfah below. 
 
287
      double precision coeffs(3*(limpow+1),numfunc)
 
288
      character*4 funcnam(numfunc)
 
289
      integer maxpow(numfunc)
 
290
      data maxpow  /     2,   2 ,      2,    4,      4,    4,     4,
 
291
     ,              2 ,    4 ,    4    ,   2  ,  4  ,  4 ,        2/
 
292
 
 
293
      data funcnam/'b970','b980','b971','hcth','hcta','h120','h147',
 
294
     ,             'b97g','h407','hp14','b972','407p','b973','b97d'/
 
295
C               B97        B98   B97-1          HCTH        HCTH-A
 
296
C m max          2,            2,            4,           4,
 
297
Cc X s,0
 
298
      data (coeffs(1,n),n=1,numfunc)/
 
299
     /     +0.80940d+00,0.790194d0, +0.789518d+00,+0.109320d+01,
 
300
     ,     +0.109878d+01,1.09163d0,  1.09025d0, 1.1068d0,   1.08184d0,
 
301
     ,     +0.103161d+01,+0.827642D+00,+1.08018D0,+7.334648D-01,
 
302
     ,     +1.086620d+00/
 
303
 
 
304
c C ss,0 
 
305
      data (coeffs(2,n),n=1,numfunc)/
 
306
     ,     +0.17370d+00,-0.120163d0,+0.820011d-01,+0.222601d+00,
 
307
     ,     +0.136823d-01, 0.48951d0,  0.56258d0, 0.4883d0,  1.18777d0,
 
308
     ,     +0.282414d+01,+0.585808D+00,+0.80302D0,+5.623649D-01,
 
309
     ,     +0.22340d+00/
 
310
c C ab,0 
 
311
      data (coeffs(3,n),n=1,numfunc)/
 
312
     ,     +0.94540d+00,0.934715d0,+0.955689d+00,+0.729974d+00,
 
313
     ,     +0.836897d+00,0.51473d0,  0.54235d0,  0.7961d0,  0.58908d0,
 
314
     ,     +0.821827d-01,+0.999849D+00,+0.73604D0,+1.133830D+00,
 
315
     ,     +0.690410d+00/
 
316
c X s,1 
 
317
      data (coeffs(4,n),n=1,numfunc)/
 
318
     ,     +0.50730d+00,0.400271d0,+0.573805d+00,-0.744056d+00,
 
319
     ,     -0.251173d+01,-0.74720d0, -0.79920d0, -0.8765d0, -0.5183d0,
 
320
     ,     -0.360781d+00,+0.478400D-01,-0.4117D0,+2.925270D-01,
 
321
     ,     -0.521270d+00/
 
322
c C ss,1 
 
323
      data (coeffs(5,n),n=1,numfunc)/
 
324
     ,     +0.23487d+01,2.82332d0,+0.271681d+01,-0.338622d-01,
 
325
     ,     +0.268920d+00,-0.26070d0, -0.01710d0, -2.117d0, -2.4029d0,
 
326
     ,     +0.318843d-01,-0.691682D+00,-1.0479D0,-1.322980D+00,
 
327
     ,     -1.562080d+00/
 
328
c C ab,1 
 
329
      data (coeffs(6,n),n=1,numfunc)/
 
330
     ,     +0.74710d+00,1.14105d0,+0.788552d+00,+0.335287d+01,
 
331
     ,     +0.172051d+01,6.92980d0,  7.01460d0, 5.7060d0,  4.4237d0,
 
332
     ,     +0.456466d+01,+0.140626D+01,+3.0270D0,-2.811967D+00,
 
333
     ,     +6.302700d+00/
 
334
c X s,2 
 
335
      data (coeffs(7,n),n=1,numfunc)/
 
336
     ,     +0.74810d+00,0.832857d0,+0.660975d+00,+0.559920d+01,
 
337
     ,     +0.156233d-01,5.07830d0,  5.57210d0, 4.2639d0,   3.4256d0,
 
338
     ,     +0.351994d+01,+0.176125D+01,+2.4368D0,+3.338789D+00,
 
339
     ,     +3.254290d+00/
 
340
c C ss,2
 
341
      data (coeffs(8,n),n=1,numfunc)/
 
342
     ,     -0.24868d+01,-2.59412d0,-0.287103d+01,-0.125170d-01,
 
343
     ,     -0.550769d+00,0.43290d0, -1.30640d0, 2.3235d0,   5.6174d0,
 
344
     ,     -0.178512d+01,+0.394796D+00,+4.9807D0,+6.359191D+00,
 
345
     ,     +1.942930d+00/
 
346
c C ab,2
 
347
      data (coeffs(9,n),n=1,numfunc)/
 
348
     ,     -0.45961d+01,-5.33398d0,-0.547869d+01,-0.115430d+02,
 
349
     ,     -0.278498d+01,-24.7070d0, -28.3820d0,-14.9820d0,-19.222d0,
 
350
     ,     -0.135529d+02,-0.744060D+01,-10.075D0,+7.431302D+00,
 
351
     ,     -14.97120d+00/
 
352
c X s,3 
 
353
      data (coeffs(10,n),n=1,numfunc)/
 
354
     ,      0.0000000d0,0.0d000000, 0.00000000d0,-0.678549d+01,
 
355
     ,     0.00000000d0,-4.10750d0, -5.86760d0 ,0d0       , -2.6290d0,
 
356
     ,     -0.495944d+01,0.d0000000000,+1.3890D0,-1.051158D+01,
 
357
     ,      0.0000000d0/
 
358
c C ss,3
 
359
      data (coeffs(11,n),n=1,numfunc)/
 
360
     ,      0.0000000d0,0.0d000000, 0.00000000d0,-0.802496d+00,
 
361
     ,     +0.103947d+01,-1.99250d0,  1.05750d0,0d0       , -9.1792d0,
 
362
     ,     +0.239795d+01,0.d0000000000,-12.890D0,-7.464002D+00,
 
363
     ,      0.0000000d0/
 
364
c C ab,3
 
365
      data (coeffs(12,n),n=1,numfunc)/
 
366
     ,      0.0000000d0,0.0d000000, 0.00000000d0,+0.808564d+01,
 
367
     ,     -0.457504d+01, 23.1100d0,  35.0330d0,0d0       , 42.572d0,
 
368
     ,     +0.133820d+02,0.000000d0,+20.611D0,-1.969342D+00,
 
369
     ,      0.0000000d0/
 
370
c X s,4 
 
371
      data (coeffs(13,n),n=1,numfunc)/
 
372
     ,      0.0000000d0,0.0d000000, 0.00000000d0,+0.449357d+01,
 
373
     ,     0.00000000d0, 1.17170d0,  3.04540d0, 0d0       , 2.2886d0,
 
374
     ,     +0.241165d+01,0.000000d0,-1.3529D0,+1.060907D+01,
 
375
     ,      0.0000000d0/
 
376
c C ss,4
 
377
      data (coeffs(14,n),n=1,numfunc)/
 
378
     ,      0.0000000d0,0.0d000000, 0.00000000d0,+0.155396d+01,
 
379
     ,     0.00000000d0, 2.48530d0,  0.88540d0, 0d0       , 6.2480d0,
 
380
     ,     -0.876909d+00,0.000000d0,9.6446D0,+1.827082D+00,
 
381
     ,      0.0000000d0/
 
382
c C ab,4
 
383
      data (coeffs(15,n),n=1,numfunc)/
 
384
     ,      0.0000000d0,0.0d000000, 0.00000000d0,-0.447857d+01,
 
385
     ,     0.00000000d0,-11.3230d0, -20.4280d0, 0d0, -42.005d0,
 
386
     ,     -0.317493d+01,0.000000d0,-29.418D0,-1.174423D+01,
 
387
     ,      0.0000000d0/
 
388
c
 
389
c X +0.1! coeffs for HF exchange
 
390
c
 
391
C     ,     +0.19430d+00,+0.210000d+00, 0.00000000d0, 0.00000000d0/
 
392
 
 
393
C     Initialise
 
394
 
 
395
      dfdrac = 0.D0
 
396
      dfdrax = 0.D0
 
397
      dfdrbc = 0.D0
 
398
      dfdrbx = 0.D0
 
399
      dfdzac = 0.D0
 
400
      dfdzax = 0.D0
 
401
      dfdzbc = 0.D0
 
402
      dfdzbx = 0.D0
 
403
      hE_c = 0.D0
 
404
      hE_x = 0.D0
 
405
 
 
406
      IF (rhoa .LT. tol_rho.and.rhob.lt.tol_rho) RETURN
 
407
Cfah numerical cutoff: if the density is too low, its contribution is 
 
408
Cfah neglectable. 
 
409
      nofunc = -1               ! take care of compiler warnings
 
410
      do n=1,numfunc
 
411
        if(functional.eq.funcnam(n)) nofunc=n
 
412
      enddo
 
413
      if(nofunc.eq.-1) call errquit('xchcth: cant pair funcname ',0,
 
414
     &       UNKNOWN_ERR)
 
415
      max_pow_u=maxpow(nofunc)
 
416
      do n=1,3*(limpow+1)
 
417
        sol(n)=coeffs(n,nofunc)
 
418
      enddo
 
419
 
 
420
C please refer to these coeffs as THCH1/iterate-e750-g500-v1-m4-n4
 
421
 
 
422
c      sol( 1) =     0.109320D+01
 
423
c      sol( 2) =     0.222601D+00
 
424
c      sol( 3) =     0.729974D+00
 
425
c      sol( 4) =    -0.744056D+00
 
426
c      sol( 5) =    -0.338622D-01
 
427
c      sol( 6) =     0.335287D+01
 
428
c      sol( 7) =     0.559920D+01
 
429
c      sol( 8) =    -0.125170D-01
 
430
c      sol( 9) =    -0.115430D+02
 
431
c      sol(10) =    -0.678549D+01
 
432
c      sol(11) =    -0.802496D+00
 
433
c      sol(12) =     0.808564D+01
 
434
c      sol(13) =     0.449357D+01
 
435
c      sol(14) =     0.155396D+01
 
436
c      sol(15) =    -0.447857D+01
 
437
      
 
438
      CALL hcderiv(max_pow_u,ipol,
 
439
     &     F,
 
440
CFF,
 
441
     &     F_xc,
 
442
     &     rhoa,rhob,za,zb,
 
443
     &     sol,tol_rho)
 
444
 
 
445
c     if(ipol.eq.2) then
 
446
c       DO n = 1, (max_pow_u+1)*3 
 
447
c         dfdra = dfdra + F(n,1) 
 
448
c         dfdrb = dfdrb + F(n,2) 
 
449
c         if(za.gt.tol_rho) dfdza = dfdza + F(n,3) / za
 
450
c         if(zb.gt.tol_rho) dfdzb = dfdzb + F(n,4) / zb  
 
451
c       ENDDO
 
452
c     else
 
453
c        DO n = 1, (max_pow_u+1)*3 
 
454
c          dfdra = dfdra + F(n,1) 
 
455
c        enddo
 
456
c        if(za.gt.tol_rho) then
 
457
c          DO n = 1, (max_pow_u+1)*3 
 
458
c            dfdza = dfdza + F(n,3) / za
 
459
c          enddo
 
460
c        endif
 
461
c     endif
 
462
Cfah big thanks to NCH: cadpac requires df/(za * dza), NOT 
 
463
Cfah                                    df/dza 
 
464
      DO n = 0, max_pow_u 
 
465
        hE_x = hE_x + F_xc (n*3 + 1) 
 
466
        hE_c = hE_c + F_xc (n*3 + 2) + F_xc (n*3 + 3)
 
467
        dfdrax = dfdrax + F(n*3+1,1) 
 
468
        dfdrac = dfdrac + F(n*3+2,1) + F(n*3+3,1) 
 
469
        if(za.gt.tol_rho) then
 
470
            dfdzax = dfdzax + F(n*3+1,3) / za
 
471
            dfdzac = dfdzac + (F(n*3+2,3)+F(n*3+3,3)) / za
 
472
        endif
 
473
      if(ipol.eq.2) then
 
474
        dfdrbx = dfdrbx + F(n*3+1,2) 
 
475
        dfdrbc = dfdrbc + F(n*3+2,2) + F(n*3+3,2) 
 
476
        if(zb.gt.tol_rho) then
 
477
            dfdzbx = dfdzbx + F(n*3+1,4) / zb
 
478
            dfdzbc = dfdzbc + (F(n*3+2,4)+F(n*3+3,4)) / zb
 
479
        endif
 
480
      endif
 
481
      ENDDO
 
482
      RETURN
 
483
      END
 
484
      SUBROUTINE hcderiv(max_pow_u,ipol,
 
485
     &     F,
 
486
CFF, 
 
487
     &     F_xc,
 
488
     &             rhoa,rhob,za,zb,
 
489
     &             sol,tol_rho)
 
490
 
 
491
c    subroutine supplied by Fred Hamprecht fah@igc.phys.chem.ethz.ch
 
492
      implicit none
 
493
      INTEGER max_pow_u,ipol
 
494
      integer limpow
 
495
      parameter (limpow=4)
 
496
      double precision f_xc((limpow + 1)*3)
 
497
      double precision f((limpow+1)*3,4)
 
498
C, ff((limpow+1)*3,5,4)
 
499
      double precision rhoa, rhob, za, zb,tol_rho
 
500
 
 
501
Cfah  COMMON/special/h_atom
 
502
Cfah  LOGICAL h_atom
 
503
      DOUBLE PRECISION sol((limpow+1)*3)
 
504
    
 
505
      
 
506
      DOUBLE PRECISION dF_xa(4)
 
507
      DOUBLE PRECISION dF_xb(4)
 
508
      DOUBLE PRECISION dF_caa(4)
 
509
      DOUBLE PRECISION dF_cbb(4)
 
510
      DOUBLE PRECISION dF_cab(4)
 
511
Cfah these are the first derivatives of the terms of F_xc with respect to 
 
512
Cfah the 4 quantities. the index
 
513
Cfah runs over the particular partial derivatives of each term.  
 
514
Cfah More explicitly: these are the partial functional derivatives of 
 
515
Cfah F_XXX with respect to rhoa, rhob, za and zb. 
 
516
 
 
517
c      DOUBLE PRECISION d2F_xa(4,4)
 
518
c      DOUBLE PRECISION d2F_xb(4,4)
 
519
c      DOUBLE PRECISION d2F_caa(4,4)
 
520
c      DOUBLE PRECISION d2F_cbb(4,4)
 
521
c      DOUBLE PRECISION d2F_cab(4,4)
 
522
 
 
523
Cfah these are the first derivatives of the different transformed variables 
 
524
Cfah u with respect to rhoa, rhob, za and zb. These different derivatives 
 
525
Cfah with respect to these 4 quantities named above are stored in these 
 
526
Cfah arrays.
 
527
 
 
528
      DOUBLE PRECISION Pi 
 
529
      PARAMETER (Pi = 3.1415926535898D0)
 
530
      double precision rho
 
531
      DOUBLE PRECISION s_a2, s_b2, s_avg2, u_caa, u_cbb, u_cab
 
532
      DOUBLE PRECISION du_caa_by_drhoa, du_caa_by_dza, du_cbb_by_drhob 
 
533
      DOUBLE PRECISION du_cbb_by_dzb, du_cab_by_drhoa, du_cab_by_drhob 
 
534
      DOUBLE PRECISION du_cab_by_dza, du_cab_by_dzb
 
535
C, du_caa_by_drhoa_dza 
 
536
C      DOUBLE PRECISION du_caa_by_dza_dza, du_cbb_by_dzb_dzb
 
537
C      DOUBLE PRECISION du_cbb_by_drhob_dzb, du_cab_by_drhoa_dza 
 
538
C      DOUBLE PRECISION du_cab_by_drhoa_dzb, du_cab_by_drhob_dza 
 
539
C      DOUBLE PRECISION du_cab_by_drhob_dzb, du_cab_by_dza_dza, 
 
540
C     ,du_cab_by_dza_dzb 
 
541
C      DOUBLE PRECISION du_cab_by_dzb_dzb 
 
542
      DOUBLE PRECISION rsa, rsa12, rsa32, rsa21, rsb, 
 
543
     ,rsb12, rsb32, rsb21 
 
544
      DOUBLE PRECISION rsab, rsab12, rsab32, rsab21 
 
545
      DOUBLE PRECISION drsa_by_drhoa, drsb_by_drhob, drsab_by_drhoa
 
546
      DOUBLE PRECISION drsab_by_drhob 
 
547
      DOUBLE PRECISION zeta, dzeta_by_drhoa, dzeta_by_drhob 
 
548
      DOUBLE PRECISION fzeta, dfzeta_by_dzeta, 
 
549
     ,     e_crsa1, e_crsb1
 
550
      DOUBLE PRECISION e_crsab1, e_crsab0, a_crsab 
 
551
      DOUBLE PRECISION e_crsabzeta, de_crsa1_by_drsa, de_crsb1_by_drsb 
 
552
      DOUBLE PRECISION da_crsab_by_drsab, de_crsab0_by_drsab 
 
553
      DOUBLE PRECISION de_crsab1_by_drsab, de_crsabzeta_by_drsab 
 
554
      DOUBLE PRECISION de_crsabzeta_by_dzeta, e_caa, e_cbb, e_cab, 
 
555
     & de_caa_by_drhoa, de_cbb_by_drhob, de_cab_by_drhoa, 
 
556
     & de_cab_by_drhob,
 
557
     & c_naa, c_nbb, c_nab
 
558
      DOUBLE PRECISION F_xs,F_xs0 ! this is a function which is called. 
 
559
      DOUBLE PRECISION dF_xs_by_drhos, dF_xs_by_dzs,
 
560
     ,dF_xs_by_drhos0,dF_xs_by_drhos1,  dF_xs_by_dzs1
 
561
      INTEGER i, j,  n
 
562
      integer n1
 
563
      double precision x1,x2,x3,x4
 
564
      double precision e_crs1
 
565
      double precision drsbydrh
 
566
      double precision decrsdrs
 
567
      double precision eps
 
568
      parameter (eps=1d-19)
 
569
C
 
570
C     F_xs computes HCTH contribution to exchange Energy
 
571
C     using Dirac functional as LDA part
 
572
C     usage of F_xs
 
573
C     F_xs(n, sol(), rhoa, za)
 
574
C
 
575
      F_xs(n1, x1, x2, x3) =
 
576
     = (-3.D0*x1*(3.D0/Pi)**(1.D0/3.D0)*x2**(4.D0/3.D0)*
 
577
     -     ((0.004D0*x3**2.D0)/(0.004D0*x3**2.D0 +
 
578
     -     x2**(8.D0/3.D0)))**n1)/(2.D0*2.D0**(2.D0/3.D0))
 
579
      F_xs0( x1, x2, x3) =
 
580
     = (-3.D0*x1*(3.D0/Pi)**(1.D0/3.D0)*x2**(4.D0/3.D0)
 
581
     -     )/(2.D0*2.D0**(2.D0/3.D0))
 
582
C
 
583
C     dF_xs_by_drhos computes dE_x/drho derivative
 
584
Cfah  computes the derivative of the term with u^n of the exchange part of
 
585
Cfah  F_xc with respect to rho of the same spin.
 
586
Cfah  n     -- the power of u involved in this term
 
587
Cfah  c_xs  -- the coefficient c_xs(n) of the term of spin s with the
 
588
Cfah           power n of u; is NOT passed over as an array.
 
589
Cfah  rhos -- rhosigma, that is, either rhoalpha or rhobeta
 
590
Cfah  zs    -- mod(grad(rhosigma)), again for alpha or beta
 
591
C     usage dF_xs_by_drhos(n, c_xs, rhos, zs)
 
592
C
 
593
       dF_xs_by_drhos(n1, x1, x2, x3) =  -(x1*(6.D0/Pi)**
 
594
     *     (1.D0/3.D0)*x2**(1.D0/3.D0)*((0.004D0*x3*x3)/
 
595
     /     (x2**(8.D0/3.D0)+0.004D0*x3*x3))**n1)+
 
596
     +     (x1*0.008D0*n1*(6.D0/Pi)**(1.D0/3.D0)*
 
597
     *     x2**3.D0*x3*x3*((0.004D0*x3*x3)/
 
598
     /     (x2**(8.D0/3.D0)+0.004D0*x3*x3))**(-1 + n1))/
 
599
     /     (x2**(8.D0/3.D0)+0.004D0*x3*x3)**2
 
600
       dF_xs_by_drhos0(x1, x2, x3) =  -(x1*(6.D0/Pi)**
 
601
     *     (1.D0/3.D0)*x2**(1.D0/3.D0))
 
602
       dF_xs_by_drhos1(x1, x2, x3) =  -(x1*(6.D0/Pi)**
 
603
     *     (1.D0/3.D0)*x2**(1.D0/3.D0)*((0.004D0*x3*x3)/
 
604
     /     (x2**(8.D0/3.D0)+0.004D0*x3*x3)))+
 
605
     +     (x1*0.008D0*(6.D0/Pi)**(1.D0/3.D0)*
 
606
     *     x2**3.D0*x3*x3)/
 
607
     /     (x2**(8.D0/3.D0)+0.004D0*x3*x3)**2
 
608
C
 
609
C     F_xc with respect to zs
 
610
Cfah  see above (function dF_xs_by_drhos) for definition of the
 
611
Cfah  other variables
 
612
C     usage  dF_xs_by_dzs (n, c_xs, rhos, zs)
 
613
c
 
614
      dF_xs_by_dzs(n1, x1, x2, x3) = 
 
615
     =      (-3.d0*x1*n1*(3.D0/Pi)**(1.D0/3.D0)*
 
616
     *     x2**(4.D0/3.D0)*((0.004D0*x3*x3)/
 
617
     /     (x2**(8.D0/3.D0)+ 0.004D0*x3*x3))**(-1+n1)*
 
618
     *     ((-0.000032D0*x3*x3*x3)/(x2**(8.D0/3.D0)+
 
619
     +     0.004D0*x3*x3)**2+(0.008D0*x3)/
 
620
     /     (x2**(8.D0/3.D0)+0.004D0*x3*x3)))/
 
621
     /     (2.D0**(5.D0/3.D0))
 
622
      dF_xs_by_dzs1(x1, x2, x3) = 
 
623
     =      (-3.d0*x1*(3.D0/Pi)**(1.D0/3.D0)*
 
624
     *     x2**(4.D0/3.D0)*
 
625
     *     ((-0.000032D0*x3*x3*x3)/(x2**(8.D0/3.D0)+
 
626
     +     0.004D0*x3*x3)**2+(0.008D0*x3)/
 
627
     /     (x2**(8.D0/3.D0)+0.004D0*x3*x3)))/
 
628
     /     (2.D0**(5.D0/3.D0))
 
629
c      dF_xs_by_dzs0(x1, x2, x3) = 0d0
 
630
c
 
631
c     usage
 
632
c     e_crsa1 = e_crs1(rsa12,rsa,rsa32,rsa21)
 
633
c
 
634
      e_crs1(x1,x2,x3,x4) = -0.03108999999999999d0*
 
635
     *  dlog(1.d0 + 32.16468317787069d0/
 
636
     /     (14.1189d0*x1+6.1977d0*x2 + 3.3662d0*x3 +
 
637
     +     0.6251699999999999d0*x4))*(1.d0 + 0.20548d0*x2)
 
638
      drsbydrh(x1) = -((1.d0/x1)**(4.D0/3.D0)/
 
639
     -    (6.d0**(2.D0/3.D0)*Pi**(1.D0/3.D0)))
 
640
c     usage decrsdrs(rsa,rsa12,rsa21,rsa32)
 
641
      decrsdrs(x1,x2,x3,x4) = ((1.d0 + 0.20548d0*x1)*
 
642
     -     (6.1977d0 + 7.05945d0/x2 + 1.25034d0*x1+5.0493d0*x2))/
 
643
     -     ((6.1977d0*x1+14.1189d0*x2+0.6251699999999999d0*x3 + 
 
644
     +     3.3662d0*x4)**2d0*(1.d0 + 32.16468317787069d0/
 
645
     -     (6.1977d0*x1+14.1189d0*x2+0.6251699999999999d0*x3+
 
646
     +     3.3662d0*x4))) - 0.006388373199999999d0*
 
647
     -   dlog(1.d0 + 32.16468317787069d0/(6.1977d0*x1 + 14.1189d0*x2 + 
 
648
     -        0.6251699999999999d0*x3 + 3.3662d0*x4)) 
 
649
c
 
650
      DO j = 1, 4
 
651
        DO n = 1, (max_pow_u+1)*3
 
652
          F(n,j) = 0.D0
 
653
Cfah  later on, n has a different meaning: n as power of u, not 
 
654
Cfah  as number of the coefficient. 
 
655
        ENDDO
 
656
        dF_xa(j) = 0.D0
 
657
        dF_xb(j) = 0.D0
 
658
        dF_caa(j) = 0.D0
 
659
        dF_cbb(j) = 0.D0
 
660
        dF_cab(j) = 0.D0
 
661
C        DO k = 1, 4
 
662
C          DO n = 1, (max_pow_u+1)*3
 
663
C            FF(n,j,k) = 0.D0
 
664
C          ENDDO
 
665
C          d2F_xa(j,k) = 0.D0
 
666
C          d2F_xb(j,k) = 0.D0
 
667
C          d2F_caa(j,k) = 0.D0
 
668
C          d2F_cbb(j,k) = 0.D0
 
669
C          d2F_cab(j,k) = 0.D0
 
670
C        ENDDO
 
671
      ENDDO
 
672
      DO j = 1, (max_pow_u+1)*3
 
673
        F_xc(j) = 0.D0
 
674
      ENDDO 
 
675
 
 
676
Cfah --------------------------------------------------------------
 
677
 
 
678
Cfah call the expensive correlation parts here just once, and store their
 
679
Cfah values in a temporary variable. Then compute the actual F_c derivatives
 
680
Cfah with the various powers of u.  
 
681
 
 
682
      rho = rhoa + rhob
 
683
 
 
684
      s_a2=0.d0
 
685
      if(za.gt.tol_rho) s_a2 = za**2.D0 / rhoa**(8.D0/3.D0)
 
686
      s_b2=0.d0
 
687
      if(zb.gt.tol_rho) s_b2 = zb**2.D0 / rhob**(8.D0/3.D0)
 
688
      s_avg2 = 0.5D0*(s_a2 + s_b2)
 
689
 
 
690
      u_caa = 0.2D0*s_a2/(1.D0+0.2D0*s_a2) 
 
691
      u_cbb = 0.2D0*s_b2/(1.D0+0.2D0*s_b2) 
 
692
 
 
693
      u_cab = 0.006D0*s_avg2/(1.d0+0.006D0*s_avg2)
 
694
      if(rhoa.gt.tol_rho) then
 
695
         rsa = ((3.d0/Pi)**(1.D0/3.D0)*
 
696
     -        (1.d0/rhoa)**(1.D0/3.D0))/
 
697
     -        2**(2.D0/3.D0)
 
698
         rsa12 = rsa**(1.D0/2.D0)
 
699
         rsa32 = rsa**(3.D0/2.D0)
 
700
         rsa21 = rsa**2.D0
 
701
      else
 
702
         rsa=0d0
 
703
         rsa12=0d0
 
704
         rsa32=0d0
 
705
         rsa21=0d0
 
706
      endif
 
707
 
 
708
      if(rhob.gt.tol_rho) then
 
709
         rsb = ((3.d0/Pi)**(1.D0/3.D0)*
 
710
     -        (1.d0/rhob)**(1.D0/3.D0))/
 
711
     -        2**(2.D0/3.D0)
 
712
         rsb12 = rsb**(1.D0/2.D0)
 
713
         rsb32 = rsb**(3.D0/2.D0)
 
714
         rsb21 = rsb**2.D0
 
715
C     
 
716
C     pw91 LDA Ecorr
 
717
C
 
718
         if(rhob.gt.tol_rho) then
 
719
            e_crsb1 = e_crs1(rsb12,rsb,rsb32,rsb21)
 
720
            de_crsb1_by_drsb =  decrsdrs(rsb,rsb12,rsb21,rsb32)
 
721
         else
 
722
            e_crsb1 = 0d0
 
723
            de_crsb1_by_drsb = 0d0
 
724
         endif
 
725
            
 
726
         du_cbb_by_drhob = (-1.6D0*zb**2*rhob**(5.D0/3.D0))/
 
727
     -        (3.d0*(0.2D0*zb**2 + 
 
728
     -        rhob**(8.D0/3.D0))**2)
 
729
         du_cbb_by_dzb = (2*0.2D0*zb*rhob**(8.D0/3.D0))/
 
730
     -        (0.2D0*zb**2 + rhob**(8.D0/3.D0))**2
 
731
         if(rhoa.gt.0d0) then
 
732
         du_cab_by_drhoa = (-16*0.006D0*za*za*rhoa**(5.D0/3.D0)*
 
733
     -        rhob**(16.D0/3.D0))/
 
734
     -        (3.d0*(0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
735
     -        0.006D0*za*za*rhob**(8.D0/3.D0) + 
 
736
     -        2.d0*rhoa**(8.D0/3.D0)*
 
737
     -        rhob**(8.D0/3.D0))**2) 
 
738
         du_cab_by_dza = (4*0.006D0*za*rhoa**(8.D0/3.D0)*
 
739
     -        rhob**(16.D0/3.D0))/
 
740
     -        (0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
741
     -        0.006D0*za*za*rhob**(8.D0/3.D0) + 
 
742
     -        2.d0*rhoa**(8.D0/3.D0)*
 
743
     -        rhob**(8.D0/3.D0))**2
 
744
         du_cab_by_drhob = (-16*0.006D0*zb**2*rhob**(5.D0/3.D0)*
 
745
     -        rhoa**(16.D0/3.D0))/
 
746
     -        (3.d0*(0.006D0*za*za*rhob**(8.D0/3.D0) + 
 
747
     -        0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
748
     -        2.d0*rhob**(8.D0/3.D0)*
 
749
     -        rhoa**(8.D0/3.D0))**2) 
 
750
         du_cab_by_dzb = (4*0.006D0*zb*rhoa**(16.D0/3.D0)*
 
751
     -        rhob**(8.D0/3.D0))/
 
752
     -        (0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
753
     -        0.006D0*za*za*rhob**(8.D0/3.D0) + 
 
754
     -        2.d0*rhoa**(8.D0/3.D0)*
 
755
     -        rhob**(8.D0/3.D0))**2
 
756
         else
 
757
            du_cab_by_drhoa = 0d0
 
758
            du_cab_by_dza = 0d0
 
759
            du_cab_by_drhob = 0d0
 
760
            du_cab_by_dzb = 0d0
 
761
         endif
 
762
         drsb_by_drhob = drsbydrh(rhob)
 
763
      else
 
764
         e_crsb1 = 0d0
 
765
         de_crsb1_by_drsb = 0d0
 
766
         du_cbb_by_drhob = 0d0
 
767
         du_cbb_by_dzb = 0d0
 
768
         du_cab_by_drhoa = 0d0
 
769
         du_cab_by_drhob = 0d0
 
770
         du_cab_by_dza = 0d0
 
771
         du_cab_by_dzb = 0d0
 
772
         drsb_by_drhob = 0d0
 
773
      endif
 
774
 
 
775
      rsab = ((3.d0/Pi)**(1.D0/3.D0)*
 
776
     -    (1.d0/rho)**(1.D0/3.D0))/
 
777
     -  2**(2.D0/3.D0)
 
778
      rsab12 = rsab**(1.D0/2.D0)
 
779
      rsab32 = rsab**(3.D0/2.D0)
 
780
      rsab21 = rsab**2.D0
 
781
 
 
782
      zeta = (rhoa-rhob)/rho
 
783
      if(zeta.lt.-1d0) zeta=-1d0
 
784
      if(zeta.gt.1d0) zeta=1d0
 
785
 
 
786
      if(abs(1d0-zeta).gt.eps) then
 
787
         fzeta = (-2.d0 + sign(1d0,1.d0 - zeta)*(abs(1.d0 - zeta))**
 
788
     -        (4.D0/3.D0) +
 
789
     -        (1.d0 + zeta)**(4.D0/3.D0))/
 
790
     -        (-2.d0 + 2.d0*2.d0**(1.D0/3.D0))
 
791
         else
 
792
            fzeta = 1d0
 
793
         endif
 
794
 
 
795
C     
 
796
C     pw91 LDA Ecorr
 
797
C
 
798
      if(rhoa.gt.tol_rho) then
 
799
         e_crsa1 = e_crs1(rsa12,rsa,rsa32,rsa21)
 
800
      else
 
801
         e_crsa1 = 0d0
 
802
      endif
 
803
      if(rho.gt.tol_rho) then
 
804
         e_crsab1 = e_crs1(rsab12,rsab,rsab32,rsab21)
 
805
         e_crsab0 = -0.062182d0*dlog(1.d0 +
 
806
     -        16.0818243221511d0/
 
807
     -        (7.595699999999999d0*rsab12 +
 
808
     -        3.5876d0*rsab +
 
809
     -        1.6382d0*rsab32 +
 
810
     -        0.49294d0*rsab21))*
 
811
     -        (1.d0 + 0.2137d0*rsab)
 
812
 
 
813
         a_crsab = 0.03377399999999999d0*
 
814
     -        dlog(1.d0 + 29.60857464321667/
 
815
     -        (10.35699999999999d0*rsab12 +
 
816
     -        3.623099999999999d0*rsab +
 
817
     -        0.88026d0*rsab32 +
 
818
     -        0.49671d0*rsab21))*
 
819
     -        (1.d0 + 0.11125d0*rsab)
 
820
      else
 
821
         e_crsab1 = 0d0
 
822
         e_crsab0 = 0d0
 
823
         a_crsab=0d0
 
824
      endif
 
825
 
 
826
      e_crsabzeta = e_crsab0+a_crsab*fzeta*(1.d0-zeta**4)/1.709921D0+
 
827
     -  (e_crsab1-e_crsab0)*fzeta*zeta**4
 
828
 
 
829
      e_caa = rhoa*e_crsa1
 
830
      e_cbb = rhob*e_crsb1
 
831
      e_cab = rho*e_crsabzeta - rhoa*e_crsa1 - rhob*e_crsb1
 
832
      if(rhoa.gt.tol_rho) then
 
833
         du_caa_by_drhoa = (-1.6D0*za*za*rhoa**(5.D0/3.D0))/
 
834
     -        (3.*(0.2D0*za*za + 
 
835
     -        rhoa**(8.D0/3.D0))**2)
 
836
         du_caa_by_dza = (2*0.2D0*za*rhoa**(8.D0/3.D0))/
 
837
     -        (0.2D0*za*za + rhoa**(8.D0/3.D0))**2
 
838
      else
 
839
         du_caa_by_drhoa = 0d0
 
840
         du_caa_by_dza = 0d0
 
841
      endif
 
842
 
 
843
 
 
844
 
 
845
Cfah Second derivatives are not required by cadpac. 
 
846
Cfah   du_caa_by_drhoa_dza = (16*0.2D0*za*rhoa**(5.D0/3.D0)*
 
847
Cfah -    (0.2D0*za**2 - rhoa**(8.D0/3.D0)))/
 
848
Cfah -  (3.*(0.2D0*za**2 + 
 
849
Cfah -       rhoa**(8.D0/3.D0))**3)
 
850
Cfah   du_cbb_by_drhob_dzb = (16*0.2D0*zb*rhob**(5.D0/3.D0)*
 
851
Cfah -    (0.2D0*zb**2 - rhob**(8.D0/3.D0)))/
 
852
Cfah -  (3.*(0.2D0*zb**2 + 
 
853
Cfah -       rhob**(8.D0/3.D0))**3)
 
854
Cfah
 
855
Cfah   du_caa_by_dza_dza = (2*0.2D0*rhoa**(8.D0/3.D0)*
 
856
Cfah -    (-3*0.2D0*za**2 + rhoa**(8.D0/3.D0))
 
857
Cfah -    )/
 
858
Cfah -  (0.2D0*za**2 + rhoa**(8.D0/3.D0))**3
 
859
Cfah   du_cbb_by_dzb_dzb = (2*0.2D0*rhob**(8.D0/3.D0)*
 
860
Cfah -    (-3*0.2D0*zb**2 + rhob**(8.D0/3.D0))
 
861
Cfah -    )/
 
862
Cfah -  (0.2D0*zb**2 + rhob**(8.D0/3.D0))**3
 
863
Cfah
 
864
Cfah   du_cab_by_drhoa_dza = (-32*0.006D0*rhoa**(5.D0/3.D0)*
 
865
Cfah -    (0.006D0*za*zb**2*
 
866
Cfah -       rhoa**(8.D0/3.D0)*
 
867
Cfah -       rhob**(16.D0/3.D0) - 
 
868
Cfah -      0.006D0*za**3*rhob**8 + 
 
869
Cfah -      2*za*rhoa**(8.D0/3.D0)*rhob**8))/
 
870
Cfah -  (3.*(0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
871
Cfah -       0.006D0*za**2*rhob**(8.D0/3.D0) + 
 
872
Cfah -       2*rhoa**(8.D0/3.D0)*
 
873
Cfah -        rhob**(8.D0/3.D0))**3) 
 
874
Cfah   du_cab_by_drhoa_dzb = (64*0.006D0**2*za**2*zb*
 
875
Cfah -    rhoa**(13.D0/3.D0)*
 
876
Cfah -    rhob**(16.D0/3.D0))/
 
877
Cfah -  (3.*(0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
878
Cfah -       0.006D0*za**2*rhob**(8.D0/3.D0) + 
 
879
Cfah -       2*rhoa**(8.D0/3.D0)*
 
880
Cfah -        rhob**(8.D0/3.D0))**3) 
 
881
Cfah   du_cab_by_drhob_dza = (64*0.006D0**2*za*zb**2*
 
882
Cfah -    rhoa**(16.D0/3.D0)*
 
883
Cfah -    rhob**(13.D0/3.D0))/
 
884
Cfah -  (3.*(0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
885
Cfah -       0.006D0*za**2*rhob**(8.D0/3.D0) + 
 
886
Cfah -       2*rhoa**(8.D0/3.D0)*
 
887
Cfah -        rhob**(8.D0/3.D0))**3) 
 
888
Cfah   du_cab_by_drhob_dzb = (-32*0.006D0*rhob**(5.D0/3.D0)*
 
889
Cfah -    (-(0.006D0*zb**3*rhoa**8) + 
 
890
Cfah -      0.006D0*za**2*zb*
 
891
Cfah -       rhoa**(16.D0/3.D0)*
 
892
Cfah -       rhob**(8.D0/3.D0) + 
 
893
Cfah -      2*zb*rhoa**8*rhob**(8.D0/3.D0)))/
 
894
Cfah -  (3.*(0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
895
Cfah -       0.006D0*za**2*rhob**(8.D0/3.D0) + 
 
896
Cfah -       2*rhoa**(8.D0/3.D0)*
 
897
Cfah -        rhob**(8.D0/3.D0))**3) 
 
898
Cfah   du_cab_by_dza_dza = (4*0.006D0*(0.006D0*zb**2*
 
899
Cfah -       rhoa**(16.D0/3.D0)*
 
900
Cfah -       rhob**(16.D0/3.D0) - 
 
901
Cfah -      3*0.006D0*za**2*rhoa**(8.D0/3.D0)*
 
902
Cfah -       rhob**8 + 2*rhoa**(16.D0/3.D0)*rhob**8
 
903
Cfah -      ))/
 
904
Cfah -  (0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
905
Cfah -     0.006D0*za**2*rhob**(8.D0/3.D0) + 
 
906
Cfah -     2*rhoa**(8.D0/3.D0)*
 
907
Cfah -      rhob**(8.D0/3.D0))**3 
 
908
Cfah   du_cab_by_dza_dzb = (-16*0.006D0**2*za*zb*
 
909
Cfah -    rhoa**(16.D0/3.D0)*
 
910
Cfah -    rhob**(16.D0/3.D0))/
 
911
Cfah -  (0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
912
Cfah -     0.006D0*za**2*rhob**(8.D0/3.D0) + 
 
913
Cfah -     2*rhoa**(8.D0/3.D0)*
 
914
Cfah -      rhob**(8.D0/3.D0))**3 
 
915
Cfah   du_cab_by_dzb_dzb = (4*0.006D0*rhoa**(16.D0/3.D0)*
 
916
Cfah -    rhob**(8.D0/3.D0)*
 
917
Cfah -    (-3*0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
918
Cfah -      0.006D0*za**2*rhob**(8.D0/3.D0) + 
 
919
Cfah -      2*rhoa**(8.D0/3.D0)*
 
920
Cfah -       rhob**(8.D0/3.D0)))/
 
921
Cfah -  (0.006D0*zb**2*rhoa**(8.D0/3.D0) + 
 
922
Cfah -     0.006D0*za**2*rhob**(8.D0/3.D0) + 
 
923
Cfah -     2*rhoa**(8.D0/3.D0)*
 
924
Cfah -      rhob**(8.D0/3.D0))**3 
 
925
 
 
926
      if(rhoa.gt.tol_rho) then
 
927
         drsa_by_drhoa = drsbydrh(rhoa)
 
928
      else
 
929
         drsa_by_drhoa =0d0
 
930
      endif
 
931
      if(rho.gt.tol_rho) then
 
932
         drsab_by_drhoa = drsbydrh(rho) 
 
933
         drsab_by_drhob = drsab_by_drhoa 
 
934
      else
 
935
         drsab_by_drhoa = 0d0
 
936
         drsab_by_drhob = 0d0
 
937
      endif
 
938
 
 
939
      dzeta_by_drhoa = 2.d0*rhob/rho**2
 
940
      dzeta_by_drhob = -2.d0*rhoa/rho**2
 
941
 
 
942
      dfzeta_by_dzeta = ((-4.d0*sign(1d0,1.d0 - zeta)*
 
943
     *     (abs(1.d0 - zeta))**(1.D0/3.D0))/
 
944
     -     3.d0 + (4.d0*(1.d0 + zeta)**
 
945
     -        (1.D0/3.D0))/3.)/
 
946
     -  (-2.d0 + 2d0*2**(1.D0/3.D0))
 
947
 
 
948
 
 
949
      da_crsab_by_drsab = (-1.d0*(1.d0 + 0.11125d0*rsab)*
 
950
     -     (3.623099999999999d0 + 
 
951
     -       5.178499999999999d0/rsab12 + 
 
952
     -       0.99342d0*rsab + 1.32039d0*rsab12))/
 
953
     -   ((1.d0 + 29.60857464321667d0/
 
954
     -        (3.623099999999999d0*rsab + 
 
955
     -          10.35699999999999d0*rsab12 + 
 
956
     -          0.49671d0*rsab21 + 0.88026d0*rsab32))*
 
957
     -     (3.623099999999999d0*rsab + 
 
958
     -        10.35699999999999d0*rsab12 + 
 
959
     -        0.49671d0*rsab21 + 0.880260*rsab32)**2) + 
 
960
     -  0.003757357499999999d0*
 
961
     -   dlog(1.d0 + 29.60857464321667/
 
962
     -      (3.623099999999999d0*rsab + 
 
963
     -        10.35699999999999d0*rsab12 + 
 
964
     -        0.49671d0*rsab21 + 0.88026d0*rsab32)) 
 
965
 
 
966
      de_crsab0_by_drsab = (1.d0*(1.d0 + 0.2137d0*rsab)*
 
967
     -     (3.5876d0 + 3.797849999999999d0/rsab12 + 
 
968
     -       0.98588d0*rsab + 2.4573*rsab12))/
 
969
     -   ((3.5876d0*rsab + 7.595699999999999d0*rsab12 + 
 
970
     -        0.49294d0*rsab21 + 1.6382d0*rsab32)**2*
 
971
     -     (1.d0 + 16.0818243221511d0/
 
972
     -        (3.5876d0*rsab + 7.595699999999999d0*rsab12 + 
 
973
     -          0.49294d0*rsab21 + 1.6382d0*rsab32))) - 
 
974
     -  0.01328829339999999d0*
 
975
     -   dlog(1.d0 + 16.0818243221511d0/
 
976
     -      (3.5876*rsab + 7.595699999999999d0*rsab12 + 
 
977
     -        0.49294d0*rsab21 + 1.6382d0*rsab32))
 
978
      if(rhoa.gt.tol_rho) then
 
979
         de_crsa1_by_drsa = decrsdrs(rsa,rsa12,rsa21,rsa32)
 
980
         de_crsab1_by_drsab = decrsdrs(rsab,rsab12,rsab21,rsab32)
 
981
      else
 
982
         de_crsa1_by_drsa = 0d0
 
983
         de_crsab1_by_drsab = 0d0
 
984
      endif
 
985
 
 
986
 
 
987
      de_crsabzeta_by_drsab = 1.124999956683108D0*(1.d0 - zeta**4)*
 
988
     -   (-2.d0+sign(1d0,1.d0-zeta)*(abs(1.d0-zeta))**(4.D0/3.D0)+ 
 
989
     -     (1.d0 + zeta)**(4.D0/3.D0))*
 
990
     -   da_crsab_by_drsab + 
 
991
     -  de_crsab0_by_drsab + 
 
992
     -  fzeta*zeta**4*
 
993
     -   (- de_crsab0_by_drsab + 
 
994
     -      de_crsab1_by_drsab  )
 
995
 
 
996
      de_crsabzeta_by_dzeta = 1.499999942244144D0*(-1.d0 + zeta**4)*
 
997
     -   (sign(1d0,1.d0 - zeta)*(abs(1.d0 - zeta))**(1.D0/3.D0) - 
 
998
     -     (1.d0 + zeta)**(1.D0/3.D0))*a_crsab - 
 
999
     -  4.499999826732434D0*zeta**3*
 
1000
     -   (-2.d0 + sign(1d0,1.d0-zeta)*abs(1.d0-zeta)**(4.D0/3.D0)+ 
 
1001
     -     (1.d0 + zeta)**(4.D0/3.D0))*a_crsab + 
 
1002
     -  (2*zeta**4*sign(1d0,1.d0-zeta)*(abs(1.d0-zeta)**(1.D0/3.D0)- 
 
1003
     -       (1.d0 + zeta)**(1.D0/3.D0))*
 
1004
     -     (e_crsab0 - e_crsab1))/
 
1005
     -   (3.*(-1.d0 + 2**(1.D0/3.D0))) + 
 
1006
     -  4*fzeta*(-e_crsab0 + 
 
1007
     -     e_crsab1)*zeta**3
 
1008
 
 
1009
Cfah this is with application of the chain rule; I keep it that general
 
1010
Cfah because this way, I only have to define one "G". 
 
1011
      de_caa_by_drhoa = e_crsa1 + rhoa*de_crsa1_by_drsa*drsa_by_drhoa 
 
1012
      de_cbb_by_drhob = e_crsb1 + rhob*de_crsb1_by_drsb*drsb_by_drhob 
 
1013
 
 
1014
      de_cab_by_drhoa = -e_crsa1 + 
 
1015
     -  e_crsabzeta - 
 
1016
     -  rhoa*de_crsa1_by_drsa* 
 
1017
     -  drsa_by_drhoa + 
 
1018
     -  rho*(de_crsabzeta_by_drsab*
 
1019
     -  drsab_by_drhoa + 
 
1020
     -  de_crsabzeta_by_dzeta*
 
1021
     -  dzeta_by_drhoa)
 
1022
 
 
1023
      de_cab_by_drhob = -e_crsb1 + 
 
1024
     -  e_crsabzeta - 
 
1025
     -  rhob*de_crsb1_by_drsb* 
 
1026
     -  drsb_by_drhob + 
 
1027
     -  rho*(de_crsabzeta_by_drsab*
 
1028
     -  drsab_by_drhob + 
 
1029
     -  de_crsabzeta_by_dzeta*
 
1030
     -  dzeta_by_drhob)
 
1031
 
 
1032
 
 
1033
 
 
1034
Cfah Here starts the big outer loop over the powers u 
 
1035
      DO n = 0, max_pow_u 
 
1036
        c_naa = sol((n*3) + 2)
 
1037
        c_nbb = c_naa
 
1038
        c_nab = sol((n*3) + 3) 
 
1039
 
 
1040
Cfah construction of the F_xc itself
 
1041
Cfah -------------------------------
 
1042
        IF (rhoa.GT.tol_rho) THEN
 
1043
          if(n.eq.0) then
 
1044
            F_xc(1) = F_xs0 (sol(1), rhoa, za)
 
1045
          else
 
1046
            F_xc(n*3+1) = F_xs (n, sol((n*3) + 1), rhoa, za)
 
1047
          endif
 
1048
        ENDIF
 
1049
          if(u_caa.gt.tol_rho)then
 
1050
             if(n.eq.0) then
 
1051
             F_xc(2) = e_caa*c_naa
 
1052
             else
 
1053
             F_xc(n*3+2) = e_caa*u_caa**n*c_naa
 
1054
             endif
 
1055
          endif
 
1056
 
 
1057
        IF (rhob.GT.tol_rho) THEN
 
1058
           if(n.eq.0) then
 
1059
          F_xc(1) = F_xc(1)+F_xs0(sol(1), rhob, zb)
 
1060
           else
 
1061
          F_xc(n*3+1) = F_xc(n*3+1)+F_xs(n, sol((n*3) + 1), rhob, zb)
 
1062
          endif
 
1063
        ENDIF
 
1064
          if(u_cbb.gt.tol_rho) then
 
1065
             if(n.eq.0) then
 
1066
                F_xc(2) = F_xc(2)+e_cbb*c_nbb
 
1067
             else
 
1068
                F_xc(n*3+2) = F_xc(n*3+2)+e_cbb*u_cbb**n*c_nbb
 
1069
             endif
 
1070
          endif
 
1071
 
 
1072
          if(u_cab.gt.tol_rho) then
 
1073
             if(n.eq.0) then
 
1074
                F_xc(3) = e_cab*c_nab
 
1075
             else
 
1076
                F_xc(n*3+3) = e_cab*u_cab**n*c_nab
 
1077
             endif
 
1078
          endif
 
1079
 
 
1080
Cfah       print*, 'in deriv:', e_cab, u_cab, c_nab
 
1081
 
 
1082
Cfah    First Derivatives
 
1083
Cfah ---------------------
 
1084
 
 
1085
        if(za.gt.tol_rho)then 
 
1086
           if(n.eq.0) then
 
1087
            dF_xa(1) = dF_xs_by_drhos0 ( sol(1), rhoa, za) 
 
1088
            dF_xa(3) = 0d0
 
1089
         elseif(n.eq.1) then
 
1090
            dF_xa(1) = dF_xs_by_drhos1 (sol(4), rhoa, za) 
 
1091
            dF_xa(3) = dF_xs_by_dzs1 ( sol(4), rhoa, za)
 
1092
         else
 
1093
            dF_xa(1) = dF_xs_by_drhos (n, sol((n*3) + 1), rhoa, za) 
 
1094
            dF_xa(3) = dF_xs_by_dzs (n, sol((n*3) + 1), rhoa, za)
 
1095
         endif
 
1096
          endif
 
1097
 
 
1098
        if(zb.gt.tol_rho) then
 
1099
           if(n.eq.0) then
 
1100
             dF_xb(2) = dF_xs_by_drhos0(sol(1), rhob, zb)
 
1101
             dF_xb(4) = 0d0
 
1102
          elseif(n.eq.1) then
 
1103
             dF_xb(2) = dF_xs_by_drhos1(sol(4), rhob, zb)
 
1104
             dF_xb(4) = dF_xs_by_dzs1 ( sol(4), rhob, zb)
 
1105
          else
 
1106
             dF_xb(2) = dF_xs_by_drhos (n, sol((n*3) + 1), rhob, zb)
 
1107
             dF_xb(4) = dF_xs_by_dzs (n, sol((n*3) + 1), rhob, zb)
 
1108
          endif
 
1109
           endif
 
1110
 
 
1111
        if(u_caa.gt.tol_rho) then
 
1112
           if(n.eq.0) then
 
1113
          dF_caa(1) = c_naa*de_caa_by_drhoa
 
1114
          dF_caa(3) = 0d0
 
1115
           elseif(n.eq.1) then
 
1116
          dF_caa(1) = c_naa*u_caa*
 
1117
     *       de_caa_by_drhoa+c_naa*e_caa*du_caa_by_drhoa
 
1118
          dF_caa(3) = c_naa*e_caa*du_caa_by_dza
 
1119
          else
 
1120
          dF_caa(1) = c_naa*u_caa**n*
 
1121
     *       de_caa_by_drhoa+c_naa*n*e_caa*u_caa**(-1+n)*
 
1122
     *       du_caa_by_drhoa
 
1123
          dF_caa(3) = c_naa*n*e_caa*u_caa**(-1+n)*du_caa_by_dza
 
1124
          endif
 
1125
        endif
 
1126
 
 
1127
        if(u_cbb.gt.tol_rho) then
 
1128
           if(n.eq.0) then
 
1129
          dF_cbb(2) = c_nbb*de_cbb_by_drhob 
 
1130
          dF_cbb(4) = 0d0
 
1131
           elseif(n.eq.1) then
 
1132
          dF_cbb(2) = c_nbb*u_cbb*de_cbb_by_drhob + 
 
1133
     -   c_nbb*e_cbb*du_cbb_by_drhob
 
1134
          dF_cbb(4) = c_nbb*e_cbb*du_cbb_by_dzb
 
1135
           else
 
1136
          dF_cbb(2) = c_nbb*u_cbb**n*de_cbb_by_drhob + 
 
1137
     -   c_nbb*n*e_cbb*u_cbb**(-1 + n)*du_cbb_by_drhob
 
1138
          dF_cbb(4) = c_nbb*n*e_cbb*u_cbb**(-1+n)*du_cbb_by_dzb
 
1139
          endif
 
1140
        endif
 
1141
 
 
1142
 
 
1143
        if(u_cab.gt.tol_rho) then
 
1144
           if(n.eq.0) then
 
1145
          dF_cab(1) = c_nab*de_cab_by_drhoa
 
1146
          dF_cab(2) = c_nab*de_cab_by_drhob
 
1147
          dF_cab(3) = 0d0
 
1148
          dF_cab(4) = 0d0
 
1149
           elseif(n.eq.1) then
 
1150
          dF_cab(1) = c_nab*u_cab*
 
1151
     *         de_cab_by_drhoa+c_nab*n*e_cab*du_cab_by_drhoa 
 
1152
          dF_cab(2) = c_nab*u_cab*
 
1153
     -         de_cab_by_drhob+c_nab*n*e_cab*du_cab_by_drhob
 
1154
          dF_cab(3) = c_nab*e_cab*du_cab_by_dza
 
1155
          dF_cab(4) = c_nab*n*e_cab*du_cab_by_dzb
 
1156
          else
 
1157
          dF_cab(1) = c_nab*u_cab**n*
 
1158
     *         de_cab_by_drhoa+c_nab*n*e_cab*u_cab**(-1+n)*
 
1159
     *         du_cab_by_drhoa 
 
1160
          dF_cab(2) = c_nab*u_cab**n*
 
1161
     -         de_cab_by_drhob+c_nab*n*e_cab*u_cab**(-1+n)*
 
1162
     -         du_cab_by_drhob
 
1163
          dF_cab(3) = c_nab*n*e_cab*
 
1164
     -         u_cab**(-1+n)*du_cab_by_dza
 
1165
          dF_cab(4) = c_nab*n*e_cab*
 
1166
     -         u_cab**(-1+n)*du_cab_by_dzb
 
1167
          endif
 
1168
        endif
 
1169
 
 
1170
Cfah Second Derivatives
 
1171
Cfah ------------------
 
1172
 
 
1173
Cfah         d2F_xa(1,1) = d2F_xs_by_drhos_drhos (n, sol((n*3) + 1), 
 
1174
Cfah      &                                         rhoa, za)
 
1175
Cfah see comment below, for the (2,2) term. 
 
1176
Cfah    d2F_xa(1,2) = 0 
 
1177
Cfah    d2F_xa(1,3) = d2F_xs_by_drhos_dzs (n, sol((n*3) + 1), rhoa, za)
 
1178
Cfah    d2F_xa(1,4) = 0 
 
1179
Cfah    d2F_xa(2,2) = 0  
 
1180
Cfah    d2F_xa(2,3) = 0  
 
1181
Cfah    d2F_xa(2,4) = 0 
 
1182
Cfah    d2F_xa(3,3) = d2F_xs_by_dzs_dzs (n, sol((n*3) + 1), rhoa, za)
 
1183
Cfah    d2F_xa(3,4) = 0 
 
1184
Cfah    d2F_xa(4,4) = 0 
 
1185
 
 
1186
Cfah for alpha spin, elements are non-zero when both indices are odd; 
 
1187
Cfah for beta spin, elements are non-zero when both indices are even. 
 
1188
Cfah the matrix is symmetric, and the upper triangle contains the 
 
1189
Cfah 10 elements given above and below. 
 
1190
 
 
1191
Cfah    d2F_xb(1,1) = 0
 
1192
Cfah    d2F_xb(1,2) = 0  
 
1193
Cfah    d2F_xb(1,3) = 0           
 
1194
Cfah    d2F_xb(1,4) = 0 
 
1195
Cfah        d2F_xb(2,2) = d2F_xs_by_drhos_drhos (n, sol((n*3) + 1), 
 
1196
Cfah     &                                         rhob, zb)
 
1197
Cfah this term is NOT zero, but needs not be evaluated since we don't 
 
1198
Cfah need it for the construction of v (cf. routine "va" in the fit 
 
1199
Cfah program) 
 
1200
Cfah    d2F_xb(2,3) = 0  
 
1201
Cfah    d2F_xb(2,4) = d2F_xs_by_drhos_dzs (n, sol((n*3) + 1), rhob, zb)
 
1202
Cfah    d2F_xb(3,3) = 0
 
1203
Cfah    d2F_xb(3,4) = 0 
 
1204
Cfah    d2F_xb(4,4) = d2F_xs_by_dzs_dzs (n, sol((n*3) + 1), rhob, zb)
 
1205
 
 
1206
 
 
1207
Cfah    d2F_caa(1,1) = !=0, but not needed 
 
1208
Cfah    d2F_caa(1,2) = 0.D0 (not needed)  
 
1209
Cfah    d2F_caa(1,3) = c_naa*n*u_caa**(-1 + n)*
 
1210
Cfah -   de_caa_by_drhoa*
 
1211
Cfah -   du_caa_by_dza + 
 
1212
Cfah -  c_naa*(-1 + n)*n*e_caa*
 
1213
Cfah -   u_caa**(-2 + n)*
 
1214
Cfah -   du_caa_by_dza*
 
1215
Cfah -   du_caa_by_drhoa + 
 
1216
Cfah -  c_naa*n*e_caa*u_caa**(-1 + n)*
 
1217
Cfah -   du_caa_by_drhoa_dza
 
1218
Cfah    d2F_caa(1,4) = 0.D0
 
1219
Cfah    d2F_caa(2,2) = 0.D0 (not needed)
 
1220
Cfah    d2F_caa(2,3) = 0.D0 
 
1221
Cfah    d2F_caa(2,4) = 0.D0 
 
1222
Cfah    d2F_caa(3,3) = c_naa*n*e_caa*u_caa**(-2 + n)*
 
1223
Cfah -  ((-1 + n)*du_caa_by_dza**
 
1224
Cfah -      2 + u_caa*
 
1225
Cfah -     du_caa_by_dza_dza)
 
1226
Cfah    d2F_caa(3,4) = 0.D0 
 
1227
Cfah    d2F_caa(4,4) = 0.D0 
 
1228
 
 
1229
 
 
1230
Cfah    d2F_cbb(1,1) = 0.D0 (not needed)
 
1231
Cfah    d2F_cbb(1,2) = 0.D0 (not needed)
 
1232
Cfah    d2F_cbb(1,3) = 0.D0
 
1233
Cfah    d2F_cbb(1,4) = 0.D0
 
1234
Cfah    d2F_cbb(2,2) = !=0, but not needed 
 
1235
Cfah    d2F_cbb(2,3) = 0.D0
 
1236
Cfah    d2F_cbb(2,4) = c_nbb*n*u_cbb**(-1 + n)*
 
1237
Cfah -   de_cbb_by_drhob*
 
1238
Cfah -   du_cbb_by_dzb +
 
1239
Cfah -  c_nbb*(-1 + n)*n*e_cbb*
 
1240
Cfah -   u_cbb**(-2 + n)*
 
1241
Cfah -   du_cbb_by_dzb*
 
1242
Cfah -   du_cbb_by_drhob +
 
1243
Cfah -  c_nbb*n*e_cbb*u_cbb**(-1 + n)*
 
1244
Cfah -   du_cbb_by_drhob_dzb
 
1245
Cfah    d2F_cbb(3,3) = 0.D0
 
1246
Cfah    d2F_cbb(3,4) = 0.D0
 
1247
Cfah    d2F_cbb(4,4) =  c_nbb*n*e_cbb*u_cbb**(-2 + n)*
 
1248
Cfah -  ((-1 + n)*du_cbb_by_dzb**
 
1249
Cfah -      2 + u_cbb*
 
1250
Cfah -     du_cbb_by_dzb_dzb)
 
1251
 
 
1252
Cfah    d2F_cab(1,1) = not needed
 
1253
Cfah    d2F_cab(1,2) = not needed
 
1254
Cfah    d2F_cab(1,3) = c_nab*n*u_cab**(-2 + n)*
 
1255
Cfah -  ((-1 + n)*e_cab*
 
1256
Cfah -     du_cab_by_dza
 
1257
Cfah -      *du_cab_by_drhoa + 
 
1258
Cfah -    u_cab*(de_cab_by_drhoa*
 
1259
Cfah -        du_cab_by_dza + e_cab*
 
1260
Cfah -        du_cab_by_drhoa_dza
 
1261
Cfah -  ))
 
1262
Cfah    d2F_cab(1,4) = c_nab*n*u_cab**(-2 + n)*
 
1263
Cfah -  (  (-1 + n)*e_cab*
 
1264
Cfah -     du_cab_by_dzb
 
1265
Cfah -      *du_cab_by_drhoa + 
 
1266
Cfah -    u_cab*
 
1267
Cfah -     (de_cab_by_drhoa*
 
1268
Cfah -        du_cab_by_dzb + 
 
1269
Cfah -       e_cab*
 
1270
Cfah -        du_cab_by_drhoa_dzb))
 
1271
Cfah    d2F_cab(2,2) = not needed
 
1272
Cfah    d2F_cab(2,3) = c_nab*n*u_cab**(-2 + n)*
 
1273
Cfah -  ((-1 + n)*e_cab*
 
1274
Cfah -     du_cab_by_dza
 
1275
Cfah -      *du_cab_by_drhob +
 
1276
Cfah -    u_cab*
 
1277
Cfah -     (de_cab_by_drhob*
 
1278
Cfah -        du_cab_by_dza + 
 
1279
Cfah -       e_cab*
 
1280
Cfah -        du_cab_by_drhob_dza))
 
1281
Cfah    d2F_cab(2,4) = c_nab*n*u_cab**(-2 + n)*
 
1282
Cfah -  ((-1 + n)*e_cab*
 
1283
Cfah -     du_cab_by_dzb
 
1284
Cfah -      *du_cab_by_drhob + 
 
1285
Cfah -    u_cab*(de_cab_by_drhob*
 
1286
Cfah -        du_cab_by_dzb + e_cab*
 
1287
Cfah -        du_cab_by_drhob_dzb ))
 
1288
Cfah    d2F_cab(3,3) = c_nab*n*e_cab*
 
1289
Cfah -  u_cab**(-2 + n)*
 
1290
Cfah -  ((-1 + n)*du_cab_by_dza**2 + 
 
1291
Cfah -    u_cab*
 
1292
Cfah -     du_cab_by_dza_dza)
 
1293
Cfah    d2F_cab(3,4) = c_nab*n*e_cab*
 
1294
Cfah -  u_cab**(-2 + n)*
 
1295
Cfah -  ((-1 + n)*du_cab_by_dzb*
 
1296
Cfah -     du_cab_by_dza
 
1297
Cfah -       + u_cab*
 
1298
Cfah -     du_cab_by_dza_dzb)
 
1299
Cfah    d2F_cab(4,4) = c_nab*n*e_cab*
 
1300
Cfah -  u_cab**(-2 + n)*
 
1301
Cfah -  ((-1 + n)*du_cab_by_dzb**2 + 
 
1302
Cfah -    u_cab*
 
1303
Cfah -     du_cab_by_dzb_dzb)
 
1304
Cfah
 
1305
Cfah here, the second derivatives are completed (Schwartz's rule: 
 
1306
Cfah df/(dadb) = df/(dbda) 
 
1307
Cfah    DO i = 1, 4
 
1308
Cfah      DO j = i, 4
 
1309
Cfah        d2F_xa(j,i) = d2F_xa(i,j)  
 
1310
Cfah        d2F_xb(j,i) = d2F_xb(i,j)
 
1311
Cfah        d2F_caa(j,i) = d2F_caa(i,j) 
 
1312
Cfah        d2F_cbb(j,i) = d2F_cbb(i,j) 
 
1313
Cfah        d2F_cab(j,i) = d2F_cab(i,j) 
 
1314
Cfah      ENDDO
 
1315
Cfah    ENDDO
 
1316
 
 
1317
Cfah test for zero densities (as in beta part of H atom):
 
1318
        IF (rhob.LT.tol_rho) THEN 
 
1319
          DO i = 1, 4
 
1320
            dF_xb(i) = 0.D0
 
1321
            dF_cbb(i) = 0.D0
 
1322
            dF_cab(i) = 0.D0
 
1323
Cfah        DO j = 1, 4
 
1324
Cfah          d2F_xb(i,j) = 0.D0
 
1325
Cfah          d2F_cbb(i,j) = 0.D0
 
1326
Cfah          d2F_cab(i,j) = 0.D0
 
1327
Cfah        ENDDO 
 
1328
          ENDDO 
 
1329
        ENDIF
 
1330
 
 
1331
        IF (rhoa.LT.tol_rho) THEN
 
1332
          DO i = 1, 4
 
1333
            dF_xa(i) = 0.D0
 
1334
            dF_caa(i) = 0.D0
 
1335
            dF_cab(i) = 0.D0
 
1336
Cfah        DO j = 1, 4
 
1337
Cfah          d2F_xa(i,j) = 0.D0
 
1338
Cfah          d2F_caa(i,j) = 0.D0
 
1339
Cfah          d2F_cab(i,j) = 0.D0
 
1340
Cfah        ENDDO
 
1341
          ENDDO
 
1342
        ENDIF
 
1343
 
 
1344
 
 
1345
Cfah Sum up all the partial derivatives with respect to the same function
 
1346
Cfah of terms containing different powers of u with the help of the big outer 
 
1347
Cfah loop: 
 
1348
 
 
1349
Cfah have the partial derivative 
 
1350
 
 
1351
        DO i = 1, 4
 
1352
          F(n*3+1,i) = dF_xa(i) + dF_xb(i) 
 
1353
          F(n*3+2,i) = dF_caa(i) +dF_cbb(i) 
 
1354
          F(n*3+3,i) = dF_cab(i) 
 
1355
Cfah      DO j = 1, 4
 
1356
Cfah        FF(n*3+1,i,j) = d2F_xa(i,j) + d2F_xb(i,j) 
 
1357
Cfah        FF(n*3+2,i,j) = d2F_caa(i,j) + d2F_cbb(i,j) 
 
1358
Cfah        FF(n*3+3,i,j) = d2F_cab(i,j)  
 
1359
Cfah      ENDDO 
 
1360
        ENDDO 
 
1361
 
 
1362
Cfah these partial derivatives have not been computed because they are
 
1363
Cfah zero since we don't have a gradrhoagradrhob term in the Becke V functional
 
1364
C        F(n*3+1,5) = 0
 
1365
C        F(n*3+2,5) = 0
 
1366
C        F(n*3+3,5) = 0
 
1367
Cfah    DO i = 1, 5
 
1368
Cfah      FF(n*3+1,i,5) = 0
 
1369
Cfah      FF(n*3+2,i,5) = 0
 
1370
Cfah      FF(n*3+3,i,5) = 0
 
1371
Cfah      FF(n*3+1,5,i) = 0
 
1372
Cfah      FF(n*3+2,5,i) = 0
 
1373
Cfah      FF(n*3+3,5,i) = 0
 
1374
Cfah    ENDDO
 
1375
 
 
1376
      ENDDO
 
1377
 
 
1378
      RETURN
 
1379
 
 
1380
      END
 
1381
 
 
1382
Cfah-----------------------------------------------------------
 
1383