reference_analysis
reference_analysis
¶
Reference data analysis tools for Hessians and eigenmatrices.
Diagnostic utilities for sanity-checking QM reference data before optimization. Complements the benchmark and PES distortion tools by focusing on the input Hessian quality rather than the output fit.
Implements the tools proposed in GitHub issue #122:
- Eigenvalue spectrum analysis: count/magnitude of negatives, condition number, real-mode filtering.
- Symmetry check: verify Hessian is symmetric within tolerance.
- Frequency comparison: QM vs MM RMSD, MAE, max deviation, per-mode percent error.
- Mode coupling analysis: off-diagonal magnitude in eigenmatrix.
EigenvalueAnalysis
dataclass
¶
EigenvalueAnalysis(eigenvalues: ndarray, n_negative: int, negative_values: ndarray, n_zero: int, condition_number: float, expected_negatives: int, is_consistent: bool)
Results from eigenvalue spectrum analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
eigenvalues |
ndarray
|
All eigenvalues sorted ascending. |
n_negative |
int
|
Number of negative eigenvalues. |
negative_values |
ndarray
|
The negative eigenvalues themselves. |
n_zero |
int
|
Number of near-zero eigenvalues (below zero_tol). |
condition_number |
float
|
Ratio of largest to smallest positive eigenvalue.
|
expected_negatives |
int
|
Expected count (1 for TS, 0 for minimum). |
is_consistent |
bool
|
Whether negative count matches expectation. |
SymmetryCheck
dataclass
¶
Results from Hessian symmetry verification.
Attributes:
| Name | Type | Description |
|---|---|---|
is_symmetric |
bool
|
Whether |
max_deviation |
float
|
Largest absolute difference between |
mean_deviation |
float
|
Mean absolute asymmetry. |
tolerance |
float
|
Threshold used for the check. |
FrequencyComparison
dataclass
¶
FrequencyComparison(qm_frequencies: ndarray, other_frequencies: ndarray, n_modes: int, rmsd: float, mae: float, max_deviation: float, per_mode: list[dict[str, int | float]] = list())
QM vs MM (or other) frequency comparison metrics.
Attributes:
| Name | Type | Description |
|---|---|---|
qm_frequencies |
ndarray
|
QM reference frequencies (real modes, cm⁻¹). |
other_frequencies |
ndarray
|
Comparison frequencies (real modes, cm⁻¹). |
n_modes |
int
|
Number of modes compared. |
rmsd |
float
|
Root-mean-square deviation (cm⁻¹). |
mae |
float
|
Mean absolute error (cm⁻¹). |
max_deviation |
float
|
Largest absolute difference (cm⁻¹). |
per_mode |
list[dict[str, int | float]]
|
Per-mode detail as list of dicts with keys |
ModeCouplingAnalysis
dataclass
¶
ModeCouplingAnalysis(coupling_matrix: ndarray, max_coupling: float, mean_coupling: float, strongly_coupled_pairs: list[tuple[int, int, float]] = list(), coupling_threshold: float = 0.1)
Results from eigenmatrix off-diagonal analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
coupling_matrix |
ndarray
|
Absolute off-diagonal elements normalized by the geometric mean of the corresponding diagonal elements. |
max_coupling |
float
|
Largest normalized off-diagonal value. |
mean_coupling |
float
|
Mean normalized off-diagonal value. |
strongly_coupled_pairs |
list[tuple[int, int, float]]
|
List of |
coupling_threshold |
float
|
Threshold used to flag strongly coupled pairs. |
analyze_eigenvalues
¶
analyze_eigenvalues(hessian: ndarray, *, is_transition_state: bool = True, zero_tol: float = 1e-06) -> EigenvalueAnalysis
Analyze the eigenvalue spectrum of a Hessian matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hessian
|
ndarray
|
|
required |
is_transition_state
|
bool
|
If |
True
|
zero_tol
|
float
|
Eigenvalues with absolute value below this are counted as "near-zero". |
1e-06
|
Returns:
| Type | Description |
|---|---|
EigenvalueAnalysis
|
EigenvalueAnalysis with spectrum statistics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If hessian is not square. |
Source code in q2mm/diagnostics/reference_analysis.py
check_symmetry
¶
check_symmetry(hessian: ndarray, *, tolerance: float = 1e-08) -> SymmetryCheck
Check whether a Hessian matrix is symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hessian
|
ndarray
|
|
required |
tolerance
|
float
|
Maximum acceptable deviation between |
1e-08
|
Returns:
| Type | Description |
|---|---|
SymmetryCheck
|
SymmetryCheck with deviation statistics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If hessian is not square. |
Source code in q2mm/diagnostics/reference_analysis.py
compare_frequencies
¶
compare_frequencies(qm_freqs: Sequence[float] | ndarray, other_freqs: Sequence[float] | ndarray, *, threshold: float = REAL_FREQUENCY_THRESHOLD) -> FrequencyComparison
Compare two sets of vibrational frequencies.
Both input arrays are filtered to real modes (above threshold) and sorted. The shorter array is used to determine the number of modes compared.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qm_freqs
|
Sequence[float] | ndarray
|
QM reference frequencies (cm⁻¹). |
required |
other_freqs
|
Sequence[float] | ndarray
|
Comparison frequencies (cm⁻¹), e.g. from an MM engine. |
required |
threshold
|
float
|
Minimum frequency to include (cm⁻¹). |
REAL_FREQUENCY_THRESHOLD
|
Returns:
| Type | Description |
|---|---|
FrequencyComparison
|
FrequencyComparison with RMSD, MAE, max deviation, and |
FrequencyComparison
|
per-mode detail. |
Source code in q2mm/diagnostics/reference_analysis.py
analyze_mode_coupling
¶
analyze_mode_coupling(hessian: ndarray, eigenvectors: ndarray, *, coupling_threshold: float = 0.1, skip_modes: int = 0) -> ModeCouplingAnalysis
Analyze off-diagonal mode coupling in an eigenmatrix.
Projects hessian onto the basis defined by eigenvectors and examines how large the off-diagonal elements are relative to the diagonal. Large values indicate that modes in the projection basis are coupled in hessian — common when comparing an MM Hessian against QM eigenvectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hessian
|
ndarray
|
|
required |
eigenvectors
|
ndarray
|
|
required |
coupling_threshold
|
float
|
Normalized coupling above this is flagged as "strongly coupled". |
0.1
|
skip_modes
|
int
|
Number of lowest modes to skip (e.g. 6 for translations/rotations). |
0
|
Returns:
| Type | Description |
|---|---|
ModeCouplingAnalysis
|
ModeCouplingAnalysis with coupling matrix and flagged pairs. |
Source code in q2mm/diagnostics/reference_analysis.py
format_hessian_report
¶
format_hessian_report(hessian: ndarray, *, symbols: Sequence[str] | None = None, is_transition_state: bool = True, mm_frequencies: Sequence[float] | ndarray | None = None, mm_hessian: ndarray | None = None) -> str
Generate a human-readable diagnostic report for a Hessian.
Runs all available analyses and formats the results as a multi- section text report suitable for terminal output or logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hessian
|
ndarray
|
|
required |
symbols
|
Sequence[str] | None
|
Element symbols (length N) for frequency conversion. If provided, frequencies are computed and included. |
None
|
is_transition_state
|
bool
|
Expected saddle-point order. |
True
|
mm_frequencies
|
Sequence[float] | ndarray | None
|
Optional MM frequencies for comparison. |
None
|
mm_hessian
|
ndarray | None
|
Optional MM Hessian for mode coupling analysis. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Multi-line report string. |
Source code in q2mm/diagnostics/reference_analysis.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |