def test_process_units_object(units_preparation): natoms, frames, comment, conver_xyz, conver_cell = units_preparation output = "objects" filedesc, xyz, atom_names = xyz_gen.xyz_traj_filedesc( natoms, frames, comment) cell = mt.abc2h(1.0, 1.0, 1.0, np.pi / 2.0, np.pi / 2.0, np.pi / 2.0) masses = [] _count = 0 for _at in atom_names: print(Elements.mass(_at), _count, _at) masses.append(Elements.mass(_at)) _count += 1 masses = np.array(masses) res = testing.process_units( comment, cell.copy(), xyz.copy(), np.array(atom_names).copy(), np.array(masses).copy(), output=output, ) npt.assert_array_almost_equal(res["atoms"].q, xyz * conver_xyz, 5) npt.assert_array_almost_equal(res["atoms"].m, masses, 5) npt.assert_array_almost_equal(res["cell"].h, cell * conver_cell, 5) npt.assert_array_equal(res["atoms"].names, atom_names, 5)
def test_process_units_noobj(units_preparation): natoms, frames, comment, conver_xyz, conver_cell = units_preparation output = "noobj" filedesc, xyz, atom_names = xyz_gen.xyz_traj_filedesc( natoms, frames, comment) cell = mt.abc2h(1.0, 1.0, 1.0, np.pi / 2.0, np.pi / 2.0, np.pi / 2.0) masses = [] _count = 0 print("atom_names", atom_names) for _at in atom_names: print(Elements.mass(_at), _count, _at) masses.append(Elements.mass(_at)) _count += 1 masses = np.array(masses) type(masses) res = testing.process_units( comment, cell.copy(), xyz.copy(), np.array(atom_names).copy(), np.array(masses).copy(), output=output, ) print(xyz, res["data"]) npt.assert_array_almost_equal(res["data"], xyz * conver_xyz, 5) npt.assert_array_almost_equal(res["masses"], masses, 5) npt.assert_array_almost_equal(res["cell"], cell * conver_cell, 5) npt.assert_array_equal(res["names"], atom_names, 5) assert res["natoms"] == natoms
def test_process_units_object(units_preparation): natoms, frames, comment, conver_xyz, conver_cell = units_preparation output = 'objects' filedesc, xyz, atom_names = xyz_gen.xyz_traj_filedesc(natoms, frames, comment) cell = mt.abc2h(1.0, 1.0, 1.0, np.pi / 2.0, np.pi / 2.0, np.pi / 2.0) masses = [] _count = 0 for _at in atom_names: print Elements.mass(_at), _count, _at masses.append(Elements.mass(_at)) _count += 1 masses = np.array(masses) res = testing.process_units(comment, cell.copy(), xyz.copy(), np.array(atom_names).copy(), np.array(masses).copy(), output=output) npt.assert_array_almost_equal(res['atoms'].q, xyz * conver_xyz, 5) npt.assert_array_almost_equal(res['atoms'].m, masses, 5) npt.assert_array_almost_equal(res['cell'].h, cell * conver_cell, 5) npt.assert_array_equal(res['atoms'].names, atom_names, 5)
def test_process_units_noobj(units_preparation): natoms, frames, comment, conver_xyz, conver_cell = units_preparation output = 'noobj' filedesc, xyz, atom_names = xyz_gen.xyz_traj_filedesc(natoms, frames, comment) cell = mt.abc2h(1.0, 1.0, 1.0, np.pi / 2.0, np.pi / 2.0, np.pi / 2.0) masses = [] _count = 0 print 'atom_names', atom_names for _at in atom_names: print Elements.mass(_at), _count, _at masses.append(Elements.mass(_at)) _count += 1 masses = np.array(masses) type(masses) res = testing.process_units(comment, cell.copy(), xyz.copy(), np.array(atom_names).copy(), np.array(masses).copy(), output=output) print xyz, res['data'] npt.assert_array_almost_equal(res['data'], xyz * conver_xyz, 5) npt.assert_array_almost_equal(res['masses'], masses, 5) npt.assert_array_almost_equal(res['cell'], cell * conver_cell, 5) npt.assert_array_equal(res['names'], atom_names, 5) assert res['natoms'] == natoms
def main(fns_in, fn_out, begin, end, stride, wrap, unwrap): verbosity.level = "low" print('Multiplexing {:d} beads into one trajectory.'.format(len(fns_in))) print() print('input file names:') for fn in fns_in: print(fn) print() print('output file name:', fn_out) print() # Open input trajectory iterators. trjs_in = [iter_file_name_raw(fn) for fn in fns_in] mode = os.path.splitext(fns_in[0])[-1] # Open output file. f_out = open_backup(fn_out, 'w') mode_out = os.path.splitext(fn_out)[-1] # Loop over all frames. i_frame = 0 i_frame_saved = 0 # There can be multiple trajectories, so we store a frame_last for each trajectory frame_last = [None] * len(fns_in) while True: # Check the endpoint index, exit if we're done. if (end > -1) and (i_frame >= end): break # Should we save output from this frame? do_output = (i_frame >= begin) and ((i_frame % stride) == 0) try: # Get the frames from all trajectories... for idx, trj in enumerate(trjs_in): frame = next(trj) # gets units from first frame dimension, units, cell_units = auto_units( comment=frame["comment"]) frame = process_units(dimension=dimension, units=units, cell_units=cell_units, mode=mode, **frame) if wrap: frame = wrap_positions(frame) if unwrap: frame = unwrap_positions(frame, frame_last[idx]) frame_last[idx] = frame.copy() # ... and possibly save them in the output trajectory. if do_output: print_file(mode_out, frame['atoms'], frame['cell'], f_out, dimension=dimension, units=units, cell_units=cell_units) if do_output: i_frame_saved += 1 except StopIteration: # Stop when any of the trajectories runs out of frames. break # Count frames and print information on progress. i_frame += 1 if i_frame % 100 == 0: print('\rframe {:d}'.format(i_frame), end='') sys.stdout.flush() f_out.close() print() print() print('Loaded {:d} frames.'.format(i_frame)) print('Saved {:d} frames.'.format(i_frame_saved))
def main(fns_in, fn_out, begin, end, stride, wrap, unwrap): verbosity.level = "low" print('Multiplexing {:d} beads into one trajectory.'.format(len(fns_in))) print() print('input file names:') for fn in fns_in: print(fn) print() print('output file name:', fn_out) print() # Open input trajectory iterators. trjs_in = [iter_file_name_raw(fn) for fn in fns_in] mode = os.path.splitext(fns_in[0])[-1] # Open output file. f_out = open_backup(fn_out, 'w') mode_out = os.path.splitext(fn_out)[-1] # Loop over all frames. i_frame = 0 i_frame_saved = 0 # There can be multiple trajectories, so we store a frame_last for each trajectory frame_last = [None] * len(fns_in) while True: # Check the endpoint index, exit if we're done. if (end > -1) and (i_frame >= end): break # Should we save output from this frame? do_output = (i_frame >= begin) and ((i_frame % stride) == 0) try: # Get the frames from all trajectories... for idx,trj in enumerate(trjs_in): frame = trj.next() # gets units from first frame dimension, units, cell_units = auto_units(comment=frame["comment"]) frame = process_units(dimension=dimension, units=units, cell_units=cell_units, mode=mode, **frame) if wrap: frame = wrap_positions(frame) if unwrap: frame = unwrap_positions(frame,frame_last[idx]) frame_last[idx] = frame.copy() # ... and possibly save them in the output trajectory. if do_output: print_file(mode_out, frame['atoms'], frame['cell'], f_out, dimension=dimension, units=units, cell_units=cell_units) if do_output: i_frame_saved += 1 except StopIteration: # Stop when any of the trajectories runs out of frames. break # Count frames and print information on progress. i_frame += 1 if i_frame % 100 == 0: print('\rframe {:d}'.format(i_frame), end='') sys.stdout.flush() f_out.close() print() print() print('Loaded {:d} frames.'.format(i_frame)) print('Saved {:d} frames.'.format(i_frame_saved))