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

Fix monty imports, enhance test for Outcar parser to cover uncompressed format #4068

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7d2ed7b
test monty fix for reverse readline
DanielYang59 Sep 15, 2024
bf6ff01
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Sep 18, 2024
6edc2b5
add test for uncompressed OUTCAR
DanielYang59 Sep 18, 2024
26398f2
replace reverse_readline with faster reverse readfile
DanielYang59 Sep 19, 2024
5ebc946
add more comments
DanielYang59 Sep 19, 2024
e9d0e5b
fix monty imports
DanielYang59 Sep 19, 2024
73d6aea
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Sep 29, 2024
fb72de7
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Oct 15, 2024
ffddc6f
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Oct 21, 2024
3e9984b
Merge branch 'master' into test-monty-reverse-read
shyuep Oct 21, 2024
bd53015
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Nov 8, 2024
eba026d
parametrize to reduce code repetition
DanielYang59 Nov 8, 2024
7137b7a
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Nov 13, 2024
a7bafa2
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Nov 16, 2024
9c0d003
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Nov 25, 2024
c4caab0
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Dec 11, 2024
80619f8
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Dec 11, 2024
c670ca9
revert monty test
DanielYang59 Dec 11, 2024
ec6eb06
bump monty
DanielYang59 Dec 12, 2024
c258807
swap compressed condition
DanielYang59 Dec 12, 2024
b7aacb4
what? looks like the latest monty doesn't pack reverse readline fix?
DanielYang59 Dec 12, 2024
02e5c0e
install directly from git
DanielYang59 Dec 17, 2024
49bbce4
remove Python < 3.10 check
DanielYang59 Dec 17, 2024
0ec9ee0
Revert "remove Python < 3.10 check"
DanielYang59 Dec 17, 2024
d41a039
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Dec 17, 2024
d9964d1
bump monty version
DanielYang59 Jan 4, 2025
ddc94b7
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Jan 4, 2025
1b501fc
add some types for io.exciting inputs
DanielYang59 Jan 4, 2025
0e1d11e
Revert "add some types for io.exciting inputs"
DanielYang59 Jan 4, 2025
bf2da8e
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Jan 9, 2025
02ec5d4
bump monty further
DanielYang59 Jan 10, 2025
16d04d9
Merge remote-tracking branch 'upstream/master' into test-monty-revers…
DanielYang59 Jan 10, 2025
789c157
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Jan 18, 2025
7c4fbcc
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Jan 19, 2025
d9906fa
Merge branch 'master' into test-monty-reverse-read
DanielYang59 Jan 24, 2025
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: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ jobs:

uv pip install --editable '.[${{ matrix.config.extras }}]' --resolution=${{ matrix.config.resolution }}

# TODO: test monty fix for reverse readline
uv pip install git+https://github.com/DanielYang59/monty.git@readline-line-ending

- name: Install optional Ubuntu dependencies
if: matrix.config.os == 'ubuntu-latest'
run: |
Expand Down
2 changes: 1 addition & 1 deletion dev_scripts/potcar_scrambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from typing import TYPE_CHECKING

import numpy as np
from monty.io import zopen
from monty.os.path import zpath
from monty.serialization import zopen

from pymatgen.core import SETTINGS
from pymatgen.io.vasp import Potcar, PotcarSingle
Expand Down
22 changes: 10 additions & 12 deletions src/pymatgen/io/adf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import re
from typing import TYPE_CHECKING

from monty.io import reverse_readline
from monty.io import reverse_readfile
from monty.itertools import chunks
from monty.json import MSONable
from monty.serialization import zopen

from pymatgen.core.structure import Molecule

Expand Down Expand Up @@ -645,16 +644,15 @@ def _parse_logfile(self, logfile):
# The last non-empty line of the logfile must match the end pattern.
# Otherwise the job has some internal failure. The TAPE13 part of the
# ADF manual has a detailed explanation.
with zopen(logfile, mode="rt") as file:
for line in reverse_readline(file):
if line == "":
continue
if end_patt.search(line) is None:
self.is_internal_crash = True
self.error = "Internal crash. TAPE13 is generated!"
self.is_failed = True
return
break
for line in reverse_readfile(logfile):
if line.strip() == "":
continue
if end_patt.search(line) is None:
self.is_internal_crash = True
self.error = "Internal crash. TAPE13 is generated!"
self.is_failed = True
return
break

with open(logfile) as file:
for line in file:
Expand Down
3 changes: 2 additions & 1 deletion tests/core/test_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import numpy as np
import pytest
from monty.serialization import MontyDecoder, loadfn
from monty.json import MontyDecoder
from monty.serialization import loadfn
from numpy.testing import assert_allclose
from pytest import approx

Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import TYPE_CHECKING

import pytest
from monty.serialization import MontyDecoder
from monty.json import MontyDecoder

from pymatgen.core.structure import Structure
from pymatgen.io.cif import CifParser, CifWriter
Expand Down
19 changes: 16 additions & 3 deletions tests/io/vasp/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import numpy as np
import pytest
from monty.io import zopen
from monty.shutil import decompress_file
from monty.tempfile import ScratchDir
from numpy.testing import assert_allclose
from pytest import approx

Expand Down Expand Up @@ -831,9 +833,20 @@ def test_parse_potcar_cwd_relative(self):
assert vrun.potcar_spec[ipot]["summary_stats"] == potcar[ipot]._summary_stats


class TestOutcar(PymatgenTest):
DanielYang59 marked this conversation as resolved.
Show resolved Hide resolved
def test_init(self):
outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz")
class TestOutcar:
@pytest.mark.parametrize("compressed", [True, False])
def test_init(self, compressed: bool):
"""Test from both compressed and uncompressed versions,
as there was a bug in monty causing different behaviours.
"""
with ScratchDir("."):
if compressed:
copyfile(f"{VASP_OUT_DIR}/OUTCAR.gz", "./OUTCAR.gz")
decompress_file("./OUTCAR.gz")
outcar = Outcar("./OUTCAR")
else:
outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz")

expected_mag = (
{"d": 0.0, "p": 0.003, "s": 0.002, "tot": 0.005},
{"d": 0.798, "p": 0.008, "s": 0.007, "tot": 0.813},
Expand Down