Skip to content

Commit

Permalink
Marks external neighbour set for recomputation
Browse files Browse the repository at this point in the history
Also adds a variable to the main type to prevent DFTB+ updating the
neighbourlist if it has been set externally.
  • Loading branch information
bhourahine committed Sep 30, 2023
1 parent 426da8f commit 7bfd505
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/dftbp/dftbplus/initprogram.F90
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ module dftbp_dftbplus_initprogram
!> Index in cellVec for each atom
integer, allocatable :: iCellVec(:)

!> Are neighbour lists set externally (via the API), so should not be changed internally
logical :: areNeighSetExternal = .false.

!> ADT for neighbour parameters
type(TNeighbourList), allocatable :: neighbourList
Expand Down
25 changes: 15 additions & 10 deletions src/dftbp/dftbplus/main.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ subroutine processGeometry(this, env, iGeoStep, iLatGeoStep, tWriteRestart, tSto
& this%img2CentCell, this%iCellVec, this%neighbourList, this%nAllAtom, this%coord0Fold,&
& this%coord,this%species, this%rCellVec, this%nNeighbourSk, this%nNeighbourLC,&
& this%ints, this%H0, this%rhoPrim, this%iRhoPrim, this%ERhoPrim, this%iSparseStart,&
& this%cm5Cont, errStatus)
& this%cm5Cont, this%areNeighSetExternal, errStatus)
@:PROPAGATE_ERROR(errStatus)
end if

Expand Down Expand Up @@ -2029,7 +2029,7 @@ subroutine handleCoordinateChange(env, boundaryCond, coord0, latVec, species0, c
& tHelical, sccCalc, tblite, repulsive, dispersion, solvation, thirdOrd, rangeSep, reks,&
& img2CentCell, iCellVec, neighbourList, nAllAtom, coord0Fold, coord, species, rCellVec,&
& nNeighbourSK, nNeighbourLC, ints, H0, rhoPrim, iRhoPrim, ERhoPrim, iSparseStart, cm5Cont,&
& errStatus)
& areNeighSetExternal, errStatus)

!> Environment settings
type(TEnvironment), intent(in) :: env
Expand Down Expand Up @@ -2131,6 +2131,9 @@ subroutine handleCoordinateChange(env, boundaryCond, coord0, latVec, species0, c
!> Charge model 5
type(TChargeModel5), allocatable, intent(inout) :: cm5Cont

!> Are Neighbour lists set externally, so should not be updated
logical, intent(in) :: areNeighSetExternal

!> Status of operation
type(TStatus), intent(out) :: errStatus

Expand All @@ -2141,15 +2144,17 @@ subroutine handleCoordinateChange(env, boundaryCond, coord0, latVec, species0, c
coord0Fold(:,:) = coord0
call boundaryCond%foldCoordsToCell(coord0Fold, latVec)

if (tHelical) then
call updateNeighbourListAndSpecies(env, coord, species, img2CentCell, iCellVec,&
& neighbourList, nAllAtom, coord0Fold, species0, cutoff%mCutoff, rCellVec,&
& errStatus, helicalBoundConds=latVec)
else
call updateNeighbourListAndSpecies(env, coord, species, img2CentCell, iCellVec,&
& neighbourList, nAllAtom, coord0Fold, species0, cutoff%mCutOff, rCellVec, errStatus)
if (.not.areNeighSetExternal) then
if (tHelical) then
call updateNeighbourListAndSpecies(env, coord, species, img2CentCell, iCellVec,&
& neighbourList, nAllAtom, coord0Fold, species0, cutoff%mCutoff, rCellVec,&
& errStatus, helicalBoundConds=latVec)
else
call updateNeighbourListAndSpecies(env, coord, species, img2CentCell, iCellVec,&
& neighbourList, nAllAtom, coord0Fold, species0, cutoff%mCutOff, rCellVec, errStatus)
end if
@:PROPAGATE_ERROR(errStatus)
end if
@:PROPAGATE_ERROR(errStatus)

call getNrOfNeighboursForAll(nNeighbourSK, neighbourList, cutoff%skCutOff)

Expand Down
2 changes: 2 additions & 0 deletions src/dftbp/dftbplus/mainapi.F90
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ subroutine setNeighbourList(env, main, nNeighbour, iNeighbour, neighDist, cutOff
call setNeighbourListOrig(main%neighbourList, env, nNeighbour, iNeighbour, neighDist, cutOff,&
& main%coord0, main%species0, coordNeighbours, neighbour2CentCell, main%rCellVec,&
& main%nAllAtom, main%img2CentCell, main%iCellVec, main%coord, main%species)
main%areNeighSetExternal = .true.
main%tCoordsChanged = .true.

end subroutine setNeighbourList

Expand Down
9 changes: 8 additions & 1 deletion test/src/dftbp/api/mm/testers/test_neighbour_list.f90
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ program test_neighbour_list
x = 2.5639291987021915_dp
coord(:,:) = reshape([-x, -x, x, x, -x, -x, -x, x, -x, x, x, x], shape(coord))
img2CentCell(:) = [2, 2, 2, 2]
nNeighbour(:) = [4, 0]
iNeighbour(:,:) = reshape([1, 2, 3, 4, 0, 0, 0, 0], shape(iNeighbour))
dist = sqrt(19.721198807872987_dp)
neighDist(:,:) = reshape([dist, dist, dist, dist, 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp],&
& shape(neighDist))

nNeighbour(:) = [3, 0]
! set the neighbour list
call dftbp%setNeighbourList(nNeighbour, iNeighbour, neighDist, cutoff, coord, img2CentCell)
! evaluate energy and forces
call dftbp%getEnergy(merminEnergy)
call dftbp%getGradients(gradients)

nNeighbour(:) = [4, 0]
! set the neighbour list
call dftbp%setNeighbourList(nNeighbour, iNeighbour, neighDist, cutoff, coord, img2CentCell)

Expand Down

0 comments on commit 7bfd505

Please sign in to comment.