rot8 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. rot8/__init__.py +15 -0
  2. rot8/analysis/__init__.py +4 -0
  3. rot8/analysis/freq_projection.py +191 -0
  4. rot8/analysis/report.py +784 -0
  5. rot8/analysis/thermo.py +120 -0
  6. rot8/analysis/timing.py +419 -0
  7. rot8/analysis/ts_checker.py +630 -0
  8. rot8/analysis/ts_cli.py +209 -0
  9. rot8/analysis/ts_movie.py +203 -0
  10. rot8/chimerax/__init__.py +1 -0
  11. rot8/chimerax/chimerax_rotobond.py +1818 -0
  12. rot8/cli.py +77 -0
  13. rot8/core/__init__.py +10 -0
  14. rot8/core/corrector.py +79 -0
  15. rot8/core/dihedral.py +531 -0
  16. rot8/core/orchestrator.py +244 -0
  17. rot8/core/utils.py +145 -0
  18. rot8/logger.py +462 -0
  19. rot8/main.py +21 -0
  20. rot8/py.typed +0 -0
  21. rot8/runners/__init__.py +5 -0
  22. rot8/runners/_workdir.py +29 -0
  23. rot8/runners/enan.py +247 -0
  24. rot8/runners/rot8.py +166 -0
  25. rot8/title.py +31 -0
  26. rot8-1.0.0.dist-info/METADATA +392 -0
  27. rot8-1.0.0.dist-info/RECORD +53 -0
  28. rot8-1.0.0.dist-info/WHEEL +5 -0
  29. rot8-1.0.0.dist-info/entry_points.txt +5 -0
  30. rot8-1.0.0.dist-info/licenses/LICENSE +21 -0
  31. rot8-1.0.0.dist-info/top_level.txt +2 -0
  32. rotobond/__init__.py +18 -0
  33. rotobond/cli.py +139 -0
  34. rotobond/core/__init__.py +1 -0
  35. rotobond/core/topology.py +109 -0
  36. rotobond/core/transform.py +61 -0
  37. rotobond/core/workflow.py +265 -0
  38. rotobond/logger/__init__.py +1 -0
  39. rotobond/logger/create_log.py +82 -0
  40. rotobond/logger/formatter.py +68 -0
  41. rotobond/logger/listener.py +39 -0
  42. rotobond/logger/logger.py +466 -0
  43. rotobond/managers/__init__.py +5 -0
  44. rotobond/managers/config.py +101 -0
  45. rotobond/managers/neb_manager.py +350 -0
  46. rotobond/managers/optimization_manager.py +113 -0
  47. rotobond/parse_arguments.py +196 -0
  48. rotobond/py.typed +0 -0
  49. rotobond/utils/__init__.py +1 -0
  50. rotobond/utils/constants.py +7 -0
  51. rotobond/utils/path_energies.py +63 -0
  52. rotobond/utils/silencer.py +63 -0
  53. rotobond/utils/title.py +31 -0
rot8/__init__.py ADDED
@@ -0,0 +1,15 @@
1
+ """rot8: rotational barrier search orchestrating rotobond and ensemble-analyzer."""
2
+
3
+ import importlib.metadata
4
+
5
+ try:
6
+ # set by setuptools-scm from the git tag at build/install time
7
+ __version__ = importlib.metadata.version("rot8")
8
+ except importlib.metadata.PackageNotFoundError:
9
+ __version__ = "unknown"
10
+
11
+ from rot8.main import main
12
+ from rot8.cli import parse_arguments
13
+ from rot8.core.orchestrator import Orchestrator
14
+ from rot8.analysis.report import ReportGenerator
15
+ from rot8.logger import create_logger
@@ -0,0 +1,4 @@
1
+ """Analysis tools for rot8 output."""
2
+
3
+ from rot8.analysis.report import ReportGenerator
4
+ from rot8.analysis.ts_checker import TSChecker
@@ -0,0 +1,191 @@
1
+ """Re-projection of legacy (unprojected) vibrational data in rot8 checkpoints.
2
+
3
+ Older ensemble-analyzer ML vibrations stored all 3N ASE modes, including the six
4
+ (five for linear molecules) translations/rotations. These spurious low
5
+ frequencies inflate ZPVE and, above all, the qRRHO entropy. Current EnAn
6
+ diagonalises the mass-weighted Hessian only in the internal subspace
7
+ (``ensemble_analyzer.mode_analysis.project_hessian``).
8
+
9
+ For records still in the legacy 3N format the Hessian is rebuilt from the
10
+ stored frequencies and orthonormal mass-weighted modes, projected with the same
11
+ EnAn routine, and the thermochemistry is recomputed.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import os
18
+ import shutil
19
+ from typing import TYPE_CHECKING, Any, Unpack
20
+
21
+ import numpy as np
22
+ from ase import Atoms, units
23
+
24
+ from ensemble_analyzer.mode_analysis import project_hessian
25
+
26
+ from rot8.analysis.report import _parse_checkpoint
27
+ from rot8.analysis.thermo import ThermoKwargs, recompute_energy_record
28
+
29
+ if TYPE_CHECKING:
30
+ from rot8.logger import OrchestratorLogger
31
+
32
+ # sqrt(eigenvalue) of a mass-weighted Hessian in eV/(Ų amu) -> eV (same as ASE/EnAn).
33
+ _HESSIAN_TO_EV = units._hbar * 1e10 / np.sqrt(units._e * units._amu)
34
+ _ORTHO_TOL = 1e-4
35
+ _CORRECTION_KEYS = ("zpve", "H", "S", "G_E")
36
+
37
+
38
+ def is_unprojected(rec: dict[str, Any], n_atoms: int) -> bool:
39
+ """Check whether a record carries the full 3N ASE modes (legacy, not projected).
40
+
41
+ Args:
42
+ rec: Energy record of one protocol step.
43
+ n_atoms: Number of atoms of the conformer.
44
+
45
+ Returns:
46
+ True if ``Freq`` has 3N entries and ``NormalModes`` has shape (3N, N, 3).
47
+
48
+ """
49
+ freqs = rec.get("Freq")
50
+ modes = rec.get("NormalModes")
51
+ if freqs is None or modes is None or n_atoms == 0:
52
+ return False
53
+ n3 = 3 * n_atoms
54
+ return len(freqs) == n3 and np.shape(modes) == (n3, n_atoms, 3)
55
+
56
+
57
+ def reproject_record(
58
+ rec: dict[str, Any], conf: dict[str, Any], logger: OrchestratorLogger | None = None,
59
+ ) -> bool:
60
+ """Replace ``Freq``/``NormalModes`` of a legacy record with projected ones.
61
+
62
+ The record is left untouched when the stored modes are not orthonormal
63
+ (Hessian cannot be rebuilt) or the geometry is missing.
64
+
65
+ Args:
66
+ rec: Energy record of one protocol step (modified in place).
67
+ conf: Conformer record providing atomic symbols and last geometry.
68
+ logger: Optional logger for warnings; falls back to ``print``.
69
+
70
+ Returns:
71
+ True if the record was re-projected, False otherwise.
72
+
73
+ """
74
+ symbols = conf.get("atoms") or []
75
+ geometry = conf.get("last_geometry")
76
+ n = len(symbols)
77
+ if geometry is None or not is_unprojected(rec, n):
78
+ return False
79
+
80
+ freqs = np.asarray(rec["Freq"], dtype=float)
81
+ L = np.asarray(rec["NormalModes"], dtype=float).reshape(3 * n, 3 * n)
82
+ if not np.allclose(L @ L.T, np.eye(3 * n), atol=_ORTHO_TOL):
83
+ msg = (f" Conf {conf.get('number', '?')}: stored normal modes are not "
84
+ "orthonormal, cannot re-project frequencies")
85
+ if logger:
86
+ logger.warn(msg)
87
+ else:
88
+ print(f"[WARN]{msg}")
89
+ return False
90
+
91
+ masses = Atoms(symbols=symbols).get_masses()
92
+ w2 = np.sign(freqs) * (np.abs(freqs) * units.invcm / _HESSIAN_TO_EV) ** 2
93
+ hess_mw = L.T @ (w2[:, None] * L)
94
+ sqm = np.repeat(np.sqrt(masses), 3)
95
+ hessian = hess_mw * sqm[:, None] * sqm[None, :]
96
+
97
+ new_freqs, new_modes = project_hessian(hessian, masses, np.asarray(geometry, dtype=float))
98
+ rec["Freq"] = new_freqs.tolist()
99
+ rec["NormalModes"] = new_modes.tolist()
100
+ return True
101
+
102
+
103
+ def _is_valid(value: float | None) -> bool:
104
+ """Check that a stored energy value is present and not NaN.
105
+
106
+ Args:
107
+ value: Energy value read from a record.
108
+
109
+ Returns:
110
+ True if the value is neither ``None`` nor NaN.
111
+
112
+ """
113
+ return value is not None and not np.isnan(value)
114
+
115
+
116
+ def reproject_conformer(
117
+ conf: dict[str, Any],
118
+ logger: OrchestratorLogger | None = None,
119
+ **thermo_kwargs: Unpack[ThermoKwargs],
120
+ ) -> int:
121
+ """Re-project legacy records of a conformer and recompute their qRRHO.
122
+
123
+ Steps without frequencies that inherited thermochemical corrections from a
124
+ re-projected step (EnAn ``copy_thermochemical_corrections``) get the new
125
+ corrections too.
126
+
127
+ Args:
128
+ conf: Conformer record (modified in place).
129
+ logger: Optional logger for warnings.
130
+ **thermo_kwargs: Thermochemistry settings forwarded to
131
+ :func:`~rot8.analysis.thermo.recompute_energy_record`.
132
+
133
+ Returns:
134
+ Number of re-projected records.
135
+
136
+ """
137
+ energies = conf.get("energies", {})
138
+ if "data" in energies:
139
+ energies = energies["data"]
140
+
141
+ n_done = 0
142
+ corrections: dict[str, Any] | None = None
143
+ for key in sorted(energies.keys(), key=int):
144
+ rec = energies[key]
145
+ if rec.get("Freq"):
146
+ corrections = None
147
+ if reproject_record(rec, conf, logger=logger):
148
+ n_done += 1
149
+ if recompute_energy_record(rec, conf, **thermo_kwargs):
150
+ corrections = {k: rec[k] for k in _CORRECTION_KEYS}
151
+ elif corrections is not None and _is_valid(rec.get("G")) and _is_valid(rec.get("E")):
152
+ rec.update(corrections)
153
+ rec["G"] = rec["E"] + corrections["G_E"]
154
+ return n_done
155
+
156
+
157
+ def reproject_checkpoint(
158
+ ckpt_path: str,
159
+ logger: OrchestratorLogger | None = None,
160
+ **thermo_kwargs: Unpack[ThermoKwargs],
161
+ ) -> int:
162
+ """Re-project every legacy record in a checkpoint and rewrite it in place.
163
+
164
+ The original file is copied to ``checkpoint.json.bak`` (once) before the
165
+ first rewrite. Checkpoints without legacy records are not touched, so the
166
+ function is idempotent.
167
+
168
+ Args:
169
+ ckpt_path: Path to the ``checkpoint.json`` file.
170
+ logger: Optional logger for warnings.
171
+ **thermo_kwargs: Thermochemistry settings forwarded to
172
+ :func:`~rot8.analysis.thermo.recompute_energy_record`.
173
+
174
+ Returns:
175
+ Number of re-projected records.
176
+
177
+ """
178
+ with open(ckpt_path) as f:
179
+ raw = _parse_checkpoint(f.read())
180
+
181
+ n_done = sum(reproject_conformer(conf, logger=logger, **thermo_kwargs)
182
+ for conf in raw.values())
183
+ if n_done == 0:
184
+ return 0
185
+
186
+ backup = ckpt_path + ".bak"
187
+ if not os.path.exists(backup):
188
+ shutil.copy2(ckpt_path, backup)
189
+ with open(ckpt_path, "w") as f:
190
+ json.dump(raw, f, indent=4)
191
+ return n_done