-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support residue "ins codes", linear backbone indexing only + other ch…
…anges
- Loading branch information
1 parent
99d32dd
commit 35a27e8
Showing
13 changed files
with
73 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,33 @@ | ||
export Backbone | ||
|
||
""" | ||
Backbone{T <: Real, M <: AbstractMatrix{T}} <: AbstractMatrix{T} | ||
Backbone{T<:Real,M<:AbstractMatrix{T}} <: AbstractVector{AbstractVector{T}} | ||
The `Backbone` type is designed to efficiently store and manipulate the three-dimensional coordinates of backbone atoms. | ||
# Examples | ||
A `Backbone` can be created from a matrix of coordinates: | ||
```jldoctest | ||
julia> backbone = Backbone(zeros(3, 5)) # 5 atoms with 3 coordinates each | ||
3×5 Backbone{Float64, Matrix{Float64}}: | ||
0.0 0.0 0.0 0.0 0.0 | ||
0.0 0.0 0.0 0.0 0.0 | ||
0.0 0.0 0.0 0.0 0.0 | ||
julia> backbone[1] = [1.0, 2.0, 3.0]; # set the first atom's coordinates | ||
julia> backbone | ||
3×5 Backbone{Float64, Matrix{Float64}}: | ||
1.0 0.0 0.0 0.0 0.0 | ||
2.0 0.0 0.0 0.0 0.0 | ||
3.0 0.0 0.0 0.0 0.0 | ||
julia> backbone[1:2] # indexing by range returns a new Backbone | ||
3×2 Backbone{Float64, Matrix{Float64}}: | ||
1.0 0.0 | ||
2.0 0.0 | ||
3.0 0.0 | ||
``` | ||
Arrays will always be flattened to a 3xN matrix: | ||
```jldoctest | ||
julia> backbone = Backbone(zeros(3, 3, 4)) # e.g. 3 coordinates per atom, 3 atoms per residue, 4 residues | ||
3×12 Backbone{Float64, Matrix{Float64}}: | ||
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 | ||
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 | ||
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 | ||
``` | ||
""" | ||
struct Backbone{T <: Real, M <: AbstractMatrix{T}} <: AbstractMatrix{T} | ||
struct Backbone{T<:Real,M<:AbstractMatrix{T}} <: AbstractVector{AbstractVector{T}} | ||
coords::M | ||
|
||
function Backbone{T, M}(coords::M) where {T <: Real, M <: AbstractMatrix{T}} | ||
function Backbone{T,M}(coords::M) where {T<:Real,M<:AbstractMatrix{T}} | ||
size(coords, 1) == 3 || throw(ArgumentError("Expected the first dimension of coords to have a size of 3")) | ||
return new{T, M}(coords) | ||
return new(coords) | ||
end | ||
end | ||
|
||
Backbone{T}(coords::M) where {T <: Real, M <: AbstractMatrix{T}} = Backbone{T, M}(coords) | ||
Backbone{T}(coords::AbstractArray{T}) where T <: Real = Backbone{T}(reshape(coords, size(coords, 1), :)) | ||
Backbone{T}(coords::AbstractArray{<:Real}) where T <: Real = Backbone{T}(convert.(T, coords)) | ||
Backbone{T}(backbone::Backbone) where T <: Real = Backbone{T}(backbone.coords) | ||
Backbone(coords::AbstractArray{T}) where T <: Real = Backbone{T}(coords) | ||
|
||
Backbone{T, M}(::UndefInitializer, n::Integer) where {T <: Real, M <: AbstractMatrix{T}} = Backbone{T, M}(M(undef, 3, n)) | ||
Backbone{T}(::UndefInitializer, n::Integer) where T = Backbone{T, Matrix{T}}(undef, n) | ||
Backbone{T}() where T = Backbone{T}(undef, 0) | ||
|
||
Base.values(backbone::Backbone) = backbone.coords | ||
|
||
@inline Base.size(backbone::Backbone) = size(backbone.coords) | ||
@inline Base.getindex(backbone::Backbone, i, j) = backbone.coords[i, j] | ||
@inline Base.view(backbone::Backbone, i, j) = view(backbone.coords, i, j) | ||
@inline Base.setindex!(backbone::Backbone, v, i, j) = (backbone.coords[i, j] .= v) | ||
|
||
@inline Base.length(backbone::Backbone) = size(backbone, 2) | ||
@inline Base.size(backbone::Backbone) = Tuple(size(backbone.coords, 2)) | ||
@inline Base.getindex(backbone::Backbone, i) = Backbone(backbone.coords[:, i]) | ||
@inline Base.view(backbone::Backbone, i) = Backbone(view(backbone.coords, :, i)) | ||
@inline Base.setindex!(backbone::Backbone, v, i) = (backbone.coords[:, i] .= v) | ||
|
||
@inline Base.getindex(backbone::Backbone, i::Integer) = backbone.coords[:, i] | ||
@inline Base.view(backbone::Backbone, i::Integer) = view(backbone.coords, :, i) | ||
|
||
Base.copy(backbone::Backbone) = copy(backbone.coords) | ||
|
||
Base.:(==)(backbone1::Backbone, backbone2::Backbone) = backbone1.coords == backbone2.coords | ||
Base.:(==)(backbone::Backbone, coords::AbstractMatrix) = backbone.coords == coords | ||
Base.:(==)(coords::AbstractMatrix, backbone::Backbone) = coords == backbone.coords | ||
|
||
Base.hash(backbone::Backbone, h::UInt) = hash(backbone.coords, h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
35a27e8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
Release notes:
Backbone{T}
a subtype ofAbstractVector{AbstractVector{T}}
, instead ofAbstractMatrix{T}
.get_bond_lengths(bond_vectors)
,get_bond_angles(bond_vectors)
, andget_dihedrals(bond_vectors)
methods, in favor of only having the method for backbones, which calls_get_bond_lengths(bond_vectors)
,_get_bond_angles(bond_vectors)
, and_get_dihedrals(bond_vectors)
.35a27e8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/108219
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: