def test_read_xyz(): """Tests that xyz files are read correctly.""" with open(local("test.pos_0.xyz"), "r") as f: atoms = io_xyz.read_xyz(f) assert(len(atoms) == 3) assert_equal(pos, atoms.q)
def init_xyz(filename): """Reads an xyz file and returns the data contained in it. Args: filename: A string giving the name of the xyz file to be read from. Returns: A list of Atoms objects as read from each frame of the xyz file. """ rfile = open(filename, "r") ratoms = [] while True: #while loop, so that more than one configuration can be given #so multiple beads can be initialized at once. try: myatoms = read_xyz(rfile) except EOFError: break ratoms.append(myatoms) return ratoms
def init_xyz(filename): """Reads an xyz file and returns the data contained in it. Args: filename: A string giving the name of the xyz file to be read from. Returns: A list of Atoms objects as read from each frame of the xyz file. """ rfile = open(filename,"r") ratoms = [] while True: #while loop, so that more than one configuration can be given #so multiple beads can be initialized at once. try: myatoms = read_xyz(rfile) except EOFError: break ratoms.append(myatoms) return ratoms
def step(self): """Does one simulation time step.""" self.ptime = self.ttime = 0 self.qtime = -time.time() try: if (self.intraj.mode == "xyz"): for b in self.beads: myatoms = read_xyz(self.rfile) myatoms.q *= unit_to_internal("length", self.intraj.units, 1.0) b.q[:] = myatoms.q elif (self.intraj.mode == "pdb"): for b in self.beads: myatoms, mycell = read_pdb(self.rfile) myatoms.q *= unit_to_internal("length", self.intraj.units, 1.0) mycell.h *= unit_to_internal("length", self.intraj.units, 1.0) b.q[:] = myatoms.q self.cell.h[:] = mycell.h elif (self.intraj.mode == "chk" or self.intraj.mode == "checkpoint"): # reads configuration from a checkpoint file xmlchk = xml_parse_file(self.rfile) # Parses the file. from ipi.inputs.simulation import InputSimulation simchk = InputSimulation() simchk.parse(xmlchk.fields[0][1]) mycell = simchk.cell.fetch() mybeads = simchk.beads.fetch() self.cell.h[:] = mycell.h self.beads.q[:] = mybeads.q softexit.trigger(" # Read single checkpoint") except EOFError: softexit.trigger(" # Finished reading re-run trajectory") self.qtime += time.time()
def step(self): """Does one simulation time step.""" self.ptime = self.ttime = 0 self.qtime = -time.time() try: if self.intraj.mode == "xyz": for b in self.beads: myatoms = read_xyz(self.rfile) myatoms.q *= unit_to_internal("length", self.intraj.units, 1.0) b.q[:] = myatoms.q elif self.intraj.mode == "pdb": for b in self.beads: myatoms, mycell = read_pdb(self.rfile) myatoms.q *= unit_to_internal("length", self.intraj.units, 1.0) mycell.h *= unit_to_internal("length", self.intraj.units, 1.0) b.q[:] = myatoms.q self.cell.h[:] = mycell.h elif self.intraj.mode == "chk" or self.intraj.mode == "checkpoint": # reads configuration from a checkpoint file xmlchk = xml_parse_file(self.rfile) # Parses the file. from ipi.inputs.simulation import InputSimulation simchk = InputSimulation() simchk.parse(xmlchk.fields[0][1]) mycell = simchk.cell.fetch() mybeads = simchk.beads.fetch() self.cell.h[:] = mycell.h self.beads.q[:] = mybeads.q softexit.trigger(" # Read single checkpoint") except EOFError: softexit.trigger(" # Finished reading re-run trajectory") self.qtime += time.time()