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
source activate my_environment python /path/to/script/newick_visualization.py
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:
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.