deepmodeling / deepmodeling/deepmd-kit

[Code scan] Ignore virtual atoms in dpmodel neighbor statistics

Open
#5,630 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
2k
Forks
649
Avg merge
6d 18h
Merged PRs (30d)
15

Description

Found during a Codex global scan of `deepmodeling/deepmd-kit` at commit `73de44b1f94471b2e3bdb6b11f57b34d7bc791bb`.

## Problem

`NeighborStatOP.call()` computes the minimum pair distance and per-center neighbor counts without consistently masking virtual atoms (`atype < 0`).

Evidence:

- dpmodel neighbor-list code documents negative types as virtual atoms: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/dpmodel/utils/nlist.py#L89-L117
- `extend_coord_with_ghosts` preserves negative atom types in the extended atom-type array: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/dpmodel/utils/nlist.py#L438-L500
- `NeighborStatOP.call()` removes only self pairs before computing `min_rr2`; it does not mask pairs where the center or neighbor atom is virtual: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/dpmodel/utils/neighbor_stat.py#L81-L95
- The mixed-types count masks negative neighbors, but it still counts real neighbors around virtual centers; the non-mixed branch also lacks a center mask: https://github.com/deepmodeling/deepmd-kit/blob/73de44b1f94471b2e3bdb6b11f57b34d7bc791bb/deepmd/dpmodel/utils/neighbor_stat.py#L96-L108

A minimal external run with one real atom and one overlapping virtual atom returned `min_rr2 == 0` and nonzero neighbor counts, even though the virtual atom should not contribute to statistics.

## Impact

Virtual atoms can drive the reported minimum distance to zero and can inflate `max_nnei` through virtual center rows. These statistics feed automatic neighbor selection and environment-matrix range checks, so they can produce overly conservative selections or false close-contact diagnostics.

## Suggested Fix

Apply a real-center and real-neighbor mask before both `min_rr2` and neighbor counting. Add regression tests with overlapping real/virtual atoms and with a virtual center near real atoms, for both `mixed_types=True` and `False`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.