Skip to content

get_resolved_dos() Inconsistent Behavior with atom_indices Type #1584

@yuyuanjingxuan

Description

@yuyuanjingxuan

Summary

There is a bug in the get_resolved_dos() method when plotting the DOS via the electronic_structure object. The function behaves differently depending on whether atom_indices is a native Python int or a numpy.int64.

pyiron Version and Platform

pyiron: '0.5.2'
pyiron_atomistics: '0.6.12'

Expected Behavior

The get_resolved_dos() method should return DOS data with consistent behavior regardless of whether atom_indices is a numpy.int64 or a native Python int.

Actual Behavior

When passing an atom_indices of type numpy.int64, the method returns an unexpected output shape.

es.get_resolved_dos(atom_indices=132, orbital_indices=orb_dict['d']).shape
# Output: (8000,)

k = atom_list[0]
es.get_resolved_dos(atom_indices=k, orbital_indices=orb_dict['d']).shape
# Output: (9, 8000)

type(k), type(132)
# Output: (numpy.int64, int)

In this case, 132 is a native Python int, and k is a numpy.int64, leading to different behaviors despite representing the same index.

Steps to Reproduce

  1. Load an electronic structure object:
    es = job_load.get_electronic_structure()
  2. Call get_resolved_dos() using a Python int as atom_indices:
    es.get_resolved_dos(atom_indices=132, orbital_indices=orb_dict['d']).shape
    # Expected Output: (8000,)
  3. Call get_resolved_dos() using a numpy.int64 as atom_indices:
    k = atom_list[0]
    es.get_resolved_dos(atom_indices=k, orbital_indices=orb_dict['d']).shape
    # Output: (9, 8000)

Further Information, Files, and Links

The issue arises because the following code does not correctly identify numpy.int64:

if isinstance(atom_indices, int):

A suggested fix is to replace this line with:

if isinstance(atom_indices, numbers.Integral):

This will ensure both numpy.int64 and native int types are handled correctly. Thanks to @pmrv for this suggestion!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions