'Input two maps, their resolutions(required) and contours(optional)' ) print 'reading map1' if c1 is None: Name1, emmap1, c1 = map_contour(m1, t=1.5) else: Name1 = os.path.basename(m1).split('.')[0] emmap1 = MapParser.readMRC(m1) print 'reading map2' if c2 is None: Name2, emmap2, c2 = map_contour(m2, t=1.5) else: Name2 = os.path.basename(m2).split('.')[0] emmap2 = MapParser.readMRC(m2) if not sc.mapComparison(emmap1, emmap2): if None in [r1, r2]: sys.exit( 'Input two maps, their resolutions(required) and contours(optional)' ) emmap1._crop_box(c1, 0.5) emmap2._crop_box(c2, 0.5) if r1 > 1.25 * r2: emmap_2 = lpfilter(emmap2, r1) emmap1, emmap2 = match_grid(emmap1, emmap_2, c1, c2) elif r2 > 1.25 * r1: emmap_1 = lpfilter(emmap1, r2) emmap1, emmap2 = match_grid(emmap_1, emmap2, c1, c2) else: emmap1, emmap2 = match_grid(emmap1, emmap2, c1, c2)
def score_cmd(session, comparators, compared, rez_comparators, rez_compared, contours_comparators, contour_compared): sc = ScoringFunctions() blurrer = StructureBlurrer() # Loop through these to be compared idx = 0 scores = [] for comparator in comparators: emmap1 = None emmap2 = None if type(comparator) is AtomicStructure: if type(compared) is AtomicStructure: # Both models if None in ([rez_compared] + rez_comparators): print("Please provide the resolution for all models") return bms1 = chimera_to_tempy_model(compared) bms2 = chimera_to_tempy_model(comparator) emmap1 = model_contour( bms1, rez_compared, emmap=False,t=0.5) if contours_comparators[idx] is None: emmap2 = model_contour(bms2, rez_comparators[idx],emmap=False,t=0.5) else: emmap2 = blur_model(bms2, rez_comparators[idx], emmap=False) else: # 0 - map, 1 - model if rez_comparators[idx] == None: print("Please provide the resolution for the model.") return emmap1 = chimera_to_tempy_map(compared) bms = chimera_to_tempy_model(comparator) emmap2 = blurrer.gaussian_blur(bms, rez_compared, densMap=emmap1) else: if type(compared) is AtomicStructure: # 0 - model, 1 - map if rez_compared == None: print("Please provide the resolution for the model.") return emmap2 = chimera_to_tempy_map(comparator) bms = chimera_to_tempy_model(compared) emmap1 = blurrer.gaussian_blur(bms, rez_compared, densMap=emmap2) else: # 0 - map, 1 - map emmap1 = chimera_to_tempy_map(compared) emmap2 = chimera_to_tempy_map(comparator) c1 = contour_compared # Contouring if c1 == None: c1 = map_contour(emmap1,t=1.5) c2 = contours_comparators[idx] # This kinda makes no sense and could be tricky if c2 == None: c2 = map_contour(emmap2,t=1.5) # Some kind of fix if the maps don't match? # Resize, resample or blur of somekind if not sc.mapComparison(emmap1,emmap2): emmap1._crop_box(c1,0.5) emmap2._crop_box(c2,0.5) if rez_compared > 1.25*rez_comparators[idx]: emmap_2 = lpfilter(emmap2,rez_compared) emmap1, emmap2 = match_grid(emmap1,emmap_2,c1,c2) elif rez_comparators[idx] > 1.25*rez_compared: emmap_1 = lpfilter(emmap1,rez_comparators[idx]) emmap1, emmap2 = match_grid(emmap_1,emmap2,c1,c2) else: emmap1, emmap2 = match_grid(emmap1,emmap2,c1,c2) nmi = 0.0 try: nmi = sc.MI(emmap1,emmap2,c1,c2,1,None,None,True) if nmi < 0.0: nmi = 0.0 except: print('Exception for NMI score') print_exc() nmi = 0.0 scores.append(nmi) idx+=1 return scores
def test_tempy_nmi(self): ''' Test the tempy nmi score based on the files provided. Use this as a baseline for the second chimeraX test. ''' path_test = "./" m = os.path.join(path_test, 'emd_5168.map') p = os.path.join(path_test, 'emd_5170.map') sc = ScoringFunctions() rez1 = 6.6 rez2 = 15.0 Name1, emmap1, c1 = map_contour(m, t=1.5) Name2, emmap2, c2 = map_contour(p, t=1.5) print(rez1, rez2, c1, c2, emmap1.apix, emmap2.apix) if not sc.mapComparison(emmap1, emmap2): emmap1._crop_box(c1, 0.5) emmap2._crop_box(c2, 0.5) if rez1 > 1.25 * rez2: emmap_2 = lpfilter(emmap2, rez1) emmap1, emmap2 = match_grid(emmap1, emmap_2, c1, c2) elif rez2 > 1.25 * rez1: emmap_1 = lpfilter(emmap1, rez2) emmap1, emmap2 = match_grid(emmap_1, emmap2, c1, c2) else: emmap1, emmap2 = match_grid(emmap1, emmap2, c1, c2) nmi = 0 try: nmi = sc.MI(emmap1, emmap2, c1, c2, 1, None, None, True) if nmi < 0.0: nmi = 0.0 except: self.assertTrue(False) print_exc() nmi = 0.0 self.assertTrue(abs(round(nmi, 5) - 1.0492) < 0.001) # Now test with a model and map p = os.path.join(path_test, '1J6Z.pdb') m = os.path.join(path_test, 'emd_5168_monomer.mrc') res = 6.6 Name1 = os.path.basename(m).split('.')[0] Name2 = os.path.basename(p).split('.')[0] emmap1 = MapParser.readMRC(m) structure_instance = PDBParser.read_PDB_file(Name2, p, hetatm=False, water=False) blurrer = StructureBlurrer() emmap2 = blurrer.gaussian_blur(structure_instance, res, densMap=emmap1) c1 = 9.7 c2 = 1.0 nmi = 0 try: nmi = sc.MI(emmap1, emmap2, c1, c2, 1, None, None, True) if nmi < 0.0: nmi = 0.0 except: self.assertTrue(False) print_exc() nmi = 0.0 self.assertTrue(abs(round(nmi, 5) - 1.0575) < 0.001)
def score(session, atomic_model1 = None, map_model1 = None, atomic_model2 = None, map_model2 = None, rez1 = None, rez2 = None, c1 = None, c2 = None): """ Generate the NMI score for 2 maps or 1 map and 1 model. """ sc = ScoringFunctions() # We have choices - 1 map and one model, 2 maps or 2 models emmap1 = None emmap2 = None blurrer = StructureBlurrer() if atomic_model1 != None and map_model1 != None: # 1 map 1 model if rez1 == None: print("Please provide the resolution for the model.") return emmap1 = chimera_to_tempy_map(map_model1) bms = chimera_to_tempy_model(atomic_model1) emmap2 = blurrer.gaussian_blur(bms, rez1, densMap=emmap1) elif map_model1 != None and map_model2 != None: # 2 maps emmap1 = chimera_to_tempy_map(map_model1) emmap2 = chimera_to_tempy_map(map_model2) elif atomic_model1 != None and atomic_model2 != None: # 2 models if None in [rez1,rez2]: print("Please provide the resolution for both model") return bms1 = chimera_to_tempy_model(atomic_model1) bms2 = chimera_to_tempy_model(atomic_model2) emmap1 = model_contour( bms1, rez1, emmap=False,t=0.5) if c2 is None: emmap2 = model_contour(bms2, rez2,emmap=False,t=0.5) else: emmap2 = blur_model( bms2, rez2, emmap=False) else: print("Error. Must have 1 model and 1 map, 2 maps or 2 models") return # Contouring if c1 == None: c1 = map_contour(emmap1,t=1.5) if c2 == None: c2 = map_contour(emmap2,t=1.5) # Some kind of fix if the maps don't match? # Resize, resample or blur of somekind if not sc.mapComparison(emmap1,emmap2): emmap1._crop_box(c1,0.5) emmap2._crop_box(c2,0.5) if rez1 > 1.25*rez2: emmap_2 = lpfilter(emmap2,rez1) emmap1, emmap2 = match_grid(emmap1,emmap_2,c1,c2) elif rez2 > 1.25*rez1: emmap_1 = lpfilter(emmap1,rez2) emmap1, emmap2 = match_grid(emmap_1,emmap2,c1,c2) else: emmap1, emmap2 = match_grid(emmap1,emmap2,c1,c2) nmi = 0.0 try: nmi = sc.MI(emmap1,emmap2,c1,c2,1,None,None,True) if nmi < 0.0: nmi = 0.0 except: print('Exception for NMI score') print_exc() nmi = 0.0 return nmi