Example #1
0
def calculate_distances():
    print("Calculating distances...")
    traj_files = sorted(glob.glob("traj*xtc"))
    traj = [ md.load(filename, top='structure.gro') for filename in traj_files ]
    indices = [ a.index for a in traj[0].topology.atoms if a.element.symbol != 'NA' and a.element.symbol != 'CL' ]
#        indices = traj[i].topology.select('name==CA')   
    pairs = list(combinations(indices, 2))
    features = AtomPairsFeaturizer(pairs)
    transformed_data = features.fit_transform(traj)
    for i in range(len(transformed_data)):
        np.save('out_' + str(i) + '.npy', transformed_data[i])
    'pairlist.txt', dtype=int
)  #indexes for the atom pairs you are interestd(index starts from 0): atom1 atom2
xtc_file_dir = 'trajectories/'  #folder to put xtc

featurizer = AtomPairsFeaturizer(pair_indices=atom_pairs)

traj_list_array = []
for line in open("trajlist"):
    traj_list_array.append(line.strip())
print traj_list_array  #trajectory name

####################calculate the pairwise distances for tica
ticadist = []
for trajfile in traj_list_array:
    xyz = dataset(xtc_file_dir + trajfile, topology='test.pdb')
    temp = featurizer.fit_transform(xyz)
    ticadist.append(
        temp[0]
    )  #now we have the pairwise distance between the atoms of interest

###apart from the pairwise distances, other features you can try are "dihedral angle", "raw coordinates", "reciporacal distances", "contact map" and so on

###scan the tica parameters
'''   
lag_time_list=range(1,20,1)
for lag_time in lag_time_list:
    tica_model=tICA(lag_time=lag_time,n_components=10)
    tica_trajs=tica_model.fit(ticadist)  #projected tica coordinate
    print lag_time, tica_trajs.timescales_[0],tica_trajs.timescales_[1],tica_trajs.timescales_[2],tica_trajs.timescales_[3],tica_trajs.timescales_[4],tica_trajs.timescales_[5],tica_trajs.timescales_[6],tica_trajs.timescales_[7],tica_trajs.timescales_[8],tica_trajs.timescales_[9]
    np.savetxt('tic_eigenvector_lagtime_%d.txt'%(lag_time), tica_trajs.eigenvectors_)
    tica_trajs = tica_model.fit_transform(ticadist)