Skip to content

Commit

Permalink
fix io.vasp
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Apr 13, 2024
1 parent afac73e commit 147cb85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ def from_str(cls, data, default_names=None, read_velocities=True) -> Self:
lattice *= scale

vasp5_symbols = False
atomic_symbols = []
try:
n_atoms = [int(i) for i in lines[5].split()]
ipos = 6
Expand Down Expand Up @@ -362,7 +363,7 @@ def from_str(cls, data, default_names=None, read_velocities=True) -> Self:
iline_natoms_start = 5 + n_lines_symbols
for iline_natoms in range(iline_natoms_start, iline_natoms_start + n_lines_symbols):
n_atoms.extend([int(i) for i in lines[iline_natoms].split()])
atomic_symbols = []

for i, nat in enumerate(n_atoms):
atomic_symbols.extend([symbols[i]] * nat)
ipos = 5 + 2 * n_lines_symbols
Expand All @@ -383,11 +384,12 @@ def from_str(cls, data, default_names=None, read_velocities=True) -> Self:
# them. This is in line with VASP's parsing order that the POTCAR
# specified is the default used.
if default_names:
with contextlib.suppress(IndexError):
atomic_symbols = []
try:
for i, nat in enumerate(n_atoms):
atomic_symbols.extend([default_names[i]] * nat)
vasp5_symbols = True
except IndexError:
pass

if not vasp5_symbols:
ind = 6 if has_selective_dynamics else 3
Expand Down Expand Up @@ -1389,8 +1391,11 @@ def from_str(cls, string: str) -> Self:

kpts_shift: tuple[float, float, float] = (0, 0, 0)
if len(lines) > 4 and coord_pattern.match(lines[4]):
with contextlib.suppress(ValueError):
try:
_kpts_shift = tuple(float(i) for i in lines[4].split())
except ValueError:
_kpts_shift = (0, 0, 0)

if len(_kpts_shift) == 3:
kpts_shift = _kpts_shift

Expand All @@ -1400,8 +1405,7 @@ def from_str(cls, string: str) -> Self:
if num_kpts <= 0:
_style = cls.supported_modes.Cartesian if style in "ck" else cls.supported_modes.Reciprocal
_kpts_shift = tuple(float(i) for i in lines[6].split())
if len(_kpts_shift) == 3:
kpts_shift = _kpts_shift
kpts_shift = _kpts_shift if len(_kpts_shift) == 3 else (0, 0, 0)

return cls(
comment=comment,
Expand Down
8 changes: 8 additions & 0 deletions pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3776,7 +3776,15 @@ def __init__(self, filename):
current_band = 0
done = False
spin = Spin.down

weights = None
n_kpoints = None
n_bands = None
n_ions = None
weights = []
headers = None
data = None
phase_factors = None

for line in file_handle:
line = line.strip()
Expand Down

0 comments on commit 147cb85

Please sign in to comment.