Skip to content

Commit c377960

Browse files
committed
add json output for tblite
Signed-off-by: albert <[email protected]>
1 parent 80f2695 commit c377960

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

src/main/json.F90

+25-3
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959
! "version": 6.1
6060
! }
6161
module xtb_main_json
62+
use xtb_mctc_accuracy, only: wp
6263
implicit none
6364

6465
private
6566

6667
public :: main_xtb_json, write_json_gfnff_lists
67-
public :: main_ptb_json
68-
68+
public :: main_ptb_json, main_tblite_json
6969
contains
7070

7171
subroutine main_xtb_json &
@@ -585,7 +585,29 @@ subroutine write_json_gfnff_lists(n, etot, gnorm, topo, neigh, nlist, printTopo)
585585
call close_file(iunit)
586586

587587
end subroutine write_json_gfnff_lists
588-
588+
589+
!> wrapper for tblite-PTB JSON output
590+
subroutine main_tblite_json &
591+
(ijson, calc, energy, gradient, sigma)
592+
593+
#if WITH_TBLITE
594+
use tblite_output_ascii
595+
#endif
596+
use xtb_tblite_calculator, only : TTBLiteCalculator
597+
598+
integer, intent(in) :: ijson
599+
type(TTBLiteCalculator), intent(in) :: calc
600+
real(wp), intent(in) :: energy
601+
real(wp), intent(in) :: gradient(:,:)
602+
real(wp), intent(in) :: sigma(:,:)
603+
604+
#if WITH_TBLITE
605+
call json_results(ijson, ' ', energy=energy, gradient=gradient, &
606+
& sigma=sigma, energies=calc%results%energies)
607+
#endif
608+
609+
end subroutine main_tblite_json
610+
589611
!> wrapper for tblite-PTB JSON output
590612
subroutine main_ptb_json &
591613
(ijson, mol, wfx, calc, sccres, freqres)

src/prog/main.F90

+14-11
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module xtb_prog_main
7777
use xtb_xtb_gfn2
7878
use xtb_main_setup
7979
use xtb_main_defaults, only: initDefaults
80-
use xtb_main_json, only: main_xtb_json, write_json_gfnff_lists
80+
use xtb_main_json, only: main_xtb_json, write_json_gfnff_lists, main_ptb_json, main_tblite_json
8181
use xtb_geoopt
8282
use xtb_metadynamic
8383
use xtb_biaspath
@@ -97,8 +97,6 @@ module xtb_prog_main
9797
use xtb_ptb_calculator, only: TPTBCalculator
9898
use xtb_solv_cpx, only: TCpcmx
9999
use xtb_dipro, only: get_jab, jab_input
100-
!> PTB related modules
101-
use xtb_main_json, only: main_ptb_json
102100

103101
implicit none
104102
private
@@ -1020,32 +1018,39 @@ subroutine xtbMain(env, argParser)
10201018
end if
10211019

10221020
if (set%pr_json) then
1023-
select type (calc)
1021+
select type (calc)
10241022
type is (TxTBCalculator)
10251023
call open_file(ich, 'xtbout.json', 'w')
10261024
call main_xtb_json(ich, &
10271025
mol, chk%wfn, calc%basis, res, fres)
10281026
call close_file(ich)
1027+
1028+
type is (TTBLiteCalculator)
1029+
call open_file(ich, 'tblite.json', 'w')
1030+
call main_tblite_json(ich, &
1031+
calc, etot, g, sigma)
1032+
call close_file(ich)
1033+
10291034
type is (TPTBCalculator)
10301035
call open_file(ich, 'xtbout.json', 'w')
10311036
call main_ptb_json(ich, &
10321037
mol, chk%wfn, calc, res, fres)
10331038
call close_file(ich)
10341039
end select
10351040
end if
1041+
10361042
if (printTopo%any()) then
10371043
select type (calc)
10381044
type is (TGFFCalculator)
10391045
call write_json_gfnff_lists(mol%n, res%e_total, res%gnorm, calc%topo, calc%neigh, chk%nlist, printTopo)
10401046
end select
10411047
end if
1042-
if ((set%runtyp == p_run_opt) .or. (set%runtyp == p_run_ohess) .or. &
1043-
(set%runtyp == p_run_omd) .or. (set%runtyp == p_run_screen) .or. &
1044-
(set%runtyp == p_run_metaopt) .or. (set%runtyp == p_run_bhess)) then
1048+
1049+
if ( anyopt .or. (set%runtyp == p_run_bhess) ) then
10451050
call main_geometry(iprop, mol)
10461051
end if
10471052

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

1061-
if ((set%runtyp == p_run_opt) .or. (set%runtyp == p_run_ohess) .or. &
1062-
(set%runtyp == p_run_omd) .or. (set%runtyp == p_run_screen) .or. &
1063-
(set%runtyp == p_run_metaopt) .or. (set%runtyp == p_run_bhess)) then
1066+
if ( anyopt .or. (set%runtyp == p_run_bhess) ) then
10641067
call generateFileName(tmpname, 'xtbopt', extension, mol%ftype)
10651068
write (env%unit, '(/,a,1x,a,/)') &
10661069
"optimized geometry written to:", tmpname

src/tblite/calculator.F90

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module xtb_tblite_calculator
4040
use tblite_xtb_ipea1, only : new_ipea1_calculator, export_ipea1_param
4141
use tblite_xtb_singlepoint, only : xtb_singlepoint
4242
use tblite_data_spin, only : get_spin_constant
43+
use tblite_results, only : results_type
4344
#endif
4445
use xtb_mctc_accuracy, only : wp
4546
use xtb_type_calculator, only : TCalculator
@@ -89,6 +90,8 @@ module xtb_tblite_calculator
8990
type(xtb_calculator) :: tblite
9091
!> Perform a spin-polarized calculation
9192
logical :: spin_polarized = .false.
93+
!> results
94+
type(results_type) :: results
9295
#endif
9396
contains
9497
!> Perform calculator for a singlepoint
@@ -284,7 +287,7 @@ subroutine singlepoint(self, env, mol, chk, printlevel, restart, &
284287
call get_qat_from_qsh(self%tblite%bas, chk%tblite%qsh, chk%tblite%qat)
285288

286289
call xtb_singlepoint(ctx, struc, self%tblite, chk%tblite, self%accuracy, &
287-
& energy, gradient, sigma, printlevel)
290+
& energy, gradient, sigma, printlevel,self%results)
288291
if (ctx%failed()) then
289292
do while(ctx%failed())
290293
call ctx%get_error(error)

0 commit comments

Comments
 (0)