Ensemble plugin.py

Revision as of 14:10, 15 November 2017 by Bernhard (talk | contribs) (Created page with "<pre> import gobject global model_no_animate, imol_animate, model_no_max_animate global animate_id if (have_coot_python): if coot_python.main_menubar(): menu = co...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
import gobject

global model_no_animate, imol_animate, model_no_max_animate
global animate_id

if (have_coot_python):
  if coot_python.main_menubar():
    
    menu = coot_menubar_menu("Ensembles")

    def animate_model(imol):
        global animate_id, model_no_animate

        model_no_max_animate = n_models(imol)
        model_no_animate = 1
        
        def animate_single_model_func(imol, model_no_max_animate):
          while True:
            while gtk.events_pending():
              gtk.main_iteration(False)
            global model_no_animate
            single_model_view_model_number(imol, model_no_animate)
            model_no_animate += 1
            if model_no_animate > model_no_max_animate:
                model_no_animate = 1
            return True

        animate_id = gobject.timeout_add(20, animate_single_model_func,
                                         imol, model_no_max_animate)
        
    add_simple_coot_menu_menuitem(
        menu,
        "Animate a model...",
        lambda func:
        molecule_chooser_gui("Ensemble model to animate:",
                             lambda imol:
                             animate_model(imol)))

    add_simple_coot_menu_menuitem(
        menu,
        "Stop model animation",
        lambda func: gobject.source_remove(animate_id))

    
    def toolbar_model(imol):
        button_text = "Ensemble selection " + str(imol) + " " + molecule_name(imol)
        coot_toolbar_combobox(button_text, map(str, range(n_models(imol)+1)),
                              [single_model_view_model_number, imol], tooltip=button_text)
#                              [printf], tooltip=button_text)
        
    def toolbar_model_play(imol):
        global animate_id
        callback_func_str = "single_model_view_next_model_number(" + str(imol) + ")"

        coot_toolbar_button("First model",
                            "single_model_view_model_number(" + str(imol) + ", 1)",
                            icon_name="gtk-goto-first",
                            tooltip="Jump to first model")

        coot_toolbar_button("Previous model",
                            "single_model_view_prev_model_number(" + str(imol) + ")",
                            icon_name="gtk-go-back",
                            tooltip="Jump to previous model")

        coot_toolbar_button("Next model",
                            "single_model_view_next_model_number(" + str(imol) + ")",
                            icon_name="gtk-go-forward",
                            tooltip="Jump to next model")

        coot_toolbar_button("Last model",
                            "single_model_view_model_number(" + str(imol) + ","  + str(n_models(imol)) + ")",
                            icon_name="gtk-goto-last",
                            tooltip="Jump to last model")

        coot_toolbar_button("All models",
                            "single_model_view_model_number(" + str(imol) + ", 0)",
                            icon_name="gtk-home",
                            tooltip="All model")

        # we cannot add the stop button until we have the animate_id
        # so unfortunatley no button for this yet
##        coot_toolbar_button("Animate models",
##                            "animate_model(" + str(imol) + ")",
##                            icon_name="gtk-media-play",
##                            tooltip="Animate the models")

##        coot_toolbar_button("Stop animation",
##                            "gobject.source_remove(" + str(animate_id) + ")",
##                            icon_name="gtk-media-stop",
##                            tooltip="Stop animation of the models")

        
    add_simple_coot_menu_menuitem(
        menu,
        "Add model play to toolbar...",
        lambda func:
        molecule_chooser_gui("Ensemble model for toolbar selection:",
                             lambda imol:
                             toolbar_model_play(imol)))


    add_simple_coot_menu_menuitem(
        menu,
        "Add model selection toolbar...",
        lambda func:
        molecule_chooser_gui("Ensemble model for toolbar selection:",
                             lambda imol:
                             toolbar_model(imol)))

Load with:

Calculate->Run Script

Or put the file in e.g. .coot-preferences directory to make it permanent.