Skip to content

Commit

Permalink
Check math against bilbao
Browse files Browse the repository at this point in the history
(I was wrong)
  • Loading branch information
WardLT committed Dec 4, 2023
1 parent 899e3a0 commit 8f18c2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions mofa/scoring/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ def score_mof(self, record: MOFRecord) -> float:

# Get the initial and final structures
init_strc = read_vasp(StringIO(traj[0]))
final_strc: ase.Atoms = read_vasp(StringIO(traj[0]))
final_strc: ase.Atoms = read_vasp(StringIO(traj[1]))

# Compute the maximum principal strain
strain = np.linalg.solve(final_strc.cell.array, init_strc.cell.array) - np.eye(3)
# Following: https://www.cryst.ehu.es/cgi-bin/cryst/programs/nph-strain
strain = np.matmul(init_strc.cell.array, np.linalg.inv(final_strc.cell.array)) - np.eye(3)
strain = 0.5 * (strain + strain.T)
strains = np.linalg.eigvals(strain)
return np.abs(strains).max()
3 changes: 2 additions & 1 deletion tests/scoring/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ def test_strain(example_record):
write_vasp(sio, final_atoms)
example_record.md_trajectory['uff'][1] = sio.getvalue()

assert scorer.score_mof(example_record) > 0
max_strain = scorer.score_mof(example_record)
assert np.isclose(max_strain, 0.09647) # Checked against https://www.cryst.ehu.es/cryst/strain.html

0 comments on commit 8f18c2d

Please sign in to comment.