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)
def __init__(self, sidechain_angles=None, mon_lib_srv=None, log=None, data_version="8000"): # data_version="500"): if sidechain_angles is None: sidechain_angles = SidechainAngles(True) self.sidechain_angles = sidechain_angles if mon_lib_srv is None: mon_lib_srv = mmtbx.monomer_library.server.server() if log is None: log = sys.stdout self.data_version = data_version if self.data_version == "8000": self.outlier_threshold = 0.003 fileprefix = "rota8000-" else: raise Sorry("data_version given to RotamerEval not recognized.") self.log = log self.mon_lib_srv = mon_lib_srv self.rot_id = RotamerID() main_aaTables = RotamerEval.aaTables self.aaTables = {} for aa, ndt_weakref in main_aaTables.items(): # convert existing weak references to strong references self.aaTables[aa] = ndt_weakref() rotamer_data_dir = find_rotarama_data_dir() no_update = os.path.exists(os.path.join(rotamer_data_dir, "NO_UPDATE")) target_db = open_rotarama_dlite(rotarama_data_dir=rotamer_data_dir) for aa, aafile in aminoAcids.items(): if (self.aaTables.get(aa) is not None): continue data_file = fileprefix + aafile + ".data" pickle_file = fileprefix + aafile + ".pickle" pair_info = target_db.pair_info(source_path=data_file, target_path=pickle_file, path_prefix=rotamer_data_dir) if (((pair_info.needs_update) and (not no_update)) or not os.path.exists( os.path.join(rotamer_data_dir, pickle_file))): raise Sorry( "chem_data/rotarama_data/*.pickle files are missing or out of date.\n" " Please run\n" " mmtbx.rebuild_rotarama_cache\n" " to resolve this problem.\n") ndt = easy_pickle.load(file_name=os.path.join( rotamer_data_dir, pair_info.target.path)) self.aaTables[aa] = ndt main_aaTables[aa] = weakref.ref(ndt)
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
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
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)
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)
def __init__(self): from mmtbx.rotamer.sidechain_angles import SidechainAngles from mmtbx.rotamer import rotamer_eval self.sa = SidechainAngles(False) self.data_version = "8000" self.r = rotamer_eval.RotamerEval(data_version=self.data_version)
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
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