schrodinger / pymol-open-source

Open-source foundation of the user-sponsored PyMOL molecular visualization system.
https://pymol.org/
Other
1.15k stars 275 forks source link

Automatically update selection based on frame #257

Closed cyril-schroeder-ox closed 1 year ago

cyril-schroeder-ox commented 2 years ago

Hi all,

I am trying to solve pretty much the same problem as issue #218 - also updating the selection to only display molecules which are in contact on a frame-by-frame basis. What would it take to directly access the Pymol event signals and run a function each time I move to a new frame by accessing these signals? So far I couldn't find anything of the sort and have to manually run my function each time.

Thanks a lot in advance for your help!

Best, Cyril

speleo3 commented 2 years ago

Wizards can act as callbacks on various events. Example:

from pymol import cmd
from pymol.wizard import Wizard

class StateCallbackWizard(Wizard):
    def get_event_mask(self):
        return Wizard.event_mask_state
    def do_state(self, state):
        self.cmd.select("atoms_with_negative_x", "x < 0", state=state, quiet=0)

cmd.set_wizard(StateCallbackWizard())
JarrettSJohnson commented 1 year ago

Closing since I believe Thomas has provided the best solution currently available.