dpdata icon indicating copy to clipboard operation
dpdata copied to clipboard

feat: add support for non-orthogonal cells in amber/md format

Open Copilot opened this issue 4 months ago • 4 comments

The amber/md format previously only supported orthogonal unit cells (90° angles), raising a RuntimeError("Unsupported cells") for any simulation with non-orthogonal cells. This limitation prevented users from processing AMBER trajectories with triclinic, monoclinic, or hexagonal crystal systems.

Changes

  • Added cell_lengths_angles_to_cell() function that converts cell lengths and angles to 3×3 cell vector matrices using standard crystallographic conventions
  • Removed orthogonal-only restriction in read_amber_traj() by replacing the angle check with general cell conversion
  • Maintains full backward compatibility - orthogonal cells produce identical results to the previous implementation

Supported Crystal Systems

The implementation now handles all crystal systems:

  • Cubic/Orthorhombic: α = β = γ = 90°
  • Monoclinic: α = γ = 90°, β ≠ 90°
  • Hexagonal: α = β = 90°, γ = 120°
  • Triclinic: α, β, γ ≠ 90°

Example Usage

import dpdata

# Previously would raise RuntimeError for non-orthogonal cells
system = dpdata.LabeledSystem("simulation", fmt="amber/md")
# Now works with any cell angles, including:
# - Protein crystals with monoclinic cells
# - Hexagonal ice simulations 
# - Triclinic organic crystals

Testing

Added comprehensive test coverage including:

  • Unit tests for all crystal system types
  • Edge case validation (extreme angles, multiple frames)
  • Integration tests verifying RuntimeError elimination
  • Backward compatibility verification

All existing amber/md tests continue to pass, ensuring no breaking changes.

Fixes #869.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Aug 23 '25 02:08 Copilot

pre-commit.ci autofix

njzjz avatar Aug 23 '25 03:08 njzjz

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 85.53%. Comparing base (beee99a) to head (14d6447).

Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #870      +/-   ##
==========================================
+ Coverage   85.48%   85.53%   +0.04%     
==========================================
  Files          82       82              
  Lines        7607     7625      +18     
==========================================
+ Hits         6503     6522      +19     
+ Misses       1104     1103       -1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Aug 23 '25 03:08 codecov[bot]

CodSpeed WallTime Performance Report

Merging #870 will not alter performance

Comparing copilot/fix-869 (14d6447) with devel (beee99a)

Summary

✅ 2 untouched benchmarks

codspeed-hq[bot] avatar Aug 23 '25 03:08 codspeed-hq[bot]

pre-commit.ci autofix

njzjz avatar Aug 23 '25 05:08 njzjz