Skip to content

feat: add support for multiple LAMMPS atom styles with automatic detection#867

Merged
wanghan-iapcm merged 10 commits intodevelfrom
copilot/fix-853
Aug 25, 2025
Merged

feat: add support for multiple LAMMPS atom styles with automatic detection#867
wanghan-iapcm merged 10 commits intodevelfrom
copilot/fix-853

Conversation

Copy link
Contributor

Copilot AI commented Aug 21, 2025

This PR adds comprehensive support for different LAMMPS atom styles beyond the previously supported "atomic" style. The implementation now supports 8 common LAMMPS atom styles with automatic detection and charge extraction while maintaining full backward compatibility.

Supported Atom Styles

  • atomic: atom-ID atom-type x y z (default fallback)
  • full: atom-ID molecule-ID atom-type q x y z (includes charges and molecule IDs)
  • charge: atom-ID atom-type q x y z (includes charges)
  • bond: atom-ID molecule-ID atom-type x y z (includes molecule IDs)
  • angle: atom-ID molecule-ID atom-type x y z
  • molecular: atom-ID molecule-ID atom-type x y z
  • dipole: atom-ID atom-type q x y z mux muy muz (includes charges)
  • sphere: atom-ID atom-type diameter density x y z

Key Features

  • Automatic atom style detection: Parses LAMMPS data file headers and comments (e.g., Atoms # full) with intelligent fallback based on column analysis
  • Automatic charge extraction and registration: For atom styles that include charges (full, charge, dipole), charges are automatically extracted, stored, and properly registered as a DataType
  • Smart defaults: atom_style="auto" is now the default, eliminating the need for manual specification in most cases
  • Backward compatibility: Existing code continues to work without any changes
  • Robust error handling: Clear error messages for unsupported atom styles with graceful fallbacks

Usage

# Automatic detection (new default behavior)
system = dpdata.System("data.lmp", type_map=["O", "H"])  # Detects style automatically

# Full style with charges and molecule IDs
system = dpdata.System("data.lmp", type_map=["O", "H"])  # Auto-detects "full" style
print(system["charges"])  # Access extracted charges

# Explicit styles still supported for edge cases
system = dpdata.System("data.lmp", type_map=["O", "H"], atom_style="charge")

Implementation Details

The solution adds intelligent atom style detection that:

  1. Parses header comments after "Atoms" sections for explicit style declarations
  2. Uses heuristic analysis of column count and content patterns as fallback
  3. Maintains the existing configurable atom style parameter for explicit control
  4. Automatically registers charge DataType when charge data is present

All parsing functions (get_atype, get_posi, get_charges) were updated to handle different column arrangements with full type hints. Comprehensive tests cover both comment-based and heuristic detection scenarios.

Fixes #853.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor Author

Copilot AI commented Aug 21, 2025

@njzjz 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 2 commits August 21, 2025 11:28
Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Copilot AI changed the title [WIP] [Feature Request] support other lammps data styles Add support for multiple LAMMPS atom styles in lammps/lmp format Aug 21, 2025
Copilot AI requested a review from njzjz August 21, 2025 11:32
…t automatic detection

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Copilot AI changed the title Add support for multiple LAMMPS atom styles in lammps/lmp format Add support for multiple LAMMPS atom styles with automatic detection Aug 21, 2025
Copilot AI requested a review from njzjz August 21, 2025 11:57
@codecov
Copy link

codecov bot commented Aug 21, 2025

Codecov Report

❌ Patch coverage is 89.28571% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.47%. Comparing base (beee99a) to head (77d0560).
⚠️ Report is 28 commits behind head on devel.

Files with missing lines Patch % Lines
dpdata/lammps/lmp.py 88.31% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #867      +/-   ##
==========================================
- Coverage   85.48%   85.47%   -0.02%     
==========================================
  Files          82       82              
  Lines        7607     7675      +68     
==========================================
+ Hits         6503     6560      +57     
- Misses       1104     1115      +11     

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

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 21, 2025

CodSpeed WallTime Performance Report

Merging #867 will not alter performance

Comparing copilot/fix-853 (1e6356f) with devel (beee99a)

Summary

✅ 2 untouched benchmarks

@njzjz
Copy link
Member

njzjz commented Aug 21, 2025

pre-commit.ci autofix

…tomatic detection in tests

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Copilot AI requested a review from njzjz August 21, 2025 13:55
@njzjz njzjz marked this pull request as ready for review August 21, 2025 14:26
@njzjz njzjz marked this pull request as draft August 23, 2025 05:32
… to reduce code duplication

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Copilot AI requested a review from njzjz August 23, 2025 05:47
@njzjz
Copy link
Member

njzjz commented Aug 23, 2025

pre-commit.ci autofix

Copy link
Member

@njzjz njzjz left a comment

Choose a reason for hiding this comment

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

@copilot please add type hints to all methods you added. Thanks!

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 23, 2025

@copilot please add type hints to all methods you added. Thanks!

Added comprehensive type hints to all new methods including the core parsing functions in dpdata/lammps/lmp.py, the charge registration function in dpdata/plugins/lammps.py, and all test helper methods in tests/test_lammps_atom_styles.py. All functions now have proper parameter and return type annotations following the project's type hinting conventions. Commit: 54d9709

Copilot AI requested a review from njzjz August 23, 2025 06:00
@njzjz
Copy link
Member

njzjz commented Aug 23, 2025

pre-commit.ci autofix

Copy link
Member

@njzjz njzjz left a comment

Choose a reason for hiding this comment

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

LGTM (the CI status is not related) - @wanghan-iapcm, please double-check the PR.

@njzjz njzjz requested a review from wanghan-iapcm August 23, 2025 06:12
@njzjz njzjz marked this pull request as ready for review August 23, 2025 06:12
@njzjz
Copy link
Member

njzjz commented Aug 24, 2025

@copilot Use conventional commit format for the PR title.

Copy link
Contributor Author

Copilot AI commented Aug 24, 2025

@copilot Use conventional commit format for the PR title.

I cannot directly change the PR title as I don't have permissions to update PR metadata. However, the conventional commit format for this PR title should be:

feat: add support for multiple LAMMPS atom styles with automatic detection

You can update the PR title manually to follow this conventional commit format.

Copilot AI changed the title Add support for multiple LAMMPS atom styles with automatic detection feat: add support for multiple LAMMPS atom styles with automatic detection Aug 24, 2025
Copilot AI requested a review from njzjz August 24, 2025 08:02
@wanghan-iapcm wanghan-iapcm merged commit 5f1dec8 into devel Aug 25, 2025
21 of 24 checks passed
@wanghan-iapcm wanghan-iapcm deleted the copilot/fix-853 branch August 25, 2025 12:59
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.

[Feature Request] support other lammps data styles

3 participants