Skip to content

Commit 00d19d1

Browse files
committed
rename specialize_resnames!
1 parent 3b4e96e commit 00d19d1

4 files changed

Lines changed: 30 additions & 19 deletions

File tree

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# BioStructures.jl release notes
22

3+
## v4.7.0 - Sep 2025
4+
5+
* `specializeresnames!` is added, allowing residues to be renamed to reflect the bonding topology.
6+
37
## v4.6.1 - Sep 2025
48

59
* mmCIF file parsing is made more robust with respect to the available fields, and for example will use `_atom_site.label_atom_id` when `_atom_site.auth_atom_id` is not available.

docs/src/documentation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ Similar to [`ContactMap`](@ref), contacts are found between any element type pas
568568
So if you wanted the graph of chain contacts in a protein complex you could give a [`Model`](@ref) as the first argument.
569569

570570
Calling `MetaGraph` on a [`Chain`](@ref) without a contact distance does something different: it constructs a graph of atoms where edges are determined by the known bonds of standard amino acids in the chain.
571-
Hydrogens should be present and atom names should match those in OpenMM. See [`specialize_resnames!`](@ref) to
571+
Hydrogens should be present and atom names should match those in OpenMM. See [`specializeresnames!`](@ref) to
572572
ensure that residue names have been specialized to their actual configuration in the protein:
573573

574574
```julia-repl
@@ -586,11 +586,11 @@ julia> mg = MetaGraph(struc_M3YHX5["A"]; strict=false)
586586
{1833, 1850} undirected Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)
587587
```
588588

589-
but if you really want to get all the bonds, you'd better use the default `strict=true`.
589+
But if you really want to get all the bonds, you'd better use the default `strict=true`.
590590
Fortunately, this example only requires residue renaming:
591591

592592
```julia-repl
593-
julia> specialize_resnames!(struc_M3YHX5)
593+
julia> specializeresnames!(struc_M3YHX5)
594594
MolecularStructure AF-M3YHX5-F1-model_v4_hydrogens.cif with 1 models, 1 chains (A), 112 residues, 1833 atoms
595595

596596
julia> mg = MetaGraph(struc_M3YHX5["A"])

src/model.jl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export
3939
defaultresname,
4040
defaultresidue,
4141
resnames,
42-
specialize_resnames!,
4342
sscode,
4443
sscode!,
4544
chain,
@@ -56,6 +55,7 @@ export
5655
modelnumbers,
5756
models,
5857
defaultmodel,
58+
specializeresnames!,
5959
sequentialresidues,
6060
collect,
6161
collectmodels,
@@ -1099,15 +1099,19 @@ This is the `Model` with the lowest model number.
10991099
defaultmodel(struc::MolecularStructure) = first(sort(collect(values(models(struc)))))
11001100

11011101
"""
1102-
specialize_resnames!(r)
1102+
specializeresnames!(el)
11031103
1104-
If `r` is a histidine residue, rename it to reflect a specific protonation configuration (HID,
1105-
HIE, or HIP) based on the presence of HD1 and HE2 atoms. For any other residue,
1106-
`r` will be unchanged.
1104+
Rename residues to reflect the bonding topology.
1105+
1106+
Renames histidine residues to reflect a specific protonation configuration
1107+
(HID, HIE, or HIP) based on the presence of HD1 and HE2 atoms.
1108+
Renames N-terminal and C-terminal (e.g. ALA -> NALA) residues based on the
1109+
presence of certain atoms.
1110+
Other residues remain unchanged.
11071111
11081112
Hydrogens must have been assigned prior to calling this function.
11091113
"""
1110-
function specialize_resnames!(r::Residue)
1114+
function specializeresnames!(r::Residue)
11111115
rname = resname(r)
11121116
if rname == "HIS"
11131117
hd1 = findatombyname(r, "HD1"; strict=false)
@@ -1130,21 +1134,24 @@ function specialize_resnames!(r::Residue)
11301134
end
11311135
return r
11321136
end
1133-
specialize_resnames!(r::DisorderedResidue) = (foreach(specialize_resnames!, collectresidues(r; expand_disordered=true)); r)
1134-
function specialize_resnames!(c::Chain)
1137+
1138+
specializeresnames!(r::DisorderedResidue) = (foreach(specializeresnames!, collectresidues(r; expand_disordered=true)); r)
1139+
1140+
function specializeresnames!(c::Chain)
11351141
for (key, res) in c.residues
11361142
if isa(res, DisorderedResidue)
11371143
# Create a new `names` dictionary with specialized residue names
1138-
names = Dict((specialize_resnames!(r); resname(r, strip=false) => r) for r in values(res.names))
1144+
names = Dict((specializeresnames!(r); resname(r, strip=false) => r) for r in values(res.names))
11391145
c.residues[key] = DisorderedResidue(names, resname(res.names[defaultresname(res)]))
11401146
else
1141-
specialize_resnames!(res)
1147+
specializeresnames!(res)
11421148
end
11431149
end
11441150
return c
11451151
end
1146-
specialize_resnames!(m::Model) = (foreach(specialize_resnames!, m); m)
1147-
specialize_resnames!(s::MolecularStructure) = (foreach(specialize_resnames!, s); s)
1152+
1153+
specializeresnames!(m::Model) = (foreach(specializeresnames!, m); m)
1154+
specializeresnames!(s::MolecularStructure) = (foreach(specializeresnames!, s); s)
11481155

11491156
# Sort lists of elements
11501157

test/runtests.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3512,7 +3512,7 @@ end
35123512
@test_throws KeyError MetaGraph(struc_1AKE["A"]) # it's missing hydrogens
35133513
struc_M3YHX5 = read(joinpath(@__DIR__, "data", "AF-M3YHX5-F1-model_v4_hydrogens.cif"), MMCIFFormat)
35143514
@test_throws KeyError MetaGraph(struc_M3YHX5["A"]; strict=true) # residues need to be renamed
3515-
specialize_resnames!(struc_M3YHX5)
3515+
specializeresnames!(struc_M3YHX5)
35163516
mg = MetaGraph(struc_M3YHX5["A"]; strict=true)
35173517
@test nv(mg) == 1833
35183518

@@ -3648,9 +3648,9 @@ end
36483648
rm(temp_filename)
36493649
end
36503650

3651-
@testset "ff19SB-compliant residue names for added hydrogens" begin
3651+
@testset "Renaming residues" begin
36523652
struc = read(joinpath(@__DIR__, "data", "AF-M3YHX5-F1-model_v4_hydrogens.cif"), MMCIFFormat)
3653-
specialize_resnames!(struc)
3653+
specializeresnames!(struc)
36543654
A = struc["A"]
36553655
@test resname(first(A)) == "NMET"
36563656
@test resname(last(A)) == "CSER"
@@ -3673,7 +3673,7 @@ end
36733673
r = struc_1res['A'][1]
36743674
@test r isa DisorderedResidue
36753675
@test resname(defaultresidue(r)) == "HIS"
3676-
specialize_resnames!(struc_1res)
3676+
specializeresnames!(struc_1res)
36773677
r = struc_1res['A'][1]
36783678
@test r isa DisorderedResidue
36793679
@test resname(defaultresidue(r)) == "HIE"

0 commit comments

Comments
 (0)