Commit df0ba797 authored by eric pellegrini's avatar eric pellegrini
Browse files

Fully docstringed new modules

parent a7bdcd3d
......@@ -27,7 +27,7 @@
'''
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini
'''
import abc
......@@ -125,14 +125,12 @@ class ClassRegistry(abc.ABCMeta):
if moduleDir not in sys.path:
sys.path.append(moduleDir)
__import__(moduleName, locals(), globals())
# # Any error that may occur here has to be caught. In such case the module is skipped.
# try:
# __import__(moduleName, locals(), globals())
# except:
# continue
# Any error that may occur here has to be caught. In such case the module is skipped.
try:
__import__(moduleName, locals(), globals())
except:
continue
@classmethod
def info(cls, interface):
......
......@@ -27,7 +27,7 @@
'''
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini
'''
class Error(Exception):
......
......@@ -27,10 +27,9 @@
'''
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini
'''
# Standards imports.
import abc
import ctypes
import datetime
......@@ -588,6 +587,7 @@ class PlatformWin(Platform):
import platform
system = platform.system()
# Instantiate the proper platform class depending on the OS on which MDANSE runs
if system == 'Linux':
PLATFORM=PlatformLinux()
......
......@@ -27,7 +27,7 @@
'''
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini
'''
import abc
......@@ -310,7 +310,7 @@ class Preferences(collections.OrderedDict):
def load(self):
'''
Load the preferences from a preferences file.
Load the preferences.
'''
path = PLATFORM.preferences_file()
......@@ -333,7 +333,7 @@ class Preferences(collections.OrderedDict):
def save(self):
'''
Save the preferences to a file.
Save the preferences.
'''
path = PLATFORM.preferences_file()
......
......@@ -27,7 +27,7 @@
'''
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini
'''
class Singleton(type):
......
......@@ -27,7 +27,7 @@
'''
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini
'''
import _abcoll
......
......@@ -29,5 +29,5 @@ This package contains all the MDANSE cython extensions.
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini
'''
......@@ -34,5 +34,5 @@ This package contains all the externals dependencies of MDANSE. It contains:
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini
'''
......@@ -27,7 +27,7 @@
'''
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini
'''
import collections
......@@ -52,10 +52,13 @@ class AtomSelectionConfigurator(IConfigurator):
This configurator allows the selection of a specific set of atoms on which the analysis will be performed.
Without any selection, all the atoms stored into the trajectory file will be selected.
To Build an atom selection you have to :
* Create a workspace based on a mmtk_trajectory data
* drag a molecular viewer on it
* drag into the Molecular Viewer his "Atom selection" plugin
To Build an atom selection from the GUI you have to :
#. Create a workspace based on a MMTK trajectory data
#. Drag a molecular viewer on it
#. Drag into the Molecular Viewer the Atom selection plugin
:note: this configurator depends on 'trajectory' configurator to be configured
'''
type = 'atom_selection'
......@@ -63,6 +66,16 @@ class AtomSelectionConfigurator(IConfigurator):
_default = "all"
def configure(self, configuration, value):
'''
Configure this configurator with a given input value. The value must be
a string that can be either an atom selection string or a valid user
definition.
:param configuration: the current configuration
:type configuration: a MDANSE.Framework.Configurable.Configurable object
:param value: the input value
:type value: str
'''
trajConfig = configuration[self._dependencies['trajectory']]
......@@ -72,8 +85,10 @@ class AtomSelectionConfigurator(IConfigurator):
self["value"] = value
ud = UD_STORE[trajConfig["basename"],"atom_selection",value]
# The input value is a user definition: get it and update the configuration
if ud is not None:
self.update(ud)
# The input value is an atom selection string: parse it and update the configuration
else:
parser = AtomSelectionParser(trajConfig["instance"])
self["indexes"] = parser.parse(value)
......@@ -93,23 +108,40 @@ class AtomSelectionConfigurator(IConfigurator):
@staticmethod
def find_parent(atom, level):
'''
Retrieve recursively the parent of a given MMTK atom at a given level.
For example, a level of 1 will return the direct parent of the atom.
:note: this is a static method
:param atom: the atom for which the parent is searched for
:type atom: MMTK.Atom object
:param level: the level of the parent
:type level: int
'''
for _ in range(level):
atom = atom.parent
return atom
def group(self, selectedAtoms, level="atom"):
level = level.strip().lower()
def group(self, atoms, level="atom"):
'''
Group the selected atoms according to a given granularity and update
the configurator with the grouping results.
:param atoms: the atoms for
:type atoms: list of MMTK.Atom
:param level: the level of granularity at which the atoms should be grouped
:type level: str
'''
groups = collections.OrderedDict()
for i, idx in enumerate(self["indexes"]):
at = selectedAtoms[i]
for at in atoms:
lvl = LEVELS[level][at.topLevelChemicalObject().__class__.__name__.lower()]
parent = self.find_parent(at,lvl)
groups.setdefault(parent,[]).append(idx)
groups.setdefault(parent,[]).append(at.index)
self["groups"] = groups.values()
......@@ -123,7 +155,10 @@ class AtomSelectionConfigurator(IConfigurator):
self.set_contents()
def set_contents(self):
'''
Sets the contents of the atom selection.
'''
self["contents"] = collections.OrderedDict()
self['index_to_symbol'] = collections.OrderedDict()
for i, group in enumerate(self["elements"]):
......@@ -132,12 +167,18 @@ class AtomSelectionConfigurator(IConfigurator):
self['index_to_symbol'][self["groups"][i][j]] = el
for k,v in self["contents"].items():
self["contents"][k] = numpy.array(v)
self["contents"][k] = numpy.array(v,dtype=numpy.int32)
self["n_atoms_per_element"] = dict([(k,len(v)) for k,v in self["contents"].items()])
self['n_selected_elements'] = len(self["contents"])
def get_information(self):
'''
Returns some informations about this configurator
:return: the information about this configurator
:rtype: str
'''
info = []
info.append("Number of selected atoms:%d\n" % self["n_selected_atoms"])
......
......@@ -27,7 +27,7 @@
'''
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini
'''
from MDANSE import ELEMENTS
......@@ -37,22 +37,39 @@ from MDANSE.Framework.AtomSelectionParser import AtomSelectionParser
class AtomTransmutationConfigurator(IConfigurator):
"""
This configurator allow to select among the User Definitions, an atomic transmutation.
Without any transmutation, all the atoms records into the trajectory keep there own types.
If a transmutation is define, the analysis will consider atoms of a certain type
exactly like if they have another type, respectfully to the transmutation definition.
This configurator allows to define a set of atoms to be transmutated to a given chemical
element.
To Build an atomic transmutation from the GUI you have to :
#. Create a workspace based on a MMTK trajectory data,
#. Drag a molecular viewer on it,
#. Drag into the Molecular Viewer the Atom transmutation plugin
To Build an atomic transmutation definition you have to :
- Create a workspace based on a mmtk_trajectory data,
- drag a molecular viewer on it,
- drag into the Molecular Viewer his "Atom transmutation" plugin
:note: this configurator depends on 'trajectory' and 'atom_selection' configurators to be properly configured
"""
type = 'atom_transmutation'
_default = None
def configure(self, configuration, value):
'''
Configure this configurator with a given input value. The value can be:
#. None: no transmutation is performed
#. (str,str)-dict: for each (str,str) pair, a transmutation will be performed
by parsing the 1st element as an atom selection string and transmutating the
corresponding atom selection to the target chemical element stored in the 2nd element
#. str: the transmutation will be performed by reading the corresponding user definition
:param configuration: the current configuration
:type configuration: a MDANSE.Framework.Configurable.Configurable object
:param value: the input value
:type value: None or (str,str)-dict or str
'''
self["value"] = value
# if the input value is None, do not perform any transmutation
if value is None:
return
......@@ -64,7 +81,7 @@ class AtomTransmutationConfigurator(IConfigurator):
parser = AtomSelectionParser(trajConfig["instance"])
# If the input value is a dictionary, it must have a selection string or a python script as key and the element
# If the input value is a dictionary, it must have a selection string as key and the element
# to be transmutated to as value
if isinstance(value,dict):
for expression,element in value.items():
......@@ -86,24 +103,37 @@ class AtomTransmutationConfigurator(IConfigurator):
or a list of string that match an user definition",self)
def transmutate(self, configuration, selection, element):
'''
Transmutates a set of atoms to a given element
:param configuration: the current configuration
:type configuration: a MDANSE.Framework.Configurable.Configurable object
:param selection: the indexes of the atoms to be transmutated
:type selection: list of int
:param element: the symbol of the element to which the selected atoms should
be transmutated
:type element: str
'''
if element not in ELEMENTS:
raise ConfiguratorError("the element %r is not registered in the database" % element, self)
for idx in selection:
try:
pos = self["atom_selection"]["groups"].index([idx])
except ValueError:
continue
else:
self["atom_selection"]["elements"][pos] = [element]
pos = self["atom_selection"]["groups"].index([idx])
self["atom_selection"]["elements"][pos] = [element]
# Update the current configuration according to the changes triggered by
# atom transumutation
configuration[self._dependencies['atom_selection']].set_contents()
def get_information(self):
'''
Returns some informations about this configurator
:return: the information about this configurator
:rtype: str
'''
if self["value"] is None:
return "No atoms selected for deuteration"
......
......@@ -27,7 +27,7 @@
'''
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini and Bachir Aoun
'''
from MDANSE.Framework.UserDefinitions.IUserDefinition import UD_STORE
......@@ -36,14 +36,15 @@ from MDANSE.MolecularDynamics.Trajectory import find_atoms_in_molecule
class AxisSelection(IConfigurator):
"""
This configurator allow to select an axis selection among the User Definitions.
This could be mandatory for the analysis, if not, some generic behavior will be setup.
An axis selection is defined using two atomic coordinates (or atomic cluster center of mass)
This configurator allows to define an axis per molecule. For each molecule, the
axis is basically defined using the coordinates of two of its atoms.
To Build an axis selection definition you have to :
- Create a workspace based on a mmtk_trajectory data,
- drag a molecular viewer on it,
- drag into the Molecular Viewer his "Axis selection" plugin
To Build an axis selection from the GUI you have to :
#. Create a workspace based on a mmtk_trajectory data,
#. Drag a molecular viewer on it,
#. Drag into the Molecular Viewer the Axis selection plugin
:note: this configurator depends on 'trajectory' configurator to be configured
"""
type = "axis_selection"
......@@ -51,6 +52,19 @@ class AxisSelection(IConfigurator):
_default = None
def configure(self, configuration, value):
'''
Configure this configurator with a given input value. The value can be:
#. a dict with 'molecule', 'endpoint1' and 'endpoint2' keys. 'molecule' key
is the molecule name for which the axis selection will be performed
and 'endpoint1' and 'endpoint2' keys are the names of two atoms of the molecule
along which the axis will be defined
#. str: the axis selection will be performed by reading the corresponding user definition
:param configuration: the current configuration
:type configuration: a MDANSE.Framework.Configurable.Configurable object
:param value: the input value
:type value: tuple or str
'''
trajConfig = configuration[self._dependencies['trajectory']]
......@@ -70,5 +84,11 @@ class AxisSelection(IConfigurator):
self['n_axis'] = len(self['endpoints'])
def get_information(self):
'''
Returns some informations about this configurator
:return: the information about this configurator
:rtype: str
'''
return "Axis vector:%s" % self["value"]
\ No newline at end of file
......@@ -27,7 +27,7 @@
'''
Created on Mar 30, 2015
@author: pellegrini
@author: Eric C. Pellegrini and Bachir Aoun
'''
from MDANSE.Framework.UserDefinitions.IUserDefinition import UD_STORE
......@@ -36,17 +36,15 @@ from MDANSE.MolecularDynamics.Trajectory import find_atoms_in_molecule
class BasisSelection(IConfigurator):
"""
This configurator allow to select a basis selection among the User Definitions.
This could be mandatory for the analysis, if not, some generic behavior will be setup.
An axis selection is defined using :
- one origin,
- two vector define using the origin and two atomic coordinates (or atomic cluster center of mass),
- the third direction, automatically taken as the vector product of the two precedent.
This configurator allows to define basis per molecule. For each molecule, the
basis is basically defined using the coordinates of three of its atoms. This coordinates
will respectively define the origin the X axis and y axis of the basis, the Z axis
being defined in such a way that the basis is direct.
To Build a basis selection definition you have to :
- Create a workspace based on a mmtk_trajectory data,
- drag a molecular viewer on it,
- drag into the Molecular Viewer his "Basis selection" plugin
To Build a basis selection from the GUI you have to :
#. Create a workspace based on a mmtk_trajectory data,
#. Drag a molecular viewer on it,
#. Drag into the Molecular Viewer the Basis selection plugin
"""
type = 'basis_selection'
......@@ -54,6 +52,22 @@ class BasisSelection(IConfigurator):
_default = None
def configure(self, configuration, value):
'''
Configure this configurator with a given input value. The value can be:
#. a dict with 'molecule', 'origin', 'x_axis' and 'y_axis' keys.
'molecule' key is the molecule name for which the axis selection will be performed
and 'origin', 'x_axis' and 'y_axis' keys are the names of three atoms of the molecule
that will be used to define respectively the origin, the X and Y axis of the basis
#. str: the axis selection will be performed by reading the corresponding user definition
:param configuration: the current configuration
:type configuration: a MDANSE.Framework.Configurable.Configurable object
:param value: the input value
:type value: tuple or str
:note: this configurator depends on 'trajectory' configurator to be configured
'''
trajConfig = configuration[self._dependencies['trajectory']]
ud = UD_STORE[trajConfig["basename"],"basis_selection",value]
......@@ -73,5 +87,11 @@ class BasisSelection(IConfigurator):
self['n_basis'] = len(self['basis'])
def get_information(self):
'''
Returns some informations about this configurator
:return: the information about this configurator
:rtype: str
'''
return "Basis vector:%s" % self["value"]
\ No newline at end of file
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