## \example em2d/clustering_of_pdb_models.py ## This example clusters pdb models of an structure, chosen from a ## selection file. ## ## It is assumed that all the pdb files belong to the same structure ## and that the order of the atoms in the pdb files is the same in all files. ## ## After the clustering procedure, a linkage matrix is generated. ## import IMP import IMP.core as core import IMP.atom as atom import IMP.em2d as em2d import os import sys import csv """ Clustering of pdb models. This script clusters pdb models of an structure, chosen from a selection file. - It is assumed that all the pdb files belong to the same structure and that the order of the atoms in the pdb files is the same in all files - After the clustering procedure, a linkage matrix is generated. """ if sys.platform == 'win32': sys.stderr.write("this example does not currently work on Windows\n") sys.exit(0) def get_columns(fn,cols=[],delimiter=" ",comment="#"): """ ge the columns of a file: cols - a list of columns to extract. E.g [0,3,5] If empty, all the columns are extracted lines starting with the comment character are ignored """ columns=[[] for i in cols] # get a reader for the file reader=csv.reader(open(fn,"r"),delimiter=delimiter,skipinitialspace=True) for row in reader: if(row!=[] and row[0][0]!=comment): # not empty or comment row if(cols==[]): for i in range(0,len(row)): columns[i].append(row[i]) else: for i in range(0,len(cols)): columns[i].append(row[cols[i]]) return columns def argmin(sequence): """ Argmin function: Returns the pair (min_value,min_index), where min_index is the index of the minimum value """ min_value = sequence[0] min_index = 0 for i in range(0,len(sequence)): # print "argmin - checking ",sequence[i] if(sequence[i]