Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. #!/usr/bin/python
  2. from molmod.io.xyz import XYZFile
  3. from molmod.unit_cells import UnitCell
  4. import numpy as np
  5.  
  6. def main(file_name)
  7.  
  8.     xyz_file = XYZFile(file_name)
  9.     frames = xyz_file.geometries
  10.     n_atoms = xyz_file.geometries.shape[1]
  11.     n_steps = xyz_file.geometries.shape[0]
  12.     titles = xyz_file.titles
  13.     # Unit cell, decide how to make this general
  14.     matrix=np.array([\
  15.          [1.4731497044857509E+01, 3.2189795740722255E-02, 4.5577626559295564E-02],\
  16.          [4.2775481701113616E-02, 2.1087874593411915E+01, -2.8531114198383896E-02],\
  17.          [6.4054385616337750E-02, 1.3315840416191497E-02, 1.4683043045316882E+01]])
  18.     cell = UnitCell(matrix)
  19.     frac = UnitCell.to_fractional(cell, frames)
  20.     decimals = np.modf(frac)[0]
  21.     frac_wrapped = np.where(frac < 0, 1 + frac, frac)
  22.     cart_wrapped = molmod.unit_cells.UnitCell.to_cartesian(cell, frac_wrapped)
  23.  
  24.     xyz_file.geometries = cart_wrapped
  25.     xyz_file.write_to_file(file_name.rsplit(".",1)[0]+"_wrapped.xyz")
  26.  
  27. if __name__ == "__main__":
  28.     msg = " wrap_cell -p <path/to/trajectory>"
  29.     parser = argparse.ArgumentParser(description=msg)
  30.     parser.add_argument('-p', required=True, help='path to the xyz trajectory')
  31.     args = parser.parse_args()
  32.     main(args.p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement