-
Notifications
You must be signed in to change notification settings - Fork 1
Description
It would be nice if the ribbon would re-render every time the backbone coordinates of the chains changed. Oxygen atoms and secondary structure would have to be re-assigned.
Here's my attempt at implementing it:
function Makie.plot!(ribbon::Ribbon{Tuple{Vector{Protein.Chain}}})
coords_observables = [Observable(chain.backbone.coords) for chain in ribbon[1][]]
function update_plot(coords_observables...)
chains = deepcopy(ribbon[1][])
Protein.assign_oxygens!.(chains)
_assign_secondary_structure!(chains)
isnothing(ribbon.colors[]) && (ribbon.colors = [LinRange(0, 1, length(chain)) for chain in chains])
empty!(ribbon.plots)
render!(ribbon, chains)
end
Makie.Observables.onany(update_plot, coords_observables...)
update_plot(coords_observables...)
return ribbon
endThis doesn't work because Observables doesn't detect mutation of coords, and the user can also not reach inside to update coords_observables and trigger update_plot. We can wrap coords in whatever, but the user will never have access to that thing, and Observables doesn't listen to mutations, I think -- only to e.g. obs = Observable(0); obs[] = 1.
Alternatively we could instead define Makie.plot!(ribbon::Ribbon{Tuple{Observable{Vector{Protein.Chain}}}}) such that the user could update a passed observable. The user wouldn't necessarily need to pass an observable if we define a convert_arguments for this.