예제 #1
0
파일: core.py 프로젝트: uitb/GromacsWrapper
    def store_xvg(self, name, a, **kwargs):
        """Store array *a* as :class:`~gromacs.formats.XVG` in result *name*.

        kwargs are passed to :class:`gromacs.formats.XVG`.

        This is a helper method that simplifies the task of storing
        results in the form of a numpy array as a data file on disk in
        the xmgrace format and also as a :class:`~gromacs.formats.XVG`
        instance in the :attr:`gromacs.analysis.core.Worker.results`
        dictionary.
        """
        from gromacs.formats import XVG
        kwargs.pop('filename', None)  # ignore filename
        filename = self.plugindir(name + '.xvg')
        xvg = XVG(**kwargs)
        xvg.set(a)
        xvg.write(filename)
        self.results[name] = xvg
        self.parameters.filenames[name] = filename
        return filename
예제 #2
0
    def store_xvg(self, name, a, **kwargs):
        """Store array *a* as :class:`~gromacs.formats.XVG` in result *name*.

        kwargs are passed to :class:`gromacs.formats.XVG`.

        This is a helper method that simplifies the task of storing
        results in the form of a numpy array as a data file on disk in
        the xmgrace format and also as a :class:`~gromacs.formats.XVG`
        instance in the :attr:`gromacs.analysis.core.Worker.results`
        dictionary.
        """
        from gromacs.formats import XVG
        kwargs.pop('filename',None)     # ignore filename
        filename = self.plugindir(name+'.xvg')
        xvg = XVG(**kwargs)
        xvg.set(a)
        xvg.write(filename)
        self.results[name] = xvg
        self.parameters.filenames[name] = filename
        return filename
예제 #3
0
    def analyze(self, **kwargs):
        """Load results from disk into :attr:`_Dihedrals.results` and compute PMF.

        The PMF W(phi) in kT is computed from each dihedral
        probability distribution P(phi) as

           W(phi) = -kT ln P(phi)

        It is stored in :attr:`_Dihedrals.results` with the key *PMF*.

        :Keywords:
          *bins*
             bins for histograms (passed to numpy.histogram(new=True))

        :Returns: a dictionary of the results and also sets
                  :attr:`_Dihedrals.results`.
        """

        bins = kwargs.pop("bins", 361)

        results = AttributeDict()

        # get graphs that were produced by g_angle
        for name, f in self.parameters.filenames.items():
            try:
                results[name] = XVG(f)
            except IOError:
                pass  # either not computed (yet) or some failure

        # compute individual distributions
        ts = results["timeseries"].array  # ts[0] = time, ts[1] = avg
        dih = ts[2:]

        phi_range = (-180.0, 180.0)

        Ndih = len(dih)
        p = Ndih * [None]  # histograms (prob. distributions), one for each dihedral i
        for i in xrange(Ndih):
            phis = dih[i]
            p[i], e = numpy.histogram(phis, bins=bins, range=phi_range, normed=True, new=True)

        P = numpy.array(p)
        phi = 0.5 * (e[:-1] + e[1:])  # midpoints of bin edges
        distributions = numpy.concatenate((phi[numpy.newaxis, :], P))  # phi, P[0], P[1], ...

        xvg = XVG()
        xvg.set(distributions)
        xvg.write(self.parameters.filenames["distributions"])
        results["distributions"] = xvg
        del xvg

        # compute PMF (from individual distributions)
        W = -numpy.log(P)  # W(phi)/kT = -ln P
        W -= W.min(axis=1)[:, numpy.newaxis]  # minimum at 0 kT
        pmf = numpy.concatenate((phi[numpy.newaxis, :], W), axis=0)
        xvg = XVG()
        xvg.set(pmf)
        xvg.write(self.parameters.filenames["PMF"])
        results["PMF"] = xvg

        self.results = results
        return results
    def analyze(self, **kwargs):
        """Load results from disk into :attr:`_Dihedrals.results` and compute PMF.

        The PMF W(phi) in kT is computed from each dihedral
        probability distribution P(phi) as

           W(phi) = -kT ln P(phi)

        It is stored in :attr:`_Dihedrals.results` with the key *PMF*.

        :Keywords:
          *bins*
             bins for histograms (passed to numpy.histogram(new=True))

        :Returns: a dictionary of the results and also sets
                  :attr:`_Dihedrals.results`.
        """

        bins = kwargs.pop('bins', 361)

        results = AttributeDict()

        # get graphs that were produced by g_angle
        for name, f in self.parameters.filenames.items():
            try:
                results[name] = XVG(f)
            except IOError:
                pass    # either not computed (yet) or some failure

        # compute individual distributions
        ts = results['timeseries'].array    # ts[0] = time, ts[1] = avg
        dih = ts[2:]

        phi_range = (-180., 180.)

        Ndih = len(dih)
        p = Ndih * [None]  # histograms (prob. distributions), one for each dihedral i
        for i in xrange(Ndih):
            phis = dih[i]
            p[i],e = numpy.histogram(phis, bins=bins, range=phi_range, normed=True, new=True)

        P = numpy.array(p)
        phi = 0.5*(e[:-1]+e[1:])   # midpoints of bin edges
        distributions = numpy.concatenate((phi[numpy.newaxis, :], P))  # phi, P[0], P[1], ...

        xvg = XVG()
        xvg.set(distributions)
        xvg.write(self.parameters.filenames['distributions'])
        results['distributions'] = xvg
        del xvg

        # compute PMF (from individual distributions)
        W = -numpy.log(P)                      # W(phi)/kT = -ln P
        W -= W.min(axis=1)[:, numpy.newaxis]   # minimum at 0 kT
        pmf = numpy.concatenate((phi[numpy.newaxis, :], W), axis=0)
        xvg = XVG()
        xvg.set(pmf)
        xvg.write(self.parameters.filenames['PMF'])
        results['PMF'] = xvg

        self.results = results
        return results