Skip to content

Conversation

@stestoll
Copy link
Member

@stestoll stestoll commented May 2, 2025

No description provided.

@stestoll stestoll requested a review from mtessmer May 2, 2025 14:59
@stestoll
Copy link
Member Author

stestoll commented May 2, 2025

Unclear why tests don't pass with 1e-7 tolerance. Precision of the two methods appears comparable:

import numpy as np
r = 4   # angstrom
n = 100000
err1 = np.empty(n)
err2 = np.empty(n)
for i in range(n):
  N = np.random.random_sample(3,)*r
  CA = np.random.random_sample(3,)*r
  C = np.random.random_sample(3,)*r

  CA_N = N - CA
  CA_N /= np.linalg.norm(CA_N)
  CA_C = C - CA
  CA_C /= np.linalg.norm(CA_C)
  z = CA_N + CA_C
  z /= np.linalg.norm(z)

  # unit vectors
  y = CA_N - CA_C
  y /= np.linalg.norm(y)
  
  # projection
  y2 = N - C
  y2 = y2 - np.dot(y2,z)*z
  y2 /= np.linalg.norm(y2)
  
  err1[i] = np.dot(z,y)
  err2[i] = np.dot(z,y2)

print(f"""
unitvectors (new):  mean {np.mean(err1)} std {np.std(err1)}
projection (old):   mean {np.mean(err2)} std {np.std(err2)}
""")
unitvectors (new):  mean -3.742426358502478e-19 std 4.0585430030246706e-16
projection (old):   mean 2.586048995625379e-19 std 1.7544848971476776e-16

@mtessmer
Copy link
Collaborator

mtessmer commented May 2, 2025

It looks like terminal atoms are the biggest failures. In my experience, rotation matrices amplify numerical instabilities.

@mtessmer mtessmer merged commit 3285828 into main May 2, 2025
3 checks passed
@mtessmer mtessmer deleted the bisect_simplify branch May 2, 2025 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants