def exercise_model_utils () : pdb_in = get_1yjp_pdb() residue = pdb_in.hierarchy.only_model().chains()[0].residue_groups()[0].only_atom_group() sele = pdb_in.hierarchy.atom_selection_cache().selection("resname TYR") water_sel = building.get_nearby_water_selection( pdb_hierarchy=pdb_in.hierarchy, xray_structure=pdb_in.input.xray_structure_simple(), selection=sele) assert (list(water_sel.iselection()) == [59, 60, 61, 62, 63]) from mmtbx.monomer_library import idealized_aa from mmtbx.monomer_library import server mon_lib_srv = server.server() ideal_dict = idealized_aa.residue_dict() for resname, hierarchy in ideal_dict.iteritems() : residue = hierarchy.only_model().only_chain().only_residue_group().only_atom_group() result = building.generate_sidechain_clusters(residue, mon_lib_srv) if (len(result) == 0) : # no side-chain clusters for UNK as well assert (residue.resname in ["ALA", "GLY", "UNK"]), residue.resname # show_chain_resseq_ranges resids = [ (1,''),(2,''),(2,'A'),(4,''),(5,''),(6,''),(10,'B') ] import iotbx.pdb.hierarchy chain = iotbx.pdb.hierarchy.chain(id='A') for (resseq, icode) in resids : rg = iotbx.pdb.hierarchy.residue_group(resseq="%4d" % resseq, icode=icode) chain.append_residue_group(rg) out = StringIO() building.show_chain_resseq_ranges(chain.residue_groups(), out=out, prefix=" ") assert out.getvalue() == """ chain 'A': 1-2A,4-6,10B\n""", out.getvalue()
def extend_residue(residue, target_atom_group, mon_lib_srv): """ Rebuild a sidechain by substituting an ideal amino acid and rotating the sidechain to match the old conformation as closely as possible. Limited functionality: 1) Amino-acids only, 2) side chain atoms only. """ from iotbx.pdb import hierarchy from mmtbx.building import generate_sidechain_clusters import mmtbx.refinement.real_space tmp_residue = residue.detached_copy() new_residue = hierarchy.substitute_atom_group(current_group=tmp_residue, new_group=target_atom_group) clusters = generate_sidechain_clusters(residue=new_residue, mon_lib_srv=mon_lib_srv) scorer = conformation_scorer(old_residue=residue, new_residue=new_residue) mmtbx.refinement.real_space.torsion_search( scorer=scorer, clusters=clusters, sites_cart=new_residue.atoms().extract_xyz(), start=0, stop=360, step=1) scorer.apply_final() return new_residue
def __init__(self, residue, sites_cart, mon_lib_srv, params, prev_residue=None, next_residue=None, next_next_residue=None, evaluate_backbone_callback=None): adopt_init_args(self, locals()) from mmtbx.rotamer import rotamer_eval from mmtbx.rotamer import ramachandran_eval import iotbx.pdb from scitbx.array_family import flex get_class = iotbx.pdb.common_residue_names_get_class assert get_class( residue.resname) == "common_amino_acid", residue.resname self.rotamer_scorer = rotamer_eval.RotamerEval(data_version="8000") self.ramachandran_scorer = ramachandran_eval.RamachandranEval() self.sidechain_clusters = generate_sidechain_clusters( residue=residue, mon_lib_srv=mon_lib_srv) self.sites_start = sites_cart.deep_copy() self.i_seqs_residue = residue.atoms().extract_i_seq() self.i_seqs_sidechain = flex.size_t() for atom in self.residue.atoms(): if (not atom.name.strip() in ["C", "N", "H", "CA", "CB", "self"]): self.i_seqs_sidechain.append(atom.i_seq) self.i_seqs_primary = flex.size_t() if (not None in [prev_residue, next_residue]): self.set_up_backrub() if (next_next_residue is not None): self.set_up_shear() for i_seq in self.shear_i_seqs_primary1: self.i_seqs_primary.append(i_seq) for i_seq in self.shear_i_seqs_primary2: self.i_seqs_primary.append(i_seq) for i_seq in self.shear_i_seqs_middle: self.i_seqs_primary.append(i_seq) else: for i_seq in self.backrub_i_seqs: self.i_seqs_primary.append(i_seq) else: self.i_seqs_primary = self.i_seqs_residue
def __init__ (self, residue, sites_cart, mon_lib_srv, params, prev_residue=None, next_residue=None, next_next_residue=None, evaluate_backbone_callback=None) : adopt_init_args(self, locals()) from mmtbx.rotamer import rotamer_eval from mmtbx.rotamer import ramachandran_eval import iotbx.pdb from scitbx.array_family import flex get_class = iotbx.pdb.common_residue_names_get_class assert get_class(residue.resname) == "common_amino_acid", residue.resname self.rotamer_scorer = rotamer_eval.RotamerEval(data_version="8000") self.ramachandran_scorer = ramachandran_eval.RamachandranEval() self.sidechain_clusters = generate_sidechain_clusters( residue=residue, mon_lib_srv=mon_lib_srv) self.sites_start = sites_cart.deep_copy() self.i_seqs_residue = residue.atoms().extract_i_seq() self.i_seqs_sidechain = flex.size_t() for atom in self.residue.atoms() : if (not atom.name.strip() in ["C","N","H","CA","CB","self"]) : self.i_seqs_sidechain.append(atom.i_seq) self.i_seqs_primary = flex.size_t() if (not None in [prev_residue, next_residue]) : self.set_up_backrub() if (next_next_residue is not None) : self.set_up_shear() for i_seq in self.shear_i_seqs_primary1 : self.i_seqs_primary.append(i_seq) for i_seq in self.shear_i_seqs_primary2 : self.i_seqs_primary.append(i_seq) for i_seq in self.shear_i_seqs_middle : self.i_seqs_primary.append(i_seq) else: for i_seq in self.backrub_i_seqs : self.i_seqs_primary.append(i_seq) else : self.i_seqs_primary = self.i_seqs_residue
def extend_residue(residue, ideal_dict, mon_lib_srv=None, hydrogens=False, match_conformation=True): """ Rebuild a sidechain by substituting an ideal amino acid and (optionally) rotating the sidechain to match the old conformation as closely as possible. """ from iotbx.pdb import hierarchy res_key = residue.resname.lower() if (hydrogens == True): res_key += "_h" ideal = ideal_dict[res_key] tmp_residue = residue.detached_copy() new_residue = hierarchy.substitute_atom_group( current_group=tmp_residue, new_group=ideal.only_model().only_chain().only_residue_group(). only_atom_group(), backbone_only=True, is_amino_acid=True, # XXX this could probably be smarter... exclude_hydrogens=False) assert (new_residue.resname == residue.resname) if (match_conformation): from mmtbx.building import generate_sidechain_clusters import mmtbx.refinement.real_space assert (mon_lib_srv is not None) clusters = generate_sidechain_clusters(residue=new_residue, mon_lib_srv=mon_lib_srv) scorer = conformation_scorer(old_residue=residue, new_residue=new_residue) mmtbx.refinement.real_space.torsion_search( scorer=scorer, clusters=clusters, sites_cart=new_residue.atoms().extract_xyz(), start=0, stop=360, step=1) scorer.apply_final() return new_residue
def extend_residue (residue, ideal_dict, mon_lib_srv=None, hydrogens=False, match_conformation=True) : """ Rebuild a sidechain by substituting an ideal amino acid and (optionally) rotating the sidechain to match the old conformation as closely as possible. """ from iotbx.pdb import hierarchy res_key = residue.resname.lower() if (hydrogens == True) : res_key += "_h" ideal = ideal_dict[res_key] tmp_residue = residue.detached_copy() new_residue = hierarchy.substitute_atom_group( current_group=tmp_residue, new_group=ideal.only_model().only_chain().only_residue_group().only_atom_group(), backbone_only=True, is_amino_acid=True, # XXX this could probably be smarter... exclude_hydrogens=False) assert (new_residue.resname == residue.resname) if (match_conformation) : from mmtbx.building import generate_sidechain_clusters import mmtbx.refinement.real_space assert (mon_lib_srv is not None) clusters = generate_sidechain_clusters(residue=new_residue, mon_lib_srv=mon_lib_srv) scorer = conformation_scorer( old_residue=residue, new_residue=new_residue) mmtbx.refinement.real_space.torsion_search( scorer=scorer, clusters=clusters, sites_cart=new_residue.atoms().extract_xyz(), start=0, stop=360, step=1) scorer.apply_final() return new_residue