def calc_expectation(self, values, conds):
        decor_enes = self._decor_outs.get_concatenated_datatype('enes')
        decor_ops = self._decor_outs.get_concatenated_datatype('ops')
        decor_staples = self._decor_outs.get_concatenated_datatype('staples')
        rpots = utility.calc_reduced_potentials(decor_enes, decor_ops,
                                                decor_staples, conds)
        ave, vari = self._mbar.computeExpectations(values, rpots)
        ave = ave[0].astype(float)
        std = np.sqrt(vari)[0].astype(float)

        return ave, std
Beispiel #2
0
 def _construct_decorrelation_mask(self, sim_collection, rep, skip):
     enes = sim_collection.reps_energies[rep]
     ops = sim_collection.reps_order_params[rep]
     steps = enes.steps
     rpots = utility.calc_reduced_potentials(enes, ops,
                                             sim_collection.conditions)
     start_i, g, Neff = timeseries.detectEquilibration(rpots, nskip=skip)
     template = '{:<8} {:<8} {:<3} {:<4.1f} {:<.1f}'
     print(template.format(sim_collection.conditions.fileformat, steps,
             start_i, g, Neff))
     indices = (timeseries.subsampleCorrelatedData(rpots[start_i:], g=skip*g))
     return [i + start_i for i in indices]
    def _calc_decorrelated_rpots_for_all_conditions(self):
        conditions_rpots = []
        decor_enes = self._decor_outs.get_concatenated_datatype('enes')
        decor_ops = self._decor_outs.get_concatenated_datatype('ops')
        for conditions in self._decor_outs.all_conditions:
            # What if I just want to do one rep?
            rpots = utility.calc_reduced_potentials(decor_enes, decor_ops,
                                                    conditions)
            conditions_rpots.append(rpots)
            # I should split this up if I want to separate mbar from calcs that use it
            self._conditions_to_decor_rpots[conditions.fileformat] = rpots

        return np.array(conditions_rpots)
    def _calc_decorrelated_rpots_for_all_conditions(self):
        conditions_rpots = []
        decor_enes = self._decor_outs.get_concatenated_datatype('enes')
        decor_ops = self._decor_outs.get_concatenated_datatype('ops')
        for conditions in self._decor_outs.all_conditions:
            # What if I just want to do one rep?
            rpots = utility.calc_reduced_potentials(decor_enes, decor_ops,
                    conditions)
            conditions_rpots.append(rpots)
            # I should split this up if I want to separate mbar from calcs that use it
            self._conditions_to_decor_rpots[conditions.fileformat] = rpots

        return np.array(conditions_rpots)
def calc_lfes(mbarw, conds, bins, bin_index_series, decor_enes, decor_ops,
              decor_staples):
    rpots = utility.calc_reduced_potentials(decor_enes, decor_ops,
                                            decor_staples, conds)

    return mbarw._mbar.computePMF(rpots, bin_index_series, len(bins))
Beispiel #6
0
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    inp_filebase = create_input_filepathbase(args)
    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, inp_filebase,
                                          system_file)
    staple_lengths = system_file._staple_lengths
    sim_collections = create_simplesim_collections(args, inp_filebase,
                                                   all_conditions)
    decor_outs = decorrelate.SimpleDecorrelatedOutputs(sim_collections,
                                                       all_conditions)
    decor_outs.read_decors_from_files()

    mbarw = mbar_wrapper.MBARWrapper(decor_outs)
    mbarw.perform_mbar()

    out_filebase = create_output_filepathbase(args)
    conds = conditions.SimConditions(
        {
            'temp': args.temp,
            'staple_m': args.staple_m,
            'bias': biases.NoBias()
        }, fileformatter, staple_lengths)
    all_tags = decor_outs.all_conditions.condition_tags
    aves = []
    stds = []
    for tag in decor_outs.all_series_tags:
        all_tags.append(tag)
        series = decor_outs.get_concatenated_series(tag)
        ave, std = mbarw.calc_expectation(series, conds)
        aves.append(ave)
        stds.append(std)

        # Hack calculate LFEs
        values = decor_outs.get_concatenated_series(tag)
        decor_enes = decor_outs.get_concatenated_datatype('enes')
        decor_ops = decor_outs.get_concatenated_datatype('ops')
        bins = list(set(values))
        bins.sort()
        value_to_bin = {value: i for i, value in enumerate(bins)}
        bin_index_series = [value_to_bin[i] for i in values]
        bin_index_series = np.array(bin_index_series)
        rpots = utility.calc_reduced_potentials(decor_enes, decor_ops, conds)
        lfes, lfe_stds = mbarw._mbar.computePMF(rpots, bin_index_series,
                                                len(bins))

        # Hack write LFEs to file
        header = np.array(['ops', args.temp])
        lfes_filebase = '{}_{}-lfes-melting'.format(out_filebase, tag)
        lfes_file = files.TagOutFile('{}.aves'.format(lfes_filebase))
        lfes = np.concatenate([[bins], [lfes]]).T
        lfes_file.write(header, lfes)
        stds_file = files.TagOutFile('{}.stds'.format(lfes_filebase))
        lfe_stds = np.concatenate([[bins], [lfe_stds]]).T
        stds_file.write(header, lfe_stds)

    # Hack to write expectations to file
    aves_file = files.TagOutFile('{}.aves'.format(out_filebase))
    cond_char_values = conds.condition_to_characteristic_value
    cond_values = [v for k, v in sorted(cond_char_values.items())]
    aves_file.write(all_tags, [np.concatenate([cond_values, np.array(aves)])])
    stds_file = files.TagOutFile('{}.stds'.format(out_filebase))
    stds_file.write(all_tags, [np.concatenate([cond_values, np.array(stds)])])