def cluster(data_dir, traj_dir, n_clusters): reduced_data = verboseload(data_dir) trajs = np.concatenate(reduced_data) plt.hexbin(trajs[:, 0], trajs[:, 1], bins='log', mincnt=1) clusterer = MiniBatchKMedoids(n_clusters=n_clusters) clusterer.fit_transform(reduced_data) centers = clusterer.cluster_centers_ for i in range(0, np.shape(centers)[0]): center = centers[i, :] plt.scatter(center[0], center[1]) plt.annotate('C%d' % i, xy=(center[0], center[1]), xytext=(center[0] + 0.1, center[1] + 0.1), arrowprops=dict(facecolor='black', shrink=0.05)) location = clusterer.cluster_ids_[i, :] print(location) traj = get_trajectory_files(traj_dir)[location[0]] print(("traj = %s" % traj)) print(("frame = %d" % location[1])) conformation = md.load_frame(traj, location[1]) conformation.save_pdb( "/scratch/users/enf/b2ar_analysis/cluster_%d.pdb" % i) plt.show()
def cluster(data_dir, traj_dir, n_clusters, lag_time): clusterer_dir = "/scratch/users/enf/b2ar_analysis/clusterer_%d_t%d.h5" %(n_clusters, lag_time) if (os.path.exists(clusterer_dir)): print "Already clustered" else: reduced_data = verboseload(data_dir) trajs = np.concatenate(reduced_data) clusterer = MiniBatchKMedoids(n_clusters = n_clusters) clusterer.fit_transform(reduced_data) verbosedump(clusterer, "/scratch/users/enf/b2ar_analysis/clusterer_%d_t%d.h5" %(n_clusters, lag_time))
def cluster(data_dir, traj_dir, n_clusters, lag_time): clusterer_dir = "/scratch/users/enf/b2ar_analysis/clusterer_%d_t%d.h5" % ( n_clusters, lag_time) if (os.path.exists(clusterer_dir)): print("Already clustered") else: reduced_data = verboseload(data_dir) trajs = np.concatenate(reduced_data) clusterer = MiniBatchKMedoids(n_clusters=n_clusters) clusterer.fit_transform(reduced_data) verbosedump( clusterer, "/scratch/users/enf/b2ar_analysis/clusterer_%d_t%d.h5" % (n_clusters, lag_time))
def cluster(data_dir, traj_dir, n_clusters): reduced_data = verboseload(data_dir) trajs = np.concatenate(reduced_data) plt.hexbin(trajs[:,0], trajs[:,1], bins='log', mincnt=1) clusterer = MiniBatchKMedoids(n_clusters = n_clusters) clusterer.fit_transform(reduced_data) centers = clusterer.cluster_centers_ for i in range(0, np.shape(centers)[0]): center = centers[i,:] plt.scatter(center[0],center[1]) plt.annotate('C%d' %i, xy=(center[0],center[1]),xytext=(center[0]+0.1,center[1]+0.1), arrowprops=dict(facecolor='black',shrink=0.05)) location = clusterer.cluster_ids_[i,:] print location traj = get_trajectory_files(traj_dir)[location[0]] print("traj = %s" %traj) print("frame = %d" %location[1]) conformation = md.load_frame(traj, location[1]) conformation.save_pdb("/scratch/users/enf/b2ar_analysis/cluster_%d.pdb" %i) plt.show()