diff --git a/src/ProtPlot.jl b/src/ProtPlot.jl index bec8e7d..f421a9a 100644 --- a/src/ProtPlot.jl +++ b/src/ProtPlot.jl @@ -1,13 +1,10 @@ module ProtPlot -using Backboner +import Backboner export Backboner -using GLMakie -using Colors, ColorSchemes -using LinearAlgebra - -include("utils/utils.jl") include("ribbon/ribbon.jl") +export Ribbon + end diff --git a/src/ribbon/ribbon.jl b/src/ribbon/ribbon.jl index 6277162..2b3376d 100644 --- a/src/ribbon/ribbon.jl +++ b/src/ribbon/ribbon.jl @@ -1,3 +1,14 @@ +module Ribbon + +using Backboner +using GLMakie +using Colors +using ColorSchemes +using LinearAlgebra + +include("utils/utils.jl") include("segment.jl") include("shapes.jl") -include("render.jl") \ No newline at end of file +include("render.jl") + +end \ No newline at end of file diff --git a/src/ribbon/segment.jl b/src/ribbon/segment.jl index a4c3649..173c64f 100644 --- a/src/ribbon/segment.jl +++ b/src/ribbon/segment.jl @@ -85,6 +85,8 @@ function segments(chain::Chain) end +# utilities + function segment_startpoint(segment::Segment, A=1) # nitrogen return segment.backbone.coords[:,A,1] # first residue end @@ -96,4 +98,13 @@ function segment_endpoint(segment::Segment, A=1) # nitrogen else return segment.chain.backbone[:,A,segment_stop+1] # next residue end +end + +function remove_singleton_strands!(chain::Chain) + ssvector = chain.ssvector + for i in 2:length(ssvector)-1 + if ssvector[i-1] != Strand && ssvector[i] == Strand && ssvector[i+1] != Strand + ssvector[i] = Loop + end + end end \ No newline at end of file diff --git a/src/ribbon/shapes.jl b/src/ribbon/shapes.jl index f868ec3..90dc5b7 100644 --- a/src/ribbon/shapes.jl +++ b/src/ribbon/shapes.jl @@ -22,26 +22,26 @@ function tube_surface( surface_vertices = zeros(T, 3, N, length(tube_angles)) # Precompute tangents and initialize normals - tangents = [path_tangent(path[:, max(1, i-1)], path[:, i], path[:, min(N, i+1)]) for i in 1:N] + tangents = stack(path_tangent(path[:, max(1, i-1)], path[:, i], path[:, min(N, i+1)]) for i in 1:N) normals = zeros(T, 3, N) # Initial normal vector (arbitrary, but not aligned with the first tangent) - normals[:, 1] = abs(tangents[1][1]) < 0.9 ? [1, 0, 0] : [0, 1, 0] + normals[:, 1] = abs(tangents[1, 1]) < 0.9 ? [1, 0, 0] : [0, 1, 0] # Propagate the normal vector along the path for idx in 2:N prev_normal = normals[:, idx-1] - t = tangents[idx] + t = tangents[:, idx] projected_normal = prev_normal - dot(t, prev_normal) * t if norm(projected_normal) < 1e-5 - projected_normal = cross(tangents[idx - 1], t) + projected_normal = cross(tangents[:, idx - 1], t) end normals[:, idx] = normalize!(projected_normal) end # Generate surface vertices for idx in 1:N - t = tangents[idx] + t = tangents[:, idx] n = normals[:, idx] b = cross(n, t) @@ -108,6 +108,8 @@ end # the shape is normalized such that length of the entire arrow is 1 arrow_function(l=0.5, w=0.5, W=1.0) = t -> t > l ? W*(t-1)/(l-1) : w +# TODO: just use oxygen atoms for calculating paths + function arrow_surface( points1::AbstractMatrix{T}, points2::AbstractMatrix{T}; @@ -135,7 +137,7 @@ function arrow_surface( arrow_head_length = 3.0 arrow_body_length = length_of_path - arrow_head_length l = findfirst(>(arrow_body_length), cumulative_length_of_path) / N - arrow = arrow_function(l, width, width*1.8) + arrow = arrow_function(l, width, width*2.0) surface_vertices = zeros(T, 3, N, 5) for idx in 1:N diff --git a/src/utils/utils.jl b/src/ribbon/utils/colors.jl similarity index 63% rename from src/utils/utils.jl rename to src/ribbon/utils/colors.jl index 093d8b8..f52f28e 100644 --- a/src/utils/utils.jl +++ b/src/ribbon/utils/colors.jl @@ -1,14 +1,3 @@ -include("splines.jl") - -function remove_singleton_strands!(chain::Chain) - ssvector = chain.ssvector - for i in 2:length(ssvector)-1 - if ssvector[i-1] != Strand && ssvector[i] == Strand && ssvector[i+1] != Strand - ssvector[i] = Loop - end - end -end - # expand vector to have length N while keeping the same discrete color gradient function expand_colors(colors::Vector, N::Integer) L = length(colors) diff --git a/src/utils/splines.jl b/src/ribbon/utils/splines.jl similarity index 100% rename from src/utils/splines.jl rename to src/ribbon/utils/splines.jl diff --git a/src/ribbon/utils/utils.jl b/src/ribbon/utils/utils.jl new file mode 100644 index 0000000..5b7b366 --- /dev/null +++ b/src/ribbon/utils/utils.jl @@ -0,0 +1,2 @@ +include("splines.jl") +include("colors.jl") \ No newline at end of file