Skip to content

Commit

Permalink
remove _env suffixes in crystalmod environment routines
Browse files Browse the repository at this point in the history
  • Loading branch information
aoterodelaroza committed Feb 14, 2024
1 parent 3f9b2cc commit f1f4872
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 80 deletions.
4 changes: 2 additions & 2 deletions src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -1335,10 +1335,10 @@ function structvareval(svar,fder,errmsg,x0,syl,periodic) result(q)
errmsg = 'atom ID in rho0nuc structural variable out of range'
return
end if
call syl%c%nearest_atom_env(x0,icrd_cart,nid0,dist,lvec=lvec,id0=nid)
call syl%c%nearest_atom(x0,icrd_cart,nid0,dist,lvec=lvec,id0=nid)
if (nid /= nid0) return ! fixme: the atom was too far
else
call syl%c%nearest_atom_env(x0,icrd_cart,nid,dist,lvec=lvec)
call syl%c%nearest_atom(x0,icrd_cart,nid,dist,lvec=lvec)
end if

if (nid == 0) then
Expand Down
2 changes: 1 addition & 1 deletion src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module subroutine bader_integrate(s,bas,iref)
! check if it is an atom (use ratom)
isassigned = .false.
if (bas%atexist) then
nid = s%c%identify_atom_env(dv,icrd_crys,distmax=bas%ratom)
nid = s%c%identify_atom(dv,icrd_crys,distmax=bas%ratom)
if (nid > 0) then
path_volnum = nid
isassigned = .true.
Expand Down
44 changes: 10 additions & 34 deletions src/crystalmod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ module crystalmod
! core charges
integer :: zpsp(maxzat0)

!! Initialization level: isenv !!
! atomic environment of the cell
integer :: nblock(3) ! number of environemt blocks
integer,allocatable :: iblock0(:,:,:) ! starting atomic index for each block
real*8 :: blockrmax ! radius of the largest sphere contained in a block
real*8 :: blockomega ! volume of a block
real*8 :: blockcv(3) ! cross products of the block lattice vectors

!! Initialization level: isast !!
! asterisms
type(neighstar), allocatable :: nstar(:) !< Neighbor stars
integer :: nmol = 0 !< Number of molecules in the unit cell
Expand Down Expand Up @@ -180,9 +178,9 @@ module crystalmod
! atomic environments and distance calculations
procedure :: build_env
procedure :: list_near_atoms
procedure :: nearest_atom_env
procedure :: identify_atom_env
procedure :: promolecular_env
procedure :: nearest_atom
procedure :: identify_atom
procedure :: promolecular_atom
procedure :: find_asterisms_covalent
procedure :: list_near_lattice_points
procedure :: nearest_lattice_point
Expand Down Expand Up @@ -359,33 +357,11 @@ module function are_lclose(c,x0,x1,eps,dd)
real*8, intent(out), optional :: dd
logical :: are_lclose
end function are_lclose
module subroutine nearest_atom(c,xp,icrd,nid,dist,distmax,lvec,cidx0,idx0,is0,nozero)
class(crystal), intent(in) :: c
real*8, intent(in) :: xp(3)
integer, intent(in) :: icrd
integer, intent(out) :: nid
real*8, intent(out) :: dist
real*8, intent(in), optional :: distmax
integer, intent(out), optional :: lvec(3)
integer, intent(in), optional :: cidx0
integer, intent(in), optional :: idx0
integer, intent(in), optional :: is0
logical, intent(in), optional :: nozero
end subroutine nearest_atom
module subroutine nearest_atom_grid(c,n,idg)
class(crystal), intent(inout) :: c
integer, intent(in) :: n(3)
integer, allocatable, intent(inout) :: idg(:,:,:)
end subroutine nearest_atom_grid
module function identify_atom(c,x0,icrd,lvec,dist,distmax)
class(crystal), intent(in) :: c
real*8, intent(in) :: x0(3)
integer, intent(in) :: icrd
integer, intent(out), optional :: lvec(3)
real*8, intent(out), optional :: dist
real*8, intent(in), optional :: distmax
integer :: identify_atom
end function identify_atom
module function identify_spc(c,str) result(res)
use crystalseedmod, only: crystalseed
class(crystal), intent(inout) :: c
Expand Down Expand Up @@ -417,7 +393,7 @@ module subroutine list_near_atoms(c,xp,icrd,sorted,nat,eid,dist,lvec,ishell0,up2
integer, intent(in), optional :: ispc0
logical, intent(in), optional :: nozero
end subroutine list_near_atoms
module subroutine nearest_atom_env(c,xp,icrd,nid,dist,distmax,lvec,nid0,id0,iz0,ispc0,nozero)
module subroutine nearest_atom(c,xp,icrd,nid,dist,distmax,lvec,nid0,id0,iz0,ispc0,nozero)
class(crystal), intent(inout) :: c
real*8, intent(in) :: xp(3)
integer, intent(in) :: icrd
Expand All @@ -430,17 +406,17 @@ module subroutine nearest_atom_env(c,xp,icrd,nid,dist,distmax,lvec,nid0,id0,iz0,
integer, intent(in), optional :: iz0
integer, intent(in), optional :: ispc0
logical, intent(in), optional :: nozero
end subroutine nearest_atom_env
module function identify_atom_env(c,x0,icrd,lvec,dist,distmax)
end subroutine nearest_atom
module function identify_atom(c,x0,icrd,lvec,dist,distmax)
class(crystal), intent(inout) :: c
real*8, intent(in) :: x0(3)
integer, intent(in) :: icrd
integer, intent(out), optional :: lvec(3)
real*8, intent(out), optional :: dist
real*8, intent(in), optional :: distmax
integer :: identify_atom_env
end function identify_atom_env
module subroutine promolecular_env(c,x0,icrd,f,fp,fpp,nder,zpsp,fr)
integer :: identify_atom
end function identify_atom
module subroutine promolecular_atom(c,x0,icrd,f,fp,fpp,nder,zpsp,fr)
use fragmentmod, only: fragment
class(crystal), intent(inout) :: c
real*8, intent(in) :: x0(3)
Expand All @@ -451,7 +427,7 @@ module subroutine promolecular_env(c,x0,icrd,f,fp,fpp,nder,zpsp,fr)
integer, intent(in) :: nder
integer, intent(in), optional :: zpsp(:)
type(fragment), intent(in), optional :: fr
end subroutine promolecular_env
end subroutine promolecular_atom
module subroutine find_asterisms_covalent(c)
class(crystal), intent(inout) :: c
end subroutine find_asterisms_covalent
Expand Down
4 changes: 2 additions & 2 deletions src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ module function ewald_pot(c,x)
end if

! is this a nuclear position? -> get charge
idnuc = c%identify_atom_env(x,icrd_crys)
idnuc = c%identify_atom(x,icrd_crys)
if (idnuc > 0) then
qnuc = c%spc(c%atcel(idnuc)%is)%qat
else
Expand Down Expand Up @@ -268,7 +268,7 @@ module subroutine promolecular_grid(c,f,n,zpsp,fr)
do j = 1, n(2)
do i = 1, n(1)
x = (i-1) * xdelta(:,1) + (j-1) * xdelta(:,2) + (k-1) * xdelta(:,3)
call c%promolecular_env(x,icrd_crys,rho,rdum1,rdum2,0,zpsp,fr)
call c%promolecular_atom(x,icrd_crys,rho,rdum1,rdum2,0,zpsp,fr)

!$omp critical(write)
f%f(i,j,k) = rho
Expand Down
4 changes: 2 additions & 2 deletions src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ module subroutine wholemols(c,ti)
if (ldone(c%atcel(k)%idx)) cycle

x0 = matmul(c%rotm(1:3,1:3,i),c%atcel(k)%x) + c%rotm(:,4,i) + c%cen(:,j)
id = c%identify_atom_env(x0,icrd_crys)
id = c%identify_atom(x0,icrd_crys)

if (id == 0) &
call ferror('wholemols','error identifying rotated atom',faterr)
Expand Down Expand Up @@ -649,7 +649,7 @@ module subroutine wholemols(c,ti)
if (.not.sgroup(j,ig)) cycle
do k = 1, c%ncv
x0 = matmul(c%rotm(1:3,1:3,j),c%atcel(i)%x) + c%rotm(:,4,j) + c%cen(:,k)
id = c%identify_atom_env(x0,icrd_crys)
id = c%identify_atom(x0,icrd_crys)
if (id == 0) &
call ferror('wholemols','error identifying rotated atom',faterr)
isuse(id) = .true.
Expand Down
18 changes: 9 additions & 9 deletions src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ end subroutine list_near_atoms
!> - nozero = disregard zero-distance atoms.
!>
!> This routine is thread-safe.
module subroutine nearest_atom_env(c,xp,icrd,nid,dist,distmax,lvec,nid0,id0,iz0,ispc0,nozero)
module subroutine nearest_atom(c,xp,icrd,nid,dist,distmax,lvec,nid0,id0,iz0,ispc0,nozero)
class(crystal), intent(inout) :: c
real*8, intent(in) :: xp(3)
integer, intent(in) :: icrd
Expand Down Expand Up @@ -553,44 +553,44 @@ module subroutine nearest_atom_env(c,xp,icrd,nid,dist,distmax,lvec,nid0,id0,iz0,
dist = dist_(1)
if (present(lvec)) lvec = lvec_(:,1)

end subroutine nearest_atom_env
end subroutine nearest_atom

!> Given point x0 (with icrd input coordinates), if x0 corresponds
!> to an atomic position (to within distmax or atomeps if distmax is
!> not given), return the complete-list ID of the atom. Otherwise,
!> return 0. Optionally, return the lattice vector translation
!> (lvec) and the distance (dist) to the closest atom. This routine
!> is thread-safe.
module function identify_atom_env(c,x0,icrd,lvec,dist,distmax)
module function identify_atom(c,x0,icrd,lvec,dist,distmax)
use global, only: atomeps
class(crystal), intent(inout) :: c
real*8, intent(in) :: x0(3)
integer, intent(in) :: icrd
integer, intent(out), optional :: lvec(3)
real*8, intent(out), optional :: dist
real*8, intent(in), optional :: distmax
integer :: identify_atom_env
integer :: identify_atom

real*8 :: distmax_, dist0
integer :: lvec0(3)

identify_atom_env = 0
identify_atom = 0
distmax_ = atomeps
if (present(distmax)) distmax_ = distmax

call c%nearest_atom_env(x0,icrd,identify_atom_env,dist0,distmax=distmax_,lvec=lvec0)
call c%nearest_atom(x0,icrd,identify_atom,dist0,distmax=distmax_,lvec=lvec0)
if (present(lvec)) lvec = lvec0
if (present(dist)) dist = dist0

end function identify_atom_env
end function identify_atom

!> Calculate the core (if zpsp is present) or promolecular densities
!> at a point x0 (coord format given by icrd) using atomic radial
!> grids up to a number of derivatives nder (max: 2). Returns the
!> density (f), gradient (fp, nder >= 1), and Hessian (fpp, nder >=
!> 2). If a fragment (fr) is given, then only the atoms in it
!> contribute. This routine is thread-safe.
module subroutine promolecular_env(c,x0,icrd,f,fp,fpp,nder,zpsp,fr)
module subroutine promolecular_atom(c,x0,icrd,f,fp,fpp,nder,zpsp,fr)
use grid1mod, only: cgrid, agrid, grid1
use global, only: cutrad
use fragmentmod, only: fragment
Expand Down Expand Up @@ -721,7 +721,7 @@ module subroutine promolecular_env(c,x0,icrd,f,fp,fpp,nder,zpsp,fr)

if (allocated(isinfr)) deallocate(isinfr)

end subroutine promolecular_env
end subroutine promolecular_atom

!> Find the covalent bond connectivity and return the bonds in the
!> c%nstar array.
Expand Down
4 changes: 2 additions & 2 deletions src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module function identify_fragment(c,nat,x0) result(fr)

n = 0
do i = 1, nat
id = c%identify_atom_env(x0(:,i),icrd_cart)
id = c%identify_atom(x0(:,i),icrd_cart)
if (id > 0) then
n = n + 1
fr%at(n)%r = x0(:,i)
Expand Down Expand Up @@ -90,7 +90,7 @@ module function identify_fragment_from_xyz(c,file,errmsg,ti) result(fr)
do i = 1, nat
read(lu,*,err=999,end=999) word, x0
x0 = x0 / bohrtoa - c%molx0
id = c%identify_atom_env(x0,icrd_cart)
id = c%identify_atom(x0,icrd_cart)
if (id == 0) then
fr%nat = 0
deallocate(fr%at)
Expand Down
4 changes: 2 additions & 2 deletions src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ module subroutine struct_new(c,seed,crashfail,noenv,ti)
! Write the half nearest-neighbor distance
do i = 1, c%nneq
if (.not.c%ismolecule .or. c%ncel > 1) then
call c%nearest_atom_env(c%at(i)%r,icrd_cart,iat,dist,nozero=.true.)
call c%nearest_atom(c%at(i)%r,icrd_cart,iat,dist,nozero=.true.)
c%at(i)%rnn2 = 0.5d0 * dist
else
c%at(i)%rnn2 = 0d0
Expand Down Expand Up @@ -816,7 +816,7 @@ module subroutine nearest_atom_grid(c,n,idg)
do j = 1, n(2)
do i = 1, n(1)
x = (i-1) * xdelta(:,1) + (j-1) * xdelta(:,2) + (k-1) * xdelta(:,3)
call c%nearest_atom_env(x,icrd_crys,nid,dist)
call c%nearest_atom(x,icrd_crys,nid,dist)
!$omp critical(write)
idg(i,j,k) = nid
!$omp end critical(write)
Expand Down
2 changes: 1 addition & 1 deletion src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ module subroutine rho2(f,vpl,nder,frho,gfrho,hfrho)
frho = 0d0
gfrho = 0d0
hfrho = 0d0
call c%nearest_atom_env(vpl,icrd_crys,nid,dist,lvec=lvec)
call c%nearest_atom(vpl,icrd_crys,nid,dist,lvec=lvec)

! inside a muffin tin
inmt = (nid > 0)
Expand Down
18 changes: 9 additions & 9 deletions src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -876,11 +876,11 @@ recursive module subroutine grd(f,v,nder,res,fder,periodic)
! all work done in Cartesians in a finite environment.

case(type_promol)
call f%c%promolecular_env(wcr,icrd_cart,res%f,res%gf,res%hf,nder)
call f%c%promolecular_atom(wcr,icrd_cart,res%f,res%gf,res%hf,nder)
! not needed because grd_atomic uses struct.

case(type_promol_frag)
call f%c%promolecular_env(wcr,icrd_cart,res%f,res%gf,res%hf,nder,fr=f%fr)
call f%c%promolecular_atom(wcr,icrd_cart,res%f,res%gf,res%hf,nder,fr=f%fr)
! not needed because grd_atomic uses struct.

case(type_ghost)
Expand All @@ -903,7 +903,7 @@ recursive module subroutine grd(f,v,nder,res,fder,periodic)

! augment with the core if applicable
if (f%usecore .and. any(f%zpsp /= -1)) then
call f%c%promolecular_env(wc,icrd_cart,rho,grad,h,nder,zpsp=f%zpsp)
call f%c%promolecular_atom(wc,icrd_cart,rho,grad,h,nder,zpsp=f%zpsp)
res%f = res%f + rho
res%gf = res%gf + grad
res%hf = res%hf + h
Expand All @@ -914,7 +914,7 @@ recursive module subroutine grd(f,v,nder,res,fder,periodic)

! If it's on a nucleus, nullify the gradient (may not be zero in
! grid fields, for instance)
nid = f%c%identify_atom_env(wc,icrd_cart,distmax=1d-5)
nid = f%c%identify_atom(wc,icrd_cart,distmax=1d-5)
res%isnuc = (nid > 0)

! gradient
Expand Down Expand Up @@ -1002,9 +1002,9 @@ recursive module function grd0(f,v,periodic)
case(type_dftb)
call f%dftb%rho2(wcr,f%exact,0,rho,grad,h,gkin)
case(type_promol)
call f%c%promolecular_env(wcr,icrd_cart,rho,grad,h,0)
call f%c%promolecular_atom(wcr,icrd_cart,rho,grad,h,0)
case(type_promol_frag)
call f%c%promolecular_env(wcr,icrd_cart,rho,grad,h,0,fr=f%fr)
call f%c%promolecular_atom(wcr,icrd_cart,rho,grad,h,0,fr=f%fr)
case(type_ghost)
rho = eval(f%expr,errmsg,wc,f%sptr,periodic)
if (len_trim(errmsg) > 0) &
Expand All @@ -1014,7 +1014,7 @@ recursive module function grd0(f,v,periodic)
end select

if (f%usecore .and. any(f%zpsp /= -1)) then
call f%c%promolecular_env(wc,icrd_cart,rhoaux,grad,h,0,zpsp=f%zpsp)
call f%c%promolecular_atom(wc,icrd_cart,rhoaux,grad,h,0,zpsp=f%zpsp)
rho = rho + rhoaux
end if
grd0 = rho
Expand Down Expand Up @@ -2050,7 +2050,7 @@ module subroutine addcp(f,x0,cpeps,nuceps,nucepsh,gfnormeps,itype)
end if

! distance to atoms
nid = f%c%identify_atom_env(xc,icrd_crys,dist=dist,distmax=max(nuceps,nucepsh))
nid = f%c%identify_atom(xc,icrd_crys,dist=dist,distmax=max(nuceps,nucepsh))
if (nid > 0) then
if (dist < nuceps) goto 999
if (f%c%spc(f%c%atcel(nid)%is)%z == 1 .and. dist < nucepsh) goto 999
Expand Down Expand Up @@ -2295,7 +2295,7 @@ module subroutine gradient(fid,xpoint,iup,nstep,ier,up2beta,plen,path,prune,path
end if

! nearest nucleus
call fid%c%nearest_atom_env(xpoint,icrd_crys,idnuc,sphrad,lvec=lvec)
call fid%c%nearest_atom(xpoint,icrd_crys,idnuc,sphrad,lvec=lvec)
xnuc = fid%c%x2c(fid%c%atcel(idnuc)%x + lvec)
xnucr = fid%c%atcel(idnuc)%x + lvec
idnuc = fid%c%atcel(idnuc)%idx
Expand Down
2 changes: 1 addition & 1 deletion src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ subroutine flx_prepareprintpath(x,title,iup,dir,icp)
call sy%f(sy%iref)%nearest_cp(flx_path(flx_n)%x,flx_cpcelid(2),dist)
if (dist <= cpeps) goto 999

flx_cpcelid(2) = sy%c%identify_atom_env(flx_path(flx_n)%x,icrd_crys,dist=dist,distmax=max(nuceps,nucepsh))
flx_cpcelid(2) = sy%c%identify_atom(flx_path(flx_n)%x,icrd_crys,dist=dist,distmax=max(nuceps,nucepsh))
if (flx_cpcelid(2) > 0) then
if (dist < nuceps) goto 999
if (sy%c%spc(sy%c%atcel(flx_cpcelid(2))%is)%z == 1 .and. dist < nucepsh) goto 999
Expand Down
2 changes: 1 addition & 1 deletion src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -3154,7 +3154,7 @@ subroutine crystalmod_promolecular(cptr,x0,icrd,f,fp,fpp,nder,zpsp,fr)
type(crystal), pointer :: c

call c_f_pointer(cptr,c)
call c%promolecular_env(x0,icrd,f,fp,fpp,nder,zpsp,fr)
call c%promolecular_atom(x0,icrd,f,fp,fpp,nder,zpsp,fr)

end subroutine crystalmod_promolecular

Expand Down
2 changes: 1 addition & 1 deletion src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ subroutine int_reorder_gridout(ff,bas)
! assign attractors to atoms
if (bas%atexist) then
do i = 1, nattr0
nid = ff%c%identify_atom_env(bas%xattr(:,i),icrd_crys,distmax=bas%ratom)
nid = ff%c%identify_atom(bas%xattr(:,i),icrd_crys,distmax=bas%ratom)
if (nid > 0) then
assigned(i) = nid
else
Expand Down
2 changes: 1 addition & 1 deletion src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ function read_fragment(lu) result(fr)
ok = ok .and. eval_next(x(3),line,lp)
if (.not.ok) call ferror('nciplot','bad atom in fragment',faterr)
x = x / bohrtoa - sy%c%molx0
id = sy%c%identify_atom_env(x,icrd_cart)
id = sy%c%identify_atom(x,icrd_cart)

if (id > 0) then
fr%nat = fr%nat + 1
Expand Down
4 changes: 2 additions & 2 deletions src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -2524,8 +2524,8 @@ subroutine wrtpath(xpath,nptf,udat,rp0,r01,r02,cosalfa,sinalfa)
logical :: wasblank

! identify the endpoints
nid1 = sy%c%identify_atom_env(xpath(1)%x,icrd_crys,dist=dist1,distmax=1.1d0*prunedist)
nid2 = sy%c%identify_atom_env(xpath(nptf)%x,icrd_crys,dist=dist2,distmax=1.1d0*prunedist)
nid1 = sy%c%identify_atom(xpath(1)%x,icrd_crys,dist=dist1,distmax=1.1d0*prunedist)
nid2 = sy%c%identify_atom(xpath(nptf)%x,icrd_crys,dist=dist2,distmax=1.1d0*prunedist)
rgb = (/0,0,0/)
if (nid1 > 0 .and. (dist1 < dist2 .or. nid2 == 0)) then
iz = sy%c%spc(sy%c%atcel(nid1)%is)%z
Expand Down
Loading

0 comments on commit f1f4872

Please sign in to comment.