Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update output parser, improve tests. #184

Merged
merged 10 commits into from
Aug 24, 2023
42 changes: 19 additions & 23 deletions aiida_cp2k/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def parse_cp2k_output_advanced(
result_dict["spin_square_expectation"] = []
result_dict["spin_square_expectation"].append(float(s2_expect))

# read the number of electrons in the first scf (NOTE: it may change but it is not updated!)
# Read the number of electrons in the first scf (NOTE: it may change but it is not updated!)
if re.search("Number of electrons: ", line):
if "init_nel_spin1" not in result_dict.keys():
result_dict["init_nel_spin1"] = int(line.split()[3])
Expand All @@ -100,17 +100,6 @@ def parse_cp2k_output_advanced(
if re.search("Smear method", line):
result_dict["smear_method"] = line.split()[-1]

if re.search(r"subspace spin", line):
if int(line.split()[-1]) == 1:
line_is = "eigen_spin1_au"
if "eigen_spin1_au" not in result_dict.keys():
result_dict["eigen_spin1_au"] = []
elif int(line.split()[-1]) == 2:
line_is = "eigen_spin2_au"
if "eigen_spin2_au" not in result_dict.keys():
result_dict["eigen_spin2_au"] = []
continue

# Parse warnings
if re.search(r"Using a non-square number of", line):
result_dict["warnings"].append("Using a non-square number of MPI ranks")
Expand All @@ -121,18 +110,25 @@ def parse_cp2k_output_advanced(
if re.search(r"Specific L-BFGS convergence criteria", line):
result_dict["warnings"].append("LBFGS converged with specific criteria")

# Parse eigenvalues.
if "subspace spin" in line and "owest" not in line:
if int(line.split()[-1]) == 1:
line_is = "eigen_spin1_au"
result_dict["eigen_spin1_au"] = []
elif int(line.split()[-1]) == 2:
line_is = "eigen_spin2_au"
result_dict["eigen_spin2_au"] = []
continue

# If a tag has been detected, now read the following line knowing what they are
if line_is is not None:
# Read eigenvalues as 4-columns row, then convert to float
if line_is in ["eigen_spin1_au", "eigen_spin2_au"]:
if re.search(r"-------------", line) or re.search(
r"Reached convergence", line
):
continue
if line.split() and len(line.split()) <= 4:
result_dict[line_is] += [float(x) for x in line.split()]
else:
line_is = None
if line_is in ["eigen_spin1_au", "eigen_spin2_au"]:
if "------" in line:
continue
splitted_line = line.split()
try:
result_dict[line_is] += [float(x) for x in splitted_line]
except ValueError:
line_is = None

####################################################################
# THIS SECTION PARSES THE PROPERTIES AT GOE_OPT/CELL_OPT/MD STEP #
Expand Down
Loading
Loading