Skip to content
This repository was archived by the owner on May 5, 2026. It is now read-only.

Commit 367232b

Browse files
authored
Add files via upload
1 parent 740e60f commit 367232b

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

multioptpy/Wrapper/mapper.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from abc import ABC, abstractmethod
2727
from collections import Counter
2828
from dataclasses import dataclass, field
29+
from typing import Any
2930

3031
import numpy as np
3132
from scipy.spatial.distance import cdist, pdist
@@ -611,7 +612,7 @@ def _kabsch_rmsd(pa: np.ndarray, pb: np.ndarray) -> float:
611612
RMSD for enantiomeric pairs.
612613
"""
613614
U, S, Vt = np.linalg.svd(pb.T @ pa)
614-
d = np.sign(np.linalg.det(U) * np.linalg.det(Vt))
615+
d = 1.0 if np.linalg.det(U) * np.linalg.det(Vt) >= 0 else -1.0
615616
E0 = np.sum(pa ** 2) + np.sum(pb ** 2)
616617
rmsd_sq = max(0.0, E0 - 2.0 * (S[0] + S[1] + d * S[2])) / len(pa)
617618
return float(np.sqrt(rmsd_sq))
@@ -724,7 +725,7 @@ class ExplorationTask:
724725
xyz_file: str
725726
afir_params: list[str]
726727
priority: float = 0.0
727-
metadata: dict = field(default_factory=dict)
728+
metadata: dict[str, Any] = field(default_factory=dict)
728729

729730

730731
@dataclass
@@ -1054,31 +1055,36 @@ def __init__(self, filepath: str, flush_interval: int = 100) -> None:
10541055
# ------------------------------------------------------------------ #
10551056

10561057
def _load(self) -> None:
1057-
"""Load existing records from the text file (if present)."""
10581058
if not os.path.isfile(self._filepath):
10591059
return
1060-
1060+
10611061
with open(self._filepath, "r", encoding="utf-8") as fh:
1062-
for line in fh:
1062+
for lineno, line in enumerate(fh, 1):
10631063
line = line.strip()
10641064
if not line or line.startswith("#"):
10651065
continue
10661066
parts = line.split()
10671067
if len(parts) < 4:
10681068
continue
10691069
try:
1070-
# Strip the leading "EQ" prefix before converting to int
10711070
node_id = int(parts[0][2:])
10721071
atom_i = int(parts[1])
10731072
atom_j = int(parts[2])
10741073
gamma_sign = parts[3]
1075-
1074+
10761075
if gamma_sign not in ("+", "-"):
10771076
continue
1078-
1077+
10791078
self._explored.add((node_id, atom_i, atom_j, gamma_sign))
10801079
self._explored_node_ids.add(node_id)
10811080
except (ValueError, IndexError):
1081+
logger.warning(
1082+
"ExploredPairsLog._load: malformed record at %s:%d "
1083+
"(content=%r) — skipped.",
1084+
self._filepath,
1085+
lineno,
1086+
line,
1087+
)
10821088
continue
10831089

10841090
logger.info(
@@ -2551,7 +2557,7 @@ def _collect_task_batch(self, n: int) -> list[tuple[ExplorationTask, str, str, i
25512557
An empty list is returned when no runnable tasks are available,
25522558
which signals :meth:`_run_batch_parallel` to stop the loop.
25532559
"""
2554-
batch: list[tuple[ExplorationTask, str, str, str, str, int]] = []
2560+
batch: list[tuple[ExplorationTask, str, str, int, int, int]] = []
25552561
# Safety limit: if every task remaining in the queue is already
25562562
# explored, stop after at most (current queue size + n) skips rather
25572563
# than draining the entire queue one pop at a time.
@@ -3005,6 +3011,7 @@ def _save_run_metadata(
30053011
task: ExplorationTask,
30063012
status: str,
30073013
profile_dirs: list[str],
3014+
iteration=None,
30083015
) -> None:
30093016
info = {
30103017
"iteration": self._iteration,

0 commit comments

Comments
 (0)