Skip to content

Commit

Permalink
Move Simlation MolDyn to new algorithm
Browse files Browse the repository at this point in the history
Refs #10391
  • Loading branch information
DanNixon committed Oct 21, 2014
1 parent c072250 commit 2617575
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 55 deletions.
Expand Up @@ -68,7 +68,7 @@ def summary(self):
return 'Imports nMOLDYN simulations from CDL and ASCII files.'

def PyInit(self):
self.declareProperty(FileProperty('SampleFile', '',
self.declareProperty(FileProperty('Filename', '',
action=FileAction.OptionalLoad,
extensions=['.cdl', '.dat']),
doc='File path for data')
Expand Down Expand Up @@ -99,7 +99,7 @@ def PyInit(self):
def validateInputs(self):
issues = dict()

sample_filename = self.getPropertyValue('SampleFile')
sample_filename = self.getPropertyValue('Filename')
function_list = self.getProperty('Functions').value
res_ws = self.getPropertyValue('Resolution')

Expand Down Expand Up @@ -173,7 +173,7 @@ def _setup(self):
self._plot = self.getProperty('Plot').value
self._save = self.getProperty('Save').value

self._sam_path = self.getPropertyValue('SampleFile')
self._sam_path = self.getPropertyValue('Filename')

raw_functions = self.getProperty('Functions').value
self._functions = [x.strip() for x in raw_functions]
Expand Down
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>444</width>
<height>155</height>
<height>182</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -33,7 +33,7 @@
<widget class="QLineEdit" name="leFunctionNames"/>
</item>
<item row="0" column="1">
<widget class="MantidQt::MantidWidgets::MWRunFiles" name="mwRun">
<widget class="MantidQt::MantidWidgets::MWRunFiles" name="mwRun" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -43,7 +43,7 @@
<property name="label" stdset="0">
<string/>
</property>
<property name="fileExtensions">
<property name="fileExtensions" stdset="0">
<stringlist>
<string>.dat</string>
<string>.cdl</string>
Expand All @@ -58,6 +58,71 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lblEnergyCrop">
<property name="text">
<string>Max. Energy:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lblResolution">
<property name="text">
<string>Resolution:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="MantidQt::MantidWidgets::DataSelector" name="dsResolution" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="autoLoad" stdset="0">
<bool>true</bool>
</property>
<property name="loadLabelText" stdset="0">
<string/>
</property>
<property name="workspaceSuffixes" stdset="0">
<stringlist>
<string>_red</string>
<string>_res</string>
</stringlist>
</property>
<property name="fileBrowserSuffixes" stdset="0">
<stringlist>
<string>_red.nxs</string>
<string>_res.nxs</string>
</stringlist>
</property>
<property name="showLoad" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="leMaxEnergy"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -165,6 +230,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MantidQt::MantidWidgets::DataSelector</class>
<extends>QWidget</extends>
<header>MantidQtMantidWidgets/DataSelector.h</header>
</customwidget>
<customwidget>
<class>MantidQt::MantidWidgets::MWRunFiles</class>
<extends>QWidget</extends>
Expand Down
Expand Up @@ -2,6 +2,7 @@
#define MANTID_CUSTOMINTERFACES_INDIRECTSIMULATIONTAB_H_

#include "MantidKernel/System.h"
#include "MantidQtAPI/AlgorithmRunner.h"
#include <QSettings>
#include <QWidget>

Expand All @@ -16,6 +17,8 @@ namespace MantidQt
@author Samuel Jackson, STFC
TODO: Make this inherit from IndirectTab (#10277)
Copyright &copy; 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Expand Down Expand Up @@ -62,9 +65,13 @@ namespace MantidQt

protected:
void runPythonScript(const QString& pyInput);
void runAlgorithm(const Mantid::API::IAlgorithm_sptr alg);

private:
MantidQt::API::AlgorithmRunner m_algoRunner;

};
} // namespace CustomInterfaces
} // namespace Mantid

#endif
#endif
79 changes: 34 additions & 45 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectMolDyn.cpp
@@ -1,23 +1,27 @@
#include "MantidQtCustomInterfaces/IndirectMolDyn.h"

#include "MantidAPI/AlgorithmManager.h"

#include <QFileInfo>
#include <QString>

using namespace Mantid::API;

namespace MantidQt
{
namespace CustomInterfaces
{
IndirectMolDyn::IndirectMolDyn(QWidget * parent) :
IndirectMolDyn::IndirectMolDyn(QWidget * parent) :
IndirectSimulationTab(parent)
{
m_uiForm.setupUi(parent);
}

/**
* Validate the form to check the program can be run
*
* @return :: Whether the form was valid
*/
* Validate the form to check the program can be run
*
* @return :: Whether the form was valid
*/
bool IndirectMolDyn::validate()
{
QString filename = m_uiForm.mwRun->getFirstFilename();
Expand All @@ -28,60 +32,45 @@ namespace MantidQt
{
emit showMessageBox("File is not of expected type:\n File type must be .dat or .cdl");
return false;
}
}

return true;
}

/**
* Collect the settings on the GUI and build a python
* script that runs IndirectMolDyn
*/
void IndirectMolDyn::run()
* Collect the settings on the GUI and run the MolDyn algorithm.
*/
void IndirectMolDyn::run()
{
QString verbose("False");
QString plot("False");
QString save("False");

QString filename = m_uiForm.mwRun->getFirstFilename();
QFileInfo finfo(filename);
QString ext = finfo.extension().toLower();

QString funcNames = m_uiForm.leFunctionNames->text();
// Get filename and base filename (for naming output workspace group)
QString filename = m_uiForm.mwRun->getFirstFilename();
QFileInfo fi(filename);
QString baseName = fi.baseName();

//output options
if(m_uiForm.chkVerbose->isChecked()){ verbose = "True"; }
if(m_uiForm.chkSave->isChecked()){ save ="True"; }
plot = m_uiForm.cbPlot->currentText();
// Setup algorithm
IAlgorithm_sptr molDynAlg = AlgorithmManager::Instance().create("MolDyn");
molDynAlg->setProperty("Filename", filename.toStdString());
molDynAlg->setProperty("Functions", m_uiForm.leFunctionNames->text().toStdString());
molDynAlg->setProperty("Verbose", m_uiForm.chkVerbose->isChecked());
molDynAlg->setProperty("Save", m_uiForm.chkSave->isChecked());
molDynAlg->setProperty("Plot", m_uiForm.cbPlot->currentText().toStdString());
molDynAlg->setProperty("MaxEnergy", m_uiForm.leMaxEnergy->text().toStdString());
molDynAlg->setProperty("Resolution", m_uiForm.dsResolution->getCurrentDataName().toStdString());
molDynAlg->setProperty("OutputWorkspace", baseName.toStdString());


QString pyInput =
"from IndirectMolDyn import ";

QString pyFunc("");
if(ext == "dat")
{
pyFunc = "MolDynText";
pyInput += pyFunc + "\n" + pyFunc + "('"+filename+"',"+verbose+",'"+plot+"',"+save+")";
}
else if (ext == "cdl")
{
pyFunc = "MolDynImport";
pyInput += pyFunc + "\n" + pyFunc + "('"+filename+"','"+funcNames+"',"+verbose+",'"+plot+"',"+save+")";
}

runPythonScript(pyInput);
runAlgorithm(molDynAlg);
}

/**
* Set the data selectors to use the default save directory
* when browsing for input files.
*
* @param settings :: The settings to loading into the interface
*/
* Set the data selectors to use the default save directory
* when browsing for input files.
*
* @param settings :: The settings to loading into the interface
*/
void IndirectMolDyn::loadSettings(const QSettings& settings)
{
m_uiForm.mwRun->readSettings(settings.group());
}

} // namespace CustomInterfaces
} // namespace MantidQt
@@ -1,6 +1,8 @@
#include "MantidQtAPI/UserSubWindow.h"
#include "MantidQtCustomInterfaces/IndirectSimulationTab.h"

using namespace Mantid::API;

namespace MantidQt
{
namespace CustomInterfaces
Expand All @@ -9,9 +11,9 @@ namespace MantidQt
//----------------------------------------------------------------------------------------------
/** Constructor
*/
IndirectSimulationTab::IndirectSimulationTab(QWidget * parent) : QWidget(parent)
IndirectSimulationTab::IndirectSimulationTab(QWidget * parent) : QWidget(parent),
m_algoRunner(parent)
{

}

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -41,5 +43,16 @@ namespace MantidQt
{
emit executePythonScript(pyInput, false);
}

/**
* Runs an algorithm async from the UI thread.
*
* @param alg Configured algorithm to run
*/
void IndirectSimulationTab::runAlgorithm(const IAlgorithm_sptr alg)
{
m_algoRunner.startAlgorithm(alg);
}

}
} // namespace MantidQt
2 changes: 1 addition & 1 deletion Code/Mantid/docs/source/algorithms/MolDyn-v1.rst
Expand Up @@ -29,7 +29,7 @@ Usage

.. testcode:: ExLoadCDLFile

out_ws_group = MolDyn(SampleFile='NaF_DISF.cdl', Functions=['Fqt-total', 'Fqt-Na'])
out_ws_group = MolDyn(Filename='NaF_DISF.cdl', Functions=['Fqt-total', 'Fqt-Na'])

for ws_name in out_ws_group.getNames():
print ws_name
Expand Down

0 comments on commit 2617575

Please sign in to comment.