-
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.
- Loading branch information
anton083
committed
Oct 30, 2023
1 parent
e200fc7
commit f16ca51
Showing
15 changed files
with
310 additions
and
142 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
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,20 +1,43 @@ | ||
include("utils.jl") | ||
include("residue_array.jl") | ||
""" | ||
Backbone{A, T} | ||
const Backbone = ResidueArray{3} | ||
const BackboneAndOxygen = ResidueArray{4} | ||
A wrapper for a 3xAxN matrix of coordinates of atoms in a backbone chain. | ||
""" | ||
struct Backbone{A, T <: Real} <: AbstractArray{T, 3} | ||
coords::AbstractArray{T, 3} | ||
|
||
nitrogen_coord_matrix(ra::ResidueArray) = _ith_column_coords(ra, 1) | ||
alphacarbon_coord_matrix(ra::ResidueArray) = _ith_column_coords(ra, 2) | ||
carbon_coord_matrix(ra::ResidueArray) = _ith_column_coords(ra, 3) | ||
oxygen_coord_matrix(ra::ResidueArray) = _ith_column_coords(ra, 4) | ||
function Backbone(coords::AbstractArray{T, 3}) where T <: Real | ||
A = size(coords, 2) | ||
@assert size(coords, 1) == 3 "coords must have 3 coordinates per atom" | ||
return new{A, T}(coords) | ||
end | ||
end | ||
|
||
nitrogens(ra::ResidueArray) = eachcol(_ith_column_coords(ra, 1)) | ||
alphacarbons(ra::ResidueArray) = eachcol(_ith_column_coords(ra, 2)) | ||
carbons(ra::ResidueArray) = eachcol(_ith_column_coords(ra, 3)) | ||
oxygens(ra::ResidueArray) = eachcol(_ith_column_coords(ra, 4)) | ||
@inline Base.size(bb::Backbone) = size(bb.coords) | ||
@inline Base.length(bb::Backbone) = size(bb, 3) | ||
@inline Base.getindex(bb::Backbone, i, j, k) = bb.coords[i,j,k] | ||
@inline Base.getindex(bb::Backbone, r::UnitRange{<:Integer}) = Backbone(view(bb.coords, :, :, r)) | ||
@inline Base.getindex(bb::Backbone, i::Integer) = view(bb.coords, :, :, i) | ||
|
||
unroll_coords(ra::ResidueArray{A}) where A = reshape(permutedims(ra.coords, (2, 1, 3)), :, A) | ||
""" | ||
atom_coord_matrix(bb, i) | ||
Returns the coordinates of specific columns of atoms in a backbone. | ||
""" | ||
function atom_coord_matrix(bb::Backbone{A}, i) where A | ||
return view(bb.coords, :, i, :) | ||
end | ||
|
||
""" | ||
unroll_atoms(bb, i) | ||
Returns the coordinates of specific columns of atoms in a backbone, | ||
but unrolled into a 3xN matrix where N is the number of residues times | ||
the number of columns selected (atoms selected per residue). | ||
""" | ||
function unroll_atoms(bb::Backbone{A}, i=Colon()) where A | ||
return reshape(atom_coord_matrix(bb, i), 3, :) | ||
end | ||
|
||
include("oxygen.jl") | ||
include("residue.jl") | ||
include("ncaco.jl") |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
nitrogen_coord_matrix(bb::Backbone) = atom_coord_matrix(bb, 1) | ||
alphacarbon_coord_matrix(bb::Backbone) = atom_coord_matrix(bb, 2) | ||
carbon_coord_matrix(bb::Backbone) = atom_coord_matrix(bb, 3) | ||
oxygen_coord_matrix(bb::Backbone) = atom_coord_matrix(bb, 4) |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function render!(segment::Segment{ASS.Loop}) | ||
startpoint = segment_startpoint(segment) | ||
stoppoint = segment_stoppoint(segment) | ||
anchors = alphacarbon_coord_matrix(segment.subbackbone[2:end]) | ||
coords = hcat(startpoint, anchors, stoppoint) | ||
surface_vertices, color_matrix = tube(coords, 0.3, spline_quality=10, tube_quality=10, color_start=segment.range.start/length(segment.backbone), color_end=segment.range.stop/length(segment.backbone)) | ||
surface!(eachslice(surface_vertices, dims=1)..., color=color_matrix) | ||
end | ||
|
||
function render!(segment::Segment{ASS.Helix}) | ||
startpoint = segment_startpoint(segment) | ||
stoppoint = segment_stoppoint(segment) | ||
anchors = alphacarbon_coord_matrix(segment.subbackbone[2:end]) # startpoint is first point instead. including first N *and* CA could mess with normals | ||
coords = hcat(startpoint, anchors, stoppoint) | ||
surface_vertices, color_matrix = tube(coords, 1, x_elongation=0.15, color_start=segment.range.start/length(segment.backbone), color_end=segment.range.stop/length(segment.backbone)) | ||
surface!(eachslice(surface_vertices, dims=1)..., color=color_matrix) | ||
end | ||
|
||
function render!(segment::Segment{ASS.Strand}) | ||
startpoint = segment_startpoint(segment) | ||
stoppoint = segment_stoppoint(segment) | ||
oxygen_coords = oxygen_coord_matrix(segment.subbackbone) | ||
oxygen_coords_side1 = oxygen_coords[:, 1:2:end-1] | ||
oxygen_coords_side2 = oxygen_coords[:, 2:2:end] | ||
coords1 = hcat(startpoint, oxygen_coords_side1, stoppoint) | ||
coords2 = hcat(startpoint, oxygen_coords_side2, stoppoint) | ||
surface_vertices, color_matrix = sheet(coords1, coords2, thickness=0.5, width_pad=0.5, color_start=segment.range.start/length(segment.backbone), color_end=segment.range.stop/length(segment.backbone)) | ||
surface!(eachslice(surface_vertices, dims=1)..., color=color_matrix) | ||
end | ||
|
||
function render!(backbone::Backbone{4}, ssclasses::Vector{ASS.SSClass}) | ||
segments = segmenter(ssclasses, backbone) | ||
render!.(segments) | ||
end | ||
|
||
function render!(backbones::Vector{<:Backbone{4}}) | ||
set_theme!(backgroundcolor = :black) | ||
|
||
ssclasses_vec = ASS.dssp([bb.coords for bb in backbones]) | ||
scene = lines(Float64[])#, axis=(;type=Axis3, aspect=:data)) | ||
for (backbone, ssclasses) in zip(backbones, ssclasses_vec) | ||
render!(backbone, ssclasses) | ||
end | ||
display(scene) | ||
end |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
struct Segment{C} | ||
range::UnitRange{Int} | ||
backbone::Backbone | ||
subbackbone::Backbone | ||
|
||
function Segment{C}(range::UnitRange{Int}, backbone::Backbone) where C | ||
return new{C}(range, backbone, backbone[range]) | ||
end | ||
end | ||
|
||
function segmenter(ss::AbstractVector{ASS.SSClass}, backbone::Backbone) | ||
start_idx = 1 | ||
end_idx = 1 | ||
segments = Segment[] | ||
for (i, class) in enumerate(ss) | ||
if class != ss[start_idx] | ||
push!(segments, Segment{ss[start_idx]}(start_idx:end_idx, backbone)) | ||
start_idx = i | ||
end | ||
end_idx = i | ||
end | ||
push!(segments, Segment{ss[start_idx]}(start_idx:end_idx, backbone)) | ||
return segments | ||
end | ||
|
||
function segment_startpoint(segment::Segment) | ||
return segment.subbackbone[1][:,1] # first nitrogen atom | ||
end | ||
|
||
function segment_stoppoint(segment::Segment) | ||
stop = segment.range.stop | ||
if stop == length(segment.backbone) | ||
return segment.backbone[stop][:,3] # last carbon atom | ||
else | ||
return segment.backbone[stop+1][:,1] # next nitrogen atom | ||
end | ||
end |
Oops, something went wrong.