Python Commands in Maestro
Python is a full-featured scripting language that has been embedded in Maestro to provide scripting facilities to control the program. It has also been extended with access to Maestro functionality for dealing with chemical structures, projects, and Maestro files.
The two main Python commands used in Maestro are:
-
pythonrun: executes a Python module. The syntax is:pythonrun module.function -
pythonimport: rereads a Python file so that the next time you use thepythonruncommand, it uses the updated version of the module. The syntax is:pythonimport filename
You can run Python scripts directly from Maestro by installing them on the Scripts menu, then running them by choosing Scripts → script. See the Install Scripts Panel and Manage Scripts Panel topics for details of installation.
You can install site-wide scripts as follows:
- Copy the scripts to the
mmshare-vversion/python/commondirectory of your installation. - Add a
scriptsx.mnufile to this directory (or edit the one that is there) to define which scripts are added to the Scripts menu.
The scriptsx.mnu file contains two lines for each script: the menu item is on the first line, and the pythonrun command is on the second line. You can create a submenu for the menu item with the syntax submenu:item.
If you want to add site-wide scripts outside the installation directory (to keep them in a release-independent location, for example), you can do the following:
-
Copy the scripts to a directory that is accessible to all users.
-
Create a
scriptsx.mnufile in the same directory, and add the relevant lines to this file for each script. -
Set the environment variable
SCHRODINGER_SCRIPTSto the directory to which the scripts were copied. Make sure you use the full path.
If you are interested in developing Python scripts for your own use, you can find general information in the Python Module Overview. There is an extensive library of functions that provides access to many Maestro features, which is included in the installation. For details of the API to this library, see the Python API Reference.
If you want to run Python interactively within the context of Maestro, choose Window → Python Shell to open the IPython with Maestro integration panel. This is an IPython shell in which the Maestro modules have been imported by default with the command
from schrodinger.maestro import maestro
You can import many other modules from the Schrödinger Python API—see the Python API Reference. See https://ipython.readthedocs.io/ for documentation of IPython.