def setup(self):
     x1 = [0.0, 1.0, 2.0, 3.0, 4.0]
     y1 = [0.1, 1.3, 1.8, 3.3, 4.2]
     luf1 = LookupFunction(x1, y1)
     x2 = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0]
     y2 = [0.6, 0.8, 1.3, 1.9, 2.6, 2.8, 3.3, 3.9]
     luf2 = LookupFunction(x2, y2)
     x3 = [1.0, 2.0]
     y3 = [1.0, 2.0]
     luf3 = LookupFunction(x3, y3)
     y4 = [1.1, 1.9]
     luf4 = LookupFunction(x3, y4)
     y5 = [1.2, 2.2]
     luf5 = LookupFunction(x3, y5)
     self.group = LookupFunctionGroup([luf1, luf2, luf3, luf4, luf5])
예제 #2
0
    def total_crossing_probability(self,
                                   steps=None,
                                   method="wham",
                                   force=False):
        """Return the total crossing probability using `method`

        Parameters
        ----------
        steps : iterable of :class:`.MCStep`
            cycles to be analyzed
        method : "wham" (later: or "mbar" or "tram")
            approach to use to combine the histograms
        force : bool (False)
            if true, cached results are overwritten
        """

        if method == "wham":
            run_ensembles = False
            for ens in self.ensembles:
                try:
                    hist = self.histograms['max_lambda'][ens]
                except KeyError:
                    run_ensembles = True
            if run_ensembles or force:
                if steps is None:
                    raise RuntimeError(
                        "Unable to build histograms without steps source")
                self.all_statistics(steps, force=True)

            df = histograms_to_pandas_dataframe(
                self.histograms['max_lambda'].values(),
                fcn="reverse_cumulative").sort_index(axis=1)
            # if lambdas not set, returns None and WHAM uses fallback
            lambdas = self.interfaces.lambdas
            wham = WHAM(interfaces=lambdas)
            # wham.load_from_dataframe(df)
            # wham.clean_leading_ones()
            tcp = wham.wham_bam_histogram(df).to_dict()
        elif method == "mbar":
            pass
        else:
            raise ValueError(
                "Only supported methods are 'wham' and 'mbar'.  " +
                "Whereas 'mbar' is not yet implemented!")

        self.tcp = LookupFunction(tcp.keys(), tcp.values())
        return self.tcp
예제 #3
0
    def from_ensemble_histograms(self, hists):
        """Calculate results from a dict of ensemble histograms.

        Parameters
        ----------
        hists : dict of {:class:`.Ensemble`: :class:`.numerics.Histogram`}
            histogram for each ensemble (from ``self.max_lambda_calc``)

        Returns
        -------
        :class:`.LookupFunction`
            the total crossing probability function
        """
        tcp_results = {}
        input_hists = [hists[ens] for ens in self.transition.ensembles]
        df = paths.numerics.histograms_to_pandas_dataframe(
            input_hists, fcn="reverse_cumulative").sort_index(axis=1)
        # TODO: remove WHAM-specific name here
        tcp = self.combiner.wham_bam_histogram(df).to_dict()
        return LookupFunction(tcp.keys(), tcp.values())
 def test_append(self):
     luf = LookupFunction([0.0, 1.0, 2.0], [0.5, 1.5, 2.5])
     self.group.append(luf)
     assert_almost_equal(self.group(1.0), 1.15)
 def test_setitem(self):
     luf = LookupFunction([0.0, 1.0, 2.0], [0.5, 1.5, 2.5])
     self.group[3] = luf
     assert_almost_equal(self.group(1.0), 1.16)