Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cp2kdata/block_parser/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def parse_all_md_cells(output_file: List[str],
# notice that the cell of step 0 is excluded from MD| block

# choose parser according to cp2k_info.version
if cp2k_info.version in ['9.1', '2022.2', '2023.1', '2023.2', '2024.1']:
if cp2k_info.version in ['9.1', '2022.2', '2023.1', '2023.2', '2024.1', '2024.2', '2025.1', '2025.2']:
ALL_MD_CELL_RE = ALL_MD_CELL_RE_V2023
elif cp2k_info.version in ['7.1']:
ALL_MD_CELL_RE = ALL_MD_CELL_RE_V7
Expand Down
6 changes: 4 additions & 2 deletions cp2kdata/block_parser/energies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

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


Expand Down
37 changes: 35 additions & 2 deletions cp2kdata/block_parser/forces.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
re.VERBOSE
)

FORCES_HEADER_RE = re.compile(
r"^\s*FORCES\|\s+Atomic\s+forces\s+\[.*\]\s*$",
re.MULTILINE
)


def parse_atomic_forces_list(output_file):
atomic_forces_list = []
Expand All @@ -29,5 +34,33 @@ def parse_atomic_forces_list(output_file):
atomic_forces_list.append(atomic_forces)
if atomic_forces_list:
return np.array(atomic_forces_list, dtype=float)
else:
return None

atomic_forces_list = []
lines = output_file.splitlines()
in_block = False
current = []
for line in lines:
if FORCES_HEADER_RE.match(line):
in_block = True
current = []
continue
if in_block:
if line.lstrip().startswith("FORCES|"):
parts = line.split()
if len(parts) >= 5 and parts[1].isdigit():
current.append([parts[2], parts[3], parts[4]])
continue
if parts[1] in ("Sum", "Total"):
if current:
atomic_forces_list.append(current)
in_block = False
else:
if current:
atomic_forces_list.append(current)
in_block = False

if in_block and current:
atomic_forces_list.append(current)
if atomic_forces_list:
return np.array(atomic_forces_list, dtype=float)
return None
42 changes: 42 additions & 0 deletions tests/test_energy_force/v2025.1/normal/answer/answer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"run_type": "ENERGY_FORCE",
"version": 2025.2,
"pot_energy": [
-75.63501801634357
],
"chemical_symbols": [
"Si",
"Si",
"Si",
"O",
"O",
"O",
"O"
],
"chemical_symbols_fake": [
"Si",
"Si",
"Si",
"O",
"O",
"O",
"O"
],
"atomic_kind": [
"Si",
"O"
],
"atom_num": [
3,
4
],
"atom_kinds_list": [
1,
1,
1,
2,
2,
2,
2
]
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
1,167 changes: 1,167 additions & 0 deletions tests/test_energy_force/v2025.1/normal/output

Large diffs are not rendered by default.