\(\renewcommand\AA{\unicode{x212B}}\)

MantidPython and Notebook

MantidPython can be used to access all of the functionality of the Mantid Framework outside of the Workbench interface.

The Jupyter Notebook is a web-based interactive computational environment where you can combine code execution, text, mathematics, plots and rich media into a single document.

Launching on different platforms

Windows

Open a Command Prompt.

Launch MantidPython:

C:\MantidInstall\bin\mantidpython.bat --classic

Launch Jupyter Notebook:

C:\MantidInstall\bin\mantidpython.bat notebook

MacOS

Open Terminal.

Launch MantidPython:

/Applications/MantidWorkbench.app/Contents/MacOS/mantidpython --classic

Launch Jupyter Notebook:

/Applications/MantidWorkbench.app/Contents/MacOS/mantidpython notebook

Ubuntu

Open Terminal.

Launch MantidPython:

/opt/Mantid/bin/mantidpython --classic

Launch Jupyter Notebook:

/opt/Mantid/bin/mantidpython notebook --notebook-dir="~"

Accessing Algorithms

In MantidPython or an Jupyter Notebook, accessing the Mantid Framework should be as simple as:

from mantid.simpleapi import *

If this doesn’t work, the path to the Mantid Installation directory should be set:

import sys
sys.path.append('PATH')

Where the ‘PATH’ should be:

  • Windows: [INSTALL_PATH]\bin where INSTALL_PATH eg. 'C:\MantidInstall\bin\'
  • Linux: /opt/Mantid/bin:/opt/Mantid/lib for an official release and /opt/mantidnightly/bin:/opt/mantidnightly/lib for a nightly development build
  • MacOS: /Applications/MantidWorkbench.app/Contents/MacOS

Running a Script

Simply call the script after the MantidPython or Notebook launch command:

Run a python script on MacOS:

/Applications/MantidWorkbench.app/Contents/MacOS/mantidpython --classic script.py

Run a notebook on Windows:

C:\MantidInstall\bin\mantidpython.bat notebook "Downloads\Introduction to using Mantid with IPython Notebook.ipynb"

Download this Example Notebook

Script and Notebook Generation

After processing a workspace in Mantid, the history of how this data was manipulated can be converted to a script or a notebook, with the use of GeneratePythonScript v1 or GenerateIPythonNotebook v1 respectively.

Category: Concepts