Commit 10c38dc7 authored by eric pellegrini's avatar eric pellegrini

All the analysis are now reintroduced in MDANSE

Splitted the Plotter plugin in several modules
parent 36f7b144
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''
Created on Mar 30, 2015
@author: Gael Goret, Eric C. Pellegrini
'''
from MDANSE.App.GUI.Plugins.IPlugin import IPlugin
class ComponentPlugin(IPlugin):
type = None
@property
def datakey(self):
return self.parent.datakey
@property
def dataproxy(self):
return self.parent.dataproxy
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''
Created on Mar 30, 2015
@author: Gael Goret, Eric C. Pellegrini
'''
import wx
import wx.aui as wxaui
from MDANSE import REGISTRY
from MDANSE.Externals.pubsub import pub
from MDANSE.App.GUI import DATA_CONTROLLER
from MDANSE.App.GUI.Plugins.IPlugin import IPlugin, plugin_parent
class DataPlugin(IPlugin):
type = 'data'
ancestor = None
def __init__(self, parent, datakey):
IPlugin.__init__(self, parent, wx.ID_ANY)
self._datakey = datakey
self._dataProxy = DATA_CONTROLLER[self._datakey]
self._mgr.Bind(wx.EVT_CHILD_FOCUS, self.on_changing_pane)
self._currentWindow = self
def build_panel(self):
pass
def plug(self, standalone=False):
pass
@property
def currentWindow(self):
return self._currentWindow
@property
def datakey(self):
return self._datakey
@datakey.setter
def datakey(self, key):
self._datakey = key
@property
def dataproxy(self):
return self._dataProxy
def drop(self, pluginName):
# If no plugin match the name of the dropped plugin, do nothing.
plugin = REGISTRY["plugin"].get(pluginName,None)
if plugin is None:
return
if not issubclass(self.__class__,REGISTRY['plugin'][plugin.ancestor]):
return
plugin = plugin(self)
self._mgr.AddPane(plugin, wxaui.AuiPaneInfo().Caption(getattr(plugin, "label", pluginName)))
self._mgr.Update()
plugin.plug()
plugin.SetFocus()
def has_parent(self, window):
return False
def on_changing_pane(self, event):
window = plugin_parent(event.GetWindow())
if window is None:
return
self._currentWindow = window
pub.sendMessage(('set_plugins_tree'), message= window)
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''
Created on Mar 30, 2015
@author: Gael Goret, Eric C. Pellegrini
'''
import abc
import cPickle
import wx
import wx.aui as aui
from MDANSE import REGISTRY
def plugin_parent(window):
if window == window.TopLevelParent:
return None
if isinstance(window,IPlugin):
return window
else:
return plugin_parent(window.Parent)
class PluginDropTarget(wx.DropTarget):
def __init__(self, targetPanel):
wx.DropTarget.__init__(self)
self._targetPanel = targetPanel
self._data = wx.CustomDataObject("Plugin")
self.SetDataObject(self._data)
@property
def target_panel(self):
return self._targetPanel
def OnDrop(self, x, y):
return True
def OnDragOver(self, x, y, d):
return wx.DragCopy
def OnData(self, x, y, d):
if self.GetData():
pluginName = cPickle.loads(self._data.GetData())
self._targetPanel.drop(pluginName)
return d
class IPlugin(wx.Panel):
__metaclass__ = REGISTRY
type = "plugin"
ancestor = None
def __init__(self, parent, *args, **kwargs):
wx.Panel.__init__(self, parent, *args, **kwargs)
self._parent = parent
self.SetDropTarget(PluginDropTarget(self))
self.build_dialog()
self._mgr.Bind(aui.EVT_AUI_PANE_CLOSE, self.on_close_pane)
@abc.abstractmethod
def build_panel(self):
pass
@abc.abstractmethod
def plug(self, standalone=False):
pass
@property
def mgr(self):
return self._mgr
@property
def parent(self):
return self._parent
def close_children(self):
childrenPlugins = [p.window for p in self._mgr.GetAllPanes()]
for plugin in childrenPlugins:
try:
plugin.close_children()
except AttributeError:
continue
self.close()
def close(self):
pass
def on_close_pane(self, event):
plugin = event.GetPane().window
try:
plugin.close_children()
except AttributeError:
plugin.Close()
def build_dialog(self):
self.Freeze()
self._mgr = aui.AuiManager(self)
self.build_panel()
self._mgr.Update()
self.Thaw()
def drop(self, pluginName):
# If no plugin match the name of the dropped plugin, do nothing.
plugin = REGISTRY["plugin"].get(pluginName,None)
if plugin is None:
return
if not issubclass(self.__class__,REGISTRY['plugin'][plugin.ancestor]):
self.parent.drop(pluginName)
return
plugin = plugin(self)
self._mgr.AddPane(plugin, aui.AuiPaneInfo().Caption(getattr(plugin, "label", pluginName)))
self._mgr.Update()
plugin.plug()
plugin.SetFocus()
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''
Created on Apr 13, 2015
@author: Gael Goret, Eric C. Pellegrini
'''
import matplotlib
class ScaledLocator(matplotlib.ticker.MaxNLocator):
"""
Locates regular intervals along an axis scaled by *dx* and shifted by
*x0*. For example, this would locate minutes on an axis plotted in seconds
if dx=60. This differs from MultipleLocator in that an approriate interval
of dx units will be chosen similar to the default MaxNLocator.
"""
def __init__(self, dx=1.0, x0=0.0):
self.dx = dx
self.x0 = x0
matplotlib.ticker.MaxNLocator.__init__(self, nbins=9, steps=[1, 2, 5, 10])
def rescale(self, x):
return x * self.dx + self.x0
def inv_rescale(self, x):
return (x - self.x0) / self.dx
def __call__(self):
vmin, vmax = self.axis.get_view_interval()
vmin, vmax = self.rescale(vmin), self.rescale(vmax)
vmin, vmax = matplotlib.transforms.nonsingular(vmin, vmax, expander = 0.05)
locs = self.bin_boundaries(vmin, vmax)
locs = self.inv_rescale(locs)
prune = self._prune
if prune=='lower':
locs = locs[1:]
elif prune=='upper':
locs = locs[:-1]
elif prune=='both':
locs = locs[1:-1]
return self.raise_if_exceeds(locs)
class ScaledFormatter(matplotlib.ticker.OldScalarFormatter):
"""Formats tick labels scaled by *dx* and shifted by *x0*."""
def __init__(self, dx=1.0, x0=0.0, **kwargs):
self.dx, self.x0 = dx, x0
def rescale(self, x):
return x * self.dx + self.x0
def __call__(self, x, pos=None):
xmin, xmax = self.axis.get_view_interval()
xmin, xmax = self.rescale(xmin), self.rescale(xmax)
d = abs(xmax - xmin)
x = self.rescale(x)
s = self.pprint_val(x, d)
return s
......@@ -78,6 +78,8 @@ class ClassRegistry(abc.ABCMeta):
:type namespace: dict
'''
print name, bases, namespace
super(ClassRegistry, self).__init__(name, bases, namespace)
# Get the typ of the class
......@@ -123,8 +125,6 @@ class ClassRegistry(abc.ABCMeta):
moduleName, moduleExt = os.path.splitext(moduleFile)
print moduleName
if moduleDir not in sys.path:
sys.path.append(moduleDir)
......
......@@ -204,6 +204,27 @@ class InputDirectory(PreferencesItem):
raise PreferencesError('Error when setting input directory %r' % value)
self._value = value
class LoggingLevel(PreferencesItem):
type = "logging_level"
LOGGING_LEVELS = ["debug","info","warning","error","critical","fatal"]
def set_value(self, value):
'''
Set the value of the logging level preferences item.
:param value: the logging level
:type value: str
'''
value = value.lower()
if not value in LoggingLevel.LOGGING_LEVELS:
raise PreferencesError("Invalid logging level")
self._value = value
class Preferences(collections.OrderedDict):
'''
......@@ -220,12 +241,14 @@ class Preferences(collections.OrderedDict):
Constructs the preferences
'''
collections.OrderedDict.__init__(self)
self["working_directory"] = InputDirectory("working_directory", "paths", PLATFORM.home_directory())
self["macros_directory"] = InputDirectory("macros_directory", "paths", os.path.join(PLATFORM.home_directory(), "mdanse_macros"))
self._parser = ConfigParser.ConfigParser()
for s in self._items.values():
for s in self.values():
try:
self._parser.add_section(s.section)
except ConfigParser.DuplicateSectionError:
......@@ -276,11 +299,11 @@ class Preferences(collections.OrderedDict):
:type value: any
'''
if not self._items.has_key(item):
if not self.has_key(item):
return
try:
self._items[item].value = value
self[item].value = value
except KeyError:
raise PreferencesError("The preferences item %r is not valid" % item)
......@@ -320,7 +343,7 @@ class Preferences(collections.OrderedDict):
except (IOError,TypeError) as e:
raise PreferencesError(e)
for v in self._items.values():
for v in self.values():
self._parser.set(v.section,v.name,v.value)
# Write the preferences.
......
......@@ -66,7 +66,6 @@ def create_mmtk_atom_entry(name, symbol=None, mass=0.0):
symbol = name
filename = os.path.join(PLATFORM.local_mmtk_database_directory(),"Atoms", name)
print filename
f = open(filename, 'w')
# This three entries are compulsory for a MMTK.Atom to be valid
f.write('name = "%s"\n\n' % name)
......@@ -275,19 +274,19 @@ class ElementsDatabase(object):
>>> # Import the database
>>> from MDANSE import ELEMENTS
>>>
>>>
>>> # Fetch the hydrogen natural element --> get a deep-copy of the its properties
>>> hydrogen = ELEMENTS["H"]
>>>
>>>
>>> # Fetch the hydrogen H[1] isotope --> get a deep-copy of the its properties
>>> h1 = ELEMENTS["H[1]"]
>>>
>>>
>>> # Return a list of the properties stored in the database
>>> l = ELEMENTS.get_properties()
>>>
>>>
>>> # Return the atomic weight of U[235] element
>>> w = ELEMENTS["U[235]","atomic_weight"]
>>>
>>>
>>> # Returns the elements stored currently in the database
>>> elements = ELEMENTS.get_elements()
'''
......
......@@ -186,7 +186,9 @@ class Configurable(object):
for name,(typ,kwds) in configurators.items():
cfg=REGISTRY["configurator"][typ](name, **kwds)
doclist.append({'Configurator' : name,'Default value' : repr(cfg.default),'Description' : str(cfg.__doc__)})
descr = kwds.get("description","")
descr += "\n"+str(cfg.__doc__)
doclist.append({'Configurator' : name,'Default value' : repr(cfg.default),'Description' : descr})
docstring = "\n:Example:\n\n"
docstring += ">>> from MDANSE import REGISTRY\n"
......@@ -227,8 +229,6 @@ class Configurable(object):
docstring += "\n"
# print docstring
return docstring
@classmethod
......
......@@ -100,7 +100,6 @@ class MDFile(dict):
self["instance"].seek(0)
def read_step(self, step):
"""
"""
......@@ -129,12 +128,10 @@ class MDFile(dict):
return timeStep, basisVectors, config
def close(self):
self["instance"].close()
class CASTEP_Converter(IJob):
class CASTEPConverter(IJob):
"""
Converts a Castep Trajectory into a MMTK NetCDFFile.
"""
......
This diff is collapsed.
......@@ -35,7 +35,7 @@ import collections
from MDANSE import ELEMENTS
from MDANSE.Framework.Jobs.IJob import IJob
from MDANSE.Mathematics.Arithmetic import weight
from MDANSE.Mathematics.Signal import correlation, differentiate, normalize, get_spectrum
from MDANSE.Mathematics.Signal import correlation, differentiate, get_spectrum
from MDANSE.MolecularDynamics.Trajectory import read_atoms_trajectory
class DensityOfStates(IJob):
......
This diff is collapsed.
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Fre