print "align_atom_indices:", align_atom_indices trajs.superpose(reference=trajs[0], frame=0, atom_indices=align_atom_indices) print "Alignment done." # =========================================================================== # =========================================================================== # Just keep the atoms in atom indices, remove other atoms atom_indices = np.loadtxt('atom_indices', dtype=np.int32).tolist() print "atom_indices:", atom_indices trajs_sub_atoms = trajs.atom_slice(atom_indices, inplace=False) #just keep the the atoms in atom indices print "Trajs:", trajs print "Sub_atoms_trajs:", trajs_sub_atoms # =========================================================================== # do Clustering using KCenters method #cluster = KCenters(n_clusters=n_clusters, metric="euclidean", random_state=0) cluster = KCenters(n_clusters=n_clusters, metric="rmsd", random_state=0) print cluster #cluster.fit(phi_psi) cluster.fit(trajs_sub_atoms) labels = cluster.labels_ print labels n_microstates = len(set(labels)) - (1 if -1 in labels else 0) print('Estimated number of clusters: %d' % n_microstates) cluster_centers_ = cluster.cluster_centers_ # plot micro states clustering_name = "kcenters_n_" + str(n_microstates) np.savetxt("assignments_"+clustering_name+".txt", labels, fmt="%d") np.savetxt("cluster_centers_"+clustering_name+".txt", cluster_centers_, fmt="%d") trajs[cluster_centers_].save("cluster_centers.pdb")
phi_psi = np.column_stack((phi_angles, psi_angles)) else: phi_angles, psi_angles = trajreader.get_phipsi(trajs, psi=[6, 8, 14, 16], phi=[4, 6, 8, 14]) #phi_angles, psi_angles = trajreader.get_phipsi(trajs, psi=[5, 7, 13, 15], phi=[3, 5, 7, 13]) #phi_psi = np.column_stack((phi_angles, psi_angles)) np.savetxt("./phi_angles.txt", phi_angles, fmt="%f") np.savetxt("./psi_angles.txt", psi_angles, fmt="%f") #phi_angles, psi_angles = trajreader.get_phipsi(trajs, psi=[6, 8, 14, 16], phi=[4, 6, 8, 14]) #phi_psi=np.column_stack((phi_angles, psi_angles)) # =========================================================================== # do Clustering using KCenters method #cluster = KCenters(n_clusters=n_clusters, metric="euclidean", random_state=0) cluster = KCenters(n_clusters=n_clusters, metric="rmsd", random_state=0) print(cluster) #cluster.fit(phi_psi) cluster.fit(trajs) labels = cluster.labels_ print(labels) n_microstates = len(set(labels)) - (1 if -1 in labels else 0) print('Estimated number of clusters: %d' % n_microstates) cluster_centers_ = cluster.cluster_centers_ # plot micro states clustering_name = "kcenters_n_" + str(n_microstates) splited_assignments = split_assignments(labels, traj_len) #np.savetxt("assignments_"+clustering_name+".txt", labels, fmt="%d") np.savetxt("assignments_" + clustering_name + ".txt",
# psi_angles = np.loadtxt("./psi_angles.txt", dtype=np.float32) #X=np.column_stack((phi_angles, psi_angles)) #print(X.shape) #n_size = X.shape[0] #dimension = X.shape[1] ''' # =========================================================================== n_clusters = 10 print( '---------------------------------------------------------------------------------' ) from msmbuilder.cluster import KCenters cluster = KCenters(n_clusters=n_clusters, metric="euclidean", random_state=0) print(cluster) #cluster.fit(phi_psi) cluster.fit(X) labels = cluster.labels_ print(labels) labels = np.concatenate(labels) n_microstates = len(set(labels)) - (1 if -1 in labels else 0) print('Estimated number of clusters: %d' % n_microstates) #cluster_centers_ = cluster.cluster_centers_ # plot micro states clustering_name = "kcenters_n_" + str(n_microstates) #splited_assignments =split_assignments(labels, traj_len)
# =========================================================================== # Just keep the atoms in atom indices, remove other atoms atom_indices = np.loadtxt('atom_indices', dtype=np.int32).tolist() print "atom_indices:", atom_indices trajs_sub_atoms = trajs.atom_slice(atom_indices, inplace=False) #just keep the the atoms in atom indices print "Trajs:", trajs print "Sub_atoms_trajs:", trajs_sub_atoms # =========================================================================== # Reading Clustering Centers centers = md.load("cluster_centers_sub_atoms.pdb") print "Centers:", centers # =========================================================================== # do Assigning using KCenters method #cluster = KCenters(n_clusters=n_clusters, metric="euclidean", random_state=0) cluster = KCenters(centers=centers, n_clusters=n_clusters, metric="rmsd", random_state=0) print cluster #cluster.fit(phi_psi) #cluster.fit(trajs_sub_atoms) cluster.assign(trajs_sub_atoms, cluster) labels = cluster.labels_ print labels n_microstates = len(set(labels)) - (1 if -1 in labels else 0) print('Estimated number of clusters: %d' % n_microstates) # plot micro states clustering_name = "kcenters_assign_n_" + str(n_microstates) np.savetxt("assignments_"+clustering_name+".txt", labels, fmt="%d")