Skip to content

Commit

Permalink
Fix tests and update eigenvalues parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha committed Aug 23, 2023
1 parent 9df5cb2 commit 14b68d0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 481 deletions.
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 "subspace spin" in line and "owest" not in 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"]:
splitted_line = line.split()
try:
result_dict[line_is] += [float(x) for x in splitted_line]
except ValueError:
if "fermi energy" in line.lower():
line_is = None
else:
continue
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

0 comments on commit 14b68d0

Please sign in to comment.