Skip to content

Commit 600a148

Browse files
committed
Checking for non-orthonormal columns.
This highlights if you are likely to lose a basis in your normalization, which can happen if your matrix is wrong somehow, eg. your gaussian run transformed coordinates or something. If nothing is wrong this does nothing. But it might help debug some weird things.
1 parent 325c751 commit 600a148

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

arkane/statmech.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,26 @@ def project_rotors(conformer, hessian, rotors, linear, is_ts, get_projected_out_
10641064
d[3 * i + 1, 1] = amass[i]
10651065
d[3 * i + 2, 2] = amass[i]
10661066

1067+
# Check if projection matrix is full rank at this point
1068+
# Compute the QR decomposition in reduced mode
1069+
Q, R = np.linalg.qr(p, mode='reduced')
1070+
# Verify that Q has orthonormal columns:
1071+
if np.isclose(np.dot(Q.T, Q), np.eye(Q.shape[1])).all():
1072+
logging.debug("Q has orthonormal columns")
1073+
else:
1074+
logging.warning("Q does not have orthonormal columns")
1075+
# Verify the reconstruction
1076+
reconstructed_p = Q @ R
1077+
if np.isclose(p, reconstructed_p).all():
1078+
logging.debug("Reconstruction of projection matrix is correct")
1079+
else:
1080+
logging.warning("Reconstruction of projection matrix is incorrect")
1081+
# Check for nearly zero columns in the QR decomposition
1082+
for i, rkk in enumerate(R.diagonal()):
1083+
if abs(rkk) < 1E-15:
1084+
logging.warning(f'Column {i} of the QR decomposition is nearly zero, could lose a basis')
1085+
1086+
10671087
# Construction of the projection vectors for external rotation
10681088
for i in range(n_atoms):
10691089
d[3 * i, 3] = (p[i, 1] * inertia_xyz[0, 2] - p[i, 2] * inertia_xyz[0, 1]) * amass[i]

0 commit comments

Comments
 (0)