Ejemplo n.º 1
0
    def _process_plot_kwargs(self, kwargs):
        import matplotlib.colors
        from itertools import cycle

        kw = {}
        frames = kwargs.pop('frames', None)
        if frames is None:
            frames = numpy.sort(self.profiles.keys()[::kwargs.pop('step', 1)])
        else:
            frames = asiterable(frames)
        kw['frames'] = frames
        kw['yshift'] = kwargs.pop('yshift', 0.0)
        kw['rmax'] = kwargs.pop('rmax', None)
        kw['label'] = kwargs.pop('label', True)
        if kw['label'] == "_nolegend_":
            kw['label'] = False
        elif kw['label'] is None:
            kw['label'] = True
        color = kwargs.pop('color', None)
        if color is None:
            cmap = kwargs.pop('cmap', matplotlib.cm.jet)
            normalize = matplotlib.colors.normalize(vmin=numpy.min(frames), vmax=numpy.max(frames))
            colors = cmap(normalize(frames))
        else:
            colors = cycle(asiterable(color))
        kw['colors'] = colors
        kw['linestyles'] = cycle(asiterable(kwargs.pop('linestyle', '-')))
        return kw, kwargs
Ejemplo n.º 2
0
    def _write_REMARK(self, fh, remarks, remarknumber=1):
        """Write REMARK record.

        The *remarknumber* is typically 1 but :program:`pdb2pgr`
        also uses 6 for the total charge and 5 for warnings.
        """
        for line in util.asiterable(remarks):  # either one line or multiple lines
            fh.write("REMARK   {0} {1}\n".format(remarknumber, line))
Ejemplo n.º 3
0
def _process_selection(select):
    """Return a canonical selection dictionary.

    :Arguments:
      *select*
         - any valid selection string for
           :meth:`~MDAnalysis.core.AtomGroup.AtomGroup.selectAtoms` that produces identical
           selections in *mobile* and *reference*; or
         - dictionary ``{'mobile':sel1, 'reference':sel2}``.
           The :func:`fasta2select` function returns such a
           dictionary based on a ClustalW_ or STAMP_ sequence alignment.
         - tuple ``(sel1, sel2)``

    :Returns: dict with keys `reference` and `mobile`; the values are guaranteed to
              be iterable (so that one can provide selections that retain order)
    """
    if type(select) is str:
        select = {'reference': select, 'mobile': select}
    elif type(select) is tuple:
        try:
            select = {'mobile': select[0], 'reference': select[1]}
        except IndexError:
            raise IndexError("select must contain two selection strings "
                             "(reference, mobile)")
    elif type(select) is dict:
        # compatability hack to use new nomenclature
        try:
            select['mobile'] = select['target']
            warnings.warn("use key 'mobile' instead of deprecated 'target'; "
                          "'target' will be removed in 0.8",
                          DeprecationWarning)
        except KeyError:
            pass
        try:
            select['mobile']
            select['reference']
        except KeyError:
            raise KeyError("select dictionary must contain entries for keys "
                           "'mobile' and 'reference'.")
    else:
        raise TypeError("'select' must be either a string, 2-tuple, or dict")
    select['mobile'] = asiterable(select['mobile'])
    select['reference'] = asiterable(select['reference'])
    return select
Ejemplo n.º 4
0
 def _get_atomnames(self, atoms):
     """Return a list of atom names"""
     # AtomGroup
     try:
         return atoms.names()
     except AttributeError:
         pass
     # universe?
     try:
         return atoms.atoms.names()
     except AttributeError:
         pass
     # list or string (can be a single atom name... deal with this in write_next_timestep() once we know numatoms)
     return numpy.asarray(util.asiterable(atoms))
Ejemplo n.º 5
0
 def _get_atomnames(self, atoms):
     """Return a list of atom names"""
     # AtomGroup
     try:
         return atoms.names()
     except AttributeError:
         pass
     # universe?
     try:
         return atoms.atoms.names()
     except AttributeError:
         pass
     # list or string (can be a single atom name... deal with this in write_next_timestep() once we know numatoms)
     return numpy.asarray(util.asiterable(atoms))
Ejemplo n.º 6
0
    def __init__(self, filenames, **kwargs):
        """Set up the chain reader.

        :Arguments:
           *filenames*
               file name or list of file names; the reader will open
               all file names and provide frames in the order of
               trajectories from the list. Each trajectory must
               contain the same number of atoms in the same order
               (i.e. they all must belong to the same topology). The trajectory
               format is deduced from the extension of *filename*.

               Extension: filenames are either single filename or list of file names in either plain file names
               format or (filename,format) tuple combination

           *skip*
               skip step (also passed on to the individual trajectory
               readers); must be same for all trajectories

           *delta*
               The time between frames in MDAnalysis time units if no
               other information is available. If this is not set then
               any call to :attr:`~ChainReader.time` will raise a
               :exc:`ValueError`.

           *kwargs*
               all other keyword arguments are passed on to each
               trajectory reader unchanged

        .. versionchanged:: 0.8
           The *delta* keyword was added.
        """
        self.filenames = asiterable(filenames)
        self.readers = [
            core.reader(filename, **kwargs) for filename in self.filenames
        ]
        self.__active_reader_index = 0  # pointer to "active" trajectory index into self.readers

        self.skip = kwargs.get('skip', 1)
        self._default_delta = kwargs.pop('delta', None)
        self.numatoms = self._get_same('numatoms')
        self.fixed = self._get_same('fixed')

        # Translation between virtual frames and frames in individual
        # trajectories.
        # Assumes that individual trajectories i contain frames that can
        # be addressed with an index 0 <= f < numframes[i]

        # Build a map of frames: ordered list of starting virtual
        # frames; the index i into this list corresponds to the index
        # into self.readers
        #
        # For virtual frame k (1...sum(numframes)) find corresponding
        # trajectory i and local frame f (i.e. readers[i][f] will
        # correspond to ChainReader[k]).

        # build map 'start_frames', which is used by _get_local_frame()
        numframes = self._get('numframes')
        # [0]: frames are 0-indexed internally
        # (see Timestep._check_slice_indices())
        self.__start_frames = numpy.cumsum([0] + numframes)

        self.numframes = numpy.sum(numframes)

        #: source for trajectories frame (fakes trajectory)
        self.__chained_trajectories_iter = None

        # make sure that iteration always yields frame 1
        # rewind() also sets self.ts
        self.ts = None
        self.rewind()
Ejemplo n.º 7
0
    def __init__(self, filenames, **kwargs):
        """Set up the chain reader.

        :Arguments:
           *filenames*
               file name or list of file names; the reader will open
               all file names and provide frames in the order of
               trajectories from the list. Each trajectory must
               contain the same number of atoms in the same order
               (i.e. they all must belong to the same topology). The trajectory
               format is deduced from the extension of *filename*.

               Extension: filenames are either single filename or list of file names in either plain file names
               format or (filename,format) tuple combination

           *skip*
               skip step (also passed on to the individual trajectory
               readers); must be same for all trajectories

           *delta*
               The time between frames in MDAnalysis time units if no
               other information is available. If this is not set then
               any call to :attr:`~ChainReader.time` will raise a
               :exc:`ValueError`.

           *kwargs*
               all other keyword arguments are passed on to each
               trajectory reader unchanged

        .. versionchanged:: 0.8
           The *delta* keyword was added.
        """
        self.filenames = asiterable(filenames)
        self.readers = [core.reader(filename, **kwargs) for filename in self.filenames]
        self.__active_reader_index = 0  # pointer to "active" trajectory index into self.readers

        self.skip = kwargs.get("skip", 1)
        self._default_delta = kwargs.pop("delta", None)
        self.numatoms = self._get_same("numatoms")
        self.fixed = self._get_same("fixed")

        # Translation between virtual frames and frames in individual
        # trajectories.
        # Assumes that individual trajectories i contain frames that can
        # be addressed with an index 0 <= f < numframes[i]

        # Build a map of frames: ordered list of starting virtual
        # frames; the index i into this list corresponds to the index
        # into self.readers
        #
        # For virtual frame k (1...sum(numframes)) find corresponding
        # trajectory i and local frame f (i.e. readers[i][f] will
        # correspond to ChainReader[k]).

        # build map 'start_frames', which is used by _get_local_frame()
        numframes = self._get("numframes")
        # [0]: frames are 0-indexed internally
        # (see Timestep._check_slice_indices())
        self.__start_frames = numpy.cumsum([0] + numframes)

        self.numframes = numpy.sum(numframes)

        #: source for trajectories frame (fakes trajectory)
        self.__chained_trajectories_iter = None

        # make sure that iteration always yields frame 1
        # rewind() also sets self.ts
        self.ts = None
        self.rewind()