Skip to content

Comments

feat(lammps): implement to_system method for LAMMPSDumpFormat#882

Merged
wanghan-iapcm merged 2 commits intodevelfrom
copilot/fix-664
Aug 31, 2025
Merged

feat(lammps): implement to_system method for LAMMPSDumpFormat#882
wanghan-iapcm merged 2 commits intodevelfrom
copilot/fix-664

Conversation

Copy link
Contributor

Copilot AI commented Aug 29, 2025

This PR implements the missing to_system method for the LAMMPSDumpFormat class, enabling conversion from LAMMPS .lmp files to .dump format.

Problem

Previously, users could not convert LAMMPS data files (.lmp) to dump format (.dump) because the LAMMPSDumpFormat class only supported reading dump files (from_system) but not writing them (to_system). This resulted in a NotImplementedError when attempting the conversion:

import dpdata
system = dpdata.System('minimized_structure.output', fmt='lammps/lmp')
system.to('lammps/dump', 'output.dump')  # Raised NotImplementedError

Solution

Added the missing functionality by:

  1. Implementing from_system_data() function in dpdata/lammps/dump.py that converts system data to LAMMPS dump format string with proper:

    • Timestep headers
    • Atom count information
    • Box bounds and tilt parameters
    • Coordinate data with correct LAMMPS indexing
  2. Adding to_system() method to LAMMPSDumpFormat class that uses the new conversion function

  3. Adding comprehensive tests to verify the conversion works correctly and maintains data integrity

Verification

  • All existing tests continue to pass (101 LAMMPS-related tests)
  • Round-trip conversions (LMP → DUMP → LMP) preserve coordinates with perfect precision
  • Generated dump files follow LAMMPS standard format and can be loaded back successfully
  • The exact use case from the issue now works as expected

Example Usage

import dpdata

# Load LAMMPS data file
system = dpdata.System('data.lmp', fmt='lammps/lmp', type_map=['O', 'H'])

# Convert to dump format (now works!)
system.to('lammps/dump', 'output.dump')

# Generated dump file can be loaded back
system2 = dpdata.System('output.dump', fmt='lammps/dump', type_map=['O', 'H'])

Fixes #664.


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

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Copilot AI changed the title [WIP] the structure file lammps.lmp can not be transformed to lammps.dump feat(lammps): implement to_system method for LAMMPSDumpFormat Aug 29, 2025
Copilot AI requested a review from njzjz August 29, 2025 13:54
@codecov
Copy link

codecov bot commented Aug 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.84%. Comparing base (ab61da1) to head (69649f2).
⚠️ Report is 25 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #882      +/-   ##
==========================================
+ Coverage   85.45%   85.84%   +0.39%     
==========================================
  Files          82       82              
  Lines        7678     7706      +28     
==========================================
+ Hits         6561     6615      +54     
+ Misses       1117     1091      -26     

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

@njzjz njzjz marked this pull request as ready for review August 29, 2025 14:14
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

@njzjz njzjz requested a review from wanghan-iapcm August 29, 2025 14:15
@wanghan-iapcm wanghan-iapcm merged commit ba31bcd into devel Aug 31, 2025
20 of 23 checks passed
@wanghan-iapcm wanghan-iapcm deleted the copilot/fix-664 branch August 31, 2025 03:39
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.

the structure file lammps.lmp can not be transformed to lammps.dump

3 participants