Executing External Scripts
Now, wouldn’t it be nice to able execute scripts automatically after a simulation? This would safe you the time and effort to start e.g. a python session and execute your script after every simulation.
For this situation, Morpheus provides a useful Analysis
plugin called External
. This plugin, based on the tiny process library, let’s you execute shell scripts during or after simulation.
For instance, here we specify a shell script to execute the following bash
script to first activate a conda environment my_environment
and then execute the python script newick_visualization.py
:
source activate my_environment
python /path/to/script/newick_visualization.py
![The `External` allows you to execute `bash` and `python` scripts during or after a Morpheus simulation.](/media/course/drawing-cell-genealogies/genealogy-external-command_hu257c5b2d5ec961c326a67ab828a3bbd1_39771_a14c49e2847097d2a8097d34511b771b.png)
External
allows you to execute bash
and python
scripts during or after a Morpheus simulation.
To customize the environment, one can override environment variables such as PYTHONPATH
. Here, we use to point it to the correct Python installation in the Anaconda folder:
![Override the PYTHONPATH to find the correct python/conda installation.](/media/course/drawing-cell-genealogies/genealogy-external-environment_huf8cdecc5060a81b085d46b58df6931ad_38401_31a869fc119a2c936464b202065c8738.png)
Shell scripts can be executed as part of the same thread as the simulation, or using a separate background process, using the detach
option. In this case, one can set a timeout
to kill a detached process after a specific time (in seconds) to prevent a script to hang a simulation, i.e. during a parameter sweep.
Another protip is to use %
(percentage) in the Command to provide global symbols as arguments in the script. For instance the substring %time
will be replaced with the current time.