def start_nh(): """ Starts Nano-Hive server in the background. Returns 1 if Nano-Hive path is not set or if the path does not exist. Returns 2 if Nano-Hive config file does not exist. """ # Get Nano-Hive executable path from the prefs db. nanohive_exe = env.prefs[nanohive_path_prefs_key] if not nanohive_exe: return 1 if not os.path.exists(nanohive_exe): return 1 nanohive_config = get_nh_config_filename() if not nanohive_config: return 2 args = ["-f", nanohive_config] # print "start_nh(): args=", args from processes.Process import Process arguments = [] for arg in args: if arg != "": arguments.append(arg) nhProcess = Process() nhProcess.start(nanohive_exe, args) return 0
def start_nh(): """ Starts Nano-Hive server in the background. Returns 1 if Nano-Hive path is not set or if the path does not exist. Returns 2 if Nano-Hive config file does not exist. """ # Get Nano-Hive executable path from the prefs db. nanohive_exe = env.prefs[nanohive_path_prefs_key] if not nanohive_exe: return 1 if not os.path.exists(nanohive_exe): return 1 nanohive_config = get_nh_config_filename() if not nanohive_config: return 2 args = ['-f', nanohive_config] #print "start_nh(): args=", args from processes.Process import Process arguments = [] for arg in args: if arg != "": arguments.append(arg) nhProcess = Process() nhProcess.start(nanohive_exe, args) return 0
def verifyPluginUsingVersionFlag(plugin_path, version_flag, vstring): """ Verifies a plugin by running it with I{version_flag} as the only command line argument and matching the output to I{vstring}. @return: 0 if there is a match. Otherwise, returns 1 @rtype: int @note: This is only useful if the plug-in supports a version flag arguments. """ if not plugin_path: return 1 if not os.path.exists(plugin_path): return 1 args = [version_flag] arguments = [] for arg in args: if arg != "": arguments.append(arg) p = Process() p.start(plugin_path, arguments) if not p.waitForFinished (10000): # Wait for 10000 milliseconds = 10 seconds return 1 output = 'Not vstring' output = str(p.readAllStandardOutput()) #print "output=", output #print "vstring=", vstring if output.find(vstring) == -1: return 1 else: return 0 # Match found.
def verify_program(program, version_flag, vstring): """ Verifies a program by running it with the version_flag and matching the output to vstring. Returns 0 if there is a match. Otherwise, returns 1 """ if not program: return 1 if not os.path.exists(program): return 1 args = [version_flag] from processes.Process import Process arguments = [] for arg in args: if arg != "": arguments.append(arg) print print "arguments:", arguments p = Process() p.start(program, arguments) if not p.waitForFinished(10000): # Wait for 10000 milliseconds = 10 seconds return 1 output = "Not vstring" output = str(p.readAllStandardOutput()) # print "output=", output # print "vstring=", vstring if output.find(vstring) == -1: return 1 else: return 0 # Match found.
def verifyPluginUsingVersionFlag(plugin_path, version_flag, vstring): """ Verifies a plugin by running it with I{version_flag} as the only command line argument and matching the output to I{vstring}. @return: 0 if there is a match. Otherwise, returns 1 @rtype: int @note: This is only useful if the plug-in supports a version flag arguments. """ if not plugin_path: return 1 if not os.path.exists(plugin_path): return 1 args = [version_flag] arguments = [] for arg in args: if arg != "": arguments.append(arg) p = Process() p.start(plugin_path, arguments) if not p.waitForFinished( 10000): # Wait for 10000 milliseconds = 10 seconds return 1 output = 'Not vstring' output = str(p.readAllStandardOutput()) #print "output=", output #print "vstring=", vstring if output.find(vstring) == -1: return 1 else: return 0 # Match found.
def verify_program(program, version_flag, vstring): """ Verifies a program by running it with the version_flag and matching the output to vstring. Returns 0 if there is a match. Otherwise, returns 1 """ if not program: return 1 if not os.path.exists(program): return 1 args = [version_flag] from processes.Process import Process arguments = [] for arg in args: if arg != "": arguments.append(arg) print print "arguments:", arguments p = Process() p.start(program, arguments) if not p.waitForFinished (10000): # Wait for 10000 milliseconds = 10 seconds return 1 output = 'Not vstring' output = str(p.readAllStandardOutput()) #print "output=", output #print "vstring=", vstring if output.find(vstring) == -1: return 1 else: return 0 # Match found.
def runGNUplot(self, plotfile): """Sends plotfile to GNUplot. """ # Make sure plotfile exists if not os.path.exists(plotfile): msg = redmsg("Plotfile [" + plotfile + "] is missing. Plot aborted.") env.history.message(cmd + msg) return # filePath = the current directory NE-1 is running from. filePath = os.path.dirname(os.path.abspath(sys.argv[0])) # "program" is the full path to the GNUplot executable. if sys.platform == 'win32': program = os.path.normpath(filePath + '/../bin/wgnuplot.exe') else: program = os.path.normpath('/usr/bin/gnuplot') # Set environment variables to make gnuplot use a specific AquaTerm on # Mac. Originally "Huaicai 3/18", fixed by Brian Helfrich May 23, 2007. # if sys.platform == 'darwin': aquaPath = os.path.normpath(filePath + '/../bin/AquaTerm.app') os.environ['AQUATERM_PATH'] = aquaPath aquaPath = \ os.path.normpath(filePath + '/../Frameworks/AquaTerm.framework') os.environ['DYLD_LIBRARY_PATH'] = aquaPath # Note: I tried using: # environment.append(QString('AQUATERM_PATH=%s' % aquaPath)) # environment.append(QString('DYLD_LIBRARY_PATH=%s' % aquaPath)) # followed by plotProcess.setEnvironment(environment), but it just # wouldn't see the AquaTerm library. So, although the above is more # heavy-handed than just changing the Process environment, at least # it works. # Make sure GNUplot executable exists if not os.path.exists(program): msg = redmsg("GNUplot executable [" + program + "] is missing. Plot aborted.") env.history.message(cmd + msg) return plotProcess = None try: from processes.Process import Process plotProcess = Process() # Run gnuplot as a new, separate process. started = plotProcess.startDetached(program, QStringList(plotfile)) ###e It might also be good to pass gnuplot some arg to tell it to ignore ~/.gnuplot. [bruce 060425 guess] if not started: env.history.message(redmsg("gnuplot failed to run!")) else: env.history.message("Running gnuplot file: " + plotfile) if debug_gnuplot: try: #bruce 060425 debug code; Qt assistant for QProcess says this won't work on Windows (try it there anyway). pid = plotProcess.pid() # This should work on Windows in Qt 4.2 [mark 2007-05-03] pid = int(pid) # this is what is predicted to fail on Windows env.history.message("(debug: gnuplot is %r, its process id is %d)" % (program, pid)) except: print_compact_traceback("debug: exception printing processIdentifier (might be normal on Windows): ") pass pass except: # We had an exception. print"exception in GNUplot; continuing: " if plotProcess: print ">>> %d" % plotProcess.error() print "Killing process" plotProcess.kill() plotProcess = None
def runGNUplot(self, plotfile): """Sends plotfile to GNUplot. """ # Make sure plotfile exists if not os.path.exists(plotfile): msg = redmsg("Plotfile [" + plotfile + "] is missing. Plot aborted.") env.history.message(cmd + msg) return # filePath = the current directory NE-1 is running from. filePath = os.path.dirname(os.path.abspath(sys.argv[0])) # "program" is the full path to the GNUplot executable. if sys.platform == 'win32': program = os.path.normpath(filePath + '/../bin/wgnuplot.exe') else: program = os.path.normpath(filePath + '/../bin/gnuplot') # Set environment variables to make gnuplot use a specific AquaTerm on # Mac. Originally "Huaicai 3/18", fixed by Brian Helfrich May 23, 2007. # if sys.platform == 'darwin': aquaPath = os.path.normpath(filePath + '/../bin/AquaTerm.app') os.environ['AQUATERM_PATH'] = aquaPath aquaPath = \ os.path.normpath(filePath + '/../Frameworks/AquaTerm.framework') os.environ['DYLD_LIBRARY_PATH'] = aquaPath # Note: I tried using: # environment.append(QString('AQUATERM_PATH=%s' % aquaPath)) # environment.append(QString('DYLD_LIBRARY_PATH=%s' % aquaPath)) # followed by plotProcess.setEnvironment(environment), but it just # wouldn't see the AquaTerm library. So, although the above is more # heavy-handed than just changing the Process environment, at least # it works. # Make sure GNUplot executable exists if not os.path.exists(program): msg = redmsg("GNUplot executable [" + program + "] is missing. Plot aborted.") env.history.message(cmd + msg) return plotProcess = None try: from processes.Process import Process plotProcess = Process() # Run gnuplot as a new, separate process. started = plotProcess.startDetached(program, QStringList(plotfile)) ###e It might also be good to pass gnuplot some arg to tell it to ignore ~/.gnuplot. [bruce 060425 guess] if not started: env.history.message(redmsg("gnuplot failed to run!")) else: env.history.message("Running gnuplot file: " + plotfile) if debug_gnuplot: try: #bruce 060425 debug code; Qt assistant for QProcess says this won't work on Windows (try it there anyway). pid = plotProcess.pid() # This should work on Windows in Qt 4.2 [mark 2007-05-03] pid = int(pid) # this is what is predicted to fail on Windows env.history.message("(debug: gnuplot is %r, its process id is %d)" % (program, pid)) except: print_compact_traceback("debug: exception printing processIdentifier (might be normal on Windows): ") pass pass except: # We had an exception. print"exception in GNUplot; continuing: " if plotProcess: print ">>> %d" % plotProcess.error() print "Killing process" plotProcess.kill() plotProcess = None
def launch_qutemol(pdb_file): """ Launch and load QuteMolX with the PDB file I{pdb_file}. @param pdb_file: the PDB filename to load @type pdb_file: string @return: (errorcode, errortext) where errorcode is one of the following: ###k 0 = successful 8 = QuteMolX failed for an unknown reason. @rtype: int, text """ plugin_name = "QuteMolX" plugin_prefs_keys = (qutemol_enabled_prefs_key, qutemol_path_prefs_key) errorcode, errortext_or_path = \ checkPluginPreferences(plugin_name, plugin_prefs_keys, insure_executable = True) if errorcode: return errorcode, errortext_or_path program_path = errortext_or_path workdir, junk_exe = os.path.split(program_path) # This provides a way to tell NE1 which version of QuteMolX is installed. if debug_pref("QuteMol 0.4.1 or later", Choice_boolean_True, prefs_key = True): version = "0.4.1" else: version = "0.4.0" # Start QuteMolX. try: args = [pdb_file] if env.debug(): print "Debug: Launching", plugin_name, \ "\n working directory=", workdir, \ "\n program_path=", program_path, \ "\n args are %r" % (args,) arguments = QStringList() for arg in args: if arg != "": arguments.append(arg) p = Process() # QuteMolX must run from the directory its executable lives. Otherwise, # it has serious problems (but still runs). Mark 2007-06-02. p.setWorkingDirectory(QString(workdir)) # Tried p.startDetached() so that QuteMolX would be its own process and # continue to live even if NE1 exits. Unfortunately, # setWorkingDirectory() doesn't work. Seems like a Qt bug to me. # Mark 2007-06-02 p.start(program_path, arguments) except: print_compact_traceback( "exception in launch_qutemol(): " ) return 8, "%s failed for an unknown reason." % plugin_name # set an appropriate exitcode and msg if p.exitStatus() == QProcess.NormalExit: exitcode = p.exitStatus() if not exitcode: msg = plugin_name + " launched." else: msg = plugin_name + " had exitcode %r" % exitcode else: exitcode = p.exitStatus() exitcode = -1 msg = "Abnormal exit (or failure to launch)" if exitcode: return 8, "Error: " + msg # this breaks the convention of the other error returns return 0, plugin_name + " launched." # from launch_qutemol
def launch_povray_or_megapov( win, info, povray_ini): #bruce 060707/11 revised this extensively for Mac A8 """ Try to launch POV-Ray or MegaPOV, as specified in <info> (as returned from decode_povray_prefs, assumed already checked), on the given <povray_ini> file (which should already exist), and running in the directory of that file (this is required, since it may contain relative pathnames). <win> must be the main window object (used for .glpane.is_animating). Returns (errorcode, errortext), where errorcode is one of the following: ###k 0 = successful 8 = POV-Ray or MegaPOV failed for an unknown reason. """ (program_nickname, program_path, include_dir) = info #e rename this arg renderer_info? exit = '' program = program_path if sys.platform == 'win32': program = "\"" + program + "\"" # Double quotes needed by Windows. Mark 060602. if program_nickname == 'POV-Ray': exit = "/EXIT" # Later we'll cd to the POV-Ray's INI file directory and use tmp_ini in the POV-Ray command-line. # This helps us get around POV-Ray's I/O Restrictions. Mark 060529. workdir, tmp_ini = os.path.split(povray_ini) # Render scene. try: args = [tmp_ini] if exit: args += [exit] if env.debug(): ## use env.history.message(_graymsg(msg)) ? print "debug: Launching %s: \n" % program_nickname,\ "working directory=",workdir,"\n program_path=", program_path, "\n args are %r" % (args,) arguments = QStringList() for arg in args: if arg != "": arguments.append(arg) from processes.Process import Process p = Process() #bruce 060707: this doesn't take advantage of anything not in QProcess, # unless it matters that it reads and discards stdout/stderr # (eg so large output would not block -- unlikely that this matters). # It doesn't echo stdout/stderr. See also blabout/blaberr in other files. Maybe fix this? ###@@@ p.setWorkingDirectory(workdir) p.start(program, arguments) # Put up hourglass cursor to indicate we are busy. Restore the cursor below. Mark 060621. QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) win.glpane.is_animating = True # This disables selection [do you mean highlighting? #k] while rendering the image. import time msg = "Rendering image" while p.state() == QProcess.Running: # Display a message on the status bar that POV-Ray/MegaPOV is rendering. # I'd much rather display a progressbar and stop button by monitoring the size of the output file. # This would require the output file to be written in PPM or BMP format, but not PNG format, since # I don't believe a PNG's final filesize can be predicted. # Check out monitor_progress_by_file_growth() in runSim.py, which does this. [mark] time.sleep(0.25) env.history.statusbar_msg(msg) env.call_qApp_processEvents() if 1: # Update the statusbar message while rendering. if len( msg ) > 40: #bruce changed 100 -> 40 in case of short statusbar msg = "Rendering image" else: #msg = msg + "." msg += "." except: #bruce 060707 moved print_compact_traceback earlier, and its import to toplevel (after Windows A8, before Linux/Mac A8) print_compact_traceback("exception in launch_povray_or_megapov(): ") QApplication.restoreOverrideCursor() win.glpane.is_animating = False return 8, "%s failed for an unknown reason." % program_nickname #bruce 060707 moved the following outside the above try clause, and revised it (after Windows A8, before Linux/Mac A8) QApplication.restoreOverrideCursor() # Restore the cursor. Mark 060621. ## env.history.statusbar_msg("Rendering finished!") # this is wrong if it was not a normal exit. [bruce 060707 removed it] win.glpane.is_animating = False if 1: #bruce 060707 added this (after Windows A8, before Linux/Mac A8): # set an appropriate exitcode and msg if p.exitStatus() == QProcess.NormalExit: exitcode = p.exitStatus() if not exitcode: msg = "Rendering finished!" else: msg = "Rendering program had exitcode %r" % exitcode # e.g. 126 for Mac failure; same as shell exitcode, which says "cannot execute binary file"; # but /usr/bin/open helps, so we'll try that above (but not in this commit, which is just to # improve error reporting). ###@@@ # [bruce 060707] else: exitcode = p.exitStatus() exitcode = -1 msg = "Abnormal exit (or failure to launch)" if exitcode or env.debug(): print msg env.history.statusbar_msg(msg) ## if env.debug(): ## env.history.message(_graymsg(msg)) # not needed, caller prints it if exitcode: return 8, "Error: " + msg # this breaks the convention of the other error returns pass # Display image in separate window here. [Actually I think this is done in the caller -- bruce 060707 comment] return 0, "Rendering finished" # from launch_povray_or_megapov
def launch_qutemol(pdb_file): """ Launch and load QuteMolX with the PDB file I{pdb_file}. @param pdb_file: the PDB filename to load @type pdb_file: string @return: (errorcode, errortext) where errorcode is one of the following: ###k 0 = successful 8 = QuteMolX failed for an unknown reason. @rtype: int, text """ plugin_name = "QuteMolX" plugin_prefs_keys = (qutemol_enabled_prefs_key, qutemol_path_prefs_key) errorcode, errortext_or_path = \ checkPluginPreferences(plugin_name, plugin_prefs_keys, insure_executable = True) if errorcode: return errorcode, errortext_or_path program_path = errortext_or_path workdir, junk_exe = os.path.split(program_path) # This provides a way to tell NE1 which version of QuteMolX is installed. if debug_pref("QuteMol 0.4.1 or later", Choice_boolean_True, prefs_key=True): version = "0.4.1" else: version = "0.4.0" # Start QuteMolX. try: args = [pdb_file] if env.debug(): print "Debug: Launching", plugin_name, \ "\n working directory=", workdir, \ "\n program_path=", program_path, \ "\n args are %r" % (args,) arguments = QStringList() for arg in args: if arg != "": arguments.append(arg) p = Process() # QuteMolX must run from the directory its executable lives. Otherwise, # it has serious problems (but still runs). Mark 2007-06-02. p.setWorkingDirectory(QString(workdir)) # Tried p.startDetached() so that QuteMolX would be its own process and # continue to live even if NE1 exits. Unfortunately, # setWorkingDirectory() doesn't work. Seems like a Qt bug to me. # Mark 2007-06-02 p.start(program_path, arguments) except: print_compact_traceback("exception in launch_qutemol(): ") return 8, "%s failed for an unknown reason." % plugin_name # set an appropriate exitcode and msg if p.exitStatus() == QProcess.NormalExit: exitcode = p.exitStatus() if not exitcode: msg = plugin_name + " launched." else: msg = plugin_name + " had exitcode %r" % exitcode else: exitcode = p.exitStatus() exitcode = -1 msg = "Abnormal exit (or failure to launch)" if exitcode: return 8, "Error: " + msg # this breaks the convention of the other error returns return 0, plugin_name + " launched." # from launch_qutemol
def launch_povray_or_megapov(win, info, povray_ini): #bruce 060707/11 revised this extensively for Mac A8 """ Try to launch POV-Ray or MegaPOV, as specified in <info> (as returned from decode_povray_prefs, assumed already checked), on the given <povray_ini> file (which should already exist), and running in the directory of that file (this is required, since it may contain relative pathnames). <win> must be the main window object (used for .glpane.is_animating). Returns (errorcode, errortext), where errorcode is one of the following: ###k 0 = successful 8 = POV-Ray or MegaPOV failed for an unknown reason. """ (program_nickname, program_path, include_dir) = info #e rename this arg renderer_info? exit = '' program = program_path if sys.platform == 'win32': program = "\""+program+"\"" # Double quotes needed by Windows. Mark 060602. if program_nickname == 'POV-Ray': exit = "/EXIT" # Later we'll cd to the POV-Ray's INI file directory and use tmp_ini in the POV-Ray command-line. # This helps us get around POV-Ray's I/O Restrictions. Mark 060529. workdir, tmp_ini = os.path.split(povray_ini) # Render scene. try: args = [tmp_ini] if exit: args += [exit] if env.debug(): ## use env.history.message(_graymsg(msg)) ? print "debug: Launching %s: \n" % program_nickname,\ "working directory=",workdir,"\n program_path=", program_path, "\n args are %r" % (args,) arguments = QStringList() for arg in args: if arg != "": arguments.append(arg) from processes.Process import Process p = Process() #bruce 060707: this doesn't take advantage of anything not in QProcess, # unless it matters that it reads and discards stdout/stderr # (eg so large output would not block -- unlikely that this matters). # It doesn't echo stdout/stderr. See also blabout/blaberr in other files. Maybe fix this? ###@@@ p.setWorkingDirectory(workdir) p.start(program, arguments) # Put up hourglass cursor to indicate we are busy. Restore the cursor below. Mark 060621. QApplication.setOverrideCursor( QCursor(Qt.WaitCursor) ) win.glpane.is_animating = True # This disables selection [do you mean highlighting? #k] while rendering the image. import time msg = "Rendering image" while p.state() == QProcess.Running: # Display a message on the status bar that POV-Ray/MegaPOV is rendering. # I'd much rather display a progressbar and stop button by monitoring the size of the output file. # This would require the output file to be written in PPM or BMP format, but not PNG format, since # I don't believe a PNG's final filesize can be predicted. # Check out monitor_progress_by_file_growth() in runSim.py, which does this. [mark] time.sleep(0.25) env.history.statusbar_msg(msg) env.call_qApp_processEvents() if 1: # Update the statusbar message while rendering. if len(msg) > 40: #bruce changed 100 -> 40 in case of short statusbar msg = "Rendering image" else: #msg = msg + "." msg += "." except: #bruce 060707 moved print_compact_traceback earlier, and its import to toplevel (after Windows A8, before Linux/Mac A8) print_compact_traceback( "exception in launch_povray_or_megapov(): " ) QApplication.restoreOverrideCursor() win.glpane.is_animating = False return 8, "%s failed for an unknown reason." % program_nickname #bruce 060707 moved the following outside the above try clause, and revised it (after Windows A8, before Linux/Mac A8) QApplication.restoreOverrideCursor() # Restore the cursor. Mark 060621. ## env.history.statusbar_msg("Rendering finished!") # this is wrong if it was not a normal exit. [bruce 060707 removed it] win.glpane.is_animating = False if 1: #bruce 060707 added this (after Windows A8, before Linux/Mac A8): # set an appropriate exitcode and msg if p.exitStatus() == QProcess.NormalExit: exitcode = p.exitStatus() if not exitcode: msg = "Rendering finished!" else: msg = "Rendering program had exitcode %r" % exitcode # e.g. 126 for Mac failure; same as shell exitcode, which says "cannot execute binary file"; # but /usr/bin/open helps, so we'll try that above (but not in this commit, which is just to # improve error reporting). ###@@@ # [bruce 060707] else: exitcode = p.exitStatus() exitcode = -1 msg = "Abnormal exit (or failure to launch)" if exitcode or env.debug(): print msg env.history.statusbar_msg(msg) ## if env.debug(): ## env.history.message(_graymsg(msg)) # not needed, caller prints it if exitcode: return 8, "Error: " + msg # this breaks the convention of the other error returns pass # Display image in separate window here. [Actually I think this is done in the caller -- bruce 060707 comment] return 0, "Rendering finished" # from launch_povray_or_megapov
def run_rosetta(self, movie, args): """ Main method that executes the rosetta simulation @param movie: simulation object @type movie: L{Movie} @param args: list of simulation arguments @type args: list @note: This method needs to be refactored very badly """ self._movie = movie assert args >= 1 #we have set it up such that the first element in arg[0] is number of simulations self.numSim = args[0][0] #set the program path, database path and write the paths.txt in here #we have set it up such that the third argument in args[0] always have # the name of the protein we are running rosetta simulation for #also we say that an error has occurred if we cannot write the resfile. #not sure if this should be the case self.errcode = self.set_options_errQ( args[0][2]) if self.errcode: # used to be a local var 'r' return #get the starting pdb structure for rosetta simulation self.sim_input_file = self.sim_input_filename(args[0][2]) if self.sim_input_file is None: return #this marks the beginning of the simulation. Although technically we are yet # to call QProcess, it seems like a good place to set the waitcursor to True self.set_waitcursor(True) progressBar = self.win.statusBar().progressBar # Disable some QActions (menu items/toolbar buttons) while the sim is running. self.win.disable_QActions_for_sim(True) try: self.simProcess = None #sets up the argument list for running rosetta including the ones #that were provided in the pop up dialog backRubArgs = [] if len(args) == 3: backRubArgs = args[2] self.setup_sim_args(args[0][1], backRubArgs) progressBar.setRange(0, 0) progressBar.reset() progressBar.show() env.history.statusbar_msg("Running Rosetta on " + self.sim_input_file[0:len(self.sim_input_file) - 4]) #this is used to name all the files related to this simulation #we make sure that the pdb id is there in the filename so that it is #easy to identify for which protein chunk we are running the simulation rosettaFullBaseFileName = self.tmp_file_prefix rosettaFullBaseFileInfo = QFileInfo(rosettaFullBaseFileName) rosettaWorkingDir = rosettaFullBaseFileInfo.dir().absolutePath() rosettaBaseFileName = rosettaFullBaseFileInfo.fileName() rosettaProcess = Process() rosettaProcess.setProcessName("rosetta") rosettaProcess.redirect_stdout_to_file("%s-rosetta-stdout.txt" % rosettaFullBaseFileName) rosettaProcess.redirect_stderr_to_file("%s-rosetta-stderr.txt" % rosettaFullBaseFileName) rosettaStdOut = rosettaFullBaseFileName + "-rosetta-stdout.txt" #rosetta files are all put in RosettaDesignFiles under Nanorex rosettaProcess.setWorkingDirectory(rosettaWorkingDir) environmentVariables = rosettaProcess.environment() rosettaProcess.setEnvironment(environmentVariables) msg = greenmsg("Starting Rosetta sequence design") env.history.message(self.cmdname + ": " + msg) env.history.message("%s: Rosetta files at %s%s%s.*" % (self.cmdname, rosettaWorkingDir, os.sep, rosettaFullBaseFileInfo.completeBaseName())) abortHandler = AbortHandler(self.win.statusBar(), "rosetta") #main rosetta simulation call errorCode = rosettaProcess.run(self.program, self._arguments, False, abortHandler) abortHandler = None if (errorCode != 0): if errorCode == -2: # User pressed Abort button in progress dialog. msg = redmsg("Aborted.") env.history.message(self.cmdname + ": " + msg) env.history.statusbar_msg("") if self.simProcess: self.simProcess.kill() else: #the stdout will tell the user for what other reason, #the simulation may fail msg = redmsg("Rosetta sequence design failed. For details check" + rosettaStdOut) env.history.message(self.cmdname + ": " + msg) self.errcode = 2; env.history.statusbar_msg("") else: #Error code is not zero but there's in reality error in stdout #check if that be the case env.history.statusbar_msg("") errorInStdOut = self.checkErrorInStdOut(rosettaStdOut) if errorInStdOut: msg = redmsg("Rosetta sequence design failed, Rosetta returned %d" % errorCode) env.history.message(self.cmdname + "," + self.cmd_type + ": " + msg) env.history.statusbar_msg("") else: #bug in rosetta: often for some reason or the other rosetta #run does not produce an o/p file. One instance is that if # you already have an output file for this starting structure #already in the directory rosetta refuses to optimize the #structue again even if your residue file has changed #since we remove all related output files before any run on #the same protein, this is not a possible source of error #in our case but there can be other similar problems #Hence we always check the desired output file actually exists #in the RosettaDesignFiles directory before we actually declare #that it has been a successful run if self.cmd_type == "ROSETTA_FIXED_BACKBONE_SEQUENCE_DESIGN": outputFile = self.outfile + '_0001.pdb' outPath = os.path.join(os.path.dirname(self.tmp_file_prefix), outputFile) if os.path.exists(outPath): #if there's the o/p pdb file, then rosetta design "really" #succeeded msg = greenmsg("Rosetta sequence design succeeded") env.history.message(self.cmdname + "> " + self.cmd_type + ": " + msg) #find out best score from all the generated outputs #may be we will do it some day, but for now we only output #the chunk with the lowest energy (Score) score, bestSimOutFileName = getScoreFromOutputFile(self.tmp_file_prefix, self.outfile, self.numSim) chosenOutPath = os.path.join(os.path.dirname(self.tmp_file_prefix), bestSimOutFileName) insertpdb(self.assy, str(chosenOutPath), None) #set the secondary structure of the rosetta output protein #to that of the inpput protein outProtein = self._set_secondary_structure_of_rosetta_output_protein(bestSimOutFileName) #update the protein combo box in build protein mode with #newly created protein chunk self._updateProteinComboBoxInBuildProteinMode(outProtein) env.history.statusbar_msg("") fastaFile = self.outfile + "_design.fasta" fastaFilePath = os.path.join(os.path.dirname(self.tmp_file_prefix), fastaFile) #process th fasta file to find the sequence of the protein #with lowest score proteinSeqList = processFastaFile(fastaFilePath, bestSimOutFileName, self.sim_input_file[0:len(self.sim_input_file)-4]) #show a pop up dialog to show the best score and most #optimized sequence if score is not None and proteinSeqList is not []: self.showResults(score, proteinSeqList) else: #even when there's nothing in stderr or errocode is zero, #rosetta may not output anything. msg1 = redmsg("Rosetta sequence design failed. ") msg2 = redmsg(" %s file was never created by Rosetta." % outputFile) msg = msg1 + msg2 env.history.message(self.cmdname + ": " + msg) env.history.statusbar_msg("") if self.cmd_type == "BACKRUB_PROTEIN_SEQUENCE_DESIGN": #its important to set thi pref key to False so that if the #subsequent rosetta run is with fixed backbone then the #resfile is correctly written from utilities.prefs_constants import rosetta_backrub_enabled_prefs_key env.prefs[rosetta_backrub_enabled_prefs_key] = False #Urmi 20080807: first copy the backrub_low.pdb to a new pdb #file with the pdb info also added there outProteinName, outPath = createUniquePDBOutput(self.tmp_file_prefix, self.sim_input_file[0:len(self.sim_input_file)-4], self.win) if outProteinName is None: msg1 = redmsg("Rosetta sequence design with backrub motion has failed. ") msg2 = redmsg(" backrub_low.pdb was never created by Rosetta.") msg = msg1 + msg2 env.history.message(self.cmdname + "," + self.cmd_type + ": " + msg) env.history.statusbar_msg("") else: env.history.statusbar_msg("") msg = greenmsg("Rosetta sequence design with backrub motion allowed, succeeded") env.history.message(self.cmdname + "> " + self.cmd_type + ": " + msg) insertpdb(self.assy, str(outPath), None) outProtein = self._set_secondary_structure_of_rosetta_output_protein(outProteinName + ".pdb") self._updateProteinComboBoxInBuildProteinMode(outProtein) inProteinName = self.sim_input_file[0:len(self.sim_input_file)-4] proteinSeqList = getProteinNameAndSeq(inProteinName, outProteinName, self.win) score = getScoreFromBackrubOutFile(outPath) if score is not None and proteinSeqList is not []: self.showResults(score, proteinSeqList) if self.cmd_type == "ROSETTA_SCORE": msg = greenmsg("Rosetta scoring has succeeded") env.history.message(self.cmdname + "> " + self.cmd_type + ": " + msg) showRosettaScore(self.tmp_file_prefix, self.scorefile, self.win) except: print_compact_traceback("bug in simulator-calling code: ") self.errcode = -11111 self.set_waitcursor(False) self.win.disable_QActions_for_sim(False) env.history.statusbar_msg("") if not self.errcode: return # success return # caller should look at self.errcode
def run_using_old_movie_obj_to_hold_sim_params(self, movie, args): self._movie = movie assert args >= 1 #for now args has number of simulations self.numSim = args[0][0] #set the program path, database path and write the paths.txt in here self.errcode = self.set_options_errQ( ) if self.errcode: # used to be a local var 'r' return self.sim_input_file = self.sim_input_filename(self.part) if self.sim_input_file is None: return self.set_waitcursor(True) progressBar = self.win.statusBar().progressBar # Disable some QActions (menu items/toolbar buttons) while the sim is running. self.win.disable_QActions_for_sim(True) try: #bruce 050325 added this try/except wrapper, to always restore cursor self.simProcess = None #bruce 051231 self.setup_sim_args(args) progressBar.setRange(0, 0) progressBar.reset() progressBar.show() env.history.statusbar_msg("Running Rosetta") rosettaFullBaseFileName = self.tmp_file_prefix rosettaFullBaseFileInfo = QFileInfo(rosettaFullBaseFileName) rosettaWorkingDir = rosettaFullBaseFileInfo.dir().absolutePath() rosettaBaseFileName = rosettaFullBaseFileInfo.fileName() rosettaProcess = Process() rosettaProcess.setProcessName("rosetta") rosettaProcess.redirect_stdout_to_file("%s-rosetta-stdout.txt" % rosettaFullBaseFileName) rosettaProcess.redirect_stderr_to_file("%s-rosetta-stderr.txt" % rosettaFullBaseFileName) rosettaStdOut = rosettaFullBaseFileName + "-rosetta-stdout.txt" rosettaProcess.setWorkingDirectory(rosettaWorkingDir) environmentVariables = rosettaProcess.environment() rosettaProcess.setEnvironment(environmentVariables) msg = greenmsg("Starting Rosetta sequence design") env.history.message(self.cmdname + ": " + msg) env.history.message("%s: Rosetta files at %s%s%s.*" % (self.cmdname, rosettaWorkingDir, os.sep, rosettaFullBaseFileInfo.completeBaseName())) abortHandler = AbortHandler(self.win.statusBar(), "rosetta") errorCode = rosettaProcess.run(self.program, self._arguments, False, abortHandler) abortHandler = None if (errorCode != 0): if errorCode == -2: # User pressed Abort button in progress dialog. msg = redmsg("Aborted.") env.history.message(self.cmdname + ": " + msg) env.history.statusbar_msg("") if self.simProcess: #bruce 051231 added condition (since won't be there when use_dylib) self.simProcess.kill() else: msg = redmsg("Rosetta sequence design failed. For details check" + rosettaStdOut) env.history.message(self.cmdname + ": " + msg) self.errcode = 2; env.history.statusbar_msg("") else: #run has been successful #open pdb file env.history.statusbar_msg("") errorInStdOut = self.checkErrorInStdOut(rosettaStdOut) if errorInStdOut: msg = redmsg("Rosetta sequence design failed, Rosetta returned %d" % errorCode) env.history.message(self.cmdname + ": " + msg) env.history.statusbar_msg("") else: #env.history.message(self.cmdname + ": " + msg) outputFile = self.outfile + '_0001.pdb' outPath = os.path.join(os.path.dirname(self.tmp_file_prefix), outputFile) if os.path.exists(outPath): msg = greenmsg("Rosetta sequence design succeeded") env.history.message(self.cmdname + ": " + msg) #find out best score from all the generated outputs score, bestSimOutFileName = getScoreFromOutputFile(self.tmp_file_prefix, self.outfile, self.numSim) chosenOutPath = os.path.join(os.path.dirname(self.tmp_file_prefix), bestSimOutFileName) insertpdb(self.assy, str(chosenOutPath), None) env.history.statusbar_msg("") fastaFile = self.outfile + "_design.fasta" fastaFilePath = os.path.join(os.path.dirname(self.tmp_file_prefix), fastaFile) proteinSeqList = processFastaFile(fastaFilePath, bestSimOutFileName, self.sim_input_file[0:len(self.sim_input_file)-4]) #score = getScoreFromOutputFile(outPath) if score is not None and proteinSeqList is not []: self.showResults(score, proteinSeqList) else: msg1 = redmsg("Rosetta sequence design failed. ") msg2 = redmsg(" %s file was never created by Rosetta." % outputFile) msg = msg1 + msg2 env.history.message(self.cmdname + ": " + msg) env.history.statusbar_msg("") except: print_compact_traceback("bug in simulator-calling code: ") self.errcode = -11111 self.set_waitcursor(False) self.win.disable_QActions_for_sim(False) env.history.statusbar_msg("") if not self.errcode: return # success return # caller should look at self.errcode