1313! limitations under the License.
1414
1515module test_write_ctfile
16+ use mctc_env_accuracy, only : wp
1617 use mctc_env_testing, only : new_unittest, unittest_type, error_type, check
1718 use testsuite_structure, only : get_structure
1819 use mctc_io_write_ctfile
@@ -35,7 +36,10 @@ subroutine collect_write_ctfile(testsuite)
3536
3637 testsuite = [ &
3738 & new_unittest(" valid1-mol" , test_valid1_mol), &
38- & new_unittest(" valid1-sdf" , test_valid1_sdf) &
39+ & new_unittest(" valid1-sdf" , test_valid1_sdf), &
40+ & new_unittest(" v3k-large-mol" , test_v3k_large_mol), &
41+ & new_unittest(" v3k-large-sdf" , test_v3k_large_sdf), &
42+ & new_unittest(" v3k-with-bonds" , test_v3k_with_bonds) &
3943 & ]
4044
4145end subroutine collect_write_ctfile
@@ -97,4 +101,147 @@ subroutine test_valid1_sdf(error)
97101end subroutine test_valid1_sdf
98102
99103
104+ subroutine test_v3k_large_mol (error )
105+
106+ ! > Error handling
107+ type (error_type), allocatable , intent (out ) :: error
108+
109+ type (structure_type) :: struc, struc_read
110+ integer :: unit, nat, i
111+ character (len= 2 ), allocatable :: sym(:)
112+ real (wp), allocatable :: xyz(:, :)
113+
114+ ! Create a structure with 1001 atoms to trigger V3000 format
115+ nat = 1001
116+ allocate (sym(nat), xyz(3 , nat))
117+
118+ ! Create alternating H and C atoms on a line
119+ do i = 1 , nat
120+ if (mod (i, 2 ) == 0 ) then
121+ sym(i) = " C"
122+ else
123+ sym(i) = " H"
124+ end if
125+ xyz(1 , i) = real (i, wp)
126+ xyz(2 , i) = 0.0_wp
127+ xyz(3 , i) = 0.0_wp
128+ end do
129+
130+ call new (struc, sym, xyz)
131+
132+ open (status= ' scratch' , newunit= unit)
133+ call write_molfile(struc, unit)
134+ rewind(unit)
135+
136+ call read_molfile(struc_read, unit, error)
137+ close (unit)
138+ if (allocated (error)) return
139+
140+ call check(error, struc_read% nat, nat, " Number of atoms does not match" )
141+ if (allocated (error)) return
142+ call check(error, struc_read% nid, 2 , " Number of species does not match" )
143+ if (allocated (error)) return
144+
145+ end subroutine test_v3k_large_mol
146+
147+
148+ subroutine test_v3k_large_sdf (error )
149+
150+ ! > Error handling
151+ type (error_type), allocatable , intent (out ) :: error
152+
153+ type (structure_type) :: struc, struc_read
154+ integer :: unit, nat, i
155+ character (len= 2 ), allocatable :: sym(:)
156+ real (wp), allocatable :: xyz(:, :)
157+
158+ ! Create a structure with 1001 atoms to trigger V3000 format
159+ nat = 1001
160+ allocate (sym(nat), xyz(3 , nat))
161+
162+ ! Create alternating H and C atoms on a line
163+ do i = 1 , nat
164+ if (mod (i, 2 ) == 0 ) then
165+ sym(i) = " C"
166+ else
167+ sym(i) = " H"
168+ end if
169+ xyz(1 , i) = real (i, wp)
170+ xyz(2 , i) = 0.0_wp
171+ xyz(3 , i) = 0.0_wp
172+ end do
173+
174+ call new (struc, sym, xyz)
175+
176+ open (status= ' scratch' , newunit= unit)
177+ call write_sdf(struc, unit)
178+ rewind(unit)
179+
180+ call read_sdf(struc_read, unit, error)
181+ close (unit)
182+ if (allocated (error)) return
183+
184+ call check(error, struc_read% nat, nat, " Number of atoms does not match" )
185+ if (allocated (error)) return
186+ call check(error, struc_read% nid, 2 , " Number of species does not match" )
187+ if (allocated (error)) return
188+
189+ end subroutine test_v3k_large_sdf
190+
191+
192+ subroutine test_v3k_with_bonds (error )
193+
194+ ! > Error handling
195+ type (error_type), allocatable , intent (out ) :: error
196+
197+ type (structure_type) :: struc, struc_read
198+ integer :: unit, nat, nbd, i
199+ character (len= 2 ), allocatable :: sym(:)
200+ real (wp), allocatable :: xyz(:, :)
201+ integer , allocatable :: bond(:, :)
202+
203+ ! Create a structure with 1001 atoms and 1000 bonds to trigger V3000 format
204+ nat = 1001
205+ nbd = 1000
206+ allocate (sym(nat), xyz(3 , nat), bond(3 , nbd))
207+
208+ ! Create a linear chain of alternating H and C atoms
209+ do i = 1 , nat
210+ if (mod (i, 2 ) == 0 ) then
211+ sym(i) = " C"
212+ else
213+ sym(i) = " H"
214+ end if
215+ xyz(1 , i) = real (i, wp)
216+ xyz(2 , i) = 0.0_wp
217+ xyz(3 , i) = 0.0_wp
218+ end do
219+
220+ ! Create bonds connecting each consecutive atom pair
221+ do i = 1 , nbd
222+ bond(1 , i) = i
223+ bond(2 , i) = i + 1
224+ bond(3 , i) = 1 ! single bond
225+ end do
226+
227+ call new (struc, sym, xyz, bond= bond)
228+
229+ open (status= ' scratch' , newunit= unit)
230+ call write_molfile(struc, unit)
231+ rewind(unit)
232+
233+ call read_molfile(struc_read, unit, error)
234+ close (unit)
235+ if (allocated (error)) return
236+
237+ call check(error, struc_read% nat, nat, " Number of atoms does not match" )
238+ if (allocated (error)) return
239+ call check(error, struc_read% nid, 2 , " Number of species does not match" )
240+ if (allocated (error)) return
241+ call check(error, struc_read% nbd, nbd, " Number of bonds does not match" )
242+ if (allocated (error)) return
243+
244+ end subroutine test_v3k_with_bonds
245+
246+
100247end module test_write_ctfile
0 commit comments