Skip to content

Commit

Permalink
Rename OSZICAR to electronic_minimization (#172)
Browse files Browse the repository at this point in the history
* rename oszicar to electronic minimzation
* Fix tests related to renaming
  • Loading branch information
sudarshanv01 authored Nov 14, 2024
1 parent bf692b9 commit 36448f5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/py4vasp/_raw/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/_raw/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/_util/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/calculation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand All @@ -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,
Expand Down

0 comments on commit 36448f5

Please sign in to comment.