Skip to content

Instantly share code, notes, and snippets.

View tnorthey's full-sized avatar

tn tnorthey

View GitHub Profile
@tnorthey
tnorthey / read_xyz.py
Last active August 23, 2022 10:00
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