Skip to content

Commit

Permalink
More parser
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Jul 19, 2024
1 parent 4dd775d commit d534af0
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 32 deletions.
67 changes: 67 additions & 0 deletions src/aiida_sssp_workflow/protocol/criteria.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,70 @@ v2024.1001:
eps: 1.0e-3
unit: meV/atom

efficiency:
name: Legacy efficiency
description: Protocol to pick the legacy efficiency pseudopotestials.

cohesive_energy:
mode: 0
bounds: [0.0, 2.0] # when relative error < 2.0 meV/atom
eps: 1.0e-3
unit: meV/atom

eos:
mode: 0
bounds: [0.0, 0.2] # when absolute error < 0.2 meV/atom
eps: 1.0e-3
unit: meV/atom

phonon_frequencies:
mode: 0
bounds: [0.0, 2.0] # when relative error < 2.0%
eps: 1.0e-3
unit: "%"

pressure:
mode: 0
bounds: [0.0, 1.0] # when relative error < 1.0%
eps: 1.0e-3
unit: "%"

bands:
mode: 0
bounds: [0.0, 20] # when error eta_c < 20 meV
eps: 1.0e-3
unit: meV/atom

precision:
name: Legacy precision
description: Protocol to pick the legacy efficiency pseudopotestials.

cohesive_energy:
mode: 0
bounds: [0.0, 2.0] # when relative error < 2.0 meV/atom
eps: 1.0e-3
unit: meV/atom

eos:
mode: 0
bounds: [0.0, 0.2] # when absolute error < 0.2 meV/atom
eps: 1.0e-3
unit: meV/atom

phonon_frequencies:
mode: 0
bounds: [0.0, 1.0] # when relative error < 2.0%
eps: 1.0e-3
unit: "%"

pressure:
mode: 0
bounds: [0.0, 0.5] # when relative error < 1.0%
eps: 1.0e-3
unit: "%"

bands:
mode: 0
bounds: [0.0, 20] # when error eta_c < 20 meV
eps: 1.0e-3
unit: meV/atom
11 changes: 11 additions & 0 deletions src/aiida_sssp_workflow/utils/pseudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class PseudoInfo(BaseModel):
# source_lib: str
# ...


class DualType(Enum):
NC = "nc"
AUGLOW = "charge augmentation low"
Expand All @@ -142,6 +143,16 @@ def extract_pseudo_info(pseudo_text: str) -> PseudoInfo:
z_valence=upf_info["z_valence"],
)

def extract_pseudo_info_from_filename(filename: str) -> PseudoInfo:
"""We give standard filename for PP, so it now can be parsed"""
parts = filename.split('.')

return PseudoInfo(
element=parts[0],
type=parts[1],
functional=parts[2],
z_valence=int(parts[3].split('_')[1])
)

def _get_proper_dual(pp_info: PseudoInfo) -> int:
if pp_info.type == "nc":
Expand Down
14 changes: 8 additions & 6 deletions src/aiida_sssp_workflow/workflows/convergence/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def compute_xy(
do_smearing = True

xs = []
ys = []
ys_eta_c = []
ys_max_diff_c = []
for node_point in report.convergence_list:
if node_point.exit_status != 0:
# TODO: log to a warning file for where the node is not finished_okay
Expand Down Expand Up @@ -220,15 +221,16 @@ def compute_xy(
unit = res.get("unit", None)

# eta_c is the y, others are write into as metadata
ys.append(eta_c)
ys_eta_c.append(eta_c)
ys_max_diff_c.append(max_diff_c)


return {
'x': xs,
'y': ys,
'xs': xs,
'ys': ys_eta_c,
'ys_eta_c': ys_eta_c,
'ys_max_diff_c': ys_max_diff_c,
'metadata': {
'shift_c': shift_c,
'max_diff_c': max_diff_c,
'unit': unit,
}
}
14 changes: 11 additions & 3 deletions src/aiida_sssp_workflow/workflows/convergence/cohesive_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from aiida_pseudo.data.pseudo import UpfData

from aiida_sssp_workflow.utils import get_default_mpi_options
from aiida_sssp_workflow.utils.element import ACTINIDE_ELEMENTS, LANTHANIDE_ELEMENTS
from aiida_sssp_workflow.workflows.convergence.report import ConvergenceReport
from aiida_sssp_workflow.workflows.convergence._base import _BaseConvergenceWorkChain
from aiida_sssp_workflow.workflows.evaluate._cohesive_energy import (
Expand Down Expand Up @@ -160,6 +161,12 @@ def prepare_evaluate_builder(self, ecutwfc, ecutrho) -> ProcessBuilder:
},
}

# XXX: This I have to add here, although not best option to keep
# an condition inside the generic workflow. But for lanthanoids and actinoids
# using large nbnd is the only way to make it converge. Set it to 5 * Z
if self.element in LANTHANIDE_ELEMENTS + ACTINIDE_ELEMENTS:
atom_pw_parameters["SYSTEM"]["nbnd"] = 5 * self.inputs.pseudo.z_valence

atom_kpoints = orm.KpointsData()
atom_kpoints.set_kpoints_mesh([1, 1, 1])

Expand Down Expand Up @@ -196,12 +203,13 @@ def compute_xy(
node = orm.load_node(node_point.uuid)
output_parameters_p: orm.Dict = node.outputs.output_parameters

y = abs((output_parameters_p['cohesive_energy_per_atom'] - y_ref) / y_ref) * 100
y = (output_parameters_p['cohesive_energy_per_atom'] - y_ref) / y_ref * 100
ys.append(y)

return {
'x': xs,
'y': ys,
'xs': xs,
'ys': ys,
'ys_relative_diff': ys,
'metadata': {
'unit': '%',
}
Expand Down
15 changes: 9 additions & 6 deletions src/aiida_sssp_workflow/workflows/convergence/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,20 @@ def prepare_evaluate_builder(self, ecutwfc, ecutrho) -> ProcessBuilder:
return builder

def compute_xy(
report: ConvergenceReport,
node: orm.Node,
) -> dict[str, Any]:
"""From report calculate the xy data, xs are cutoffs and ys are band distance from reference"""
"""From report calculate the xy data, xs are cutoffs and ys are eos from reference"""
report_dict = node.outputs.report.get_dict()
report = ConvergenceReport.construct(**report_dict)

reference_node = orm.load_node(report.reference.uuid)
output_parameters_r: orm.Dict = reference_node.outputs.output_parameters
ref_V0, ref_B0, ref_B1 = output_parameters_r['birch_murnaghan_results']



xs = []
ys = []
ys_nu = []
for node_point in report.convergence_list:
if node_point.exit_status != 0:
# TODO: log to a warning file for where the node is not finished_okay
Expand All @@ -157,11 +160,11 @@ def compute_xy(

y_nu = rel_errors_vec_length(ref_V0, ref_B0, ref_B1, V0, B0, B1)

ys.append(y_nu)
ys_nu.append(y_nu)

return {
'x': xs,
'y': ys,
'xs': xs,
'ys': ys_nu,
'metadata': {
'unit': 'n/a',
}
Expand Down
28 changes: 16 additions & 12 deletions src/aiida_sssp_workflow/workflows/convergence/phonon_frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def compute_xy(
y_ref = output_parameters_r["dynamical_matrix_1"]["frequencies"]

xs = []
ys = []
ys_relative_diff = []
ys_omega_max = []
ys_relative_max_diff = []
for node_point in report.convergence_list:
if node_point.exit_status != 0:
# TODO: log to a warning file for where the node is not finished_okay
Expand All @@ -202,14 +204,11 @@ def compute_xy(
weights = np.array(y_ref)

relative_diff = np.sqrt(np.mean((diffs / weights) ** 2))
y = relative_diff

# XXX: properties that should write down for GUI rendering
# omega_max = np.amax(y_p)
# absolute_diff = np.mean(diffs)
# absolute_max_diff = np.amax(diffs)
#
# relative_max_diff = np.amax(diffs / weights)
omega_max = np.amax(y_p)
absolute_diff = np.mean(diffs)
absolute_max_diff = np.amax(diffs)
relative_max_diff = np.amax(np.abs(diffs / weights))

# Legacy modification required when configuration is `GS` which is not run for convergence anymore
# Keep it here just for reference.
Expand All @@ -227,13 +226,18 @@ def compute_xy(
# else:
# start_idx = 0
#
ys.append(y)
ys_relative_diff.append(relative_diff)
ys_omega_max.append(omega_max)
ys_relative_max_diff.append(relative_max_diff)

return {
'x': xs,
'y': ys,
'xs': xs,
'ys': ys_relative_diff,
'ys_relative_diff': ys_relative_diff,
'ys_omega_max': ys_omega_max,
'ys_relative_max_diff': ys_relative_max_diff,
'metadata': {
'unit': '%',
'unit_default': '%',
}
}

8 changes: 4 additions & 4 deletions src/aiida_sssp_workflow/workflows/convergence/pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,17 @@ def compute_xy(
y_p = output_parameters_p["hydrostatic_stress"]

# calculate the diff
absolute_diff = abs(y_p - y_ref)
diff = y_p - y_ref
relative_diff = _helper_get_volume_from_pressure_birch_murnaghan(
absolute_diff, V0, B0, B1,
diff, V0, B0, B1,
)

y = relative_diff
ys.append(y)

return {
'x': xs,
'y': ys,
'xs': xs,
'ys': ys,
'metadata': {
'unit': '%',
}
Expand Down
22 changes: 21 additions & 1 deletion src/aiida_sssp_workflow/workflows/transferability/eos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""Workchain to calculate delta factor of specific psp"""
from typing import Tuple
from typing import Tuple, Any
from pathlib import Path

from aiida import orm
Expand Down Expand Up @@ -454,3 +454,23 @@ def inspect_transferability(self):
def _finalize(self):
"""calculate the delta factor"""
# TODO: see what need to be added here

def extract_eos(
node: orm.Node,
) -> Tuple[dict[str, Any], dict[str, Any]]:
"""From report calculate the xy data, xs are cutoffs and ys are cohesive energy diff from reference"""
report_dict = node.outputs.report.get_dict()
report = EOSReport.construct(**report_dict)

raw_eos = {}
metric_dict = {}
for k, v in report.eos_dict.items():
point_node = orm.load_node(v.uuid)
if point_node.exit_status != 0:
# TODO: log to a warning file for where the node is not finished_okay
continue

raw_eos[k] = point_node.outputs.eos.output_volume_energy.get_dict()
metric_dict[k] = point_node.outputs.output_parameters.get_dict()

return raw_eos, metric_dict
16 changes: 16 additions & 0 deletions tests/utils/test_pseudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_pseudo_O,
get_pseudo_N,
CurateType,
extract_pseudo_info_from_filename,
)

upf_folder = Path(__file__).parent.parent / "_statics" / "upf"
Expand Down Expand Up @@ -82,3 +83,18 @@ def test_compute_total_nelectrons():
)
def test_get_dual_type(element, pp_type, expected_dual_type):
assert get_dual_type(pp_type, element) == expected_dual_type


@pytest.mark.parametrize(
"filename, element, functional, z_valence, pp_type",
[
('Ti.us.pbe.z_12.uspp.gbrv.v1.4.upf', 'Ti', 'pbe', 12, 'us'),
]
)
def test_extract_pseudo_info_from_filename(filename, element, functional, z_valence, pp_type):
pseudo_info = extract_pseudo_info_from_filename(filename)

assert pseudo_info.element == element
assert pseudo_info.type == pp_type
assert pseudo_info.functional == functional
assert pseudo_info.z_valence == z_valence

0 comments on commit d534af0

Please sign in to comment.