-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
If you try to plot3d() from a generated structure with select_atoms showing subset of atoms:
from pyiron import Project
pr = Project('test')
struc = pr.create.structure.bulk('Fe', cubic=True)
struc.plot3d(select_atoms=[0])
you will end up with the error:
File /u/system/SLES12/soft/pyiron/dev/anaconda3/lib/python3.10/site-packages/structuretoolkit/visualize.py:310, in _plot3d(structure, show_cell, show_axes, camera, spacefill, particle_size, select_atoms, background, color_scheme, colors, scalar_field, scalar_start, scalar_end, scalar_cmap, vector_field, vector_color, magnetic_moments, view_plane, distance_from_camera)
308 if select_atoms is not None:
309 select_atoms = np.array(select_atoms, dtype=int)
--> 310 elements = elements[select_atoms]
311 atomic_numbers = atomic_numbers[select_atoms]
312 positions = positions[select_atoms]
TypeError: only integer scalar arrays can be converted to a scalar index
The current structure.plot3d() currently works as follows:
- plot3d() Inside pyiron_atomistics/atomistics/structure/atoms.py calls and passes pyiron_to_ase(self): self=structure to
- plot3d() inside /structuretoolkit/visualize.py
- Which passes the element list as a list and not numpy array
- However plot3d() inside visualize.py explicitly changes the select_atoms into a numpy:
select_atoms = np.array(select_atoms, dtype=int)
- You end up trying to index a list with a numpy array which does not work:
s = ['A', 'B', 'C', 'D']
ind = np.array([1])
s[ind]
If you try to use plot3d() directly from visual.py and pass the structure to it, it works because elements is an array no pyiron_to_ase was imposed.
from structuretoolkit.visualize import _plot3d
_plot3d(struc, select_atoms=[0])
Proposed solutions:
- remove pyiron_to_ase(self) and just pass (self) in plot3d() in atoms.py
- explicitly change elements list to numpy similar to select_atoms in plot3d() in visual.py: elements= np.array(elements)
Both are tested and work locally. However, I am not sure if they affect other functionalities.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working