Newer
Older
Gigg, Martyn Anthony
committed
//
Gigg, Martyn Anthony
committed
// Wrappers for classes in the API namespace
Gigg, Martyn Anthony
committed
//
Gigg, Martyn Anthony
committed
#include "MantidPythonAPI/api_exports.h"
#include "MantidPythonAPI/stl_proxies.h"
#include "MantidPythonAPI/WorkspaceProxies.h"
Gigg, Martyn Anthony
committed
#include <string>
Gigg, Martyn Anthony
committed
#include <ostream>
Gigg, Martyn Anthony
committed
// API
Gigg, Martyn Anthony
committed
#include "MantidAPI/AlgorithmProperty.h"
#include "MantidAPI/FileFinder.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/IEventWorkspace.h"
Janik Zikovsky
committed
#include "MantidAPI/IEventList.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/ISpectrum.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/Sample.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidAPI/WorkspaceValidators.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/WorkspaceHistory.h"
Gigg, Martyn Anthony
committed
#include "MantidGeometry/MDGeometry/IMDDimension.h"
Janik Zikovsky
committed
Gigg, Martyn Anthony
committed
#include "MantidPythonAPI/PyAlgorithmWrapper.h"
Gigg, Martyn Anthony
committed
//Poco
#include <Poco/ActiveResult.h>
Gigg, Martyn Anthony
committed
namespace Mantid
{
namespace PythonAPI
{
Janik Zikovsky
committed
using namespace API;
using namespace Geometry;
using namespace boost::python;
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
//@cond
Gigg, Martyn Anthony
committed
//---------------------------------------------------------------------------
// Class export functions
//---------------------------------------------------------------------------
Gigg, Martyn Anthony
committed
// Overloads for create*Algorithms function which has 1 optional argument
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(FM_createManagedAlgorithmOverloader, PythonAPI::FrameworkManagerProxy::createManagedAlgorithm, 1, 2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(FM_createUnmanagedAlgorithmOverloader, PythonAPI::FrameworkManagerProxy::createUnmanagedAlgorithm, 1, 2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(FM_getRegisteredAlgorithmOverloader, PythonAPI::FrameworkManagerProxy::getRegisteredAlgorithms, 0, 1)
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
void export_frameworkmanager()
{
/**
Gigg, Martyn Anthony
committed
* Python Framework class (note that this is not the API::FrameworkManager, there is another in
Gigg, Martyn Anthony
committed
* PythonAPI::FrameworkManager)
* This is the main class through which Python interacts with Mantid and with the exception of PyAlgorithm and V3D,
* is the only one directly instantiable in Python
Gigg, Martyn Anthony
committed
*/
Gigg, Martyn Anthony
committed
class_<FrameworkManagerProxy, FrameworkProxyCallback, boost::noncopyable>("FrameworkManager")
Gigg, Martyn Anthony
committed
.def("clear", &FrameworkManagerProxy::clear)
.def("clearAlgorithms", &FrameworkManagerProxy::clearAlgorithms)
.def("clearData", &FrameworkManagerProxy::clearData)
.def("clearInstruments", &FrameworkManagerProxy::clearInstruments)
Gigg, Martyn Anthony
committed
.def("isAlgorithmName", &FrameworkManagerProxy::isAlgorithmName)
Gigg, Martyn Anthony
committed
.def("createManagedAlgorithm", &FrameworkManagerProxy::createManagedAlgorithm,
FM_createManagedAlgorithmOverloader()[return_internal_reference<>()] )
.def("createUnmanagedAlgorithm", &FrameworkManagerProxy::createUnmanagedAlgorithm,
FM_createUnmanagedAlgorithmOverloader()[return_value_policy< return_by_value >()])
Peterson, Peter
committed
.def("_getPropertyOrder", &FrameworkManagerProxy::getPropertyOrder, return_internal_reference<>())
.def("createAlgorithmDocs", &FrameworkManagerProxy::createAlgorithmDocs)
Gigg, Martyn Anthony
committed
.def("registerPyAlgorithm", &FrameworkManagerProxy::registerPyAlgorithm)
.def("_getRegisteredAlgorithms", &FrameworkManagerProxy::getRegisteredAlgorithms,
FM_getRegisteredAlgorithmOverloader())
Gigg, Martyn Anthony
committed
.def("_observeAlgFactoryUpdates", &FrameworkManagerProxy::observeAlgFactoryUpdates)
Gigg, Martyn Anthony
committed
.def("deleteWorkspace", &FrameworkManagerProxy::deleteWorkspace)
.def("getWorkspaceNames", &FrameworkManagerProxy::getWorkspaceNames)
.def("getWorkspaceGroupNames", &FrameworkManagerProxy::getWorkspaceGroupNames)
.def("getWorkspaceGroupEntries", &FrameworkManagerProxy::getWorkspaceGroupEntries)
.def("sendLogMessage", &FrameworkManagerProxy::sendLogMessage)
.def("workspaceExists", &FrameworkManagerProxy::workspaceExists)
Gigg, Martyn Anthony
committed
.def("getConfigProperty", &FrameworkManagerProxy::getConfigProperty)
.def("releaseFreeMemory", &FrameworkManagerProxy::releaseFreeMemory)
.def("_getRawIEventWorkspacePointer", &FrameworkManagerProxy::retrieveIEventWorkspace)
Janik Zikovsky
committed
.def("_getRawIMDWorkspacePointer", &FrameworkManagerProxy::retrieveIMDWorkspace)
.def("_getRawIMDEventWorkspacePointer", &FrameworkManagerProxy::retrieveIMDEventWorkspace)
Gigg, Martyn Anthony
committed
.def("_getRawMatrixWorkspacePointer", &FrameworkManagerProxy::retrieveMatrixWorkspace)
.def("_getRawTableWorkspacePointer", &FrameworkManagerProxy::retrieveTableWorkspace)
.def("_getRawWorkspaceGroupPointer", &FrameworkManagerProxy::retrieveWorkspaceGroup)
Gigg, Martyn Anthony
committed
.def("_workspaceRemoved", &FrameworkProxyCallback::default_workspaceRemoved)
.def("_workspaceReplaced", &FrameworkProxyCallback::default_workspaceReplaced)
.def("_workspaceAdded", &FrameworkProxyCallback::default_workspaceAdded)
.def("_workspaceStoreCleared", &FrameworkProxyCallback::default_workspaceStoreCleared)
.def("_algorithmFactoryUpdated", &FrameworkProxyCallback::default_algorithmFactoryUpdated)
Gigg, Martyn Anthony
committed
;
Gigg, Martyn Anthony
committed
}
Doucet, Mathieu
committed
/**
* Function used to define the IAlgorithm.setWorkspaceProperty() method in python.
* Since getProperty/setProperty only deal with strings, we need a new method if we
* want to set workspace properties by passing a pointer to an actual workspace.
* This is necessary to be able to run sub-algorithm within a PythonAlgorithm.
* TODO: This can be removed if we properly expose the getProperty/setProperty
* methods to deal with the type of the properties as opposed to strings.
*/
void _setMatrixWorkspaceProperty(API::IAlgorithm& self, const std::string & prop_name, API::MatrixWorkspace_sptr workspace)
Doucet, Mathieu
committed
{
Gigg, Martyn Anthony
committed
self.setProperty(prop_name,workspace);
Doucet, Mathieu
committed
}
/**
* Function used to define the IAlgorithm.getWorkspaceProperty() method in python.
*/
API::MatrixWorkspace_sptr _getMatrixWorkspaceProperty(API::IAlgorithm& self, const std::string & prop_name)
{
Gigg, Martyn Anthony
committed
return self.getProperty(prop_name);
Doucet, Mathieu
committed
}
// Overloads for createSubAlgorithm function which has 1 optional argument
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(PyAlgorithmBase_createSubAlgorithmOverloader, PythonAPI::PyAlgorithmBase::_createSubAlgorithm, 1, 2)
Gigg, Martyn Anthony
committed
void export_ialgorithm()
{
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
class_<Poco::ActiveResult<bool> >("ActiveResult_bool", no_init)
.def("available", &Poco::ActiveResult<bool>::available)
.def("wait", (void (Poco::ActiveResult<bool>::*)())&Poco::ActiveResult<bool>::wait)
.def("data", (bool& (Poco::ActiveResult<bool>::*)() const)&Poco::ActiveResult<bool>::data,return_value_policy< copy_non_const_reference >())
;
Gigg, Martyn Anthony
committed
register_ptr_to_python<API::IAlgorithm*>();
register_ptr_to_python<boost::shared_ptr<API::IAlgorithm> >();
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
class_< API::IAlgorithm, boost::noncopyable>("IAlgorithm", no_init)
.def("name", &API::IAlgorithm::name)
Gigg, Martyn Anthony
committed
.def("version", &API::IAlgorithm::version)
Gigg, Martyn Anthony
committed
.def("category", &API::IAlgorithm::category)
.def("alias", &API::IAlgorithm::alias)
Gigg, Martyn Anthony
committed
.def("getOptionalMessage", &API::IAlgorithm::getOptionalMessage)
Gigg, Martyn Anthony
committed
.def("initialize", &API::IAlgorithm::initialize)
.def("execute", &API::IAlgorithm::execute)
.def("executeAsync", &API::IAlgorithm::executeAsync)
.def("isRunningAsync", &API::IAlgorithm::isRunningAsync)
.def("isInitialized", &API::IAlgorithm::isInitialized)
.def("isExecuted", &API::IAlgorithm::isExecuted)
.def("setRethrows", &API::IAlgorithm::setRethrows)
Gigg, Martyn Anthony
committed
.def("existsProperty", &API::IAlgorithm::existsProperty)
Gigg, Martyn Anthony
committed
.def("setPropertyValue", &API::IAlgorithm::setPropertyValue)
.def("getPropertyValue", &API::IAlgorithm::getPropertyValue)
.def("getProperties", &API::IAlgorithm::getProperties, return_value_policy< copy_const_reference >())
Gigg, Martyn Anthony
committed
.def("getProperty", &API::IAlgorithm::getPointerToProperty, return_value_policy<return_by_value>())
Doucet, Mathieu
committed
.def("_setWorkspaceProperty", &_setMatrixWorkspaceProperty)
.def("_getWorkspaceProperty", &_getMatrixWorkspaceProperty)
Gigg, Martyn Anthony
committed
// Special methods
.def("__str__", &API::IAlgorithm::toString)
Gigg, Martyn Anthony
committed
;
Gigg, Martyn Anthony
committed
class_< API::Algorithm, bases<API::IAlgorithm>, boost::noncopyable>("IAlgorithm", no_init)
Gigg, Martyn Anthony
committed
;
Gigg, Martyn Anthony
committed
class_< API::CloneableAlgorithm, bases<API::Algorithm>, boost::noncopyable>("CloneableAlgorithm", no_init)
Gigg, Martyn Anthony
committed
;
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/// Algorithm properties
class_<Mantid::Kernel::PropertyWithValue<IAlgorithm_sptr>,
bases<Mantid::Kernel::Property>, boost::noncopyable>("PropertyWithValue_AlgorithmProperty", no_init)
.add_property("value", make_function(&Mantid::Kernel::PropertyWithValue<IAlgorithm_sptr>::operator(), return_value_policy<copy_const_reference>()))
Gigg, Martyn Anthony
committed
;
class_<API::AlgorithmProperty, bases<Kernel::PropertyWithValue<IAlgorithm_sptr> >, boost::noncopyable>("AlgorithmProperty", no_init)
Gigg, Martyn Anthony
committed
;
Gigg, Martyn Anthony
committed
//PyAlgorithmBase
//Save some typing for all of the templated declareProperty and getProperty methods
Gigg, Martyn Anthony
committed
#define EXPORT_DECLAREPROPERTY(type, suffix)\
Gigg, Martyn Anthony
committed
.def("declareProperty_"#suffix,(void(PyAlgorithmBase::*)(const std::string &, type, const std::string &,const unsigned int))&PyAlgorithmBase::_declareProperty<type>) \
.def("declareProperty_"#suffix,(void(PyAlgorithmBase::*)(const std::string &, type, Kernel::IValidator<type> &,const std::string &,const unsigned int))&PyAlgorithmBase::_declareProperty<type>) \
Gigg, Martyn Anthony
committed
.def("declareListProperty_"#suffix,(void(PyAlgorithmBase::*)(const std::string &, boost::python::list, const std::string &,const unsigned int))&PyAlgorithmBase::_declareListProperty<type>)\
.def("declareListProperty_"#suffix,(void(PyAlgorithmBase::*)(const std::string &, boost::python::list, Kernel::IValidator<type> &,const std::string &,const unsigned int))&PyAlgorithmBase::_declareListProperty<type>) \
.def("declareListProperty_"#suffix,(void(PyAlgorithmBase::*)(const std::string &, boost::python::list, Kernel::IValidator<std::vector<type> > &,const std::string &,const unsigned int))&PyAlgorithmBase::_declareListProperty<type>)
Gigg, Martyn Anthony
committed
#define EXPORT_GETPROPERTY(type, suffix)\
.def("getProperty_"#suffix,(type(PyAlgorithmBase::*)(const std::string &))&PyAlgorithmBase::_getProperty<type>)
#define EXPORT_GETLISTPROPERTY(type, suffix)\
.def("getListProperty_"#suffix,(std::vector<type>(PyAlgorithmBase::*)(const std::string &))&PyAlgorithmBase::_getListProperty<type>)
Gigg, Martyn Anthony
committed
class_< PyAlgorithmBase, boost::shared_ptr<PyAlgorithmCallback>, bases<API::CloneableAlgorithm>,
Gigg, Martyn Anthony
committed
boost::noncopyable >("PyAlgorithmBase")
.enable_pickling()
.def("_setMatrixWorkspaceProperty", &PyAlgorithmBase::_setMatrixWorkspaceProperty)
.def("_setTableWorkspaceProperty", &PyAlgorithmBase::_setTableWorkspaceProperty)
.def("_declareFileProperty", &PyAlgorithmBase::_declareFileProperty)
.def("_declareMatrixWorkspace", (void(PyAlgorithmBase::*)(const std::string &, const std::string &,const std::string &, const unsigned int))&PyAlgorithmBase::_declareMatrixWorkspace)
.def("_declareMatrixWorkspace", (void(PyAlgorithmBase::*)(const std::string &, const std::string &,Kernel::IValidator<boost::shared_ptr<API::MatrixWorkspace> >&,const std::string &, const unsigned int))&PyAlgorithmBase::_declareMatrixWorkspace)
Gigg, Martyn Anthony
committed
.def("_declareTableWorkspace", &PyAlgorithmBase::_declareTableWorkspace)
Doucet, Mathieu
committed
.def("_declareAlgorithmProperty", &PyAlgorithmBase::_declareAlgorithmProperty)
.def("_setAlgorithmProperty", &PyAlgorithmBase::_setAlgorithmProperty)
.def("_getAlgorithmProperty", &PyAlgorithmBase::_getAlgorithmProperty)
.def("log", &PyAlgorithmBase::getLogger, return_internal_reference<>())
.def("_createSubAlgorithm", &PyAlgorithmBase::_createSubAlgorithm, PyAlgorithmBase_createSubAlgorithmOverloader()[return_value_policy< return_by_value >()] )
Gigg, Martyn Anthony
committed
EXPORT_DECLAREPROPERTY(int, int)
EXPORT_DECLAREPROPERTY(double, dbl)
EXPORT_DECLAREPROPERTY(std::string, str)
Gigg, Martyn Anthony
committed
EXPORT_DECLAREPROPERTY(bool, bool)
EXPORT_GETPROPERTY(int, int)
EXPORT_GETLISTPROPERTY(int, int)
EXPORT_GETPROPERTY(double, dbl)
EXPORT_GETLISTPROPERTY(double, dbl)
EXPORT_GETPROPERTY(bool, bool)
;
//Leave the place tidy
#undef EXPORT_DECLAREPROPERTY
#undef EXPORT_GETPROPERTY
Gigg, Martyn Anthony
committed
#undef EXPORT_GETLISTPROPERTY
Gigg, Martyn Anthony
committed
}
// Overloads for createSubAlgorithm function which has 1 optional argument
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Workspace_isDirtyOverloader, API::Workspace::isDirty, 0, 1)
Gigg, Martyn Anthony
committed
void export_workspace()
{
Gigg, Martyn Anthony
committed
/// Shared pointer registration
register_ptr_to_python<boost::shared_ptr<Workspace> >();
Gigg, Martyn Anthony
committed
class_<API::Workspace, boost::noncopyable>("Workspace", no_init)
.def("getTitle", &API::Workspace::getTitle,
Anders Markvardsen
committed
return_value_policy< return_by_value >())
Gigg, Martyn Anthony
committed
.def("getComment", &API::MatrixWorkspace::getComment,
Russell Taylor
committed
return_value_policy< copy_const_reference >() )
Gigg, Martyn Anthony
committed
.def("getMemorySize", &API::Workspace::getMemorySize)
.def("isDirty", &API::Workspace::isDirty, Workspace_isDirtyOverloader()[return_value_policy< return_by_value >()])
Gigg, Martyn Anthony
committed
.def("getName", &API::Workspace::getName, return_value_policy< copy_const_reference >())
.def("__str__", &API::Workspace::getName, return_value_policy< copy_const_reference >())
Gigg, Martyn Anthony
committed
.def("getHistory", &API::Workspace::getHistory, return_internal_reference<>())
Gigg, Martyn Anthony
committed
;
}
Gigg, Martyn Anthony
committed
// Overloads for binIndexOf function which has 1 optional argument
Gigg, Martyn Anthony
committed
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MatrixWorkspace_binIndexOfOverloads, API::MatrixWorkspace::binIndexOf, 1, 2)
Gigg, Martyn Anthony
committed
void export_matrixworkspace()
{
/// Shared pointer registration
register_ptr_to_python<boost::shared_ptr<MatrixWorkspace> >();
// A vector of MatrixWorkspace pointers
Gigg, Martyn Anthony
committed
vector_proxy<MatrixWorkspace*>::wrap("stl_vector_matrixworkspace");
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/// Typedef for data access
typedef MantidVec&(API::MatrixWorkspace::*data_modifier)(const std::size_t);
Gigg, Martyn Anthony
committed
//MatrixWorkspace class
Gigg, Martyn Anthony
committed
class_< API::MatrixWorkspace, bases<API::Workspace>, MatrixWorkspaceWrapper,
Gigg, Martyn Anthony
committed
boost::noncopyable >("MatrixWorkspace", no_init)
Gigg, Martyn Anthony
committed
.def("getNumberHistograms", &API::MatrixWorkspace::getNumberHistograms)
.def("getNumberBins", &API::MatrixWorkspace::blocksize)
.def("binIndexOf", &API::MatrixWorkspace::binIndexOf, MatrixWorkspace_binIndexOfOverloads() )
Gigg, Martyn Anthony
committed
.def("readX", &PythonAPI::MatrixWorkspaceWrapper::readX)
.def("readY", &PythonAPI::MatrixWorkspaceWrapper::readY)
.def("readE", &PythonAPI::MatrixWorkspaceWrapper::readE)
Doucet, Mathieu
committed
.def("readDx", &PythonAPI::MatrixWorkspaceWrapper::readDx)
Gigg, Martyn Anthony
committed
.def("dataX", (data_modifier)&API::MatrixWorkspace::dataX, return_internal_reference<>() )
.def("dataY", (data_modifier)&API::MatrixWorkspace::dataY, return_internal_reference<>() )
Gigg, Martyn Anthony
committed
.def("dataE", (data_modifier)&API::MatrixWorkspace::dataE, return_internal_reference<>() )
Doucet, Mathieu
committed
.def("dataDx", (data_modifier)&API::MatrixWorkspace::dataDx, return_internal_reference<>() )
Gigg, Martyn Anthony
committed
.def("isDistribution", (const bool& (API::MatrixWorkspace::*)() const)&API::MatrixWorkspace::isDistribution,
Russell Taylor
committed
return_value_policy< copy_const_reference >() )
Gigg, Martyn Anthony
committed
.def("setYUnitLabel", &API::MatrixWorkspace::setYUnitLabel)
.def("setYUnit", &API::MatrixWorkspace::setYUnit)
.def("setDistribution", (bool& (API::MatrixWorkspace::*)(const bool))&API::MatrixWorkspace::isDistribution,
return_value_policy<return_by_value>() )
Gigg, Martyn Anthony
committed
.def("getInstrument", &API::MatrixWorkspace::getInstrument)
Gigg, Martyn Anthony
committed
.def("getSpectrum", (ISpectrum * (MatrixWorkspace::*)(const size_t))&API::MatrixWorkspace::getSpectrum, return_internal_reference<>() )
Russell Taylor
committed
.def("getDetector", (Geometry::IDetector_sptr (API::MatrixWorkspace::*) (const size_t) const)&API::MatrixWorkspace::getDetector)
Gigg, Martyn Anthony
committed
.def("getRun", &API::MatrixWorkspace::run, return_internal_reference<>() )
.def("getSampleInfo", &API::MatrixWorkspace::sample, return_internal_reference<>() )
Michael Whitty
committed
.def("getNumberAxes", &API::MatrixWorkspace::axes)
.def("getAxis", &API::MatrixWorkspace::getAxis, return_internal_reference<>())
.def("replaceAxis", &API::MatrixWorkspace::replaceAxis)
Gigg, Martyn Anthony
committed
// Deprecated, here for backwards compatability
Gigg, Martyn Anthony
committed
.def("blocksize", &API::MatrixWorkspace::blocksize)
.def("getSampleDetails", &API::MatrixWorkspace::run, return_internal_reference<>() )
Gigg, Martyn Anthony
committed
;
Gigg, Martyn Anthony
committed
//Operator overloads dispatch through the above structure. The typedefs save some typing
typedef MatrixWorkspace_sptr(*binary_fn1)(const API::MatrixWorkspace_sptr, const API::MatrixWorkspace_sptr,const std::string &,const std::string &,bool, bool);
typedef MatrixWorkspace_sptr(*binary_fn2)(const API::MatrixWorkspace_sptr, double,const std::string&,const std::string &,bool,bool);
typedef bool(*binary_fn3)(const API::MatrixWorkspace_sptr, const API::MatrixWorkspace_sptr,double);
Gigg, Martyn Anthony
committed
// Binary operations helpers
def("_binary_op", (binary_fn1)&PythonAPI::performBinaryOp);
def("_binary_op", (binary_fn2)&PythonAPI::performBinaryOp);
def("_equals_op", (binary_fn3)&API::equals);
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
}
Janik Zikovsky
committed
void export_IMDWorkspace()
Janik Zikovsky
committed
{
register_ptr_to_python<API::IMDWorkspace_sptr>();
// EventWorkspace class
class_< IMDWorkspace, bases<API::Workspace>, boost::noncopyable >("IMDWorkspace", no_init)
.def("getNPoints", &IMDWorkspace::getNPoints)
Janik Zikovsky
committed
.def("getNumDims", &IMDWorkspace::getNumDims)
.def("getDimensionNum", &IMDWorkspace::getDimensionNum )
Janik Zikovsky
committed
.def("getSignalDataVector", &IMDWorkspace::getSignalDataVector)
Janik Zikovsky
committed
.def("getErrorDataVector", &IMDWorkspace::getErrorDataVector)
;
}
void export_IMDDimension()
{
register_ptr_to_python<Geometry::IMDDimension_sptr>();
class_< IMDDimension, boost::noncopyable >("IMDDimension", no_init)
.def("getName", &IMDDimension::getName)
.def("getMaximum", &IMDDimension::getMaximum)
.def("getMinimum", &IMDDimension::getMinimum)
.def("getNBins", &IMDDimension::getNBins)
.def("getX", &IMDDimension::getX)
.def("getDimensionId", &IMDDimension::getDimensionId)
Janik Zikovsky
committed
;
}
Janik Zikovsky
committed
void export_eventworkspace()
{
Janik Zikovsky
committed
register_ptr_to_python<IEventWorkspace_sptr>();
Janik Zikovsky
committed
// EventWorkspace class
Janik Zikovsky
committed
class_< IEventWorkspace, bases<API::MatrixWorkspace>, boost::noncopyable >("EventWorkspace", no_init)
.def("getNumberEvents", &IEventWorkspace::getNumberEvents)
Peterson, Peter
committed
.def("getTofMin", &IEventWorkspace::getTofMin)
.def("getTofMax", &IEventWorkspace::getTofMax)
Janik Zikovsky
committed
.def("getEventList", (IEventList*(IEventWorkspace::*)(const int) ) &IEventWorkspace::getEventListPtr, return_internal_reference<>())
.def("clearMRU", &IEventWorkspace::clearMRU)
;
Janik Zikovsky
committed
}
Gigg, Martyn Anthony
committed
void export_ISpectrum()
{
register_ptr_to_python<ISpectrum*>();
class_<ISpectrum, boost::noncopyable>("ISpectrum", no_init)
.def("addDetectorID", &ISpectrum::addDetectorID)
.def("setDetectorID", &ISpectrum::setDetectorID)
.def("hasDetectorID", &ISpectrum::hasDetectorID)
.def("clearDetectorIDs", &ISpectrum::clearDetectorIDs)
.def("getSpectrumNo", &ISpectrum::getSpectrumNo)
.def("setSpectrumNo", &ISpectrum::setSpectrumNo)
;
}
Janik Zikovsky
committed
void export_EventList()
{
register_ptr_to_python<IEventList *>();
class_< IEventList, boost::noncopyable >("IEventList", no_init)
.def("getEventType", &IEventList::getEventType)
.def("switchTo", &IEventList::switchTo)
.def("clear", &IEventList::clear)
.def("isSortedByTof", &IEventList::isSortedByTof)
.def("getNumberEvents", &IEventList::getNumberEvents)
.def("getMemorySize", &IEventList::getMemorySize)
.def("integrate", &IEventList::integrate)
.def("convertTof", &IEventList::convertTof)
.def("scaleTof", &IEventList::scaleTof)
.def("addTof", &IEventList::addTof)
.def("addPulsetime", &IEventList::addPulsetime)
.def("maskTof", &IEventList::maskTof)
.def("getTofs", &IEventList::getTofs)
.def("getTofMin", &IEventList::getTofMin)
.def("getTofMax", &IEventList::getTofMax)
.def("setTofs", &IEventList::setTofs)
.def("multiply", (void(IEventList::*)(const double,const double)) &IEventList::multiply)
.def("divide", (void(IEventList::*)(const double,const double)) &IEventList::multiply)
;
}
Janik Zikovsky
committed
Janik Zikovsky
committed
void export_mdeventworkspace()
{
register_ptr_to_python<API::IMDEventWorkspace_sptr>();
Janik Zikovsky
committed
// MDEventWorkspace class
Janik Zikovsky
committed
class_< IMDEventWorkspace, bases<API::Workspace>, boost::noncopyable >("IMDEventWorkspace", no_init)
.def("getNPoints", &IMDEventWorkspace::getNPoints)
.def("getNumDims", &IMDEventWorkspace::getNumDims)
;
}
Gigg, Martyn Anthony
committed
void export_tableworkspace()
{
// Declare the pointer
Gigg, Martyn Anthony
committed
register_ptr_to_python<API::ITableWorkspace_sptr>();
Gigg, Martyn Anthony
committed
// Table workspace
// Some function pointers since MSVC can't figure out the function to call when
// placing this directly in the .def functions below
typedef int&(ITableWorkspace::*get_integer_ptr)(const std::string &, int);
typedef double&(ITableWorkspace::*get_double_ptr)(const std::string &, int);
typedef std::string&(ITableWorkspace::*get_string_ptr)(const std::string &, int);
Gigg, Martyn Anthony
committed
// TableWorkspace class
Gigg, Martyn Anthony
committed
class_< ITableWorkspace, bases<API::Workspace>, boost::noncopyable >("ITableWorkspace", no_init)
Gigg, Martyn Anthony
committed
.def("getColumnCount", &ITableWorkspace::columnCount)
.def("getRowCount", &ITableWorkspace::rowCount)
.def("getColumnNames",&ITableWorkspace::getColumnNames)
.def("getInt", (get_integer_ptr)&ITableWorkspace::getRef<int>, return_value_policy<copy_non_const_reference>())
.def("getDouble", (get_double_ptr)&ITableWorkspace::getRef<double>, return_value_policy<copy_non_const_reference>())
.def("getString", (get_string_ptr)&ITableWorkspace::getRef<std::string>, return_value_policy<copy_non_const_reference>())
Gigg, Martyn Anthony
committed
;
}
// WorkspaceGroup
void export_workspacegroup()
{
// Pointer
Gigg, Martyn Anthony
committed
register_ptr_to_python<API::WorkspaceGroup_sptr>();
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
class_< API::WorkspaceGroup, bases<API::Workspace>,
Gigg, Martyn Anthony
committed
boost::noncopyable >("WorkspaceGroup", no_init)
.def("__len__", &API::WorkspaceGroup::getNumberOfEntries)
Gigg, Martyn Anthony
committed
.def("size", &API::WorkspaceGroup::getNumberOfEntries)
.def("getNames", &API::WorkspaceGroup::getNames)
.def("add", &API::WorkspaceGroup::add)
.def("remove", &API::WorkspaceGroup::remove)
Gigg, Martyn Anthony
committed
;
}
Michael Whitty
committed
void export_axis()
{
// Pointer
register_ptr_to_python<API::Axis*>();
// Class
class_< API::Axis, boost::noncopyable >("MantidAxis", no_init)
.def("title", (std::string & (Mantid::API::Axis::*)() ) &API::Axis::title, return_internal_reference<>())
.def("isSpectra", & API::Axis::isSpectra)
.def("isNumeric", & API::Axis::isNumeric)
.def("isText", & API::Axis::isText)
.def("label", & API::Axis::label)
.def("getUnit", (const Mantid::Kernel::Unit_sptr & (Mantid::API::Axis::*)() const) &API::Axis::unit, return_value_policy<copy_const_reference>() )
.def("setUnit", & API::Axis::setUnit)
;
// Numeric Axis subclass
class_< API::NumericAxis, bases<API::Axis>, boost::noncopyable >("NumericAxis", no_init)
.def("setValue", & API::NumericAxis::setValue)
;
// Spectra Axis subclass
class_< API::SpectraAxis, bases<API::Axis>, boost::noncopyable >("SpectraAxis", no_init)
.def("spectraNumber", (const specid_t & (Mantid::API::SpectraAxis::*)(const size_t &) const) & API::SpectraAxis::spectraNo, return_value_policy<copy_const_reference>() )
Michael Whitty
committed
.def("setValue", & API::SpectraAxis::setValue)
.def("populateOneToOne", & API::SpectraAxis::populateOneToOne)
Michael Whitty
committed
;
// Text Axis subclass
class_< API::TextAxis, bases<API::Axis>, boost::noncopyable >("TextAxis", no_init)
.def("setValue", & API::TextAxis::setLabel)
.def("getValue", & API::TextAxis::label)
;
// Axis creation helpers
def("createNumericAxis", & Mantid::PythonAPI::createNumericAxis, return_internal_reference<>());
def("createSpectraAxis", & Mantid::PythonAPI::createSpectraAxis, return_internal_reference<>());
def("createTextAxis", & Mantid::PythonAPI::createTextAxis, return_internal_reference<>());
}
Gigg, Martyn Anthony
committed
void export_sample()
{
//Pointer
Gigg, Martyn Anthony
committed
register_ptr_to_python<API::Sample*>();
Gigg, Martyn Anthony
committed
//Sample class
Gigg, Martyn Anthony
committed
class_< API::Sample, boost::noncopyable >("Sample", no_init)
.def("getName", &API::Sample::getName, return_value_policy<copy_const_reference>())
.def("getGeometryFlag", &API::Sample::getGeometryFlag)
.def("getThickness", &API::Sample::getThickness)
.def("getHeight", &API::Sample::getHeight)
.def("getWidth", &API::Sample::getWidth)
.def("__getitem__", &API::Sample::operator[], return_internal_reference<>())
.def("size", &API::Sample::size)
Gigg, Martyn Anthony
committed
;
}
Gigg, Martyn Anthony
committed
void export_run()
{
//Pointer
Gigg, Martyn Anthony
committed
register_ptr_to_python<API::Run*>();
Gigg, Martyn Anthony
committed
#define EXPORT_ADDPROPERTY(type, suffix)\
.def("addProperty_"#suffix,(void (API::Run::*)(const std::string &, const type&, bool))&Run::addProperty)
#define EXPORT_ADDPROPERTY_UNITS(type, suffix)\
.def("addProperty_"#suffix,(void (API::Run::*)(const std::string &, const type&, const std::string &, bool))&Run::addProperty)
Gigg, Martyn Anthony
committed
//Run class
Gigg, Martyn Anthony
committed
class_< API::Run, boost::noncopyable >("Run", no_init)
.def("getLogData", (Kernel::Property* (API::Run::*)(const std::string&) const)&Run::getLogData,
Gigg, Martyn Anthony
committed
return_internal_reference<>())
Gigg, Martyn Anthony
committed
.def("getLogData", (const std::vector<Kernel::Property*> & (API::Run::*)() const)&Run::getLogData,
Gigg, Martyn Anthony
committed
return_internal_reference<>())
Gigg, Martyn Anthony
committed
.def("getProtonCharge", &API::Run::getProtonCharge)
.def("hasProperty", &API::Run::hasProperty)
.def("getProperty", &API::Run::getProperty, return_value_policy<return_by_value>())
.def("getProperties", &API::Run::getProperties, return_internal_reference<>())
// .def("addProperty", (void (API::Run::*) (const std::string&, const std::string&, bool))&Run::addProperty)
EXPORT_ADDPROPERTY(int, int)
EXPORT_ADDPROPERTY(double, dbl)
EXPORT_ADDPROPERTY(std::string, str)
EXPORT_ADDPROPERTY_UNITS(int, int)
EXPORT_ADDPROPERTY_UNITS(double, dbl)
EXPORT_ADDPROPERTY_UNITS(std::string, str)
Gigg, Martyn Anthony
committed
;
#undef EXPORT_ADDPROPERTY
#undef EXPORT_ADDPROPERTY_UNITS
Gigg, Martyn Anthony
committed
}
Gigg, Martyn Anthony
committed
void export_workspace_property()
{
Gigg, Martyn Anthony
committed
class_< IWorkspaceProperty, boost::noncopyable>("IWorkspaceProperty", no_init)
;
Gigg, Martyn Anthony
committed
// Tell python about this so I can check if a property is a workspace
Gigg, Martyn Anthony
committed
class_< WorkspaceProperty<Workspace>, bases<Kernel::Property, API::IWorkspaceProperty>, boost::noncopyable>("WorkspaceProperty", no_init)
Gigg, Martyn Anthony
committed
;
Gigg, Martyn Anthony
committed
// Tell python about a MatrixWorkspace property
Gigg, Martyn Anthony
committed
class_< WorkspaceProperty<MatrixWorkspace>, bases<Kernel::Property,API::IWorkspaceProperty>, boost::noncopyable>("MatrixWorkspaceProperty", no_init)
Gigg, Martyn Anthony
committed
;
Gigg, Martyn Anthony
committed
// Tell python about a TableWorkspace property
Gigg, Martyn Anthony
committed
class_< WorkspaceProperty<ITableWorkspace>, bases<Kernel::Property,API::IWorkspaceProperty>, boost::noncopyable>("TableWorkspaceProperty", no_init)
Gigg, Martyn Anthony
committed
;
// Tell python about an EventWorkspace
Gigg, Martyn Anthony
committed
class_< WorkspaceProperty<IEventWorkspace>, bases<Kernel::Property,API::IWorkspaceProperty>, boost::noncopyable>("EventWorkspaceProperty", no_init)
Gigg, Martyn Anthony
committed
;
Gigg, Martyn Anthony
committed
}
Gigg, Martyn Anthony
committed
void export_fileproperty()
{
//FileProperty enum
enum_<FileProperty::FileAction>("FileAction")
.value("Save", FileProperty::Save)
.value("OptionalSave", FileProperty::OptionalSave)
.value("Load", FileProperty::Load)
.value("OptionalLoad", FileProperty::OptionalLoad)
.value("Directory", FileProperty::Directory)
.value("OptionalDirectory", FileProperty::OptionalDirectory)
Gigg, Martyn Anthony
committed
;
}
Gigg, Martyn Anthony
committed
void export_workspacefactory()
{
Gigg, Martyn Anthony
committed
class_< PythonAPI::WorkspaceFactoryProxy, boost::noncopyable>("WorkspaceFactoryProxy", no_init)
.def("createMatrixWorkspace", &PythonAPI::WorkspaceFactoryProxy::createMatrixWorkspace)
Gigg, Martyn Anthony
committed
.staticmethod("createMatrixWorkspace")
Gigg, Martyn Anthony
committed
.def("createMatrixWorkspaceFromTemplate",&PythonAPI::WorkspaceFactoryProxy::createMatrixWorkspaceFromTemplate)
.staticmethod("createMatrixWorkspaceFromTemplate")
void export_apivalidators()
{
class_<Kernel::IValidator<API::MatrixWorkspace_sptr>, boost::noncopyable>("IValidator_matrix", no_init)
;
// Unit checking
Gigg, Martyn Anthony
committed
class_<API::WorkspaceUnitValidator<API::MatrixWorkspace>,
bases<Kernel::IValidator<API::MatrixWorkspace_sptr> > >("WorkspaceUnitValidator", init<std::string>())
;
// Histogram checking
Gigg, Martyn Anthony
committed
class_<API::HistogramValidator<API::MatrixWorkspace>,
bases<Kernel::IValidator<API::MatrixWorkspace_sptr> > >("HistogramValidator", init<bool>())
Gigg, Martyn Anthony
committed
class_<API::RawCountValidator<API::MatrixWorkspace>,
bases<Kernel::IValidator<API::MatrixWorkspace_sptr> > >("RawCountValidator", init<bool>())
;
// Check for common bins
Gigg, Martyn Anthony
committed
class_<API::CommonBinsValidator<API::MatrixWorkspace>,
bases<Kernel::IValidator<API::MatrixWorkspace_sptr> > >("CommonBinsValidator")
Gigg, Martyn Anthony
committed
void export_workspace_history()
{
class_<API::WorkspaceHistory, boost::noncopyable>("WorkspaceHistory", no_init)
Gigg, Martyn Anthony
committed
.def("lastAlgorithm", &WorkspaceHistory::lastAlgorithm)
Gigg, Martyn Anthony
committed
.def(self_ns::str(self))
;
}
void export_file_finder()
{
class_<PythonAPI::FileFinderWrapper, boost::noncopyable>("FileFinder", no_init)
.def("getFullPath", &PythonAPI::FileFinderWrapper::getFullPath)
.staticmethod("getFullPath")
.def("findRuns", &PythonAPI::FileFinderWrapper::findRuns)
.staticmethod("findRuns")
;
}
Gigg, Martyn Anthony
committed
void export_api_namespace()
{
export_frameworkmanager();
export_ialgorithm();
export_workspace();
export_matrixworkspace();
export_eventworkspace();
Janik Zikovsky
committed
export_IMDWorkspace();
Janik Zikovsky
committed
export_mdeventworkspace();
Gigg, Martyn Anthony
committed
export_tableworkspace();
export_workspacegroup();
Michael Whitty
committed
export_axis();
Gigg, Martyn Anthony
committed
export_sample();
Gigg, Martyn Anthony
committed
export_run();
Gigg, Martyn Anthony
committed
export_workspace_property();
Gigg, Martyn Anthony
committed
export_fileproperty();
export_workspacefactory();
Gigg, Martyn Anthony
committed
export_workspace_history();
Janik Zikovsky
committed
export_IMDDimension();
Gigg, Martyn Anthony
committed
export_ISpectrum();
Janik Zikovsky
committed
export_EventList();
Gigg, Martyn Anthony
committed
}
Michael Whitty
committed
} // namespace PythonAPI
} // namespace Mantid