Skip to content

Improve wrapping logic and simplify triclinic → orthorhombic handling#379

Open
ayushk687 wants to merge 1 commit intoEAPD-DRB:mainfrom
ayushk687:patch-1
Open

Improve wrapping logic and simplify triclinic → orthorhombic handling#379
ayushk687 wants to merge 1 commit intoEAPD-DRB:mainfrom
ayushk687:patch-1

Conversation

@ayushk687
Copy link
Copy Markdown

Summary

This PR simplifies and standardizes the wrapping workflow by introducing a cleaner abstraction for handling triclinic and orthorhombic box representations.
closes #348
It removes redundant wrapping logic and ensures consistent behavior across different box types.

Problem

Currently, wrapping logic requires:

Manual detection of triclinic boxes
Multiple wrap() calls
Explicit conversion to orthorhombic boxes

Example:

self._universe.atoms.wrap(compound=self.wrap_compound)

if is_triclinic:
    ortho_box = triclinic_to_orthorhombic(ts.dimensions)
    self._universe.atoms.wrap(
        compound=self.wrap_compound,
        box=ortho_box
    )```

This leads to:

Code duplication
Reduced readability
Potential inconsistencies
Solution
Introduced a unified wrapping utility
Automatically handles triclinic → orthorhombic conversion
Eliminates redundant calls
Improves maintainability
Implementation
Refactored Wrapping Logic

import numpy as np

def is_triclinic(dimensions):
    return not np.allclose(dimensions[3:], [90.0, 90.0, 90.0])


def triclinic_to_orthorhombic(dimensions):
    lx, ly, lz, _, _, _ = dimensions
    return np.array([lx, ly, lz, 90.0, 90.0, 90.0])

def wrap_atoms(universe, compound=None):
ts = universe.trajectory.ts
dims = ts.dimensions

if is_triclinic(dims):
    box = triclinic_to_orthorhombic(dims)
    universe.atoms.wrap(compound=compound, box=box)
else:
    universe.atoms.wrap(compound=compound)
Before vs After
❌ Before
Multiple wrap calls
Manual condition handling
Repetitive logic
✅ After
Single clean function
Automatic handling
Easier to maintain

Impact
No breaking changes
Backward compatible
Improves internal logic only

@github-actions github-actions bot added the needs-intake-fix PR intake structure needs maintainer follow-up label Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-intake-fix PR intake structure needs maintainer follow-up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task] [Proposal/Architecture] Canonical CLEWS Result Extraction & Validation Layer for OG-Core Integration

1 participant