Skip to content

Commit a2a8557

Browse files
committed
expose eeqbc standalone via calculator
1 parent e07fe95 commit a2a8557

7 files changed

Lines changed: 89 additions & 15 deletions

File tree

src/calculator/api_engrad.f90

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module api_engrad
3535
use gfn0_api
3636
use gfnff_api
3737
use crest_solvation,only:solvation_setup,solvation_core
38+
use crest_electrostatic,only:electrostatic_core
3839
use libpvol_api
3940
use lj
4041
use approxg_module
@@ -54,6 +55,7 @@ module api_engrad
5455
public :: mlip_engrad
5556
public :: preinit_mlip_parallel
5657
public :: solvation_engrad
58+
public :: electrostatic_engrad
5759

5860
!=========================================================================================!
5961
!=========================================================================================!
@@ -157,6 +159,37 @@ subroutine solvation_engrad(mol,calc,energy,grad,iostatus)
157159
return
158160
end subroutine solvation_engrad
159161

162+
!========================================================================================!
163+
164+
subroutine electrostatic_engrad(mol,calc,energy,grad,iostatus)
165+
!*********************************************************************
166+
!* Interface singlepoint call for the charge-equilibration calculator
167+
!*********************************************************************
168+
implicit none
169+
type(coord) :: mol
170+
type(calculation_settings) :: calc
171+
real(wp),intent(inout) :: energy
172+
real(wp),intent(inout) :: grad(3,mol%nat)
173+
integer,intent(out) :: iostatus
174+
character(len=:),allocatable :: model
175+
176+
iostatus = 0
177+
if (.not.allocated(calc%eeq)) then
178+
iostatus = 1
179+
return
180+
end if
181+
model = 'eeqbc'
182+
if (allocated(calc%eeq%charge_model)) model = calc%eeq%charge_model
183+
184+
!>--- energy, gradient and atomic charges (kept on the settings)
185+
if (.not.allocated(calc%qat)) allocate (calc%qat(mol%nat))
186+
call electrostatic_core(mol,calc%chrg,model,energy,grad,calc%qat,iostatus)
187+
if (iostatus /= 0) return
188+
if (.not.calc%prstdout) call api_print_e_grd(.false.,calc%prch,mol,energy,grad)
189+
190+
return
191+
end subroutine electrostatic_engrad
192+
160193
!========================================================================================!
161194

162195
subroutine gfn0_engrad(mol,calc,g0calc,energy,grad,iostatus)

src/calculator/calc_type.f90

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module calc_type
2525
use tblite_api
2626
use gfn0_api
2727
use crest_solvation,only:solvation_data
28+
use crest_electrostatic,only:electrostatic_data
2829
use gfnff_api,only:gfnff_data
2930
use libpvol_api,only:libpvol_calculator
3031
!>--- other types
@@ -58,10 +59,11 @@ module calc_type
5859
integer :: penalty = 13
5960
integer :: mlip = 14
6061
integer :: solvation = 15
62+
integer :: electrostatic = 16
6163
end type enum_jobtype
6264
type(enum_jobtype), parameter,public :: jobtype = enum_jobtype()
6365

64-
character(len=45),parameter,private :: jobdescription(16) = [ &
66+
character(len=45),parameter,private :: jobdescription(17) = [ &
6567
& 'Unknown calculation type ', &
6668
& 'xTB calculation via external binary ', &
6769
& 'Generic script execution ', &
@@ -77,7 +79,8 @@ module calc_type
7779
& 'Approximate free energy computation ', &
7880
& 'Empirical penalty function ', &
7981
& 'MLIP via persistent python socket ', &
80-
& 'Standalone implicit solvation contribution ']
82+
& 'Standalone implicit solvation contribution ', &
83+
& 'Charge-equilibration electrostatics ']
8184
!&>
8285

8386
!=========================================================================================!
@@ -188,8 +191,11 @@ module calc_type
188191
real(wp) :: pvradscal = 1.0_wp !> Scaling factor for SAS radii
189192
type(libpvol_calculator),allocatable :: libpvol
190193

191-
!>--- implicit solvation composite data
192-
type(solvation_data),allocatable :: solv
194+
!>--- implicit solvation composite data
195+
type(solvation_data),allocatable :: solv
196+
197+
!>--- charge-equilibration electrostatics data
198+
type(electrostatic_data),allocatable :: eeq
193199

194200
!>--- approxg data
195201
type(approxg_params) :: ag
@@ -1164,6 +1170,7 @@ subroutine calculation_settings_deallocate(self)
11641170
if (allocated(self%tblite)) deallocate (self%tblite)
11651171
if (allocated(self%g0calc)) deallocate (self%g0calc)
11661172
if (allocated(self%solv)) deallocate (self%solv)
1173+
if (allocated(self%eeq)) deallocate (self%eeq)
11671174
if (allocated(self%ff_dat)) deallocate (self%ff_dat)
11681175
if (allocated(self%libpvol)) deallocate (self%libpvol)
11691176

@@ -1240,6 +1247,7 @@ subroutine calculation_settings_copy(self,src)
12401247
if (allocated(src%refcharges)) self%refcharges = src%refcharges
12411248
if (allocated(src%tbliteparam)) self%tbliteparam = src%tbliteparam
12421249
if (allocated(src%solv)) self%solv = src%solv
1250+
if (allocated(src%eeq)) self%eeq = src%eeq
12431251

12441252
! ── gradient settings ────────────────────────────────────────────────────────
12451253
self%numgrad = src%numgrad
@@ -1452,6 +1460,12 @@ subroutine calculation_settings_shortflag(self)
14521460
if (allocated(self%solv%solvent)) &
14531461
& self%shortflag = self%shortflag//'('//trim(self%solv%solvent)//')'
14541462
end if
1463+
case (jobtype%electrostatic)
1464+
self%shortflag = 'EEQ'
1465+
if (allocated(self%eeq)) then
1466+
if (allocated(self%eeq%charge_model)) &
1467+
& self%shortflag = trim(self%eeq%charge_model)
1468+
end if
14551469
case default
14561470
self%shortflag = 'undefined'
14571471
end select
@@ -1631,6 +1645,15 @@ subroutine calculation_settings_info(self,iunit)
16311645
end if
16321646
end if
16331647

1648+
!> charge-equilibration electrostatics details
1649+
if (self%id == jobtype%electrostatic .and. allocated(self%eeq)) then
1650+
write (iunit,fmt4) 'Charge-equilibration electrostatics (multicharge)'
1651+
if (allocated(self%eeq%charge_model)) then
1652+
write (atmp,*) 'charge model'
1653+
write (iunit,fmt3) atmp,trim(self%eeq%charge_model)
1654+
end if
1655+
end if
1656+
16341657
if (any((/jobtype%orca,jobtype%xtbsys,jobtype%turbomole, &
16351658
& jobtype%generic,jobtype%terachem/) == self%id)) then
16361659
if (index(self%binary,'gxtb') .ne. 0) then

src/calculator/calculator.F90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ subroutine potential_core(molptr,calc,id,iostatus)
411411

412412
case (jobtype%solvation)
413413
call solvation_engrad(molptr,calc%calcs(id),calc%etmp(id),calc%grdtmp(:,1:pnat,id),iostatus)
414+
415+
case (jobtype%electrostatic)
416+
call electrostatic_engrad(molptr,calc%calcs(id),calc%etmp(id),calc%grdtmp(:,1:pnat,id),iostatus)
414417
case default
415418
calc%etmp(id) = 0.0_wp
416419
calc%grdtmp(:,:,id) = 0.0_wp

src/calculator/components/electrostatic.F90

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ module crest_electrostatic
3838
implicit none
3939
private
4040

41-
public :: electrostatic_engrad
41+
public :: electrostatic_data
42+
public :: electrostatic_core
43+
44+
!> Bundled electrostatic settings (stored on calculation_settings)
45+
type :: electrostatic_data
46+
character(len=:),allocatable :: charge_model !> 'eeq' | 'eeqbc'
47+
end type electrostatic_data
4248

4349
contains
4450
!========================================================================================!
4551

46-
subroutine electrostatic_engrad(mol,chrg,model,energy,gradient,qat,iostatus,dqdr)
52+
subroutine electrostatic_core(mol,chrg,model,energy,gradient,qat,iostatus,dqdr)
4753
!***********************************************************************
4854
!* Charge-equilibration energy, gradient and atomic charges.
4955
!*
@@ -121,7 +127,7 @@ subroutine electrostatic_engrad(mol,chrg,model,energy,gradient,qat,iostatus,dqdr
121127
qat(:) = 0.0_wp
122128
if (present(dqdr)) dqdr(:,:,:) = 0.0_wp
123129
#endif
124-
end subroutine electrostatic_engrad
130+
end subroutine electrostatic_core
125131

126132
!========================================================================================!
127133
end module crest_electrostatic

src/calculator/components/solvation.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module crest_solvation
3737
use crest_parameters
3838
use strucrd,only:coord
3939
#ifdef WITH_DDX
40-
use crest_electrostatic,only:electrostatic_engrad
40+
use crest_electrostatic,only:electrostatic_core
4141
use crest_ddx_pc,only:ddx_pc_engrad
4242
use crest_surface,only:surface_engrad
4343
use mctc_env,only:error_type
@@ -149,7 +149,7 @@ subroutine solvation_core(mol,chrg,solv,energy,gradient,iostatus)
149149
allocate (qat(nat),dqdr(3,nat,nat),gtmp(3,nat),sasa(nat),dsdr(3,nat,nat))
150150

151151
! ── charges + dq/dR from the electrostatic component ─────────────────────
152-
call electrostatic_engrad(mol,chrg,solv%charge_model,edum,gtmp,qat,iostatus,dqdr=dqdr)
152+
call electrostatic_core(mol,chrg,solv%charge_model,edum,gtmp,qat,iostatus,dqdr=dqdr)
153153
if (iostatus /= 0) return
154154

155155
! ── polar (ddX) free energy + gradient (incl. dq/dR chain term) ──────────

src/parsing/parse_calcdata.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ subroutine parse_setting_auto(env,job,kv,rd)
290290
case ('solvation','solvator')
291291
job%id = jobtype%solvation
292292
if (.not.allocated(job%solv)) allocate (job%solv)
293+
case ('eeq','eeqbc','electrostatic')
294+
job%id = jobtype%electrostatic
295+
if (.not.allocated(job%eeq)) allocate (job%eeq)
296+
if (kv%value_c /= 'electrostatic') job%eeq%charge_model = kv%value_c
293297
case default
294298
job%id = jobtype%unknown
295299
!>--- keyword was recognized, but invalid argument supplied
@@ -414,6 +418,11 @@ subroutine parse_setting_auto(env,job,kv,rd)
414418
if (.not.allocated(job%solv)) allocate (job%solv)
415419
job%solv%do_hbond = kv%value_b
416420

421+
!>--- charge-equilibration electrostatics calculator settings
422+
case ('eeq_model','charge_model')
423+
if (.not.allocated(job%eeq)) allocate (job%eeq)
424+
job%eeq%charge_model = kv%value_c
425+
417426
case ('refine','refinement')
418427
select case (kv%value_c)
419428
case ('sp','singlepoint')

test/test_ddx.F90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module test_ddx
55
use crest_testmol
66
#ifdef WITH_DDX
77
use crest_ddx_pc,only:ddx_pc_engrad
8-
use crest_electrostatic,only:electrostatic_engrad
8+
use crest_electrostatic,only:electrostatic_core
99
use crest_surface,only:surface_engrad
1010
use crest_solvation,only:solvation_data,solvation_setup,solvation_core
1111
#endif
@@ -132,16 +132,16 @@ subroutine test_eeq_fd(error)
132132
h = 1.0e-4_wp
133133
call get_testmol('cytosine',mol)
134134
allocate (grad(3,mol%nat),qat(mol%nat),g(3,mol%nat))
135-
call electrostatic_engrad(mol,0,'eeqbc',energy,grad,qat,io)
135+
call electrostatic_core(mol,0,'eeqbc',energy,grad,qat,io)
136136
call check(error,io,0)
137137
if (allocated(error)) return
138138
rms = 0.0_wp; n = 0
139139
do iat = 1,mol%nat
140140
do k = 1,3
141141
mol%xyz(k,iat) = mol%xyz(k,iat)+h
142-
call electrostatic_engrad(mol,0,'eeqbc',er,g,qat,io)
142+
call electrostatic_core(mol,0,'eeqbc',er,g,qat,io)
143143
mol%xyz(k,iat) = mol%xyz(k,iat)-2.0_wp*h
144-
call electrostatic_engrad(mol,0,'eeqbc',el,g,qat,io)
144+
call electrostatic_core(mol,0,'eeqbc',el,g,qat,io)
145145
mol%xyz(k,iat) = mol%xyz(k,iat)+h
146146
dev = (er-el)/(2.0_wp*h)-grad(k,iat)
147147
rms = rms+dev*dev; n = n+1
@@ -199,7 +199,7 @@ subroutine test_solv_full_fd(error)
199199
call get_testmol('cytosine',mol)
200200
allocate (grad(3,mol%nat),geeq(3,mol%nat),qat(mol%nat),dqdr(3,mol%nat,mol%nat))
201201
!> analytic full gradient: charges + dq/dR from EEQ-BC, fed into ddX
202-
call electrostatic_engrad(mol,0,'eeqbc',eeq,geeq,qat,io,dqdr=dqdr)
202+
call electrostatic_core(mol,0,'eeqbc',eeq,geeq,qat,io,dqdr=dqdr)
203203
call ddx_pc_engrad(mol,qat,'cpcm',eps_water,energy,grad,io,dqdr=dqdr)
204204
call check(error,io,0)
205205
if (allocated(error)) return
@@ -229,7 +229,7 @@ subroutine solv_e(mol,energy,io)
229229
real(wp),allocatable :: q(:),g(:,:)
230230
real(wp) :: eeq
231231
allocate (q(mol%nat),g(3,mol%nat))
232-
call electrostatic_engrad(mol,0,'eeqbc',eeq,g,q,io)
232+
call electrostatic_core(mol,0,'eeqbc',eeq,g,q,io)
233233
call ddx_e(mol,q,energy,io)
234234
end subroutine solv_e
235235

0 commit comments

Comments
 (0)