9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-21 11:03:29 +01:00

Introduced JSON

This commit is contained in:
Anthony Scemama 2023-04-21 15:11:50 +02:00
parent fc24491dbc
commit 94662d3da0
9 changed files with 122 additions and 8 deletions

View File

@ -1,3 +1,4 @@
ao_one_e_ints
ao_two_e_ints
scf_utils
json

View File

@ -80,9 +80,15 @@ subroutine run
mo_label = 'Orthonormalized'
write(json_unit,*) '"scf" : ['
call Roothaan_Hall_SCF
call ezfio_set_hartree_fock_energy(SCF_energy)
write(json_unit,*) ']'
call json_close
end

5
src/json/EZFIO.cfg Normal file
View File

@ -0,0 +1,5 @@
[empty]
type: logical
doc: Needed to create the json directory
interface: ezfio

1
src/json/NEED Normal file
View File

@ -0,0 +1 @@
ezfio_files

5
src/json/README.rst Normal file
View File

@ -0,0 +1,5 @@
====
json
====
JSON files to simplify getting output information from QP.

39
src/json/json.irp.f Normal file
View File

@ -0,0 +1,39 @@
BEGIN_PROVIDER [ character*(128), json_filename ]
implicit none
BEGIN_DOC
! Fortran unit of the JSON file
END_DOC
integer, external :: getUnitAndOpen
integer :: counter
character*(128) :: prefix
logical :: exists
prefix = trim(ezfio_filename)//'/json/'
exists = .True.
counter = 0
do while (exists)
counter += 1
write(json_filename, '(A,I5.5,A)') trim(prefix), counter, '.json'
INQUIRE(FILE=trim(json_filename), EXIST=exists)
enddo
END_PROVIDER
BEGIN_PROVIDER [ integer, json_unit]
implicit none
BEGIN_DOC
! Unit file for JSON output
END_DOC
integer, external :: getUnitAndOpen
call ezfio_set_json_empty(.False.)
json_unit = getUnitAndOpen(json_filename, 'w')
write(json_unit, '(A)') '{'
END_PROVIDER
subroutine json_close
write(json_unit, '(A)') '}'
close(json_unit)
FREE json_unit
end

View File

@ -0,0 +1,26 @@
BEGIN_PROVIDER [ character*(64), json_int_fmt ]
&BEGIN_PROVIDER [ character*(64), json_int_fmtx ]
&BEGIN_PROVIDER [ character*(64), json_real_fmt ]
&BEGIN_PROVIDER [ character*(64), json_real_fmtx ]
&BEGIN_PROVIDER [ character*(64), json_str_fmt ]
&BEGIN_PROVIDER [ character*(64), json_str_fmtx ]
&BEGIN_PROVIDER [ character*(64), json_true_fmt ]
&BEGIN_PROVIDER [ character*(64), json_true_fmtx ]
&BEGIN_PROVIDER [ character*(64), json_false_fmt ]
&BEGIN_PROVIDER [ character*(64), json_false_fmtx ]
implicit none
BEGIN_DOC
! Formats for JSON output.
! x: used to mark the last write (no comma)
END_DOC
json_int_fmt = '('' "'',A,''": '',I10,'','')'
json_int_fmtx = '('' "'',A,''": '',I10)'
json_real_fmt = '('' "'',A,''": '',E22.15,'','')'
json_real_fmtx = '('' "'',A,''": '',E22.15)'
json_str_fmt = '('' "'',A,''": "'',A,''",'')'
json_str_fmtx = '('' "'',A,''": "'',A,''"'')'
json_true_fmt = '('' "'',A,''": true,'')'
json_true_fmtx = '('' "'',A,''": true'')'
json_false_fmt = '('' "'',A,''": false,'')'
json_false_fmtx = '('' "'',A,''": false'')'
END_PROVIDER

View File

@ -12,6 +12,7 @@ END_DOC
integer :: iteration_SCF,dim_DIIS,index_dim_DIIS
logical :: converged
integer :: i,j
logical, external :: qp_stop
double precision, allocatable :: mo_coef_save(:,:)
@ -50,10 +51,8 @@ END_DOC
!
PROVIDE FPS_SPF_matrix_AO Fock_matrix_AO
do while ( &
( (max_error_DIIS > threshold_DIIS_nonzero) .or. &
(dabs(Delta_energy_SCF) > thresh_SCF) &
) .and. (iteration_SCF < n_it_SCF_max) )
converged = .False.
do while ( .not.converged .and. (iteration_SCF < n_it_SCF_max) )
! Increment cycle number
@ -144,17 +143,45 @@ END_DOC
SOFT_TOUCH level_shift
energy_SCF_previous = energy_SCF
converged = ( (max_error_DIIS <= threshold_DIIS_nonzero) .and. &
(dabs(Delta_energy_SCF) <= thresh_SCF) )
! Print results at the end of each iteration
write(6,'(I4, 1X, F16.10, 1X, F16.10, 1X, F16.10, 1X, F16.10, 1X, I3)') &
iteration_SCF, energy_SCF, Delta_energy_SCF, max_error_DIIS, level_shift, dim_DIIS
! Write data in JSON file
if (iteration_SCF == 1) then
write(json_unit, *) '{'
else
write(json_unit, *) '}, {'
endif
write(json_unit, json_int_fmt) 'iteration', iteration_SCF
write(json_unit, json_real_fmt) 'energy', energy_SCF
write(json_unit, json_real_fmt) 'delta_energy_SCF', Delta_energy_SCF
write(json_unit, json_real_fmt) 'max_error_DIIS', max_error_DIIS
write(json_unit, json_real_fmt) 'level_shift', level_shift
write(json_unit, json_int_fmt) 'dim_DIIS', dim_DIIS
if (Delta_energy_SCF < 0.d0) then
call save_mos
write(json_unit, json_true_fmt) 'saved'
else
write(json_unit, json_false_fmt) 'saved'
endif
if (converged) then
write(json_unit, json_true_fmtx) 'converged'
else
write(json_unit, json_false_fmtx) 'converged'
endif
if (qp_stop()) exit
enddo
write(json_unit, *) '}'
if (iteration_SCF < n_it_SCF_max) then
mo_label = 'Canonical'
@ -166,6 +193,10 @@ END_DOC
write(6,'(A4, 1X, A16, 1X, A16, 1X, A16, 1X, A16)') &
'====','================','================','================','================'
write(6,*)
if (converged) then
write(6,*) 'SCF converged'
endif
if(.not.frozen_orb_scf)then
call mo_as_eigvectors_of_mo_matrix(Fock_matrix_mo,size(Fock_matrix_mo,1), &