def rank_fit_ensemble(self,ensemble_list,score,res_target_map,sigma_coeff,number_top_mod=0,\ write=False,targetMap=False,cont_targetMap=None): """ RMSD clustering of the multiple "fits" accordingly with a chosen score. Cluster the fits based on Calpha RMSD (starting from the best scoring model) Arguments: *ensemble_list* Input list of Structure Instances. *targetMap* Target Map Instance. *score* Scoring function to use. See ScoringFunctions class for a list of the available Scoring Function. E.g. set score='CCC' to use the Cross-correlation coefficient. Score option are: i 'CCC' - Cross-correlation coefficient; ii 'LAP' - Laplacian-filtered cross-correlation coefficient: useful for maps with resolutions worse than 10-15 A; iii 'MI' - Mutual information score: a good and robust score but relatively slow to calculate; iv 'ENV' - Envelope score: the fastest score to calculate due to binarisation of the map. v-vii 'NV','NV_Sobel','NV_Laplace'- Normal vector score: a vector-based surface superimposition score with or without Sobel/Laplace filter. viii 'CD' - Chamfer Distance: a score used in computer vision algorithms as a fast similarity metric *rms_cutoff* float, the Calpha RMSD cutoff based on which you want to cluster the solutions. For example 3.5 (for 3.5 A). *res_target_map* the resolution, in Angstroms, of the target Map. *sigma_coeff* the sigma value (multiplied by the resolution) that controls the width of the Gaussian. Default values is 0.356. Other values used : 0.187R corresponding with the Gaussian width of the Fourier transform falling to half the maximum at 1/resolution, as used in Situs (Wriggers et al, 1999); 0.225R which makes the Fourier transform of the distribution fall to 1/e of its maximum value at wavenumber 1/resolution, the default in Chimera (Petterson et al, 2004) 0.356R corresponding to the Gaussian width at 1/e maximum height equaling the resolution, an option in Chimera (Petterson et al, 2004); 0.425R the fullwidth half maximum being equal to the resolution, as used by FlexEM (Topf et al, 2008); 0.5R the distance between the two inflection points being the same length as the resolution, an option in Chimera (Petterson et al, 2004); 1R where the sigma value simply equal to the resolution, as used by NMFF (Tama et al, 2004). *number_top_mod* Number of Fits to cluster. Default is all. *write* True will write out a file that contains the list of the structure instances representing different fits scored and clustered. note the lrms column is the Calpha RMSD of each fit from the first fit in its class """ blurrer = StructureBlurrer() scorer = ScoringFunctions() cluster = Cluster() count = 0 dict_ensembl = {} list_to_order = [] #print targetMap if targetMap == False: #targetMap = self.protMap(prot, min(resolution/4., 3.5), resolution) print("WARNING:Need target map") sys.exit() if score not in [ 'CCC', 'LAP', 'MI', 'NV', 'NV_Sobel', 'NV_Laplace', 'ENV', 'CD' ]: print('Incorrect Scoring Function: %s', score) print( 'Please select from one of the following scoring functions: %s', ''.join([ 'CCC', 'LAP', 'MI', 'NV', 'NV_Sobel', 'NV_Laplace', 'ENV', 'CD' ])) sys.exit() targetMap = targetMap.copy() if score == 'CCC': for mod1 in ensemble_list: count += 1 name_mod = mod1[0] mod = mod1[1] sim_map = blurrer.gaussian_blur(mod, res_target_map, densMap=targetMap, sigma_coeff=sigma_coeff) if not cont_targetMap is None: score_mod = scorer.CCC_map( sim_map, targetMap, 0.5 * sim_map.fullMap.std(), cont_targetMap, 2, True)[0] #CCC(sim_map,targetMap) else: score_mod = scorer.CCC_map(sim_map, targetMap, 0.0, 0.0, True)[0] #else: score_mod=scorer.CCC(sim_map,targetMap) #'name_file','structure_instance','score','lrmsd','class' list_to_order.append([name_mod, mod, score_mod, 0, 0]) if score == 'LAP': for mod1 in ensemble_list: count += 1 name_mod = mod1[0] mod = mod1[1] sim_map = blurrer.gaussian_blur(mod, res_target_map, densMap=targetMap, sigma_coeff=sigma_coeff) score_mod = scorer.laplace_CCC(sim_map, targetMap) #'name_file','structure_instance','score','lrmsd','class' list_to_order.append([name_mod, mod, score_mod, 0, 0]) if score == 'MI': for mod1 in ensemble_list: count += 1 name_mod = mod1[0] mod = mod1[1] sim_map = blurrer.gaussian_blur(mod, res_target_map, densMap=targetMap, sigma_coeff=sigma_coeff) if not cont_targetMap is None: score_mod = scorer.MI(sim_map, targetMap, 0.5 * sim_map.fullMap.std(), cont_targetMap, 1) else: score_mod = scorer.MI(sim_map, targetMap) list_to_order.append([name_mod, mod, score_mod, 0, 0]) if score == 'NV': for mod1 in ensemble_list: count += 1 name_mod = mod1[0] mod = mod1[1] #These two values should be calculated for the experimental map, and only #need to be calculated once, at the beginning sim_map = blurrer.gaussian_blur(mod, res_target_map, densMap=targetMap, sigma_coeff=sigma_coeff) if not cont_targetMap is None: score_mod = scorer.normal_vector_score( targetMap, sim_map, cont_targetMap - (0.1 * targetMap.std()), cont_targetMap + (0.1 * targetMap.std()), Filter=None) else: min_thr = targetMap.get_primary_boundary( mod.get_prot_mass_from_atoms(), targetMap.min(), targetMap.max()) points = targetMap.get_point_map(min_thr, percentage=0.2) max_thr = targetMap.get_second_boundary(min_thr, points, min_thr, targetMap.max(), err_percent=1) score_mod = scorer.normal_vector_score(targetMap, sim_map, min_thr, max_thr, Filter=None) score_mod = 1 - (score_mod / 3.14) list_to_order.append([name_mod, mod, score_mod, 0, 0]) if score == 'NV_Sobel': for mod1 in ensemble_list: count += 1 name_mod = mod1[0] mod = mod1[1] sim_map = blurrer.gaussian_blur(mod, res_target_map, densMap=targetMap, sigma_coeff=sigma_coeff) if not cont_targetMap is None: score_mod = scorer.normal_vector_score( targetMap, sim_map, cont_targetMap - (0.1 * targetMap.std()), cont_targetMap + (0.1 * targetMap.std()), Filter='Sobel') else: min_thr = targetMap.get_primary_boundary( mod.get_prot_mass_from_atoms(), targetMap.min(), targetMap.max()) points = targetMap.get_point_map(min_thr, percentage=0.2) max_thr = targetMap.get_second_boundary(min_thr, points, min_thr, targetMap.max(), err_percent=1) score_mod = scorer.normal_vector_score(targetMap, sim_map, min_thr, max_thr, Filter='Sobel') score_mod = 1 - (score_mod / 3.14) list_to_order.append([name_mod, mod, score_mod, 0, 0]) if score == 'NV_Laplace': for mod1 in ensemble_list: count += 1 name_mod = mod1[0] mod = mod1[1] sim_map = blurrer.gaussian_blur(mod, res_target_map, densMap=targetMap, sigma_coeff=sigma_coeff) if not cont_targetMap is None: score_mod = scorer.normal_vector_score( targetMap, sim_map, cont_targetMap - (0.1 * targetMap.std()), cont_targetMap + (0.1 * targetMap.std()), Filter='Laplace') else: min_thr = targetMap.get_primary_boundary( mod.get_prot_mass_from_atoms(), targetMap.min(), targetMap.max()) points = targetMap.get_point_map(min_thr, percentage=0.2) max_thr = targetMap.get_second_boundary(min_thr, points, min_thr, targetMap.max(), err_percent=1) score_mod = scorer.normal_vector_score(targetMap, sim_map, min_thr, max_thr, Filter='Laplace') score_mod = 1 - (score_mod / 3.14) list_to_order.append([name_mod, mod, score_mod, 0, 0]) if score == 'ENV': for mod1 in ensemble_list: count += 1 name_mod = mod1[0] mod = mod1[1] min_thr = targetMap.get_primary_boundary( mod.get_prot_mass_from_atoms(), targetMap.min(), targetMap.max()) score_mod = scorer.envelope_score(targetMap, min_thr, mod) #'name_file','structure_instance','score','lrmsd','class' list_to_order.append([name_mod, mod, score_mod, 0, 0]) if score == 'CD': for mod1 in ensemble_list: count += 1 name_mod = mod1[0] mod = mod1[1] sim_map = blurrer.gaussian_blur(mod, res_target_map, densMap=targetMap, sigma_coeff=sigma_coeff) if not cont_targetMap is None: score_mod = scorer._surface_distance_score( sim_map, targetMap, 0.5 * sim_map.fullMap.std(), cont_targetMap, 'Minimum') else: min_thr = targetMap.get_primary_boundary( mod.get_prot_mass_from_atoms(), targetMap.min(), targetMap.max()) points = targetMap.get_point_map(min_thr, percentage=0.2) max_thr = targetMap.get_second_boundary(min_thr, points, min_thr, targetMap.max(), err_percent=1) score_mod = scorer.chamfer_distance(sim_map, targetMap, min_thr, max_thr, kdtree=None) score_mod = 1 / score_mod list_to_order.append([name_mod, mod, score_mod, 0, 0]) if score in ['NV', 'NV_Sobel', 'NV_Laplace']: list_ordered = sorted( list_to_order, key=lambda x: x[2], reverse=True) #was false when NV was negative else: list_ordered = sorted(list_to_order, key=lambda x: x[2], reverse=True) if number_top_mod == 0: if write == True: return cluster._print_results_cluster2(list_ordered, write) return list_ordered else: x = int(number_top_mod) if write == True: return cluster._print_results_cluster2(list_ordered[:x], write) return list_ordered[:x]
print_exc() mi_mask = 0.0 scores['mutual_information'] = mi_mask #NMI try: nmi = sc.MI(emmap1, emmap2, c1, c2, 1, None, None, True) print 'Normalized Mutual information score:', nmi if nmi < 0.0: nmi = 0.0 except: print 'Exception for NMI score' print_exc() nmi = 0.0 #CD try: chm = sc._surface_distance_score(emmap1, emmap2, c1, c2, 'Minimum') if chm == 0.0 or chm is None: chm = sc._surface_distance_score(emmap1, emmap2, c1, c2, 'Mean') print 'Surface distance score: ', chm if chm < 0.0: chm = 0.0 except: print 'Exception for surface distance score' print_exc() chm = 0.0 scores['surface_distance'] = chm try: nv = sc.normal_vector_score(emmap1, emmap2, float(c1), float(c1) + (emmap1.std() * 0.05), 'Minimum') if nv == 0.0 or nv is None: