Skip to content

Commit 89a04bd

Browse files
authored
Allow trailing whitespace in mol and sdf inputs (grimme-lab#94)
Closes grimme-lab#92
1 parent b76b93b commit 89a04bd

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

src/mctc/io/read/ctfile.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ subroutine read_molfile_v2k(self, unit, number_of_atoms, number_of_bonds, error)
197197
list12(:) = 0
198198
do i = 1, 11
199199
if (stat == 0) then
200-
if ((36+i*3) > len(line)) exit
200+
if ((36+i*3) > len_trim(line)) exit
201201
token = token_type(34 + i*3, 36 + i*3)
202202
call read_token(line, token, list12(i+1), stat)
203203
end if
@@ -227,7 +227,7 @@ subroutine read_molfile_v2k(self, unit, number_of_atoms, number_of_bonds, error)
227227
list7(:) = 0
228228
do i = 1, 7
229229
if (stat == 0) then
230-
if ((i*3) > len(line)) exit
230+
if ((i*3) > len_trim(line)) exit
231231
token = token_type(i*3 - 2, i*3)
232232
call read_token(line, token, list7(i), stat)
233233
end if

test/test_read_ctfile.f90

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ subroutine collect_read_ctfile(testsuite)
3636
& new_unittest("valid2-mol", test_valid2_mol), &
3737
& new_unittest("valid3-mol", test_valid3_mol), &
3838
& new_unittest("valid4-mol", test_valid4_mol), &
39+
& new_unittest("valid5-mol", test_valid5_mol), &
3940
& new_unittest("invalid1-mol", test_invalid1_mol, should_fail=.true.), &
4041
& new_unittest("invalid2-mol", test_invalid2_mol, should_fail=.true.), &
4142
& new_unittest("invalid3-mol", test_invalid3_mol, should_fail=.true.), &
@@ -386,6 +387,63 @@ subroutine test_valid4_mol(error)
386387
end subroutine test_valid4_mol
387388

388389

390+
subroutine test_valid5_mol(error)
391+
392+
!> Error handling
393+
type(error_type), allocatable, intent(out) :: error
394+
395+
type(structure_type) :: struc
396+
integer :: unit
397+
398+
open(status='scratch', newunit=unit)
399+
write(unit, '(a)') &
400+
"", &
401+
" Mrv1823 10191918163D ", &
402+
"", &
403+
" 12 12 0 0 0 0 999 V2000", &
404+
" -0.0090 -0.0157 -0.0000 C 0 ", &
405+
" -0.7131 1.2038 -0.0000 C 0 ", &
406+
" 1.3990 -0.0157 -0.0000 C 0 ", &
407+
" -0.0090 2.4232 -0.0000 C 0 ", &
408+
" 2.1031 1.2038 -0.0000 C 0 ", &
409+
" 1.3990 2.4232 0.0000 C 0 ", &
410+
" -0.5203 -0.9011 -0.0000 H 0 ", &
411+
" -1.7355 1.2038 0.0000 H 0 ", &
412+
" 1.9103 -0.9011 0.0000 H 0 ", &
413+
" -0.5203 3.3087 0.0000 H 0 ", &
414+
" 3.1255 1.2038 0.0000 H 0 ", &
415+
" 1.9103 3.3087 -0.0000 H 0 ", &
416+
" 2 1 4 0 ", &
417+
" 3 1 4 0 ", &
418+
" 4 2 4 0 ", &
419+
" 5 3 4 0 ", &
420+
" 6 4 4 0 ", &
421+
" 6 5 4 0 ", &
422+
" 1 7 1 0 ", &
423+
" 2 8 1 0 ", &
424+
" 3 9 1 0 ", &
425+
" 4 10 1 0 ", &
426+
" 5 11 1 0 ", &
427+
" 6 12 1 0 ", &
428+
"M END"
429+
rewind(unit)
430+
431+
call read_molfile(struc, unit, error)
432+
close(unit)
433+
if (allocated(error)) return
434+
435+
call check(error, .not.allocated(struc%comment), "Empty comment line should not be saved")
436+
if (allocated(error)) return
437+
call check(error, struc%nat, 12, "Number of atoms does not match")
438+
if (allocated(error)) return
439+
call check(error, struc%nid, 2, "Number of species does not match")
440+
if (allocated(error)) return
441+
call check(error, struc%nbd, 12, "Number of bonds does not match")
442+
if (allocated(error)) return
443+
444+
end subroutine test_valid5_mol
445+
446+
389447
subroutine test_invalid1_mol(error)
390448

391449
!> Error handling

0 commit comments

Comments
 (0)