The extern Stage
The extern stage provides an extremely flexible way to include your own Python code in a multisim run. The code can be embedded in the .msj file as a string value assigned to the command keyword. For example:
extern {
command = "
import os;
def main( current_stage, job ):
os.system( ’ls’ )
"
}
In the embedded Python code, you can import and use modules from your Schrödinger Python installation. If you need extra modules, you can pass their file names to multisim by setting the auxiliary_file parameter, and multisim transfers them to the scratch directory of the master job at run time. For example:
extern {
auxiliary_file = [mod1.py mod2.py]
command = "
import os
import mod1
import mod2
def main( current_stage, job ):
// does something with mod1 and mod2
os.system( ’ls’ )
"
}
The code given above is run once for each subjob in the previous stage. If you want to run it only once, use command_once instead of command. For example:
extern {
auxiliary_file = [mod1.py mod2.py]
command_once = "
import os
import mod1
import mod2
def main( current_stage ):
// does something with mod1 and mod2
os.system( ’ls’ )
"
}
For scripts that are stage-specific, your code must provide a main function that takes two arguments for command or one for command_once. The first argument in both cases corresponds to information for the current stage, while the second argument for command corresponds to information from the previous stage.
For very simple scripts, your code for command or command_once does not need to provide a main function. The following example removes a temporary file if it exists:
extern {
command = "
import os
# Removes a temporary file.
if (os.path.isfile( ’my_temporary_file’ )) :
os.remove( ’my_temporary_file’ )
"
}
Without the main function, multisim cannot pass the current stage and the current job objects to the Python code, but that is presumed to be not needed for simple operations.
The extern stage is an advanced feature. Please contact support for additional information on its use. The keywords for this stage are listed in Table 1.
|
Keyword |
Description |
|
|
List of files containing extra modules to be transferred to the runtime directory. |
|
|
Command to execute once for each subjob of the previous stage. The command specifies Python code that can span multiple lines. |
|
|
Command to execute once for the previous stage. The command specifies Python code that can span multiple lines. |