Skip to content

Commit 1c2ab95

Browse files
committed
workflow for running magnetization
1 parent b732560 commit 1c2ab95

File tree

7 files changed

+650
-12
lines changed

7 files changed

+650
-12
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
standard:
3+
name: acwf
4+
description: Delta measure parameters compatible with AiiDA common workflow
5+
6+
occupations: smearing
7+
degauss: 0.0045
8+
smearing: fd
9+
conv_thr_per_atom: 1.0e-9
10+
kpoints_distance: 0.06
11+
mixing_beta: 0.4
12+
13+
balanced:
14+
name: balanced
15+
description: The balanced protocol from Gabriel
16+
17+
occupations: smearing
18+
degauss: 0.02
19+
smearing: fd
20+
conv_thr_per_atom: 1.0e-8
21+
kpoints_distance: 0.2
22+
mixing_beta: 0.4
23+
24+
test:
25+
name: test-only
26+
description: light loose set for test
27+
28+
occupations: smearing
29+
degauss: 0.0045
30+
smearing: fd
31+
conv_thr_per_atom: 1.0e-6
32+
kpoints_distance: 0.5
33+
mixing_beta: 0.4
34+
scale_count: 5
35+
scale_increment: 0.02
36+
37+
opsp:
38+
name: opsp
39+
description: For OPSP verifications
40+
41+
occupations: smearing
42+
degauss: 0.0045
43+
smearing: fd
44+
conv_thr_per_atom: 1.0e-8
45+
kpoints_distance: 0.06
46+
mixing_beta: 0.4
47+
scale_count: 5
48+
scale_increment: 0.03

src/aiida_sssp_workflow/utils/structure.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
ACWF_CONFIGURATIONS # FIXME: should also have GS for bands and LANN
1818
)
1919

20+
@calcfunction
21+
def scale_structure(
22+
structure: orm.StructureData, scale_factor: orm.Float
23+
) -> orm.StructureData:
24+
"""Scale the structure with the given scaling factor."""
25+
ase = structure.get_ase().copy()
26+
ase.set_cell(ase.get_cell() * float(scale_factor) ** (1 / 3), scale_atoms=True)
27+
return orm.StructureData(ase=ase)
28+
2029

2130
@calcfunction
2231
def get_default_configuration(element: orm.Str, property: orm.Str) -> orm.Str:

src/aiida_sssp_workflow/workflows/evaluate/_eos.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,14 @@
44
from typing import List
55

66
from aiida import orm
7-
from aiida.engine import WorkChain, append_, calcfunction, run_get_node
7+
from aiida.engine import WorkChain, append_, run_get_node
88
from aiida.plugins import CalculationFactory, WorkflowFactory
99

10+
from aiida_sssp_workflow.utils.structure import scale_structure
11+
1012
PwBaseWorkChain = WorkflowFactory("quantumespresso.pw.base")
1113
birch_murnaghan_fit = CalculationFactory("sssp_workflow.birch_murnaghan_fit")
1214

13-
14-
@calcfunction
15-
def scale_structure(
16-
structure: orm.StructureData, scale_factor: orm.Float
17-
) -> orm.StructureData:
18-
"""Scale the structure with the given scaling factor."""
19-
ase = structure.get_ase().copy()
20-
ase.set_cell(ase.get_cell() * float(scale_factor) ** (1 / 3), scale_atoms=True)
21-
return orm.StructureData(ase=ase)
22-
23-
2415
class _EquationOfStateWorkChain(WorkChain):
2516
"""Workflow to compute the equation of state for a given crystal structure."""
2617

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
A calcfunctian create_isolate_atom
4+
Create the structure of isolate atom
5+
"""
6+
7+
from aiida import orm
8+
from aiida.engine import ToContext, calcfunction
9+
from aiida.plugins import DataFactory, WorkflowFactory
10+
11+
from . import _BaseEvaluateWorkChain
12+
13+
PwBaseWorkChain = WorkflowFactory("quantumespresso.pw.base")
14+
UpfData = DataFactory("pseudo.upf")
15+
16+
17+
@calcfunction
18+
def helper_get_hydrostatic_stress(output_trajectory, output_parameters):
19+
"""
20+
doc
21+
"""
22+
import numpy as np
23+
24+
output_stress = output_trajectory.get_array("stress")[0]
25+
stress_unit = output_parameters["stress_units"]
26+
hydrostatic_stress = np.trace(output_stress) / 3.0
27+
return orm.Dict(
28+
dict={
29+
"stress_unit": stress_unit,
30+
"hydrostatic_stress": hydrostatic_stress,
31+
}
32+
)
33+
34+
35+
class MagnetizationWorkChain(_BaseEvaluateWorkChain):
36+
"""WorkChain to calculate magnetization of input structure"""
37+
38+
@classmethod
39+
def define(cls, spec):
40+
"""Define the process specification."""
41+
# yapf: disable
42+
super().define(spec)
43+
spec.input('structure', valid_type=orm.StructureData,
44+
help='Ground state structure which the verification perform')
45+
spec.input_namespace('pseudos', valid_type=UpfData, dynamic=True,
46+
help='A mapping of `UpfData` nodes onto the kind name to which they should apply.')
47+
spec.expose_inputs(PwBaseWorkChain, exclude=["pw.structure", "pw.pseudos"])
48+
49+
spec.outline(
50+
cls.run_scf,
51+
cls.inspect_scf,
52+
cls.finalize,
53+
)
54+
spec.output('output_parameters', valid_type=orm.Dict, required=True,
55+
help='The output parameters include pressure of the structure.')
56+
57+
# yapf: enable
58+
59+
def run_scf(self):
60+
"""
61+
set the inputs and submit scf
62+
"""
63+
inputs = self.exposed_inputs(PwBaseWorkChain)
64+
inputs["pw"]["structure"] = self.inputs.structure
65+
inputs["pw"]["pseudos"] = self.inputs.pseudos
66+
67+
running = self.submit(PwBaseWorkChain, **inputs)
68+
self.report(f"Running pw scf calculation pk={running.pk}")
69+
70+
return ToContext(workchain_scf=running)
71+
72+
def inspect_scf(self):
73+
"""inspect the result of scf calculation."""
74+
workchain = self.ctx.workchain_scf
75+
76+
if workchain.is_finished:
77+
self._disable_cache(workchain)
78+
79+
if not workchain.is_finished_ok:
80+
self.report(
81+
f"PwBaseWorkChain for pressure evaluation failed with exit status {workchain.exit_status}"
82+
)
83+
return self.exit_codes.ERROR_SUB_PROCESS_FAILED_SCF
84+
85+
output_trajectory = workchain.outputs.output_trajectory
86+
output_parameters = workchain.outputs.output_parameters
87+
88+
# Return the output parameters of current workchain
89+
output_parameters = helper_get_hydrostatic_stress(
90+
output_trajectory, output_parameters
91+
)
92+
93+
self.out("output_parameters", output_parameters)
94+
95+
def finalize(self):
96+
"""set ecutwfc and ecutrho"""

src/aiida_sssp_workflow/workflows/list_run/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)