Skip to content

Add support for constraints#274

Merged
jan-janssen merged 63 commits intomainfrom
constraints
Nov 27, 2025
Merged

Add support for constraints#274
jan-janssen merged 63 commits intomainfrom
constraints

Conversation

@jan-janssen
Copy link
Copy Markdown
Member

@jan-janssen jan-janssen commented Nov 27, 2025

Summary by CodeRabbit

  • New Features

    • Added selective dynamics support for constrained atomic coordinates in LAMMPS simulations across static, MD, and minimize calculation modes.
    • Support for multiple constraint types including atom freezing and planar constraints.
  • Tests

    • Added comprehensive test suite validating constraint handling across various scenarios and configurations with proper error handling.

✏️ Tip: You can customize this high-level summary in your review settings.

jan-janssen and others added 30 commits November 8, 2025 10:13
…ction

# Conflicts:
#	tests/test_compatibility_file.py
@jan-janssen jan-janssen linked an issue Nov 27, 2025 that may be closed by this pull request
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

A new constraints module is introduced to process atomic structure constraints (FixAtoms, FixedPlane) and generate corresponding LAMMPS commands for selective dynamics. This functionality is integrated into the LAMMPS input file generator for static, MD, and minimize calculation modes.

Changes

Cohort / File(s) Summary
New constraints module
pyiron_lammps/compatibility/constraints.py
Adds _get_fixed_atom_boolean_vector() to build a boolean matrix of fixed coordinates per atom, and set_selective_dynamics() to compute LAMMPS group/fix commands from constraints. Supports FixAtoms and FixedPlane constraint types across all axis combinations (xyz, xy, xz, yz, x, y, z). Raises ValueError for unsupported constraints or directions.
File generator integration
pyiron_lammps/compatibility/file.py
Integrates selective dynamics into LAMMPS input generation. Calls set_selective_dynamics() with appropriate calc_md flags (False for static/minimize, True for md) and appends resulting commands to lmp.in content for all calculation modes.
Test suite
tests/test_constraints.py
Comprehensive test coverage for selective dynamics with mixed constraint scenarios, individual plane constraints, calc_md toggling, error handling for invalid constraints, and validation of generated control dictionary entries and LAMMPS command strings.

Sequence Diagram

sequenceDiagram
    participant User
    participant FileGen as file.py<br/>(calc methods)
    participant ConstraintsModule as constraints.py<br/>(set_selective_dynamics)
    participant LammpsInput as LAMMPS Input<br/>(lmp.in)
    
    User->>FileGen: Initiate static/md/minimize calc
    FileGen->>ConstraintsModule: set_selective_dynamics(structure, calc_md=flag)
    
    alt Constraints exist
        ConstraintsModule->>ConstraintsModule: _get_fixed_atom_boolean_vector()
        ConstraintsModule->>ConstraintsModule: Build group commands
        ConstraintsModule->>ConstraintsModule: Build fix/setforce commands
        alt calc_md=True
            ConstraintsModule->>ConstraintsModule: Add velocity commands
        end
        ConstraintsModule-->>FileGen: Return dict with commands
    else No constraints
        ConstraintsModule-->>FileGen: Return empty dict
    end
    
    FileGen->>LammpsInput: Append selective dynamics commands
    FileGen->>LammpsInput: Append calculation-specific commands
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Key areas requiring attention:
    • Logic in _get_fixed_atom_boolean_vector() for correctly building boolean matrices from different constraint types
    • Constraint direction mapping and command generation in set_selective_dynamics() to verify all axis combinations (xyz, xy, xz, yz, x, y, z) produce correct LAMMPS syntax
    • Integration points in file.py across three calculation modes (static, md, minimize) to ensure calc_md flags are passed correctly
    • Error handling for unsupported constraint types and directions

Poem

A rabbit hops through constraints so tight,
Fixing atoms left and right! 🐰
In LAMMPS scripts we now confine,
Selective dynamics—oh so fine!
Dynamics dance on permitted planes,
No more freedom, just these chains! ✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch constraints

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d47127 and ccf639f.

📒 Files selected for processing (3)
  • pyiron_lammps/compatibility/constraints.py (1 hunks)
  • pyiron_lammps/compatibility/file.py (3 hunks)
  • tests/test_constraints.py (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 27, 2025

Codecov Report

❌ Patch coverage is 97.36842% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.47%. Comparing base (2d47127) to head (ccf639f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pyiron_lammps/compatibility/constraints.py 97.22% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #274      +/-   ##
==========================================
+ Coverage   92.03%   92.47%   +0.43%     
==========================================
  Files           7        8       +1     
  Lines         854      930      +76     
==========================================
+ Hits          786      860      +74     
- Misses         68       70       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@jan-janssen jan-janssen marked this pull request as draft November 27, 2025 10:25
Base automatically changed from lammps_function to main November 27, 2025 12:27
# Conflicts:
#	pyiron_lammps/compatibility/file.py
#	tests/test_compatibility_file.py
@jan-janssen jan-janssen marked this pull request as ready for review November 27, 2025 12:33
@jan-janssen jan-janssen merged commit 1952102 into main Nov 27, 2025
20 of 21 checks passed
@jan-janssen jan-janssen deleted the constraints branch November 27, 2025 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for constraints in the LAMMPS structure generation

1 participant