예제 #1
0
파일: Atoms.py 프로젝트: engelund/CalcTroll
    def __getitem__(self, sl):
        constraints = self.constraints

        # Handle ASE bug that numpy arrays cannot slice.
        if isinstance(sl, np.ndarray):
            if sl.dtype == "int":
                pass
            elif sl.dtype == "bool":
                sl = np.arange(len(self))[sl]
            else:
                raise ValueError
            sl = map(int, sl)

        base = AseAtoms.__getitem__(self, sl)
        if isinstance(sl, int):
            pass
        elif len(constraints) == 1 and isinstance(constraints[0], FixAtoms):
            indices = constraints[0].index
            mask = np.zeros(len(self))
            mask[indices] = True
            mask = mask[sl]
            base.set_constraint(FixAtoms(mask=mask))

        if isinstance(base, AseAtoms):
            base = Atoms(base)
            for tag in self.tags():
                tag = tag.removedAtoms(self, sl)
                tag = tag.copy(base)
                base.__tags.append(tag)

        return base