Skip to content

Commit 6c549f9

Browse files
committed
avoid reserved variable names
1 parent f1c2cca commit 6c549f9

4 files changed

Lines changed: 39 additions & 22 deletions

File tree

ext/BioStructuresDSSPExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function BioStructures.rundssp!(struc::MolecularStructure)
4949
return struc
5050
end
5151

52-
BioStructures.rundssp(el::Union{MolecularStructure, Model}) = rundssp!(deepcopy(el))
52+
BioStructures.rundssp(el::Union{MolecularStructure, Model}) = rundssp!(copy(el))
5353

5454
function BioStructures.rundssp(filepath_in, dssp_filepath_out)
5555
run(`$dssp_executable $filepath_in $dssp_filepath_out`)

ext/BioStructuresSTRIDEExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function BioStructures.runstride!(struc::MolecularStructure)
3535
return struc
3636
end
3737

38-
BioStructures.runstride(el::Union{MolecularStructure, Model}) = runstride!(deepcopy(el))
38+
BioStructures.runstride(el::Union{MolecularStructure, Model}) = runstride!(copy(el))
3939

4040
function BioStructures.runstride(filepath_in, stride_filepath_out)
4141
run(`$stride_executable $filepath_in -f$stride_filepath_out`)

src/model.jl

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,21 @@ struct Atom <: AbstractAtom
113113
charge::String
114114
residue::StructuralElement
115115
end
116-
Atom(a::Atom, r::StructuralElement) = Atom(a.serial, a.name, a.alt_loc_id, copy(a.coords), a.occupancy, a.temp_factor, a.element, a.charge, r)
116+
117+
function Atom(a::Atom, r::StructuralElement)
118+
return Atom(a.serial, a.name, a.alt_loc_id, copy(a.coords), a.occupancy,
119+
a.temp_factor, a.element, a.charge, r)
120+
end
117121

118122
"A container to hold different locations of the same atom."
119123
struct DisorderedAtom <: AbstractAtom
120124
alt_loc_ids::Dict{Char, Atom}
121125
default::Char
122126
end
123-
DisorderedAtom(da::DisorderedAtom, r::StructuralElement) = DisorderedAtom(Dict(k => Atom(a, r) for (k, a) in da.alt_loc_ids), da.default)
127+
128+
function DisorderedAtom(da::DisorderedAtom, r::StructuralElement)
129+
return DisorderedAtom(Dict(k => Atom(a, r) for (k, a) in da.alt_loc_ids), da.default)
130+
end
124131

125132
"""
126133
A residue (amino acid) or other molecule - either a `Residue` or a
@@ -139,11 +146,13 @@ mutable struct Residue <: AbstractResidue
139146
chain::StructuralElement
140147
ss_code::Char
141148
end
142-
function Residue(r::Residue, chain::StructuralElement)
143-
atoms = Dict{String, AbstractAtom}()
144-
rnew = Residue(r.name, r.number, r.ins_code, r.het_res, [name for name in r.atom_list], atoms, chain, r.ss_code)
149+
150+
function Residue(r::Residue, ch::StructuralElement)
151+
atom_dict = Dict{String, AbstractAtom}()
152+
rnew = Residue(r.name, r.number, r.ins_code, r.het_res, [name for name in r.atom_list],
153+
atom_dict, ch, r.ss_code)
145154
for (name, atom) in r.atoms
146-
atoms[name] = isa(atom, Atom) ? Atom(atom, rnew) : DisorderedAtom(atom, rnew)
155+
atom_dict[name] = isa(atom, Atom) ? Atom(atom, rnew) : DisorderedAtom(atom, rnew)
147156
end
148157
return rnew
149158
end
@@ -156,7 +165,10 @@ struct DisorderedResidue <: AbstractResidue
156165
names::Dict{String, Residue}
157166
default::String
158167
end
159-
DisorderedResidue(dr::DisorderedResidue, chain::StructuralElement) = DisorderedResidue(Dict(k => Residue(r, chain) for (k, r) in dr.names), dr.default)
168+
169+
function DisorderedResidue(dr::DisorderedResidue, ch::StructuralElement)
170+
return DisorderedResidue(Dict(k => Residue(r, ch) for (k, r) in dr.names), dr.default)
171+
end
160172

161173
"A chain (molecule) from a macromolecular structure."
162174
mutable struct Chain <: StructuralElement
@@ -165,11 +177,12 @@ mutable struct Chain <: StructuralElement
165177
residues::Dict{String, AbstractResidue}
166178
model::StructuralElement
167179
end
168-
function Chain(c::Chain, model::StructuralElement)
169-
residues = Dict{String, AbstractResidue}()
170-
cnew = Chain(c.id, [id for id in c.res_list], residues, model)
180+
181+
function Chain(c::Chain, mo::StructuralElement)
182+
res_dict = Dict{String, AbstractResidue}()
183+
cnew = Chain(c.id, [id for id in c.res_list], res_dict, mo)
171184
for (id, res) in c.residues
172-
residues[id] = isa(res, Residue) ? Residue(res, cnew) : DisorderedResidue(res, cnew)
185+
res_dict[id] = isa(res, Residue) ? Residue(res, cnew) : DisorderedResidue(res, cnew)
173186
end
174187
return cnew
175188
end
@@ -180,11 +193,12 @@ struct Model <: StructuralElement
180193
chains::Dict{String, Chain}
181194
structure::StructuralElement
182195
end
183-
function Model(m::Model, structure::StructuralElement)
184-
chains = Dict{String, Chain}()
185-
mnew = Model(m.number, chains, structure)
196+
197+
function Model(m::Model, struc::StructuralElement)
198+
chain_dict = Dict{String, Chain}()
199+
mnew = Model(m.number, chain_dict, struc)
186200
for (id, ch) in m.chains
187-
chains[id] = Chain(ch, mnew)
201+
chain_dict[id] = Chain(ch, mnew)
188202
end
189203
return mnew
190204
end
@@ -197,11 +211,12 @@ struct MolecularStructure <: StructuralElement
197211
name::String
198212
models::Dict{Int, Model}
199213
end
214+
200215
function MolecularStructure(s::MolecularStructure)
201-
models = Dict{Int, Model}()
202-
snew = MolecularStructure(s.name, models)
216+
model_dict = Dict{Int, Model}()
217+
snew = MolecularStructure(s.name, model_dict)
203218
for (number, mo) in s.models
204-
models[number] = Model(mo, snew)
219+
model_dict[number] = Model(mo, snew)
205220
end
206221
return snew
207222
end
@@ -373,7 +388,8 @@ end
373388
Base.firstindex(struc::MolecularStructure) = first(modelnumbers(struc))
374389
Base.lastindex(struc::MolecularStructure) = last(modelnumbers(struc))
375390

376-
# recursive copy methods. If we copy a subelement (anything below MolecularStructure), it shares the parent element
391+
# Recursive copy methods
392+
# If we copy a sub-element (anything below MolecularStructure), it shares the parent element
377393
Base.copy(a::Atom) = Atom(a, a.residue)
378394
Base.copy(da::DisorderedAtom) = DisorderedAtom(da, only(unique(a -> a.residue, values(da.alt_loc_ids))).residue)
379395
Base.copy(r::Residue) = Residue(r, r.chain)

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ getchildren(r::Residue) = values(r.atoms)
9494
getchildren(c::Chain) = values(c.residues)
9595
getchildren(m::Model) = values(m.chains)
9696
getchildren(s::MolecularStructure) = values(s.models)
97+
9798
function testparent(children, parent)
9899
for child in children
99100
if isa(child, DisorderedAtom)
@@ -249,7 +250,7 @@ end
249250
@test struc_copy['A'][10]["CA"].coords[2] == 100
250251
@test a.coords[2] == 2
251252
@test struc['A'][10]["CA"].coords[2] == 2
252-
# intermediate copies preserve parenting up to the node of the copy
253+
# Intermediate copies preserve parenting up to the node of the copy
253254
testparent(getchildren(mo), mo)
254255
mo_copy = copy(mo)
255256
testparent(getchildren(mo_copy), mo_copy)

0 commit comments

Comments
 (0)