def exercise_cablam(): regression_pdb = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/pdb103l.ent", test=os.path.isfile) #This is the same file used for tst_kinemage.py if (regression_pdb is None): print "Skipping exercise_cablam(): input pdb (pdb103l.ent) not available" return #----- pdb_io = pdb.input(regression_pdb) pdbid = os.path.basename(regression_pdb) hierarchy = pdb_io.construct_hierarchy() output_holder = cablam_test_string() cablamalyze = cablam.cablamalyze( pdb_hierarchy = hierarchy, outliers_only=False, out=output_holder, quiet=False) cablamalyze.as_oneline() assert not show_diff(output_holder.output , ref_cablam_oneline) output_holder.output = "" cablamalyze.as_text() assert not show_diff(output_holder.output , ref_cablam_text)
def find_sec_str(self, pdb_hierarchy): if self.params.secondary_structure.protein.search_method == "ksdssp": pdb_str = pdb_hierarchy.as_pdb_string() print >> self.log, " running ksdssp..." (records, stderr) = run_ksdssp_direct(pdb_str) return iotbx.pdb.secondary_structure.annotation.from_records( records=records, log=self.log) elif self.params.secondary_structure.protein.search_method == "mmtbx_dssp": from mmtbx.secondary_structure import dssp print >> self.log, " running mmtbx.dssp..." return dssp.dssp( pdb_hierarchy=pdb_hierarchy, pdb_atoms=self.pdb_atoms, out=null_out()).get_annotation() elif self.params.secondary_structure.protein.search_method == "from_ca": from mmtbx.secondary_structure import find_ss_from_ca print >> self.log, " running find_ss_from_ca..." fss = find_ss_from_ca.find_secondary_structure( hierarchy=pdb_hierarchy, out=null_out()) return fss.get_annotation() elif self.params.secondary_structure.protein.search_method == "cablam": from mmtbx.validation import cablam print >> self.log, " running cablam..." cablam_results = cablam.cablamalyze( pdb_hierarchy = pdb_hierarchy, outliers_only=False, out=null_out(), quiet=False) return cablam_results.as_secondary_structure() else: print >> self.log, " WARNING: Unknown search method for SS. No SS found." return iotbx.pdb.secondary_structure.annotation.from_records()
def identify_outliers(self): cab_results = cablamalyze( pdb_hierarchy=self.model.get_master_hierarchy(), outliers_only=True, out=null_out(), quiet=True, cablam_contours=self.cablam_contours, ca_contours=self.ca_contours, motif_contours=self.motif_contours) outliers_only = [ x for x in cab_results.results if x.feedback.cablam_outlier ] # and x.feedback.c_alpha_geom_outlier] outliers_by_chain = {} for k, g in itertools.groupby(outliers_only, key=lambda x: x.residue_id()[:2]): outliers_by_chain[k] = [] comb = [] for i in g: # print i.resseq, i.resseq_as_int(), i.icode, i, i.altloc, dir(i) if i.altloc.strip() != '': print >> self.log, " ", i, "<--- SKIPPING, alternative conformations." continue if len(comb) == 0: comb = [i] else: if (i.resseq_as_int() - comb[-1].resseq_as_int() == 1 or (i.resseq_as_int() == comb[-1].resseq_as_int() and i.icode != comb[-1].icode)): comb.append(i) else: outliers_by_chain[k].append(comb) comb = [i] print >> self.log, " ", i outliers_by_chain[k].append(comb) # here we want to combine them if they are next to each other. # probably will go with list of tuples return outliers_by_chain
def find_sec_str(self, pdb_hierarchy): if (pdb_hierarchy.atoms_size() > 99999 and self.params.secondary_structure.protein.search_method == "ksdssp"): print >> self.log, "Warning!!! ksdssp method is not applicable for" + \ "structures with more than 99999 atoms!\nSwitching to from_ca." self.params.secondary_structure.protein.search_method = "from_ca" if self.params.secondary_structure.protein.search_method == "ksdssp": pdb_str = pdb_hierarchy.as_pdb_string() print >> self.log, " running ksdssp..." (records, stderr) = run_ksdssp_direct(pdb_str) return iotbx.pdb.secondary_structure.annotation.from_records( records=records, log=self.log) elif self.params.secondary_structure.protein.search_method == "mmtbx_dssp": from mmtbx.secondary_structure import dssp print >> self.log, " running mmtbx.dssp..." return dssp.dssp(pdb_hierarchy=pdb_hierarchy, pdb_atoms=self.pdb_atoms, out=null_out()).get_annotation() elif self.params.secondary_structure.protein.search_method == "from_ca": from mmtbx.secondary_structure import find_ss_from_ca print >> self.log, " running find_ss_from_ca..." fss = find_ss_from_ca.find_secondary_structure( hierarchy=pdb_hierarchy, out=null_out()) return fss.get_annotation() elif self.params.secondary_structure.protein.search_method == "cablam": from mmtbx.validation import cablam print >> self.log, " running cablam..." cablam_results = cablam.cablamalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False, out=null_out(), quiet=False) return cablam_results.as_secondary_structure() else: print >> self.log, " WARNING: Unknown search method for SS. No SS found." return iotbx.pdb.secondary_structure.annotation.from_records()
def run(self): hierarchy = self.data_manager.get_model().get_hierarchy() cablam = cablamalyze(pdb_hierarchy=hierarchy, outliers_only=self.params.outliers_only, out=self.logger, quiet=False) #output_type = *text kin full_kin points_kin records records_and_pdb oneline if self.params.output_type == 'oneline': pdb_file_str = os.path.basename( self.data_manager.get_model_names()[0]) cablam.as_oneline(pdbid=pdb_file_str) elif self.params.output_type == 'kin': cablam.as_kinemage() elif self.params.output_type == 'full_kin': cablam.as_full_kinemage(pdbid=pdbid) elif self.params.output_type == 'points_kin': cablam.as_pointcloud_kinemage() elif self.params.output_type == 'records': cablam.as_records() elif self.params.output_type == 'records_and_pdb': cablam.as_records_and_pdb() else: #default text output cablam.as_text(outliers_only=self.params.outliers_only)
def run_cablam(self) : from mmtbx.validation import cablam cablam_result = cablam.cablamalyze( pdb_hierarchy = self.hierarchy, outliers_only = False, out = sys.stdout, quiet = False) t = True for result in cablam_result.results : resd = mdb_utils.get_resd(self.pdb_code,result) MDBRes = mdb_utils.MDBResidue(**resd) reskey = MDBRes.get_residue_key() if not result.prevres : continue if reskey in self.residues.keys() : self.residues[reskey].add_cablam_result(result) elif MDBRes.altloc != '' : # alts exist in reskey but the actual residue has no alt #assert MDBRes.altloc != '','"%s"' % MDBRes.altloc newkey = MDBRes.get_residue_key(no_alt=True) if newkey not in self.residues.keys() : print >> sys.stderr, 'WARNING : trouble finding %s' % reskey else : #print ' ' + newkey,newkey in self.residues.keys() cal = result.altloc result.altloc = ' ' self.residues[newkey].add_cablam_result(result,cablam_altloc=cal) else : # Side chain has alternates but bb does not. for l in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' : newkey = MDBRes.get_residue_key(assign_alt=l) if newkey in self.residues.keys() : result.altloc = l self.residues[newkey].add_cablam_result(result) newkey = MDBRes.get_residue_key(assign_alt=l.lower()) if newkey in self.residues.keys() : result.altloc = l.lower() result.altloc = self.residues[newkey].add_cablam_result(result)
def __init__( self, pdb_hierarchy, molprobity_scores=False, ): """ This class is being pickled. Try not to introduce huge members, e.g. self.hierarchy, etc. This is the reason ramalyze_obj, rotalyze_obj etc are not members of the class (not self.ramalyze_obj). """ self.clashscore = None self.ramachandran_outliers = None self.ramachandran_allowed = None self.ramachandran_favored = None self.rotamer_outliers = None self.c_beta_dev = None self.mpscore = None self.omglz = None self.n_cis_proline = None self.n_cis_general = None self.n_twisted_proline = None self.n_twisted_general = None if(molprobity_scores): ramalyze_obj = ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) self.ramachandran_outliers = ramalyze_obj.percent_outliers self.ramachandran_outliers_cf = ramalyze_obj.get_outliers_count_and_fraction() self.ramachandran_allowed = ramalyze_obj.percent_allowed self.ramachandran_allowed_cf = ramalyze_obj.get_allowed_count_and_fraction() self.ramachandran_favored = ramalyze_obj.percent_favored self.ramachandran_favored_cf = ramalyze_obj.get_favored_count_and_fraction() rotalyze_obj = rotalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) self.rotamer_outliers = rotalyze_obj.percent_outliers self.rotamer_cf = rotalyze_obj.get_outliers_count_and_fraction() cbetadev_obj = cbetadev( pdb_hierarchy = pdb_hierarchy, outliers_only = True, out = null_out()) self.c_beta_dev = cbetadev_obj.get_outlier_count() self.c_beta_dev_percent = cbetadev_obj.get_weighted_outlier_percent() self.clashscore = clashscore(pdb_hierarchy=pdb_hierarchy).get_clashscore() self.mpscore = molprobity_score( clashscore = self.clashscore, rota_out = self.rotamer_outliers, rama_fav = self.ramachandran_favored) omglz = omegalyze.omegalyze( pdb_hierarchy=pdb_hierarchy, quiet=True) self.n_proline = omglz.n_proline() self.n_general = omglz.n_general() self.n_cis_proline = omglz.n_cis_proline() self.n_cis_general = omglz.n_cis_general() self.n_twisted_proline = omglz.n_twisted_proline() self.n_twisted_general = omglz.n_twisted_general() self.cis_general = 0 self.twisted_general = 0 self.cis_proline = 0 self.twisted_proline = 0 if self.n_proline != 0: self.cis_proline = self.n_cis_proline*100./self.n_proline self.twisted_proline = self.n_twisted_proline*100./self.n_proline if self.n_general != 0: self.cis_general = self.n_cis_general*100./self.n_general self.twisted_general = self.n_twisted_general*100./self.n_general self.cablam_outliers=None self.cablam_disfavored=None self.cablam_ca_outliers=None try: cablam_results = cablam.cablamalyze(pdb_hierarchy, outliers_only=False, out=null_out(), quiet=True) self.cablam_outliers = cablam_results.percent_outliers() self.cablam_disfavored = cablam_results.percent_disfavored() self.cablam_ca_outliers = cablam_results.percent_ca_outliers() except Exception as e: print "CaBLAM failed with exception:" print " %s" % str(e) pass