Add a serialization attribute to Source

Adds serialization as an optional attribute to Source objects.
This attribute represents the path to the file containing the serialized
representation of the source.
This commit is contained in:
Dan Short 2020-07-31 10:26:33 +01:00
parent 51424d27b7
commit 61cf4f71a9

View file

@ -22,6 +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
.. versionadded:: 0.12
strength : float
@ -41,6 +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
strength : float
Strength of the source
particle : {'neutron', 'photon'}
@ -49,12 +53,13 @@ class Source:
"""
def __init__(self, space=None, angle=None, energy=None, filename=None,
library=None, strength=1.0, particle='neutron'):
library=None, serialization=None, strength=1.0, particle='neutron'):
self._space = None
self._angle = None
self._energy = None
self._file = None
self._library = None
self._serialization = None
if space is not None:
self.space = space
@ -66,6 +71,8 @@ class Source:
self.file = filename
if library is not None:
self.library = library
if serialization is not None:
self.serialization = serialization
self.strength = strength
self.particle = particle
@ -77,6 +84,10 @@ class Source:
def library(self):
return self._library
@property
def serialization(self):
return self._serialization
@property
def space(self):
return self._space
@ -107,6 +118,11 @@ 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
@space.setter
def space(self, space):
cv.check_type('spatial distribution', space, Spatial)
@ -150,6 +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.space is not None:
element.append(self.space.to_xml_element())
if self.angle is not None:
@ -191,6 +209,10 @@ class Source:
if library is not None:
source.library = library
serialization = get_text(elem, 'serialization')
if serialization is not None:
source.serialization = serialization
space = elem.find('space')
if space is not None:
source.space = Spatial.from_xml_element(space)