Commit 8d3fb9a6 authored by eric pellegrini's avatar eric pellegrini

Bug fix related to change of variable name for all analysis

Improved the generic converter
Reintroduced and refactored rigid-body trajectory analysis
Implemented the dipole autocorrelation function analysis
parent 7bd2071e
#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 Jun 9, 2015
@author: Eric C. Pellegrini
'''
from Scientific.IO.NetCDF import NetCDFFile
from MDANSE.Framework.Configurators.IConfigurator import ConfiguratorError
from MDANSE.Framework.Configurators.InputFileConfigurator import InputFileConfigurator
class PythonScriptConfigurator(InputFileConfigurator):
"""
This configurator allows to input a Python script.
"""
type = 'python_script'
_default = ''
def __init__(self, name, variables=None, **kwargs):
'''
Initializes the configurator.
:param name: the name of the configurator as it will appear in the configuration.
:type name: str
:param variables: the list of NetCDF variables that must be present in the input NetCDF file or None if there is no compulsory variable.
:type variables: list of str or None
'''
# The base class constructor.
InputFileConfigurator.__init__(self, name, **kwargs)
self._variables = variables if variables is not None else []
def configure(self, configuration, value):
'''
Configure a python script.
:param configuration: the current configuration.
:type configuration: a MDANSE.Framework.Configurable.Configurable object
:param value: the path for the python script.
:type value: str
'''
InputFileConfigurator.configure(self, configuration, value)
namespace = {}
execfile(value,self.__dict__,namespace)
for v in self._variables:
if not namespace.has_key(v):
raise ConfiguratorError("The variable %r is not defined in the %r python script file" % (v,self["value"]))
self.update(namespace)
@property
def variables(self):
'''
Returns the list of NetCDF variables that must be present in the NetCDF file.
:return: the list of NetCDF variables that must be present in the NetCDF file.
:rtype: list of str
'''
return self._variables
def get_information(self):
'''
Returns some basic informations about the contents of the MMTK trajectory file.
:return: the informations about the contents of the MMTK trajectory file.
:rtype: str
'''
info = ["NetCDF input file: %r" % self["value"]]
if self.has_key('instance'):
info.append("Contains the following variables:")
for v in self['instance'].variables:
info.append(v)
return "\n".join(info)
\ No newline at end of file
......@@ -148,6 +148,6 @@ class AngularCorrelation(IJob):
self._outputData['ac'] /= self.configuration['axis_selection']['n_axis']
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -125,5 +125,5 @@ class AreaPerMolecule(IJob):
Finalize the analysis (close trajectory, write output data ...)
"""
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
This diff is collapsed.
......@@ -129,7 +129,7 @@ class CoordinationNumber(DistanceHistogram):
self._outputData["cn_inter_%s%s" % invPair][:] = self.averageDensity*cAlpha*cnInter
self._outputData["cn_total_%s%s" % invPair][:] = self.averageDensity*cAlpha*cnTotal
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......
......@@ -235,6 +235,6 @@ class CurrentCorrelationFunction(IJob):
sqfTransTotal = weight(props,self._outputData,self.configuration['atom_selection']['n_atoms_per_element'],2,"J(q,f)_trans_%s%s")
self._outputData["J(q,f)_trans_total"][:] = sqfTransTotal
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -112,6 +112,6 @@ class Density(IJob):
Finalize the job.
"""
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -166,6 +166,6 @@ class DensityOfStates(IJob):
"dos_%s")
self._outputData["dos_total"][:] = dosTotal
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......@@ -160,6 +160,6 @@ class DensityProfile(IJob):
rValues = self._extent*numpy.linspace(0,1,self._nBins+1)
self._outputData["r"][:] = (rValues[1:]+rValues[:-1])/2
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#71 avenue des Martyrs
#38000 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 Jun 9, 2015
@author: Bachir Aoun and Eric C. Pellegrini
'''
import collections
import numpy
from MDANSE.Framework.Jobs.IJob import IJob, JobError
from MDANSE.Mathematics.Signal import correlation
class DipoleAutoCorrelationFunction(IJob):
"""
"""
type = 'dacf'
label = "Dipole AutoCorrelation Function"
category = ('Infrared',)
ancestor = "mmtk_trajectory"
settings = collections.OrderedDict()
settings['trajectory'] = ('mmtk_trajectory',{})
settings['frames'] = ('frames', {'dependencies':{'trajectory':'trajectory'}})
settings['atom_selection'] = ('atom_selection',{'dependencies':{'trajectory':'trajectory'}})
settings['atom_charges'] = ('python_script',{'variables':['charges']})
settings['output_files'] = ('output_files', {'formats':["netcdf","ascii"]})
settings['running_mode'] = ('running_mode',{})
def initialize(self):
"""
Initialize the input parameters and analysis self variables
"""
self.numberOfSteps = self.configuration['frames']['number']
# Will store the time.
self._outputData.add("time","line", self.configuration['frames']['time'], units='ps')
self._dipoleMoments = numpy.zeros((self.configuration['frames']['number'],3),dtype=numpy.float64)
self._outputData.add("dacf","line", (self.configuration['frames']['number'],), axis="time")
if not isinstance(self.configuration["atom_charges"]["charges"],dict):
raise JobError(self,'Invalid type for partial charges. Must be a dictionary that maps atom index to to partial charge.')
for idx, in self.configuration['atom_selection']["groups"]:
if not self.configuration["atom_charges"]["charges"].has_key(idx):
raise JobError(self,'Partial charge not defined for atom: %d' % idx)
def run_step(self, index):
"""
Runs a single step of the job.\n
:Parameters:
#. index (int): The index of the step.
:Returns:
#. index (int): The index of the step.
#. dipolarAC (numpy.array): The calculated dipolar auto-correlation function for atom of index=index
"""
# get the Frame index
frameIndex = self.configuration['frames']['value'][index]
self.configuration['trajectory']['instance'].universe.setFromTrajectory(self.configuration['trajectory']['instance'], frameIndex)
conf = self.configuration['trajectory']['instance'].universe.contiguousObjectConfiguration()
dipoleMoment = numpy.zeros((3,),dtype=numpy.float64)
for idx, in self.configuration['atom_selection']["groups"]:
dipoleMoment += self.configuration["atom_charges"]["charges"][idx]*conf[idx]
return index, dipoleMoment
def combine(self, index, x):
"""
Combines returned results of run_step.\n
:Parameters:
#. index (int): The index of the step.\n
#. x (any): The returned result(s) of run_step
"""
self._dipoleMoments[index] = x
def finalize(self):
"""
Finalizes the calculations (e.g. averaging the total term, output files creations ...).
"""
self._outputData["dacf"][:] = correlation(self._dipoleMoments,axis=0,average=1)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -188,7 +188,7 @@ class DynamicCoherentStructureFactor(IJob):
sqfTotal = weight(props,self._outputData,self.configuration['atom_selection']['n_atoms_per_element'],2,"s(q,f)_%s%s")
self._outputData["s(q,f)_total"][:] = sqfTotal
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......@@ -168,6 +168,6 @@ class DynamicIncoherentStructureFactor(IJob):
self._outputData["s(q,f)_total"][:] = weight(props,self._outputData,self.configuration['atom_selection']['n_atoms_per_element'],1,"s(q,f)_%s")
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -218,6 +218,6 @@ class Eccentricity(IJob):
"""
# Write the output variables.
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -152,6 +152,6 @@ class ElasticIncoherentStructureFactor(IJob):
self._outputData["eisf_total"][:] = weight(props,self._outputData,self.configuration['atom_selection']['n_atoms_per_element'],1,"eisf_%s")
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -169,6 +169,6 @@ class GaussianDynamicIncoherentStructureFactor(IJob):
self._outputData["s(q,f)_total"][:] = weight(props,self._outputData,self.configuration['atom_selection']['n_atoms_per_element'],1,"s(q,f)_%s")
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -145,6 +145,6 @@ class GeneralAutoCorrelationFunction(IJob):
self._outputData["gacf_total"][:] = gacfTotal
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -62,7 +62,7 @@ class JobError(Error):
trace = []
tback = traceback.extract_stack()
for tb in tback:
trace.append(' -- '.join([str(t) for t in tb]))
......@@ -479,7 +479,8 @@ class IJob(Configurable):
if self._status is not None:
self._status.finish()
except:
raise JobError(self)
tb = traceback.format_exc()
raise JobError(self,tb)
@property
def info(self):
......
......@@ -233,7 +233,7 @@ class McStasVirtualInstrument(IJob):
# Convert McStas output files into NetCDF format
self.convert(self.configuration["options"]["mcstas_output_directory"])
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
def treat_str_var(self, s):
return s.strip().replace(' ', '_')
......
......@@ -157,7 +157,7 @@ class MolecularTrace(IJob):
self._outputData['molecular_trace'][:] = self.grid
# Write the output variables.
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......@@ -220,6 +220,6 @@ class OrderParameter(IJob):
self._outputData['p1'] /= self._nAxis
self._outputData['p2'] /= self._nAxis
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......@@ -130,7 +130,7 @@ class PairDistributionFunction(DistanceHistogram):
"pdf_total_%s%s")
self._outputData["pdf_total"][:] = pdfTotal
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......
......@@ -145,7 +145,7 @@ class PositionAutoCorrelationFunction(IJob):
self._outputData.add("pacf_total","line", pacfTotal, axis="time", units="nm2")
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......
......@@ -116,7 +116,7 @@ class RadiusOfGyration(IJob):
Finalizes the calculations (e.g. averaging the total term, output files creations ...).
"""
# Write the output variables.
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......
This diff is collapsed.
......@@ -137,7 +137,7 @@ class RootMeanSquareDeviation(IJob):
# Write the output variables.
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......
......@@ -114,6 +114,6 @@ class RootMeanSquareFluctuation(IJob):
"""
# Write the output variables.
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -149,6 +149,6 @@ class SolventAccessibleSurface(IJob):
self._outputData['sas'] *= self.solidAngleIncr
# Write the output variables.
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -187,6 +187,6 @@ class SpatialDensity(IJob):
self._outputData.add("inter_spatial_density","volume",self.hist)
# Write the output variables.
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -142,6 +142,6 @@ class StaticStructureFactor(DistanceHistogram):
self._outputData["ssf_total"][:] = ssfIntra + ssfInter
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ No newline at end of file
......@@ -114,6 +114,6 @@ class StructureFactorFromScatteringFunction(IJob):
Finalizes the calculations (e.g. averaging the total term, output files creations ...).
"""
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['netcdf_input_file']['instance'].close()
......@@ -133,7 +133,7 @@ class Temperature(IJob):
self._outputData['temperature'][:] = 2.0*Units.eV*self._outputData['kinetic_energy']/fact
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......
......@@ -133,7 +133,7 @@ class VelocityAutoCorrelationFunction(IJob):
series = self.configuration['projection']["projector"](series)
atomicVACF = correlation(series,axis=0,reduce=1)
atomicVACF = correlation(series,axis=0,average=1)
return index, atomicVACF
......@@ -150,8 +150,7 @@ class VelocityAutoCorrelationFunction(IJob):
element = self.configuration['atom_selection']['elements'][index][0]
self._outputData["vacf_%s" % element] += x
def finalize(self):
"""
Finalizes the calculations (e.g. averaging the total term, output files creations ...).
......@@ -174,7 +173,7 @@ class VelocityAutoCorrelationFunction(IJob):
"vacf_%s")
self._outputData["vacf_total"][:] = vacfTotal
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......
......@@ -202,7 +202,7 @@ class Voronoi(IJob):
self._outputData.add('neighbourhood_histogram',"line", self.neighbourhood, units="au")
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
......@@ -151,6 +151,6 @@ class StaticStructureFactor(DistanceHistogram):
self._outputData["xssf_total"][:] = xssfIntra + xssfInter
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self.header)
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
self.configuration['trajectory']['instance'].close()
\ 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