Пример #1
0
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, system_file)
    inp_filebase = create_input_filepathbase(args)
    sim_collections = outputs.create_sim_collections(inp_filebase,
                                                     all_conditions, args.reps)
    reps = len(sim_collections[0]._reps)
    reps_converged = [False for i in range(reps)]
    for rep in range(reps):
        for sim_collection in sim_collections:
            ops = sim_collection.get_reps_data('ops')[rep]
            stacked_pairs = ops['numstackedpairs']
            fully_stacked = np.where(
                stacked_pairs == args.fully_stacked_pairs)[0]
            if len(fully_stacked) == 0:
                continue

            steps_since_fully_stacked = len(stacked_pairs) - fully_stacked[0]
            if steps_since_fully_stacked > args.prod_steps:
                reps_converged[rep] = True
                break

    if np.all(reps_converged):
        print(1)
    else:
        print(0)
Пример #2
0
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, system_file)
    inp_filebase = create_input_filepathbase(args)
    sim_collections = outputs.create_sim_collections(inp_filebase,
                                                     all_conditions, args.reps)
    for sim_collection in sim_collections:
        for rep in sim_collection._reps:
            ops = sim_collection.get_reps_data('ops', concatenate=False)
            runs = len(ops[rep])
            for run in range(runs):
                run_filebase = sim_collection.get_filebase(run, rep)
                states_filename = '{}.states'.format(run_filebase)
                states = np.loadtxt(states_filename)[:, :args.scaffold_domains]
                states = states == 2
                ops = datatypes.OrderParams.from_file(run_filebase)
                for i in range(args.scaffold_domains):
                    tag = 'domainstate{}'.format(i)
                    if tag in ops.tags:
                        ops[tag] = states[:, i]
                    else:
                        ops.add_column(tag, states[:, i])

                ops.to_file(run_filebase)
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    traj_file = files.TxtTrajInpFile(args.traj_filename, system_file)
    ref_ext = args.ref_filename.split('.')[-1]
    if ref_ext == 'json':
        ref_file = files.JSONStructInpFile(args.ref_filename)
    elif ref_ext == 'trj':
        ref_file = files.TxtTrajInpFile(args.ref_filename, system_file)

    ref_config = np.array(ref_file.chains(args.step))
    ref_positions = config_process.center_on_origin(ref_config)
    aligned_positions, rmsds = config_process.align_positions(
        traj_file, ref_config)

    np.savetxt(args.outfile, rmsds)
Пример #4
0
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    traj_file = files.TxtTrajInpFile(args.traj_filename, system_file)
    rgs = config_process.calc_radius_of_gyration(traj_file)

    np.savetxt(args.out_file, rgs)
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, system_file)
    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)
    tag_pairs = parse_tag_pairs(args.tag_pairs)
    for tag_pair in tag_pairs:
        mbarw.calc_2d_lfes(tag_pair[0], tag_pair[1], all_conditions,
                           out_filebase)

    mbarw.calc_all_expectations(out_filebase)
    mbarw.calc_1d_lfes(all_conditions, out_filebase, xtag='bias')

    # Hacky shit
    all_tags = decor_outs.all_series_tags
    for tag in all_tags:
        if 'staplestates' in tag:
            mbarw.calc_2d_lfes(tag, 'numfullyboundstaples', all_conditions,
                               out_filebase)

        if 'adj-d' in tag:
            mbarw.calc_2d_lfes(tag, 'dist-sum', all_conditions, out_filebase)
Пример #6
0
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, system_file)
    inp_filebase = create_input_filepathbase(args)
    sim_collections = outputs.create_sim_collections(inp_filebase,
                                                     all_conditions, args.reps)

    tag = 'numfullyboundstaples'
    for sim_collection in sim_collections:
        staple_states = sim_collection.get_reps_data('staplestates',
                                                     concatenate=False)
        for rep in sim_collection._reps:
            runs = len(staple_states[rep])
            for run in range(runs):
                back_ops_filebase = sim_collection.get_filebase(run, rep)
                back_ops = datatypes.OrderParams.from_file(back_ops_filebase)
                total_staples = staple_states[rep][run]._data[1:, :].sum(
                    axis=0)
                if tag in back_ops.tags:
                    back_ops[tag] = total_staples
                else:
                    back_ops.add_column(tag, total_staples)

                back_ops.to_file(back_ops_filebase)
Пример #7
0
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    traj_file = files.TxtTrajInpFile(args.traj_filename, system_file)
    dists = config_process.calc_end_to_end_dists(traj_file)

    np.savetxt(args.out_file, dists)
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, system_file)
    inp_filebase = create_input_filepathbase(args)
    sim_collections = outputs.create_sim_collections(inp_filebase,
                                                     all_conditions, args.reps)
    for sim_collection in sim_collections:
        ops_series_runs = sim_collection.get_reps_data('ops')
        filtered_steps = []
        for ops_series in ops_series_runs:
            if ops_series == 0:
                continue
            for step in range(ops_series.steps):
                filter_step = True
                for tag, value in zip(args.tags, args.values):
                    if ops_series[tag][step] != value:
                        filter_step = False
                        break

                    filtered_steps.append(step)

        if filtered_steps != []:
            print(sim_collection.conditions.fileformat)
            print(filtered_steps)
Пример #9
0
def main():
    args = parse_args()
    sys_inp_file = files.JSONStructInpFile(args.sys_filename)
    traj_file = files.TxtTrajInpFile(args.trj_filename, sys_inp_file)
    chains = traj_file.get_chains(args.step)
    sys_out_filename = '{}.json'.format(args.out_filebase)
    sys_out_file = files.JSONStructOutFile(sys_out_filename, sys_inp_file)
    sys_out_file.write(chains)
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)
def main():
    args = parse_cl()
    origami = files.JSONStructInpFile(args.system_file)
    binding_h = []
    binding_s = []
    misbinding_h = []
    misbinding_s = []
    for chain_i in origami.sequences:
        for seq_i in chain_i:
            seq_i_revcomp = nn.calc_complementary_sequence(seq_i)[::-1]
            for chain_j in origami.sequences:
                for seq_j in chain_j:
                    if seq_i_revcomp == seq_j:
                        h, s = nn.calc_hybridization_enthalpy_and_entropy(
                            seq_i, args.cation_M)
                        binding_h.append(nn.remove_energy_units(h))
                        binding_s.append(nn.remove_energy_units(s))
                    else:
                        seqs = nn.find_longest_contig_complement(seq_i, seq_j)
                        seqs_h = []
                        seqs_s = []
                        for seq in seqs:
                            h, s = nn.calc_hybridization_enthalpy_and_entropy(
                                seq, args.cation_M)
                            seqs_h.append(h)
                            seqs_s.append(s)

                        if len(seqs) == 0:
                            misbinding_h.append(0)
                            misbinding_s.append(0)
                        else:
                            misbinding_h.append(
                                nn.remove_energy_units(np.mean(seqs_h)))
                            misbinding_s.append(
                                nn.remove_energy_units(np.mean(seqs_s)))

    sbinding_h = []
    sbinding_s = []
    for staple in origami.sequences[1:]:
        seq = ''
        for s in staple:
            seq += s

        h, s = nn.calc_hybridization_enthalpy_and_entropy(seq, args.cation_M)
        sbinding_h.append(nn.remove_energy_units(h))
        sbinding_s.append(nn.remove_energy_units(s))

    print('Average bound domain hybridization enthalpy: ', np.mean(binding_h))
    print('Average bound domain hybridization entropy: ', np.mean(binding_s))
    print('Average misbound domain hybridization enthalpy: ',
          np.mean(misbinding_h))
    print('Average misbound domain hybridization entropy: ',
          np.mean(misbinding_s))
    print('Average staple hybridization enthalpy: ', np.mean(sbinding_h))
    print('Average staple domain hybridization entropy: ', np.mean(sbinding_s))
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    conditions_map = construct_conditions_map(args)
    fileformatter = construct_fileformatter()
    all_conditions = conditions.AllSimConditions(
        conditions_map, fileformatter, system_file)
    inp_filebase = create_input_filepathbase(args)
    enums = outputs.EnumCollection(inp_filebase, all_conditions)
    out_filebase = create_output_filepathbase(args)
    enums.calc_all_1d_means(out_filebase)
Пример #13
0
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, system_file)
    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.perform_decorrelation(args.skip)
    decor_outs.apply_masks()
    decor_outs.write_decors_to_files()
Пример #14
0
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    domain_pairs = parse_domain_pairs(args.domain_pairs)

    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, system_file)
    inp_filebase = create_input_filepathbase(args)
    sim_collections = outputs.create_sim_collections(inp_filebase,
                                                     all_conditions, args.reps)
    for sim_collection in sim_collections:
        for rep in sim_collection._reps:
            ops = sim_collection.get_reps_data('ops', concatenate=False)
            runs = len(ops[rep])
            for run in range(runs):
                run_filebase = sim_collection.get_filebase(run, rep)
                trj_filename = '{}.trj'.format(run_filebase)
                trj_file = files.TxtTrajInpFile(trj_filename, system_file)
                ops = datatypes.OrderParams.from_file(run_filebase)
                all_dists = [[] for i in range(len(domain_pairs))]
                for i, step in enumerate(trj_file):
                    config = np.array(step[0]['positions'])
                    for j, domain_pair in enumerate(domain_pairs):
                        pos_i = config[domain_pair[0]]
                        pos_j = config[domain_pair[1]]
                        all_dists[j].append(
                            config_process.calc_dist(pos_i, pos_j))

                for domain_pair, dists in zip(domain_pairs, all_dists):
                    dist_tag = 'dist-d{}-d{}'.format(domain_pair[0],
                                                     domain_pair[1])
                    if dist_tag in ops.tags:
                        ops[dist_tag] = dists
                    else:
                        ops.add_column(dist_tag, dists)
                    adj_tag = 'adj-d{}-d{}'.format(domain_pair[0],
                                                   domain_pair[1])
                    adj_sites = np.array(dists) == 1
                    if adj_tag in ops.tags:
                        ops[adj_tag] = adj_sites
                    else:
                        ops.add_column(adj_tag, adj_sites)

                dist_sum = np.sum(all_dists, axis=0)
                tag = 'dist-sum'
                if tag in ops.tags:
                    ops[tag] = dist_sum
                else:
                    ops.add_column(tag, dist_sum)

                ops.to_file(run_filebase)
Пример #15
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)
    sim_collections = create_simplesim_collections(args, inp_filebase,
                                                   all_conditions)

    tag = 'numfullyboundstaples'
    for sim_collection in sim_collections:
        staple_states = sim_collection.get_data('staplestates')
        back_ops = datatypes.OrderParams.from_file(sim_collection.filebase)
        total_staples = staple_states._data[1:, :].sum(axis=0)
        if tag in back_ops.tags:
            back_ops[tag] = total_staples
        else:
            back_ops.add_column(tag, total_staples)

        back_ops.to_file(sim_collection.filebase)
def main():
    args = parse_args()
    system_file = files.JSONStructInpFile(args.system_filename)
    fileformatter = construct_fileformatter()
    all_conditions = construct_conditions(args, fileformatter, system_file)
    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)
    mbarw.calc_all_expectations(out_filebase)
    for smult in args.stack_mults:
        reduced_conditions = construct_variable_temp_conditions(
            args, smult, fileformatter, system_file)
        reduced_out_filebase = '{}-{}'.format(out_filebase, smult)
        mbarw.calc_1d_lfes(reduced_conditions, reduced_out_filebase)
Пример #17
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)
    sim_collections = create_simplesim_collections(args, inp_filebase,
                                                   all_conditions)
    for sim_collection in sim_collections:
        states_filename = '{}.states'.format(sim_collection.filebase)
        states = np.loadtxt(states_filename)[:, :args.scaffold_domains]
        states = states == 2
        ops = datatypes.OrderParams.from_file(sim_collection.filebase)
        for i in range(args.scaffold_domains):
            tag = 'domainstate{}'.format(i)
            if tag in ops.tags:
                ops[tag] = states[:, i]
            else:
                ops.add_column(tag, states[:, i])

        ops.to_file(sim_collection.filebase)
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)
Пример #19
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)
Пример #20
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)])])