def calc_all_expectations(self, filebase):
        print('Calculating all expectation values')
        all_aves = []
        all_stds = []
        all_tags = self._decor_outs.all_conditions.condition_tags
        series_tags = self._decor_outs.all_series_tags
        for i, tag in enumerate(series_tags):
            print('Calculating expectation of {} ({} of {})'.format(
                tag, i, len(series_tags)))
            values = self._decor_outs.get_concatenated_series(tag)
            aves, stds = self._calc_expectations(values)
            all_tags.append(tag)
            all_aves.append(aves)
            all_stds.append(stds)

        all_conds = self._decor_outs.all_conditions.condition_to_characteristic_values
        all_conds = np.array(all_conds, dtype=float)
        aves_file = files.TagOutFile('{}.aves'.format(filebase))
        aves_file.write(
            all_tags,
            np.concatenate([all_conds, np.array(all_aves).T], axis=1))
        stds_file = files.TagOutFile('{}.stds'.format(filebase))
        stds_file.write(
            all_tags,
            np.concatenate([all_conds, np.array(all_stds).T], axis=1))
    def calc_1d_lfes(self, reduced_conditions, filebase):
        print('Calculating all 1D LFEs')

        # This is bad
        temps = [str(c.temp) for c in reduced_conditions]
        all_tags = self._decor_outs.all_conditions.condition_tags
        series_tags = self._decor_outs.all_series_tags

        # Also bad
        for tag in ['tenergy', 'henthalpy', 'hentropy', 'stacking', 'bias']:
            series_tags.remove(tag)

        for i, tag in enumerate(series_tags):
            print('Calculating 1D LFEs of {} ({} of {})'.format(
                tag, i, len(series_tags)))
            values = self._decor_outs.get_concatenated_series(tag)
            bins = list(set(values))
            lfes, stds = self._calc_lfes(bins, values, reduced_conditions)

            # Ugly
            header = np.concatenate([['ops'], temps])
            lfes_filebase = '{}_{}-lfes'.format(filebase, tag)

            lfes_file = files.TagOutFile('{}.aves'.format(lfes_filebase))
            lfes = self._hack_prepare_1d_lfe_series_for_write(lfes, bins)
            lfes_file.write(header, lfes)

            stds_file = files.TagOutFile('{}.stds'.format(lfes_filebase))
            stds = self._hack_prepare_1d_lfe_series_for_write(stds, bins)
            stds_file.write(header, stds)
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
    out_filebase = create_output_filepathbase(args)
    conds = conditions.SimConditions(
        {
            'temp': args.temp,
            'staple_m': args.staple_m,
            'bias': biases.NoBias()
        }, fileformatter, staple_lengths)

    # Expecations along OP slices
    mbarws = []
    all_decor_outs = []
    sampled_ops = []
    for i in range(1, args.assembled_op + 1):
        sim_collections = create_simplesim_collections(args, inp_filebase,
                                                       all_conditions)
        decor_outs = decorrelate.SimpleDecorrelatedOutputs(
            sim_collections, all_conditions)
        decor_outs.read_decors_from_files()
        filtered_count = decor_outs.filter_collections(args.tag, i)
        if filtered_count == 0:
            continue

        sampled_ops.append(i)
        all_decor_outs.append(decor_outs)
        mbarw = mbar_wrapper.MBARWrapper(decor_outs)
        mbarw.perform_mbar()
        mbarws.append(mbarw)

    # Calculate expectations across selected order parameter
    all_tags = []
    for i in range(1, args.staple_types + 1):
        all_tags.append('staples{}'.format(i))
        all_tags.append('staplestates{}'.format(i))

    for i in range(args.scaffold_domains):
        all_tags.append('domainstate{}'.format(i))

    aves, stds = calc_reduced_expectations(conds, mbarws, all_decor_outs,
                                           all_tags)

    aves = np.concatenate([[sampled_ops], np.array(aves).T])
    aves_file = files.TagOutFile('{}-{}.aves'.format(out_filebase, args.tag))
    aves_file.write([args.tag] + all_tags, aves.T)

    stds = np.concatenate([[sampled_ops], np.array(stds).T])
    stds_file = files.TagOutFile('{}-{}.stds'.format(out_filebase, args.tag))
    stds_file.write([args.tag] + all_tags, stds.T)
Beispiel #4
0
    def calc_all_1d_means(self, filebase):
        means = []
        for weights in self._enum_weights:
            means.append(weights.calc_all_1d_means())

        all_conds = self._all_conditions.condition_to_characteristic_values
        tags = self._all_conditions.condition_tags + self._enum_weights[0].tags
        out_file = files.TagOutFile('{}.aves'.format(filebase))
        out_file.write(tags,
                       np.concatenate([all_conds, np.array(means)], axis=1))
    def calc_2d_lfes(self, tag1, tag2, reduced_conditions, filebase):
        temps = [str(c.temp) for c in reduced_conditions]
        decor_value_pairs = list(
            zip(self._decor_outs.get_concatenated_series(tag1),
                self._decor_outs.get_concatenated_series(tag2)))
        bins = list(set(decor_value_pairs))
        lfes, stds = self._calc_lfes(bins, decor_value_pairs,
                                     reduced_conditions)

        # Ugly
        header = np.concatenate([[tag1, tag2], temps])
        lfes_filebase = '{}_{}-{}-lfes'.format(filebase, tag1, tag2)

        lfes_file = files.TagOutFile('{}.aves'.format(lfes_filebase))
        lfes = self._hack_prepare_2d_lfe_series_for_write(lfes, bins)
        lfes_file.write(header, lfes)

        stds_file = files.TagOutFile('{}.stds'.format(lfes_filebase))
        stds = self._hack_prepare_2d_lfe_series_for_write(stds, bins)
        stds_file.write(header, stds)
Beispiel #6
0
    def calc_all_1d_lfes(self, filebase):
        for tag in self._enum_weights[0]._tags:
            bins = self._enum_weights[0].get_op_range(tag)
            lfes = []
            for weights in self._enum_weights:
                lfes.append(weights.calc_1d_lfes(bins, tag))

            all_conds = self._all_conditions.condition_to_characteristic_values
            all_tags = self._all_conditions.condition_tags
            temp_i = all_tags.index('temp')
            temps = [c[temp_i] for c in all_conds]
            header = np.concatenate([['ops'], temps])
            bins = np.array(bins).reshape(len(bins), 1)
            data = np.concatenate([bins, np.array(lfes).T], axis=1)
            lfes_filebase = '{}_{}-lfes'.format(filebase, tag)
            lfes_file = files.TagOutFile('{}.aves'.format(lfes_filebase))
            lfes_file.write(header, data)
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, system_file)
    staple_lengths = all_conditions._staple_lengths
    inp_filebase = create_input_filepathbase(args)

    mbarws = []
    all_decor_outs = []
    sampled_ops = []
    for i in range(1, args.assembled_op + 1):
        sim_collections = outputs.create_sim_collections(
            inp_filebase, all_conditions, args.reps)
        decor_outs = decorrelate.DecorrelatedOutputs(sim_collections,
                                                     all_conditions)
        decor_outs.read_decors_from_files(data_only=True)
        filtered_count = decor_outs.filter_collections(args.tag, i)
        if filtered_count == 0:
            continue

        sampled_ops.append(i)
        all_decor_outs.append(decor_outs)
        mbarw = mbar_wrapper.MBARWrapper(decor_outs)
        mbarw.perform_mbar()
        mbarws.append(mbarw)

    out_filebase = create_output_filepathbase(args)

    # Calculate expectations across selected order parameter
    conds = conditions.SimConditions(
        {
            'temp': args.temp,
            'staple_m': args.staple_m,
            'bias': biases.NoBias()
        }, fileformatter, staple_lengths)
    all_tags = []
    for i in range(1, args.staple_types + 1):
        all_tags.append('staples{}'.format(i))
        all_tags.append('staplestates{}'.format(i))

    for i in range(args.scaffold_domains):
        all_tags.append('domainstate{}'.format(i))

    aves, stds = calc_reduced_expectations(conds, mbarws, all_decor_outs,
                                           all_tags)

    aves = np.concatenate([[sampled_ops], np.array(aves).T])
    aves_file = files.TagOutFile('{}-{}.aves'.format(out_filebase, args.tag))
    aves_file.write([args.tag] + all_tags, aves.T)

    stds = np.concatenate([[sampled_ops], np.array(stds).T])
    stds_file = files.TagOutFile('{}-{}.stds'.format(out_filebase, args.tag))
    stds_file.write([args.tag] + all_tags, stds.T)

    # Hacky calculation for plotting a melting temperature LFE curve
    sim_collections = outputs.create_sim_collections(inp_filebase,
                                                     all_conditions, args.reps)
    decor_outs = decorrelate.DecorrelatedOutputs(sim_collections,
                                                 all_conditions)
    decor_outs.read_decors_from_files()
    mbarw = mbar_wrapper.MBARWrapper(decor_outs)
    mbarw.perform_mbar()
    values = decor_outs.get_concatenated_series(args.tag)
    decor_enes = decor_outs.get_concatenated_datatype('enes')
    decor_ops = decor_outs.get_concatenated_datatype('ops')
    decor_staples = decor_outs.get_concatenated_datatype('staples')
    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)
    conds = conditions.SimConditions(
        {
            'temp': args.temp,
            'staple_m': args.staple_m,
            'bias': biases.NoBias()
        }, fileformatter, staple_lengths)
    lfes, lfe_stds = calc_lfes(mbarw, conds, bins, bin_index_series,
                               decor_enes, decor_ops, decor_staples)
    header = np.array(['ops', args.temp])
    lfes_filebase = '{}_{}-lfes-melting'.format(out_filebase, args.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)
Beispiel #8
0
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, system_file)
    staple_lengths = all_conditions._staple_lengths
    inp_filebase = create_input_filepathbase(args)
    sim_collections = outputs.create_sim_collections(inp_filebase,
                                                     all_conditions, args.reps)
    decor_outs = decorrelate.DecorrelatedOutputs(
        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)

    values = decor_outs.get_concatenated_series(args.tag)
    decor_enes = decor_outs.get_concatenated_datatype('enes')
    decor_ops = decor_outs.get_concatenated_datatype('ops')
    decor_staples = decor_outs.get_concatenated_datatype('staples')
    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)
    conds = conditions.SimConditions({'temp': args.guess_temp, 'staple_m': args.staple_m,
                                      'bias': biases.NoBias()}, fileformatter, staple_lengths)
    melting_temp = minimize(squared_barrier_diff, args.guess_temp,
                            args=(mbarw, values, bins, bin_index_series, decor_enes, decor_ops, decor_staples,
                                  conds)).x[0]
    lfes, lfe_stds = calc_lfes(mbarw, conds, bins, bin_index_series, decor_enes,
                               decor_ops, decor_staples)
    barrier_height = np.around(calc_forward_barrier_height(lfes), decimals=3)
    barrier_i = find_barrier(lfes)
    melting_temp = '{:.3f}'.format(np.around(melting_temp, decimals=3))

    print('Estimated melting temperature: {} K'.format(melting_temp))
    print('Barrier height: {:.3f} kT'.format(barrier_height))
    print('Barrier peak: {:.3f}'.format(bins[barrier_i]))

    header = np.array(['ops', melting_temp])
    lfes_filebase = '{}_{}-lfes-melting'.format(out_filebase, args.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)

    # Calculated 2D LFEs
    tag2 = 'numfulldomains'
    decor_op_pairs = list(zip(decor_outs.get_concatenated_series(args.tag),
                              decor_outs.get_concatenated_series(tag2)))
    bins = list(set(decor_op_pairs))
    value_to_bin = {value: i for i, value in enumerate(bins)}
    bin_index_series = [value_to_bin[i] for i in decor_op_pairs]
    bin_index_series = np.array(bin_index_series)
    lfes, lfe_stds = calc_lfes(mbarw, conds, bins, bin_index_series, decor_enes,
                               decor_ops, decor_staples)
    header = np.array([args.tag, tag2, melting_temp])
    lfes_filebase = '{}_{}-{}-lfes-melting'.format(
        out_filebase, args.tag, tag2)
    bins = np.array(bins).reshape(len(bins), 2)

    lfes = np.concatenate([bins, np.array(lfes, ndmin=2).T], axis=1)
    lfes_file = files.TagOutFile('{}.aves'.format(lfes_filebase))
    lfes_file.write(header, lfes)

    lfe_stds = np.concatenate([bins, np.array(lfe_stds, ndmin=2).T], axis=1)
    stds_file = files.TagOutFile('{}.stds'.format(lfes_filebase))
    stds_file.write(header, lfe_stds)

    # Calculate expectations along the selected OP
    mbarws = []
    all_decor_outs = []
    sampled_ops = []
    for i in range(1, args.assembled_op + 1):
        sim_collections = outputs.create_sim_collections(inp_filebase,
                                                         all_conditions, args.reps)
        decor_outs = decorrelate.DecorrelatedOutputs(
            sim_collections, all_conditions)
        decor_outs.read_decors_from_files(data_only=True)
        filtered_count = decor_outs.filter_collections(args.tag, i)
        if filtered_count == 0:
            continue

        sampled_ops.append(i)
        all_decor_outs.append(decor_outs)
        mbarw = mbar_wrapper.MBARWrapper(decor_outs)
        mbarw.perform_mbar()
        mbarws.append(mbarw)

    out_filebase = create_output_filepathbase(args)

    # Calculate expectations across selected order parameter
    all_tags = []
    for i in range(1, args.staple_types + 1):
        all_tags.append('staples{}'.format(i))
        all_tags.append('staplestates{}'.format(i))

    for i in range(args.scaffold_domains):
        all_tags.append('domainstate{}'.format(i))

    aves, stds = calc_reduced_expectations(
        conds, mbarws, all_decor_outs, all_tags)

    aves = np.concatenate([[sampled_ops], np.array(aves).T])
    aves_file = files.TagOutFile('{}-{}.aves'.format(out_filebase, args.tag))
    aves_file.write([args.tag] + all_tags, aves.T)

    stds = np.concatenate([[sampled_ops], np.array(stds).T])
    stds_file = files.TagOutFile('{}-{}.stds'.format(out_filebase, args.tag))
    stds_file.write([args.tag] + all_tags, stds.T)
Beispiel #9
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)])])