Exemple #1
0
    def _unpack_simple_data(self, start, end=None):

        self.all_data = np.array([], dtype=np.float32)
        self.all_data_aux = np.array([], dtype=DTYPE)
        self.n_samples = np.array([]).astype(int)
        self.bias_mat = None

        # If autocorr not set, set it ouselves
        if self.calc_autocorr:
            self.autocorr = np.zeros(self.n_windows)

        for i, (ds_name, ds) in enumerate(self.dr.datasets.items()):
            log.info('extracting ds {}'.format(i))

            if self.ts == None:
                self.ts = []

            # Sanity check - every input should have same timestep
            #else:
            #    np.testing.assert_almost_equal(self.ts, ds.ts)
            self.ts.append(ds.ts)
            data = ds.data[start:end]
            dataframe = np.array(data)

            if self.calc_autocorr:
                autocorr_len = np.ceil(
                    pymbar.timeseries.integratedAutocorrelationTime(
                        dataframe[:, -1]))
                self.autocorr[i] = ds.ts * autocorr_len

            self.n_samples = np.append(self.n_samples, dataframe.shape[0])

            if self.bias_mat is None:
                self.bias_mat = self.beta * dataframe.copy()
            else:
                self.bias_mat = np.vstack(
                    (self.bias_mat, self.beta * dataframe))

            self.all_data = np.append(self.all_data, dataframe[:, -1])
            #self.all_data_aux = np.append(self.all_data_aux, ds.aux_data[start:end])

            del ds

        #if do_autocorr:
        log.info("saving integrated autocorr times (in ps) to 'autocorr.dat'")
        np.savetxt(
            'autocorr.dat',
            self.autocorr,
            header='integrated autocorrelation times for each window (in ps)')
        self.ts = np.array(self.ts)
        dr.clearData()
Exemple #2
0
    def _unpack_xvg_data(self, start, end=None):

        self.all_data = None
        self.n_samples = np.array([], dtype=np.int32)
        self.bias_mat = None

        if self.autocorr is None:
            do_autocorr = True
            self.autocorr = np.zeros(self.n_windows)
        else:
            do_autocorr = False

        for i, (ds_name, ds) in enumerate(self.dr.datasets.iteritems()):
            log.info("Unpacking {}th dataset ({:s})".format(i, ds_name))

            if self.ts == None:
                self.ts = ds.ts
            else:
                np.testing.assert_almost_equal(self.ts, ds.ts)
            dataframe = np.array(ds.data[start:end], dtype=np.float32)

            if do_autocorr:
                log.info("    Calculating autocorrelation time...")
                autocorr_nsteps = 1
                for k in xrange(self.n_windows):
                    if k == i:
                        continue
                    try:
                        autocorr_res = 2 * np.ceil(pymbar.timeseries.integratedAutocorrelationTime(dataframe[:,k]))
                        if autocorr_res > autocorr_nsteps:
                            autocorr_nsteps = autocorr_res
                    except:
                        continue
                self.autocorr[i] = self.ts * autocorr_nsteps * 0.5
                log.info("      Tau={} ps".format(self.autocorr[i]))
            bias = self.beta*dataframe # biased values for all windows
            self.n_samples = np.append(self.n_samples, dataframe.shape[0])

            if self.all_data is None:
                self.all_data = dataframe
            else:
                self.all_data = np.vstack((self.all_data, dataframe))

            if self.bias_mat is None:
                self.bias_mat = bias
            else:
                self.bias_mat = np.vstack((self.bias_mat, bias))

        dr.clearData()
Exemple #3
0
    def _unpack_pmf_data(self, start, end=None):

        self.all_data = np.array([], dtype=DTYPE)
        self.all_data_aux = np.array([], dtype=DTYPE)
        self.n_samples = np.array([]).astype(int)

        # If autocorr not set, set it ouselves
        if self.calc_autocorr:
            self.autocorr = np.zeros(self.n_windows)

        for i, (ds_name, ds) in enumerate(self.dr.datasets.items()):

            if self.ts == None:
                self.ts = ds.ts
            # Sanity check - every input should have same timestep
            else:
                np.testing.assert_almost_equal(self.ts, ds.ts)

            data = ds.data[start:end]
            dataframe = np.array(data['dr_sq'])

            if self.calc_autocorr:
                autocorr_len = np.ceil(
                    pymbar.timeseries.integratedAutocorrelationTime(
                        dataframe[:]))
                self.autocorr[i] = ds.ts * autocorr_len

            self.n_samples = np.append(self.n_samples, dataframe.shape[0])

            self.all_data = np.append(self.all_data, dataframe)
            self.all_data_aux = np.append(self.all_data_aux, dataframe)

        self.bias_mat = np.zeros((self.n_tot, self.n_windows),
                                 dtype=np.float32)

        # Ugh !
        for i, (ds_name, ds) in enumerate(self.dr.datasets.items()):
            self.bias_mat[:,
                          i] = self.beta * (0.5 * ds.kappa * (self.all_data))

        log.info("saving integrated autocorr times (in ps) to 'autocorr.dat'")
        np.savetxt(
            'autocorr.dat',
            self.autocorr,
            header='integrated autocorrelation times for each window (in ps)')

        dr.clearData()
Exemple #4
0
    def _unpack_phi_data(self, start, end=None):

        self.all_data = np.array([], dtype=np.float32)
        self.all_data_N = np.array([]).astype(int)
        self.n_samples = np.array([]).astype(int)

        if self.autocorr is None:
            do_autocorr = True
            self.autocorr = np.zeros(self.n_windows)
        else:
            do_autocorr = False

        for i, (ds_name, ds) in enumerate(self.dr.datasets.iteritems()):

            if self.ts == None:
                self.ts = ds.ts
            # Sanity check - every input should have same timestep
            else:
                np.testing.assert_almost_equal(self.ts, ds.ts)

            data = ds.data[start:end]
            dataframe = np.array(data['$\~N$'])
            dataframe_N = np.array(data['N']).astype(np.int32)

            if do_autocorr:
                autocorr_len = np.ceil(pymbar.timeseries.integratedAutocorrelationTime(dataframe[:]))
                self.autocorr[i] = self.ts * autocorr_len

            self.n_samples = np.append(self.n_samples, dataframe.shape[0])

            self.all_data = np.append(self.all_data, dataframe)
            self.all_data_N = np.append(self.all_data_N, dataframe_N)

        self.bias_mat = np.zeros((self.n_tot, self.n_windows), dtype=np.float32)

        # Ugh !
        for i, (ds_name, ds) in enumerate(self.dr.datasets.iteritems()):
            self.bias_mat[:, i] = self.beta*(0.5*ds.kappa*(self.all_data-ds.Nstar)**2 + ds.phi*self.all_data) 

        dr.clearData()
Exemple #5
0
    this_uncorr_ntwid_dat = this_ntwid_dat[rem:].reshape(n_uncorr_sample, g_inef).mean(axis=1)

    uncorr_phi_vals.append(this_uncorr_phi)
    uncorr_psi_vals.append(this_uncorr_psi)
    uncorr_nreg_dat.append(this_uncorr_nreg_dat)
    uncorr_ntwid_dat.append(this_uncorr_ntwid_dat)

    print("  n_samples: {}, uncorr_n_samples: {}".format(n_sample, n_uncorr_sample))

    nreg_dat.append(n_dat['N'])
    ntwid_dat.append(n_dat['$\~N$'])
    phi_vals.append(this_phi)
    psi_vals.append(this_psi)
    n_samples.append(n_sample)
    uncorr_n_samples.append(n_uncorr_sample)
    dr.clearData()


phi_vals = np.concatenate(phi_vals)
psi_vals = np.concatenate(psi_vals)
uncorr_phi_vals = np.concatenate(uncorr_phi_vals)
uncorr_psi_vals = np.concatenate(uncorr_psi_vals)

nreg_dat = np.concatenate(nreg_dat)
ntwid_dat = np.concatenate(ntwid_dat)
uncorr_nreg_dat = np.concatenate(uncorr_nreg_dat)
uncorr_ntwid_dat = np.concatenate(uncorr_ntwid_dat)

assert phi_vals.size == psi_vals.size == ntwid_dat.size == nreg_dat.size

n_samples = np.array(n_samples)
Exemple #6
0
    def _unpack_phi_data(self, start, end=None):

        self.all_data = np.array([], dtype=DTYPE)
        self.all_data_aux = np.array([], dtype=DTYPE)
        self.n_samples = np.array([]).astype(int)
        # For subvol Ntwid - may not be used.
        self.sub_all_data = np.array([], dtype=DTYPE)

        self.kappas = np.zeros(self.n_windows, dtype=DTYPE)
        self.phis = np.zeros(self.n_windows, dtype=DTYPE)
        self.Nstars = np.zeros(self.n_windows, dtype=DTYPE)
        self.avg_N = np.zeros(self.n_windows, dtype=DTYPE)

        ## May not be used
        self.sub_kappas = np.zeros_like(self.kappas)
        self.sub_phis = np.zeros_like(self.phis)
        self.sub_Nstars = np.zeros_like(self.Nstars)

        # If autocorr not set, set it ouselves
        if self.calc_autocorr:
            self.autocorr = np.zeros(self.n_windows)

        for i, (ds_name, ds) in enumerate(self.dr.datasets.items()):

            log.info("Extracting {}th dataset {}".format(i, ds_name))

            if self.ts == None:
                self.ts = ds.ts
            # Sanity check - every input should have same timestep
            else:
                np.testing.assert_almost_equal(self.ts, ds.ts)

            data = ds.data[start:end]
            dataframe = np.array(data['$\~N$'])
            dataframe_N = np.array(data['N']).astype(np.int32)

            if self.calc_autocorr:
                autocorr_len = np.ceil(
                    pymbar.timeseries.integratedAutocorrelationTime(
                        dataframe[:]))
                self.autocorr[i] = ds.ts * autocorr_len

            self.n_samples = np.append(self.n_samples, dataframe.shape[0])

            self.all_data = np.append(self.all_data, dataframe)
            self.all_data_aux = np.append(self.all_data_aux, dataframe_N)

            self.kappas[i] = ds.kappa
            self.phis[i] = ds.phi
            self.Nstars[i] = ds.Nstar
            self.avg_N[i] = dataframe.mean()
            log.info("   kappa: {:.5f}  phi: {:.5f}  Nstar: {:.2f}".format(
                ds.kappa, ds.phi, ds.Nstar))

            # Load in sub vol data, if provided.
            if self.phisub:
                sub_data = ds.ds_sub.data[start:end]
                sub_dataframe = np.array(sub_data['$\~N$'])
                self.sub_all_data = np.append(self.sub_all_data, sub_dataframe)

                self.sub_kappas[i] = ds.ds_sub.kappa
                self.sub_phis[i] = ds.ds_sub.kappa
                self.sub_Nstars[i] = ds.ds_sub.Nstar

        self.bias_mat = np.zeros((self.n_tot, self.n_windows),
                                 dtype=np.float32)

        # Ugh !
        for i, (ds_name, ds) in enumerate(self.dr.datasets.items()):

            self.bias_mat[:, i] = self.beta * (0.5 * ds.kappa *
                                               (self.all_data - ds.Nstar)**2 +
                                               ds.phi * self.all_data)

            if self.phisub:
                self.bias_mat[:, i] += self.beta * (
                    0.5 * ds.ds_sub.kappa *
                    (self.sub_all_data - ds.ds_sub.Nstar)**2 +
                    ds.ds_sub.phi * self.sub_all_data)

        log.info("saving integrated autocorr times (in ps) to 'autocorr.dat'")
        np.savetxt(
            'autocorr.dat',
            self.autocorr,
            header='integrated autocorrelation times for each window (in ps)')

        dr.clearData()