Skip to content

Commit 18fd4e5

Browse files
authored
Additional error handling for ctfiles in non-V2000 format (#31)
1 parent 9e2ebec commit 18fd4e5

File tree

3 files changed

+123
-2
lines changed

3 files changed

+123
-2
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
with:
1212
python-version: '3.x'
1313
- name: Install dependencies
14-
run: pip install ford
14+
run: pip install ford==6.1.6
1515
- name: Build Documentation
1616
run: ford docs.md
1717
- uses: JamesIves/github-pages-deploy-action@3.7.1

src/mctc/io/read/ctfile.f90

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ subroutine read_molfile(self, unit, error)
115115
& line, token, filename(unit), lnum, "expected integer value")
116116
return
117117
end if
118+
token = token_type(35, 39)
119+
stat = 1
120+
if (len(line) >= 39) then
121+
if (line(35:39) == 'V2000') stat = 0
122+
end if
123+
124+
if (stat /= 0) then
125+
call io_error(error, "Format version not supported", &
126+
& line, token, filename(unit), lnum, "invalid format version")
127+
return
128+
end if
129+
if (number_of_atoms < 1) then
130+
call io_error(error, "Invalid number of atoms", &
131+
& line, token_type(1, 3), filename(unit), lnum, "expected positive integer")
132+
return
133+
end if
118134

119135
allocate(sdf(number_of_atoms))
120136
allocate(xyz(3, number_of_atoms))

test/test_read_ctfile.f90

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ subroutine collect_read_ctfile(testsuite)
3838
& new_unittest("invalid2-mol", test_invalid2_mol, should_fail=.true.), &
3939
& new_unittest("invalid3-mol", test_invalid3_mol, should_fail=.true.), &
4040
& new_unittest("invalid4-mol", test_invalid4_mol, should_fail=.true.), &
41+
& new_unittest("invalid5-mol", test_invalid5_mol, should_fail=.true.), &
4142
& new_unittest("valid1-sdf", test_valid1_sdf), &
4243
& new_unittest("valid2-sdf", test_valid2_sdf), &
4344
& new_unittest("invalid1-sdf", test_invalid1_sdf, should_fail=.true.), &
4445
& new_unittest("invalid2-sdf", test_invalid2_sdf, should_fail=.true.), &
4546
& new_unittest("invalid3-sdf", test_invalid3_sdf, should_fail=.true.), &
46-
& new_unittest("invalid4-sdf", test_invalid4_sdf, should_fail=.true.) &
47+
& new_unittest("invalid4-sdf", test_invalid4_sdf, should_fail=.true.), &
48+
& new_unittest("unsupported1-sdf", test_unsupported1_sdf, should_fail=.true.) &
4749
& ]
4850

4951
end subroutine collect_read_ctfile
@@ -358,6 +360,41 @@ subroutine test_invalid4_mol(error)
358360
end subroutine test_invalid4_mol
359361

360362

363+
subroutine test_invalid5_mol(error)
364+
365+
!> Error handling
366+
type(error_type), allocatable, intent(out) :: error
367+
368+
type(structure_type) :: struc
369+
integer :: unit
370+
371+
open(status='scratch', newunit=unit)
372+
write(unit, '(a)') &
373+
"", &
374+
" Mrv1823 10191918163D ", &
375+
"", &
376+
" 0 12 0 0 0 0 999 V2000", &
377+
" 2 1 4 0 0 0 0", &
378+
" 3 1 4 0 0 0 0", &
379+
" 4 2 4 0 0 0 0", &
380+
" 5 3 4 0 0 0 0", &
381+
" 6 4 4 0 0 0 0", &
382+
" 6 5 4 0 0 0 0", &
383+
" 1 7 1 0 0 0 0", &
384+
" 2 8 1 0 0 0 0", &
385+
" 3 9 1 0 0 0 0", &
386+
" 4 10 1 0 0 0 0", &
387+
" 5 11 1 0 0 0 0", &
388+
" 6 12 1 0 0 0 0", &
389+
"M END"
390+
rewind(unit)
391+
392+
call read_molfile(struc, unit, error)
393+
close(unit)
394+
395+
end subroutine test_invalid5_mol
396+
397+
361398
subroutine test_valid1_sdf(error)
362399

363400
!> Error handling
@@ -702,4 +739,72 @@ subroutine test_invalid4_sdf(error)
702739
end subroutine test_invalid4_sdf
703740

704741

742+
subroutine test_unsupported1_sdf(error)
743+
744+
!> Error handling
745+
type(error_type), allocatable, intent(out) :: error
746+
747+
type(structure_type) :: struc
748+
integer :: unit
749+
750+
open(status='scratch', newunit=unit)
751+
write(unit, '(a)') &
752+
"Compound 11", &
753+
" RDKit 3D", &
754+
"", &
755+
" 0 0 0 0 0 0 0 0 0 0999 V3000", &
756+
"M V30 BEGIN CTAB", &
757+
"M V30 COUNTS 17 16 0 0 0", &
758+
"M V30 BEGIN ATOM", &
759+
"M V30 1 O -2.821131 -0.276238 -0.753131 0", &
760+
"M V30 2 C -2.076407 0.000289 0.175864 0", &
761+
"M V30 3 O -2.469860 0.872693 1.126516 0", &
762+
"M V30 4 C -0.648307 -0.508439 0.384207 0 CFG=1", &
763+
"M V30 5 N -0.553725 -1.908221 -0.092137 0", &
764+
"M V30 6 C 0.306640 0.448659 -0.352110 0", &
765+
"M V30 7 C 1.764852 0.167437 -0.097096 0", &
766+
"M V30 8 C 2.575104 0.984442 0.587951 0", &
767+
"M V30 9 H -3.391314 1.091514 0.873612 0", &
768+
"M V30 10 H -0.438887 -0.513473 1.460318 0", &
769+
"M V30 11 H 0.421206 -2.197466 -0.111774 0", &
770+
"M V30 12 H -0.893195 -1.946576 -1.055443 0", &
771+
"M V30 13 H 0.073377 1.483235 -0.066299 0", &
772+
"M V30 14 H 0.129860 0.396798 -1.434760 0", &
773+
"M V30 15 H 2.179323 -0.745345 -0.519251 0", &
774+
"M V30 16 H 2.219589 1.914253 1.021797 0", &
775+
"M V30 17 H 3.622875 0.736438 0.730780 0", &
776+
"M V30 END ATOM", &
777+
"M V30 BEGIN BOND", &
778+
"M V30 1 2 1 2", &
779+
"M V30 2 1 2 3", &
780+
"M V30 3 1 4 2", &
781+
"M V30 4 1 4 5", &
782+
"M V30 5 1 4 6", &
783+
"M V30 6 1 6 7", &
784+
"M V30 7 2 7 8 CFG=2", &
785+
"M V30 8 1 3 9", &
786+
"M V30 9 1 4 10 CFG=1", &
787+
"M V30 10 1 5 11", &
788+
"M V30 11 1 5 12", &
789+
"M V30 12 1 6 13", &
790+
"M V30 13 1 6 14", &
791+
"M V30 14 1 7 15", &
792+
"M V30 15 1 8 16", &
793+
"M V30 16 1 8 17", &
794+
"M V30 END BOND", &
795+
"M V30 BEGIN COLLECTION", &
796+
"M V30 MDLV30/STERAC1 ATOMS=(1 4)", &
797+
"M V30 END COLLECTION", &
798+
"M V30 END CTAB", &
799+
"M END", &
800+
"> <smiles> (1) ", &
801+
"NC(CC=C)C(=O)O", &
802+
"", &
803+
"$$$$"
804+
rewind(unit)
805+
806+
call read_sdf(struc, unit, error)
807+
808+
end subroutine test_unsupported1_sdf
809+
705810
end module test_read_ctfile

0 commit comments

Comments
 (0)