dpdata icon indicating copy to clipboard operation
dpdata copied to clipboard

feat: do not output spin info for lmp format

Open OutisLi opened this issue 4 months ago • 4 comments

fix issue #885 in dpdata and issue #312 in dpgen2

However, adding an additional parameter is not the best method. Please provide another way to fix this issue, thanks.

Summary by CodeRabbit

  • New Features

    • Optional setting to include per-atom spin information (direction and magnitude) in exported LAMMPS data; disabled by default and only emitted when explicitly enabled and spin data exists.
  • Tests

    • Tests updated to parameterize and verify spin output behavior (on/off) and corresponding expected file contents.

OutisLi avatar Aug 30 '25 09:08 OutisLi

📝 Walkthrough

Walkthrough

Adds an optional output_spins flag to the LAMMPS writer path; the plugin reads and forwards this flag, and the writer emits per-atom spin columns only when spins exist and output_spins=True. Default behavior (no spins) is unchanged.

Changes

Cohort / File(s) Summary of edits
LAMMPS writer spin gating
dpdata/lammps/lmp.py
Added output_spins parameter to from_system_data(f_idx=0, output_spins=False). Guarded spin-related coordinate formatting, spins_norm calculation, and per-atom spin output behind checks for both presence of spins and output_spins.
Plugin plumb-through
dpdata/plugins/lammps.py
LAMMPSLmpFormat.to_system reads output_spins = bool(kwargs.pop("output_spins", False)) and forwards it to from_system_data(data, frame_idx, output_spins=output_spins). Call formatting adjusted; public API unchanged.
Tests updated for flag
tests/test_lammps_spin.py
Parameterized tests to pass output_spins through dpdata.System.to(..., output_spins=...). Adjusted expected coordinate blocks and signatures for tests that assert spin output presence/absence.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Plugin as LAMMPSLmpFormat.to_system
  participant Writer as lammps.lmp.from_system_data
  participant File as "LAMMPS Data File"

  User->>Plugin: to_system(data, file_name, frame_idx, output_spins)
  Plugin->>Writer: from_system_data(system, f_idx, output_spins)
  alt spins present AND output_spins == true
    Writer->>File: write per-atom coords + spin vectors & magnitudes
  else
    Writer->>File: write per-atom coords (no spin columns)
  end

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • deepmodeling/dpdata#738 — Also modifies LAMMPS spin handling and writer/plugin interactions; directly related to gating or altering spin output.

Suggested reviewers

  • wanghan-iapcm
  • njzjz

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary change of disabling spin output for the LAMMPS format, accurately reflecting the addition of a flag to gate spin data and the default behavior change without including extraneous details.

[!TIP]

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


📜 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 80ef876bcab1a83f9efb10d6840be27aa3b5c784 and 5589f809df77c9ae287853810a319db6a981afa2.

📒 Files selected for processing (3)
  • dpdata/lammps/lmp.py (3 hunks)
  • dpdata/plugins/lammps.py (1 hunks)
  • tests/test_lammps_spin.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • dpdata/lammps/lmp.py
  • dpdata/plugins/lammps.py
  • tests/test_lammps_spin.py
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

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.

coderabbitai[bot] avatar Aug 30 '25 09:08 coderabbitai[bot]

Hi, @OutisLi, please fix the unittest.

pxlxingliang avatar Aug 30 '25 13:08 pxlxingliang

please check the suggestions by coderabbitai

wanghan-iapcm avatar Sep 01 '25 00:09 wanghan-iapcm

CodSpeed WallTime Performance Report

Merging #886 will not alter performance

Comparing OutisLi:fix/stru_mag (5589f80) with devel (b25e0e7)

Summary

✅ 2 untouched benchmarks

codspeed-hq[bot] avatar Sep 09 '25 09:09 codspeed-hq[bot]