def write(state, filename, filter=All(), mode='wb', log=None): """Write the given simulation state out to a GSD file. Args: state (State): Simulation state. filename (str): File name to write. filter (`hoomd.filter.ParticleFilter`): Select the particles to write. mode (str): The file open mode. Defaults to ``'wb'``. log (`hoomd.logging.Logger`): Provide log quantities to write. The valid file modes for `write` are ``'wb'`` and ``'xb'``. """ if mode != 'wb' and mode != 'xb': raise ValueError(f"Invalid GSD.write file mode: {mode}") writer = _hoomd.GSDDumpWriter(state._cpp_sys_def, filename, state._get_group(filter), mode, False) if state._simulation._system_communicator is not None: writer.setCommunicator(state._simulation._system_communicator) if log is not None: writer.log_writer = _GSDLogWriter(log) writer.analyze(state._simulation.timestep)
def __init__(self, filename, period, group, overwrite=False, truncate=False, phase=0, time_step=None, dynamic=None): categories = ['attribute', 'property', 'momentum', 'topology'] dynamic_quantities = ['property'] if dynamic is not None: for v in dynamic: if v not in categories: hoomd.context.current.device.cpp_msg.warning( "dump.gsd: dynamic quantity " + v + " is not recognized\n") dynamic_quantities = ['property'] + dynamic # initialize base class hoomd.analyze._analyzer.__init__(self) self.cpp_analyzer = _hoomd.GSDDumpWriter( hoomd.context.current.system_definition, filename, group.cpp_group, overwrite, truncate) self.cpp_analyzer.setWriteAttribute('attribute' in dynamic_quantities) self.cpp_analyzer.setWriteProperty('property' in dynamic_quantities) self.cpp_analyzer.setWriteMomentum('momentum' in dynamic_quantities) self.cpp_analyzer.setWriteTopology('topology' in dynamic_quantities) if period is not None: self.setupAnalyzer(period, phase) else: if time_step is None: time_step = hoomd.context.current.system.getCurrentTimeStep() self.cpp_analyzer.analyze(time_step) # store metadata self.filename = filename self.period = period self.group = group self.phase = phase self.metadata_fields = ['filename', 'period', 'group', 'phase']
def __init__(self, filename, period, group, overwrite=False, truncate=False, phase=0, time_step=None, static=['attribute', 'momentum', 'topology']): hoomd.util.print_status_line() for v in static: if v not in ['attribute', 'property', 'momentum', 'topology']: hoomd.context.msg.warning("dump.gsd: static quantity", v, "is not recognized") # initialize base class hoomd.analyze._analyzer.__init__(self) self.cpp_analyzer = _hoomd.GSDDumpWriter( hoomd.context.current.system_definition, filename, group.cpp_group, overwrite, truncate) self.cpp_analyzer.setWriteAttribute('attribute' not in static) self.cpp_analyzer.setWriteProperty('property' not in static) self.cpp_analyzer.setWriteMomentum('momentum' not in static) self.cpp_analyzer.setWriteTopology('topology' not in static) if period is not None: self.setupAnalyzer(period, phase) else: if time_step is None: time_step = hoomd.context.current.system.getCurrentTimeStep() self.cpp_analyzer.analyze(time_step) # store metadata self.filename = filename self.period = period self.group = group self.phase = phase self.metadata_fields = ['filename', 'period', 'group', 'phase']
def _attach(self): # validate dynamic property categories = ['attribute', 'property', 'momentum', 'topology'] dynamic_quantities = ['property'] if self.dynamic is not None: for v in self.dynamic: if v not in categories: raise RuntimeError( f"GSD: dynamic quantity {v} is not valid") dynamic_quantities = ['property'] + self.dynamic self._cpp_obj = _hoomd.GSDDumpWriter( self._simulation.state._cpp_sys_def, self.filename, self._simulation.state._get_group(self.filter), self.mode, self.truncate) self._cpp_obj.setWriteAttribute('attribute' in dynamic_quantities) self._cpp_obj.setWriteProperty('property' in dynamic_quantities) self._cpp_obj.setWriteMomentum('momentum' in dynamic_quantities) self._cpp_obj.setWriteTopology('topology' in dynamic_quantities) self._cpp_obj.log_writer = self.log super()._attach()
def __init__(self, filename, period, group, overwrite=False, truncate=False, phase=0, time_step=None, static=None, dynamic=None): hoomd.util.print_status_line() if static is not None and dynamic is not None: raise ValueError( "Cannot specify both static and dynamic arguments") categories = ['attribute', 'property', 'momentum', 'topology'] dynamic_quantities = ['property'] # process inputs and build list of dynamic quantities if static is not None: hoomd.context.msg.warning( "The static argument to hoomd.dump.gsd is deprecated, use dynamic instead.\n" ) # notify they user of possible typos for v in static: if v not in categories: hoomd.context.msg.warning("dump.gsd: static quantity " + v + " is not recognized\n") # invert the sense of the static arg dynamic_quantities = [] for v in categories: if v not in static: dynamic_quantities.append(v) if dynamic is not None: for v in dynamic: if v not in categories: hoomd.context.msg.warning("dump.gsd: dynamic quantity " + v + " is not recognized\n") dynamic_quantities = ['property'] + dynamic # initialize base class hoomd.analyze._analyzer.__init__(self) self.cpp_analyzer = _hoomd.GSDDumpWriter( hoomd.context.current.system_definition, filename, group.cpp_group, overwrite, truncate) self.cpp_analyzer.setWriteAttribute('attribute' in dynamic_quantities) self.cpp_analyzer.setWriteProperty('property' in dynamic_quantities) self.cpp_analyzer.setWriteMomentum('momentum' in dynamic_quantities) self.cpp_analyzer.setWriteTopology('topology' in dynamic_quantities) if period is not None: self.setupAnalyzer(period, phase) else: if time_step is None: time_step = hoomd.context.current.system.getCurrentTimeStep() self.cpp_analyzer.analyze(time_step) # store metadata self.filename = filename self.period = period self.group = group self.phase = phase self.metadata_fields = ['filename', 'period', 'group', 'phase']