Skip to content

Conversation

@thomasloux
Copy link
Collaborator

Summary

Inspired by ASE Atoms.set_cell, add set_cell method to change the cell and the atoms positions at the same time. Reproduce the same code in Torch.

Could also be used to apply constraint latter, for example an equivalent of FixSymmetry.

Checklist

Before a pull request can be merged, the following items must be checked:

  • Doc strings have been added in the Google docstring format.
  • Run ruff on your code.
  • Tests have been added for any new functionality or bug fixes.

@thomasloux thomasloux self-assigned this Nov 17, 2025
@thomasloux thomasloux added the enhancement New feature or request label Nov 17, 2025
Copy link
Collaborator

@orionarcher orionarcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

def test_state_set_cell(ti_sim_state: SimState) -> None:
"""Test the set_cell method of SimState."""
new_cell = (
torch.diag_embed(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe assign the torch.diag_embed to M so it's similar to the way we define the M matrix in the testcase below.

Copy link
Collaborator

@curtischong curtischong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

math looks good. I would've preferred an einsum instead but it's good.

@orionarcher
Copy link
Collaborator

Ready to merge @thomasloux?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants