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

Remove reverse readline, test against NP1 and recover NumPy 1 dependency support #203

Merged
merged 7 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
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
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