Пример #1
0
 def __init__(cls, name, bases, dict):
     
     for fname, field in ATOMIC_FIELDS.iteritems():
         
         if field.private:
             continue
         
         meth = field.meth_pl
         getMeth = 'get' + meth
 
         def getData(self, meth=field.meth_pl, dtype=field.dtype):
             data = getattr(self._ag, '_get' + meth)()
             if data is not None:
                 if self._mapping is None:
                     return data[self._indices]
                 else:
                     result = zeros((self._len,) + data.shape[1:], dtype)
                     result[self._mapping] = data[self._indices]
                     return result
 
         getData = wrapGetMethod(getData)
         getData.__name__ = getMeth
         if field.dtype in (int, float):
             zero = 0
         elif field.dtype == bool:
             zero = True
         else:
             zero = ''
         getData.__doc__ = (field.getDocstr('get', selex=False) +
                            ' Entries for dummy atoms will be ``{0:s}``.'
                            .format(repr(zero))) 
         setattr(cls, getMeth, getData)
         setattr(cls, '_' + getMeth, getData)
Пример #2
0
 def __init__(cls, name, bases, dict):
     
     for field in ATOMIC_FIELDS.values():
         
         if field.private:
             continue
         
         meth = field.meth
         getMeth = 'get' + meth
         setMeth = 'set' + meth
         # Define public method for retrieving a copy of data array
         if field.call:
             def getData(self, var=field.var, call=field.call):
                 if self._ag._data[var] is None:
                     [getattr(self._ag, meth)() for meth in call]
                 return self._ag._data[var][self._index] 
         else:
             def getData(self, var=field.var):
                 array = self._ag._data[var]
                 if array is None:
                     return None
                 return array[self._index] 
         getData = wrapGetMethod(getData)
         getData.__name__ = getMeth
         getData.__doc__ = field.getDocstr('get', False)
         setattr(cls, getMeth, getData)
         setattr(cls, '_' + getMeth, getData)
         
         if field.readonly:
             continue
         
         # Define public method for setting values in data array
         def setData(self, value, var=field.var, none=field.none):
             array = self._ag._data[var]
             if array is None:
                 raise AttributeError('attribute of the AtomGroup is '
                                      'not set')
             array[self._index] = value
             if none:
                 [self._ag.__setattr__(nm,  None) if nm[0] == '_' else
                  self._ag._data.__setitem__(nm,  None) for nm in none]
         setData = wrapSetMethod(setData)
         setData.__name__ = setMeth 
         setData.__doc__ = field.getDocstr('set', False)
         setattr(cls, setMeth, setData)
Пример #3
0
 def __init__(self, title='Unnamed'):
     
     self._title = str(title)
     self._n_atoms = 0
     self._coords = None
     self._hv = None
     self._sn2i = None
     self._timestamps = None
     self._kdtrees = None
     self._bmap = None
     self._bonds = None
     
     self._cslabels = []
     self._acsi = None
     self._n_csets = 0
     
     self._data = dict([(field.var, None) 
                        for field in ATOMIC_FIELDS.itervalues()])
Пример #4
0
 def __init__(cls, name, bases, dict):
     
     for field in ATOMIC_FIELDS.values():
         
         if field.private:
             continue
         
         meth = field.meth_pl
         getMeth = 'get' + meth
 
         if field.call:
             def getData(self, var=field.var, call=field.call, 
                         dtype=field.dtype):
                 for meth in call:
                     getattr(self._ag, meth)()
                 data = self._ag._data[var][self._indices]
                 result = np.zeros((self._len,) + data.shape[1:], dtype)
                 result[self._mapping] = data
                 return result 
 
         else:
             def getData(self, var=field.var, dtype=field.dtype):
                 array = self._ag._data[var]
                 if array is None:
                     return None
                 data = self._ag._data[var][self._indices]
                 result = np.zeros((self._len,) + data.shape[1:], dtype)
                 result[self._mapping] = data
                 return result
 
         getData = wrapGetMethod(getData)
         getData.__name__ = getMeth
         if field.dtype in (int, float):
             zero = 0
         elif field.dtype == bool:
             zero = True
         else:
             zero = ''
         getData.__doc__ = (field.getDocstr('get', selex=False) +
                            ' Entries for dummy atoms will be ``{0:s}``.'
                            .format(repr(zero))) 
         setattr(cls, getMeth, getData)
         setattr(cls, '_' + getMeth, getData)
Пример #5
0
    def __init__(cls, name, bases, dict):
    
        for field in ATOMIC_FIELDS.values():

            meth = field.meth_pl
            getMeth = 'get' + meth
            setMeth = 'set' + meth
            if field.call:
                # Define public method for retrieving a copy of data array
                if not field.private:
                    def getData(self, var=field.var, call=field.call):
                        if self._data[var] is None:
                            [getattr(self, meth)() for meth in call]
                        return self._data[var].copy()
                # Define private method for retrieving actual data array
                def _getData(self, var=field.var, call=field.call):
                    if self._data[var] is None:
                        [getattr(self, meth)() for meth in call]
                    return self._data[var]
            else:
                if not field.private:
                    def getData(self, var=field.var):
                        array = self._data[var]
                        if array is None:
                            return None
                        return array.copy() 
                def _getData(self, var=field.var):
                    return self._data[var]

            if not field.private:
                getData = wrapGetMethod(getData)
                getData.__name__ = getMeth
                getData.__doc__ = field.getDocstr('get')
                setattr(cls, getMeth, getData)
            
            _getData = wrapGetMethod(_getData)
            _getData.__name__ = '_' + getMeth
            _getData.__doc__ = field.getDocstr('_get')
            setattr(cls, '_' + getMeth, _getData)
            
            if field.readonly or field.private:
                continue
            
            # Define public method for setting values in data array
            def setData(self, array, var=field.var, dtype=field.dtype, 
                        ndim=field.ndim, none=field.none):
                if self._n_atoms == 0:
                    self._n_atoms = len(array)
                elif len(array) != self._n_atoms:
                    raise ValueError('length of array must match numAtoms')
                    
                if isinstance(array, list):
                    array = np.array(array, dtype)
                elif not isinstance(array, np.ndarray):
                    raise TypeError('array must be an ndarray or a list')
                elif array.ndim != ndim:
                        raise ValueError('array must be {0:d} dimensional'
                                         .format(ndim))
                elif array.dtype != dtype:
                    try:
                        array = array.astype(dtype)
                    except ValueError:
                        raise ValueError('array cannot be assigned type '
                                         '{0:s}'.format(dtype))
                self._data[var] = array
                if none:
                    [self.__setattr__(nm,  None) if nm[0] == '_' else
                     self._data.__setitem__(nm,  None) for nm in none]
            setData = wrapSetMethod(setData)
            setData.__name__ = setMeth 
            setData.__doc__ = field.getDocstr('set')
            setattr(cls, setMeth, setData)