Commit 4bcdbbf9 authored by eric pellegrini's avatar eric pellegrini

Bug fix when using atom_transmutation configurator

Bug fix when grouping atom through grouping_level configurator
The grouping_level configurator depends now on atom_selection and
atom_transmutation configurator
The weight configurator depends now on atom_selection configurator
parent ccb98160
......@@ -77,7 +77,7 @@ class Configurable(object):
for name,(typ,kwds) in self.settings.items():
try:
self._configuration[name] = REGISTRY["configurator"][typ](name, **kwds)
self._configuration[name] = REGISTRY["configurator"][typ](self, name, **kwds)
# Any kind of error has to be caught
except:
raise ConfigurationError("Invalid type for %r configurator" % name)
......@@ -150,22 +150,22 @@ class Configurable(object):
continue
if conf.check_dependencies(configured):
conf.configure(self,parameters[name])
conf.configure(parameters[name])
self._configuration[name]=conf
self._info += conf.get_information()
configured.add(name)
progress = True
if not progress:
raise ConfigurationError("Circular or unsatisfiable dependencies when setting up configuration.")
self._configured=True
def __str__(self):
'''
Returns the informations about the current configuration in text form.
......
......@@ -44,17 +44,15 @@ class PartialChargeConfigurator(IConfigurator):
_default = ''
def configure(self, configuration, value):
def configure(self, 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
'''
trajConfig = configuration[self._dependencies['trajectory']]
trajConfig = self._configurable[self._dependencies['trajectory']]
if UD_STORE.has_definition(trajConfig["basename"],'partial_charges',value):
self.update(UD_STORE.get_definition(trajConfig["basename"],'partial_charges',value))
......
......@@ -45,7 +45,7 @@ class RangeConfigurator(IConfigurator):
_default = (0,10,1)
def __init__(self, name, valueType=int, includeLast=False, sort=False, toList=False, mini=None, maxi=None, **kwargs):
def __init__(self, configurable, name, valueType=int, includeLast=False, sort=False, toList=False, mini=None, maxi=None, **kwargs):
'''
Initializes the configurator.
......@@ -65,7 +65,7 @@ class RangeConfigurator(IConfigurator):
:type maxi: int, float or None
'''
IConfigurator.__init__(self, name, **kwargs)
IConfigurator.__init__(self, configurable, name, **kwargs)
self._valueType = valueType
......@@ -79,12 +79,10 @@ class RangeConfigurator(IConfigurator):
self._maxi = maxi
def configure(self, configuration, value):
def configure(self, value):
'''
Configure a range from its first, last and step values.
:param configuration: the current configuration
:type configuration: a MDANSE.Framework.Configurable.Configurable object
:param value: the first, last and step values used to generate the range.
:type value: 3-tuple
'''
......@@ -101,7 +99,7 @@ class RangeConfigurator(IConfigurator):
value = value[value >= self._mini]
if self._maxi is not None:
value = value[value <= self._maxi]
value = value[value < self._maxi]
if value.size == 0:
raise ConfiguratorError("the input range is empty." , self)
......
......@@ -72,8 +72,9 @@ class BoxCenteredTrajectory(IJob):
# Create a MMTK collection from the atoms selected for translation.
atoms = sorted_atoms(self.configuration['trajectory']['instance'].universe)
self._selectedAtoms = Collection([atoms[ind] for ind in self.configuration['atom_selection']['indexes']])
self._indexes = [idx for idxs in self.configuration['atom_selection']['indexes'] for idx in idxs]
self._selectedAtoms = Collection([atoms[idx] for idx in self._indexes])
# The output trajectory is opened for writing.
self._btt = Trajectory(self._selectedAtoms, self.configuration['output_files']['files'][0], "w")
self._btt.title = self.__class__.__name__
......@@ -117,7 +118,7 @@ class BoxCenteredTrajectory(IJob):
conf = Configuration(self._universe, self._universe._boxToRealPointArray(self._boxCoords))
# The universe is translated by the center of the selected atoms.
c = center(conf.array[self.configuration['atom_selection']['indexes'],:])
c = center(conf.array[self._indexes,:])
conf.array -= c
self._universe.setConfiguration(conf)
......
......@@ -56,9 +56,8 @@ class CenterOfMassesTrajectory(IJob):
settings = collections.OrderedDict()
settings['trajectory'] = ('mmtk_trajectory',{})
settings['frames'] = ('frames', {'dependencies':{'trajectory':'trajectory'}, 'default':(0,1,1)})
settings['atom_selection'] = ('atom_selection',{'dependencies':{'trajectory':'trajectory',
'grouping_level':'grouping_level'}})
settings['grouping_level'] = ('grouping_level',{})
settings['atom_selection'] = ('atom_selection',{'dependencies':{'trajectory':'trajectory'}})
settings['grouping_level']=('grouping_level',{"dependencies":{'trajectory':'trajectory','atom_selection':'atom_selection'}})
settings['output_files'] = ('output_files', {'formats':["netcdf"]})
def initialize(self):
......@@ -67,8 +66,8 @@ class CenterOfMassesTrajectory(IJob):
"""
self.numberOfSteps = self.configuration['frames']['number']
self._partition = partition_universe(self.configuration['trajectory']['instance'].universe,self.configuration['atom_selection']['groups'])
self._partition = partition_universe(self.configuration['trajectory']['instance'].universe,self.configuration['atom_selection']['indexes'])
self._newUniverse = copy.copy(self.configuration['trajectory']['instance'].universe)
......
......@@ -55,8 +55,7 @@ class CoordinationNumber(DistanceHistogram):
settings['frames'] = ('frames', {'dependencies':{'trajectory':'trajectory'}})
settings['r_values'] = ('range', {'valueType':float, 'includeLast':True, 'mini':0.0})
settings['atom_selection'] = ('atom_selection', {'dependencies':{'trajectory':'trajectory'}})
settings['transmutated_atoms'] = ('atom_transmutation', {'dependencies':{'trajectory':'trajectory',
'atom_selection':'atom_selection'}})
settings['atom_transmutation'] = ('atom_transmutation', {'dependencies':{'trajectory':'trajectory','atom_selection':'atom_selection'}})
settings['output_files'] = ('output_files', {'formats':["netcdf","ascii"]})
settings['running_mode'] = ('running_mode',{})
......@@ -94,12 +93,13 @@ class CoordinationNumber(DistanceHistogram):
for k in self._concentrations.keys():
self._concentrations[k] /= nFrames
for pair in self._elementsPairs:
ni = self.configuration['atom_selection']['n_atoms_per_element'][pair[0]]
nj = self.configuration['atom_selection']['n_atoms_per_element'][pair[1]]
nAtomsPerElement = self.configuration['atom_selection'].get_natoms()
for at1,at2 in self._elementsPairs:
ni = nAtomsPerElement[at1]
nj = nAtomsPerElement[at2]
idi = self.selectedElements.index(pair[0])
idj = self.selectedElements.index(pair[1])
idi = self.selectedElements.index(at1)
idj = self.selectedElements.index(at2)
if idi == idj:
nij = ni*(ni-1)/2.0
......
......@@ -67,7 +67,8 @@ class CroppedTrajectory(IJob):
atoms = sorted_atoms(self.configuration['trajectory']['instance'].universe)
# The collection of atoms corresponding to the atoms selected for output.
self._selectedAtoms = Collection([atoms[ind] for ind in self.configuration['atom_selection']['indexes']])
indexes = [idx for idxs in self.configuration['atom_selection']['indexes'] for idx in idxs]
self._selectedAtoms = Collection([atoms[ind] for ind in indexes])
# The output trajectory is opened for writing.
self._ct = Trajectory(self._selectedAtoms, self.configuration['output_files']['files'][0], "w")
......
......@@ -35,7 +35,6 @@ import itertools
import numpy
from MDANSE import ELEMENTS
from MDANSE.Framework.Jobs.IJob import IJob
from MDANSE.Mathematics.Arithmetic import weight
from MDANSE.Mathematics.Signal import correlation, normalize, get_spectrum
......@@ -65,9 +64,8 @@ class CurrentCorrelationFunction(IJob):
settings['q_vectors'] = ('q_vectors',{'dependencies':{'trajectory':'trajectory'}})
settings['atom_selection'] = ('atom_selection',{'dependencies':{'trajectory':'trajectory'}})
settings['normalize'] = ('boolean', {'default':False})
settings['transmutated_atoms'] = ('atom_transmutation',{'dependencies':{'trajectory':'trajectory',
'atom_selection':'atom_selection'}})
settings['weights'] = ('weights', {'default':'b_coherent'})
settings['atom_transmutation'] = ('atom_transmutation',{'dependencies':{'trajectory':'trajectory','atom_selection':'atom_selection'}})
settings['weights'] = ('weights', {'default':'b_coherent',"dependencies":{'trajectory':'trajectory','atom_selection':'atom_selection', 'atom_transmutation':'atom_transmutation'}})
settings['output_files'] = ('output_files', {'formats':["netcdf","ascii"]})
settings['running_mode'] = ('running_mode',{})
......@@ -91,8 +89,11 @@ class CurrentCorrelationFunction(IJob):
self._outputData.add("times","line", self.configuration['frames']['time'], units='ps')
self._outputData.add("frequency","line", self._instrResolution["frequencies"],units='THz')
self._elementsPairs = sorted(itertools.combinations_with_replacement(self.configuration['atom_selection']['contents'].keys(),2))
self._elements = self.configuration['atom_selection']['unique_names']
self._elementsPairs = sorted(itertools.combinations_with_replacement(self._elements,2))
self._indexesPerElement = self.configuration['atom_selection'].get_indexes()
for pair in self._elementsPairs:
self._outputData.add("j(q,t)_long_%s%s" % pair,"surface", (nQShells,self._nFrames), axis="q|times", units="au")
......@@ -115,7 +116,7 @@ class CurrentCorrelationFunction(IJob):
#. index (int): The index of the step.
#. rho (numpy.array): The exponential part of I(q,t)
"""
shell = self.configuration["q_vectors"]["shells"][index]
if not shell in self.configuration["q_vectors"]["value"]:
......@@ -139,7 +140,7 @@ class CurrentCorrelationFunction(IJob):
rhoTrans = {}
rhoLong_loop = {}
rhoTrans_loop = {}
for element in self.configuration['atom_selection']['contents'].keys():
for element in self._elements:
rho[element] = numpy.zeros((self._nFrames, 3, nQVectors), dtype = numpy.complex64)
rho_loop[element] = numpy.zeros((self._nFrames, 3, nQVectors), dtype = numpy.complex64)
rhoLong_loop[element] = numpy.zeros((self._nFrames, 3, nQVectors), dtype = numpy.complex64)
......@@ -150,7 +151,7 @@ class CurrentCorrelationFunction(IJob):
conf = traj.configuration[frame]
vel = traj.velocities[frame]
for element,idxs in self.configuration['atom_selection']['contents'].items():
for element,idxs in self._indexesPerElement.items():
selectedCoordinates = conf.array[idxs,:]
selectedVelocities = vel.array[idxs,:]
selectedVelocities = numpy.transpose(selectedVelocities)[:,:,numpy.newaxis]
......@@ -159,7 +160,7 @@ class CurrentCorrelationFunction(IJob):
Q2 = numpy.sum(qVectors**2,axis=0)
for element in self.configuration['atom_selection']['contents'].keys():
for element in self._elements:
qj = numpy.sum(rho[element]*qVectors,axis=1)
rhoLong[element] = (qj[:,numpy.newaxis,:]*qVectors[numpy.newaxis,:,:])/Q2
rhoTrans[element] = rho[element] - rhoLong[element]
......@@ -173,32 +174,34 @@ class CurrentCorrelationFunction(IJob):
#. index (int): The index of the step.\n
#. x (any): The returned result(s) of run_step
"""
if x is None:
return
jLong, jTrans = x
for pair in self._elementsPairs:
for at1,at2 in self._elementsPairs:
corrLong = numpy.zeros((self._nFrames,),dtype=numpy.float64)
corrTrans = numpy.zeros((self._nFrames,),dtype=numpy.float64)
for i in range(3):
corrLong += correlation(jLong[pair[0]][:,i,:],jLong[pair[1]][:,i,:], axis=0, average=1)
corrTrans += correlation(jTrans[pair[0]][:,i,:],jTrans[pair[1]][:,i,:], axis=0, average=1)
corrLong += correlation(jLong[at1][:,i,:],jLong[at2][:,i,:], axis=0, average=1)
corrTrans += correlation(jTrans[at1][:,i,:],jTrans[at2][:,i,:], axis=0, average=1)
self._outputData["j(q,t)_long_%s%s" % pair][index,:] += corrLong
self._outputData["j(q,t)_trans_%s%s" % pair][index,:] += corrTrans
self._outputData["j(q,t)_long_%s%s" % (at1,at2)][index,:] += corrLong
self._outputData["j(q,t)_trans_%s%s" % (at1,at2)][index,:] += corrTrans
def finalize(self):
"""
Finalizes the calculations (e.g. averaging the total term, output files creations ...)
"""
nAtomsPerElement = self.configuration['atom_selection'].get_natoms()
for pair in self._elementsPairs:
ni = self.configuration['atom_selection']['n_atoms_per_element'][pair[0]]
nj = self.configuration['atom_selection']['n_atoms_per_element'][pair[1]]
at1,at2 = pair
ni = nAtomsPerElement[at1]
nj = nAtomsPerElement[at2]
self._outputData["j(q,t)_long_%s%s" % pair][:] /= ni*nj
self._outputData["j(q,t)_trans_%s%s" % pair][:] /= ni*nj
self._outputData["J(q,f)_long_%s%s" % pair][:] = get_spectrum(self._outputData["j(q,t)_long_%s%s" % pair],
......@@ -215,22 +218,16 @@ class CurrentCorrelationFunction(IJob):
self._outputData["j(q,t)_long_%s%s" % pair] = normalize(self._outputData["j(q,t)_long_%s%s" % pair],axis=1)
self._outputData["j(q,t)_trans_%s%s" % pair] = normalize(self._outputData["j(q,t)_trans_%s%s" % pair],axis=1)
props = dict([[k,ELEMENTS[k,self.configuration["weights"]["property"]]] for k in self.configuration['atom_selection']['n_atoms_per_element'].keys()])
jqtLongTotal = weight(props,self._outputData,self.configuration['atom_selection']['n_atoms_per_element'],2,"j(q,t)_long_%s%s")
jqtLongTotal = weight(self.configuration["weights"].get_weights(),self._outputData,nAtomsPerElement,2,"j(q,t)_long_%s%s")
self._outputData["j(q,t)_long_total"][:] = jqtLongTotal
jqtTransTotal = weight(props,self._outputData,self.configuration['atom_selection']['n_atoms_per_element'],2,"j(q,t)_trans_%s%s")
jqtTransTotal = weight(self.configuration["weights"].get_weights(),self._outputData,nAtomsPerElement,2,"j(q,t)_trans_%s%s")
self._outputData["j(q,t)_trans_total"][:] = jqtTransTotal
sqfLongTotal = weight(props,
self._outputData,
self.configuration['atom_selection']['n_atoms_per_element'],
2,
"J(q,f)_long_%s%s")
sqfLongTotal = weight(self.configuration["weights"].get_weights(),self._outputData,nAtomsPerElement,2,"J(q,f)_long_%s%s")
self._outputData["J(q,f)_long_total"][:] = sqfLongTotal
sqfTransTotal = weight(props,self._outputData,self.configuration['atom_selection']['n_atoms_per_element'],2,"J(q,f)_trans_%s%s")
sqfTransTotal = weight(self.configuration["weights"].get_weights(),self._outputData,nAtomsPerElement,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._info)
......
......@@ -32,7 +32,6 @@ Created on Apr 10, 2015
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, get_spectrum
......@@ -56,17 +55,13 @@ class DensityOfStates(IJob):
settings = collections.OrderedDict()
settings['trajectory'] = ('mmtk_trajectory',{})
settings['frames'] = ('frames', {'dependencies':{'trajectory':'trajectory'}})
settings['instrument_resolution'] = ('instrument_resolution',{'dependencies':{'trajectory':'trajectory',
'frames' : 'frames'}})
settings['interpolation_order'] = ('interpolation_order', {'label':"velocities",
'dependencies':{'trajectory':'trajectory'}})
settings['instrument_resolution'] = ('instrument_resolution',{'dependencies':{'trajectory':'trajectory','frames' : 'frames'}})
settings['interpolation_order'] = ('interpolation_order', {'label':"velocities",'dependencies':{'trajectory':'trajectory'}})
settings['projection'] = ('projection', {'label':"project coordinates"})
settings['atom_selection'] = ('atom_selection',{'dependencies':{'trajectory':'trajectory',
'grouping_level':'grouping_level'}})
settings['grouping_level'] = ('grouping_level',{})
settings['atom_transmutation'] = ('atom_transmutation',{'dependencies':{'trajectory':'trajectory',
'atom_selection':'atom_selection'}})
settings['weights'] = ('weights',{})
settings['atom_selection'] = ('atom_selection',{'dependencies':{'trajectory':'trajectory'}})
settings['grouping_level']=('grouping_level',{"dependencies":{'trajectory':'trajectory','atom_selection':'atom_selection', 'atom_transmutation':'atom_transmutation'}})
settings['atom_transmutation'] = ('atom_transmutation',{'dependencies':{'trajectory':'trajectory','atom_selection':'atom_selection'}})
settings['weights']=('weights',{"dependencies":{"atom_selection":"atom_selection"}})
settings['output_files'] = ('output_files', {'formats':["netcdf","ascii"]})
settings['running_mode'] = ('running_mode',{})
......@@ -75,7 +70,7 @@ class DensityOfStates(IJob):
Initialize the input parameters and analysis self variables
"""
self.numberOfSteps = self.configuration['atom_selection']['n_groups']
self.numberOfSteps = self.configuration['atom_selection']['selection_length']
instrResolution = self.configuration["instrument_resolution"]
......@@ -85,7 +80,7 @@ class DensityOfStates(IJob):
self._outputData.add("frequency","line", instrResolution["frequencies"], units='THz')
self._outputData.add("frequency_window","line", instrResolution["frequency_window"], axis="frequency", units="au")
for element in self.configuration['atom_selection']['contents'].keys():
for element in self.configuration['atom_selection']['unique_names']:
self._outputData.add("vacf_%s" % element,"line", (self.configuration['frames']['number'],), axis="time", units="nm2/ps2")
self._outputData.add("dos_%s" % element,"line", (instrResolution['n_frequencies'],), axis="frequency", units="nm2/ps")
self._outputData.add("vacf_total","line", (self.configuration['frames']['number'],), axis="time", units="nm2/ps2")
......@@ -104,14 +99,16 @@ class DensityOfStates(IJob):
"""
# get atom index
indexes = self.configuration['atom_selection']["groups"][index]
indexes = self.configuration['atom_selection']["indexes"][index]
masses = self.configuration['atom_selection']["masses"][index]
series = read_atoms_trajectory(self.configuration["trajectory"]["instance"],
indexes,
first=self.configuration['frames']['first'],
last=self.configuration['frames']['last']+1,
step=self.configuration['frames']['step'],
variable=self.configuration['interpolation_order']["variable"])
variable=self.configuration['interpolation_order']["variable"],
weights=masses)
val = self.configuration["interpolation_order"]["value"]
......@@ -135,7 +132,7 @@ class DensityOfStates(IJob):
"""
# The symbol of the atom.
element = self.configuration['atom_selection']['elements'][index][0]
element = self.configuration['atom_selection']["names"][index]
self._outputData["vacf_%s" % element] += x
......@@ -143,27 +140,19 @@ class DensityOfStates(IJob):
"""
Finalizes the calculations (e.g. averaging the total term, output files creations ...).
"""
for element, number in self.configuration['atom_selection']['n_atoms_per_element'].items():
nAtomsPerElement = self.configuration['atom_selection'].get_natoms()
for element, number in nAtomsPerElement.items():
self._outputData["vacf_%s" % element][:] /= number
self._outputData["dos_%s" % element][:] = get_spectrum(self._outputData["vacf_%s" % element],
self.configuration["instrument_resolution"]["time_window"],
self.configuration["instrument_resolution"]["time_step"])
props = dict([[k,ELEMENTS[k,self.configuration["weights"]["property"]]] for k in self.configuration['atom_selection']['n_atoms_per_element'].keys()])
vacfTotal = weight(props,
self._outputData,
self.configuration['atom_selection']['n_atoms_per_element'],
1,
"vacf_%s")
weights = self.configuration["weights"].get_weights()
vacfTotal = weight(weights,self._outputData,nAtomsPerElement,1,"vacf_%s")
self._outputData["vacf_total"][:] = vacfTotal
dosTotal = weight(props,
self._outputData,
self.configuration['atom_selection']['n_atoms_per_element'],
1,
"dos_%s")
dosTotal = weight(weights,self._outputData,nAtomsPerElement,1,"dos_%s")
self._outputData["dos_total"][:] = dosTotal
self._outputData.write(self.configuration['output_files']['root'], self.configuration['output_files']['formats'], self._info)
......
......@@ -34,7 +34,6 @@ import collections
import numpy
from MDANSE import ELEMENTS
from MDANSE.Core.Error import Error
from MDANSE.Framework.Jobs.IJob import IJob
from MDANSE.Mathematics.Arithmetic import weight
......@@ -60,11 +59,10 @@ class DensityProfile(IJob):
settings['trajectory'] = ('mmtk_trajectory',{})
settings['frames'] = ('frames', {'dependencies':{'trajectory':'trajectory'}})
settings['atom_selection'] = ('atom_selection',{'dependencies':{'trajectory':'trajectory'}})
settings['transmutated_atoms'] = ('atom_transmutation',{'dependencies':{'trajectory':'trajectory',
'atom_selection':'atom_selection'}})
settings['atom_transmutation'] = ('atom_transmutation',{'dependencies':{'trajectory':'trajectory','atom_selection':'atom_selection'}})
settings['axis'] = ('single_choice', {'choices':['a','b','c'], 'default':'c'})
settings['dr'] = ('float', {'default':0.01, 'mini':1.0e-9})
settings['weights'] = ('weights',{})
settings['weights']=('weights',{"dependencies":{"atom_selection":"atom_selection"}})
settings['output_files'] = ('output_files', {'formats':["netcdf","ascii"]})
settings['running_mode'] = ('running_mode',{})
......@@ -87,7 +85,9 @@ class DensityProfile(IJob):
self._outputData.add('r',"line", (self._nBins,), units="nm")
for element in self.configuration['atom_selection']['contents'].keys():
self._indexesPerElement = self.configuration['atom_selection'].get_indexes()
for element in self._indexesPerElement.keys():
self._outputData.add("dp_%s" % element,"line", (self._nBins,), axis="r", units="au")
self._extent = 0.0
......@@ -117,7 +117,7 @@ class DensityProfile(IJob):
dpPerFrame = {}
for k,v in self.configuration['atom_selection']["contents"].iteritems():
for k,v in self._indexesPerElement.iteritems():
h = numpy.histogram(conf.array[v,self.configuration["axis"]["index"]],bins=self._nBins, range=[-0.5,0.5])
dpPerFrame[k] = h[0]
......@@ -142,16 +142,11 @@ class DensityProfile(IJob):
Finalize the job.
"""
for element in self.configuration['atom_selection']['contents'].keys():
nAtomsPerElement = self.configuration['atom_selection'].get_natoms()
for element in nAtomsPerElement.keys():
self._outputData["dp_%s" % element] += self.numberOfSteps
props = dict([[k,ELEMENTS[k,self.configuration["weights"]["property"]]] for k in self.configuration['atom_selection']['n_atoms_per_element'].keys()])
dpTotal = weight(props,
self._outputData,
self.configuration['atom_selection']['n_atoms_per_element'],
1,
"dp_%s")
dpTotal = weight(self.configuration["weights"].get_weights(),self._outputData,nAtomsPerElement,1,"dp_%s")
self._outputData.add("dp_total","line", dpTotal, axis="times", units="au")
......
......@@ -52,10 +52,8 @@ class DipoleAutoCorrelationFunction(IJob):
settings = collections.OrderedDict()
settings['trajectory'] = ('mmtk_trajectory',{})
settings['frames'] = ('frames', {'dependencies':{'trajectory':'trajectory'}})
settings['atom_selection'] = ('atom_selection',{'dependencies':{'trajectory':'trajectory'},
'default' : 'atom_index 0,1,2'})
settings['atom_charges'] = ('partial_charges',{'dependencies':{'trajectory':'trajectory'},
'default':{0:0.5,1:1.2,2:-0.2}})
settings['atom_selection'] = ('atom_selection',{'dependencies':{'trajectory':'trajectory'},'default' : 'atom_index 0,1,2'})
settings['atom_charges'] = ('partial_charges',{'dependencies':{'trajectory':'trajectory'},'default':{0:0.5,1:1.2,2:-0.2}})
settings['output_files'] = ('output_files', {'formats':["netcdf","ascii"]})
settings['running_mode'] = ('running_mode',{})
......@@ -76,7 +74,8 @@ class DipoleAutoCorrelationFunction(IJob):
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"]:
self._indexes = [idx for idxs in self.configuration['atom_selection']['indexes'] for idx in idxs]
for idx in self._indexes:
if not self.configuration["atom_charges"]["charges"].has_key(idx):
raise JobError(self,'Partial charge not defined for atom: %d' % idx)
......@@ -98,7 +97,7 @@ class DipoleAutoCorrelationFunction(IJob):
conf = self.configuration['trajectory']['instance'].universe.contiguousObjectConfiguration()
dipoleMoment = numpy.zeros((3,),dtype=numpy.float64)
for idx, in self.configuration['atom_selection']["groups"]:
for idx in self._indexes:
dipoleMoment += self.configuration["atom_charges"]["charges"][idx]*conf[idx]
return index, dipoleMoment
......
......@@ -52,8 +52,8 @@ class DistanceHistogram(IJob):
settings['frames'] = ('frames', {'dependencies':{'trajectory':'trajectory'}})
settings['r_values'] = ('range', {'valueType':float, 'includeLast':True, 'mini':0.0})
settings['atom_selection'] = ('atom_selection', {'dependencies':{'trajectory':'trajectory'}})
settings['transmutated_atoms'] = ('atom_transmutation', {'dependencies':{'trajectory':'trajectory','atom_selection':'atom_selection'}})
settings['weights'] = ('weights',{})
settings['atom_transmutation'] = ('atom_transmutation', {'dependencies':{'trajectory':'trajectory','atom_selection':'atom_selection'}})
settings['weights']=('weights',{"dependencies":{"atom_selection":"atom_selection"}})
settings['output_files'] = ('output_files', {'formats':["netcdf","ascii"]})
settings['running_mode'] = ('running_mode',{})
......@@ -63,16 +63,19 @@ class DistanceHistogram(IJob):
"""
self.numberOfSteps = self.configuration['frames']['number']
self._indexes = [idx for idxs in self.configuration['atom_selection']['indexes'] for idx in idxs]
self._indexes = numpy.array(self._indexes,dtype=numpy.int32)
self.selectedElements = self.configuration['atom_selection']['n_atoms_per_element'].keys()
self.indexToSymbol = numpy.array([self.selectedElements.index(self.configuration['atom_selection']['index_to_symbol'][i]) for i in self.configuration['atom_selection']['indexes']], dtype = numpy.int32)
self.selectedElements = self.configuration['atom_selection']['unique_names']
self.indexToSymbol = numpy.array([self.selectedElements.index(name) for name in self.configuration['atom_selection']['names']], dtype = numpy.int32)
lut = atomindex_to_moleculeindex(self.configuration['trajectory']['instance'].universe)
self.indexToMolecule = numpy.array([lut[i] for i in self.configuration['atom_selection']['indexes']], dtype=numpy.int32)
self.indexToMolecule = numpy.array([lut[i] for i in self._indexes], dtype=numpy.int32)
nElements = self.configuration['atom_selection']['n_selected_elements']
nElements = len(self.selectedElements)
# The histogram of the intramolecular distances.
self.hIntra = numpy.zeros((nElements,nElements,len(self.configuration['r_values']['mid_points'])),dtype=numpy.float64)
......@@ -80,15 +83,16 @@ class DistanceHistogram(IJob):
# The histogram of the intermolecular distances.
self.hInter = numpy.zeros((nElements,nElements,len(self.configuration['r_values']['mid_points'])),dtype=numpy.float64)
self.scaleconfig = numpy.zeros((self.configuration['atom_selection']['n_groups'],3), dtype=numpy.float64)
self.scaleconfig = numpy.zeros((self.configuration['atom_selection']['selection_length'],3), dtype=numpy.float64)
self.averageDensity = 0.0
self._nAtomsPerElement = self.configuration['atom_selection'].get_natoms()
self._concentrations = {}
for k in self.configuration['atom_selection']['n_atoms_per_element'].keys():
for k in self._nAtomsPerElement.keys():
self._concentrations[k] = 0.0
self._elementsPairs = sorted(itertools.combinations_with_replacement(self.configuration['atom_selection']['contents'].keys(),2))
self._elementsPairs = sorted(itertools.combinations_with_replacement(self.selectedElements,2))
if not self.configuration['trajectory']['instance'].universe.is_periodic:
raise Error("Pair distribution function cannot be calculated for infinite universe trajectories")
......@@ -106,6 +110,7 @@ class DistanceHistogram(IJob):
#. hInterTemp (np.array): The calculated distance inter-molecular histogram
"""
# get the Frame index
frameIndex = self.configuration['frames']['value'][index]
......@@ -121,12 +126,10 @@ class DistanceHistogram(IJob):
hIntraTemp = numpy.zeros(self.hIntra.shape, dtype=numpy.float64)
hInterTemp = numpy.zeros(self.hInter.shape, dtype=numpy.float64)
indexes = numpy.array(self.configuration['atom_selection']['indexes'],dtype=numpy.int32)
distance_histogram.distance_histogram(universe.configuration().array[indexes,:],
distance_histogram.distance_histogram(universe.configuration().array[self._indexes,:],
directCell,
reverseCell,
indexes,
self._indexes,
self.indexToMolecule,
self.indexToSymbol,
hIntraTemp,
......@@ -158,6 +161,6 @@ class DistanceHistogram(IJob):
self.hIntra += x[1]
self.hInter += x[2]
for k,v in self.configuration['atom_selection']['n_atoms_per_element'].items():
for k,v in self._nAtomsPerElement.items():
self._concentrations[k] += float(v)/nAtoms
\ No newline at end of file
......@@ -35,7 +35,6 @@ import itertools
import numpy
from MDANSE import ELEMENTS
from MDANSE.Core.Error import Error
from MDANSE.Framework.Jobs.IJob import IJob
from MDANSE.Mathematics.Arithmetic import weight
......@@ -62,13 +61,11 @@ class DynamicCoherentStructureFactor(IJob):
settings = collections.OrderedDict()
settings['trajectory'] = ('mmtk_trajectory',{})
settings['frames'] = ('frames', {'dependencies':{'trajectory':'trajectory'}})
settings['instrument_resolution'] = ('instrument_resolution',{'dependencies':{'trajectory':'trajectory',
'frames' : 'frames'}})
settings['instrument_resolution'] = ('instrument_resolution',{'dependencies':{'trajectory':'trajectory','frames' : 'frames'}})
settings['q_vectors'] = ('q_vectors',{'dependencies':{'trajectory':'trajectory'}})
settings['atom_selection'] = ('atom_selection', {'dependencies':{'trajectory':'trajectory'}})
settings['transmutated_atoms'] = ('atom_transmutation', {'dependencies':{'trajectory':'trajectory',
'atom_selection':'atom_selection'}})
settings['weights'] = ('weights', {'default':'b_coherent'})
settings['atom_transmutation'] = ('atom_transmutation', {'dependencies':{'trajectory':'trajectory','atom_selection':'atom_selection'}})
settings['weights'] = ('weights', {'default':'b_coherent',"dependencies":{'trajectory':'trajectory','atom_selection':'atom_selection', 'atom_transmutation':'atom_transmutation'}})
settings['output_files'] = ('output_files', {'formats':["netcdf","ascii"]})
settings['running_mode'] = ('running_mode',{})
......@@ -78,10 +75,10 @@ class DynamicCoherentStructureFactor(IJob):
"""
if not self.configuration['trajectory']['instance'].universe.is_periodic:
raise DynamicCoherentStructureFactorError('Cannot start %s analysis on non-periodic system'%self.label)
raise DynamicCoherentStructureFactorError('Cannot start %s analysis on non-periodic system' % self.label)
if not self.configuration['q_vectors']['is_lattice']:
raise DynamicCoherentStructureFactorError('The Q vectors must be generated on a lattice to run %s analysis'%self.label)
raise DynamicCoherentStructureFactorError('The Q vectors must be generated on a lattice to run %s analysis' % self.label)