Exemplo n.º 1
0
 def validate_residues(self):
     from mmtbx.conformation_dependent_library import generate_protein_threes
     from mmtbx.rotamer import ramachandran_eval, rotamer_eval
     # this is so we generate rama_eval only once
     rama_eval = ramachandran_eval.RamachandranEval()
     rota_eval = rotamer_eval.RotamerEval()
     rotamer_id = rotamer_eval.RotamerID()  # loads in the rotamer names
     threes = generate_protein_threes(hierarchy=self.pdb_hierarchy,
                                      include_non_linked=True,
                                      backbone_only=False,
                                      geometry=None)
     for i, three in enumerate(threes):
         if i == 0:
             self.residues.append(
                 ValidationResidue(three,
                                   rama_eval,
                                   rota_eval,
                                   rotamer_id,
                                   index=0))
         self.residues.append(
             ValidationResidue(three, rama_eval, rota_eval, rotamer_id))
         if three.end:
             self.residues.append(
                 ValidationResidue(three,
                                   rama_eval,
                                   rota_eval,
                                   rotamer_id,
                                   index=2))
Exemplo n.º 2
0
 def __init__(self,
              pdb_hierarchy,
              xray_structure,
              range_start=-10.0,
              range_stop=10.0,
              step=1.0,
              min_angle_between_solutions=0.5,
              name_hash=None,
              selection=None,
              log=None):
     if (log is None): log = sys.stdout
     self.log = log
     self.mon_lib_srv = mmtbx.monomer_library.server.server()
     self.unit_cell = xray_structure.unit_cell()
     self.exclude_free_r_reflections = False
     self.torsion_params = \
       fit_rotamers.torsion_search_params().extract().torsion_search
     self.torsion_params.range_start = range_start
     self.torsion_params.range_stop = range_stop
     self.torsion_params.step = step
     self.torsion_params.min_angle_between_solutions = \
       min_angle_between_solutions
     self.selection = selection
     if self.selection is None:
         sites_cart = pdb_hierarchy.atoms().extract_xyz()
         self.selection = flex.bool(len(sites_cart), True)
     self.c_alpha_hinges = torsion_utils.get_c_alpha_hinges(
         pdb_hierarchy=pdb_hierarchy,
         xray_structure=xray_structure,
         selection=self.selection)
     self.name_hash = name_hash
     if self.name_hash is None:
         self.name_hash = build_name_hash(pdb_hierarchy)
     from mmtbx.rotamer.sidechain_angles import SidechainAngles
     from mmtbx.rotamer import rotamer_eval
     self.sa = SidechainAngles(False)
     self.rotamer_id = rotamer_eval.RotamerID()
     self.rotamer_evaluator = rotamer_eval.RotamerEval(
         mon_lib_srv=self.mon_lib_srv)
     self.target_map_data = None
     self.residual_map_data = None
Exemplo n.º 3
0
def update_restraints(hierarchy,
                      geometry, # restraints_manager,
                      current_geometry=None, # xray_structure!!
                      sites_cart=None,
                      rdl_proxies=None,
                      esd_factor=1.,
                      exclude_backbone=False,
                      assert_rotamer_found=False,
                      rdl_selection=None,
                      log=None,
                      verbose=False,
                      data_version="8000",
                      ):
  assert data_version == "8000","data_version not recognized."
  assert not exclude_backbone
  loud=True and False
  if loud:
    verbose=1
  from mmtbx.rotamer.sidechain_angles import SidechainAngles
  from mmtbx.rotamer import rotamer_eval
  from mmtbx.validation import rotalyze
  #
  def _set_or_reset_angle_restraints(geometry,
                                     lookup,
                                     use_rdl_weights=False,
                                     verbose=False,
                                     ):
    count = 0
    for angle_proxy in geometry.angle_proxies:
      if angle_proxy.i_seqs in lookup:
        if verbose: print(" i_seqs %-15s initial %12.3f %12.3f" % (
          angle_proxy.i_seqs,
          angle_proxy.angle_ideal,
          angle_proxy.weight,
          ))
        assert angle_proxy.angle_ideal<181
        angle_proxy.angle_ideal = lookup[angle_proxy.i_seqs][0]
        if use_rdl_weights: angle_proxy.weight = esd_factor/lookup[angle_proxy.i_seqs][1]**2
        if verbose: print(" i_seqs %-15s final   %12.3f %12.3f" % (
          angle_proxy.i_seqs,
          angle_proxy.angle_ideal,
          angle_proxy.weight,
          ))
        count += 1
    return count
  #
  def _set_or_reset_dihedral_restraints(geometry,
                                        lookup,
                                        use_rdl_weights=False,
                                        verbose=False,
                                        ):
    count = 0
    for angle_proxy in geometry.dihedral_proxies:
      if angle_proxy.i_seqs in lookup:
        if verbose: print(" i_seqs %-15s initial %12.3f %12.3f %s %d" % (
          angle_proxy.i_seqs,
          angle_proxy.angle_ideal,
          angle_proxy.weight,
          angle_proxy.alt_angle_ideals,
          angle_proxy.periodicity,
          ))
        angle_proxy.angle_ideal = lookup[angle_proxy.i_seqs][0]
        if use_rdl_weights: angle_proxy.weight = esd_factor/lookup[angle_proxy.i_seqs][1]**2
        angle_proxy.alt_angle_ideals=None
        angle_proxy.periodicity = lookup[angle_proxy.i_seqs][2]
        if verbose: print(" i_seqs %-15s final   %12.3f %12.3f %s %d" % (
          angle_proxy.i_seqs,
          angle_proxy.angle_ideal,
          angle_proxy.weight,
          angle_proxy.alt_angle_ideals,
          angle_proxy.periodicity,
          ))
        count += 1
    return count
  #
  t0=time.time()
  sa = SidechainAngles(False)
  rotamer_id = rotamer_eval.RotamerID()
  rotamer_evaluator = rotamer_eval.RotamerEval(data_version=data_version)
  sites_cart = None
  if current_geometry:
    sites_cart = current_geometry.sites_cart()
  #
  if rdl_proxies is None:
    rdl_proxies = []
  i_seqs_restraints = {}
  i_seqs_restraints_reverse = {}
  #
  def _alt_loc_atom_generator(residue_group, atom_group):
    atoms = []
    for ag in residue_group.atom_groups():
      if ag.altloc.strip()=="" or ag.altloc.strip()==atom_group.altloc.strip():
        for atom in ag.atoms(): yield atom
  #
  for model in hierarchy.models():
    #if verbose: print 'model: "%s"' % model.id
    for chain in model.chains():
      #if verbose: print 'chain: "%s"' % chain.id
      for residue_group in chain.residue_groups():
        all_dict = rotalyze.construct_complete_sidechain(residue_group)
        for atom_group in residue_group.atom_groups():
          if rdl_selection is None: pass
          elif 'all' in rdl_selection: pass
          elif atom_group.resname in rdl_selection: pass
          else: continue
          rc = get_rotamer_data(atom_group,
                                sa,
                                rotamer_evaluator,
                                rotamer_id,
                                all_dict=all_dict,
                                sites_cart=sites_cart,
            )
          if rc is None: continue
          rotamer_name, chis, value = rc
          if verbose:
            chis_str = "["
            if chis:
              for chi in chis:
                chis_str += " %6.1f," % chi
              chis_str = chis_str[:-1]+']'
            try:
              print("  %s %s %s %-5s %-60s %0.1f" % (
                chain.id,
                atom_group.resname,
                residue_group.resseq,
                rotamer_name,
                chis_str,
                value,
              ), file=log)
            except TypeError as e:
              print("  %s %s %s %-5s %-60s %s" % (
                chain.id,
                atom_group.resname,
                residue_group.resseq,
                rotamer_name,
                chis_str,
                value,
              ), file=log)
          if loud: print('exclude_backbone',exclude_backbone)
          if rotamer_name in ["OUTLIER"]: continue
          resname_lookup = substitute_residue_lookup.get(atom_group.resname,
                                                         atom_group.resname,
                                                         )
          if rotamer_name not in rdl_database[resname_lookup]:
            if assert_rotamer_found:
              raise Sorry("rotamer %s not found in db" % rotamer_name)
            else:
              continue
          if loud: print('not outlier')
          if rotamer_name not in rdl_database[resname_lookup]:
            if loud: print("rotamer_name %s not in RDL db" % rotamer_name)
            continue
          if loud: print('rotamer_name %s found' % rotamer_name)
          restraints = rdl_database[resname_lookup][rotamer_name]
          defaults = rdl_database[resname_lookup]["default"]
          rdl_proxies.append(atom_group.id_str())
          for names, values in restraints.items():
            i_seqs = []
            if exclude_backbone and names[1] in ["N", "CA", "C"]: continue
            for name in names:
              for atom in _alt_loc_atom_generator(residue_group, atom_group):
                if name.strip()==atom.name.strip():
                  i_seqs.append(atom.i_seq)
                  break
            if len(i_seqs)!=len(names): continue
            i_seqs_restraints[tuple(i_seqs)] = values
            i_seqs.reverse()
            i_seqs_restraints[tuple(i_seqs)] = values
            if names in defaults:
              i_seqs_restraints_reverse[tuple(i_seqs)] = defaults[names]
              i_seqs.reverse()
              i_seqs_restraints_reverse[tuple(i_seqs)] = defaults[names]
  #
  if loud:
    for i, atom in enumerate(hierarchy.atoms()):
      print(i, atom.quote())
  count = _set_or_reset_dihedral_restraints(geometry,
                                            i_seqs_restraints_reverse,
                                            #verbose=loud,
                                            )
  count_d = _set_or_reset_dihedral_restraints(geometry,
                                            i_seqs_restraints,
                                            verbose=loud,
                                            )
  count = _set_or_reset_angle_restraints(geometry,
                                         i_seqs_restraints_reverse,
                                         #verbose=loud,
                                         )
  count_a = _set_or_reset_angle_restraints(geometry,
                                         i_seqs_restraints,
                                         verbose=loud,
                                         )
  #
  print("    Number of angles, dihedrals RDL adjusted : %d, %d" % (
    count_a,
    count_d,
    ), file=log)
  print("    Time to adjust                           : %0.1fs" % (
    time.time()-t0), file=log)
  return rdl_proxies
Exemplo n.º 4
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
    },
    'PHE': {
        'm-10': {
            lookup['PHE'][2]: [-14.7, 19.8, 2]
        },
    },
    'TYR': {
        'm-10': {
            lookup['PHE'][2]: [-14.7, 20.2, 2]
        },
    },
    'VAL': 1,
}

rotamer_evaluator = rotamer_eval.RotamerEval(data_version='8000')
rotamer_id = rotamer_eval.RotamerID()  # loads in the rotamer names


def generate_chis(
    chis=None,
    n=2,
    step=10,
    depth=0,
    starting_chis=None,
):
    if chis is None:
        if starting_chis:
            chis = []
            for c in starting_chis:
                chis.append(c)
                depth += 1