1C> \ingroup nwint
2C> @{
3C>
4C> \brief Compute 2-center 2-electron integral 2nd derivatives
5C>
6C> Compute the 2-center 2-electron integral 2nd derivatives as given by
7C> \f{eqnarray*}{
8C> \frac{\partial^2({\mu}|{\nu})}{\partial X_x\partial X_y} = \int_{-\infty}^{\infty} \frac{\partial^2 g_{\mu}(X_{\mu},r_{1})\frac{1}{r_{12}}g_{\nu}(X_{\nu},r_{2})}{\partial X_x\partial X_y}dr_{1}dr_{2}
9C> \f}
10C> The integral derivatives are stored in an order that is consistent with
11C> the declaration `ERI(natcrd*(natcrd+1)/2,nint)`, where `nint` is the number
12C> of integrals in the shell pair, `natcrd` is the number of Cartesian
13C> coordinates in the shell pair, i.e. 6 ( = 2 atoms * 3 coordinates).
14C> The actual lexical indeces of the atoms on which the shells `ish` and
15C> `jsh` are centered are returned in `idatom`.
16C>
17      subroutine intdd_2e2c(brain, ish, ketin, jsh,
18     &       lscr, scr, leri, eri, idatom)
19c $Id$
20      implicit none
21c
22* basic api routine to generate 4 center two electron
23* integral second derivatives
24c
25* The buffer comes out as:
26*      (upper triangle block derivative, basis indecies)
27c------------------------------------------------------------
28c construct all 10 blocks of sec.der. (output) from 6 blocks:
29c
30c          AA AB AC AD                AA AB AC
31c             BB BC BD      from         BB BC
32c                CC CD                      CC
33c                   DD
34c      1-6, 7-15,16-24,25-33         1-6, 7-15,16-24
35c          34-39,40-48,49-57             25-30,31-39
36c                58-63,64-72                   40-45
37c                      73-78
38c------------------------------------------------------------
39* block AA: (1-6)  | block BB: (34-39)| block CC: (58-63)   |
40c       axax=1     |       bxbx=34    |       cxcx=58       |
41c       axay=2     |       bxby=35    |       cxcy=59       |
42c       axaz=3     |       bxbz=36    |       cxcz=60       |
43c       ayay=4     |       byby=37    |       cycy=61       |
44c       ayaz=5     |       bybz=38    |       cycz=62       |
45c       azaz=6     |       bzbz=39    |       czcz=63       |
46* block AB: (7-15) | block BC: (40-48)| block CD: (64-72)   |
47c       axbx=7     |       bxcx=40    |       cxdx=64       |
48c       axby=8     |       bxcy=41    |       cxdy=65       |
49c       axbz=9     |       bxcz=42    |       cxdz=66       |
50c       aybx=10    |       bycx=43    |       cydx=67       |
51c       ayby=11    |       bycy=44    |       cydy=68       |
52c       aybz=12    |       bycz=45    |       cydz=69       |
53c       azbx=13    |       bzcx=46    |       czdx=70       |
54c       azby=14    |       bzcy=47    |       czdy=71       |
55c       azbz=15    |       bzcz=48    |       czdz=72       |
56* block AC: (16-24)| block BD: (49-57)| block DD: (73-78)   |
57c       axcx=16    |       bxdx=49    |       dxdx=73       |
58c       axcy=17    |       bxdy=50    |       dxdy=74       |
59c       axcz=18    |       bxdz=51    |       dxdz=75       |
60c       aycx=19    |       bydx=52    |       dydy=76       |
61c       aycy=20    |       bydy=53    |       dydz=77       |
62c       aycz=21    |       bydz=54    |       dzdz=78       |
63c       azcx=22    |       bzdx=55    |                     |
64c       azcy=23    |       bzdy=56    |                     |
65c       azcz=24    |       bzdz=57    |                     |
66* block AD: (25-33)|                  |                     |
67c       axdx=25    |                  |                     |
68c       axdy=26    |                  |                     |
69c       axdz=27    |                  |                     |
70c       aydx=28    |                  |                     |
71c       aydy=29    |                  |                     |
72c       aydz=30    |                  |                     |
73c       azdx=31    |                  |                     |
74c       azdy=32    |                  |                     |
75c       azdz=33    |                  |                     |
76c------------------------------------------------------------
77#include "stdio.fh"
78#include "errquit.fh"
79#include "nwc_const.fh"
80#include "bas.fh"
81#include "basP.fh"
82#include "basdeclsP.fh"
83#include "geomP.fh"
84#include "geobasmapP.fh"
85#include "mafdecls.fh"
86#include "bas_exndcf_dec.fh"
87#include "bas_ibs_dec.fh"
88c
89c::external subroutines used
90c errquit
91c::functions
92      integer int_nint_cart
93      external int_nint_cart
94ckw
95      integer int_nint
96      external int_nint
97c
98      logical cando_nw
99      logical cando_txs
100      external cando_nw
101      external cando_txs
102ckw
103c::passed
104      integer brain !< [Input] basis set handle for bra basis
105      integer ish   !< [Input] lexical contraction index
106      integer ketin !< [Input] basis set handle for ket basis
107      integer jsh   !< [Input] lexical contraction index
108      integer lscr  !< [Input] length of scratch array
109      integer leri  !< [Input] length of eri array
110      double precision scr(lscr) !< [Scratch] scratch array for integral code.
111      double precision eri(leri) !< [Output]  array for two electron integral derivatives.
112c NOTE: length of idatom is always 4 because there can be at most 4 centers involved
113      integer idatom(4)          !< [Output]  array identifying centers for derivatives
114c
115c::local
116      integer nint, ucont
117      integer bra, ket, ab_geom, cd_geom
118      integer iatom
119      integer jatom
120c
121      double precision roff(3)
122      integer txs_i, txs_j, txs_k, txs_l
123      logical status_nw, status_txs
124      logical dum_log
125      integer nintzero, num_quart, dummy_lab
126      double precision q4
127ckw
128c
129      logical used_nw
130c
131#include "bas_exndcf_sfn.fh"
132#include "bas_ibs_sfn.fh"
133c
134      used_nw = .false.
135      nint = int_nint_cart(brain,ish,0, 0,ketin,jsh, 0,0)
136*
137      if (nint*78.gt.leri) then
138        write(luout,*) 'nint*78 = ',nint*78
139        write(luout,*) 'leri     = ',leri
140        call errquit('intdd_2e2c: nint>leri error',911, INT_ERR)
141      endif
142c
143      bra = brain + BASIS_HANDLE_OFFSET
144      ket = ketin + BASIS_HANDLE_OFFSET
145c
146      ab_geom = ibs_geom(bra)
147      cd_geom = ibs_geom(ket)
148      if (ab_geom.ne.cd_geom) then
149        write(luout,*)
150     &      'intdd_2e2c.F: two different geometries for',
151     &         ' derivatives?'
152        call errquit('intdd_2e2c: geom error ',911, INT_ERR)
153      endif
154c
155      ucont = (sf_ibs_cn2ucn(ish,bra))
156      iatom = (sf_ibs_cn2ce(ish,bra))
157      idatom(1)=iatom
158      idatom(2)=0
159c
160      ucont = (sf_ibs_cn2ucn(jsh,ket))
161      jatom = (sf_ibs_cn2ce(jsh,ket))
162      idatom(3)=jatom
163      idatom(4)=0
164c
165      if (iatom.eq.jatom) then
166        call dcopy((nint*78),0.0d00,0,eri,1)
167        call ifill(4,-1,idatom,1)
168        return
169      endif
170c
171      status_nw  = .false.
172      status_txs =.true.
173      status_txs = status_txs .and.
174     &    cando_txs(brain,ish,0).and.cando_txs(ketin,jsh,0)
175c
176      if (status_txs) then
177        call dcopy(3,0.0d00,0,roff,1)
178        q4 = 1.0d00
179        txs_i = ish
180        txs_j = 0
181        txs_k = jsh
182        txs_l = 0
183        num_quart=1
184        dum_log=.false.
185c
186        call texas_hf2_m(
187     &      brain,txs_i,txs_j,
188     &      ketin,txs_k,txs_l,num_quart,
189     &      q4,.false.,
190c...............................use roff set false
191     &      roff,roff,roff,roff,.false.,
192     &      eri, leri, dummy_lab, dummy_lab, dummy_lab, dummy_lab,
193c...............gen labs .. more_integrals
194     &      nint, .false., dum_log, scr, lscr, 0.0d0,'der2_int')
195        write(6,*)' intdd:2e2c:txshfm:nint = ',nint
196        if (nint .eq. 0) then
197          nintzero = int_nint(brain,ish,0,0,ketin,jsh, 0,0)
198          nintzero = nintzero*78
199          call dcopy(nintzero, 0.0d0, 0, eri, 1)
200          call ifill(4,-9,idatom,1)
201        endif
202c
203      else
204        write(luout,*)'intdd_2e2c: could not use the texas '
205        write(luout,*)'           integral second derivatives'
206        write(luout,*)' Please notify nwchem-support@emsl.pnl.gov with'
207        write(luout,*)'        the input deck and output available'
208        call errquit('intdd_2e2c: fatal error',911, INT_ERR)
209      endif
210c
211      end
212C> @}
213