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