Skip to content

Improve Atoms.index usability #954

@tfrederiksen

Description

@tfrederiksen

Currently, geom.atoms.index("H") raises a KeyError("Could not find atom in the list of atoms.") if no atoms of that species exist. This makes workflows like subsetting by element more cumbersome, since users must wrap calls in try/except.

It would be more intuitive if:

  • Atoms.index(symbol) returned an empty array [] when no atoms are found.
  • Atoms.index accepted multiple species in one call, e.g.:
geom.atoms.index("H", "C")
geom.atoms.index(["H", "C"])

returning the combined indices.

Both changes would simplify common tasks like extracting subsets (CH, CN, etc.) while remaining backwards-compatible.

Happy to open a PR if this direction is welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions