Commit ba31bcd
feat(lammps): implement to_system method for LAMMPSDumpFormat (#882)
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:
```python
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
```python
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.
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 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](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>1 parent ab61da1 commit ba31bcd
File tree
3 files changed
+87
-0
lines changed- dpdata
- lammps
- plugins
- tests
3 files changed
+87
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
358 | 414 | | |
359 | 415 | | |
360 | 416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
33 | 43 | | |
34 | 44 | | |
35 | 45 | | |
| |||
0 commit comments