-
Notifications
You must be signed in to change notification settings - Fork 48
Fix column->row cell vector mismatch in integrators #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
#17 is also related to this as if we solve that we can just drop the call to roll the positions back into the cell from the integrators. |
my preference is to tackle that then and address #17 here instead of merging just a minor patch |
I would still merge this but just wanted to raise that to bump the idea |
i think i found 2 more bugs in need some eyes on the changes in 6b82750 1e7290e from preferably two reviewers @orionarcher @abhijeetgangan @CompRhys |
tests/test_transforms.py
Outdated
# Correct expected wrapped position for this triclinic cell | ||
expected = torch.tensor([[2.0, 0.5, 0.2]]) | ||
# Expected wrapped position calculated using r' = (r @ inv(M_row.T) % 1) @ M_row | ||
expected = torch.tensor([[1.875, 0.9875, 0.125]], dtype=torch.float64) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These weird values for the expected result seems self-evidently to suggest broken logic to me? These values must be projected onto the lattice vectors which isn't what I would expect the function to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import numpy as np
from pymatgen.core import Lattice, Structure
lattice = Lattice(np.array([[2.0, 0.5, 0.0],
[0.0, 2.0, 0.0],
[0.0, 0.3, 2.0]]).T)
# Create structure with a single H atom at the given position
s = Structure(lattice, ["H"], [[2.5, 2.5, 2.5]], coords_are_cartesian=True)
# Get the wrapped (folded) position in cartesian coordinates
wrapped_pos = s.frac_coords[0] % 1 # fractional coords wrapped to [0,1)
wrapped_cart = lattice.get_cartesian_coords(wrapped_pos)
print(wrapped_cart)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this gives the same answer as the old test. I think that also suggests that there was an issue with the old function as I am giving the lattice as column vectors (due to transpose) to a function that expects row vectors.
…not use the row vector cell so this suggests this is a bug that it's used in the integrators
… to row vector convention (M_row) for lattice vectors - improve docstrings to clarify assumptions and formulas used in periodic boundary condition calculations
…ew row vector approach, including manual wrapping calculations as to get reference values
…us changes to wrap pbc
@abhijeetgangan this okay to merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great! thanks @CompRhys 👍
Summary
The tests of the function do not use the row vector cell so this suggests this is a bug that it's used in the integrators.
see that tests of function don't use the swap axis: https://github.com/Radical-AI/torch-sim/blob/d2cee6628ff3b4a8da7557772cc12a669a0c09b4/tests/test_transforms.py#L267
fixes #171