Skip to content

Commit

Permalink
add json output for tblite
Browse files Browse the repository at this point in the history
Signed-off-by: albert <92109627+Albkat@users.noreply.github.com>
  • Loading branch information
Albkat committed Mar 7, 2024
1 parent 80f2695 commit ffa7d25
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
28 changes: 25 additions & 3 deletions src/main/json.F90
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@
! "version": 6.1
! }
module xtb_main_json
use xtb_mctc_accuracy, only: wp
implicit none

private

public :: main_xtb_json, write_json_gfnff_lists
public :: main_ptb_json

public :: main_ptb_json, main_tblite_json
contains

subroutine main_xtb_json &
Expand Down Expand Up @@ -585,7 +585,29 @@ subroutine write_json_gfnff_lists(n, etot, gnorm, topo, neigh, nlist, printTopo)
call close_file(iunit)

end subroutine write_json_gfnff_lists


!> wrapper for tblite-PTB JSON output
subroutine main_tblite_json &
(ijson, calc, energy, gradient, sigma)

#if WITH_TBLITE
use tblite_output_ascii
#endif
use xtb_tblite_calculator, only : TTBLiteCalculator

integer, intent(in) :: ijson
type(TTBLiteCalculator), intent(in) :: calc
real(wp), intent(in) :: energy
real(wp), intent(in) :: gradient(:,:)
real(wp), intent(in) :: sigma(:,:)

#if WITH_TBLITE
call json_results(ijson, ' ', energy=energy, gradient=gradient, &
& sigma=sigma, energies=calc%results%energies)
#endif

end subroutine main_tblite_json

!> wrapper for tblite-PTB JSON output
subroutine main_ptb_json &
(ijson, mol, wfx, calc, sccres, freqres)
Expand Down
25 changes: 14 additions & 11 deletions src/prog/main.F90
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module xtb_prog_main
use xtb_xtb_gfn2
use xtb_main_setup
use xtb_main_defaults, only: initDefaults
use xtb_main_json, only: main_xtb_json, write_json_gfnff_lists
use xtb_main_json, only: main_xtb_json, write_json_gfnff_lists, main_ptb_json, main_tblite_json
use xtb_geoopt
use xtb_metadynamic
use xtb_biaspath
Expand All @@ -97,8 +97,6 @@ module xtb_prog_main
use xtb_ptb_calculator, only: TPTBCalculator
use xtb_solv_cpx, only: TCpcmx
use xtb_dipro, only: get_jab, jab_input
!> PTB related modules
use xtb_main_json, only: main_ptb_json

implicit none
private
Expand Down Expand Up @@ -1020,32 +1018,39 @@ subroutine xtbMain(env, argParser)
end if

if (set%pr_json) then
select type (calc)
select type (calc)
type is (TxTBCalculator)
call open_file(ich, 'xtbout.json', 'w')
call main_xtb_json(ich, &
mol, chk%wfn, calc%basis, res, fres)
call close_file(ich)

type is (TTBLiteCalculator)
call open_file(ich, 'tblite.json', 'w')
call main_tblite_json(ich, &
calc, etot, g, sigma)
call close_file(ich)

type is (TPTBCalculator)
call open_file(ich, 'xtbout.json', 'w')
call main_ptb_json(ich, &
mol, chk%wfn, calc, res, fres)
call close_file(ich)
end select
end if

if (printTopo%any()) then
select type (calc)
type is (TGFFCalculator)
call write_json_gfnff_lists(mol%n, res%e_total, res%gnorm, calc%topo, calc%neigh, chk%nlist, printTopo)
end select
end if
if ((set%runtyp == p_run_opt) .or. (set%runtyp == p_run_ohess) .or. &
(set%runtyp == p_run_omd) .or. (set%runtyp == p_run_screen) .or. &
(set%runtyp == p_run_metaopt) .or. (set%runtyp == p_run_bhess)) then

if (anyopt) then
call main_geometry(iprop, mol)
end if

if ((set%runtyp == p_run_hess) .or. (set%runtyp == p_run_ohess) .or. (set%runtyp == p_run_bhess)) then
if (anyhess) then
call generic_header(iprop, 'Frequency Printout', 49, 10)
call main_freq(iprop, mol, chk%wfn, fres)
end if
Expand All @@ -1058,9 +1063,7 @@ subroutine xtbMain(env, argParser)
end if
end if

if ((set%runtyp == p_run_opt) .or. (set%runtyp == p_run_ohess) .or. &
(set%runtyp == p_run_omd) .or. (set%runtyp == p_run_screen) .or. &
(set%runtyp == p_run_metaopt) .or. (set%runtyp == p_run_bhess)) then
if ( anyopt .or. (set%runtyp == p_run_bhess) ) then
call generateFileName(tmpname, 'xtbopt', extension, mol%ftype)
write (env%unit, '(/,a,1x,a,/)') &
"optimized geometry written to:", tmpname
Expand Down
5 changes: 4 additions & 1 deletion src/tblite/calculator.F90
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module xtb_tblite_calculator
use tblite_xtb_ipea1, only : new_ipea1_calculator, export_ipea1_param
use tblite_xtb_singlepoint, only : xtb_singlepoint
use tblite_data_spin, only : get_spin_constant
use tblite_results, only : results_type
#endif
use xtb_mctc_accuracy, only : wp
use xtb_type_calculator, only : TCalculator
Expand Down Expand Up @@ -89,6 +90,8 @@ module xtb_tblite_calculator
type(xtb_calculator) :: tblite
!> Perform a spin-polarized calculation
logical :: spin_polarized = .false.
!> results
type(results_type) :: results
#endif
contains
!> Perform calculator for a singlepoint
Expand Down Expand Up @@ -284,7 +287,7 @@ subroutine singlepoint(self, env, mol, chk, printlevel, restart, &
call get_qat_from_qsh(self%tblite%bas, chk%tblite%qsh, chk%tblite%qat)

call xtb_singlepoint(ctx, struc, self%tblite, chk%tblite, self%accuracy, &
& energy, gradient, sigma, printlevel)
& energy, gradient, sigma, printlevel,self%results)
if (ctx%failed()) then
do while(ctx%failed())
call ctx%get_error(error)
Expand Down

0 comments on commit ffa7d25

Please sign in to comment.