Ejemplo n.º 1
0
def points_from_selection(*args, **kwargs):
    """Create a list of points from selected atoms in a format suitable for ``qhull``.

    points_from_selection(topology, structure, selection="name CA", filename="points.dat", scale=None)

    :Arguments:
    - psf: Charmm topology file
    - pdb: coordinates
    - selection: MDAnalysis selectAtoms() selection string [C-alpha atoms]
    - filename: name of the output file; used as input for :class:`ConvexHull`
    - scale: scale points around the centre of geometry; values of 0.5 - 0.7 typically ensure that
      the convex hull is inside the protein; default is to not to scale, i.e. scale = 1.
    """

    from MDAnalysis import asUniverse
    u = asUniverse(*args, permissive=kwargs.pop('permissive', None))
    coordinates = u.selectAtoms(kwargs.pop('selection', "name CA")).coordinates()
    write_coordinates(kwargs.pop('filename', "points.dat"), coordinates, scale=kwargs.pop('scale',None))
Ejemplo n.º 2
0
def points_from_selection(*args, **kwargs):
    """Create a list of points from selected atoms in a format suitable for ``qhull``.

    points_from_selection(topology, structure, selection="name CA", filename="points.dat", scale=None)

    :Arguments:
    - psf: Charmm topology file
    - pdb: coordinates
    - selection: MDAnalysis selectAtoms() selection string [C-alpha atoms]
    - filename: name of the output file; used as input for :class:`ConvexHull`
    - scale: scale points around the centre of geometry; values of 0.5 - 0.7 typically ensure that
      the convex hull is inside the protein; default is to not to scale, i.e. scale = 1.
    """

    from MDAnalysis import asUniverse
    u = asUniverse(*args, permissive=kwargs.pop('permissive', None))
    coordinates = u.selectAtoms(kwargs.pop('selection',
                                           "name CA")).coordinates()
    write_coordinates(kwargs.pop('filename', "points.dat"),
                      coordinates,
                      scale=kwargs.pop('scale', None))
Ejemplo n.º 3
0
    def __init__(self, pdb, delta=1.0, atomselection='resname HOH and name O',
                 metadata=None, padding=1.0, sigma=None):
        """Construct the density from psf and pdb and the atomselection.

          DC = BfactorDensityCreator(pdb, delta=<delta>, atomselection=<MDAnalysis selection>,
                                  metadata=<dict>, padding=2, sigma=None)

          density = DC.Density()

        :Arguments:

          pdb
            PDB file or :class:`MDAnalysis.Universe`; a PDB is read with the
            simpl PDB reader. If the Bio.PDB reader is required, either set
            the *permissive_pdb_reader* flag to ``False`` in
            :data:`MDAnalysis.core.flags` or supply a Universe
            that was created with the `permissive` = ``False`` keyword.
          atomselection
            selection string (MDAnalysis syntax) for the species to be analyzed
          delta
            bin size for the density grid in Angstroem (same in x,y,z) [1.0]
          metadata
            dictionary of additional data to be saved with the object
          padding
            increase histogram dimensions by padding (on top of initial box size)
          sigma
            width (in Angstrom) of the gaussians that are used to build up the
            density; if None then uses B-factors from pdb

        For assigning X-ray waters to MD densities one might have to use a sigma
        of about 0.5 A to obtain a well-defined and resolved x-ray water density
        that can be easily matched to a broader density distribution.

        """
        from MDAnalysis import asUniverse

        u = asUniverse(pdb)
        group = u.selectAtoms(atomselection)
        coord = group.coordinates()
        logger.info("Selected %d atoms (%s) out of %d total." %
                    (coord.shape[0], atomselection, len(u.atoms)))
        smin = numpy.min(coord, axis=0) - padding
        smax = numpy.max(coord, axis=0) + padding

        BINS = fixedwidth_bins(delta, smin, smax)
        arange = zip(BINS['min'], BINS['max'])
        bins = BINS['Nbins']

        # get edges by doing a fake run
        grid, self.edges = numpy.histogramdd(numpy.zeros((1, 3)),
                                             bins=bins, range=arange, normed=False)
        self.delta = numpy.diag(map(lambda e: (e[-1] - e[0]) / (len(e) - 1), self.edges))
        self.midpoints = map(lambda e: 0.5 * (e[:-1] + e[1:]), self.edges)
        self.origin = map(lambda m: m[0], self.midpoints)
        numframes = 1

        if sigma is None:
            # histogram individually, and smear out at the same time
            # with the appropriate B-factor
            if numpy.any(group.bfactors == 0.0):
                wmsg = "Some B-factors are Zero (will be skipped)."
                logger.warn(wmsg)
                warnings.warn(wmsg, category=MissingDataWarning)
            rmsf = Bfactor2RMSF(group.bfactors)
            grid *= 0.0  # reset grid
            self.g = self._smear_rmsf(coord, grid, self.edges, rmsf)
        else:
            # histogram 'delta functions'
            grid, self.edges = numpy.histogramdd(coord, bins=bins, range=arange, normed=False)
            logger.info("Histogrammed %6d atoms from pdb." % len(group.atoms))
            # just a convolution of the density with a Gaussian
            self.g = self._smear_sigma(grid, sigma)

        try:
            metadata['pdb'] = pdb
        except TypeError:
            metadata = {'pdb': pdb}
        metadata['atomselection'] = atomselection
        metadata['numframes'] = numframes
        metadata['sigma'] = sigma
        self.metadata = metadata

        logger.info("Histogram completed (initial density in Angstrom**-3)")