def __init__(self, ag, indices, acsi, **kwargs): AtomPointer.__init__(self, ag, acsi) if not isinstance(indices, np.ndarray): indices = np.array(indices, int) elif not indices.dtype == int: indices = indices.astype(int) if kwargs.get('unique'): self._indices = indices else: self._indices = np.unique(indices) self._selstr = kwargs.get('selstr')
def __init__(self, ag, indices, mapping, dummies, title='Unnamed', acsi=None, **kwargs): """Instantiate an atom map. :arg ag: AtomGroup instance from which atoms are mapped :arg indices: indices of mapped atoms :arg mapping: mapping of the atoms :arg dummies: list of indices for dummy atoms :arg title: title of the instance, default is 'Unnamed' :arg acsi: active coordinate set index, defaults is that of *ag* Length of *mapping* must be equal to length of *indices*. Number of atoms (including dummy atoms) are determined from the total lengths of *mapping* and *dummies* arrays. Following built-in functions are customized for this class: * :func:`len` returns the number of atoms in the instance. * :func:`iter` yields :class:`~.Atom` instances. * Indexing is not available.""" AtomPointer.__init__(self, ag, acsi) if not isinstance(indices, np.ndarray): self._indices = np.array(indices, int) elif not indices.dtype == int: self._indices = indices.astype(int) else: self._indices = indices if not isinstance(mapping, np.ndarray): self._mapping = np.array(mapping, int) elif not mapping.dtype == int: self._mapping = mapping.astype(int) else: self._mapping = mapping if not isinstance(dummies, np.ndarray): self._dummies = np.array(dummies, int) elif not dummies.dtype == int: self._dummies = dummies.astype(int) else: self._dummies = dummies self._title = str(title) self._len = len(self._dummies) + len(self._mapping)
def __init__(self, ag, indices, acsi=None, **kwargs): """Instantiate an atom map. :arg ag: AtomGroup instance from which atoms are mapped :arg indices: indices of mapped atoms :arg acsi: active coordinate set index, defaults is that of *ag* :arg mapping: mapping of atom *indices* :arg dummies: dummy atom indices :arg title: title of the instance, default is 'Unknown' *mapping* and *dummies* arrays must be provided together. Length of *mapping* must be equal to length of *indices*. Elements of *mapping* must be an ordered in ascending order. When dummy atoms are present, number of atoms is the sum of lengths of *mapping* and *dummies*. Following built-in functions are customized for this class: * :func:`len` returns the number of atoms in the instance. * :func:`iter` yields :class:`.Atom` instances. * Indexing returns an :class:`.Atom` or an :class:`.AtomMap` instance depending on the type and value of the index.""" AtomPointer.__init__(self, ag, acsi) self._dummies = self._mapping = None mapping = kwargs.get('mapping', None) dummies = kwargs.get('dummies', False) if mapping is None: if not kwargs.get('intarrays'): indices = array(indices, int) try: len(dummies) except TypeError: pass else: raise TypeError('mapping and dummies must be provided ' 'together') self._len = len(indices) if dummies: dummies = (indices == DUMMY).nonzero()[0] if len(dummies): self._dummies = dummies self._mapping = (indices < DUMMY).nonzero()[0] self._indices = indices[self._mapping] self._idarray = indices else: self._indices = self._idarray = indices else: self._indices = self._idarray = indices else: if dummies is None: raise TypeError('mapping and dummies must be provided ' 'together') if len(mapping) != len(indices): raise ValueError('indices and mapping arrays must have the ' 'same length') if not kwargs.get('intarrays'): indices = array(indices, int) mapping = array(mapping, int) dummies = array(dummies, int) if any(mapping[1:] - mapping[:-1] < 0): raise ValueError('mapping must be an ordered array') self._len = len(indices) if len(dummies): self._indices = indices self._mapping = mapping self._dummies = dummies self._len += len(dummies) self._idarray = idarray = zeros(self._len, int) idarray[self._mapping] = self._indices idarray[self._dummies] = DUMMY else: self._indices = self._idarray = indices[mapping] self._title = str(kwargs.get('title', 'Unknown'))
def __init__(self, ag, index, acsi): AtomPointer.__init__(self, ag, acsi) self._index = int(index)