Exemple #1
0
    def test_tempy_sccc(self):
        ''' Test the tempy sccc score based on the files
    provided. Use this as a baseline for the second
    chimeraX test. '''

        # the sigma factor determines the width of the Gaussian distribution used to describe each atom
        sim_sigma_coeff = 0.187

        path_test = "./"
        m = os.path.join(path_test, '1akeA_10A.mrc')
        p = os.path.join(path_test, '1ake_mdl1.pdb')
        r = 10.0
        rb_file = os.path.join(path_test, '1ake_mdl1_rigid.txt')

        scorer = ScoringFunctions()

        # read map file
        emmap = MapParser.readMRC(m)

        # read PDB file
        structure_instance = PDBParser.read_PDB_file('pdbfile',
                                                     p,
                                                     hetatm=False,
                                                     water=False)
        SCCC_list_structure_instance = []

        # read rigid body file and generate structure instances for each segment
        listRB = RBParser.read_FlexEM_RIBFIND_files(rb_file,
                                                    structure_instance)

        # score each rigid body segment
        listsc_sccc = []

        for RB in listRB:
            # sccc score
            score_SCCC = scorer.SCCC(emmap, r, sim_sigma_coeff,
                                     structure_instance, RB)
            listsc_sccc.append(score_SCCC)

        self.assertTrue(len(listRB) == 6)
        self.assertTrue(abs(round(listsc_sccc[0], 4) - 0.954) < 0.01)
        self.assertTrue(abs(round(listsc_sccc[1], 4) - 0.427) < 0.01)
        self.assertTrue(abs(round(listsc_sccc[2], 4) - 0.624) < 0.01)
        self.assertTrue(abs(round(listsc_sccc[3], 4) - 0.838) < 0.01)
        self.assertTrue(abs(round(listsc_sccc[4], 4) - 0.971) < 0.01)
        self.assertTrue(abs(round(listsc_sccc[5], 4) - 0.928) < 0.01)
Exemple #2
0
def score(session, atomic_model, map_model, rez):
    ''' Perform the CCC score. Takes a session, a single model and map.'''

    print("Calculating CCC Score")

    # make class instances for density simulation (blurring), scoring and plot scores
    blurrer = StructureBlurrer()
    scorer = ScoringFunctions()

    atomlist = []
    for atom in atomic_model.atoms:
        atomlist.append(chimera_to_tempy_atom(atom, len(atomlist)))

    bio_atom_structure = BioPy_Structure(atomlist)
    bio_map_structure = chimera_to_tempy_map(map_model)
    map_probe = blurrer.gaussian_blur(bio_atom_structure,
                                      rez,
                                      densMap=bio_map_structure)
    score = scorer.CCC(bio_map_structure, map_probe)
    print(score)
    return score
Exemple #3
0
    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)
Exemple #4
0
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
Exemple #5
0
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