Skip to content

Ribbon Observables #27

Description

@AntonOresten

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
end

This 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions