Skip to content

Commit

Permalink
typos and restyling
Browse files Browse the repository at this point in the history
  • Loading branch information
cpignedoli committed Jan 26, 2025
2 parents 2850ce1 + 22e9389 commit a2af13f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
6 changes: 5 additions & 1 deletion aiida_cp2k/calculations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 the given 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",
Expand Down
8 changes: 6 additions & 2 deletions aiida_cp2k/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions aiida_cp2k/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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__ = [
Expand Down
2 changes: 2 additions & 0 deletions aiida_cp2k/utils/input_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
13 changes: 8 additions & 5 deletions aiida_cp2k/utils/workchains.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion aiida_cp2k/workchains/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,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)

Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand Down

0 comments on commit a2af13f

Please sign in to comment.