Fix phonopy-vasp-efe wrong warning

This commit is contained in:
Atsushi Togo 2022-03-29 09:17:33 +09:00
parent 5556a78a38
commit 302e7d679d
2 changed files with 19 additions and 20 deletions

View File

@ -33,6 +33,7 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import sys
import warnings
import xml.etree.cElementTree as etree
@ -1399,6 +1400,22 @@ class VasprunxmlExpat:
raise
def parse_vasprunxml(filename):
"""Parse vasprun.xml using VasprunxmlExpat."""
if not os.path.exists(filename):
print("File %s not found." % filename)
sys.exit(1)
with open(filename, "rb") as f:
vxml = VasprunxmlExpat(f)
try:
vxml.parse()
except (xml.parsers.expat.ExpatError, ValueError, Exception):
print("Warning: Probably xml structure of %s is broken." % filename)
print("Opening %s failed." % filename)
sys.exit(1)
return vxml
#
# XDATCAR
#

View File

@ -34,13 +34,9 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import io
import os
import sys
import numpy as np
from phonopy.interface.vasp import VasprunxmlExpat
from phonopy.interface.vasp import parse_vasprunxml
from phonopy.qha.electron import get_free_energy_at_T
"""Calculate electronic free energy from vasprun.xml at temperatures
@ -76,20 +72,6 @@ def get_options():
return args
def read_vasprunxml(filename):
if not os.path.exists(filename):
print("File %s not found." % filename)
sys.exit(1)
with io.open(filename, "rb") as f:
vxml = VasprunxmlExpat(f)
if not vxml.parse():
print("Warning: Probably xml structure of %s is broken." % filename)
return vxml
print("Opening %s failed." % filename)
sys.exit(1)
def get_free_energy_lines(temperatures, free_energies):
lines = []
n_vol = free_energies.shape[1]
@ -104,7 +86,7 @@ def get_fe_ev_lines(args):
free_energies = []
temperatures = None
for filename in args.filenames:
vxml = read_vasprunxml(filename)
vxml = parse_vasprunxml(filename)
weights = vxml.k_weights
eigenvalues = vxml.eigenvalues[:, :, :, 0]
n_electrons = vxml.NELECT