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
- Load an electronic structure object:
es = job_load.get_electronic_structure()
- 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,)
- 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!
Summary
There is a bug in the
get_resolved_dos()method when plotting the DOS via theelectronic_structureobject. The function behaves differently depending on whetheratom_indicesis a native Pythonintor anumpy.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 whetheratom_indicesis anumpy.int64or a native Pythonint.Actual Behavior
When passing an
atom_indicesof typenumpy.int64, the method returns an unexpected output shape.In this case,
132is a native Pythonint, andkis anumpy.int64, leading to different behaviors despite representing the same index.Steps to Reproduce
get_resolved_dos()using a Pythonintasatom_indices:get_resolved_dos()using anumpy.int64asatom_indices:Further Information, Files, and Links
The issue arises because the following code does not correctly identify
numpy.int64:A suggested fix is to replace this line with:
This will ensure both
numpy.int64and nativeinttypes are handled correctly. Thanks to @pmrv for this suggestion!