Skip to content

Commit a819dea

Browse files
authored
Support parsing for CP2K 2025 output format (#95)
* Fix regex pattern for SCF run convergence * Update atomic forces regex patterns for parsing * Fix regex pattern for energy extraction * Add files via upload * add test case for CP2K 2025 support
1 parent f108922 commit a819dea

8 files changed

Lines changed: 1249 additions & 5 deletions

File tree

cp2kdata/block_parser/cells.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def parse_all_md_cells(output_file: List[str],
9595
# notice that the cell of step 0 is excluded from MD| block
9696

9797
# choose parser according to cp2k_info.version
98-
if cp2k_info.version in ['9.1', '2022.2', '2023.1', '2023.2', '2024.1']:
98+
if cp2k_info.version in ['9.1', '2022.2', '2023.1', '2023.2', '2024.1', '2024.2', '2025.1', '2025.2']:
9999
ALL_MD_CELL_RE = ALL_MD_CELL_RE_V2023
100100
elif cp2k_info.version in ['7.1']:
101101
ALL_MD_CELL_RE = ALL_MD_CELL_RE_V7

cp2kdata/block_parser/energies.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
ENERGIES_RE = re.compile(
55
r"""
6-
\sENERGY\|\sTotal\sFORCE_EVAL\s\(\sQS\s\)\senergy\s\S{6}:\s+(?P<energy>[\s-]\d+\.\d+)
6+
^\s*ENERGY\|\s+Total\s+FORCE_EVAL\s+\(\s*QS\s*\)\s+energy
7+
(?:\s+[\[\(][^\]\)]+[\]\)])?
8+
\s*:?\s+(?P<energy>[-+]?\d+\.\d+(?:[Ee][+-]?\d+)?)
79
""",
8-
re.VERBOSE
10+
re.VERBOSE | re.MULTILINE
911
)
1012

1113

cp2kdata/block_parser/forces.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
re.VERBOSE
2020
)
2121

22+
FORCES_HEADER_RE = re.compile(
23+
r"^\s*FORCES\|\s+Atomic\s+forces\s+\[.*\]\s*$",
24+
re.MULTILINE
25+
)
26+
2227

2328
def parse_atomic_forces_list(output_file):
2429
atomic_forces_list = []
@@ -29,5 +34,33 @@ def parse_atomic_forces_list(output_file):
2934
atomic_forces_list.append(atomic_forces)
3035
if atomic_forces_list:
3136
return np.array(atomic_forces_list, dtype=float)
32-
else:
33-
return None
37+
38+
atomic_forces_list = []
39+
lines = output_file.splitlines()
40+
in_block = False
41+
current = []
42+
for line in lines:
43+
if FORCES_HEADER_RE.match(line):
44+
in_block = True
45+
current = []
46+
continue
47+
if in_block:
48+
if line.lstrip().startswith("FORCES|"):
49+
parts = line.split()
50+
if len(parts) >= 5 and parts[1].isdigit():
51+
current.append([parts[2], parts[3], parts[4]])
52+
continue
53+
if parts[1] in ("Sum", "Total"):
54+
if current:
55+
atomic_forces_list.append(current)
56+
in_block = False
57+
else:
58+
if current:
59+
atomic_forces_list.append(current)
60+
in_block = False
61+
62+
if in_block and current:
63+
atomic_forces_list.append(current)
64+
if atomic_forces_list:
65+
return np.array(atomic_forces_list, dtype=float)
66+
return None
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"run_type": "ENERGY_FORCE",
3+
"version": 2025.2,
4+
"pot_energy": [
5+
-75.63501801634357
6+
],
7+
"chemical_symbols": [
8+
"Si",
9+
"Si",
10+
"Si",
11+
"O",
12+
"O",
13+
"O",
14+
"O"
15+
],
16+
"chemical_symbols_fake": [
17+
"Si",
18+
"Si",
19+
"Si",
20+
"O",
21+
"O",
22+
"O",
23+
"O"
24+
],
25+
"atomic_kind": [
26+
"Si",
27+
"O"
28+
],
29+
"atom_num": [
30+
3,
31+
4
32+
],
33+
"atom_kinds_list": [
34+
1,
35+
1,
36+
1,
37+
2,
38+
2,
39+
2,
40+
2
41+
]
42+
}
Binary file not shown.
296 Bytes
Binary file not shown.
200 Bytes
Binary file not shown.

tests/test_energy_force/v2025.1/normal/output

Lines changed: 1167 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)