Python Console Environment
From MantidProject
This page describes how to control Mantid from a command line without using MantidPlot. (Note that commands such as LoadRawDialog(...) are not available from this environment) Linux users: These instructions are Windows specific due to differences within the install locations (writable vs non-writable). Please contact mantid-help if you require instructions on how to proceed on a Linux environment.
Interactive Interpreter
The interactive Python interpreter lets you enter code and have it executed immediately. It can be useful to quickly verify that the commands that you enter behave as expected. To start a Python interpreter with Mantid commands embedded, click Start Menu -> All Programs -> Mantid -> MantidScript. This will open a new window and immediately display a list of algorithms that are available. Commands, such as LoadRaw(...), can be entered and upon pressing return they will be executed and the output sent to the screen.
Stand-alone script
While the interpreter is useful for testing commands most users will want to run saved scripts. To do this first open a command line by clicking Start Menu -> Run... and then typing 'cmd'. This will open a command line in your user directory. The script, MantidScript.bat, needed to run command line programs can be found in [MantidInstall]/bin, where [MANTIDINSTALL] denotes the location where Mantid is installed, so the first step is to change to this directory. Once there, assuming a script such as this:
from mantidsimple import *
LoadRaw('GEM38370.raw', 'GEM')
AlignDetectors('GEM', 'GEM', 'offsets_2006_cycle064.cal')
DiffractionFocussing('GEM', 'GEM', 'offsets_2006_cycle064.cal')
is saved to a file called focus.py, running the command
MantidScript.bat focus.py
will execute the focus.py script and print the output of the algorithms to the screen. Note that the line from mantidsimple import * must be included so that Python can find the Mantid definitions that the file uses.
To simplify finding files such as the raw or cal file, the script above uses just file names. In order for Mantid to find the file correctly an additional variable is required in the Mantid.user.properties file within the [MantidInstall]/bin directory. Adding a line such as
datasearch.directories = ../data1; ../data2
to Mantid.user.properties would cause Mantid to search for any filename given to an algorithm in the given locations.
