#! /usr/bin/env ccp4-python # # Copyright (C) 2005 Ronan Keegan # # This code is distributed under the terms and conditions of the # CCP4 Program Suite Licence Agreement as a CCP4 Application. # A copy of the CCP4 licence can be obtained by writing to the # CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK. # # An MrBUMP wrapper for running Phaser jobs # Ronan Keegan - 8/03/06 # import os, sys, string import shutil import phaserEXE, refmacEXE, pdbtools import Cluster_Submit import convert_SG import Matches import MRBUMP_Shelxe import MRBUMP_Buccaneer import MRBUMP_ARPwARP import MRBUMP_phs2mtz import parse_buccaneer import parse_shelxe import parse_arpwarp class Phaser: """ A class to submit Phaser jobs to the local machine or a batch system on a cluster. """ def __init__(self): self.logfile = "" if os.name=="nt": self.phaserEXE = os.path.join(os.environ["CCP4_BIN"], "phaser.exe") self.pdbcurEXE = os.path.join(os.environ["CCP4_BIN"], "pdbcur.exe") self.refmacEXE = os.path.join(os.environ["CCP4_BIN"], "refmac5.exe") else: self.phaserEXE = os.path.join(os.environ["CCP4_BIN"], "phaser") self.pdbcurEXE = os.path.join(os.environ["CCP4_BIN"], "pdbcur") self.refmacEXE = os.path.join(os.environ["CCP4_BIN"], "refmac5") # The cluster_run.py script is called as an executable if submitting to a cluster self.clusterEXE = os.path.join(os.environ["MRBUMP_CLUSTBIN"], "cluster_run.py") self.DB_fail=False try: self.debug=eval(os.environ['MRBUMP_DEBUG']) except: self.debug=False def setLogfile(self, filename): self.logfile=filename def setPhaserKeywords(self, init, model, target_info): """ Setup the phaser keywords """ # Set the keywords model.phaser_keywords.append("MODE MR_AUTO") model.phaser_keywords.append("HKLIN %s" % target_info.hklin) model.phaser_keywords.append("LABIN F=" + target_info.mtz_coldata['F'] + " SIGF=" + target_info.mtz_coldata['SIGF']) model.phaser_keywords.append("COMPosition PROTein MW %.3f NUM %d" \ % (target_info.mol_weight, int(target_info.no_of_mols))) # Set up the ensemble details ensm_line = 'autoMR ' for i in range(model.num_per_ensem): if len(model.rms) > 0 and model.rms[i] != 0.0: ensm_line += 'PDBFile ' + model.PDBfile[i] + ' RMS %.3f ' % model.rms[i] else: ensm_line += 'PDBFile ' + model.PDBfile[i] + ' IDENtity %.3f ' % model.seqID[i] model.phaser_keywords.append("ENSEmble %s" % ensm_line) # Set the search line. The number to look for should depend on wheter or not fixed components were used if model.COPIES_SET: model.phaser_keywords.append("SEARCH ENSEmble autoMR NUM %d" % model.no_copies ) else: model.phaser_keywords.append("SEARCH ENSEmble autoMR NUM " + `target_info.no_of_mols/model.number_mols`) model.phaser_keywords.append("XYZOUT ON") if init.keywords.CLUSTER: model.phaser_keywords.append("JOBS 1") else: if init.keywords.PJOBS != None: model.phaser_keywords.append("JOBS %d" % int(init.keywords.PJOBS)) # If we have a newer version of Phaser (>= version 2.2.4 we use the new keywords) if init.phaserVersion >= 224: if init.keywords.PACK != None: if init.keywords.NMASU == None: model.phaser_keywords.append("PACK CUTOFF %d" % int(init.keywords.PACK)) else: model.phaser_keywords.append("PACK CUTOFF %d" % (int(init.keywords.PACK)*int(init.keywords.NMASU))) if init.keywords.FIXSG: model.phaser_keywords.append("SGALTERNATIVE SELECT NONE") else: if init.keywords.PACK != None: if init.keywords.NMASU == None: model.phaser_keywords.append("PACK %d" % int(init.keywords.PACK)) else: model.phaser_keywords.append("PACK %d" % (int(init.keywords.PACK)*int(init.keywords.NMASU))) #model.phaser_keywords.append("ROOT %s" % os.path.join(model.model_directory,'mr','phaser','phaser_' + model.name)) model.phaser_keywords.append("ROOT phaser_" + model.name) # If fixed components of the solution where provided we need to add these to the input to phaser if init.keywords.FIXED: for i in init.keywords.fixed_list.keys(): model.phaser_keywords.append("COMPosition PROTein MW %.3f NUM 1" \ % init.keywords.fixed_list[i].mol_weight) model.phaser_keywords.append("ENSEmble fixedMR_%d PDBFile %s IDENtity %.3f" \ % (i, init.keywords.fixed_list[i].filename, init.keywords.fixed_list[i].identity)) model.phaser_keywords.append("SOLU Set") model.phaser_keywords.append("SOLU 6DIM ENSE fixedMR_%d EULER %.3f %.3f %.3f FRAC %.3f %.3f %.3f" \ % (i, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)) # If we are looking in enantiomorphic SG set the keyword if init.phaserVersion >= 224: if init.keywords.SGALL: model.phaser_keywords.append("SGALTERNATIVE SELECT ALL") elif init.keywords.ENANT: model.phaser_keywords.append("SGALTERNATIVE SELECT HAND") else: if init.keywords.SGALL: model.phaser_keywords.append("SGALTERNATIVE ALL") elif init.keywords.ENANT: model.phaser_keywords.append("SGALTERNATIVE HAND") # Add any generic keyword lines specified by the user if init.keywords.PKEYWORD != []: for keyword in init.keywords.PKEYWORD: model.phaser_keywords.append(keyword) # Get Phaser to be more verbose if we are debugging if self.debug: model.phaser_keywords.append("VERBOSE ON") def setRefmacRBKeywords(self, init, model, target_info): """ Setup the refmac rigid body keywords """ # Setup the refmac keywords Dictionary model.refmacRB_phaser_keywords["LABIN"]="FP=" + target_info.mtz_coldata['F'] \ + " SIGFP=" + target_info.mtz_coldata['SIGF'] \ + " FREE=" + target_info.mtz_coldata['FREE'] model.refmacRB_phaser_keywords["RIGID NCYCLE"]=`init.keywords.RBNC` model.refmacRB_phaser_keywords["REFI"]="TYPE RIGID RESI MLKF METH CGMAT BREF OVER" model.refmacRB_phaser_keywords["MAKE"]="HYDR N" model.refmacRB_phaser_keywords["WEIGHT"]="MATRIX 0.01" # Add the TWIN keyword if specified if init.keywords.REFTWIN: model.refmacRB_phaser_keywords["TWIN"]="" def setRefmacKeywords(self, init, model, target_info): """ Setup the refmac keywords """ # Setup the refmac keywords Dictionary model.refmac_phaser_keywords["LABIN"]="FP=" + target_info.mtz_coldata['F'] \ + " SIGFP=" + target_info.mtz_coldata['SIGF'] \ + " FREE=" + target_info.mtz_coldata['FREE'] model.refmac_phaser_keywords["NCYC"]=`init.keywords.NCYC` model.refmac_phaser_keywords["MAKE"]="HYDR N" model.refmac_phaser_keywords["WEIGHT"]="MATRIX 0.01" # Add Jelly Body refinement if required if init.keywords.JBODREF: model.refmac_phaser_keywords["RIDG"]="DIST SIGM 0.02" # Add the TWIN keyword if specified if init.keywords.REFTWIN: model.refmac_phaser_keywords["TWIN"]="" def shelxe_trace(self, init, mstat, model, target_info): shelxe_job = MRBUMP_Shelxe.Shelxe() # Set the log file and the working directory for the SHELXE run shelxe_job.setShelxeLogFile(os.path.join(model.model_directory, "mr", "phaser", "build", "shelxe", "shelxe_run.log")) shelxe_job.setShelxWorkingDIR(os.path.join(model.model_directory, "mr", "phaser", "build", "shelxe")) # Set the correct input model and mtz files shelxe_PDBINfile = model.refmac_phaser_PDBfile shelxe_MTZINfile = model.refmac_phaser_MTZINfile # Run SHELXE to do phase improvement and a c-alpha trace # Build up list of argument and keyword arguments shelxe_args = [ target_info.solvent, target_info.resolution, "PHASER", shelxe_PDBINfile, shelxe_MTZINfile ] shelxe_kwargs = { 'pdboutFile' : model.shelxe_phaser_PDBfile, 'phsoutFile' : model.shelxe_phaser_PHSfile, 'traceCycles' : init.keywords.SCYCLES, 'fp' : target_info.mtz_coldata['F'], 'sigfp' : target_info.mtz_coldata['SIGF'], 'free' : target_info.mtz_coldata['FREE'], 'shelxeEXE' : init.keywords.SHLXEXE } if not init.keywords.PDBNATIVE is None: shelxe_kwargs['native'] = init.keywords.PDBNATIVE shelxe_job.runShelxe(*shelxe_args, **shelxe_kwargs) # Convert the phs file to an mtz if os.path.isfile(model.shelxe_phaser_PHSfile) and os.path.isfile(model.shelxe_phaser_PDBfile): p2m = MRBUMP_phs2mtz.PHS2MTZ() p2m.phs2mtz(model.shelxe_phaser_PHSfile, model.shelxe_phaser_PDBfile, model.shelxe_phaser_MTZfile, shelxe_job.workingDIR, hklref=target_info.hklin, f=target_info.mtz_coldata['F'], sigf=target_info.mtz_coldata['SIGF'], freeLabel=target_info.mtz_coldata['FREE'], resolution=target_info.resolution, debug=self.debug) else: sys.stdout.write("%s: warning: no PHS file found for SHELXE (after phaser):\n %s" % (model.name, model.shelxe_phaser_PHSfile)) # Set the SHELXE CC value and average chain length for partial model shelxe_job.parseLog() cc = shelxe_job.resultsDict['SHELXE_CC'] acl = shelxe_job.resultsDict['SHELXE_ACL'] if cc and acl: # Only set if found as are initialised to 0.0 model.shelxe_phaser_CCscore = cc model.shelxe_phaser_AvgChainLen = acl mstat.results_dict[model.name]["PHASER"]["SHELXE_CC"] = cc mstat.results_dict[model.name]["PHASER"]["SHELXE_ACL"] = acl mstat.results_dict[model.name]["PHASER"]["SHELXE_MCL"] = shelxe_job.resultsDict['SHELXE_MCL'] mstat.results_dict[model.name]["PHASER"]["SHELXE_NC"] = shelxe_job.resultsDict['SHELXE_NC'] mstat.results_dict[model.name]["PHASER"]["SHELXE_time"] = shelxe_job.resultsDict['SHELXE_time'] mstat.results_dict[model.name]["PHASER"]["SHELXE_version"] = shelxe_job.resultsDict['SHELXE_version'] mstat.results_dict[model.name]["PHASER"]["SHELXE_wMPE"] = shelxe_job.resultsDict['SHELXE_wMPE'] mstat.results_dict[model.name]["PHASER"]["SHELXE_os"] = shelxe_job.resultsDict['SHELXE_os'] #sys.stdout.write("%s: warning: no log file found for SHELXE (after phaser):\n %s" % (model.name, model.shelxe_phaser_logfile)) return shelxe_job def rebuild_buccaneer(self, init, mstat, model, target_info, rebuild_dir, refmacSX_MTZout, refmacSX_PDBout): # Run Buccaneer to build on the refined SHELXE trace buccaneerSX = MRBUMP_Buccaneer.Buccaneer() os.mkdir(os.path.join(rebuild_dir, "buccaneer")) # Set the output MTZ and PDB file from Buccaneer model.buccSHELXE_phaser_PDBfile = os.path.join(rebuild_dir, "buccaneer", "buccSX_output.pdb") model.buccSHELXE_phaser_MTZfile = os.path.join(rebuild_dir, "buccaneer", "buccaneer_pipeline", "refine.mtz") buccSHELXE_phaser_logfile = os.path.join(rebuild_dir, "buccaneer", "buccaneer.log") # Run Buccaneer if init.keywords.USEPHS: buccaneerSX.runBuccaneer(init.seqin, model.shelxe_phaser_MTZfile, model.buccSHELXE_phaser_PDBfile, os.path.join(rebuild_dir, "buccaneer"), 'F', 'SIGF', target_info.mtz_coldata['FREE'], "PHI_SHELXE", "FOM_SHELXE", cycles=5, pdbinFile=model.shelxe_phaser_PDBfile, WEB_PATH_START=init.WEB_PATH_START) else: buccaneerSX.runBuccaneer(init.seqin, refmacSX_MTZout, model.buccSHELXE_phaser_PDBfile, os.path.join(rebuild_dir, "buccaneer"), target_info.mtz_coldata['F'], target_info.mtz_coldata['SIGF'], target_info.mtz_coldata['FREE'], "PHIC", "FOM", "FWT", "PHWT", cycles=5, pdbinFile=refmacSX_PDBout, WEB_PATH_START=init.WEB_PATH_START) # Add the bits to the results dictionary mstat.results_dict[model.name]["PHASER"]["SXRBUCC_pdbout"] = model.buccSHELXE_phaser_PDBfile mstat.results_dict[model.name]["PHASER"]["SXRBUCC_mtzout"] = model.buccSHELXE_phaser_MTZfile if os.path.isfile(buccSHELXE_phaser_logfile): mstat.results_dict[model.name]["PHASER"]["SXRBUCC_logfile"] = buccSHELXE_phaser_logfile bp = parse_buccaneer.BuccaneerLogParser(buccSHELXE_phaser_logfile) mstat.results_dict[model.name]["PHASER"]["SXRBUCC_version"] = bp.version mstat.results_dict[model.name]["PHASER"]["SXRBUCC_final_Rfact"] = bp.finalRfact mstat.results_dict[model.name]["PHASER"]["SXRBUCC_final_Rfree"] = bp.finalRfree return def rebuild_arpwarp(self, init, mstat, model, target_info, rebuild_dir, refmacSX_MTZout, refmacSX_PDBout): # Run ARP/wARP to build on the refined SHELXE trace arpwarpSX = MRBUMP_ARPwARP.Arpwarp() os.mkdir(os.path.join(rebuild_dir, "arpwarp")) # Set the output MTZ and PDB file from ARP/wARP if init.keywords.USEPHS: model.arpSHELXE_phaser_PDBfile = os.path.join(rebuild_dir, "arpwarp", "%s_warpNtrace.pdb" % os.path.splitext(os.path.split(model.shelxe_phaser_MTZfile)[1])[0]) model.arpSHELXE_phaser_MTZfile = os.path.join(rebuild_dir, "arpwarp", "%s_warpNtrace.mtz" % os.path.splitext(os.path.split(model.shelxe_phaser_MTZfile)[1])[0]) else: model.arpSHELXE_phaser_PDBfile = os.path.join(rebuild_dir, "arpwarp", "refmacSX_output_warpNtrace.pdb") model.arpSHELXE_phaser_MTZfile = os.path.join(rebuild_dir, "arpwarp", "refmacSX_output_warpNtrace.mtz") arpSHELXE_phaser_logfile = os.path.join(rebuild_dir, "arpwarp", "arpwarp.log") # Set the number of residues in the asu noResiduesASU = target_info.no_of_res * target_info.no_of_mols # Run ARP/wARP if init.keywords.USEPHS: arpwarpSX.runARPwARP(init.seqin, model.shelxe_phaser_MTZfile, os.path.join(rebuild_dir, "arpwarp"), 'F', 'SIGF', target_info.mtz_coldata['FREE'], "PHI_SHELXE", "FOM_SHELXE", noResiduesASU, cycles=5, pdbinFile=model.shelxe_phaser_PDBfile) else: arpwarpSX.runARPwARP(init.seqin, refmacSX_MTZout, os.path.join(rebuild_dir, "arpwarp"), target_info.mtz_coldata['F'], target_info.mtz_coldata['SIGF'], target_info.mtz_coldata['FREE'], "PHIC", "FOM", noResiduesASU, cycles=5, pdbinFile=refmacSX_PDBout) # Add the bits to the results dictionary mstat.results_dict[model.name]["PHASER"]["SXRARP_pdbout"] = model.arpSHELXE_phaser_PDBfile mstat.results_dict[model.name]["PHASER"]["SXRARP_mtzout"] = model.arpSHELXE_phaser_MTZfile if os.path.isfile(arpSHELXE_phaser_logfile): mstat.results_dict[model.name]["PHASER"]["SXRARP_logfile"] = arpSHELXE_phaser_logfile ap = parse_arpwarp.ArpwarpLogParser(arpSHELXE_phaser_logfile) mstat.results_dict[model.name]["PHASER"]["SXRARP_version"] = ap.version mstat.results_dict[model.name]["PHASER"]["SXRARP_final_Rfact"] = ap.finalRfact mstat.results_dict[model.name]["PHASER"]["SXRARP_final_Rfree"] = ap.finalRfree return def submit_serial(self, init, mstat, model, target_info): #=================================================================================# #================== Run MR and refinement on the local machine ===================# #=================================================================================# ############################################################################### ############################# Running Phaser ################################## ############################################################################### phaser_job = phaserEXE.PhaserEXE() # Setup the keywords for the job self.setPhaserKeywords(init, model, target_info) # Add the keywords for keyword in model.phaser_keywords: phaser_job.add_keyword(keyword + "\n") phaser_job.add_keyword("END\n") # Set the Phaser script file model.setPhaserScriptFile(os.path.join(model.model_directory, 'mr', 'phaser', 'phaser_script_job.sh')) # Run Phaser if init.keywords.MRSOL == "": phaser_job.run(os.path.join(model.model_directory, "mr", "phaser"), model.phaser_MTZfile, model.phaser_PDBfile, model.phaser_logfile, script=model.phaser_scriptfile, LITE=init.keywords.LITE, KILLPHASER=init.keywords.KPHASER, KILLTIME=init.keywords.KTIME, WEB_PATH_START=init.WEB_PATH_START) # Check the spacegroup of the Phaser solution phaser_job.check_SG(model.phaser_MTZfile) # Delete the output MTZ from phaser (not needed beyond here) #if init.keywords.LITE and init.keywords.USECPIRATE == False: # os.remove(model.phaser_MTZfile) # Record the Phaser solution Space Group (important for accessing the Phaser log file) convert = convert_SG.Convert() model.setPhaserSolnSG(convert.xHMtoOld(phaser_job.soln_spacegroup)) else: shutil.copyfile(init.keywords.MRSOL, os.path.join(model.model_directory, 'mr', 'phaser', 'phaser_' + model.name + '.1.pdb')) model.setRefmacPhaserMTZINfile(target_info.hklin) phaser_job.soln_found = True if init.keywords.RBODREF: model.setRefmacRBPhaserMTZINfile(target_info.hklin) model.enant_solution = False # Report the spacegroup of the solution and setup the input MTZ file for refinement # If MRSOL is set and we skipped Phaser.... if not phaser_job.soln_found: sys.stdout.write("MR log: No phaser solution produced for model %s\n" % model.name) sys.stdout.write("\n") return sys.stdout.write("MR log: Spacegroup of solution from Phaser is: %s\n" % model.phaser_soln_spacegroup) if string.strip(model.phaser_soln_spacegroup).replace(" ", "").lower() == string.strip(target_info.space_group).replace(" ", "").lower(): sys.stdout.write(" - this is the spacegroup of the input target MTZ file\n") # Copy the input MTZ file to the MTZ file to be processed in refinement model.setRefmacPhaserMTZINfile(target_info.hklin) if init.keywords.RBODREF: model.setRefmacRBPhaserMTZINfile(target_info.hklin) #shutil.copyfile(target_info.hklin, model.refmac_phaser_MTZINfile) model.enant_solution = False elif init.keywords.ENANT and not init.keywords.SGALL: sys.stdout.write(" - this is the enantiomorphic spacegroup of the target data\n") # Copy the reindexed input MTZ file to the MTZ file to be processed in refinement model.setRefmacPhaserMTZINfile(target_info.enant_hklin) if init.keywords.RBODREF: model.setRefmacRBPhaserMTZINfile(target_info.enant_hklin) #shutil.copyfile(target_info.enant_hklin, model.refmac_phaser_MTZINfile) model.enant_solution = True else: model.setRefmacPhaserMTZINfile(target_info.hklin) if init.keywords.RBODREF: model.setRefmacRBPhaserMTZINfile(target_info.hklin) #shutil.copyfile(target_info.hklin, model.refmac_phaser_MTZINfile) model.enant_solution = False # Copy the input MTZ file to the MTZ file to be processed in refinement sys.stdout.write("\n") ############################################################################### ######################### Extracting PDB details ############################## ############################################################################### # Get the number of molecules found details = pdbtools.Get_PDB_Details() details.get_details(model.phaser_PDBfile) model.num_models_found = details.mol_count # second number should be consistent with SEARCH keyword used if model.COPIES_SET: if init.keywords.FIXED: sys.stdout.write("MR log: Molecular replacement (using Phaser) found %d molecule(s) out of %d requested and %d fixed.\n" % (details.mol_count, model.no_copies, init.keywords.fixedfile_count)) else: sys.stdout.write("MR log: Molecular replacement (using Phaser) found %d molecule(s) out of %d requested.\n" % (details.mol_count, model.no_copies)) elif init.keywords.FIXED: sys.stdout.write("MR log: Molecular replacement (using Phaser) found %d molecule(s) out of %d requested and %d fixed.\n" % (details.mol_count, target_info.no_of_mols / model.number_mols, init.keywords.fixedfile_count)) else: sys.stdout.write("MR log: Molecular replacement (using Phaser) found %d molecule(s) out of %d requested.\n" % (details.mol_count, target_info.no_of_mols / model.number_mols)) sys.stdout.write("\n") if init.keywords.RBODREF: ############################################################################### ########################### Running Refmac RB ################################# ############################################################################### # Now do the refinement by calling Refmac refmacRB_job = refmacEXE.RefmacEXE() # Set the refmac keywords self.setRefmacRBKeywords(init, model, target_info) # Add them to the refmac input for keyword in model.refmacRB_phaser_keywords.keys(): refmacRB_job.add_keyword(keyword + " " + model.refmacRB_phaser_keywords[keyword]) refmacRB_job.add_keyword('END') # Run refmac Rigid Body refmacRB_job.run(model.refmac_phaser_MTZINfile, model.refmacRB_phaser_MTZOUTfile, model.phaser_PDBfile, model.refmacRB_phaser_PDBfile, model.refmacRB_phaser_logfile, "Rigid Body", refineDir=os.path.join(model.model_directory, "mr", "phaser", "refine"), script=os.path.join(model.model_directory, "mr", "phaser", "refine", "refmacRB_phaser_run_script.sh"), LITE=init.keywords.LITE, WEB_PATH_START=init.WEB_PATH_START) ############################################################################### ############################# Running Refmac ################################## ############################################################################### # Now do the refinement by calling Refmac refmac_job = refmacEXE.RefmacEXE() # Set the refmac keywords self.setRefmacKeywords(init, model, target_info) # Add them to the refmac input for keyword in model.refmac_phaser_keywords.keys(): refmac_job.add_keyword(keyword + " " + model.refmac_phaser_keywords[keyword]) refmac_job.add_keyword('END') # Set the refmac PDB file depending on whether or not we have used rigid body refinement if init.keywords.RBODREF: refmac_PDBINfile = model.refmacRB_phaser_PDBfile else: refmac_PDBINfile = model.phaser_PDBfile # Set the refinement type string if init.keywords.JBODREF: refineType = "Restrained Refinement with Jelly Body" else: refineType = "Restrained Refinement" # Run refmac refmac_job.run(model.refmac_phaser_MTZINfile, model.refmac_phaser_MTZOUTfile, refmac_PDBINfile, model.refmac_phaser_PDBfile, model.refmac_phaser_logfile, refineType, refineDir=os.path.join(model.model_directory, "mr", "phaser", "refine"), script=os.path.join(model.model_directory, "mr", "phaser", "refine", "refmac_phaser_run_script.sh"), LITE=init.keywords.LITE, WEB_PATH_START=init.WEB_PATH_START) # Bail here as we can't do anything else if refmac didn't complete if not os.path.isfile(model.refmac_phaser_PDBfile): sys.stdout.write("Error: Could not find output PDB from Refmac, can't continue\n") sys.stdout.write("\n") return # Model Building with Buccaneer if init.keywords.BUCCANEER: buccaneer_job = MRBUMP_Buccaneer.Buccaneer() buccaneer_job.setBuccScriptFile(os.path.join(model.model_directory, "mr", "phaser", "build", "buccaneer", "buccaneer_run_script.sh")) buccaneer_job.setBuccLogFile(os.path.join(model.model_directory, "mr", "phaser", "build", "buccaneer", "buccaneer_run.log")) # Set the correct input sequence file and mtz file and output pdb file buccaneer_SEQfile = init.seqin buccaneer_MTZINfile = model.refmac_phaser_MTZOUTfile buccaneer_PDBOUTfile = model.buccaneer_phaser_PDBOUTfile buccaneer_job.runBuccaneer(buccaneer_SEQfile, buccaneer_MTZINfile, buccaneer_PDBOUTfile, model.buccaneer_phaser_directory, target_info.mtz_coldata['F'], target_info.mtz_coldata['SIGF'], target_info.mtz_coldata['FREE'], "PHIC", "FOM", "FWT", "PHWT", init.keywords.BCYCLES, WEB_PATH_START=init.WEB_PATH_START) # Set the Buccaneer results model.buccaneer_phaser_completeness = buccaneer_job.completeness model.buccaneer_phaser_res_built = buccaneer_job.res_built model.buccaneer_phaser_initRfact = buccaneer_job.initRfact model.buccaneer_phaser_finalRfact = buccaneer_job.finalRfact model.buccaneer_phaser_initRfree = buccaneer_job.initRfree model.buccaneer_phaser_finalRfree = buccaneer_job.finalRfree # Model building with ARP/wARP if init.keywords.ARPWARP: arpwarp_job = MRBUMP_ARPwARP.Arpwarp() arpwarp_job.setArpwarpLogFile(os.path.join(model.model_directory, "mr", "phaser", "build", "arpwarp", "arpwarp_run.log")) model.arpwarp_phaser_directory = os.path.join(model.model_directory, "mr", "phaser", "build", "arpwarp") noResiduesASU = target_info.no_of_res * target_info.no_of_mols # Set the correct input model and mtz files arpwarp_MTZINfile = model.refmac_phaser_MTZOUTfile arpwarp_job.runARPwARP(init.pirin, arpwarp_MTZINfile, model.arpwarp_phaser_directory, target_info.mtz_coldata['F'], target_info.mtz_coldata['SIGF'], target_info.mtz_coldata['FREE'], "PHIC", "FOM", noResiduesASU, cycles=init.keywords.ACYCLES) # Set the ARPWARP output values model.arpwarp_phaser_res_built = arpwarp_job.res_built model.arpwarp_phaser_initRfact = arpwarp_job.initRfact model.arpwarp_phaser_finalRfact = arpwarp_job.finalRfact model.arpwarp_phaser_initRfree = arpwarp_job.initRfree model.arpwarp_phaser_finalRfree = arpwarp_job.finalRfree # Set the output files model.arpwarp_phaser_PDBOUTfile = arpwarp_job.pdboutFile model.arpwarp_phaser_MTZOUTfile = arpwarp_job.mtzoutFile # Return here if we're not rebuilding with SHELXE if not init.keywords.SHELXE: return # C-alpha tracing with Shelxe shelxe_job = self.shelxe_trace(init, mstat, model, target_info) if not init.keywords.SXREBUILD: return # Rebuilding the shelxe trace if not os.path.isfile(model.shelxe_phaser_PDBfile) or not os.path.isfile(model.shelxe_phaser_PHSfile): sys.stdout.write("Warning: No output PDB from SHELXE, can't run SHELXE rebuild step\n") sys.stdout.write("\n") return if not shelxe_job.succeeded(): sys.stdout.write("Warning: SHELXE trace didn't pass success criteria so not continuing with rebuilding\n") sys.stdout.write("\n") return # Directory where all rebuilding is carried out rebuild_dir=os.path.join(shelxe_job.workingDIR, "rebuild") os.mkdir(rebuild_dir) # Take the SHELXE result and use it as a starting point in Buccaneer and/or ARP/wARP for building the target refmacSX_MTZout=None refmacSX_PDBout=None if not init.keywords.USEPHS: # If we are using the model file from SHELXE for phase information we need to run refmac on it # Run a round of refinement and model building with Buccaneer post SHELXE os.mkdir(os.path.join(rebuild_dir, "refine")) # Setup a Refmac run refmacSX_job = refmacEXE.RefmacEXE() # Setup the Refmac keywords refmacSX_job.add_keyword("LABIN FP=" + target_info.mtz_coldata['F'] + " SIGFP=" + target_info.mtz_coldata['SIGF'] + " FREE=" + target_info.mtz_coldata['FREE']) refmacSX_job.add_keyword('ridg DIST SIGM 0.02') refmacSX_job.add_keyword('weight auto') refmacSX_job.add_keyword('ncyc 30') refmacSX_job.add_keyword('make hydr no') refmacSX_job.add_keyword('END') # Set the output and log files for Refmac refmacSX_MTZout = os.path.join(rebuild_dir, "refine", "refmacSX_output.mtz") refmacSX_PDBout = os.path.join(rebuild_dir, "rebuild", "refine", "refmacSX_output.pdb") refmacSX_Logfile = os.path.join(rebuild_dir, "rebuild", "refine", "refmacSX.log") # Run refmac Restrained Refinement with Jelly Body refmacSX_job.run(model.refmac_phaser_MTZINfile, refmacSX_MTZout, model.shelxe_phaser_PDBfile, refmacSX_PDBout, refmacSX_Logfile, "Restrained Refinement with Jelly Body", refineDir=os.path.join(rebuild_dir, "refine"), script=os.path.join(rebuild_dir, "refine", "refmacSX_run_script.sh"), LITE=False, WEB_PATH_START=init.WEB_PATH_START) if init.keywords.SXRBUCC: self.rebuild_buccaneer(init, mstat, model, target_info, rebuild_dir, refmacSX_MTZout, refmacSX_PDBout) if init.keywords.SXRARPW: self.rebuild_arpwarp(init, mstat, model, target_info, rebuild_dir, refmacSX_MTZout, refmacSX_PDBout) return def submit_parallel(self, init, mstat, model, target_info): #=================================================================================# #============== Run MR and refinement via a batch queue on a cluster =============# #=================================================================================# # Run the job on a cluster by submitting the python script as an executable sys.stdout.write("MR log: Submitting MR and refinement jobs to cluster queue (type: %s)\n" % init.keywords.QTYPE) sys.stdout.write("\n") ############################################################################### ####################### Cluster Job Keyword Setup ############################# ############################################################################### # Write the inputs.txt file with the various parameters needed for running on a cluster node model.cluster_inputfile = os.path.join(model.model_directory, "mr", "phaser", "cluster_inputs.txt") model.setRefmacPhaserMTZINfile(target_info.hklin) cl_file = open(model.cluster_inputfile, "w") cl_file.write("DIRE " + model.model_directory + "\n") cl_file.write("SGIN " + target_info.space_group + "\n") cl_file.write("ENAN " + `init.keywords.ENANT` + "\n") cl_file.write("SGAL " + repr(init.keywords.SGALL) + "\n") cl_file.write("HKL1 " + target_info.hklin + "\n") cl_file.write("HKLR " + model.refmac_phaser_MTZINfile + "\n") cl_file.write("HKLO " + model.phaser_MTZfile + "\n") cl_file.write("PDBO " + model.phaser_PDBfile + "\n") cl_file.write("MRLO " + model.phaser_logfile + "\n") cl_file.write("REFH " + model.refmac_phaser_MTZOUTfile + "\n") cl_file.write("REFP " + model.refmac_phaser_PDBfile + "\n") cl_file.write("REFL " + model.refmac_phaser_logfile + "\n") if init.keywords.BUCCANEER: cl_file.write("BUCC True\n") cl_file.write("SEQI " + init.seqin + "\n") cl_file.write("FPIN " + target_info.mtz_coldata['F'] + "\n") cl_file.write("SIGF " + target_info.mtz_coldata['SIGF'] + "\n") cl_file.write("FREE " + target_info.mtz_coldata['FREE'] + "\n") cl_file.write("BCYC " + str(init.keywords.BCYCLES) + "\n") if init.keywords.SHELXE: cl_file.write("SHELXE True\n") if init.keywords.BUCCANEER == False: cl_file.write("FPIN " + target_info.mtz_coldata['F'] + "\n") cl_file.write("SIGF " + target_info.mtz_coldata['SIGF'] + "\n") cl_file.write("FREE " + target_info.mtz_coldata['FREE'] + "\n") cl_file.write("SOLV " + str(target_info.solvent) + "\n") cl_file.write("RESO " + str(target_info.resolution) + "\n") cl_file.write("SHLP " + model.shelxe_phaser_PDBfile + "\n") cl_file.write("SEXE " + init.keywords.SHLXEXE + "\n") cl_file.write("SCYC " + str(init.keywords.SCYCLES) + "\n") if init.keywords.RBODREF: cl_file.write("RBRH " + model.refmacRB_phaser_MTZOUTfile + "\n") cl_file.write("RBRP " + model.refmacRB_phaser_PDBfile + "\n") cl_file.write("RBRL " + model.refmacRB_phaser_logfile + "\n") if init.keywords.ENANT and not init.keywords.SGALL: cl_file.write("HKL2 " + target_info.enant_hklin + "\n") # Finally, the list of PDB input files to be passed into the MR program file_list = "" for filename in model.PDBfile: file_list = file_list + filename + " " cl_file.write("PDBI " + file_list + "\n") cl_file.close() ############################################################################### ############################## Phaser Setup ################################### ############################################################################### # Write the keywords file for the phaser job model.phaser_keyfile = os.path.join(model.model_directory, "mr", "phaser", "phaser_keywords.txt") # Setup the keywords for the job self.setPhaserKeywords(init, model, target_info) kfile = open(model.phaser_keyfile, "w") if self.debug: sys.stdout.write("DEBUG : Creating keywords file for Phaser\n Keywords:\n\n") # Add the keywords for keyword in model.phaser_keywords: if self.debug: sys.stdout.write(keyword + "\n") kfile.write(keyword + "\n") kfile.write("END\n") kfile.close() if self.debug: sys.stdout.write("\n") ############################################################################### ############################## Refmac Setup ################################### ############################################################################### ############################## # Refmac RB keywords: ############################## if init.keywords.RBODREF: # Set the refmac RB keyword file model.refmacRB_phaser_keyfile = os.path.join(model.model_directory, "mr", "phaser", "refine", "refmacRB_keywords-phaser.txt") # Set the refmac keywords self.setRefmacRBKeywords(init, model, target_info) rb_kfile = open(model.refmacRB_phaser_keyfile, "w") # Write out the Refmac keywords for keyword in model.refmacRB_phaser_keywords.keys(): rb_kfile.write(keyword + " " + model.refmacRB_phaser_keywords[keyword] + "\n") rb_kfile.write('END\n') rb_kfile.close() ########################################### # Refmac Restrained Refinement keywords: ########################################### # Set the refmac keyword file model.refmac_phaser_keyfile = os.path.join(model.model_directory, "mr", "phaser", "refine", "refmac_keywords-phaser.txt") kfile = open(model.refmac_phaser_keyfile, "w") # Set the refmac keywords self.setRefmacKeywords(init, model, target_info) # Add them to the refmac input for keyword in model.refmac_phaser_keywords.keys(): kfile.write(keyword + " " + model.refmac_phaser_keywords[keyword] + "\n") kfile.write('END\n') kfile.close() ############################################################################### ############################ Queue Submission ################################# ############################################################################### # Now setup the cluster submission script clust_sub = Cluster_Submit.Cluster_submit(init.keywords) # Set the working directory for the job clust_sub.setJobDirectory(os.path.join(model.model_directory, "mr", "phaser")) if init.keywords.RBODREF: # Set the command line for the job clust_sub.setCommandLine("ccp4-python " + self.clusterEXE + " " + model.cluster_inputfile + " " + model.phaser_keyfile + " " + model.refmacRB_phaser_keyfile + " " + model.refmac_phaser_keyfile + " phaser refmac") else: clust_sub.setCommandLine("ccp4-python " + self.clusterEXE + " " + model.cluster_inputfile + " " + model.phaser_keyfile + " " + model.refmac_phaser_keyfile + " phaser refmac") # Set the command line for the job # Set some job parameters model.phaser_jobname = "Job-Phaser-" + model.name script_name = "job_" + model.name + ".sub" logfile = "job_" + model.name + ".log" # Submit the job clust_sub.submit(init.keywords.QTYPE, model.phaser_jobname, script_name, logfile, qsub_command=init.keywords.QSUBCOM, qsub_options=init.keywords.QOPTIONS) # Note the job number and the job name model.setMR_JobID(clust_sub.job_number) mstat.jobid_array.add(model.MR_jobID) mstat.jobid_dict[model.MR_jobID] = model.phaser_jobname #mstat.jobname_dict[model.phaser_jobname]=model.name mstat.jobname_dict[model.phaser_jobname] = Matches.Job_struct() mstat.jobname_dict[model.phaser_jobname].model_name = model.name mstat.jobname_dict[model.phaser_jobname].MRPROGRAM = model.MRPROGRAM def submit_job(self, init, mstat, model, target_info): """ Function to launch a phaser/refmac5 job for a given model. """ # Check to see if the logfile has been specified, otherwise give it a default name if self.logfile=="": self.logfile=os.path.join(model.model_directory, "phaser_refmac_job.log") if not init.keywords.CLUSTER: self.submit_serial(init, mstat, model, target_info) else: self.submit_parallel(init, mstat, model, target_info)