Hi Rafael,

For this sort of thing you'll want to acquaint yourself with the wonderful world of event-driven callbacks. When ISOLDE starts a simulation the main `SimHandler` object is accessible as `session.isolde.sim_handler`. It has a `TriggerSet` (the same class as used by, for example, `session.triggers`) which defines a `coord update` trigger - which, as the name suggests, fires every time ISOLDE updates the model coordinates in ChimeraX (which under default settings is every 50 timesteps). To get the effect you want, try something like this:

class SimActor:
    def __init__(self, sim_handler, threshold=50):
        self._counter = 0
        self._threshold = threshold
        self._handler = sim_handler.triggers.add_handler('coord update', self._sim_update_cb)
        self._sim_handler = sim_handler
    def _sim_update_cb(self, *_):
        if self._sim_handler.minimize:
            return
        self._counter += 1
        if self._counter%self._threshold == 0:
            self.perform_action()
            from chimerax.core.triggerset import DEREGISTER
            return DEREGISTER
    def perform_action(self):
        # Code you actually want to run goes here
        print('Threshold reached!')

sa = SimActor(session.isolde.sim_handler)

If you want this to happen automatically every time a simulation is started, add a callback to ISOLDE's "simulation started" trigger:

def add_actor(*_):
    sa = SimActor(session.isolde.sim_handler)
   
h = session.isolde.triggers.add_handler('simulation started', add_actor)

This will automatically add a `SimActor` for every new simulation until you either close ISOLDE or call `h.remove()`.

Hope this helps!

Tristan

On Wed, Apr 26, 2023 at 3:57 PM Rafael Rocha via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Dear chimera users!
During a molecular dynamics simulation, I would like to run a python script that triggers a specific command once the simulation has reached a certain number of steps or a specific amount of time. I was able to programmatically start, pause, continue and stop a simulation using a primary Isolde object. However, it appears that the script is not waiting until the maximum number of MD steps is reached before moving on to the next command. I've tried using the sleep() python command, but unfortunately, this causes chimeraX to get stuck and unresponsive until the script is finished sleeping. Do you have any suggestions for how I can achieve this without causing chimeraX to freeze up? 
Thank you for your help!

--
Rafael E. O. Rocha, Ph. D.
Department of Biological Sciences
Federal University of Minas Gerais. 
_______________________________________________
ChimeraX-users mailing list
ChimeraX-users@cgl.ucsf.edu
Manage subscription:
https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users