Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the possibility of reading compressed vasprun.xml files. #130

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion dpdata/vasp/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,24 @@ def analyze (fname, type_idx_zero = False, begin = 0, step = 1) :
"""
can deal with broken xml file
"""

import os, bz2, gzip
fh = fname
if(isinstance(fname, str)):
fext = os.path.splitext(fname)[1]
if(fext == ".bz2"):
fh = bz2.open(fname, "r")
elif(fext == ".gz"):
fh = gzip.open(fname, "r")

all_posi = []
all_cell = []
all_ener = []
all_forc = []
all_strs = []
cc = 0
try:
for event, elem in ET.iterparse(fname):
for event, elem in ET.iterparse(fh):
if elem.tag == 'atominfo' :
eles, types = analyze_atominfo(elem)
types = np.array(types, dtype = int)
Expand Down