# =========================================================================== # =========================================================================== # 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") trajs_sub_atoms[cluster_centers_].save("cluster_centers_sub_atoms.pdb") #plot_cluster(labels=labels, phi_angles=phi_angles, psi_angles=psi_angles, name=clustering_name)
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", splited_assignments, fmt="%d") np.savetxt("cluster_centers_" + clustering_name + ".txt",
#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) #np.savetxt("assignments_"+clustering_name+".txt", labels, fmt="%d") np.savetxt("assignments_" + clustering_name + ".txt", labels, fmt="%d") #np.savetxt("cluster_centers_"+clustering_name+".txt", cluster_centers_, fmt="%d") plot_cluster(labels=labels,
# =========================================================================== # 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") trajs_sub_atoms[cluster_centers_].save("cluster_centers_sub_atoms.pdb")