Algorithm#

This is a Python binding to the C++ class Mantid::API::Algorithm.

bases: mantid.api.IAlgorithm

What are they?#

Algorithms are the verbs of Mantid. They are the actors. If you want to manipulate your data in any way it will be done through an algorithm. Algorithms operate primarily on data in Workspaces. They will normally take one or more Workspaces as an input, perform some processing on them and provide an output as another Workspace (although it is possible to have multiple outputs).

Categories, Name and Versions#

Each algorithm has a category, a name and a version. The name and version of an algorithm when taken together have to be unique.

Category#

A category is a group of algorithms that have some connection in their usage. This is primarily used to make the list of algorithms easier to work with in graphical user interfaces. Example categories include, DataHandling, Diffraction, Muon, Workflow and are currently subcategories of Algorithms category.

Name#

The name of an algorithm is what is used to refer to it. This can be different from the class name in C++, as for example if you had two versions of the same algorithm they would have the same name, but would have to have different class names (or at least be in different namespaces).

Version#

Mantid allows multiple versions of the same algorithm. These are differentiated by using a single integer as a version number, where a higher version number denotes a more recent version. This allows you to normally use the most recent version of an algorithm but also to access previous versions if you prefer.

Parameters#

Each algorithm will have one or more parameters, known within Mantid as properties, that will control how it performs its processing. These parameters specify both what the inputs and outputs of the algorithm will be as well any other options that alter the processing.

For examples of the parameters of an algorithm, look at the page for one of the example algorithms below.

Usage#

# where p1,p2 & p3 are values for algorithm "Alg"'s properties
mtd.execute("Alg","p1;p2;p3") # using parameter ordinal position
#or
mtd.execute("Alg","Property1=p1;Property2=p2;Property3=p3") #using parameter names
#or
alg = mtd.createAlgorithm("Alg") # explicitly setting each parameter, then executing
alg.setPropertyValue("Property1","p1")
alg.setPropertyValue("Property2","p2")
alg.setPropertyValue("Property3","p3")
alg.execute()

# Properties of Algorithms can be read (but not written to) through a Python dictionary. So you may do:
print(alg["Property1"])
# prints 'p1'
print(alg["Property2"])
# prints 'p2', etc

Example Algorithms#

  • Plus - An algorithm for adding data in two Workspaces together

  • Rebin - An algorithm for altering the binning of the data in a Workspace.

  • Load - An algorithm for loading the data from a file into a Workspace.

  • GroupDetectors - An algorithm for grouping two or more detectors into a larger ‘logical’ detector.

Writing your own algorithm#

A primer for this is here.

Reference#

class mantid.api.Algorithm#

Base class for all algorithms

alias((IAlgorithm)self) str :#

Return the aliases for the algorithm

aliasDeprecated((IAlgorithm)self) str :#

Deprecation date (in ISO8601 format) for the algorithm aliases. Returns empty string if no deprecation date

cancel((IAlgorithm)self) None :#

Request that the algorithm stop running

categories((IAlgorithm)self) numpy.ndarray :#

Returns the list of categories this algorithm belongs to

category((IAlgorithm)self) str :#

Returns the category containing the algorithm

createChildAlgorithm()#
object createChildAlgorithm(tuple args, dict kwds) :

Creates and intializes a named child algorithm. Output workspaces are given a dummy name.

declareOrReplaceProperty((object)self, (str)name, (object)defaultValue[, (object)validator=None[, (str)doc=''[, (int)direction=mantid.kernel._kernel.Direction.Input]]]) None :#

Declares or replaces a named property where the type is taken from the type of the defaultValue and mapped to an appropriate C++ type

declareProperty((object)self, (mantid.kernel._kernel.Property)prop[, (str)doc='']) None#
declareProperty( (object)self, (str)name, (object)defaultValue [, (object)validator=None [, (str)doc=’’ [, (int)direction=mantid.kernel._kernel.Direction.Input]]]) -> None :

Declares a named property where the type is taken from the type of the defaultValue and mapped to an appropriate C++ type

declareProperty( (object)self, (str)name, (object)defaultValue [, (str)doc=’’ [, (int)direction=mantid.kernel._kernel.Direction.Input]]) -> None :

Declares a named property where the type is taken from the type of the defaultValue and mapped to an appropriate C++ type

declareProperty( (object)self, (str)name, (object)defaultValue [, (int)direction=mantid.kernel._kernel.Direction.Input]) -> None :

Declares a named property where the type is taken from the type of the defaultValue and mapped to an appropriate C++ type

docString((IAlgorithm)self) str :#

Returns a doc string for the algorithm

enableHistoryRecordingForChild((Algorithm)self, (bool)on) None :#

Turns history recording on or off for an algorithm.

enableHistoryRecordingForProcessGroups((Algorithm)self, (bool)on) None :#

Turns parent history recording on or off for algorithms that handle group outputs directly.

execute((object)self) bool :#

Runs the algorithm and returns whether it has been successful

executeAsync((object)self) None :#

Starts the algorithm in a separate thread and returns immediately

existsProperty((IPropertyManager)self, (str)name) bool :#

Returns whether a property exists

static fromString((str)arg1) IAlgorithm :#

Initialize the algorithm from a string representation

get((IPropertyManager)self, (str)name, (object)value) Property :#

Returns the property of the given name. Use .value to give the value. If property with given name does not exist, returns given default value.

getAlgStartupLogging((IAlgorithm)self) bool :#

Returns true if logging of start and end messages

getAlgorithmID((IAlgorithm)self) object :#

Returns a unique identifier for this algorithm object

getAlwaysStoreInADS((IAlgorithm)self) bool :#

Returns true if child algorithms set tol have their workspaces stored in the ADS.

getLogger((Algorithm)self) mantid.kernel._kernel.Logger :#

Returns a reference to this algorithm’s logger

getOptionalMessage((IAlgorithm)self) str :#

Returns the optional user message attached to the algorithm

getProperties((IPropertyManager)self) std_vector_property :#

Returns the list of properties managed by this object

getProperty((IPropertyManager)self, (str)name) Property :#

Returns the property of the given name. Use .value to give the value

getPropertyValue((IPropertyManager)self, (str)name) str :#

Returns a string representation of the named property’s value

getWikiSummary((IAlgorithm)self) str :#

Returns the summary found on the wiki page

has_key((IPropertyManager)self, (str)name) bool :#

Returns whether a property exists

helpURL((IAlgorithm)self) str :#

Returns optional URL for algorithm documentation

initialize((IAlgorithm)self) None :#

Initializes the algorithm

inoutProperties((IAlgorithm)self) list :#

Returns a list of the inout properties on the algorithm

isChild((IAlgorithm)self) bool :#

Returns True if the algorithm has been marked to run as a child. If True then Output workspaces are NOT stored in the Analysis Data Service but must be retrieved from the property.

isExecuted((IAlgorithm)self) bool :#

Returns True if the algorithm has been executed successfully, False otherwise

isInitialized((IAlgorithm)self) bool :#

Returns True if the algorithm is initialized, False otherwise

isLogging((IAlgorithm)self) bool :#

Returns True if the algorithm’s logger is turned on, False otherwise

isPropertyEnabled((IPropertyManager)self, (str)name) bool :#

Returns whether a property should be enabled, according to its settings

isPropertyVisible((IPropertyManager)self, (str)name) bool :#

Returns whether a property should be visible, according to its settings

isRunning((IAlgorithm)self) bool :#

Returns True if the algorithm is considered to be running, False otherwise

keys((IPropertyManager)self) list#
log((Algorithm)self) mantid.kernel._kernel.Logger :#

Returns a reference to this algorithm’s logger

mandatoryProperties((IAlgorithm)self) list :#

Returns a list of input and in/out property names that is ordered such that the mandatory properties are first followed by the optional ones.

name((IAlgorithm)self) str :#

Returns the name of the algorithm

orderedProperties((IAlgorithm)self) list :#

Return a list of input, in/out and output properties such that the mandatory properties are first followed by the optional ones.

outputProperties((IAlgorithm)self) list :#

Returns a list of the output properties on the algorithm

propertyCount((IPropertyManager)self) int :#

Returns the number of properties being managed

seeAlso((IAlgorithm)self) numpy.ndarray :#

Returns the list of similar algorithms

setAlgStartupLogging((IAlgorithm)self, (bool)enabled) None :#

If true then allow logging of start and end messages

setAlwaysStoreInADS((IAlgorithm)self, (bool)do_store) None :#

If true then even child algorithms will have their workspaces stored in the ADS.

setChild((IAlgorithm)self, (bool)is_child) None :#

If true this algorithm is run as a child algorithm. There will be no logging and nothing is stored in the Analysis Data Service

setLogging((IAlgorithm)self, (bool)value) None :#

Toggle logging on/off.

setProperties((IPropertyManager)self, (dict)kwargs) None :#

Set a collection of properties from a dict

setProperty((IPropertyManager)self, (str)name, (object)value) None :#

Set the value of the named property

setPropertyGroup((IPropertyManager)self, (str)name, (str)group) None :#

Set the group for a given property

setPropertySettings((IPropertyManager)self, (str)name, (IPropertySettings)settingsManager) None :#

Assign the given IPropertySettings object to the named property

setPropertyValue((IPropertyManager)self, (str)name, (str)value) None :#

Set the value of the named property via a string

setRethrows((IAlgorithm)self, (bool)rethrow) None :#

To query whether an algorithm should rethrow exceptions when executing.

setWikiSummary((Algorithm)self, (str)summary) None :#

(Deprecated.) Set summary for the help.

summary((IAlgorithm)self) str :#

Returns a summary message describing the algorithm

validateInputs((IAlgorithm)self) dict :#

Cross-check all inputs and return any errors as a dictionary

values((IPropertyManager)self) std_vector_property :#

Returns the list of properties managed by this object

version((IAlgorithm)self) int :#

Returns the version number of the algorithm

workspaceMethodInputProperty((IAlgorithm)self) str :#

Returns the name of the input workspace property used by the calling object

workspaceMethodName((IAlgorithm)self) str :#

Returns a name that will be used when attached as a workspace method. Empty string indicates do not attach

workspaceMethodOn((IAlgorithm)self) numpy.ndarray :#

Returns a set of class names that will have the method attached. Empty list indicates all types