Commit 88a4aae3 authored by eric pellegrini's avatar eric pellegrini
Browse files

Removed intermediate class for setting McStas jobs

parent ef851899
......@@ -57,7 +57,7 @@ class ClassRegistry(abc.ABCMeta):
The MDANSE framework is based on a set of interfaces that covers different aspects of the framework such
as the analysis, the input data, the output file formats ... By metaclassing each base class of these interfaces
with :class:`ClassRegistry` object, their corresponding concrete class instances will be automatically registered at import time in
with :py:class:`~MDANSE.Core.ClassRegistry.ClassRegistry` object, their corresponding concrete class instances will be automatically registered at import time in
a data structure that can be further used all over the framework.
The data structure used to store the concrete classes is a nested dictionary whose primary key
......@@ -85,14 +85,14 @@ class ClassRegistry(abc.ABCMeta):
'''
super(ClassRegistry, self).__init__(name, bases, namespace)
# Any class
# If the class objet does not have a type attribute, it will not be registered.
typ = getattr(self, 'type', None)
if typ is None:
return
# A class metaclassed by ClassRegistry will define a new section of the registry.
# If the class object is metaclassed by ClassRegistry then a new section of the registry will
# be created with its type attribute.
metaClass = namespace.get("__metaclass__", None)
if metaClass is ClassRegistry:
ClassRegistry.__interfaces.add(self)
......
......@@ -312,7 +312,17 @@ class Platform(object):
:rtype: str
'''
return os.path.dirname(self.package_directory())
return os.path.join(os.path.dirname(self.package_directory()),'Data')
def base_directory(self):
'''
Returns the path for MDANSE base directory.
@return: the path for MDANSE base directory.
@rtype: str
'''
return os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
def package_directory(self):
'''
......
......@@ -30,9 +30,11 @@ Created on Mar 30, 2015
:author: Eric C. Pellegrini
'''
import os
import re
import subprocess
from MDANSE import PLATFORM
from MDANSE.Framework.Configurators.IConfigurator import IConfigurator
class McStasParametersConfigurator(IConfigurator):
......@@ -43,6 +45,20 @@ class McStasParametersConfigurator(IConfigurator):
type = "mcstas_parameters"
_mcStasTypes = {'double' : float, 'int' : int, 'string' : str}
_default = {'beam_wavelength_Angs': 2.0,
'environment_thickness_m': 0.002,
'beam_resolution_meV': 0.1,
'container':os.path.join(PLATFORM.example_data_directory(),'McStas','Samples','Al.laz'),
'container_thickness_m': 5e-05,
'sample_height_m': 0.05,
'environment':os.path.join(PLATFORM.example_data_directory(),'McStas','Samples','Al.laz'),
'environment_radius_m': 0.025,
'sample_thickness_m': 0.001,
'sample_detector_distance_m': 4.0,
'sample_width_m': 0.02,
'sample_rotation_deg': 45.0,
'detector_height_m': 3.0}
def __init__(self, name, exclude=None, **kwargs):
'''
......
......@@ -108,7 +108,7 @@ class IJob(Configurable):
section = "job"
@staticmethod
def set_name():
def define_unique_name():
"""
Sets a name for the job that is not already in use by another running job.
"""
......@@ -423,7 +423,7 @@ class IJob(Configurable):
try:
self._name = IJob.set_name()
self._name = IJob.define_unique_name()
if status:
self._status = JobStatus(self)
......
......@@ -45,7 +45,6 @@ from MMTK import Units
from MDANSE import ELEMENTS, REGISTRY
from MDANSE.Core.Error import Error
from MDANSE.Externals.magnitude import magnitude
from MDANSE.Framework.Configurable import Configurable
from MDANSE.Framework.Jobs.IJob import IJob
from MDANSE.MolecularDynamics.Trajectory import sorted_atoms
......@@ -54,24 +53,9 @@ MCSTAS_UNITS_LUT = {'THz': magnitude.mg(1,"THz","meV_eq").toval(),
'inv_nm' : magnitude.mg(1,"inv_nm","inv_ang").toval()
}
class McStasError(Error):
pass
class McStasOptions(Configurable):
type = "mcstas_options"
settings = collections.OrderedDict()
settings["ncount"] = ("integer", {"label":"neutron count", "mini":0})
settings["dir"] = ("output_directory", {"label":"McStas output directory"})
class McStasParameters(Configurable):
type = "mcstas_parameters"
settings = collections.OrderedDict()
class McStasVirtualInstrument(IJob):
"""
Performs a virtual neutron scattering experiment using a binding to the McStas, neutron ray-tracing code.
......@@ -102,26 +86,29 @@ class McStasVirtualInstrument(IJob):
"variables" :['q','frequency','s(q,f)_total'],
'default':os.path.join('..','..','..','Data','NetCDF','disf_prot.nc')})
settings['temperature'] = ('float', {"default":298.0})
settings['instrument'] = ('mcstas_instrument',{"label":'mcstas instrument',
'default' : os.path.join('..','..','..','Data','McStas','Instruments','Simple_ToF_Flat_Sample.out')})
settings['options'] = ('mcstas_options', {"label":'mcstas options'})
settings['display'] = ('boolean', {'label':'trace the 3D view of the simulation'})
settings['parameters'] = ('mcstas_parameters', {'label':'instrument parameters',
'dependencies':{"instrument":"instrument"},
'exclude':['sample_coh','sample_inc'],
'default' :{'beam_wavelength_Angs': 2.0,
'environment_thickness_m': 0.002,
'beam_resolution_meV': 0.1,
'container':os.path.join('..','..','..','Data','McStas','Samples','Al.laz'),
'container_thickness_m': 5e-05,
'sample_height_m': 0.05,
'environment':os.path.join('..','..','..','Data','McStas','Samples','Al.laz'),
'environment_radius_m': 0.025,
'sample_thickness_m': 0.001,
'sample_detector_distance_m': 4.0,
'sample_width_m': 0.02,
'sample_rotation_deg': 45.0,
'detector_height_m': 3.0}})
settings['instrument'] = ('mcstas_instrument',{"label":'mcstas instrument','default' : os.path.join('..','..','..','Data','McStas','Instruments','Simple_ToF_Flat_Sample.out')})
settings['options'] = ('mcstas_options', {'label':'mcstas options'})
# settings['options'] = ('mcstas_options', {"label":'mcstas options'})
settings['parameters'] = ('mcstas_parameters', {'label':'instrument parameters',
'dependencies':{'instrument':'instrument'},
'exclude':['sample_coh','sample_inc']})
# settings['parameters'] = ('mcstas_parameters', {'label':'instrument parameters',
# 'dependencies':{"instrument":"instrument"},
# 'exclude':['sample_coh','sample_inc'],
# 'default' :{'beam_wavelength_Angs': 2.0,
# 'environment_thickness_m': 0.002,
# 'beam_resolution_meV': 0.1,
# 'container':os.path.join('..','..','..','Data','McStas','Samples','Al.laz'),
# 'container_thickness_m': 5e-05,
# 'sample_height_m': 0.05,
# 'environment':os.path.join('..','..','..','Data','McStas','Samples','Al.laz'),
# 'environment_radius_m': 0.025,
# 'sample_thickness_m': 0.001,
# 'sample_detector_distance_m': 4.0,
# 'sample_width_m': 0.02,
# 'sample_rotation_deg': 45.0,
# 'detector_height_m': 3.0}})
settings['output_files'] = ('output_files', {'formats':["netcdf","ascii"]})
def initialize(self):
......
......@@ -49,7 +49,7 @@ class JobPlugin(ComponentPlugin):
def __init__(self, parent, *args, **kwargs):
self._jobClass = REGISTRY["job"][self.type]
self._job = REGISTRY["job"][self.type]()
ComponentPlugin.__init__(self, parent, size=wx.Size(800,400), *args, **kwargs)
......@@ -60,7 +60,7 @@ class JobPlugin(ComponentPlugin):
mainSizer = wx.BoxSizer(wx.VERTICAL)
self._parametersPanel = ConfigurationPanel(self._main, self._jobClass)
self._parametersPanel = ConfigurationPanel(self._main, self._job)
sb = wx.StaticBox(self._main, wx.ID_ANY)
sbSizer = wx.StaticBoxSizer(sb, wx.HORIZONTAL)
......@@ -94,7 +94,7 @@ class JobPlugin(ComponentPlugin):
def on_help(self, event):
d = JobHelpFrame(self,self._jobClass)
d = JobHelpFrame(self,self._job)
d.Show()
......@@ -105,11 +105,11 @@ class JobPlugin(ComponentPlugin):
if not parameters:
return
name = self._jobClass.set_name()
name = self._job.define_unique_name()
script = os.path.join(PLATFORM.jobscripts_directory(),name)+'.py'
self._jobClass.save(script, parameters)
self._job.save(script, parameters)
if PLATFORM.name == "windows":
startupinfo = subprocess.STARTUPINFO()
......@@ -143,7 +143,7 @@ class JobPlugin(ComponentPlugin):
if os.path.splitext(path)[1] != ".py":
path += ".py"
self._jobClass.save(path, parameters)
self._job.save(path, parameters)
def plug(self):
......@@ -203,6 +203,6 @@ if __name__ == "__main__":
filename = os.path.join(os.path.dirname(PLATFORM.package_directory()),'Data','Trajectories','MMTK','protein_in_periodic_universe.nc')
app = wx.App(False)
f = JobFrame(None,'msd',filename)
f = JobFrame(None,'mvi',filename)
f.Show()
app.MainLoop()
\ No newline at end of file
......@@ -30,23 +30,33 @@ Created on Mar 30, 2015
:author: Eric C. Pellegrini
'''
import collections
import wx
from MDANSE.GUI.ComboWidgets.ConfigurationPanel import ConfigurationPanel
from MDANSE.Framework.Jobs.McStasVirtualInstrument import McStasOptions
from MDANSE.Framework.Configurable import Configurable
from MDANSE.Framework.Widgets.IWidget import IWidget
class McStasOptionsConfiguratorWidget(IWidget):
type = "mcstas_options"
_mcStasTypes = {'double' : 'float', 'int' : 'integer', 'str' : 'input_file'}
def add_widgets(self):
sizer = wx.BoxSizer(wx.VERTICAL)
self._mcstasOptions = McStasOptions()
options = Configurable()
settings = collections.OrderedDict()
for name,value in self._configurator.default.items():
settings[name] = (self._mcStasTypes[type(value).__name__],{'default':value})
options.set_settings(settings)
self._panel = ConfigurationPanel(self._widgetPanel, self._mcstasOptions)
self._panel = ConfigurationPanel(self._widgetPanel, options)
sizer.Add(self._panel, 0, wx.ALL|wx.EXPAND, 5)
......
......@@ -29,14 +29,16 @@ Created on Mar 30, 2015
:author: Eric C. Pellegrini
'''
import collections
import wx
from MDANSE.GUI.ComboWidgets.ConfigurationPanel import ConfigurationPanel
from MDANSE.Externals.pubsub import pub
from MDANSE.Framework.Configurable import ConfigurationError
from MDANSE.Framework.Jobs.McStasVirtualInstrument import McStasParameters
from MDANSE.Framework.Configurable import Configurable
from MDANSE.Framework.Widgets.IWidget import IWidget
from MDANSE.GUI.ComboWidgets.ConfigurationPanel import ConfigurationPanel
class McStasParametersWidget(IWidget):
......@@ -56,25 +58,28 @@ class McStasParametersWidget(IWidget):
return self._sizer
def set_layout(self, message):
window, parameters = message
if not window in self.Parent.widgets.values():
widget, parameters = message
if not widget.Parent == self.Parent:
return
for k in self._configurator.exclude:
parameters.pop(k)
self._mcstasParameters = McStasParameters()
self._parameters = Configurable()
settings = collections.OrderedDict()
for name, value in parameters.items():
typ, default = value
self._mcstasParameters.settings[name] = (self._mcStasTypes[typ], {"default":default})
settings[name] = (self._mcStasTypes[typ], {"default":default})
self._parameters.set_settings(settings)
self._sizer.Clear(deleteWindows=True)
self._widgetPanel.Freeze()
self._configurationPanel = ConfigurationPanel(self._widgetPanel, self._mcstasParameters)
self._configurationPanel = ConfigurationPanel(self._widgetPanel, self._parameters)
for name, value in parameters.items():
typ, default = value
......
......@@ -10,7 +10,7 @@ class ConfigurationPanel(wx.Panel):
wx.Panel.__init__(self, parent, wx.ID_ANY)
self._configurable = configurable()
self._configurable = configurable
self._widgets = {}
......
......@@ -14,7 +14,7 @@ class JobHelpFrame(wx.Frame):
self.nolog = wx.LogNull()
moduleFullName = PLATFORM.full_dotted_module(job.__class__)
self._doc = os.path.join(PLATFORM.help_path(), moduleFullName+'.html')
self.build()
......
from MDANSE import REGISTRY
for v in REGISTRY['job'].itervalues():
v.build_test("Test_%s.py" % v.type)
\ No newline at end of file
v.build_test("Test_%s.py" % v.type)
......@@ -15,7 +15,6 @@ class TestAC(UnitTest):
parameters['running_mode'] = ('monoprocessor', 1)
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/waterbox_in_periodic_universe.nc'
job = REGISTRY['job']['ac']()
job.run(parameters,False)
self.assertNotRaises(job.run, parameters, status=False)
def suite():
......
......@@ -11,9 +11,9 @@ class TestMVI(UnitTest):
parameters['display'] = False
parameters['frames'] = (0, 10, 1)
parameters['instrument'] = '../../../Data/McStas/Instruments/Simple_ToF_Flat_Sample.out'
parameters['options'] = {'ncount': 10000, 'dir': '/users/pellegrini/workspace/MDANSE/Tests/FunctionalTests/Jobs/mcstas_output/27.07.2015-09:42:20'}
parameters['options'] = {'ncount': 10000, 'dir': '/tmp/mdanse_mcstas_ZJtYbd'}
parameters['output_files'] = ('output', ['netcdf'])
parameters['parameters'] = {'beam_wavelength_Angs': 2.0, 'container_thickness_m': 5e-05, 'environment_radius_m': 0.025, 'sample_detector_distance_m': 4.0, 'container': '../../../Data/McStas/Samples/Al.laz', 'environment_thickness_m': 0.002, 'detector_height_m': 3.0, 'beam_resolution_meV': 0.1, 'sample_height_m': 0.05, 'sample_thickness_m': 0.001, 'environment': '../../../Data/McStas/Samples/Al.laz', 'sample_width_m': 0.02, 'sample_rotation_deg': 45.0}
parameters['parameters'] = {'beam_wavelength_Angs': 2.0, 'container_thickness_m': 5e-05, 'environment_radius_m': 0.025, 'sample_detector_distance_m': 4.0, 'container': '/users/pellegrini/workspace/MDANSE/Data/McStas/Samples/Al.laz', 'environment_thickness_m': 0.002, 'detector_height_m': 3.0, 'beam_resolution_meV': 0.1, 'sample_height_m': 0.05, 'sample_thickness_m': 0.001, 'environment': '/users/pellegrini/workspace/MDANSE/Data/McStas/Samples/Al.laz', 'sample_width_m': 0.02, 'sample_rotation_deg': 45.0}
parameters['sample_coh'] = '../../../Data/NetCDF/dcsf_prot.nc'
parameters['sample_inc'] = '../../../Data/NetCDF/disf_prot.nc'
parameters['temperature'] = 298.0
......
......@@ -16,7 +16,6 @@ class TestSD(UnitTest):
parameters['target_molecule'] = 'atom_index 151'
parameters['trajectory'] = '../../../Data/Trajectories/MMTK/protein_in_periodic_universe.nc'
job = REGISTRY['job']['sd']()
job.run(parameters,False)
self.assertNotRaises(job.run, parameters, status=False)
def suite():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment