Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_resolved_dos() Inconsistent Behavior with atom_indices Type #1584

Open
yuyuanjingxuan opened this issue Oct 11, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@yuyuanjingxuan
Copy link

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!

@yuyuanjingxuan yuyuanjingxuan added the bug Something isn't working label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant