Skip to content

[Code scan] Reject unknown i-PI atom names instead of mapping them to type 0 #5648

Description

@njzjz

This issue comes from a Codex global scan of deepmodeling/deepmd-kit at commit 73de44b1f94471b2e3bdb6b11f57b34d7bc791bb.

Problem

The i-PI driver silently maps any atom name missing from the JSON atom_type table to DeePMD type 0.

dp_ipi reads the user-provided type table and the atom names from the XYZ file, then constructs Convert:

Inside Convert, the lookup uses std::map::operator[]:

For std::map<std::string, int>, name_type_map[atomname[ii]] inserts a missing key with the default integer value 0. A misspelled XYZ element name or an omitted JSON entry therefore runs successfully, but the atom is evaluated as model type 0.

Impact

This can produce wrong i-PI energies and forces without any diagnostic. The failure mode is especially easy to miss because type 0 is a valid DeePMD type.

Suggested fix

Use find()/at() instead of operator[], report the unknown atom name, and fail before inference. If possible, also validate that configured type IDs are in the model's supported type range.

Add a dp_ipi regression where coord_file contains an atom name that is absent from atom_type; the driver should exit with a clear error instead of evaluating the atom as type 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions