1
0
mirror of https://github.com/TREX-CoE/fparser.git synced 2024-11-03 20:54:11 +01:00
fparser/parser/interface.F90

265 lines
8.8 KiB
Fortran
Raw Normal View History

!
!
2021-03-26 06:13:07 +01:00
PROGRAM interface
USE fdf
USE prec
2021-02-25 12:41:14 +01:00
! Note the following two modules are being used to store and process the parsed data
use keywords
use periodic_table
!
implicit none
!--------------------------------------------------------------- Local Variables
2021-03-26 03:40:13 +01:00
type(block_fdf) :: bfdf
type(parsed_line), pointer :: pline
logical :: debug
integer(sp) :: i, j, ia
character(len=72) :: fmt, key
character(2), allocatable :: symbol(:)
2021-03-26 01:45:43 +01:00
character(len=20) :: real_format = '(A, T28, F14.8)'
character(len=20) :: int_format = '(A, T34, I8)'
character(len=80) :: string_format = '(A, T40, A)'
2021-03-25 14:21:38 +01:00
character(len=80) :: logical_format = '(A, T40, L)'
2021-02-23 22:44:22 +01:00
! for determinants sections
2021-03-26 04:07:08 +01:00
integer :: nelectrons, iostat
2021-03-26 01:45:43 +01:00
real(kind=8), allocatable :: det_coeff(:)
2021-03-26 03:40:13 +01:00
character(len=20) :: temp1, temp2, temp3
!------------------------------------------------------------------------- BEGIN
! Initialize
2021-03-26 00:48:53 +01:00
call fdf_init('test.inp', 'test.out')
2021-03-25 14:21:38 +01:00
write(6,*) '------------------------------------------------------'
! strings/characters
2021-02-25 12:41:14 +01:00
title = fdf_string('title', 'Default title')
2021-03-26 01:45:43 +01:00
write(6,fmt=string_format) ' Title of the calculation :: ', title
2021-02-25 12:41:14 +01:00
2021-03-25 14:21:38 +01:00
! Get the directory where the pooled data is kept
2021-02-25 12:41:14 +01:00
path_pool = fdf_string('pool', './')
2021-03-26 01:45:43 +01:00
write(6,fmt=string_format) ' pool directory location :: ', path_pool
2021-02-25 12:41:14 +01:00
2021-03-25 14:21:38 +01:00
write(6,*) '------------------------------------------------------'
2021-03-03 15:53:47 +01:00
2021-02-25 12:41:14 +01:00
2021-03-26 03:40:13 +01:00
2021-03-25 14:21:38 +01:00
! Get all the filenames from which the data is to be read
file_basis = fdf_load_filename('basis', 'default.gbs')
2021-03-26 01:45:43 +01:00
write(6,fmt=string_format) ' filename basis :: ', trim(file_basis)
file_molecule = fdf_load_filename('molecule', '')
write(6,fmt=string_format) ' filename molecule :: ', trim(file_molecule)
2021-02-25 12:41:14 +01:00
2021-03-03 12:00:32 +01:00
file_determinants = fdf_load_filename('determinants', 'default.det')
2021-03-26 01:45:43 +01:00
write(6,fmt=string_format) ' filename determinants :: ', trim(file_determinants)
2021-02-25 12:41:14 +01:00
2021-03-25 14:21:38 +01:00
write(6,*) '------------------------------------------------------'
2021-02-25 12:41:14 +01:00
2021-03-25 14:21:38 +01:00
! Logical variables
2021-03-26 00:48:53 +01:00
optimize_wave = fdf_boolean("optimize_wave", .false.)
2021-03-26 01:45:43 +01:00
! write(6,fmt=logical_format) 'optimize_wavefunction = ', optimize_wave
2021-02-25 12:41:14 +01:00
2021-03-26 03:40:13 +01:00
! Integer numbers (keyword, default_value). The variable is assigned default_value when keyword is not present
2021-03-26 01:45:43 +01:00
nextorb = fdf_integer('nextorb', 0)
! write(6,fmt=int_format) ' NExtOrb =', nextorb
2021-03-25 14:21:38 +01:00
! floats (keyword, default_value) variable is assigned default_value when keyword is not present
sr_eps = fdf_double('sr_eps', 0.025d0)
2021-03-26 01:45:43 +01:00
! write(6,fmt=real_format) ' sr_eps:', sr_eps
2021-03-26 03:40:13 +01:00
! logical :: true, .true., yes, T, 1, and TRUE are equivalent
2021-03-25 14:21:38 +01:00
debug = fdf_boolean('Debug', .TRUE.)
2021-03-26 01:45:43 +01:00
! write(6,'(A, L2)') ' Debug:', debug
2021-03-26 03:40:13 +01:00
! floats/integers/strings/boolean can be parsed generically using fdf_get
sr_tau = fdf_get('sr_tau', 0.025d0)
2021-03-26 01:45:43 +01:00
! write(6,fmt=real_format) ' sr_tau:', sr_tau
2021-03-25 14:21:38 +01:00
nspin1 = fdf_get('nspin1', 1)
2021-03-26 01:45:43 +01:00
! write(6,fmt=int_format) ' nspin1 from global ', nspin1
energy_tol = fdf_get('energy_tol', 0.00001d0)
2021-03-26 01:45:43 +01:00
! write(6,fmt=real_format) ' energy_tol:', energy_tol
opt_method = fdf_get('opt_method', "sr_n")
2021-03-26 01:45:43 +01:00
! write(6,fmt=string_format) ' Optimization method ', opt_method
2021-02-23 10:43:38 +01:00
multiple_adiag = fdf_get('multiple_adiag', .false.)
2021-03-26 01:45:43 +01:00
! write(6,fmt=logical_format) ' multiple_adiag:', multiple_adiag
2021-02-23 10:43:38 +01:00
2021-03-26 03:40:13 +01:00
! mixed types in one line (for example, reading a number with units)
tau = fdf_get('tau', 0.05)
2021-03-26 01:45:43 +01:00
! write(6,fmt=real_format) ' DMC tau = ', tau
2021-02-23 10:43:38 +01:00
etrial = fdf_physical('etrial', -20.d0, 'eV')
2021-03-26 01:45:43 +01:00
! write(6,fmt=real_format) ' Energy CutOff in eV :: ', energy_trial
2021-02-23 10:43:38 +01:00
2021-03-26 03:40:13 +01:00
! Pretty printing of above-mentioned keywords
write(6,'(A)')
2021-03-26 01:45:43 +01:00
write(6,*) '------------------------------------------------------'
write(6,fmt=string_format) ' Optimization method ', opt_method
write(6,fmt=logical_format) ' Optimize wavefunctions :: ', optimize_wave
write(6,fmt=logical_format) ' multiple_adiag :: ', multiple_adiag
write(6,fmt=logical_format) ' Debug :: ', debug
write(6,*) '-------------------------'
2021-03-26 01:45:43 +01:00
write(6,fmt=int_format) ' NExtOrb :: ', nextorb
write(6,fmt=int_format) ' Nspin1 from global :: ', nspin1
write(6,*) '-------------------------'
write(6,fmt=real_format) ' sr_tau :: ', sr_tau
write(6,fmt=real_format) ' energy_tol :: ', energy_tol
write(6,*) '-------------------------'
write(6,fmt=real_format) ' Trial Energy in eV :: ', energy_trial
write(6,'(A)')
write(6,*) '------------------------------------------------------'
if (.not. fdf_block('molecule', bfdf)) then
! External file reading
2021-03-08 10:29:30 +01:00
write(6,*) 'Reading coordinates of the molecule from an external file'
ia = 1
open (unit=12,file=file_molecule, iostat=iostat, action='read' )
if (iostat .ne. 0) stop "Problem in opening the molecule file"
read(12,*) natoms
print*, "natoms ", natoms
if (.not. allocated(cent)) allocate(cent(3,natoms))
2021-03-26 03:40:13 +01:00
if (.not. allocated(symbol)) allocate(symbol(natoms))
read(12,'(A)') key
print*, "Comment :: ", trim(key)
do i = 1, natoms
read(12,*) symbol(i), cent(1,i), cent(2,i), cent(3,i)
enddo
close(12)
2021-03-08 10:29:30 +01:00
write(6,*) 'Coordinates from Molecule load construct: '
do ia= 1, natoms
write(6,'(A4,3F10.6)') symbol(ia), (cent(i,ia),i=1,3)
enddo
2021-03-26 01:45:43 +01:00
write(6,'(A)')
write(6,*) '------------------------------------------------------'
2021-03-08 10:29:30 +01:00
endif
if (fdf_block('molecule', bfdf)) then
! External file reading
2021-03-26 01:45:43 +01:00
write(6,*) 'Beginning of molecular coordinates block '
ia = 1
do while((fdf_bline(bfdf, pline)))
! get the integer from the first line
if ((pline%id(1) .eq. "i") .and. (pline%ntokens .eq. 1)) then ! check if it is the only integer present in a line
natoms = fdf_bintegers(pline, 1)
write(*,*) "Number of atoms = ", natoms
endif
if (.not. allocated(cent)) allocate(cent(3,natoms))
2021-03-26 03:40:13 +01:00
if (.not. allocated(symbol)) allocate(symbol(natoms))
2021-02-18 23:21:04 +01:00
if (pline%ntokens == 4) then
symbol(ia) = fdf_bnames(pline, 1)
do i= 1, 3
cent(i,ia) = fdf_bvalues(pline, i)
enddo
ia = ia + 1
endif
enddo
2021-03-08 10:29:30 +01:00
2021-03-26 01:45:43 +01:00
write(6,*) 'Coordinates from Molecule block: '
2021-03-08 10:29:30 +01:00
do ia= 1, natoms
write(6,'(A4,3F10.6)') symbol(ia), (cent(i,ia),i=1,3)
enddo
2021-02-10 00:29:00 +01:00
2021-03-26 01:45:43 +01:00
write(6,'(A)')
write(6,*) '------------------------------------------------------'
endif
2021-02-23 22:44:22 +01:00
if (.not. fdf_block('determinants', bfdf)) then
if ( fdf_load_defined('determinants') ) then
! External file reading
write(6,'(A)') " Determinants Block"
2021-02-23 22:44:22 +01:00
write(6,*) '------------------------------------------------------'
2021-02-23 22:44:22 +01:00
2021-03-03 15:53:47 +01:00
write(6,*) 'Reading the determinants block from an external file '
2021-02-23 22:44:22 +01:00
2021-03-03 15:53:47 +01:00
open (unit=11,file=file_determinants, iostat=iostat, action='read' )
if (iostat .ne. 0) stop "Problem in opening the determinant file"
2021-02-23 22:44:22 +01:00
read(11,*) temp1, temp2, nelectrons, temp3, nalpha
2021-03-03 15:53:47 +01:00
2021-03-26 04:07:08 +01:00
read(11,*) temp1, ndeterminants, iwctype
2021-03-03 15:53:47 +01:00
if (.not. allocated(det_coeff)) allocate(det_coeff(ndeterminants))
2021-02-23 22:44:22 +01:00
read(11,*) (det_coeff(i), i=1,ndeterminants)
2021-03-03 15:53:47 +01:00
! write(*,'(<ndeterminants>(f11.8, 1x))') (det_coeff(i), i=1,ndeterminants) ! for Intel Fortran
2021-02-23 22:44:22 +01:00
2021-03-03 15:53:47 +01:00
nbeta = nelectrons - nalpha
2021-03-25 14:21:38 +01:00
2021-03-03 15:53:47 +01:00
write(*,*) "total number of electrons ", nelectrons
write(*,*) " number of alpha electrons ", nalpha
write(*,*) " number of beta electrons ", nbeta
2021-02-23 22:44:22 +01:00
2021-03-26 01:45:43 +01:00
write(6,'(A)')
write(*,*) "Determinant Coefficients"
2021-03-25 14:21:38 +01:00
write(fmt,*) '(', ndeterminants, '(f11.8,1x))'
write(*,fmt) (det_coeff(i), i=1,ndeterminants)
! allocate the orbital mapping array
if (.not. allocated(iworbd)) allocate(iworbd(nelectrons, ndeterminants))
2021-03-03 15:53:47 +01:00
do i = 1, ndeterminants
read(11,*) (iworbd(j,i), j=1,nelectrons)
enddo
2021-02-23 22:44:22 +01:00
2021-03-26 01:45:43 +01:00
write(6,'(A)')
write(*,*) "Spin-alpha and Spin-beta determinants"
write(fmt,*) '(', nelectrons, '(i4,1x))'
2021-03-03 15:53:47 +01:00
do i = 1, ndeterminants
2021-03-26 01:45:43 +01:00
! write(*,'(<nelectrons>(i4, 1x))') (iworbd(j,i), j=1,nelectrons) ! For Intel Fortran
write(*,fmt) (iworbd(j,i), j=1,nelectrons)
2021-03-03 15:53:47 +01:00
enddo
read(11,*) temp1
if (temp1 == "end" ) write(*,*) "Determinant File read successfully "
close(11)
2021-02-23 22:44:22 +01:00
endif ! condition if load determinant is present
2021-03-26 01:45:43 +01:00
write(6,'(A)')
write(6,*) '------------------------------------------------------'
endif ! condition determinant block not present
2021-02-23 22:44:22 +01:00
call fdf_shutdown()
!----------------------------------------------------------------------------END
2021-03-26 06:13:07 +01:00
END PROGRAM interface