pwtools.parse.traj_from_txt

pwtools.parse.traj_from_txt(txt, shape, axis=0, dtype=<class 'numpy.float64'>, sep=' ')[source]

Used for 3d trajectories where the exact shape of the array as written by the MD code must be known, e.g. (nstep,N,3) where N=3 (cell, stress) or N=natoms (coords, forces, …).

We use np.fromstring for speed, so txt can only contain numbers and separators (white space), no comments (like “# this is the header”), which numpy.loadtxt() would handle.

Parameters:
  • txt (string) – Text containing numbers (e.g. from common.backtick("grep ..."))

  • shape (tuple) – The 3d shape of the array when written along axis (see also arrayio.writetxt()) to text as 2d chunks and read back in as 3d array. Used to reconstruct the array.

  • axis (int) – Axis along which the array was written in 2d chunks to text. (see also axis in arrayio.writetxt()). Used to reconstruct the array. Only axis=0 implemented.

  • dtype (passed to np.fromstring)

  • sep (passed to np.fromstring)