diff --git a/src/gfnff/gfnff_eg.f90 b/src/gfnff/gfnff_eg.f90 index d7210e9c3..1fe2c4ab1 100644 --- a/src/gfnff/gfnff_eg.f90 +++ b/src/gfnff/gfnff_eg.f90 @@ -197,6 +197,7 @@ subroutine gfnff_eg(env,mol,pr,n,ichrg,at,xyz,sigma,g,etot,res_gff, & real(wp),allocatable :: xtmp(:) type(tb_timer) :: timer real(wp) :: dispthr, cnthr, repthr, hbthr1, hbthr2 + real(wp) :: dist(n,n) real(wp) :: ds(3,3) real(wp) :: convF !convergence factor alpha, aka ewald parameter logical, allocatable :: considered_ABH(:,:,:) @@ -225,9 +226,6 @@ subroutine gfnff_eg(env,mol,pr,n,ichrg,at,xyz,sigma,g,etot,res_gff, & ! get Distances between atoms for repulsion call neigh%getTransVec(env,mol,sqrt(repthr)) - if(allocated(neigh%distances)) deallocate(neigh%distances) - call getDistances(neigh%distances, mol, neigh) - g = 0 exb = 0 @@ -291,6 +289,18 @@ subroutine gfnff_eg(env,mol,pr,n,ichrg,at,xyz,sigma,g,etot,res_gff, & sqrab(ij + i) = 0.0d0 srab(ij + i) = 0.0d0 enddo + if (mol%npbc.ne.0) then + dist = 0.0_wp + !$omp parallel do collapse(2) default(none) shared(dist,mol) & + !$omp private(i,j) + do i=1, mol%n + do j=1, mol%n + dist(j,i) = NORM2(mol%xyz(:,j)-mol%xyz(:,i)) + enddo + enddo + !$omp end parallel do + endif + if (pr) call timer%measure(1) !----------! @@ -434,7 +444,7 @@ subroutine gfnff_eg(env,mol,pr,n,ichrg,at,xyz,sigma,g,etot,res_gff, & if (pr) call timer%measure(4) else if (pr) call timer%measure(4,'EEQ energy and q') - call goed_pbc_gfnff(env,mol,accuracy.gt.1,n,at,neigh%distances(:,:,1), & + call goed_pbc_gfnff(env,mol,accuracy.gt.1,n,at,dist, & & dfloat(ichrg),eeqtmp,cn,nlist%q,ees,solvation,param,topo, gTrans, & & rTrans, xtmp, convF) ! without dq/dr ees = ees*mcf_ees @@ -602,7 +612,7 @@ subroutine gfnff_eg(env,mol,pr,n,ichrg,at,xyz,sigma,g,etot,res_gff, & dx=xa-xyz(1,jat)-neigh%transVec(1,iTr) dy=ya-xyz(2,jat)-neigh%transVec(2,iTr) dz=za-xyz(3,jat)-neigh%transvec(3,iTr) - rab=neigh%distances(jat,iat,iTr) + rab=NORM2(xyz(:,iat)-(xyz(:,jat)+neigh%transVec(:,iTr))) r2=rab**2 ati=at(iat) atj=at(jat) @@ -734,8 +744,6 @@ subroutine gfnff_eg(env,mol,pr,n,ichrg,at,xyz,sigma,g,etot,res_gff, & call neigh%getTransVec(env,mol,sqrt(hbthr2)) if (pr) call timer%measure(10,'HB/XB (incl list setup)') if (update.or.require_update) then - if(allocated(neigh%distances)) deallocate(neigh%distances) - call getDistances(neigh%distances, mol, neigh) call gfnff_hbset(n,at,xyz,topo,neigh,nlist,hbthr1,hbthr2) end if @@ -781,12 +789,11 @@ subroutine gfnff_eg(env,mol,pr,n,ichrg,at,xyz,sigma,g,etot,res_gff, & nbk=0 iTr=0 ! nbk is the first neighbor of k ! atnb=0 - call neigh%jth_nb(nbk,1,k,iTr) + call neigh%jth_nb(n,xyz,nbk,1,k,iTr) ! get iTrC and cycle if out of cutoff (the cutoff used in last getTransVec call) iTrDum=neigh%fTrSum(iTr,iTrk) if(iTrDum.eq.-1.or.iTrDum.gt.neigh%nTrans) cycle ! get number neighbors of neighbor of k ! - if(nbk.le.0 .or. nbk.gt.n) write(*,*) 'nbk=',nbk if(nbk.ne.0) then nbnbk=sum(neigh%nb(neigh%numnb,nbk,:)) atnb=at(nbk) @@ -2283,7 +2290,7 @@ subroutine abhgfnff_eg2new(n,A,B,H,iTrA,iTrB,nbb,at,xyz,q,sqrab, & ! Neighbours of B do i=1,nbb inb=0; iTr=0 ! jth_nb output - call neigh%jth_nb(inb,i,B,iTr) ! inb is the i-th nb of B when inb is shifted to iTr + call neigh%jth_nb(n,xyz,inb,i,B,iTr) ! inb is the i-th nb of B when inb is shifted to iTr ! compute distances vecDum = neigh%transVec(:,iTr)+neigh%transVec(:,iTrB) dranb(1:3,i) = (xyz(1:3,A)+neigh%transVec(1:3,iTrA)) -(xyz(1:3,inb)+vecDum) @@ -2456,7 +2463,7 @@ subroutine abhgfnff_eg2new(n,A,B,H,iTrA,iTrB,nbb,at,xyz,q,sqrab, & gdr(1:3,H) = gdr(1:3,H) + gh(1:3) do i=1,nbb inb=0; iTr=0 ! jth_nb output - call neigh%jth_nb(inb,i,B,iTr) ! inb is the i-th nb of B when shifted to iTr + call neigh%jth_nb(n,xyz,inb,i,B,iTr) ! inb is the i-th nb of B when shifted to iTr gdr(1:3,inb) = gdr(1:3,inb) + gnb(1:3,i) end do @@ -2466,7 +2473,7 @@ subroutine abhgfnff_eg2new(n,A,B,H,iTrA,iTrB,nbb,at,xyz,q,sqrab, & sigma=sigma+mcf_ehb*spread(gh,1,3)*spread(xyz(:,H),2,3) do i=1,nbb inb=0; iTr=0 ! jth_nb output - call neigh%jth_nb(inb,i,B,iTr) ! inb is the i-th nb of B when shifted to iTr + call neigh%jth_nb(n,xyz,inb,i,B,iTr) ! inb is the i-th nb of B when shifted to iTr vecDum = neigh%transVec(:,iTr)+neigh%transVec(:,iTrB) sigma=sigma+mcf_ehb*spread(gnb(:,i),1,3)*spread(xyz(:,inb)+vecDum,2,3) enddo @@ -2543,7 +2550,7 @@ subroutine abhgfnff_eg2_rnr(n,A,B,H,iTrA,iTrB,at,xyz,q,sqrab,srab,energy,gdr,par ! Neighbours of B do i=1,nbb inb=0; iTr=0 ! jth_nb output - call neigh%jth_nb(inb,i,B,iTr) ! inb is the i-th nb of B when shifted to iTr + call neigh%jth_nb(n,xyz,inb,i,B,iTr) ! inb is the i-th nb of B when shifted to iTr ! compute distances vTrinb=neigh%transVec(:,iTr)+neigh%transVec(:,iTrB) dranb(1:3,i) = (xyz(1:3,A)+neigh%transVec(1:3,iTrA)) -(xyz(1:3,inb)+vTrinb) @@ -2753,7 +2760,7 @@ subroutine abhgfnff_eg2_rnr(n,A,B,H,iTrA,iTrB,at,xyz,q,sqrab,srab,energy,gdr,par gdr(1:3,H) = gdr(1:3,H) + gh(1:3) do i=1,nbb inb=0; iTr=0 ! jth_nb output - call neigh%jth_nb(inb,i,B,iTr) ! inb is the i-th nb of B when shifted to iTr + call neigh%jth_nb(n,xyz,inb,i,B,iTr) ! inb is the i-th nb of B when shifted to iTr gdr(1:3,inb) = gdr(1:3,inb) + gnb(1:3,i) - gnb_lp(1:3)/dble(nbb) end do @@ -2764,7 +2771,7 @@ subroutine abhgfnff_eg2_rnr(n,A,B,H,iTrA,iTrB,at,xyz,q,sqrab,srab,energy,gdr,par sigma=sigma+mcf_ehb*spread(gnb_lp,1,3)*spread(xyz(:,B)+neigh%transVec(1:3,iTrB),2,3) do i=1,nbb inb=0; iTr=0 ! jth_nb output - call neigh%jth_nb(inb,i,B,iTr) ! inb is the i-th nb of B when shifted to iTr + call neigh%jth_nb(n,xyz,inb,i,B,iTr) ! inb is the i-th nb of B when shifted to iTr vTrinb=neigh%transVec(:,iTr)+neigh%transVec(:,iTrB) sigma=sigma+mcf_ehb*spread(gnb(:,i),1,3)*spread(xyz(:,inb)+vTrinb,2,3) sigma=sigma-mcf_ehb*spread(gnb_lp(1:3)/dble(nbb),1,3)*spread(xyz(:,inb)+vTrinb,2,3) @@ -3267,8 +3274,8 @@ subroutine batmgfnff_eg(n,iat,jat,kat,iTrj,iTrk,at,xyz,q,sqrab,srab,energy,g,ds, real*8 r2ij,r2jk,r2ik,c9,mijk,imjk,ijmk,rijk3,ang,angr9,rav3 real*8 rij(3),rik(3),rjk(3),ri(3),rj(3),rk(3),drij,drik,drjk,dang,ff,fi,fj,fk,fqq parameter (fqq=3.0d0) - integer linij,linik,linjk,lina,i,j,iTrDum,dm1,dm2 - lina(i,j)=min(i,j)+max(i,j)*(max(i,j)-1)/2 + integer :: linij,linik,linjk,lina,i,j,iTrDum,dm1,dm2 + lina(i,j)=min(i,j)+max(i,j)*(max(i,j)-1)/2 fi=(1.d0-fqq*q(iat)) fi=min(max(fi,-4.0d0),4.0d0) @@ -3278,13 +3285,13 @@ subroutine batmgfnff_eg(n,iat,jat,kat,iTrj,iTrk,at,xyz,q,sqrab,srab,energy,g,ds, fk=min(max(fk,-4.0d0),4.0d0) ff=fi*fj*fk ! charge term c9=ff*param%zb3atm(at(iat))*param%zb3atm(at(jat))*param%zb3atm(at(kat)) ! strength of interaction - r2ij=neigh%distances(jat,iat,iTrj)**2 - r2ik=neigh%distances(kat,iat,iTrk)**2 + r2ij=NORM2(xyz(:,iat)-(xyz(:,jat)+neigh%transVec(:,iTrj)))**2 + r2ik=NORM2(xyz(:,iat)-(xyz(:,kat)+neigh%transVec(:,iTrk)))**2 iTrDum=neigh%fTrSum(neigh%iTrNeg(iTrj),iTrk) if(iTrDum.le.0.or.iTrDum.gt.neigh%numctr) then r2jk=NORM2((xyz(:,kat)+neigh%transVec(:,iTrk))-(xyz(:,jat)+neigh%transVec(:,iTrj)))**2 else - r2jk=neigh%distances(kat,jat,iTrDum)**2 !use adjusted iTr since jat is actually shifted + r2jk=NORM2(xyz(:,jat)-(xyz(:,kat)+neigh%transVec(:,iTrDum)))**2 endif mijk=-r2ij+r2jk+r2ik imjk= r2ij-r2jk+r2ik diff --git a/src/gfnff/gfnff_ini.f90 b/src/gfnff/gfnff_ini.f90 index f1b65be1f..a797a223b 100644 --- a/src/gfnff/gfnff_ini.f90 +++ b/src/gfnff/gfnff_ini.f90 @@ -206,19 +206,15 @@ integer function itabrow6(i) sqrab = 0 !Get all distances call neigh%getTransVec(env,mol,sqrt(hbthr2)) - if (.not. allocated(neigh%distances)) then - call getDistances(neigh%distances, mol, neigh) - endif ! Transfer calculated distances in central cell to rab and sqrab - ! want to change to neigh%distances do i=1, mol%n ati=mol%at(i) kk=i*(i-1)/2 do j=1, i-1 atj=mol%at(j) k=kk+j - rab(k) = neigh%distances(j,i,1) + rab(k) = NORM2(mol%xyz(:,i)-mol%xyz(:,j)) sqrab(k) = rab(k)**2 if(rab(k).lt.1.d-3) then write(env%unit,*) i,j,ati,atj,rab(k) @@ -404,7 +400,7 @@ integer function itabrow6(i) nn =sum(neigh%nb(neigh%numnb,i,:)) if(nn.eq.0) cycle ip =piadr2(i) - call neigh%jth_nb(ji,1,i,iTrtmp) ! ji is the first nb of i in cell iTr + call neigh%jth_nb(mol%n,mol%xyz,ji,1,i,iTrtmp) ! ji is the first nb of i in cell iTr nh =0 nm =0 do iTr=1, neigh%numctr @@ -858,7 +854,7 @@ integer function itabrow6(i) end do do i = 1,mol%n ! get first nb, iTr expected to be irrelevant since same in each cell - call neigh%jth_nb(nn,1,i,iTr) ! R - N/C/O - H ! terminal H + call neigh%jth_nb(mol%n,mol%xyz,nn,1,i,iTr) ! R - N/C/O - H ! terminal H if(nn.le.0) cycle ! cycle if there is no nb topo%hbaci(i)=param%xhaci(mol%at(i)) ! only first neighbor of interest if (amideH(mol%n,mol%at,topo%hyb,neigh%numnb,neigh%numctr,neigh%nb,piadr2,i,neigh)) & @@ -876,7 +872,7 @@ integer function itabrow6(i) if(mol%at(i).ne.1) cycle if(topo%hyb(i).eq.1) cycle ! exclude bridging hydrogens from HB correction ff=gen%hqabthr - call neigh%jth_nb(j,1,i,iTr) ! get j, first neighbor of H when j is shifted to iTr + call neigh%jth_nb(mol%n,mol%xyz,j,1,i,iTr) ! get j, first neighbor of H when j is shifted to iTr if(j.le.0) cycle if(mol%at(j).gt.10) ff=ff-0.20 ! H on heavy atoms may be negatively charged if(mol%at(j).eq.6.and.topo%hyb(j).eq.3) ff=ff+0.05 ! H on sp3 C must be really positive 0.05 @@ -1038,7 +1034,7 @@ integer function itabrow6(i) ja=piadr4(jj) if(ia.gt.0.and.ja.gt.0) then !dum=1.d-9*rab(lin(ii,jj)) ! distort so that Huckel for e.g. COT localizes to right bonds - dum=1.d-9*neigh%distances(jj,ii,iTr) ! distort so that Huckel for e.g. COT localizes to right bonds + dum=1.d-9*NORM2(mol%xyz(:,ii)-(mol%xyz(:,jj)+neigh%transVec(:,iTr))) ! distort so that Huckel for e.g. COT localizes to right bonds dum=sqrt(gen%hoffdiag(mol%at(ii))*gen%hoffdiag(mol%at(jj)))-dum ! better than arithmetic dum2=gen%hiter if(topo%hyb(ii).eq.1) dum2=dum2*gen%htriple ! triple bond is different @@ -2065,16 +2061,16 @@ integer function itabrow6(i) endif deallocate(locarr) ! sort atoms according to distance to central atom such that the same inversion angle def. always results - sdum3(1)=neigh%distances(jj,i,iTrj) - sdum3(2)=neigh%distances(kk,i,iTrk) - sdum3(3)=neigh%distances(ll,i,iTrl) + sdum3(1)=NORM2(mol%xyz(:,i)-(mol%xyz(:,jj)+neigh%transVec(:,iTrj))) + sdum3(2)=NORM2(mol%xyz(:,i)-(mol%xyz(:,kk)+neigh%transVec(:,iTrk))) + sdum3(3)=NORM2(mol%xyz(:,i)-(mol%xyz(:,ll)+neigh%transVec(:,iTrl))) ind3(1)=jj ind3(2)=kk ind3(3)=ll call ssort(3,sdum3,ind3) - sdum3(1)=neigh%distances(jj,i,iTrj) ! need old indices for sorting iTr's - sdum3(2)=neigh%distances(kk,i,iTrk) - sdum3(3)=neigh%distances(ll,i,iTrl) + sdum3(1)=NORM2(mol%xyz(:,i)-(mol%xyz(:,jj)+neigh%transVec(:,iTrj))) + sdum3(2)=NORM2(mol%xyz(:,i)-(mol%xyz(:,kk)+neigh%transVec(:,iTrk))) + sdum3(3)=NORM2(mol%xyz(:,i)-(mol%xyz(:,ll)+neigh%transVec(:,iTrl))) jj=ind3(1) ! assign sorted indices kk=ind3(2) ll=ind3(3) @@ -2163,7 +2159,7 @@ integer function itabrow6(i) if (mol%at(i).eq.6.and.sum(neigh%nb(neigh%numnb,i,:)).eq.2) then do j=1, 2 nbi=0 - call neigh%jth_nb(nbi,j,i,iTr) ! nbi is the jth nb of i in cell iTr + call neigh%jth_nb(mol%n,mol%xyz,nbi,j,i,iTr) ! nbi is the jth nb of i in cell iTr if (nbi.eq.0) cycle if (mol%at(nbi).eq.6.and.sum(neigh%nb(neigh%numnb,nbi,:)).eq.2) then nn = nn + 1 @@ -2222,7 +2218,7 @@ subroutine specialTorsList(nst, mol, topo, neigh, sTorsList) ! carbon with two neighbors bonded to other carbon* with two neighbors if (mol%at(i).eq.6.and.sum(neigh%nb(neigh%numnb,i,:)).eq.2) then do j=1, 2 - call neigh%jth_nb(nbi,j,i,iTr) ! nbi is the jth nb of i in cell iTr + call neigh%jth_nb(mol%n,mol%xyz,nbi,j,i,iTr) ! nbi is the jth nb of i in cell iTr if (nbi.eq.0.or.iTr.eq.0) cycle if (mol%at(nbi).eq.6.and.sum(neigh%nb(neigh%numnb,nbi,:)).eq.2) then ! *other carbon ! check carbon triple bond distance @@ -2231,14 +2227,14 @@ subroutine specialTorsList(nst, mol, topo, neigh, sTorsList) ! check C2 and C3 do k=1, 2 ! C2 is other nb of Ci nbk=0 - call neigh%jth_nb(nbk,k,i,iTr) ! nbk is the jth nb of i in cell iTr .ne.nbi + call neigh%jth_nb(mol%n,mol%xyz,nbk,k,i,iTr) ! nbk is the jth nb of i in cell iTr .ne.nbi if (nbk.ne.nbi.and.nbk.ne.0.and.mol%at(nbk).eq.6) then jj=nbk ! C2 index endif enddo do k=1, 2 ! C3 is other nb of Cnbi nbk=0 - call neigh%jth_nb(nbk,k,nbi,iTr) ! nbk is the jth nb of i in cell iTr .ne.nbi + call neigh%jth_nb(mol%n,mol%xyz,nbk,k,nbi,iTr) ! nbk is the jth nb of i in cell iTr .ne.nbi if (nbk.ne.i.and.nbk.ne.0.and.mol%at(nbk).eq.6) then kk=nbk ! C3 index endif @@ -2255,7 +2251,7 @@ subroutine specialTorsList(nst, mol, topo, neigh, sTorsList) ! on atom sorting in input file !!! The last one in file. do k=1, sum(neigh%nb(neigh%numnb,jj,:)) nbk=0 - call neigh%jth_nb(nbk,k,jj,iTr) ! nbk is the jth nb of i in cell iTr .ne.nbi + call neigh%jth_nb(mol%n,mol%xyz,nbk,k,jj,iTr) ! nbk is the jth nb of i in cell iTr .ne.nbi if (topo%hyb(k).eq.2.and.mol%at(k).eq.6.and.sum(neigh%nb(neigh%numnb,k,:)).eq.3.and. & & nbk.ne.i.and.nbk.ne.0) then ii=nbk @@ -2266,7 +2262,7 @@ subroutine specialTorsList(nst, mol, topo, neigh, sTorsList) ! on atom sorting in input file !!! The last one in file. do k=1, sum(neigh%nb(neigh%numnb,kk,:)) nbk=0 - call neigh%jth_nb(nbk,k,jj,iTr) ! nbk is the jth nb of i in cell iTr .ne.nbi + call neigh%jth_nb(mol%n,mol%xyz,nbk,k,jj,iTr) ! nbk is the jth nb of i in cell iTr .ne.nbi if (topo%hyb(k).eq.2.and.mol%at(k).eq.6.and.sum(neigh%nb(neigh%numnb,i,:)).eq.3.and. & & nbk.ne.nbi.and.nbk.ne.0) then ll=nbk diff --git a/src/gfnff/gfnff_ini2.f90 b/src/gfnff/gfnff_ini2.f90 index d335eabad..e0a70da3e 100644 --- a/src/gfnff/gfnff_ini2.f90 +++ b/src/gfnff/gfnff_ini2.f90 @@ -343,7 +343,7 @@ subroutine gfnff_neigh(env,makeneighbor,natoms,at,xyz,rab,fq,f_in,f2_in,lintr, & if(nb20i.gt.3.and.ati.gt.10.and.nbdiff.eq.0) hyb(i)=5 if(nb20i.eq.2) hyb(i)=3 if(nb20i.eq.2.and.nbmdiff.gt.0) then - call nn_nearest_noM(i,natoms,at,neigh,rab,j,param) ! CN of closest non-M atom + call nn_nearest_noM(i,natoms,at,mol%xyz,neigh,rab,j,param) ! CN of closest non-M atom if(j.eq.3) hyb(i)=2 ! M-O-X konj if(j.eq.4) hyb(i)=3 ! M-O-X non endif @@ -469,27 +469,32 @@ end subroutine getnb ! find the CN of the non metal atom that is closest to atom i !ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc - subroutine nn_nearest_noM(ii,n,at,neigh,r,nn,param) + subroutine nn_nearest_noM(ii,n,at,xyz,neigh,r,nn,param) + use xtb_mctc_accuracy, only : wp implicit none type(TGFFData), intent(in) :: param type(TNeigh), intent(in) :: neigh integer, intent(in) :: ii,n,at(n) + real(wp), intent(in) :: xyz(3,n) integer, intent(inout) :: nn real*8, intent(in) :: r(n*(n+1)/2) integer jmin,j,jj,lin, numnb, iTr + real(wp) :: dist real*8 rmin numnb=neigh%numnb nn=0 rmin=1.d+42 jmin=0 + dist=0.0 do iTr=1, neigh%numctr do j=1,neigh%nb(numnb,ii,iTr) jj=neigh%nb(j,ii,iTr) if(param%metal(at(jj)).ne.0) cycle - if(neigh%distances(jj,ii,iTr).lt.rmin)then - rmin=neigh%distances(jj,ii,iTr) + dist = NORM2(xyz(:,ii)-(xyz(:,jj)+neigh%transVec(:,iTr))) + if(dist.lt.rmin)then + rmin=dist jmin=jj endif enddo @@ -786,29 +791,22 @@ subroutine gfnff_hbset(n,at,xyz,topo,neigh,nlist,hbthr1,hbthr2) ! get adjustet iTr -> for use of neigh% distances and bpair with two shifted atoms iTrDum=neigh%fTrSum(neigh%iTrNeg(iTri),iTrj) if(iTrDum.gt.neigh%nTrans.or.iTrDum.lt.-1.or.iTrDum.eq.0) cycle ! cycle nonsense - if(iTrDum.eq.-1) then - rab=NORM2((xyz(:,i)+neigh%transVec(:,iTri))-(xyz(:,j)+neigh%transVec(:,iTrj)))**2 - if(rab.gt.hbthr1) cycle - ijnonbond=.true. ! i and j are not in neighboring or same cell for iTrDum=-1 + rab=NORM2((xyz(:,i)+neigh%transVec(:,iTri))-(xyz(:,j)+neigh%transVec(:,iTrj)))**2 + if(rab.gt.hbthr1) cycle + ! check if ij bonded + if(iTrDum.le.neigh%numctr.and.iTrDum.gt.0) then + ijnonbond=neigh%bpair(j,i,iTrDum).ne.1 else - ! check ij distance - rab=neigh%distances(j,i,iTrDum)**2 ! %distances are generated up to hbthr2 - if(rab.gt.hbthr1) cycle - ! check if ij bonded - if(iTrDum.le.neigh%numctr) then - ijnonbond=neigh%bpair(j,i,iTrDum).ne.1 - else - ! i and j are not in neighboring cells - ijnonbond=.true. - endif + ! i and j are not in neighboring cells + ijnonbond=.true. endif ! loop over relevant H atoms do k=1,topo%nathbH free=.true. ! tripplet not assigned yet nh =topo%hbatHl(1,k) ! nh always in central cell ! distances for non-cov bonded case - rih=neigh%distances(i,nh,iTri)**2 - rjh=neigh%distances(j,nh,iTrj)**2 + rih=NORM2(xyz(:,nh)-(xyz(:,i)+neigh%transVec(:,iTri)))**2 + rjh=NORM2(xyz(:,nh)-(xyz(:,j)+neigh%transVec(:,iTrj)))**2 ! check if i is the bonded A if(iTri.le.neigh%numctr) then ! nh is not shifted so bpair works without adjustment if(neigh%bpair(i,nh,iTri).eq.1.and.ijnonbond) then @@ -902,16 +900,14 @@ subroutine bond_hbset(n,at,xyz,npbc,bond_hbn,bond_hbl,topo,neigh,hbthr1,hbthr2) do iTri=1,neigh%nTrans do iTrj=1,neigh%nTrans iTrDum=neigh%fTrSum(neigh%iTrNeg(iTri),iTrj) - if(iTrDum.eq.-1.or.iTrDum.gt.neigh%numctr) then - rab=NORM2((xyz(:,i)+neigh%transVec(:,iTri))-(xyz(:,j)+neigh%transVec(:,iTrj)))**2 - if(rab.gt.hbthr1) cycle - ijnonbond=.true. ! i and j are not in neighboring cells for this range of iTrDum - else - ! check ij distance - rab=neigh%distances(j,i,iTrDum)**2 ! %distances are generated up to hbthr2 - if(rab.gt.hbthr1) cycle - ! check if ij bonded + rab=NORM2((xyz(:,i)+neigh%transVec(:,iTri))-(xyz(:,j)+neigh%transVec(:,iTrj)))**2 + if(rab.gt.hbthr1) cycle + ! check if ij bonded + if(iTrDum.le.neigh%numctr.and.iTrDum.gt.0) then ijnonbond=neigh%bpair(j,i,iTrDum).ne.1 + else + ! i and j are not in neighboring cells + ijnonbond=.true. endif ! loop over relevant H atoms do k=1,topo%nathbH @@ -983,7 +979,7 @@ subroutine bond_hbset0(n,at,xyz,npbc,bond_hbn,topo,neigh,hbthr1,hbthr2) ijnonbond=.true. ! i and j are not in neighboring or same cell for iTrDum=-1 else ! check ij distance - rab=neigh%distances(j,i,iTrDum)**2 + rab=NORM2(xyz(:,i)-(xyz(:,j)+neigh%transVec(:,iTrDum)))**2 if(rab.gt.hbthr1) cycle ! check if ij bonded ijnonbond=neigh%bpair(j,i,iTrDum).ne.1 @@ -1295,15 +1291,15 @@ subroutine gfnff_hbset0(n,at,xyz,topo,nhb1,nhb2,nxb,neigh,nlist,hbthr1,hbthr2) if(rab.gt.hbthr1) cycle ijnonbond=.true. ! i and j are not in neighboring or same cell for iTrDum=-1 else - ! check ij distance - rab=neigh%distances(j,i,iTrDum)**2 ! %distances are generated up to hbthr2 + ! check + rab=NORM2(xyz(:,i)-(xyz(:,j)+neigh%transVec(:,iTrDum)))**2 if(rab.gt.hbthr1) cycle ! check if ij bonded if(iTrDum.le.neigh%numctr) then ijnonbond=neigh%bpair(j,i,iTrDum).ne.1 else ! i and j are not in neighboring cells - ijnonbond=.true. + ijnonbond=.true. endif endif ! loop over relevant H atoms @@ -1311,8 +1307,8 @@ subroutine gfnff_hbset0(n,at,xyz,topo,nhb1,nhb2,nxb,neigh,nlist,hbthr1,hbthr2) free=.true. nh =topo%hbatHl(1,k) ! nh always in central cell ! distances for non-cov bonded case - rih=neigh%distances(i,nh,iTri)**2 - rjh=neigh%distances(j,nh,iTrj)**2 + rih=NORM2(xyz(:,nh)-(xyz(:,i)+neigh%transVec(:,iTri)))**2 + rjh=NORM2(xyz(:,nh)-(xyz(:,j)+neigh%transVec(:,iTrj)))**2 ! check if i is the bonded A if(iTri.le.neigh%numctr) then ! nh is not shifted so bpair works without adjustment if(neigh%bpair(i,nh,iTri).eq.1.and.ijnonbond) then @@ -1341,7 +1337,7 @@ subroutine gfnff_hbset0(n,at,xyz,topo,nhb1,nhb2,nxb,neigh,nlist,hbthr1,hbthr2) i =topo%xbatABl(1,ix) j =topo%xbatABl(2,ix) iTrj=topo%xbatABl(4,ix) - rab=neigh%distances(j,i,iTrj)**2 ! %distances are generated up to hbthr2 + rab=NORM2(xyz(:,i)-(xyz(:,j)+neigh%transVec(:,iTrj)))**2 if(rab.gt.hbthr2)cycle nxb=nxb+1 !enddo diff --git a/src/gfnff/neighbor.f90 b/src/gfnff/neighbor.f90 index 81c3aa086..843d80cf0 100644 --- a/src/gfnff/neighbor.f90 +++ b/src/gfnff/neighbor.f90 @@ -9,7 +9,7 @@ module xtb_gfnff_neighbor implicit none private - public :: TNeigh, getDistances + public :: TNeigh !> Neighbor lists type :: TNeigh @@ -24,7 +24,7 @@ module xtb_gfnff_neighbor integer, allocatable :: bpair(:,:,:) integer, allocatable :: molbpair(:) ! distances of all atoms to all atoms in central 27 cells - real(wp), allocatable :: distances(:,:,:) + !real(wp), allocatable :: distances(:,:,:) !> Maximum number of neighbors per atom ! where nb(numnb,i,transVec) is the num of neigh atom i has in cell transVec integer :: numnb = 42 @@ -115,11 +115,21 @@ subroutine get_nb(self, mol, rab, rtmp, mchar, icase, f_in, f2_in, param) !integer, intent(inout) :: nbf(20,mol%n) type(TGFFData), intent(in) :: param !real(wp) :: latThresh, maxNBr - integer :: n - - n = mol%n + real(wp) :: dist(mol%n,mol%n,self%numctr) + integer :: i,j,iTr - call fillnb(self,n,mol%at,rtmp,self%distances,mchar,icase,f_in,f2_in,param) + dist=0.0_wp + !$omp parallel do collapse(3) default(none) shared(dist,mol,self) & + !$omp private(iTr,i,j) + do iTr=1, self%numctr + do i=1, mol%n + do j=1, mol%n + dist(j,i,iTr) = NORM2(mol%xyz(:,i)-(mol%xyz(:,j)+self%transVec(:,iTr))) + enddo + enddo + enddo + !$omp end parallel do + call fillnb(self,mol%n,mol%at,rtmp,dist,mchar,icase,f_in,f2_in,param) end subroutine get_nb @@ -390,26 +400,6 @@ function id2v(self,mol,id) result(vector) end function id2v - subroutine getDistances(distances, mol, neigh) - real(wp), allocatable, intent(out) :: distances(:,:,:) - class(TNeigh), intent(in) :: neigh - type(TMolecule), intent(in) :: mol - integer :: i,j, iTr, n - - n=mol%n - allocate(distances(n,n,neigh%nTrans), source=0.0_wp) - - do iTr=1, neigh%nTrans - do i=1, n - do j=1, n - distances(j,i,iTr) = vecNorm(mol%xyz(:,j)-mol%xyz(:,i)+neigh%transVec(:,iTr)) - enddo - enddo - enddo - - - end subroutine getDistances - ! is a modified "getnb" from gfnff_ini2.f90 subroutine fillnb(self,n,at,rad,dist,mchar,icase,f,f2,param) implicit none @@ -417,8 +407,8 @@ subroutine fillnb(self,n,at,rad,dist,mchar,icase,f,f2,param) class(TNeigh), intent(inout) :: self integer, intent(in) :: n,at(n) real(wp), intent(in) :: rad(n*(n+1)/2) - real(wp), intent(in) :: mchar(n),f,f2 real(wp), intent(in) :: dist(n,n,self%numctr) + real(wp), intent(in) :: mchar(n),f,f2 integer i,j,k,iTr,nn,icase,hc_crit,nnfi,nnfj,lin integer tag(n,n,self%numctr) real(wp) rco,fm @@ -548,8 +538,10 @@ subroutine nbLoc(self, n, nblist, indexi, locarr) ! gives index j of the jth neighbor of i and the corresp transVec index iTr - subroutine jth_nb(self, j, jth, i, iTr) + subroutine jth_nb(self, n, xyz, j, jth, i, iTr) class(TNeigh), intent(inout) :: self + integer, intent(in) :: n + real(wp), intent(in) :: xyz(3,n) integer, intent(inout) :: j, iTr integer, intent(in) :: jth, i integer :: k, l, iTrdum, sizenb, sizeindx, jdum @@ -567,7 +559,7 @@ subroutine jth_nb(self, j, jth, i, iTr) do k=1, self%nb(self%numnb,i,iTrdum) jdum = self%nb(k,i,iTrdum) l=l+1 - distnb(l) = self%distances(jdum,i,iTrdum) + distnb(l) = NORM2(xyz(:,i)-(xyz(:,jdum)+self%transVec(:,iTrDum))) enddo enddo