From 36448f5b1e4b042c9808e2bed1a321782b85ebf6 Mon Sep 17 00:00:00 2001 From: Sudarshan Vijay Date: Thu, 14 Nov 2024 14:07:28 +0100 Subject: [PATCH] Rename OSZICAR to electronic_minimization (#172) * rename oszicar to electronic minimzation * Fix tests related to renaming --- src/py4vasp/_raw/data.py | 2 +- src/py4vasp/_raw/definition.py | 2 +- src/py4vasp/_util/convert.py | 2 +- src/py4vasp/calculation/__init__.py | 2 +- ...OSZICAR.py => _electronic_minimization.py} | 2 +- ...car.py => test_electronic_minimization.py} | 50 ++++++++++--------- tests/conftest.py | 8 +-- 7 files changed, 35 insertions(+), 33 deletions(-) rename src/py4vasp/calculation/{_OSZICAR.py => _electronic_minimization.py} (98%) rename tests/calculation/{test_oszicar.py => test_electronic_minimization.py} (60%) diff --git a/src/py4vasp/_raw/data.py b/src/py4vasp/_raw/data.py index 77d7866c..eeee17c5 100644 --- a/src/py4vasp/_raw/data.py +++ b/src/py4vasp/_raw/data.py @@ -313,7 +313,7 @@ class Magnetism: @dataclasses.dataclass -class OSZICAR: +class ElectronicMinimization: """The OSZICAR data as generated by VASP. All data generated by VASP and traditionally stored in the OSZICAR file will be diff --git a/src/py4vasp/_raw/definition.py b/src/py4vasp/_raw/definition.py index 6119fabc..1e82e326 100644 --- a/src/py4vasp/_raw/definition.py +++ b/src/py4vasp/_raw/definition.py @@ -379,7 +379,7 @@ def selections(quantity): ) # schema.add( - raw.OSZICAR, + raw.ElectronicMinimization, required=raw.Version(6, 5), label="intermediate/ion_dynamics/oszicar_label", convergence_data="intermediate/ion_dynamics/oszicar", diff --git a/src/py4vasp/_util/convert.py b/src/py4vasp/_util/convert.py index c97f2944..f54bb95a 100644 --- a/src/py4vasp/_util/convert.py +++ b/src/py4vasp/_util/convert.py @@ -21,7 +21,7 @@ def to_complex(array): def quantity_name(quantity): - if quantity in ["CONTCAR", "OSZICAR"]: + if quantity in ["CONTCAR"]: return quantity else: return _to_snakecase(quantity) diff --git a/src/py4vasp/calculation/__init__.py b/src/py4vasp/calculation/__init__.py index 2e6857ce..75a08478 100644 --- a/src/py4vasp/calculation/__init__.py +++ b/src/py4vasp/calculation/__init__.py @@ -62,7 +62,7 @@ class provides a more flexible interface with which you can determine the source "internal_strain", "kpoint", "magnetism", - "OSZICAR", + "electronic_minimization", "pair_correlation", "partial_charge", "phonon_band", diff --git a/src/py4vasp/calculation/_OSZICAR.py b/src/py4vasp/calculation/_electronic_minimization.py similarity index 98% rename from src/py4vasp/calculation/_OSZICAR.py rename to src/py4vasp/calculation/_electronic_minimization.py index 8aa12e91..51b2d670 100644 --- a/src/py4vasp/calculation/_OSZICAR.py +++ b/src/py4vasp/calculation/_electronic_minimization.py @@ -8,7 +8,7 @@ from py4vasp.calculation import _base, _slice -class OSZICAR(_slice.Mixin, _base.Refinery, graph.Mixin): +class ElectronicMinimization(_slice.Mixin, _base.Refinery, graph.Mixin): """Access the convergence data for each electronic step. The OSZICAR file written out by VASP stores information related to convergence. diff --git a/tests/calculation/test_oszicar.py b/tests/calculation/test_electronic_minimization.py similarity index 60% rename from tests/calculation/test_oszicar.py rename to tests/calculation/test_electronic_minimization.py index 4608b056..88350470 100644 --- a/tests/calculation/test_oszicar.py +++ b/tests/calculation/test_electronic_minimization.py @@ -10,9 +10,9 @@ @pytest.fixture -def OSZICAR(raw_data): - raw_oszicar = raw_data.OSZICAR() - oszicar = calculation.OSZICAR.from_data(raw_oszicar) +def ElectronicMinimization(raw_data): + raw_oszicar = raw_data.electronic_minimization() + oszicar = calculation.electronic_minimization.from_data(raw_oszicar) oszicar.ref = types.SimpleNamespace() convergence_data = raw_oszicar.convergence_data oszicar.ref.N = np.int64(convergence_data[:, 0]) @@ -31,9 +31,9 @@ def OSZICAR(raw_data): return oszicar -def test_read(OSZICAR, Assert): - actual = OSZICAR.read() - expected = OSZICAR.ref +def test_read(ElectronicMinimization, Assert): + actual = ElectronicMinimization.read() + expected = ElectronicMinimization.ref Assert.allclose(actual["N"], expected.N) Assert.allclose(actual["E"], expected.E) Assert.allclose(actual["dE"], expected.dE) @@ -46,20 +46,22 @@ def test_read(OSZICAR, Assert): @pytest.mark.parametrize( "quantity_name", ["N", "E", "dE", "deps", "ncg", "rms", "rms(c)"] ) -def test_read_selection(quantity_name, OSZICAR, Assert): - actual = OSZICAR.read(quantity_name) - expected = getattr(OSZICAR.ref, quantity_name.replace("(", "").replace(")", "")) +def test_read_selection(quantity_name, ElectronicMinimization, Assert): + actual = ElectronicMinimization.read(quantity_name) + expected = getattr( + ElectronicMinimization.ref, quantity_name.replace("(", "").replace(")", "") + ) Assert.allclose(actual[quantity_name], expected) -def test_read_incorrect_selection(OSZICAR): +def test_read_incorrect_selection(ElectronicMinimization): with pytest.raises(exception.RefinementError): - OSZICAR.read("forces") + ElectronicMinimization.read("forces") -def test_slice(OSZICAR, Assert): - actual = OSZICAR[0:1].read() - expected = OSZICAR.ref +def test_slice(ElectronicMinimization, Assert): + actual = ElectronicMinimization[0:1].read() + expected = ElectronicMinimization.ref Assert.allclose(actual["N"], expected.N) Assert.allclose(actual["E"], expected.E) Assert.allclose(actual["dE"], expected.dE) @@ -69,21 +71,21 @@ def test_slice(OSZICAR, Assert): Assert.allclose(actual["rms(c)"], expected.rmsc) -def test_plot(OSZICAR, Assert): - graph = OSZICAR.plot() +def test_plot(ElectronicMinimization, Assert): + graph = ElectronicMinimization.plot() assert graph.xlabel == "Iteration number" assert graph.ylabel == "E" assert len(graph.series) == 1 - Assert.allclose(graph.series[0].x, OSZICAR.ref.N) - Assert.allclose(graph.series[0].y, OSZICAR.ref.E) + Assert.allclose(graph.series[0].x, ElectronicMinimization.ref.N) + Assert.allclose(graph.series[0].y, ElectronicMinimization.ref.E) -def test_print(OSZICAR, format_): - actual, _ = format_(OSZICAR) - assert actual["text/plain"] == OSZICAR.ref.string_rep +def test_print(ElectronicMinimization, format_): + actual, _ = format_(ElectronicMinimization) + assert actual["text/plain"] == ElectronicMinimization.ref.string_rep -def test_is_converged(OSZICAR): - actual = OSZICAR.is_converged() - expected = OSZICAR.ref.is_elmin_converged +def test_is_converged(ElectronicMinimization): + actual = ElectronicMinimization.is_converged() + expected = ElectronicMinimization.ref.is_elmin_converged assert actual == expected diff --git a/tests/conftest.py b/tests/conftest.py index e58db1b0..e7e96906 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -134,8 +134,8 @@ def CONTCAR(selection): raise exception.NotImplemented() @staticmethod - def OSZICAR(selection=None): - return _example_OSZICAR() + def electronic_minimization(selection=None): + return _example_electronic_minimization() @staticmethod def density(selection): @@ -667,7 +667,7 @@ def _Sr2TiO4_cell(): ) -def _example_OSZICAR(): +def _example_electronic_minimization(): random_convergence_data = np.random.rand(9, 3) iteration_number = np.arange(1, 10)[:, np.newaxis] ncg = np.random.randint(4, 10, (9, 1)) @@ -678,7 +678,7 @@ def _example_OSZICAR(): convergence_data = raw.VaspData(convergence_data) label = raw.VaspData([b"N", b"E", b"dE", b"deps", b"ncg", b"rms", b"rms(c)"]) is_elmin_converged = [0] - return raw.OSZICAR( + return raw.ElectronicMinimization( convergence_data=convergence_data, label=label, is_elmin_converged=is_elmin_converged,