Skip to content

Conversation

CompRhys
Copy link
Member

@CompRhys CompRhys commented Apr 25, 2025

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

@cla-bot cla-bot bot added the cla-signed Contributor license agreement signed label Apr 25, 2025
@orionarcher orionarcher linked an issue Apr 25, 2025 that may be closed by this pull request
@CompRhys
Copy link
Member Author

CompRhys commented Apr 25, 2025

True error still not showing up with lazy import route, pyi needed to get the language server to work with the lazy imports. reset and moved lazy imports to #179

@CompRhys
Copy link
Member Author

#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.

@janosh
Copy link
Collaborator

janosh commented Apr 25, 2025

my preference is to tackle that then and address #17 here instead of merging just a minor patch

@CompRhys
Copy link
Member Author

I would still merge this but just wanted to raise that to bump the idea

@janosh
Copy link
Collaborator

janosh commented Apr 28, 2025

i think i found 2 more bugs in transforms.py were the code was still written to work with column vector lattices while the rest of torch-sim now uses row vector convention as of #112

need some eyes on the changes in 6b82750 1e7290e from preferably two reviewers @orionarcher @abhijeetgangan @CompRhys

@janosh janosh requested a review from orionarcher April 28, 2025 20:14
# 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)
Copy link
Member Author

@CompRhys CompRhys Apr 29, 2025

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

Copy link
Member Author

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)

Copy link
Member Author

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.

CompRhys and others added 6 commits April 29, 2025 19:37
…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
@CompRhys
Copy link
Member Author

CompRhys commented May 1, 2025

@abhijeetgangan this okay to merge?

Copy link
Collaborator

@janosh janosh left a 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 👍

@janosh janosh enabled auto-merge (squash) May 1, 2025 22:39
@janosh janosh merged commit af1bee4 into main May 1, 2025
91 checks passed
@janosh janosh deleted the fix-pbc-171 branch May 1, 2025 22:48
@janosh janosh added the fix Bug fix label May 2, 2025
@janosh janosh changed the title Updates integrator logic per #171. Fix column->row cell vector mismatch in integrators May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed Contributor license agreement signed fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fractional coordinates converting issue on non orthogonal cell

2 participants