def test_traj_from_txt(): shape = (10, 20, 30) arr3d_orig = np.random.rand(*shape) axis = 0 # general stuff for axis != 0, here for axis=0 we have written_shape==shape shape_2d_chunk = shape[:axis] + shape[(axis + 1):] written_shape = (shape[axis], ) + shape_2d_chunk print("axis, written_shape:", axis, written_shape) fn = pj(testdir, 'arr_test_traj_from_txt_axis%i.txt' % axis) arrayio.writetxt(fn, arr3d_orig, axis=axis, header=False) with open(fn) as fd: arr3d = parse.traj_from_txt(fd.read(), axis=axis, shape=written_shape) fd.seek(0) # test if the "old" way of reading also works arr3d_readtxt = arrayio.readtxt(fd, shape=written_shape, axis=axis) assert (arr3d_readtxt == arr3d_orig).all() # now test traj_from_txt result assert arr3d.shape == arr3d_orig.shape, \ ("axis={}, shapes: read={} written={} orig={}".format(axis, arr3d.shape, written_shape, arr3d_orig.shape)) assert (arr3d == arr3d_orig).all()
def test_traj_from_txt(): shape = (10,20,30) arr3d_orig = np.random.rand(*shape) axis = 0 # general stuff for axis != 0, here for axis=0 we have written_shape==shape shape_2d_chunk = shape[:axis] + shape[(axis+1):] written_shape = (shape[axis],) + shape_2d_chunk print "axis, written_shape:", axis, written_shape fn = pj(testdir, 'arr_test_traj_from_txt_axis%i.txt' %axis) arrayio.writetxt(fn, arr3d_orig, axis=axis, header=False) with open(fn) as fd: arr3d = parse.traj_from_txt(fd.read(), axis=axis, shape=written_shape) fd.seek(0) # test if the "old" way of reading also works arr3d_readtxt = arrayio.readtxt(fd, shape=written_shape, axis=axis) assert (arr3d_readtxt == arr3d_orig).all() # now test traj_from_txt result assert arr3d.shape == arr3d_orig.shape, \ ("axis={0}, shapes: read={1} written={2} orig={3}".format(axis, arr3d.shape, written_shape, arr3d_orig.shape)) assert (arr3d == arr3d_orig).all()
'time', ] assert_attrs_not_none(traj, none_attrs=none_attrs) # for test_return_3d_if_no_cell_unit _cell = parse.traj_from_txt(""" 1.004152675 0.000000000 0.000000000 -0.502076337 0.869621726 0.000000000 0.000000000 0.000000000 1.609289155 1.004147458 0.000000000 0.000000000 -0.502073729 0.869617208 0.000000000 0.000000000 0.000000000 1.609759673 1.004050225 0.000000000 0.000000000 -0.502025112 0.869533001 0.000000000 0.000000000 0.000000000 1.610320650 1.003992235 0.000000000 0.000000000 -0.501996117 0.869482780 0.000000000 0.000000000 0.000000000 1.610416170 1.003981055 0.000000000 0.000000000 -0.501990527 0.869473099 0.000000000 0.000000000 0.000000000 1.610369398 1.003981055 0.000000000 0.000000000 -0.501990527 0.869473099 0.000000000 0.000000000 0.000000000 1.610369398 """, shape=(6,3,3)) def test_return_3d_if_no_cell_unit(): filename = tools.unpack_compressed('files/pw.vc_relax_no_cell_unit.out.gz', prefix=__file__) pp = PwMDOutputFile(filename=filename) pp.parse()