From 22e93898e35add71ffbeccf4897d8d55c2a08acc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 26 Jan 2025 11:33:56 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- aiida_cp2k/calculations/__init__.py | 6 +++++- aiida_cp2k/parsers/__init__.py | 8 ++++++-- aiida_cp2k/utils/__init__.py | 4 ++-- aiida_cp2k/utils/input_generator.py | 2 ++ aiida_cp2k/utils/workchains.py | 13 ++++++++----- aiida_cp2k/workchains/base.py | 5 ++--- .../example_base_geo_opt_ignore_converge_restart.py | 10 +++++----- 7 files changed, 30 insertions(+), 18 deletions(-) diff --git a/aiida_cp2k/calculations/__init__.py b/aiida_cp2k/calculations/__init__.py index f9f2103..e623de8 100644 --- a/aiida_cp2k/calculations/__init__.py +++ b/aiida_cp2k/calculations/__init__.py @@ -205,7 +205,11 @@ def define(cls, spec): "ERROR_OUT_OF_WALLTIME", message="The calculation stopped prematurely because it ran out of walltime.", ) - spec.exit_code(450, "ERROR_SCF_NOT_CONVERGED", message="SCF cycle did not converge for thegiven threshold.") + spec.exit_code( + 450, + "ERROR_SCF_NOT_CONVERGED", + message="SCF cycle did not converge for thegiven threshold.", + ) spec.exit_code( 500, "ERROR_GEOMETRY_CONVERGENCE_NOT_REACHED", diff --git a/aiida_cp2k/parsers/__init__.py b/aiida_cp2k/parsers/__init__.py index 04e3187..bcf901f 100644 --- a/aiida_cp2k/parsers/__init__.py +++ b/aiida_cp2k/parsers/__init__.py @@ -98,7 +98,11 @@ def _parse_final_structure(self): def _check_stdout_for_errors(self, output_string): """This function checks the CP2K output file for some basic errors.""" - if "ABORT" in output_string and "SCF run NOT converged. To continue the calculation regardless" in output_string: + if ( + "ABORT" in output_string + and "SCF run NOT converged. To continue the calculation regardless" + in output_string + ): return self.exit_codes.ERROR_SCF_NOT_CONVERGED if "ABORT" in output_string: @@ -109,7 +113,7 @@ def _check_stdout_for_errors(self, output_string): if "PROGRAM STOPPED IN" not in output_string: return self.exit_codes.ERROR_OUTPUT_INCOMPLETE - + if "SCF run NOT converged ***" in output_string: return self.exit_codes.ERROR_SCF_NOT_CONVERGED diff --git a/aiida_cp2k/utils/__init__.py b/aiida_cp2k/utils/__init__.py index c92434e..a4b802c 100644 --- a/aiida_cp2k/utils/__init__.py +++ b/aiida_cp2k/utils/__init__.py @@ -14,8 +14,8 @@ Cp2kInput, add_ext_restart_section, add_first_snapshot_in_reftraj_section, - add_wfn_restart_section, add_ignore_convergence_failure, + add_wfn_restart_section, ) from .parser import parse_cp2k_output, parse_cp2k_output_advanced, parse_cp2k_trajectory from .workchains import ( @@ -24,11 +24,11 @@ check_resize_unit_cell, get_input_multiplicity, get_kinds_section, + get_last_convergence_value, merge_dict, merge_Dict, ot_has_small_bandgap, resize_unit_cell, - get_last_convergence_value, ) __all__ = [ diff --git a/aiida_cp2k/utils/input_generator.py b/aiida_cp2k/utils/input_generator.py index 85dd684..2210e49 100644 --- a/aiida_cp2k/utils/input_generator.py +++ b/aiida_cp2k/utils/input_generator.py @@ -230,6 +230,8 @@ def add_first_snapshot_in_reftraj_section(input_dict, first_snapshot): params = input_dict.get_dict() params["MOTION"]["MD"]["REFTRAJ"]["FIRST_SNAPSHOT"] = first_snapshot return Dict(params) + + @calcfunction def add_ignore_convergence_failure(input_dict): """Add IGNORE_CONVERGENCE_FAILURE for non converged SCF runs.""" diff --git a/aiida_cp2k/utils/workchains.py b/aiida_cp2k/utils/workchains.py index 6110c88..f44eac6 100644 --- a/aiida_cp2k/utils/workchains.py +++ b/aiida_cp2k/utils/workchains.py @@ -7,6 +7,7 @@ """AiiDA-CP2K utilities for workchains""" import re + from aiida.engine import calcfunction from aiida.orm import Dict from aiida.plugins import DataFactory @@ -100,11 +101,12 @@ def ot_has_small_bandgap(cp2k_input, cp2k_output, bandgap_thr_ev): is_bandgap_small = min_bandgap_ev < bandgap_thr_ev return using_ot and is_bandgap_small + def get_last_convergence_value(input_string): """ Search for last "OT CG" and returns the SCF gradient. If no "OT CG", searches for last "DIIS/Diag" and returns the gradient. - + Args: input_string (str): the cp2k output string. @@ -114,19 +116,20 @@ def get_last_convergence_value(input_string): # Search all "OT CG" lines and gets the 6th column ot_cg_pattern = r"OT CG\s+\S+\s+\S+\s+\S+\s+\S+\s+([\d.E+-]+)" ot_cg_matches = re.findall(ot_cg_pattern, input_string) - + if ot_cg_matches: return float(ot_cg_matches[-1]) # Last value found for "OT CG" - + # Search for "DIIS/Diag" lines and returns the 5th column diis_diag_pattern = r"DIIS/Diag\.\s+\S+\s+\S+\s+\S+\s+([\d.E+-]+)" diis_diag_matches = re.findall(diis_diag_pattern, input_string) - + if diis_diag_matches: return float(diis_diag_matches[-1]) # RLast value found for "DIIS/Diag" - + return None # No value found + @calcfunction def check_resize_unit_cell(struct, threshold): """Returns the multiplication factors for the cell vectors to respect, in every direction: diff --git a/aiida_cp2k/workchains/base.py b/aiida_cp2k/workchains/base.py index 9aa7a59..cfb1676 100644 --- a/aiida_cp2k/workchains/base.py +++ b/aiida_cp2k/workchains/base.py @@ -83,7 +83,7 @@ def overwrite_input_structure(self): def restart_incomplete_calculation(self, calc): """This handler restarts incomplete calculations.""" content_string = calc.outputs.retrieved.base.repository.get_object_content(calc.base.attributes.get('output_filename')) - + # Check if time wase exceeded walltime_exceeded = calc.exit_status == Cp2kCalculation.exit_codes.ERROR_OUT_OF_WALLTIME.status @@ -104,7 +104,7 @@ def restart_incomplete_calculation(self, calc): params = self.ctx.inputs.parameters params = utils.add_wfn_restart_section(params, orm.Bool('kpoints' in self.ctx.inputs)) - + # After version 9.1 Check if calculation aborted due to SCF convergence failure and in case ignore_convergence_failure is set scf_gradient = utils.get_last_convergence_value(content_string) scf_restart_thr = 1e-5 # if ABORT for not SCF convergence, but RMS gradient is small, continue @@ -131,4 +131,3 @@ def restart_incomplete_calculation(self, calc): "The CP2K calculation wasn't completed. The restart of the calculation might be able to " "fix the problem.") return engine.ProcessHandlerReport(False) - diff --git a/examples/workchains/example_base_geo_opt_ignore_converge_restart.py b/examples/workchains/example_base_geo_opt_ignore_converge_restart.py index ad8cad1..c588fb5 100644 --- a/examples/workchains/example_base_geo_opt_ignore_converge_restart.py +++ b/examples/workchains/example_base_geo_opt_ignore_converge_restart.py @@ -47,7 +47,7 @@ def example_base(cp2k_code): { "GLOBAL": { "RUN_TYPE": "GEO_OPT", - "WALLTIME": "00:02:30", + "WALLTIME": "00:02:30", }, "FORCE_EVAL": { "METHOD": "Quickstep", @@ -74,10 +74,10 @@ def example_base(cp2k_code): "PSOLVER": "MT", }, "SCF": { - "MAX_SCF" : 10, # not enough to converge - "EPS_SCF" : "1.e-6", - "PRINT": {"RESTART": {"_": "ON"}} - }, + "MAX_SCF": 10, # not enough to converge + "EPS_SCF": "1.e-6", + "PRINT": {"RESTART": {"_": "ON"}}, + }, }, "SUBSYS": { "KIND": [