Skip to content

Instantly share code, notes, and snippets.

@tnorthey
Last active August 23, 2022 10:00
Show Gist options
  • Save tnorthey/d9a98de348f7c140b7e2cb574f2c14b9 to your computer and use it in GitHub Desktop.
Save tnorthey/d9a98de348f7c140b7e2cb574f2c14b9 to your computer and use it in GitHub Desktop.
Python xyz file reader
import numpy as np
def read_xyz(self, fname):
"""Read a .xyz file"""
with open(fname, "r") as xyzfile:
xyzheader = int(xyzfile.readline())
comment = xyzfile.readline()
xyzmatrix = np.loadtxt(fname, skiprows=2, usecols=[1, 2, 3])
atomarray = np.loadtxt(fname, skiprows=2, dtype=str, usecols=[0])
return xyzheader, comment, atomarray, xyzmatrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment