Skip to content

Commit

Permalink
Fea/xx/analyze on element very (#236)
Browse files Browse the repository at this point in the history
* Add CLI for analyze element result in a bar figure

* Add eiger computers configure

* Analyse on-element
  • Loading branch information
unkcpz authored Jan 22, 2024
1 parent 56de70a commit 7c5f309
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
42 changes: 30 additions & 12 deletions aiida_sssp_workflow/cli/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ def convergence_plot(
@cmd_root.command("analyze")
@click.argument("group") # The group to inspect, name or pk of the group
@click.option("--output", "-o", default="output", help="The output file name")
def analyze(group, output):
@click.option(
"--ylimit", "-y", default=0.5, help="The y limit for the plot", type=float
)
def analyze(group, output, ylimit):
"""Render the plot for the given pseudos and measure type."""
from aiida_sssp_workflow.utils import ACWF_CONFIGURATIONS, parse_label

Expand Down Expand Up @@ -281,7 +284,7 @@ def analyze(group, output):
ax.text(0 - d, 0.33 + d, "0.33 good agreement", color="black")
ax.legend(loc="upper right", prop={"size": 10})
ax.set_ylabel("ν -factor")
ax.set_ylim([0, 0.5])
ax.set_ylim([0, ylimit])

xticks_shift = len(nodes_lst) * width / 2
xticks = [i + xticks_shift for i in range(len(ACWF_CONFIGURATIONS))]
Expand Down Expand Up @@ -367,7 +370,10 @@ def inspect(node, output):
# A4 canvas for plot
# landscape mode, shoulder to shoulder for ecutwfc and ecutrho for each property
# five rows for five properties
rows = len(wf_node.outputs.convergence)

# always plot 5 rows if the result is not accessable, add a text to indicate the property is not calculated
# rows = len(wf_node.outputs.convergence)
rows = 5
fig, axs = plt.subplots(
rows,
2,
Expand All @@ -378,12 +384,19 @@ def inspect(node, output):
subplot_index = 0

for property in [
"bands",
"cohesive_energy",
"pressure",
"delta",
"phonon_frequencies",
"cohesive_energy",
"bands",
]:
# plot to the ax
# ax1 on the left for ecutwfc
# ax2 on the right for ecutrho
# the ratio of the width is 3:1
ax1 = axs.flat[subplot_index]
ax2 = axs.flat[subplot_index + 1]

# print summary of the convergence to a json file
try:
convergence = wf_node.outputs.convergence[property]
Expand All @@ -392,6 +405,18 @@ def inspect(node, output):
f"Property {property} is not calculated for this workflow",
fg="red",
)
# add to ax1 and ax2 with a red text to indicate the property is not calculated
ax1.text(
0.5,
0.5,
f"Convergence test of {property} is not run or failed.",
color="red",
)
ax1.set_axis_off()
ax2.set_axis_off()
# jump to the next row
subplot_index += 2

continue

cutoff_control_protocol = wf_node.inputs.convergence.cutoff_control.value
Expand Down Expand Up @@ -443,13 +468,6 @@ def inspect(node, output):

convergence_summary[property] = property_summary

# plot to the ax
# ax1 on the left for ecutwfc
# ax2 on the right for ecutrho
# the ratio of the width is 3:1
ax1 = axs.flat[subplot_index]
ax2 = axs.flat[subplot_index + 1]

# data preparation
# Will only plot the measured properties e.g. for bands it is the eta_c
_ConvergenceWorkChain = WorkflowFactory(
Expand Down
14 changes: 8 additions & 6 deletions aiida_sssp_workflow/workflows/evaluate/_bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class BandsWorkChain(_BaseEvaluateWorkChain):

# maximum number of bands factor increase loop
# to prevent the infinite loop in bands evaluation
_MAX_NUM_BANDS_FACTOR = 5
# If start from 1.5, and increase 2.0 every time, it will reach 11.5 at most.
_MAX_INCREMENT_BANDS_FACTOR = 10
_BANDS_FACTOR_INCREASE_STEP = 2.0

@classmethod
def define(cls, spec):
Expand Down Expand Up @@ -108,7 +110,7 @@ def define(cls, spec):
spec.exit_code(201, 'ERROR_SUB_PROCESS_FAILED_BANDS',
message='The `PwBandsWorkChain` sub process failed.')
spec.exit_code(203, 'ERROR_REACH_MAX_BANDS_FACTOR_INCREASE_LOOP',
message=f'The maximum number={cls._MAX_NUM_BANDS_FACTOR} of bands factor'
message=f'The maximum number={cls._MAX_INCREMENT_BANDS_FACTOR} of bands factor'
'increase loop reached, but still cannot get enough bands.')
spec.exit_code(204, 'ERROR_KPOINTS_DISTANCE_BAND_STRUCTURE_NOT_SET',
message=f'kpoints distance is not set in inputs.')
Expand Down Expand Up @@ -197,11 +199,11 @@ def increase_nbands(self):
#
# If the bands evaluation failed it will keeps on increasing the `nbands_factor`
# which lead to the infinite loop to this work chain.
# Here I work around it by giving maximum nbands_factor loop to _MAX_NUM_BANDS_FACTOR=5.
# Here I work around it by giving maximum nbands_factor loop to _MAX_INCREMENT_BANDS_FACTOR=10.
# And add a `break_increase_nbands` to break and get out from `should_run_bands` immediately.
if (
self.ctx.nbands_factor
> self.inputs.init_nbands_factor.value + self._MAX_NUM_BANDS_FACTOR
> self.inputs.init_nbands_factor.value + self._MAX_INCREMENT_BANDS_FACTOR
):
return self.exit_codes.ERROR_REACH_MAX_BANDS_FACTOR_INCREASE_LOOP

Expand All @@ -210,9 +212,9 @@ def increase_nbands(self):
# I should not increase it anyway because this ctx is used
# for the input of band structure calculation.
self.report(
f"increasing nbands_factor to from {self.ctx.nbands_factor} to {self.ctx.nbands_factor + 1.0}"
f"increasing nbands_factor to from {self.ctx.nbands_factor} to {self.ctx.nbands_factor + self._BANDS_FACTOR_INCREASE_STEP}"
)
self.ctx.nbands_factor += 1.0
self.ctx.nbands_factor += self._BANDS_FACTOR_INCREASE_STEP

def should_run_band_structure(self):
"""whether run band structure"""
Expand Down
2 changes: 1 addition & 1 deletion aiida_sssp_workflow/workflows/evaluate/_eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def inspect_eos(self):
self.out("output_volume_energy", output_volume_energy)

output_birch_murnaghan_fit, node = run_get_node(
birch_murnaghan_fit, output_volume_energy
birch_murnaghan_fit, volume_energy=output_volume_energy
)

if not node.is_finished_ok:
Expand Down
2 changes: 1 addition & 1 deletion aiida_sssp_workflow/workflows/measure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class _BaseMeasureWorkChain(SelfCleanWorkChain):

# ECUT for oxygen, remember to update this if the oxygen pseudo is changed
# Currently the oxygen pseudo is `O.paw.z_6.ld1.psl.v0.1.upf`
_O_ECUTWFC = 75.0
_O_ECUTWFC = 70.0
_O_ECUTRHO = 560.0

# ECUT for nitrogen, remember to update this if the nitrogen pseudo is changed
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ project_urls =
[options]
packages = find:
install_requires =
aiida-core[atomic_tools]~=2.4.0
aiida-core[atomic_tools]~=2.4
aiida-quantumespresso~=4.3.0
python_requires = >=3.8
include_package_data = True
Expand Down

0 comments on commit 7c5f309

Please sign in to comment.