Skip to content

Commit

Permalink
Remove reverse readline, test again NP1 and recover NumPy 1 dependenc…
Browse files Browse the repository at this point in the history
…y support (#203)

* test monty fix for reverse readline

* ensure pip env consistency

* remove reverse readline

* remove monty pin

* test NP1

* use readlines

* revert numpy version pin to > 1.26 to support NP1
  • Loading branch information
DanielYang59 authored Sep 15, 2024
1 parent 11ff513 commit cde8a76
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ jobs:
pip install uv
uv pip install -e .[test,logging] --resolution=${{ matrix.version.resolution }} --system
# TODO: remove pin once reverse readline fixed
uv pip install monty==2024.7.12 --system
- name: Run Tests
run: pytest --capture=no --cov --cov-report=xml
env:
Expand Down
42 changes: 19 additions & 23 deletions chgnet/utils/vasp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings
from typing import TYPE_CHECKING

from monty.io import reverse_readfile
from monty.io import zopen
from monty.os.path import zpath
from pymatgen.io.vasp.outputs import Oszicar, Vasprun

Expand Down Expand Up @@ -58,13 +58,11 @@ def parse_vasp_dir(
exception_on_bad_xml=False,
)

charge, mag_x, mag_y, mag_z, header, all_lines = [], [], [], [], [], []
charge, mag_x, mag_y, mag_z, header = [], [], [], [], []

for line in reverse_readfile(outcar_path):
clean = line.strip()
all_lines.append(clean)
with zopen(outcar_path, encoding="utf-8") as file:
all_lines = [line.strip() for line in file.readlines()]

all_lines.reverse()
# For single atom systems, VASP doesn't print a total line, so
# reverse parsing is very difficult
# for SOC calculations only
Expand All @@ -79,23 +77,21 @@ def parse_vasp_dir(
if clean.startswith("# of ion"):
header = re.split(r"\s{2,}", clean.strip())
header.pop(0)
else:
m = re.match(r"\s*(\d+)\s+(([\d\.\-]+)\s+)+", clean)
if m:
tokens = [float(token) for token in re.findall(r"[\d\.\-]+", clean)]
tokens.pop(0)
if read_charge:
charge.append(dict(zip(header, tokens)))
elif read_mag_x:
mag_x.append(dict(zip(header, tokens)))
elif read_mag_y:
mag_y.append(dict(zip(header, tokens)))
elif read_mag_z:
mag_z.append(dict(zip(header, tokens)))
elif clean.startswith("tot"):
if ion_step_count == (len(mag_x_all) + 1):
mag_x_all.append(mag_x)
read_charge = read_mag_x = read_mag_y = read_mag_z = False
elif re.match(r"\s*(\d+)\s+(([\d\.\-]+)\s+)+", clean):
tokens = [float(token) for token in re.findall(r"[\d\.\-]+", clean)]
tokens.pop(0)
if read_charge:
charge.append(dict(zip(header, tokens)))
elif read_mag_x:
mag_x.append(dict(zip(header, tokens)))
elif read_mag_y:
mag_y.append(dict(zip(header, tokens)))
elif read_mag_z:
mag_z.append(dict(zip(header, tokens)))
elif clean.startswith("tot"):
if ion_step_count == (len(mag_x_all) + 1):
mag_x_all.append(mag_x)
read_charge = read_mag_x = read_mag_y = read_mag_z = False
if clean == "total charge":
read_charge = True
read_mag_x = read_mag_y = read_mag_z = False
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ license = { text = "Modified BSD" }
dependencies = [
"ase>=3.23.0",
"cython>=3",
# "monty==2024.7.12", # TODO: restore once readline fixed
# "numpy>=1.26", # TODO: remove after test
"numpy>=2.0.0",
"numpy>=1.26",
"nvidia-ml-py3>=7.352.0",
"pymatgen>=2024.9.10",
"torch>=2.4.1",
Expand Down

0 comments on commit cde8a76

Please sign in to comment.