Updated tools/diff_cp2k.py (#3926)

- Split ENERGY line along white spaces and take the last item.
- Some code comments (terminal colors).
This commit is contained in:
Hans Pabst 2025-01-31 11:12:04 +01:00 committed by GitHub
parent 44d3f296a0
commit 0974da54a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -86,8 +86,9 @@ def read_file(filename, field, special_keys, stats_keys):
if "NAMEOUT=" in line:
nameout[0] = line.split("=", 2)[1].strip()
continue
if "ENERGY| Total FORCE_EVAL ( QS ) energy " in line:
nameout[1] = line.split(":", 2)[1].strip()
if "ENERGY| Total FORCE_EVAL ( QS ) energy" in line:
split = line.split()
nameout[1] = split[-1] # last item
continue
if "DBCSR STATISTICS" not in line and nstats == 0:
continue
@ -136,18 +137,18 @@ def print_value(ref, value, show_comp):
comp = (value - ref) / ref * 100
else:
comp = float("Inf")
color = "\033[0m"
endc = "\033[0m"
color = "\033[0m" # reset
nocol = "\033[0m" # reset
if comp > 0:
color = "\033[92m"
color = "\033[92m" # green
elif comp < 0:
color = "\033[94m"
color = "\033[94m" # blue
if abs(comp) > 100:
color += "\033[1m"
color += "\033[1m" # bold
if show_comp:
sys.stdout.write(color + "%10.3f" % value + "%5.0f" % comp + endc)
sys.stdout.write(color + "%10.3f" % value + "%5.0f" % comp + nocol)
else:
sys.stdout.write(color + "%10.3f" % value + endc)
sys.stdout.write(color + "%10.3f" % value + nocol)
#################
@ -272,17 +273,17 @@ def main():
ref = 0
if len(files[args.file_lists[args.base - 1]][1]) > 0:
ref = float(files[args.file_lists[args.base - 1]][1])
color = "\033[0m"
endc = "\033[0m"
color = "\033[0m" # reset
nocol = "\033[0m" # reset
for filename in args.file_lists:
if len(files[filename][1]) > 0 and ref != 0:
comp = (float(files[filename][1]) - ref) / ref
if abs(comp) > 1e-14:
color = "\033[91m"
color = "\033[91m" # red
else:
color = "\033[0m"
color = "\033[0m" # reset
print(
("{0} ==> {1} : {2} : " + color + "{3}" + endc).format(
("{0} ==> {1} : {2} : " + color + "{3}" + nocol).format(
files[filename][0],
filename,
files[filename][1],