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

Merge branch 'feature-sphinx_doc' into 'develop'

Feature sphinx doc

See merge request !26
parents 017616ad fdb9294c
Pipeline #4229 passed with stages
in 36 minutes and 53 seconds
...@@ -1170,12 +1170,4 @@ def _init_mags(): ...@@ -1170,12 +1170,4 @@ def _init_mags():
if not MAGS: if not MAGS:
_init_mags() _init_mags()
if __name__ == "__main__":
print mg(1.0,'h THz','meV')
print mg(1.0,'meV/h','THz')
print mg(1.0,'hbar rad/ps','meV')
print mg(1.0,'cyc THz','rad/ps')
print mg(1.0,'rad/ps',' cyc THz')
print mg(1.0,'rad/ps',' cyc meV(freq)')
...@@ -122,36 +122,26 @@ if __name__ == "__main__": ...@@ -122,36 +122,26 @@ if __name__ == "__main__":
from MDANSE.Externals.pyparsing.pyparsing import * from MDANSE.Externals.pyparsing.pyparsing import *
def parse_keyword(token): def parse_keyword(token):
print "parse_keyword"
return '"%s"(universe).select' % token[0] return '"%s"(universe).select' % token[0]
def parse_arguments(token): def parse_arguments(token):
print "parse_arguments"
return "(%s)" % str(token) return "(%s)" % str(token)
def operator_and(token): def operator_and(token):
print "operator_and"
token[0][1] = "&" token[0][1] = "&"
return " ".join(token[0]) return " ".join(token[0])
def operator_or(token): def operator_or(token):
print "operator_or"
token[0][1] = "|" token[0][1] = "|"
return " ".join(token[0]) return " ".join(token[0])
def parse_expression(self, token): def parse_expression(self, token):
print "parse_expression"
return "".join([str(t) for t in token]) return "".join([str(t) for t in token])
...@@ -173,5 +163,4 @@ if __name__ == "__main__": ...@@ -173,5 +163,4 @@ if __name__ == "__main__":
rpar=")") rpar=")")
parsedExpression = expr.transformString(expression) parsedExpression = expr.transformString(expression)
print parsedExpression
...@@ -33,7 +33,6 @@ Created on Mar 30, 2015 ...@@ -33,7 +33,6 @@ Created on Mar 30, 2015
import collections import collections
import operator import operator
from MDANSE import ELEMENTS, REGISTRY from MDANSE import ELEMENTS, REGISTRY
from MDANSE.Framework.UserDefinitionStore import UD_STORE from MDANSE.Framework.UserDefinitionStore import UD_STORE
from MDANSE.Framework.Configurators.IConfigurator import IConfigurator, ConfiguratorError from MDANSE.Framework.Configurators.IConfigurator import IConfigurator, ConfiguratorError
...@@ -47,7 +46,7 @@ LEVELS["residue"] = {"atom" : 0, "atomcluster" : 1, "molecule" : 1, "nucleotide ...@@ -47,7 +46,7 @@ LEVELS["residue"] = {"atom" : 0, "atomcluster" : 1, "molecule" : 1, "nucleotide
LEVELS["chain"] = {"atom" : 0, "atomcluster" : 1, "molecule" : 1, "nucleotidechain" : 3, "peptidechain" : 3, "protein" : 3} LEVELS["chain"] = {"atom" : 0, "atomcluster" : 1, "molecule" : 1, "nucleotidechain" : 3, "peptidechain" : 3, "protein" : 3}
LEVELS["molecule"] = {"atom" : 0, "atomcluster" : 1, "molecule" : 1, "nucleotidechain" : 3, "peptidechain" : 3, "protein" : 4} LEVELS["molecule"] = {"atom" : 0, "atomcluster" : 1, "molecule" : 1, "nucleotidechain" : 3, "peptidechain" : 3, "protein" : 4}
class AtomSelectionConfigurator(IConfigurator): class AtomSelectionConfigurator(IConfigurator):
''' '''
This configurator allows the selection of a specific set of atoms on which the analysis will be performed. This configurator allows the selection of a specific set of atoms on which the analysis will be performed.
...@@ -55,82 +54,77 @@ class AtomSelectionConfigurator(IConfigurator): ...@@ -55,82 +54,77 @@ class AtomSelectionConfigurator(IConfigurator):
After the call to :py:meth:`~MDANSE.Framework.Configurators.AtomSelectionConfigurator.AtomSelectionConfigurator.configure` method After the call to :py:meth:`~MDANSE.Framework.Configurators.AtomSelectionConfigurator.AtomSelectionConfigurator.configure` method
the following keys will be available for this configurator the following keys will be available for this configurator
#. value: the input value used to configure this configurator #. value: the input value used to configure this configurator
#. indexes: the sorted (in increasing order) MMTK indexes of the selected atoms #. indexes: the sorted (in increasing order) MMTK indexes of the selected atoms
#. n_selected_atoms: the number of selected atoms #. n_selected_atoms: the number of selected atoms
#. elements: a nested-list of the chemical symbols of the selected atoms. The size of the nested list depends on the #. elements: a nested-list of the chemical symbols of the selected atoms. The size of the nested list depends on the grouping_level selected via :py:class:`~MDANSE.Framework.Configurators.GroupingLevelConfigurator.GroupingLevelConfigurator` configurator.
grouping_level selected via :py:class:`~MDANSE.Framework.Configurators.GroupingLevelConfigurator.GroupingLevelConfigurator`
configurator.
:note: this configurator depends on :py:class:`~MDANSE.Framework.Configurators.MMTKTrajectoryConfigurator.MMTKTrajectoryConfigurator` and :py:class:`~MDANSE.Framework.Configurators.GroupingLevelConfigurator.GroupingLevelConfigurator` configurators to be configured
:note: this configurator depends on :py:class:`~MDANSE.Framework.Configurators.MMTKTrajectoryConfigurator.MMTKTrajectoryConfigurator`
and :py:class:`~MDANSE.Framework.Configurators.GroupingLevelConfigurator.GroupingLevelConfigurator` configurators to be configured
''' '''
_default = "all" _default = "all"
def configure(self, value): def configure(self, value):
''' '''
Configure an input value. Configure an input value.
The value must be a string that can be either an atom selection string or a valid user The value must be a string that can be either an atom selection string or a valid user definition.
definition.
:param value: the input value :param value: the input value
:type value: str :type value: str
''' '''
trajConfig = self._configurable[self._dependencies['trajectory']] trajConfig = self._configurable[self._dependencies['trajectory']]
if value is None: if value is None:
value = ['all'] value = ['all']
if isinstance(value,basestring): if isinstance(value,basestring):
value = [value] value = [value]
if not isinstance(value,(list,tuple)): if not isinstance(value,(list,tuple)):
raise ConfiguratorError("Invalid input value.") raise ConfiguratorError("Invalid input value.")
self["value"] = value self["value"] = value
indexes = set() indexes = set()
for v in value: for v in value:
if UD_STORE.has_definition(trajConfig["basename"],"atom_selection",v): if UD_STORE.has_definition(trajConfig["basename"],"atom_selection",v):
ud = UD_STORE.get_definition(trajConfig["basename"],"atom_selection",v) ud = UD_STORE.get_definition(trajConfig["basename"],"atom_selection",v)
indexes.update(ud["indexes"]) indexes.update(ud["indexes"])
else: else:
parser = AtomSelectionParser(trajConfig["instance"]) parser = AtomSelectionParser(trajConfig["instance"])
indexes.update(parser.parse(v)) indexes.update(parser.parse(v))
self["flatten_indexes"] = sorted(list(indexes)) self["flatten_indexes"] = sorted(list(indexes))
trajConfig = self._configurable[self._dependencies['trajectory']] trajConfig = self._configurable[self._dependencies['trajectory']]
atoms = sorted(trajConfig["universe"].atomList(), key = operator.attrgetter('index')) atoms = sorted(trajConfig["universe"].atomList(), key = operator.attrgetter('index'))
selectedAtoms = [atoms[idx] for idx in indexes] selectedAtoms = [atoms[idx] for idx in indexes]
self["selection_length"] = len(self["flatten_indexes"]) self["selection_length"] = len(self["flatten_indexes"])
self['indexes'] = [[idx] for idx in self["flatten_indexes"]] self['indexes'] = [[idx] for idx in self["flatten_indexes"]]
self['elements'] = [[at.symbol] for at in selectedAtoms] self['elements'] = [[at.symbol] for at in selectedAtoms]
self['names'] = [at.symbol for at in selectedAtoms] self['names'] = [at.symbol for at in selectedAtoms]
self['unique_names'] = sorted(set(self['names'])) self['unique_names'] = sorted(set(self['names']))
self['masses'] = [[ELEMENTS[n,'atomic_weight']] for n in self['names']] self['masses'] = [[ELEMENTS[n,'atomic_weight']] for n in self['names']]
def get_natoms(self): def get_natoms(self):
nAtomsPerElement = {} nAtomsPerElement = {}
for v in self["names"]: for v in self["names"]:
if nAtomsPerElement.has_key(v): if nAtomsPerElement.has_key(v):
nAtomsPerElement[v] += 1 nAtomsPerElement[v] += 1
else: else:
nAtomsPerElement[v] = 1 nAtomsPerElement[v] = 1
return nAtomsPerElement return nAtomsPerElement
def get_indexes(self): def get_indexes(self):
indexesPerElement = {} indexesPerElement = {}
...@@ -139,9 +133,9 @@ class AtomSelectionConfigurator(IConfigurator): ...@@ -139,9 +133,9 @@ class AtomSelectionConfigurator(IConfigurator):
indexesPerElement[v].extend(self['indexes'][i]) indexesPerElement[v].extend(self['indexes'][i])
else: else:
indexesPerElement[v] = self['indexes'][i][:] indexesPerElement[v] = self['indexes'][i][:]
return indexesPerElement return indexesPerElement
def get_information(self): def get_information(self):
''' '''
Returns some informations the atom selection. Returns some informations the atom selection.
...@@ -152,11 +146,11 @@ class AtomSelectionConfigurator(IConfigurator): ...@@ -152,11 +146,11 @@ class AtomSelectionConfigurator(IConfigurator):
if not self.has_key("selection_length"): if not self.has_key("selection_length"):
return "Not configured yet\n" return "Not configured yet\n"
info = [] info = []
info.append("Number of selected atoms:%d" % self["selection_length"]) info.append("Number of selected atoms:%d" % self["selection_length"])
info.append("Selected elements:%s" % self["unique_names"]) info.append("Selected elements:%s" % self["unique_names"])
return "\n".join(info) return "\n".join(info)
REGISTRY["atom_selection"] = AtomSelectionConfigurator REGISTRY["atom_selection"] = AtomSelectionConfigurator
...@@ -121,7 +121,7 @@ class CoordinationNumber(DistanceHistogram): ...@@ -121,7 +121,7 @@ class CoordinationNumber(DistanceHistogram):
cBeta = self._concentrations[pair[1]] cBeta = self._concentrations[pair[1]]
invPair = pair[::-1] invPair = pair[::-1]
print pair, cnIntra
self._outputData["cn_intra_%s%s" % pair][:] = self.averageDensity*cBeta*cnIntra self._outputData["cn_intra_%s%s" % pair][:] = self.averageDensity*cBeta*cnIntra
self._outputData["cn_inter_%s%s" % pair][:] = self.averageDensity*cBeta*cnInter self._outputData["cn_inter_%s%s" % pair][:] = self.averageDensity*cBeta*cnInter
self._outputData["cn_total_%s%s" % pair][:] = self.averageDensity*cBeta*cnTotal self._outputData["cn_total_%s%s" % pair][:] = self.averageDensity*cBeta*cnTotal
......
#!python #!/usr/bin/env python
import cPickle import cPickle
import glob import glob
......
#!python #!/usr/bin/env python
if __name__ == "__main__": if __name__ == "__main__":
...@@ -6,4 +6,4 @@ if __name__ == "__main__": ...@@ -6,4 +6,4 @@ if __name__ == "__main__":
app = ElementsDatabaseEditorApp(None) app = ElementsDatabaseEditorApp(None)
app.MainLoop() app.MainLoop()
\ No newline at end of file
#!python #!/usr/bin/env python
if __name__ == "__main__": if __name__ == "__main__":
......
#!python #!/usr/bin/env python
if __name__ == "__main__": if __name__ == "__main__":
...@@ -6,4 +6,4 @@ if __name__ == "__main__": ...@@ -6,4 +6,4 @@ if __name__ == "__main__":
app = PeriodicTableViewerApp(None) app = PeriodicTableViewerApp(None)
app.MainLoop() app.MainLoop()
\ No newline at end of file
#!python #!/usr/bin/env python
if __name__ == "__main__": if __name__ == "__main__":
...@@ -6,4 +6,4 @@ if __name__ == "__main__": ...@@ -6,4 +6,4 @@ if __name__ == "__main__":
app = PlotterApp() app = PlotterApp()
app.MainLoop() app.MainLoop()
\ No newline at end of file
#!python #!/usr/bin/env python
if __name__ == "__main__": if __name__ == "__main__":
...@@ -6,4 +6,4 @@ if __name__ == "__main__": ...@@ -6,4 +6,4 @@ if __name__ == "__main__":
app = UserDefinitionViewerApp(None) app = UserDefinitionViewerApp(None)
app.MainLoop() app.MainLoop()
\ No newline at end of file
...@@ -38,10 +38,9 @@ class JobFileGenerator(): ...@@ -38,10 +38,9 @@ class JobFileGenerator():
# parameters (dict): optional. If not None, the parameters which the job file will be built with. # parameters (dict): optional. If not None, the parameters which the job file will be built with.
""" """
array_of_python_dependancies_string = ['unittest', 'numpy', 'os'] array_of_python_dependancies_string = ['unittest', 'numpy', 'os']
array_of_mdanse_dependancies_string = ['from Tests.UnitTests.UnitTest import UnitTest', array_of_mdanse_dependancies_string = ['from MDANSE import REGISTRY']
'from MDANSE import REGISTRY']
test_string = '' test_string = ''
test_string = test_string + 'class Test%s(UnitTest):\n\n' % self.job._type.upper() test_string = test_string + 'class Test%s(unittest.TestCase):\n\n' % self.job._type.upper()
test_string = test_string + ' def test(self):\n' test_string = test_string + ' def test(self):\n'
# Writes the line that will initialize the |parameters| dictionary and create the job # Writes the line that will initialize the |parameters| dictionary and create the job
if parameters is None: if parameters is None:
...@@ -56,14 +55,14 @@ class JobFileGenerator(): ...@@ -56,14 +55,14 @@ class JobFileGenerator():
# Launch the job in monoprocessor mode and copy output file # Launch the job in monoprocessor mode and copy output file
test_string = test_string + ' print "Launching job in monoprocessor mode"\n' test_string = test_string + ' print "Launching job in monoprocessor mode"\n'
test_string = test_string + ' parameters["running_mode"] = ("monoprocessor",1)\n' test_string = test_string + ' parameters["running_mode"] = ("monoprocessor",1)\n'
test_string = test_string + ' self.assertNotRaises(job.run, parameters, status=False)\n' test_string = test_string + ' job.run(parameters, status=False)\n'
test_string = test_string + ' shutil.copy(output_path + ".nc", reference_data_path + "_mono" + ".nc")\n' test_string = test_string + ' shutil.copy(output_path + ".nc", reference_data_path + "_mono" + ".nc")\n'
test_string = test_string + ' print "Monoprocessor execution completed"\n\n' test_string = test_string + ' print "Monoprocessor execution completed"\n\n'
# Launch the job in multiprocessor mode if avalaible # Launch the job in multiprocessor mode if avalaible
if self.multiprocessor: if self.multiprocessor:
test_string = test_string + ' print "Launching job in multiprocessor mode"\n' test_string = test_string + ' print "Launching job in multiprocessor mode"\n'
test_string = test_string + ' parameters["running_mode"] = ("multiprocessor",2)\n' test_string = test_string + ' parameters["running_mode"] = ("multiprocessor",2)\n'
test_string = test_string + ' self.assertNotRaises(job.run,parameters,False)\n' test_string = test_string + ' job.run(parameters,False)\n'
test_string = test_string + ' shutil.copy(output_path + ".nc", reference_data_path + "_multi" + ".nc")\n' test_string = test_string + ' shutil.copy(output_path + ".nc", reference_data_path + "_multi" + ".nc")\n'
test_string = test_string + ' print "Multiprocessor execution completed"\n\n' test_string = test_string + ' print "Multiprocessor execution completed"\n\n'
# Compare reference data with monoprocessor if reference data exists # Compare reference data with monoprocessor if reference data exists
......
...@@ -41,11 +41,10 @@ from MDANSE.Framework.Configurable import Configurable ...@@ -41,11 +41,10 @@ from MDANSE.Framework.Configurable import Configurable
from MDANSE.Framework.Configurators.IConfigurator import ConfiguratorError from MDANSE.Framework.Configurators.IConfigurator import ConfiguratorError
from MDANSE.Framework.Projectors.IProjector import ProjectorError from MDANSE.Framework.Projectors.IProjector import ProjectorError
from MDANSE.Framework.AtomSelectionParser import AtomSelectionParserError from MDANSE.Framework.AtomSelectionParser import AtomSelectionParserError
from UnitTest import UnitTest
TRAJECTORIES_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),"UserData","Trajectories") TRAJECTORIES_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),"UserData","Trajectories")
class TestConfigurator(UnitTest): class TestConfigurator(unittest.TestCase):
''' '''
Unittest for the configurators used to setup an analysis in MDANSE Unittest for the configurators used to setup an analysis in MDANSE
''' '''
...@@ -70,16 +69,16 @@ class TestConfigurator(UnitTest): ...@@ -70,16 +69,16 @@ class TestConfigurator(UnitTest):
# Case of a valid integer # Case of a valid integer
self._parameters["test_integer"] = 20 self._parameters["test_integer"] = 20
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
# Case of a float that will casted to an integer # Case of a float that will casted to an integer
self._parameters["test_integer"] = 20.2 self._parameters["test_integer"] = 20.2
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
self.assertEqual(self._configurable["test_integer"]["value"], 20) self.assertEqual(self._configurable["test_integer"]["value"], 20)
# Case of a string that can be casted to an integer # Case of a string that can be casted to an integer
self._parameters["test_integer"] = "30" self._parameters["test_integer"] = "30"
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
self.assertEqual(self._configurable["test_integer"]["value"], 30) self.assertEqual(self._configurable["test_integer"]["value"], 30)
# Case of a string that cannot be casted to an integer # Case of a string that cannot be casted to an integer
...@@ -99,17 +98,17 @@ class TestConfigurator(UnitTest): ...@@ -99,17 +98,17 @@ class TestConfigurator(UnitTest):
# Case of an integer that will be casted to a float # Case of an integer that will be casted to a float
self._parameters["test_float"] = 20 self._parameters["test_float"] = 20
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
self.assertEqual(self._configurable["test_float"]["value"], 20.0) self.assertEqual(self._configurable["test_float"]["value"], 20.0)
# Case of a float # Case of a float
self._parameters["test_float"] = 20.2 self._parameters["test_float"] = 20.2
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
self.assertEqual(self._configurable["test_float"]["value"], 20.2) self.assertEqual(self._configurable["test_float"]["value"], 20.2)
# Case of a string that can be casted to a float # Case of a string that can be casted to a float
self._parameters["test_float"] = "30.2" self._parameters["test_float"] = "30.2"
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
self.assertEqual(self._configurable["test_float"]["value"], 30.2) self.assertEqual(self._configurable["test_float"]["value"], 30.2)
# Case of a string that cannot be casted to a float # Case of a string that cannot be casted to a float
...@@ -129,7 +128,7 @@ class TestConfigurator(UnitTest): ...@@ -129,7 +128,7 @@ class TestConfigurator(UnitTest):
# Case of a valid trajectory # Case of a valid trajectory
self._parameters["trajectory"] = self._validTrajectory.filename self._parameters["trajectory"] = self._validTrajectory.filename
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
# Case of an unknown trajectory # Case of an unknown trajectory
self._parameters["trajectory"] = 'fsfsdjkfjkfjs' self._parameters["trajectory"] = 'fsfsdjkfjkfjs'
...@@ -162,12 +161,12 @@ class TestConfigurator(UnitTest): ...@@ -162,12 +161,12 @@ class TestConfigurator(UnitTest):
# No projection # No projection
self._parameters["projection"] = None self._parameters["projection"] = None
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
proj = self._configurable["projection"]['projector'](data) proj = self._configurable["projection"]['projector'](data)
self.assertTrue(numpy.array_equal(data,proj)) self.assertTrue(numpy.array_equal(data,proj))
self._parameters["projection"] = ('null',None) self._parameters["projection"] = ('null',None)
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
proj = self._configurable["projection"]['projector'](data) proj = self._configurable["projection"]['projector'](data)
self.assertTrue(numpy.array_equal(data,proj)) self.assertTrue(numpy.array_equal(data,proj))
...@@ -185,13 +184,13 @@ class TestConfigurator(UnitTest): ...@@ -185,13 +184,13 @@ class TestConfigurator(UnitTest):
# Axial projection # Axial projection
self._parameters["projection"] = ('axial',(1,0,0)) self._parameters["projection"] = ('axial',(1,0,0))
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
proj = self._configurable["projection"]['projector'](data) proj = self._configurable["projection"]['projector'](data)
self.assertTrue(numpy.array_equal(data[:,0],proj[:,0])) self.assertTrue(numpy.array_equal(data[:,0],proj[:,0]))
# Axial projection - wrong data # Axial projection - wrong data
self._parameters["projection"] = ('axial',(1,0,0)) self._parameters["projection"] = ('axial',(1,0,0))
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
self.assertRaises(ProjectorError, self._configurable["projection"]['projector'].__call__,None) self.assertRaises(ProjectorError, self._configurable["projection"]['projector'].__call__,None)
self.assertRaises(ProjectorError, self._configurable["projection"]['projector'].__call__,[1]) self.assertRaises(ProjectorError, self._configurable["projection"]['projector'].__call__,[1])
...@@ -209,7 +208,7 @@ class TestConfigurator(UnitTest): ...@@ -209,7 +208,7 @@ class TestConfigurator(UnitTest):
# Planar projection # Planar projection
self._parameters["projection"] = ('planar',(1,0,0)) self._parameters["projection"] = ('planar',(1,0,0))
self.assertNotRaises(self._configurable.setup,self._parameters) self._configurable.setup(self._parameters)
proj =