Skip to content

Commit

Permalink
add is_converged for the electronic steps
Browse files Browse the repository at this point in the history
  • Loading branch information
sudarshanv01 committed Mar 24, 2024
1 parent d824b4e commit 6aa1797
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/py4vasp/_raw/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ class OSZICAR:
"All columns of the OSZICAR file stored for all ionic steps."
label: VaspData
"Label of all the data from the OSZICAR file."
EDIFF: VaspData
"EDIFF decides the energy converge of the SCF step."


@dataclasses.dataclass
Expand Down
1 change: 1 addition & 0 deletions src/py4vasp/_raw/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def selections(quantity):
required=raw.Version(6, 5),
label="intermediate/ion_dynamics/oszicar_label",
convergence_data="intermediate/ion_dynamics/oszicar",
EDIFF="/intermediate/ion_dynamics/EDIFF",
)
#
group = "intermediate/pair_correlation"
Expand Down
9 changes: 9 additions & 0 deletions src/py4vasp/calculation/_OSZICAR.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,12 @@ def to_graph(self, selection="E"):
xlabel="Iteration number",
ylabel=ylabel,
)

@_base.data_access
def is_converged(self):
difference_energy = self._read(b"dE")
if self._more_than_one_ionic_step(difference_energy):
last_step_energy = [dE[-1] for dE in difference_energy]
else:
last_step_energy = difference_energy[-1]
return last_step_energy < self._raw_data.EDIFF
7 changes: 7 additions & 0 deletions tests/calculation/test_oszicar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def OSZICAR(raw_data):
oszicar.ref.ncg = convergence_data[:, 4]
oszicar.ref.rms = convergence_data[:, 5]
oszicar.ref.rmsc = convergence_data[:, 6]
oszicar.ref.EDIFF = raw_oszicar.EDIFF
string_rep = "N\t\tE\t\tdE\t\tdeps\t\tncg\trms\t\trms(c)\n"
format_rep = "{0:g}\t{1:0.12E}\t{2:0.6E}\t{3:0.6E}\t{4:g}\t{5:0.3E}\t{6:0.3E}\n"
for idx in range(len(convergence_data)):
Expand Down Expand Up @@ -54,3 +55,9 @@ def test_plot(OSZICAR, Assert):
def test_print(OSZICAR, format_):
actual, _ = format_(OSZICAR)
assert actual["text/plain"] == OSZICAR.ref.string_rep


def test_is_converged(OSZICAR, Assert):
actual = OSZICAR.is_converged()
expected = OSZICAR.ref.dE[-1] < OSZICAR.ref.EDIFF
assert actual == expected
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,8 @@ 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)"])
return raw.OSZICAR(convergence_data=convergence_data, label=label)
ediff = 0.5
return raw.OSZICAR(convergence_data=convergence_data, label=label, EDIFF=ediff)


def _Sr2TiO4_CONTCAR():
Expand Down

0 comments on commit 6aa1797

Please sign in to comment.