@@ -75,16 +75,17 @@ Call `MMCIFDict` with a filepath or stream to read the dictionary from that
75
75
source.
76
76
The keyword argument `gzip` (default `false`) determines if the input is gzipped.
77
77
"""
78
- struct MMCIFDict <: AbstractDict{String , Vector{String }}
79
- dict:: Dict{String , Vector{String }}
78
+ struct MMCIFDict{K <: AbstractString } <: AbstractDict{K , Vector{K }}
79
+ dict:: Dict{K , Vector{K }}
80
80
end
81
81
82
- MMCIFDict () = MMCIFDict (Dict ())
82
+ MMCIFDict {K} () where K<: AbstractString = MMCIFDict {K} (Dict {K,Vector{K}} ())
83
+ MMCIFDict () = MMCIFDict {String} ()
83
84
84
85
Base. getindex (mmcif_dict:: MMCIFDict , field:: AbstractString ) = mmcif_dict. dict[field]
85
86
86
87
function Base. setindex! (mmcif_dict:: MMCIFDict ,
87
- val:: AbstractVector{<:String } ,
88
+ val:: AbstractVector{<:AbstractString } ,
88
89
field:: AbstractString )
89
90
mmcif_dict. dict[field] = val
90
91
return mmcif_dict
@@ -147,7 +148,7 @@ splitline(s::AbstractString) = splitline!(String[], s) # mostly for testing
147
148
148
149
# Get tokens from a mmCIF file
149
150
function tokenizecif (f:: IO )
150
- tokens = String[]
151
+ tokens = SubString{ String} []
151
152
for line in eachline (f)
152
153
if startswith (line, " #" )
153
154
continue
172
173
# This will fail if there is only a single atom record in the file
173
174
# and it is not in the loop format
174
175
function tokenizecifstructure (f:: IO )
175
- tokens = String[]
176
+ tokens = SubString{ String} []
176
177
reading = false
177
178
in_keys = true
178
179
category_groups = [" _atom_site." , " _struct_conf." ]
@@ -218,14 +219,14 @@ end
218
219
219
220
# Read a mmCIF file into a MMCIFDict
220
221
function MMCIFDict (f:: IO ; gzip:: Bool = false )
221
- mmcif_dict = MMCIFDict ()
222
222
if gzip
223
223
gz = GzipDecompressorStream (f)
224
224
tokens = tokenizecif (gz)
225
225
close (gz)
226
226
else
227
227
tokens = tokenizecif (f)
228
228
end
229
+ mmcif_dict = MMCIFDict {eltype(tokens)} ()
229
230
# Data label token is read first
230
231
if length (tokens) == 0
231
232
return mmcif_dict
@@ -236,16 +237,16 @@ function MMCIFDict(f::IO; gzip::Bool=false)
236
237
end
237
238
238
239
# Add tokens to a mmCIF dictionary
239
- function populatedict! (mmcif_dict:: MMCIFDict , tokens:: AbstractVector{<:AbstractString} )
240
+ function populatedict! (mmcif_dict:: MMCIFDict{K} , tokens:: AbstractVector{<:AbstractString} ) where K <: AbstractString
240
241
key = " "
241
- keys = String []
242
+ keys = K []
242
243
loop_flag = false
243
244
i = 0 # Value counter
244
245
n = 0 # Key counter
245
246
for token in tokens
246
247
if token == " loop_" || token == " LOOP_"
247
248
loop_flag = true
248
- keys = String []
249
+ keys = K []
249
250
i = 0
250
251
n = 0
251
252
continue
@@ -258,7 +259,7 @@ function populatedict!(mmcif_dict::MMCIFDict, tokens::AbstractVector{<:AbstractS
258
259
if i > 0
259
260
loop_flag = false
260
261
else
261
- mmcif_dict[token] = String []
262
+ mmcif_dict[token] = K []
262
263
push! (keys, token)
263
264
n += 1
264
265
continue
@@ -290,14 +291,14 @@ function Base.read(input::IO,
290
291
run_dssp:: Bool = false ,
291
292
run_stride:: Bool = false ,
292
293
gzip:: Bool = false )
293
- mmcif_dict = MMCIFDict ()
294
294
if gzip
295
295
gz = GzipDecompressorStream (input)
296
296
tokens = tokenizecifstructure (gz)
297
297
close (gz)
298
298
else
299
299
tokens = tokenizecifstructure (input)
300
300
end
301
+ mmcif_dict = MMCIFDict {eltype(tokens)} ()
301
302
populatedict! (mmcif_dict, tokens)
302
303
return MolecularStructure (
303
304
mmcif_dict;
0 commit comments