Skip to content

Commit

Permalink
Added block reading functionality for displacements
Browse files Browse the repository at this point in the history
  • Loading branch information
neelravi committed Aug 20, 2024
1 parent 3652fcd commit 718553c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
12 changes: 8 additions & 4 deletions src/parser/fdf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ RECURSIVE SUBROUTINE fdf_read_custom(filein, blocklabel)
character(len=MAX_LENGTH) :: keyword

!--------------------------------------------------------------- Local Variables
logical :: dump
logical :: dump, within_block
logical, allocatable :: found(:)
character(80) :: msg
character(len=MAX_LENGTH) :: label, inc_file, modulename
Expand Down Expand Up @@ -1159,7 +1159,7 @@ RECURSIVE SUBROUTINE fdf_read_custom(filein, blocklabel)
! %block directive
ind_less = search('<', pline)
if (search('%block', pline) .eq. 1) then
! print*, "debug::library:: inside block construct "
within_block = .TRUE.
! No label found in %block directive
if (ntok .eq. 1) then
write(msg,*) '%block label not found in ', TRIM(filein)
Expand Down Expand Up @@ -1191,7 +1191,6 @@ RECURSIVE SUBROUTINE fdf_read_custom(filein, blocklabel)
nullify(pline) ! it is stored in line

nlstart = file_in%nlines
! print*, "debug:: nlstart ", nlstart

call fdf_read(inc_file, label)

Expand All @@ -1208,6 +1207,7 @@ RECURSIVE SUBROUTINE fdf_read_custom(filein, blocklabel)
call setmorphol(2, 'l', pline)
call fdf_addtoken(line, pline)
nullify(pline) ! it is stored in line
within_block = .FALSE.

! Dump included file to fileout
if (dump) call fdf_dump(label)
Expand Down Expand Up @@ -1238,6 +1238,7 @@ RECURSIVE SUBROUTINE fdf_read_custom(filein, blocklabel)

! %endblock directive
elseif (search('%endblock', pline) .eq. 1) then
within_block = .FALSE.
! print*, "debug::library:: inside endblock construct "
! Check if %block exists before %endblock
if (label .eq. ' ') then
Expand Down Expand Up @@ -1372,7 +1373,10 @@ RECURSIVE SUBROUTINE fdf_read_custom(filein, blocklabel)
! Following three lines will validate the keyword against allowed CHAMP keywords
keyword = trim(tokens(pline,1))
if (tokens(pline, 1) == "load" ) keyword = trim(tokens(pline,2))
call validate_keywords(keyword)

if (.not. within_block) then
call validate_keywords(keyword)
endif

if (label .eq. ' ') call setmorphol(1, 'l', pline)
call fdf_addtoken(line, pline)
Expand Down
56 changes: 48 additions & 8 deletions src/vmc/parser.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1735,10 +1735,10 @@ subroutine parser

! (13) Forces information (either block or from a file) [#####]

if (fdf_load_defined('forces') ) then
call read_forces_file(file_forces)
elseif (fdf_block('forces', bfdf)) then
if (fdf_block('forces', bfdf)) then
call fdf_read_forces_block(bfdf)
elseif (fdf_load_defined('forces') ) then
call read_forces_file(file_forces)
else
if(nforce.ge.1.and.iforces.eq.0.and.igradients.eq.0) then
write(errunit,*) "INPUT: block forces_displace or gradients_* missing: geometries set equal to primary"
Expand Down Expand Up @@ -2333,26 +2333,66 @@ subroutine fdf_read_forces_block(bfdf)
implicit none
type(block_fdf) :: bfdf
type(parsed_line), pointer :: pline
integer :: i,j,k
integer :: i,j,k,l

! Format of the forces block
!
! %block forces
! 1 1
! -0.733652000000 0.1 -1.157935000000
! 0.733652000000 0.1 1.157935000000
! 0.298187000000 0.1 -3.466419000000
! -0.298187000000 0.1 3.466419000000
! 2.326423000000 0.1 -3.706633000000
! -2.326423000000 0.1 3.706633000000
! -2.772181000000 0.1 -0.963193000000
! 2.772181000000 0.1 0.963193000000
! -0.855551000000 0.1 -5.146950000000
! 0.855551000000 0.1 5.146950000000
! #
! -3.733652000000 2.1 -1.157935000000
! 3.733652000000 2.1 1.157935000000
! 3.298187000000 2.1 -3.466419000000
! -3.298187000000 2.1 3.466419000000
! 3.326423000000 2.1 -3.706633000000
! -3.326423000000 2.1 3.706633000000
! -3.772181000000 2.1 -0.963193000000
! 3.772181000000 2.1 0.963193000000
! -3.855551000000 2.1 -5.146950000000
! 3.855551000000 2.1 5.146950000000
! %endblock

if (.not. allocated(delc)) allocate (delc(3, ncent, nforce))
if (.not. allocated(iwftype)) allocate (iwftype(nforce))

i = 1; j = 1
do while((fdf_bline(bfdf, pline)))
if (pline%ntokens == 1) i = fdf_bintegers(pline, 1)
if (pline%ntokens == 3) then
if (pline%ntokens == nforce .and. (pline%id(1) .eq. "i") ) then
do l = 1, nforce
iwftype(l) = fdf_bintegers(pline, l)
enddo
endif
if (pline%ntokens == 3 .and. (any(pline%id(1:3).eq."r")) ) then
do k = 1, 3
delc(k, j, i) = fdf_bvalues(pline, k)
enddo ! xyz
j = j + 1

if (mod(j, ncent) == 0) then
i = i + 1
j = 1
else
j = j + 1
endif

endif ! expect only three values in a line
enddo ! parse entire file


write(ounit,*) 'Force displacements from the %block forces '
write(ounit,*)
do i = 1, nforce
write(ounit,'(a,i4)') 'Number ::',i
write(ounit,*) '-----------------------------------------------------------------------'
write(ounit,'(a,i4)') 'Number (iwftype) :: ',i
write(ounit,*) '-----------------------------------------------------------------------'
write(ounit,'(a, t15, a, t27, a, t39, a, t45)') 'Symbol', 'x', 'y', 'z'
write(ounit,'(t14, a, t26, a, t38, a )') '(A)', '(A)', '(A)'
Expand Down

0 comments on commit 718553c

Please sign in to comment.