Skip to content

Commit 1782d7d

Browse files
authored
allow tblite parameter readin. parameter files in toml format located in assets/tblite/ (#303)
Signed-off-by: Philipp Pracht <pp555@cam.ac.uk>
1 parent d4eb649 commit 1782d7d

File tree

10 files changed

+9378
-10
lines changed

10 files changed

+9378
-10
lines changed

assets/tblite/gfn1-si.toml

Lines changed: 2542 additions & 0 deletions
Large diffs are not rendered by default.

assets/tblite/gfn1.toml

Lines changed: 2541 additions & 0 deletions
Large diffs are not rendered by default.

assets/tblite/gfn2.toml

Lines changed: 1680 additions & 0 deletions
Large diffs are not rendered by default.

assets/tblite/ipea1.toml

Lines changed: 2533 additions & 0 deletions
Large diffs are not rendered by default.

src/algos/singlepoint.f90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,22 @@ subroutine crest_singlepoint(env,tim)
7777

7878
allocate (grad(3,mol%nat),source=0.0_wp)
7979
calc = env%calc
80+
calc%calcs(:)%prstdout = .true.
8081

8182
!>--- print some info about the calculation
8283
call calc%info(stdout)
8384

8485
!>--- and then start it
8586
write (stdout,'(a)') repeat('-',80)
86-
write (stdout,'(a)',advance='no') '> Performing singlepoint calculations ... '
87+
write (stdout,'(a)',advance='yes') '> Performing singlepoint calculations ... '
8788
flush (stdout)
8889
!>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<!
8990
!>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<!
9091
call engrad(mol,calc,energy,grad,io)
9192
!>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<!
9293
!>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<!
9394
call tim%stop(14)
94-
write (stdout,*) 'done.'
95+
write (stdout,'(a)') '> done.'
9596
write (atmp,'(a)') '> Total wall time for calculations'
9697
call tim%write_timing(stdout,14,trim(atmp),.true.)
9798
write (stdout,'(a)') repeat('-',80)

src/calculator/api_engrad.f90

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ subroutine tblite_engrad(mol,calc,energy,grad,iostatus)
7777
!>--- tblite printout handling
7878
call api_handle_output(calc,'tblite.out',mol,pr)
7979
if (pr) then
80-
!> tblite uses its context (ctx)( type, rather than calc%prch
80+
!> tblite uses its context (ctx) type, rather than calc%prch
8181
calc%tblite%ctx%unit = calc%prch
8282
calc%tblite%ctx%verbosity = 1
83+
if(calc%prstdout)then
84+
!> special case, fwd to stdout (be carefule with this!)
85+
calc%tblite%ctx%unit = stdout
86+
calc%tblite%ctx%verbosity = 2
87+
endif
8388
else
8489
calc%tblite%ctx%verbosity = 0
8590
end if
@@ -100,7 +105,7 @@ subroutine tblite_engrad(mol,calc,energy,grad,iostatus)
100105
call tblite_singlepoint(mol,calc%chrg,calc%uhf,calc%tblite, &
101106
& energy,grad,iostatus)
102107
if (iostatus /= 0) return
103-
call api_print_e_grd(pr,calc%tblite%ctx%unit,mol,energy,grad)
108+
call api_print_e_grd(pr,calc%prch,mol,energy,grad)
104109

105110
!>--- postprocessing, getting other data
106111
!$omp critical

src/calculator/api_helpers.F90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ subroutine tblite_init(calc,loadnew)
149149
loadnew = .false.
150150
if (.not.allocated(calc%tblite)) then
151151
allocate (calc%tblite)
152+
if(allocated(calc%tbliteparam))then
153+
calc%tblite%paramfile = calc%tbliteparam
154+
endif
152155
loadnew = .true.
153156
end if
154157
if (calc%apiclean) loadnew = .true.

src/calculator/calc_type.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module calc_type
7676
integer :: prch = stdout !> printout channel
7777
logical :: pr = .false. !> allow the calculation to produce printout? Results in a lot I/O
7878
logical :: prappend = .false. !> append printout
79+
logical :: prstdout = .false. !> special case, fwd some printout to stdout
7980
integer :: refine_lvl = 0 !> to allow defining different refinement levels
8081

8182
integer :: chrg = 0 !> molecular charge
@@ -139,6 +140,7 @@ module calc_type
139140

140141
!>--- tblite data
141142
type(tblite_data),allocatable :: tblite
143+
character(len=:),allocatable :: tbliteparam
142144

143145
!>--- GFN0-xTB data
144146
type(gfn0_data),allocatable :: g0calc
@@ -685,6 +687,8 @@ subroutine calculation_settings_shortflag(self)
685687
self%shortflag = 'CEH'
686688
case (xtblvl%eeq)
687689
self%shortflag = 'EEQ(D4)'
690+
case (xtblvl%param)
691+
self%shortflag = 'parameter file: '//trim(self%tbliteparam)
688692
end select
689693
case( jobtype%gfn0 )
690694
self%shortflag = 'GFN0-xTB'

src/calculator/tblite_api.F90

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ module tblite_api
3232
use tblite_wavefunction_type,only:wavefunction_type,new_wavefunction
3333
use tblite_wavefunction,only:sad_guess,eeq_guess
3434
use tblite_xtb,xtb_calculator => xtb_calculator
35+
use tblite_xtb_calculator, only: new_xtb_calculator
36+
use tblite_param, only : param_record
3537
use tblite_results,only:tblite_resultstype => results_type
3638
use tblite_wavefunction_mulliken,only:get_molecular_dipole_moment
3739
use tblite_ceh_singlepoint,only:ceh_guess
@@ -65,6 +67,7 @@ module tblite_api
6567
type :: tblite_data
6668
integer :: lvl = 0
6769
real(wp) :: accuracy = 1.0_wp
70+
character(len=:),allocatable :: paramfile
6871
type(wavefunction_type) :: wfn
6972
type(xtb_calculator) :: calc
7073
type(tblite_ctx) :: ctx
@@ -81,17 +84,13 @@ module tblite_api
8184
!> the guesses can be used for charges, but NOT for e+grd!
8285
integer :: eeq = 4
8386
integer :: ceh = 5
87+
integer :: param = 6
8488
end type enum_tblite_method
8589
type(enum_tblite_method),parameter,public :: xtblvl = enum_tblite_method()
8690

8791
!> Conversion factor from Kelvin to Hartree
8892
real(wp),parameter :: ktoau = 3.166808578545117e-06_wp
8993

90-
integer :: verbosity = 0
91-
!> IMPORTANT: tblite is not entirely thread-safe
92-
!> if verbosity is >0. We'll have to turn it off.
93-
!> At least for statically compiled binaries
94-
9594
public :: wavefunction_type,xtb_calculator
9695
public :: tblite_ctx,tblite_resultstype
9796
public :: tblite_setup,tblite_singlepoint,tblite_addsettings
@@ -121,10 +120,12 @@ subroutine tblite_setup(mol,chrg,uhf,lvl,etemp,tblite)
121120
#ifdef WITH_TBLITE
122121
type(structure_type) :: mctcmol
123122
type(error_type),allocatable :: error
123+
type(param_record) :: param
124124

125125
real(wp) :: etemp_au,energy
126126
real(wp),allocatable :: grad(:,:)
127127
logical :: pr
128+
integer :: io
128129

129130
pr = (tblite%ctx%verbosity > 0)
130131

@@ -149,6 +150,19 @@ subroutine tblite_setup(mol,chrg,uhf,lvl,etemp,tblite)
149150
case (xtblvl%eeq)
150151
if (pr) call tblite%ctx%message("tblite> setting up D4 EEQ charges calculation")
151152
call new_ceh_calculator(tblite%calc,mctcmol) !> doesn't matter but needs initialization
153+
case (xtblvl%param)
154+
if (pr) call tblite%ctx%message("tblite> setting up xtb calculator from parameter file")
155+
if(allocated(tblite%paramfile))then
156+
call tblite_read_param_record(tblite%paramfile,param,io)
157+
call new_xtb_calculator(tblite%calc, mctcmol, param, error)
158+
if(allocated(error))then
159+
write(stdout,*) 'Could not read tblite parameter file '//tblite%paramfile
160+
error stop
161+
endif
162+
else
163+
if (pr) call tblite%ctx%message("tblite> parameter file does not exist, defaulting to GFN2-xTB")
164+
call new_gfn2_calculator(tblite%calc,mctcmol)
165+
endif
152166
case default
153167
call tblite%ctx%message("Error: Unknown method in tblite!")
154168
error stop
@@ -202,7 +216,7 @@ subroutine tblite_add_solv(mol,chrg,uhf,tblite,smodel,solvent)
202216
pr = (tblite%ctx%verbosity > 0)
203217

204218
!>--- some tblite calculators have nothing to do with implicit solvation
205-
if (tblite%lvl > 3) then
219+
if (tblite%lvl > 3 .and. tblite%lvl.ne.xtblvl%param) then
206220
if (pr) call tblite%ctx%message("tblite> skipping implicit solvation setup for this potential")
207221
return
208222
end if
@@ -282,11 +296,17 @@ subroutine tblite_singlepoint(mol,chrg,uhf,tblite,energy,gradient,iostatus)
282296
type(error_type),allocatable :: error
283297
real(wp) :: sigma(3,3)
284298
logical :: pr
299+
integer :: verbosity
285300

286301
iostatus = 0
287302
energy = 0.0_wp
288303
gradient(:,:) = 0.0_wp
289304
pr = (tblite%ctx%verbosity > 0)
305+
if(tblite%ctx%verbosity>1)then
306+
verbosity = tblite%ctx%verbosity
307+
else
308+
verbosity = 0
309+
endif
290310

291311
!>--- make an mctcmol object from mol
292312
call tblite_mol2mol(mol,chrg,uhf,mctcmol)
@@ -454,6 +474,42 @@ subroutine tblite_getdipole(mol,chrg,uhf,tblite,dipole)
454474
#endif
455475
end subroutine tblite_getdipole
456476

477+
!========================================================================================!
478+
479+
#ifdef WITH_TBLITE
480+
subroutine tblite_read_param_record(paramfile,param,io)
481+
use tomlf
482+
implicit none
483+
character(len=*),intent(in) :: paramfile
484+
type(param_record),intent(out) :: param
485+
integer,intent(out) :: io
486+
type(error_type),allocatable :: error
487+
type(toml_table),allocatable :: table
488+
type(toml_error),allocatable :: terror
489+
type(toml_context) :: tcontext
490+
logical,parameter :: color = .true.
491+
492+
io=1
493+
494+
call toml_load(table,paramfile,error=terror,context=tcontext, &
495+
& config=toml_parser_config(color=color))
496+
if(allocated(terror))then
497+
io=1
498+
return
499+
endif
500+
501+
call param%load_from_toml(table,error)
502+
503+
if(allocated(error))then
504+
io=1
505+
else
506+
io=0
507+
endif
508+
if(allocated(table))deallocate(table)
509+
510+
end subroutine tblite_read_param_record
511+
#endif
512+
457513
!========================================================================================!
458514
!========================================================================================!
459515
end module tblite_api

src/parsing/parse_calcdata.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ subroutine parse_setting_c(env,job,key,val)
343343
case default
344344
job%tblitelvl = xtblvl%unknown
345345
end select
346+
case('tblite_param')
347+
job%tbliteparam = val
348+
job%tblitelvl = xtblvl%param
346349

347350
case ('orca_cmd')
348351
job%id = jobtype%orca

0 commit comments

Comments
 (0)