"""Simple input class to describe output for properties.
Storage class for PropertyOutput.
Attributes:
filename: The name of the file to output to.
stride: The number of steps that should be taken between outputting the
data to file.
flush: An integer describing how often the output streams are flushed,
so that it doesn't wait for the buffer to fill before outputting to
file.
"""
default_help="""This class deals with the output of properties to one file. Between each property tag there should be an array of strings, each of which specifies one property to be output."""
"help":"A string to specify the name of the file that is output. The file name is given by 'prefix'.'filename' + format_specifier. The format specifier may also include a number if multiple similar files are output."})
raiseValueError("The stride length for the properties file output must be positive.")
classInputTrajectory(InputValue):
"""Simple input class to describe output for trajectories.
Storage class for TrajectoryOutput.
Attributes:
filename: The (base) name of the file to output to.
stride: The number of steps that should be taken between outputting the
data to file.
format: The format of the trajectory output file.
cell_units: The units that the cell parameters are given in.
bead: If the trajectory is a per-bead property, this can be used to
specify a single bead to output. If negative, it defaults to
the centroid.
flush: An integer describing how often the output streams are flushed,
so that it doesn't wait for the buffer to fill before outputting to
file.
"""
default_help="""This class defines how one trajectory file should be output. Between each trajectory tag one string should be given, which specifies what data is to be output."""
"help":"A string to specify the name of the file that is output. The file name is given by 'prefix'.'filename' + format_specifier. The format specifier may also include a number if multiple similar files are output."})
raiseValueError("The stride length for the trajectory file output must be positive.")
classInputCheckpoint(InputValue):
"""Simple input class to describe output for properties.
Storage class for CheckpointOutput.
Attributes:
filename: The (base) name of the file to output to.
stride: The number of steps that should be taken between outputting the
data to file.
overwrite: whether checkpoints should be overwritten, or multiple
files output.
"""
default_help="""This class defines how a checkpoint file should be output. Optionally, between the checkpoint tags, you can specify one integer giving the current step of the simulation. By default this integer will be zero."""
"help":"A string to specify the name of the file that is output. The file name is given by 'prefix'.'filename' + format_specifier. The format specifier may also include a number if multiple similar files are output."})
"""Overwrites the standard parse function so that we can specify this tag
in the input without any data.
We can use the syntax <checkpoint /> to do this
Args:
xml: An xml node containing all the data for the parent tag.
text: The data to read the data from. Will be None if we have not
specified any data.
"""
# just a quick hack to allow an empty element
try:
super(InputCheckpoint,self).parse(xml,text)
except:#TODO make this except a specific exception, not every one
self.value=0#This could hide actual errors, at least in theory.
defstore(self,chk):
"""Stores a CheckpointOutput object."""
super(InputCheckpoint,self).store(chk.step)
self.stride.store(chk.stride)
self.filename.store(chk.filename)
self.overwrite.store(chk.overwrite)
defcheck(self):
"""Checks for optional parameters."""
super(InputCheckpoint,self).check()
ifself.stride.fetch()<0:
raiseValueError("The stride length for the checkpoint file output must be positive.")
classInputOutputs(Input):
""" List of outputs input class.
An example of a dynamic input class: a variable number of tags might be
present, corresponding to different output requests. This allows for
instance to print multiple property outputs, with different content
and/or output frequency.
Attributes:
prefix: A string that will be appended to all output files from this
simulation.
Dynamic fields:
trajectory: Specifies a trajectory to be output
properties: Specifies some properties to be output.
checkpoint: Specifies a checkpoint file to be output.
"""
attribs={"prefix":(InputAttribute,{"dtype":str,
"default":"i-pi",
"help":"A string that will be prepended to each output file name. The file name is given by 'prefix'.'filename' + format_specifier. The format specifier may also include a number if multiple similar files are output."})
}
dynamic={"properties":(InputProperties,{"help":"Each of the properties tags specify how to create a file in which one or more properties are written, one line per frame. "}),
"trajectory":(InputTrajectory,{"help":"Each of the trajectory tags specify how to create a trajectory file, containing a list of per-atom coordinate properties. "}),
"checkpoint":(InputCheckpoint,{"help":"Each of the checkpoint tags specify how to create a checkpoint file, which can be used to restart a simulation. "}),
}
default_help="""This class defines how properties, trajectories and checkpoints should be output during the simulation. May contain zero, one or many instances of properties, trajectory or checkpoint tags, each giving instructions on how one output file should be created and managed."""
default_label="OUTPUTS"
@classmethod
defmake_default(cls):
"""Used to make the default value of the outputs class for use when no
output is specified.
Needed since this is a fairly complicated default, with many mutable
objects, and the default has to be generated by a function that does not