Пример #1
0
 def set_rota_result(self):
     from mmtbx.rotamer.sidechain_angles import SidechainAngles
     sidechain_angles = SidechainAngles(show_errs=True)
     if self.resname == "MSE": curres = "MET"
     else: curres = self.resname
     all_dict = construct_complete_sidechain(self.three[self.index],
                                             self.altloc)
     #print all_dict
     kwargs = self.get_start_kwargs()
     try:
         chis = sidechain_angles.measureChiAngles(self.three[self.index],
                                                  all_dict.get(self.altloc))
     except AttributeError:
         kwargs['incomplete'] = True
         result = rotamer(**kwargs)
         print('%s is missing some sidechain atoms' % result.id_str(),
               file=sys.stderr)
         self.rota_result = rotalyze.rotamer(**kwargs)
         return
     #print all_dict.get(self.altloc).keys()
     if None in chis:
         result = rotamer(**kwargs)
         print('%s may be missing some sidechain atoms' %\
                                  result.id_str(), file=sys.stderr)
         self.rota_result = rotalyze.rotamer(**kwargs)
         return
     cur_res = self.resname.lower().strip()
     if cur_res == 'mse':
         cur_res = 'met'
     value = self.rota_eval.evaluate(cur_res, chis)
     if value == None:
         self.rota_result = rotalyze.rotamer(**kwargs)
         return
     kwargs['score'] = value * 100
     wrap_chis = self.rotamer_id.wrap_chis(self.resname.strip(),
                                           chis,
                                           symmetry=False)
     if value >= rotalyze.ALLOWED_THRESHOLD: evaluation = "Favored"
     elif value >= rotalyze.OUTLIER_THRESHOLD: evaluation = "Allowed"
     else:
         evaluation = "OUTLIER"
         kwargs['outlier'] = True
         kwargs['rotamer_name'] = evaluation
     kwargs['evaluation'] = evaluation
     if evaluation != "OUTLIER":
         kwargs['outlier'] = False
         kwargs['rotamer_name'] = self.rotamer_id.identify(
             self.resname, wrap_chis)
         # deal with unclassified rotamers
         if kwargs['rotamer_name'] == '':
             kwargs['rotamer_name'] = "UNCLASSIFIED"
     # fill out wrap_chis win None til len == 4
     while (len(wrap_chis) < 4):
         wrap_chis.append(None)
     kwargs['chi_angles'] = wrap_chis
     self.rota_result = rotalyze.rotamer(**kwargs)
 def set_rota_result(self) :
   from mmtbx.rotamer.sidechain_angles import SidechainAngles
   sidechain_angles = SidechainAngles(show_errs=True)
   if self.resname == "MSE" : curres = "MET"
   else : curres = self.resname
   all_dict = construct_complete_sidechain(self.three[self.index],self.altloc)
   #print all_dict
   kwargs = self.get_start_kwargs()
   try :
     chis = sidechain_angles.measureChiAngles(
                        self.three[self.index],
                        all_dict.get(self.altloc))
   except AttributeError :
     kwargs['incomplete'] = True
     result = rotamer(**kwargs)
     print >> sys.stderr, '%s is missing some sidechain atoms'%result.id_str()
     self.rota_result = rotalyze.rotamer(**kwargs)
     return
   #print all_dict.get(self.altloc).keys()
   if None in chis :
     result = rotamer(**kwargs)
     print >> sys.stderr, '%s may be missing some sidechain atoms' %\
                              result.id_str()
     self.rota_result = rotalyze.rotamer(**kwargs)
     return
   cur_res = self.resname.lower().strip()
   if cur_res == 'mse':
     cur_res = 'met'
   value = self.rota_eval.evaluate(cur_res, chis)
   if value == None :
     self.rota_result = rotalyze.rotamer(**kwargs)
     return
   kwargs['score'] = value * 100
   wrap_chis = self.rotamer_id.wrap_chis(self.resname.strip(),
                         chis,symmetry=False)
   if value >= rotalyze.ALLOWED_THRESHOLD   : evaluation = "Favored"
   elif value >= rotalyze.OUTLIER_THRESHOLD : evaluation = "Allowed"
   else                                     :
     evaluation = "OUTLIER"
     kwargs['outlier'] = True
     kwargs['rotamer_name'] = evaluation
   kwargs['evaluation'] = evaluation
   if evaluation != "OUTLIER" :
     kwargs['outlier'] = False
     kwargs['rotamer_name'] = self.rotamer_id.identify(self.resname, wrap_chis)
     # deal with unclassified rotamers
     if kwargs['rotamer_name'] == '' : kwargs['rotamer_name'] = "UNCLASSIFIED"
   # fill out wrap_chis win None til len == 4
   while (len(wrap_chis) < 4) : wrap_chis.append(None)
   kwargs['chi_angles'] = wrap_chis
   self.rota_result = rotalyze.rotamer(**kwargs)
Пример #3
0
    def set_rotamer_to_reference(self,
                                 xray_structure,
                                 mon_lib_srv=None,
                                 log=None,
                                 quiet=False):
        if self.mon_lib_srv is None:
            self.mon_lib_srv = mon_lib_srv
        assert isinstance(self.mon_lib_srv,
                          mmtbx.monomer_library.server.server)
        if (log is None): log = sys.stdout
        make_sub_header("Correcting rotamer outliers to match reference model",
                        out=log)
        sa = SidechainAngles(False)
        r = rotalyze.rotalyze(pdb_hierarchy=self.pdb_hierarchy)
        rot_list_reference = {}
        coot_reference = {}
        for key in self.pdb_hierarchy_ref.keys():
            hierarchy = self.pdb_hierarchy_ref[key]
            rot_list_reference[key] = \
              rotalyze.rotalyze(pdb_hierarchy=hierarchy)
        model_hash = {}
        model_chis = {}
        reference_hash = {}
        reference_chis = {}
        model_outliers = 0
        for rot in r.results:
            model_hash[rot.id_str()] = rot.rotamer_name
            if rot.rotamer_name == "OUTLIER":
                model_outliers += 1

        for key in rot_list_reference.keys():
            reference_hash[key] = {}
            for rot in rot_list_reference[key].results:
                reference_hash[key][rot.id_str()] = rot.rotamer_name

        print >> log, "** evaluating rotamers for working model **"
        for model in self.pdb_hierarchy.models():
            for chain in model.chains():
                for residue_group in chain.residue_groups():
                    all_dict = rotalyze.construct_complete_sidechain(
                        residue_group)
                    for atom_group in residue_group.atom_groups():
                        try:
                            atom_dict = all_dict.get(atom_group.altloc)
                            chis = sa.measureChiAngles(atom_group, atom_dict)
                            if chis is not None:
                                key = utils.id_str(chain_id=chain.id,
                                                   resseq=residue_group.resseq,
                                                   resname=atom_group.resname,
                                                   icode=residue_group.icode,
                                                   altloc=atom_group.altloc)
                                model_chis[key] = chis
                        except Exception:
                            print >> log, \
                              '  %s%5s %s is missing some sidechain atoms, **skipping**' % (
                                  chain.id, residue_group.resid(),
                                  atom_group.altloc+atom_group.resname)
        if model_outliers == 0:
            print >> log, "No rotamer outliers detected in working model"
            return
        else:
            print >> log, "Number of rotamer outliers: %d" % model_outliers

        print >> log, "\n** evaluating rotamers for reference model **"
        for file in self.pdb_hierarchy_ref.keys():
            hierarchy = self.pdb_hierarchy_ref[file]
            reference_chis[file] = {}
            for model in hierarchy.models():
                for chain in model.chains():
                    for residue_group in chain.residue_groups():
                        all_dict = rotalyze.construct_complete_sidechain(
                            residue_group)
                        for atom_group in residue_group.atom_groups():
                            try:
                                atom_dict = all_dict.get(atom_group.altloc)
                                chis = sa.measureChiAngles(
                                    atom_group, atom_dict)
                                if chis is not None:
                                    key = utils.id_str(
                                        chain_id=chain.id,
                                        resseq=residue_group.resseq,
                                        resname=atom_group.resname,
                                        icode=residue_group.icode,
                                        altloc=atom_group.altloc)
                                    reference_chis[file][key] = chis
                            except Exception:
                                print >> log, \
                                  '  %s%5s %s is missing some sidechain atoms, **skipping**' % (
                                      chain.id, residue_group.resid(),
                                      atom_group.altloc+atom_group.resname)

        print >> log, "\n** fixing outliers **"
        sites_cart_start = xray_structure.sites_cart()
        for model in self.pdb_hierarchy.models():
            for chain in model.chains():
                for residue_group in chain.residue_groups():
                    if len(residue_group.conformers()) > 1:
                        print >> log, "  %s%5s %s has multiple conformations, **skipping**" % (
                            chain.id, residue_group.resid(),
                            " " + residue_group.atom_groups()[0].resname)
                        continue
                    for conformer in residue_group.conformers():
                        for residue in conformer.residues():
                            if residue.resname == "PRO":
                                continue
                            key = utils.id_str(
                                chain_id=chain.id,
                                resseq=residue_group.resseq,
                                resname=residue_group.atom_groups()[0].resname,
                                icode=residue_group.icode,
                                altloc=conformer.altloc)
                            if len(chain.id) == 1:
                                chain_id = " " + chain.id
                            else:
                                chain_id = chain.id
                            file_key = '%s%s%s' % (residue.resname, chain_id,
                                                   residue_group.resid())
                            file_key = file_key.strip()
                            file_match = self.residue_match_hash.get(file_key)
                            if file_match is not None:
                                file = file_match[0]
                            else:
                                continue
                            model_rot = model_hash.get(key)
                            reference_rot = reference_hash[file].get(
                                self.one_key_to_another(file_match[1]))
                            m_chis = model_chis.get(key)
                            r_chis = reference_chis[file].get(
                                self.one_key_to_another(file_match[1]))
                            if model_rot is not None and reference_rot is not None and \
                                m_chis is not None and r_chis is not None:
                                if (model_rot == 'OUTLIER' and \
                                    reference_rot != 'OUTLIER'): # or \
                                    #atom_group.resname in ["LEU", "VAL", "THR"]:
                                    self.change_residue_rotamer_in_place(
                                        sites_cart_start, residue, m_chis,
                                        r_chis, self.mon_lib_srv)
                                    xray_structure.set_sites_cart(
                                        sites_cart_start)

                                elif self.params.strict_rotamer_matching and \
                                  (model_rot != 'OUTLIER' and reference_rot != 'OUTLIER'):
                                    if model_rot != reference_rot:
                                        self.change_residue_rotamer_in_place(
                                            sites_cart_start, residue, m_chis,
                                            r_chis, self.mon_lib_srv)
                                        xray_structure.set_sites_cart(
                                            sites_cart_start)
Пример #4
0
  def set_rotamer_to_reference(self,
                               xray_structure,
                               mon_lib_srv=None,
                               log=None,
                               quiet=False):
    if self.mon_lib_srv is None:
      self.mon_lib_srv = mon_lib_srv
    assert isinstance(self.mon_lib_srv, mmtbx.monomer_library.server.server)
    if(log is None): log = sys.stdout
    make_sub_header(
      "Correcting rotamer outliers to match reference model",
      out=log)
    sa = SidechainAngles(False)
    r = rotalyze.rotalyze(pdb_hierarchy=self.pdb_hierarchy)
    rot_list_reference = {}
    coot_reference = {}
    for key in self.pdb_hierarchy_ref.keys():
      hierarchy = self.pdb_hierarchy_ref[key]
      rot_list_reference[key] = \
        rotalyze.rotalyze(pdb_hierarchy=hierarchy)
    model_hash = {}
    model_chis = {}
    reference_hash = {}
    reference_chis = {}
    model_outliers = 0
    for rot in r.results:
      model_hash[rot.id_str()] = rot.rotamer_name
      if rot.rotamer_name == "OUTLIER":
        model_outliers += 1

    for key in rot_list_reference.keys():
      reference_hash[key] = {}
      for rot in rot_list_reference[key].results:
        reference_hash[key][rot.id_str()] = rot.rotamer_name

    print >> log, "** evaluating rotamers for working model **"
    for model in self.pdb_hierarchy.models():
      for chain in model.chains():
        for residue_group in chain.residue_groups():
            all_dict = rotalyze.construct_complete_sidechain(residue_group)
            for atom_group in residue_group.atom_groups():
              try:
                atom_dict = all_dict.get(atom_group.altloc)
                chis = sa.measureChiAngles(atom_group, atom_dict)
                if chis is not None:
                  key = utils.id_str(
                          chain_id=chain.id,
                          resseq=residue_group.resseq,
                          resname=atom_group.resname,
                          icode=residue_group.icode,
                          altloc=atom_group.altloc)
                  model_chis[key] = chis
              except Exception:
                print >> log, \
                  '  %s%5s %s is missing some sidechain atoms, **skipping**' % (
                      chain.id, residue_group.resid(),
                      atom_group.altloc+atom_group.resname)
    if model_outliers == 0:
      print >> log, "No rotamer outliers detected in working model"
      return
    else:
      print >> log, "Number of rotamer outliers: %d" % model_outliers

    print >> log, "\n** evaluating rotamers for reference model **"
    for file in self.pdb_hierarchy_ref.keys():
      hierarchy = self.pdb_hierarchy_ref[file]
      reference_chis[file] = {}
      for model in hierarchy.models():
        for chain in model.chains():
          for residue_group in chain.residue_groups():
              all_dict = rotalyze.construct_complete_sidechain(residue_group)
              for atom_group in residue_group.atom_groups():
                try:
                  atom_dict = all_dict.get(atom_group.altloc)
                  chis = sa.measureChiAngles(atom_group, atom_dict)
                  if chis is not None:
                    key = utils.id_str(
                            chain_id=chain.id,
                            resseq=residue_group.resseq,
                            resname=atom_group.resname,
                            icode=residue_group.icode,
                            altloc=atom_group.altloc)
                    reference_chis[file][key] = chis
                except Exception:
                  print >> log, \
                    '  %s%5s %s is missing some sidechain atoms, **skipping**' % (
                        chain.id, residue_group.resid(),
                        atom_group.altloc+atom_group.resname)

    print >> log, "\n** fixing outliers **"
    sites_cart_start = xray_structure.sites_cart()
    for model in self.pdb_hierarchy.models():
      for chain in model.chains():
        for residue_group in chain.residue_groups():
          if len(residue_group.conformers()) > 1:
            print >> log, "  %s%5s %s has multiple conformations, **skipping**" % (
              chain.id, residue_group.resid(),
              " "+residue_group.atom_groups()[0].resname)
            continue
          for conformer in residue_group.conformers():
            for residue in conformer.residues():
              if residue.resname == "PRO":
                continue
              key = utils.id_str(
                      chain_id=chain.id,
                      resseq=residue_group.resseq,
                      resname=residue_group.atom_groups()[0].resname,
                      icode=residue_group.icode,
                      altloc=conformer.altloc)
              if len(chain.id) == 1:
                chain_id = " "+chain.id
              else:
                chain_id = chain.id
              file_key = '%s%s%s' %(residue.resname,
                                    chain_id,
                                    residue_group.resid())
              file_key = file_key.strip()
              file_match = self.residue_match_hash.get(file_key)
              if file_match is not None:
                file = file_match[0]
              else:
                continue
              model_rot = model_hash.get(key)
              reference_rot = reference_hash[file].get(self.one_key_to_another(file_match[1]))
              m_chis = model_chis.get(key)
              r_chis = reference_chis[file].get(self.one_key_to_another(file_match[1]))
              if model_rot is not None and reference_rot is not None and \
                  m_chis is not None and r_chis is not None:
                if (model_rot == 'OUTLIER' and \
                    reference_rot != 'OUTLIER'): # or \
                    #atom_group.resname in ["LEU", "VAL", "THR"]:
                  self.change_residue_rotamer_in_place(
                      sites_cart_start,residue, m_chis,r_chis,self.mon_lib_srv)
                  xray_structure.set_sites_cart(sites_cart_start)

                elif self.params.strict_rotamer_matching and \
                  (model_rot != 'OUTLIER' and reference_rot != 'OUTLIER'):
                  if model_rot != reference_rot:
                    self.change_residue_rotamer_in_place(
                        sites_cart_start,residue, m_chis,r_chis,self.mon_lib_srv)
                    xray_structure.set_sites_cart(sites_cart_start)
Пример #5
0
  def __init__(self, pdb_hierarchy,
      data_version="8000",
      outliers_only=False,
      show_errors=False,
      out=sys.stdout,
      quiet=False):
    validation.__init__(self)
    self.n_allowed = 0
    self.n_favored = 0
    from mmtbx.rotamer.sidechain_angles import SidechainAngles
    from mmtbx.rotamer import rotamer_eval
    from mmtbx.rotamer.rotamer_eval import RotamerID
    from mmtbx.validation import utils
    self.data_version = data_version
#   if self.data_version == "500":    self.outlier_threshold = 0.01
    if self.data_version == "8000": self.outlier_threshold = OUTLIER_THRESHOLD
    else: raise ValueError(
      "data_version given to RotamerEval not recognized (%s)." % data_version)
    sidechain_angles = SidechainAngles(show_errors)
    rotamer_evaluator = rotamer_eval.RotamerEval(
                             data_version=data_version)
    rotamer_id = rotamer_eval.RotamerID() # loads in the rotamer names
    use_segids = utils.use_segids_in_place_of_chainids(
                   hierarchy=pdb_hierarchy)
    current_rotamers = {}
    for model in pdb_hierarchy.models():
      for chain in model.chains():
        if use_segids:
          chain_id = utils.get_segid_as_chainid(chain=chain)
        else:
          chain_id = chain.id
        for rg in chain.residue_groups():
          all_dict = construct_complete_sidechain(rg)
          for atom_group in rg.atom_groups():
            coords = get_center(atom_group)
            resname = atom_group.resname
            occupancy = get_occupancy(atom_group)
            kwargs = {
              "chain_id" : chain_id,
              "resseq" : rg.resseq,
              "icode" : rg.icode,
              "altloc" : atom_group.altloc,
              "resname" : resname,
              "xyz" : coords,
              "occupancy" : occupancy,
            }
            atom_dict = all_dict.get(atom_group.altloc)
            res_key = get_residue_key(atom_group=atom_group)
            try:
              chis = sidechain_angles.measureChiAngles(
                       atom_group,
                       atom_dict)#.get(conformer.altloc))
            except AttributeError:
              if show_errors:
                kwargs['incomplete'] = True
                result = rotamer(**kwargs)
                print >> out, '%s is missing some sidechain atoms' % \
                  result.id_str()
                self.results.append(result)
              continue
            if (chis is not None):
              if None in chis:
                continue
              cur_res = resname.lower().strip()
              if cur_res == 'mse':
                cur_res = 'met'
              value = rotamer_evaluator.evaluate(cur_res, chis)
              if value is not None:
                self.n_total += 1
                kwargs['score'] = value * 100
                wrap_chis = rotamer_id.wrap_chis(resname.strip(), chis,
                  symmetry=False)
                sym_chis = wrap_chis[:]
                sym_chis = rotamer_id.wrap_sym(resname.strip(), sym_chis)
                evaluation = self.evaluateScore(value)
                kwargs['evaluation'] = evaluation
                if evaluation == "OUTLIER":
                  kwargs['outlier'] = True
                  kwargs['rotamer_name'] = evaluation
                else:
                  kwargs['outlier'] = False
                  kwargs['rotamer_name'] = rotamer_id.identify(resname,
                    wrap_chis)
                  #deal with unclassified rotamers
                  if kwargs['rotamer_name'] == '':
                    kwargs['rotamer_name'] = "UNCLASSIFIED"
                while (len(wrap_chis) < 4):
                  wrap_chis.append(None)
                kwargs['chi_angles'] = wrap_chis
                result = rotamer(**kwargs)
                if (result.is_outlier()) or (not outliers_only):
                  self.results.append(result)
    out_count, out_percent = self.get_outliers_count_and_fraction()
    self.out_percent = out_percent * 100.0
Пример #6
0
    def __init__(
        self, pdb_hierarchy, data_version="8000", outliers_only=False, show_errors=False, out=sys.stdout, quiet=False
    ):
        validation.__init__(self)
        self.n_allowed = 0
        self.n_favored = 0
        from mmtbx.rotamer.sidechain_angles import SidechainAngles
        from mmtbx.rotamer import rotamer_eval
        from mmtbx.rotamer.rotamer_eval import RotamerID
        from mmtbx.validation import utils

        self.data_version = data_version
        #   if self.data_version == "500":    self.outlier_threshold = 0.01
        if self.data_version == "8000":
            self.outlier_threshold = 0.003
        else:
            raise ValueError("data_version given to RotamerEval not recognized (%s)." % data_version)
        sidechain_angles = SidechainAngles(show_errors)
        rotamer_evaluator = rotamer_eval.RotamerEval(data_version=data_version)
        rotamer_id = rotamer_eval.RotamerID()  # loads in the rotamer names
        use_segids = utils.use_segids_in_place_of_chainids(hierarchy=pdb_hierarchy)
        current_rotamers = {}
        for model in pdb_hierarchy.models():
            for chain in model.chains():
                if use_segids:
                    chain_id = utils.get_segid_as_chainid(chain=chain)
                else:
                    chain_id = chain.id
                for rg in chain.residue_groups():
                    all_dict = construct_complete_sidechain(rg)
                    for atom_group in rg.atom_groups():
                        coords = get_center(atom_group)
                        resname = atom_group.resname
                        occupancy = get_occupancy(atom_group)
                        kwargs = {
                            "chain_id": chain_id,
                            "resseq": rg.resseq,
                            "icode": rg.icode,
                            "altloc": atom_group.altloc,
                            "resname": resname,
                            "xyz": coords,
                            "occupancy": occupancy,
                        }
                        atom_dict = all_dict.get(atom_group.altloc)
                        res_key = get_residue_key(atom_group=atom_group)
                        try:
                            chis = sidechain_angles.measureChiAngles(atom_group, atom_dict)  # .get(conformer.altloc))
                        except AttributeError:
                            if show_errors:
                                kwargs["incomplete"] = True
                                result = rotamer(**kwargs)
                                print >> out, "%s is missing some sidechain atoms" % result.id_str()
                                self.results.append(result)
                            continue
                        if chis is not None:
                            if None in chis:
                                continue
                            cur_res = resname.lower().strip()
                            if cur_res == "mse":
                                cur_res = "met"
                            value = rotamer_evaluator.evaluate(cur_res, chis)
                            if value is not None:
                                self.n_total += 1
                                kwargs["score"] = value * 100
                                wrap_chis = rotamer_id.wrap_chis(resname.strip(), chis, symmetry=False)
                                sym_chis = wrap_chis[:]
                                sym_chis = rotamer_id.wrap_sym(resname.strip(), sym_chis)
                                evaluation = self.evaluateScore(value)
                                kwargs["evaluation"] = evaluation
                                if evaluation == "OUTLIER":
                                    kwargs["outlier"] = True
                                    kwargs["rotamer_name"] = evaluation
                                else:
                                    kwargs["outlier"] = False
                                    kwargs["rotamer_name"] = rotamer_id.identify(resname, wrap_chis)
                                    # deal with unclassified rotamers
                                    if kwargs["rotamer_name"] == "":
                                        kwargs["rotamer_name"] = "UNCLASSIFIED"
                                while len(wrap_chis) < 4:
                                    wrap_chis.append(None)
                                kwargs["chi_angles"] = wrap_chis
                                result = rotamer(**kwargs)
                                if (result.is_outlier()) or (not outliers_only):
                                    self.results.append(result)
        out_count, out_percent = self.get_outliers_count_and_fraction()
        self.out_percent = out_percent * 100.0