Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fix for reading poscar reading #64

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/mctc/io/read/vasp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ subroutine read_vasp(self, unit, error)
return
end if

call parse_line(line, args, ntype)
call parse_line(" " // line, args, ntype)
call move_alloc(line, comment)

! this line contains the global scaling factor,
Expand Down Expand Up @@ -120,7 +120,7 @@ subroutine read_vasp(self, unit, error)

! CONTCAR files have additional Element line here since vasp.5.1
if (verify(line(i:j), '1234567890') /= 0) then
call parse_line(line, args, ntype)
call parse_line(" " // line, args, ntype)
call next_line(unit, line, pos, lnum, stat)
if (stat /= 0) then
call fatal_error(error, "Unexpected end of input encountered")
Expand All @@ -129,7 +129,7 @@ subroutine read_vasp(self, unit, error)
else
deallocate(comment)
end if
call parse_line(line, args2, nn)
call parse_line(" " // line, args2, nn)
if (nn /= ntype) then
call fatal_error(error, 'Number of atom types mismatches the number of counts')
return
Expand Down
36 changes: 35 additions & 1 deletion test/test_read_vasp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ subroutine collect_read_vasp(testsuite)
& new_unittest("invalid4-poscar", test_invalid4_poscar, should_fail=.true.), &
& new_unittest("invalid5-poscar", test_invalid5_poscar, should_fail=.true.), &
& new_unittest("invalid6-poscar", test_invalid6_poscar, should_fail=.true.), &
& new_unittest("invalid7-poscar", test_invalid7_poscar, should_fail=.true.) &
& new_unittest("invalid7-poscar", test_invalid7_poscar, should_fail=.true.), &
& new_unittest("issue60", test_issue60) &
& ]

end subroutine collect_read_vasp
Expand Down Expand Up @@ -476,4 +477,37 @@ subroutine test_invalid7_poscar(error)
end subroutine test_invalid7_poscar


subroutine test_issue60(error)

!> Error handling
type(error_type), allocatable, intent(out) :: error

type(structure_type) :: struc
integer :: unit

open(status='scratch', newunit=unit)
write(unit, '(a)') &
"POSCAR", &
"3.0", &
"1.0 0.0 0.0", &
"0.0 1.0 0.0", &
"0.0 0.0 1.0", &
"S", &
"1", &
"direct", &
"0.0 0.0 0.0"
rewind(unit)

call read_vasp(struc, unit, error)
close(unit)
if (allocated(error)) return

call check(error, struc%nat, 1, "Number of atoms does not match")
if (allocated(error)) return
call check(error, struc%nid, 1, "Number of species does not match")
if (allocated(error)) return

end subroutine test_issue60


end module test_read_vasp
Loading