Pass serialization as parameter attribute

Changes the implementation of the serialization to be on an attribute of
the source XML element within settings.xml. This removes the need for a
new file containing the serialization.
Parameters are provided as a key-value string, separated by a comma and
a space, although the implementation can change this is required.
Change example values to align with existing custom_source to make
comparisons easier.
Update documentation to be consistent.
This commit is contained in:
Dan Short 2020-08-03 14:24:17 +01:00
parent 1de3d9ddf9
commit 8bb10563c1
11 changed files with 84 additions and 92 deletions

View file

@ -22,8 +22,8 @@ class Source:
Source file from which sites should be sampled
library : str
Path to a custom source library
serialization : str
Path to the serialized representation of the custom source
parameters : str
Parameters to be provided to the custom source
.. versionadded:: 0.12
strength : float
@ -43,8 +43,8 @@ class Source:
Source file from which sites should be sampled
library : str or None
Path to a custom source library
serialization : str
Path to the serialized representation of the custom source
parameters : str
Parameters to be provided to the custom source
strength : float
Strength of the source
particle : {'neutron', 'photon'}
@ -53,13 +53,13 @@ class Source:
"""
def __init__(self, space=None, angle=None, energy=None, filename=None,
library=None, serialization=None, strength=1.0, particle='neutron'):
library=None, parameters=None, strength=1.0, particle='neutron'):
self._space = None
self._angle = None
self._energy = None
self._file = None
self._library = None
self._serialization = None
self._parameters = None
if space is not None:
self.space = space
@ -71,8 +71,8 @@ class Source:
self.file = filename
if library is not None:
self.library = library
if serialization is not None:
self.serialization = serialization
if parameters is not None:
self.parameters = parameters
self.strength = strength
self.particle = particle
@ -85,8 +85,8 @@ class Source:
return self._library
@property
def serialization(self):
return self._serialization
def parameters(self):
return self._parameters
@property
def space(self):
@ -118,10 +118,10 @@ class Source:
cv.check_type('library', library_name, str)
self._library = library_name
@serialization.setter
def serialization(self, serialization_path):
cv.check_type('serialization', serialization_path, str)
self._serialization = serialization_path
@parameters.setter
def parameters(self, parameters_path):
cv.check_type('parameters', parameters_path, str)
self._parameters = parameters_path
@space.setter
def space(self, space):
@ -166,8 +166,8 @@ class Source:
element.set("file", self.file)
if self.library is not None:
element.set("library", self.library)
if self.serialization is not None:
element.set("serialization", self.serialization)
if self.parameters is not None:
element.set("parameters", self.parameters)
if self.space is not None:
element.append(self.space.to_xml_element())
if self.angle is not None:
@ -209,9 +209,9 @@ class Source:
if library is not None:
source.library = library
serialization = get_text(elem, 'serialization')
if serialization is not None:
source.serialization = serialization
parameters = get_text(elem, 'parameters')
if parameters is not None:
source.parameters = parameters
space = elem.find('space')
if space is not None: