def _showRingerResults(self, e=None): i = int(self.residue) index = int(self.dataDict['_residues_dict'][self.residueList[i]]) # emringer main file mainDataFile = glob.glob( self.protocol._getExtraPath("*_emringer.pkl"))[0] command = """from mmtbx.ringer.em_rolling import easy_pickle import matplotlib.pyplot as plt # process file '%s' file_name='%s' ringer_results = easy_pickle.load(file_name) figure = plt.figure() # (figsize=(20,1000)) def show_residue (residue, show_background_boxes=True) : subplots = [] for i in range(1, residue.n_chi + 1) : chi = residue.get_angle(i) if (chi is None) : continue if (len(subplots) > 0) : p = figure.add_subplot(4, 1, i, sharex=subplots[0]) else: p = figure.add_subplot(4, 1, i) p.set_title(residue.format()) p.set_position([0.15, 0.725 - 0.225*(i-1), 0.8, 0.225]) x = [ k*chi.sampling for k in range(len(chi.densities)) ] p.plot(x, chi.densities, 'r-', linewidth=1) if (chi.fofc_densities is not None) : p.plot(x, chi.fofc_densities, linestyle='--', color=[0.5,0.0,1.0]) p.axvline(chi.angle_current, color='b', linewidth=2, linestyle='--') p.axhline(0, color=(0.4,0.4,0.4), linestyle='--', linewidth=1) if show_background_boxes: p.axhspan(0.3,1,facecolor="green",alpha=0.5) p.axhspan(-1,0.3,facecolor="grey",alpha=0.5) p.set_xlim(0,360) p.set_ylabel("Rho") p.set_xlabel("Chi" + str(i)) subplots.append(p) plt.subplots_adjust(left = 0.18, bottom = 0.00, right = 0.94, top = 0.93, wspace = 0.80, hspace = 0.43) plt.tight_layout() plt.show() index = %d show_residue(ringer_results[index]) """ % (mainDataFile, mainDataFile, index) with open(self.EMRINGERSUBPLOTSFILENAME, "w") as f: f.write(command) # execute file with phenix.python Plugin.runPhenixProgram("", self.EMRINGERSUBPLOTSFILENAME)
def runSuperposePDBsStep(self): args = os.path.abspath(self.inputStructureFixed.get().getFileName()) args += " " args += os.path.abspath(self.inputStructureMoving.get().getFileName()) cwd = os.getcwd() + "/" + self._getExtraPath() try: Plugin.runPhenixProgram(Plugin.getProgram(SUPERPOSE), args, extraEnvDict=None, cwd=cwd) except: # This exception will run when using phenix v. 1.16 after running # real space refine the .cif file generated can not be recognized by # superpose pdbs program and an error is produced list_args = args.split() self._runChangingCifFormatSuperpose(list_args)
def _readValidationPklFile(self, fileName): self.SUMMARYFILENAME = self._getTmpPath(self.SUMMARYFILENAME) command = """import pickle import collections import json def pickleData(file): with open(file,"r") as f: return pickle.load(f) # process file {VALIDATIONCRYOEMPKLFILENAME}" data = pickleData('{VALIDATIONCRYOEMPKLFILENAME}') dictSummary = collections.OrderedDict() dictSummary['Rhama_Outliers'] = data.model.geometry.ramachandran.outliers dictSummary['Rhama_Favored'] = data.model.geometry.ramachandran.favored dictSummary['Rota_Outliers'] = data.model.geometry.rotamer.outliers dictSummary['Cbeta_Outliers_n'] = data.model.geometry.c_beta.cbetadev.n_outliers dictSummary['Clash_score'] = data.model.geometry.clash.score dictSummary['MolProbity_score'] = data.model.geometry.molprobity_score """.format(VALIDATIONCRYOEMPKLFILENAME=fileName) command += """with open('%s',"w") as f: f.write(json.dumps(dictSummary)) """ % (self.SUMMARYFILENAME) pythonFileName = self.SUMMARYFILENAME.replace('.txt', '.py') # write script file with open(pythonFileName, "w") as f: f.write(command) # execute file with phenix.python Plugin.runPhenixProgram("", pythonFileName) # read file in scipion python with open(self.SUMMARYFILENAME, "r") as f: dictSummary = f.read() dictSummary = json.loads(dictSummary, object_pairs_hook=collections.OrderedDict) self.ramachandranOutliers = Float(dictSummary['Rhama_Outliers']) self.ramachandranFavored = Float(dictSummary['Rhama_Favored']) self.rotamerOutliers = Float(dictSummary['Rota_Outliers']) self.cbetaOutliers = Integer(dictSummary['Cbeta_Outliers_n']) self.clashscore = Float(dictSummary['Clash_score']) self.overallScore = Float(dictSummary['MolProbity_score'])
def createOutputStep(self): # get emringer information # values are stored in python pickle files # string to be run by phenix python # temporary file with emringer values test = self.doTest if test == True: EMRINGERTRANSFERFILENAME = self._getExtraPath( self.EMRINGERTRANSFERFILENAME) else: EMRINGERTRANSFERFILENAME = self._getTmpPath( self.EMRINGERTRANSFERFILENAME) # directory with files plots = glob.glob(self._getExtraPath("*_plots"))[0] # emringer main file mainDataFile = glob.glob(self._getExtraPath("*_emringer.pkl"))[0] # file with emringer score EMRINGERSCORESFILENAME = os.path.join(plots, self.EMRINGERSCORESFILENAME) EMRINGERFILES = [] keyList = [] # files with other scores EMRINGEROPTIMALTHRESHOLDFILENAME = \ os.path.join(plots, self.EMRINGEROPTIMALTHRESHOLDFILENAME) EMRINGERFILES.append(EMRINGEROPTIMALTHRESHOLDFILENAME) keyList.append('Optimal Threshold') EMRINGERROTAMERRATIOSFILENAME = \ os.path.join(plots, self.EMRINGERROTAMERRATIOSFILENAME) EMRINGERFILES.append(EMRINGERROTAMERRATIOSFILENAME) keyList.append('Rotamer-Ratio') EMRINGERMAXZSCOREFILENAME = \ os.path.join(plots, self.EMRINGERMAXZSCOREFILENAME) EMRINGERFILES.append(EMRINGERMAXZSCOREFILENAME) keyList.append('Max Zscore') # I do not want to use the local pickle version # but the version used to create the files # that is the phenix.python version command = """import pickle import json import sys import collections from mmtbx.ringer.em_scoring import parse_pickle from mmtbx.ringer.em_rolling import easy_pickle, RingerDict def pickleData(file): with open(file,"r") as f: return pickle.load(f) # process file %s" data = pickleData('%s') dataDict = collections.OrderedDict() # index to maxscore maxScore = max(data) maxScoreIndex = data.index(maxScore) """ % (EMRINGERSCORESFILENAME, EMRINGERSCORESFILENAME) for key, fileName in zip(keyList, EMRINGERFILES): command += "# process file %s\n" % fileName command += "data = pickleData('%s')\n" % fileName command += "dataDict['%s'] = data[maxScoreIndex]\n" % key command += """file_name='%s' waves, thresholds = parse_pickle(file_name, out=sys.stdout) # waves: list of ringer_residue objects (Non-gamma-branched, non-proline # aminoacids with a non-H gamma atom) used in global EMRinger score # computation dataDict['Model Length'] = len(waves) dataDict['EMRinger Score'] = maxScore # find max score # dataDict is shown in a table # except for those attributes starting with "_" dataDict['_thresholds'] = thresholds dataDict['_maxScoreIndex'] = maxScoreIndex ringer_results = easy_pickle.load(file_name) # ringer_results: list of ringer_residue objects (aminoacids with gamma # carbon; at least one Chi angle) hierarchy = RingerDict(ringer_results, 0) chains = sorted(hierarchy.get_chains()) dataDict['_chains'] = chains # Aminoacids that contain non-H gamma atom (at least one Chi angle; included in # ringer_results) dictResidue = {} formatResidue = [] for residue in ringer_results: resFormatTmp = residue.format() formatResidue.append(resFormatTmp) dictResidue[resFormatTmp] = ringer_results.index(residue) dataDict['_residues_format'] = formatResidue dataDict['_residues_dict'] = dictResidue """ % mainDataFile command += """with open('%s',"w") as f: f.write(json.dumps(dataDict)) """ % (EMRINGERTRANSFERFILENAME) pythonFileName = EMRINGERTRANSFERFILENAME.replace('.txt', '.py') # write script file with open(pythonFileName, "w") as f: f.write(command) # execute file with phenix.python Plugin.runPhenixProgram("", pythonFileName) # read file in scipion python with open(EMRINGERTRANSFERFILENAME, "r") as f: self.stringDataDict = String(f.read()) # self.dataDict = json.loads(f.read()) self._store()
def _runChangingCifFormatSuperpose(self, list_args): cwd = os.getcwd() + "/" + self._getExtraPath() try: if list_args[0].endswith(".cif") and list_args[1].endswith(".cif"): try: # upgrade cifs list_args1 = [] for i in range(0, 2): list_args1.append(fromCIFTommCIF(list_args[i], list_args[i])) args1 = list_args1[0] + " " + list_args1[1] Plugin.runPhenixProgram(Plugin.getProgram(SUPERPOSE), args1, extraEnvDict=None, cwd=cwd) except: # convert cifs to pdbs list_args2 = [] for i in range(0, 2): list_args2.append(fromCIFToPDB( list_args[i], list_args[i].replace('.cif', '.pdb'))) args2 = list_args2[0] + " " + list_args2[1] Plugin.runPhenixProgram(Plugin.getProgram(SUPERPOSE), args2, extraEnvDict=None, cwd=cwd) elif list_args[0].endswith(".cif") and list_args[1].endswith(".pdb"): try: # pdbs: convert cif to pdb list_args1 = [] list_args1.append(fromCIFToPDB( list_args[0], list_args[0].replace('.cif', '.pdb'))) args1 = list_args1[0] + " " + list_args[1] Plugin.runPhenixProgram(Plugin.getProgram(SUPERPOSE), args1, extraEnvDict=None, cwd=cwd) except: try: # cifs: convert pdb to cif list_args2 = [] list_args2.append(fromPDBToCIF( list_args[1], list_args[1].replace('.pdb', '.cif'))) args2 = list_args[0] + " " + list_args2[0] Plugin.runPhenixProgram(Plugin.getProgram(SUPERPOSE), args2, extraEnvDict=None, cwd=cwd) except: # upgrade cif list_args3 = [] list_args0 = args2.split() for i in range(0, 2): list_args3[i].append(fromCIFTommCIF( list_args0[i], list_args0[i])) args3 = list_args3[0] + " " + list_args3[1] Plugin.runPhenixProgram(Plugin.getProgram(SUPERPOSE), args3, extraEnvDict=None, cwd=cwd) elif list_args[0].endswith(".pdb") and list_args[1].endswith(".cif"): try: # pdbs: convert cif to pdb list_args1 = [] list_args1.append(fromCIFToPDB( list_args[1], list_args[1].replace('.cif', '.pdb'))) args1 = list_args[0] + " " + list_args1[0] Plugin.runPhenixProgram(Plugin.getProgram(SUPERPOSE), args1, extraEnvDict=None, cwd=cwd) except: try: # cifs: convert pdb to cif list_args2 = [] list_args2.append(fromPDBToCIF( list_args[0], list_args[0].replace('.pdb', '.cif'))) args2 = list_args2[0] + " " + list_args[1] Plugin.runPhenixProgram(Plugin.getProgram(SUPERPOSE), args2, extraEnvDict=None, cwd=cwd) except: # upgrade cifs list_args3 = [] list_args0 = args2.split() for i in range(0, 2): list_args3.append(fromCIFTommCIF( list_args0[i], list_args0[i])) args3 = list_args3[0] + " " + list_args3[1] Plugin.runPhenixProgram(Plugin.getProgram(SUPERPOSE), args3, extraEnvDict=None, cwd=cwd) except: # biopython conversion aSH = AtomicStructHandler() try: for i in range(0, 2): aSH.read(list_args[i]) aSH.write(list_args[i]) args = list_args[0] + " " + list_args[1] Plugin.runPhenixProgram(Plugin.getProgram(SUPERPOSE), args, extraEnvDict=None, cwd=cwd) except: print("CIF file standarization failed.")