Skip to content

Commit

Permalink
Merge pull request #284 from pyiron/fix_traj_ind
Browse files Browse the repository at this point in the history
Hotfix: Handle empty indices
  • Loading branch information
sudarsan-surendralal authored Aug 6, 2021
2 parents b5b92da + 5ccc53d commit 707c52f
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions pyiron_atomistics/atomistics/job/atomistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,17 +751,20 @@ def __init__(self):
class Trajectory(HasStructure):
"""
A trajectory instance compatible with the ase.io class
Args:
positions (numpy.ndarray): The array of the trajectory in cartesian coordinates
structure (pyiron.atomistics.structure.atoms.Atoms): The initial structure instance from which the species info
is derived
center_of_mass (bool): False (default) if the specified positions are w.r.t. the origin
cells (numpy.ndarray): Optional argument of the cell shape at every time step (Nx3x3 array) when the volume
varies
"""

def __init__(self, positions, structure, center_of_mass=False, cells=None, indices=None, table_name="trajectory"):
def __init__(self, positions, structure, center_of_mass=False, cells=None, indices=None):
"""
Args:
positions (ndarray): The array of the trajectory in cartesian coordinates
structure (pyiron.atomistics.structure.atoms.Atoms): The initial structure instance from which the species
info is derived
center_of_mass (bool): False (default) if the specified positions are w.r.t. the origin
cells (None/ndarray): Optional argument of the cell shape at every time step (Nx3x3 array) when the volume
varies
indices (None/ndarray): Indices for the species in the structure
"""

if center_of_mass:
pos = np.copy(positions)
Expand Down Expand Up @@ -789,8 +792,12 @@ def __getitem__(self, item):
return new_structure
elif isinstance(item, (list, np.ndarray, slice)):
snapshots = np.arange(len(self), dtype=int)[item]
return Trajectory(positions=self._positions[snapshots], cells=self._cells[snapshots],
structure=self[snapshots[0]], indices=self._indices[snapshots])
if self._cells is not None:
return Trajectory(positions=self._positions[snapshots], cells=self._cells[snapshots],
structure=self[snapshots[0]], indices=self._indices[snapshots])
else:
return Trajectory(positions=self._positions[snapshots], cells=self._cells,
structure=self[snapshots[0]], indices=self._indices[snapshots])

def _get_structure(self, frame=-1, wrap_atoms=True):
return self[frame]
Expand Down

0 comments on commit 707c52f

Please sign in to comment.