Example #1
0
def run_analysis(args):
    feat = coor.featurizer(args.topfile)
    feat.add_distances(tmeth.generate_pairs(args.range[0],args.range[1], args.step_size, args.cut_value))
    traj = coor.load(args.traj_file, feat, stride=args.stride)
    tica_obj = coor.tica(traj, stride=1, lag=args.lag, dim=args.ticadim)
    outputs = tica_obj.get_output()[0]
    eigen = tica_obj.eigenvalues
    np.savetxt("%s_output_raw.dat"%args.title, outputs)
    np.savetxt("%s_eigenvalues_raw.dat"%args.title, eigen)
    tmeth.plot_eigen_series(eigen, args.title, time_scale=args.time_step*args.stride)
    tmeth.plot_output(outputs, args.title, time_scale=args.time_step*args.stride)
def run_sampling(args):
    topology = args.topfile
    ticadim = 10
    num_sample_frames = 10000
    tica_lag_time = 5
    fn = args.filedir  # file name
    wn = args.weights  # weights name

    weights = np.loadtxt(wn)
    weights = weights / np.sum(weights)
    # first time
    time1 = time.clock()
    feat = coor.featurizer(topology)
    feat.add_distances(tmeth.generate_pairs(5, 288, 4, 4))
    selected_frames = np.random.choice(args.number_traj, size=num_sample_frames, replace=True, p=weights)

    selected_files = []
    selected_frames.sort()
    for i in selected_frames:
        selected_files.append("%s/traj%d.xtc" % (fn, i))
    time2 = time.clock()
    print "Took %f minutes to select new frames" % ((time2 - time1) / 60.0)
    sampled_frames = coor.load(selected_files, feat, stride=10)

    time3 = time.clock()
    print "Took %f minutes to load the new frames" % ((time3 - time2) / 60.0)

    tica_obj = coor.tica(sampled_frames, stride=1, lag=tica_lag_time, dim=ticadim)
    time4 = time.clock()
    print "Took %f minutes to calculate the tica_object" % ((time4 - time3) / 60.0)
    all_outputs = tica_obj.get_output()[0]
    for i in xrange(num_sample_frames - 1):
        outputs = tica_obj.get_output()[i + 1]
        all_outputs = np.append(all_outputs, outputs, axis=0)
    eigen = tica_obj.eigenvalues
    print "saving files"
    np.savetxt("output.dat", all_outputs)
    np.savetxt("eigenvalues.dat", eigen)
    np.savetxt("selected_frames.dat", selected_frames)
    print "files saved"
    time5 = time.clock()
    print "Took %f minutes to write the output files" % ((time5 - time4) / 60.0)