Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/aiida_epw/tools/workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,23 @@ def get_default_target_basepath(computer):
else:
raise ValueError(f"Unsupported transport type: {computer.transport_type}")
return target_basepath


def set_auto_temps(
parameters, allen_dynes_tc, lower_bound=0.5, upper_bound=2.0, nstemp=10
):
"""Automatically set EPW calculation temps parameter from Allen-Dynes critical temperature of a previous calculation.

If `temps` is not specified or is None in inputs.parameters['INPUTEPW'],
it sets `nstemp` to 10 and `temps` to be a range between 0.5 * Tc and 2.0 * Tc.
"""
inputepw = parameters.setdefault("INPUTEPW", {})

if "temps" not in inputepw or inputepw.get("temps") is None:
tmin = lower_bound * allen_dynes_tc
tmax = upper_bound * allen_dynes_tc

inputepw["nstemp"] = nstemp
inputepw["temps"] = f"{tmin:.4f} {tmax:.4f}"

return parameters
18 changes: 15 additions & 3 deletions src/aiida_epw/workflows/supercon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from aiida_epw.calculations.epw import serialize_restart_type
from aiida_epw.workflows.base import EpwBaseWorkChain
from aiida_epw.data import A2fData
from aiida_epw.tools.workchain import set_auto_temps

from aiida.engine import calcfunction

Expand Down Expand Up @@ -462,6 +463,10 @@ def run_final_epw_iso(self):
inputs = AttributeDict(
self.exposed_inputs(EpwBaseWorkChain, namespace="epw_final_iso")
)
allen_dynes_tc = self.ctx.epw_interp[-1].outputs.output_parameters[
"Allen_Dynes_Tc"
]
new_parameters = set_auto_temps(inputs.parameters.get_dict(), allen_dynes_tc)

inputs.structure = self.inputs.structure
parent_folder_epw = self.ctx.epw_interp[-1].outputs.remote_folder
Expand All @@ -472,9 +477,9 @@ def run_final_epw_iso(self):
inputs.restart_type = serialize_restart_type("ephread")

if self.ctx.degaussq:
parameters = inputs.parameters.get_dict()
parameters["INPUTEPW"]["degaussq"] = self.ctx.degaussq
inputs.parameters = orm.Dict(parameters)
new_parameters["INPUTEPW"]["degaussq"] = self.ctx.degaussq

inputs.parameters = orm.Dict(new_parameters)

inputs.metadata.call_link_label = "epw_final_iso"

Expand All @@ -501,6 +506,11 @@ def run_final_epw_aniso(self):
self.exposed_inputs(EpwBaseWorkChain, namespace="epw_final_aniso")
)

allen_dynes_tc = self.ctx.epw_interp[-1].outputs.output_parameters[
"Allen_Dynes_Tc"
]
new_parameters = set_auto_temps(inputs.parameters.get_dict(), allen_dynes_tc)

inputs.structure = self.inputs.structure
parent_folder_epw = self.ctx.epw_interp[-1].outputs.remote_folder
inputs.parent_folder_epw = parent_folder_epw
Expand All @@ -509,6 +519,8 @@ def run_final_epw_aniso(self):

inputs.restart_type = serialize_restart_type("ephread")

inputs.parameters = orm.Dict(new_parameters)

inputs.metadata.call_link_label = "epw_final_aniso"
workchain_node = self.submit(EpwBaseWorkChain, **inputs)
self.report(
Expand Down
22 changes: 22 additions & 0 deletions tests/tools/test_workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,25 @@ def get_configuration(self):

ssh_computer = MockSshComputer()
assert get_default_target_basepath(ssh_computer) == "/remote/testuser/stash"


def test_set_auto_temps():
"""Test set_auto_temps correctly parses Allen_Dynes_Tc and configures input parameters."""
from aiida_epw.tools.workchain import set_auto_temps

# 1. Mock parameters and tc
parameters = {"INPUTEPW": {}}
allen_dynes_tc = 12.0

# 2. Run set_auto_temps
result = set_auto_temps(parameters, allen_dynes_tc)

# 3. Assert outputs
assert result["INPUTEPW"]["nstemp"] == 10
assert result["INPUTEPW"]["temps"] == "6.0000 24.0000"

# 4. Assert that if temps is already defined, it is not overwritten
params_predefined = {"INPUTEPW": {"temps": "5.0000 45.0000", "nstemp": 40}}
result_predefined = set_auto_temps(params_predefined, allen_dynes_tc)
assert result_predefined["INPUTEPW"]["nstemp"] == 40
assert result_predefined["INPUTEPW"]["temps"] == "5.0000 45.0000"
Loading