def parse(filename): """ Parses XML file and returns deserialized object. The return value depends on the serialized object, summarized below - System : returns simtk.openmm.System - State : returns simtk.openmm.State - Integrator : returns simtk.openmm.Integrator subclass - ForceField : returns simtk.openmm.app.ForceField Parameters ---------- filename : str or file-like The file name or file object containing the XML-serialized object Returns ------- obj : System, State, Integrator, or ForceField The deserialized object Notes ----- OpenMM requires the entire contents of this file read into memory. As a result, this function may require a significant amount of memory. """ if isinstance(filename, string_types): with closing(genopen(filename, 'r')) as f: contents = f.read() else: contents = f.read() # ForceField is not handled by XmlSerializer if '<ForceField' in contents: obj = StringIO() obj.write(contents) obj.seek(0) return app.ForceField(obj) obj = mm.XmlSerializer.deserialize(contents) if isinstance(obj, (mm.System, mm.Integrator)): return obj elif isinstance(obj, mm.State): return _OpenMMStateContents(obj) return
def parse(filename): """ Parses XML file and returns deserialized object. The return value depends on the serialized object, summarized below - System : returns simtk.openmm.System - State : returns simtk.openmm.State - Integrator : returns simtk.openmm.Integrator subclass - ForceField : returns simtk.openmm.app.ForceField Parameters ---------- filename : str or file-like The file name or file object containing the XML-serialized object Returns ------- obj : System, State, Integrator, or ForceField The deserialized object Notes ----- OpenMM requires the entire contents of this file read into memory. As a result, this function may require a significant amount of memory. """ import simtk.openmm as mm from simtk.openmm import app if isinstance(filename, string_types): with closing(genopen(filename, 'r')) as f: contents = f.read() else: contents = filename.read() # ForceField is not handled by XmlSerializer if '<ForceField' in contents: obj = StringIO() obj.write(contents) obj.seek(0) return app.ForceField(obj) obj = mm.XmlSerializer.deserialize(contents) if isinstance(obj, mm.State): return _OpenMMStateContents(obj) return obj