def open_gui(self): """Open a Molmol pipe.""" # Test that the Molmol binary exists. test_binary('molmol') # Python 2.3 and earlier. if Popen == None: raise RelaxError("The subprocess module is not available in this version of Python.") # Open Molmol as a pipe. self.molmol = Popen(['molmol', '-f', '-'], stdin=PIPE).stdin # Execute the command history. if len(self.command_history) > 0: self.exec_cmd(self.command_history, store_command=0) return # Wait a little while for Molmol to initialise. sleep(2) # Test if the PDB file has been loaded. if hasattr(cdp, 'structure'): self.open_pdb() # Run InitAll to remove everything from Molmol. else: self.molmol.write("InitAll yes\n")
def open_gui(self): """Open a Molmol pipe.""" # Test that the Molmol binary exists. test_binary('molmol') # Python 2.3 and earlier. if Popen == None: raise RelaxError( "The subprocess module is not available in this version of Python." ) # Open Molmol as a pipe. self.molmol = Popen(['molmol', '-f', '-'], stdin=PIPE).stdin # Execute the command history. if len(self.command_history) > 0: self.exec_cmd(self.command_history, store_command=0) return # Wait a little while for Molmol to initialise. sleep(2) # Test if the PDB file has been loaded. if hasattr(cdp, 'structure'): self.open_pdb() # Run InitAll to remove everything from Molmol. else: self.molmol.write("InitAll yes\n")
def open_gui(self): """Open the PyMOL GUI.""" # Use the PyMOL python modules. if self.exec_mode == 'module': # Open the GUI. pymol.finish_launching() self.open = True # Otherwise execute PyMOL on the command line. if self.exec_mode == 'external': # Test that the PyMOL binary exists. test_binary('pymol') # Python 2.3 and earlier. if Popen == None: raise RelaxError("The subprocess module is not available in this version of Python.") # Open PyMOL as a pipe. self.pymol = Popen(['pymol', '-qpK'], stdin=PIPE).stdin # Execute the command history. if len(self.command_history) > 0: self.exec_cmd(self.command_history, store_command=0) return # Test if the PDB file has been loaded. if hasattr(cdp, 'structure'): self.open_pdb()
def open_gui(self): """Open the PyMOL GUI.""" # Use the PyMOL python modules. if self.exec_mode == 'module': # Open the GUI. pymol.finish_launching() self.open = True # Otherwise execute PyMOL on the command line. if self.exec_mode == 'external': # Test that the PyMOL binary exists. test_binary('pymol') # Python 2.3 and earlier. if Popen == None: raise RelaxError( "The subprocess module is not available in this version of Python." ) # Open PyMOL as a pipe. self.pymol = Popen(['pymol', '-qpK'], stdin=PIPE).stdin # Execute the command history. if len(self.command_history) > 0: self.exec_cmd(self.command_history, store_command=0) return # Test if the PDB file has been loaded. if hasattr(cdp, 'structure'): self.open_pdb()
def run(file_prefix="map", dir="dx", dx_exe="dx", vp_exec=True): """Execute OpenDX. @keyword file_prefix: The file prefix for all the created files. @type file_prefix: str @keyword dir: The directory to place the files into. @type dir: str or None @keyword dx_exe: The path to the OpenDX executable file. This can be changed if the binary 'dx' is not located in the system path. @type dx_exe: str @keyword vp_exec: If True, then the OpenDX visual program will be launched. @type vp_exec: bool """ # Text for changing to the directory dir. dir_text = "" if dir != None: dir_text = " -directory " + dir # Text for executing OpenDX. execute_text = "" if vp_exec: execute_text = " -execute" # Test the binary file string corresponds to a valid executable. test_binary(dx_exe) # Run OpenDX. system(dx_exe + dir_text + " -program " + file_prefix + ".net" + execute_text + " &")
def view(file=None, dir=None, grace_exe='xmgrace'): """Execute Grace. @keyword file: The name of the file to open in Grace. @type file: str @keyword dir: The optional directory containing the file. @type dir: str @keyword grace_exe: The name of the Grace executable file. This should be located within the system path. @type grace_exe: str """ # Test the binary file string corresponds to a valid executable. test_binary(grace_exe) # File path. file_path = get_file_path(file, dir) # Run Grace. system(grace_exe + " \"" + file_path + "\" &")
def __init__(self, methodName='runTest'): """Skip the tests if the subprocess module is not available (Python 2.3 and earlier). @keyword methodName: The name of the test. @type methodName: str """ # Execute the base class method. super(Palmer, self).__init__(methodName) # Missing module. if not dep_check.subprocess_module: # Store in the status object. status.skipped_tests.append([methodName, 'subprocess', self._skip_type]) # Test for the presence of the Modelfree4 binary (skip the test if not present). try: test_binary('modelfree4') except: status.skipped_tests.append([methodName, "Art Palmer's Modelfree4 software", self._skip_type])
def __init__(self, methodName='runTest'): """Skip the tests if the subprocess module is not available (Python 2.3 and earlier). @keyword methodName: The name of the test. @type methodName: str """ # Execute the base class method. super(Dasha, self).__init__(methodName) # Missing module. if not dep_check.subprocess_module: # Store in the status object. status.skipped_tests.append([methodName, 'subprocess', self._skip_type]) # Test for the presence of the Dasha binary (skip the test if not present). try: test_binary('dasha') except: status.skipped_tests.append([methodName, 'Dasha model-free software', self._skip_type])
def catia_execute(file='Fit.catia', dir=None, binary=None): """Create the CATIA input files. @keyword file: The main CATIA execution file. @type file: str @keyword dir: The optional directory to place the files into. If None, then the files will be placed into the current directory. @type dir: str or None @keyword binary: The name of the CATIA binary file. This can include the path to the binary. @type binary: str """ # The current directory. orig_dir = getcwd() # Test the binary file string corresponds to a valid executable. test_binary(binary) # The directory. if dir == None: dir = orig_dir if not access(dir, F_OK): raise RelaxDirError('CATIA', dir) # Change to the directory with the CATIA input files. chdir(dir) # Catch failures and return to the correct directory. try: # Execute CATIA. cmd = binary + ' < Fit.catia' pipe = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) # Close the pipe. pipe.stdin.close() # Write to stdout. for line in pipe.stdout.readlines(): # Decode Python 3 byte arrays. if hasattr(line, 'decode'): line = line.decode() # Write. sys.stdout.write(line) # Write to stderr. for line in pipe.stderr.readlines(): # Decode Python 3 byte arrays. if hasattr(line, 'decode'): line = line.decode() # Write. sys.stderr.write(line) # Failure. except: # Change back to the original directory. chdir(orig_dir) # Reraise the error. raise # Change back to the original directory. chdir(orig_dir)
def cpmgfit_execute(dir=None, binary='cpmgfit', force=False): """Execute CPMGFit for each spin input file. @keyword dir: The directory where the input files are located. If None, this defaults to the dispersion model name in lowercase. @type dir: str or None @keyword binary: The name of the CPMGFit binary file. This can include the path to the binary. @type binary: str @keyword force: A flag which if True will cause any pre-existing files to be overwritten by CPMGFit. @type force: bool """ # Test if the current pipe exists. check_pipe() # Test if sequence data is loaded. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # Test if the experiment type has been set. if not hasattr(cdp, 'exp_type'): raise RelaxError("The relaxation dispersion experiment type has not been specified.") # Test if the model has been set. if not hasattr(cdp, 'model_type'): raise RelaxError("The relaxation dispersion model has not been specified.") # The directory. if dir != None and not access(dir, F_OK): raise RelaxDirError('CPMGFit', dir) # Loop over each spin. for spin, spin_id in spin_loop(return_id=True, skip_desel=True): # Translate the model. function = translate_model(spin.model) # The spin input file name. file_in = dir + sep + spin_file_name(spin_id=spin_id) if not access(file_in, F_OK): raise RelaxFileError("spin input", file_in) # The spin output file name. file_out = dir + sep + spin_file_name(spin_id=spin_id, output=True) # Test the binary file string corresponds to a valid executable. test_binary(binary) # Execute CPMGFit. cmd = "%s -grid -xmgr -f %s | tee %s\n" % (binary, file_in, file_out) print("\n\n%s" % cmd) pipe = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=True) # Write to stderr. for line in pipe.stderr.readlines(): # Decode Python 3 byte arrays. if hasattr(line, 'decode'): line = line.decode() # Write. sys.stderr.write(line) # Write to stdout. for line in pipe.stdout.readlines(): # Decode Python 3 byte arrays. if hasattr(line, 'decode'): line = line.decode() # Write. sys.stdout.write(line)
def execute(dir, force, binary): """Execute Modelfree4. BUG: Control-C during execution causes the cwd to stay as dir. @param dir: The optional directory where the script is located. @type dir: str or None @param force: A flag which if True will cause any pre-existing files to be overwritten by Modelfree4. @type force: bool @param binary: The name of the Modelfree4 binary file. This can include the path to the binary. @type binary: str """ # Check for the diffusion tensor. if not hasattr(cdp, 'diff_tensor'): raise RelaxNoTensorError('diffusion') # The current directory. orig_dir = getcwd() # The directory. if dir == None: dir = pipes.cdp_name() if not access(dir, F_OK): raise RelaxDirError('Modelfree4', dir) # Change to this directory. chdir(dir) # Catch failures and return to the correct directory. try: # Python 2.3 and earlier. if Popen == None: raise RelaxError("The subprocess module is not available in this version of Python.") # Test if the 'mfin' input file exists. if not access('mfin', F_OK): raise RelaxFileError('mfin input', 'mfin') # Test if the 'mfdata' input file exists. if not access('mfdata', F_OK): raise RelaxFileError('mfdata input', 'mfdata') # Test if the 'mfmodel' input file exists. if not access('mfmodel', F_OK): raise RelaxFileError('mfmodel input', 'mfmodel') # Test if the 'mfpar' input file exists. if not access('mfpar', F_OK): raise RelaxFileError('mfpar input', 'mfpar') # Test if the 'PDB' input file exists. if cdp.diff_tensor.type != 'sphere': pdb = cdp.structure.structural_data[0].mol[0].file_name if not access(pdb, F_OK): raise RelaxFileError('PDB', pdb) else: pdb = None # Remove the file 'mfout' and '*.out' if the force flag is set. if force: for file in listdir(getcwd()): if search('out$', file) or search('rotate$', file): remove(file) # Test the binary file string corresponds to a valid executable. test_binary(binary) # Execute Modelfree4. if pdb: cmd = binary + ' -i mfin -d mfdata -p mfpar -m mfmodel -o mfout -e out -s ' + pdb else: cmd = binary + ' -i mfin -d mfdata -p mfpar -m mfmodel -o mfout -e out' pipe = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) # Close the pipe. pipe.stdin.close() # Write to stdout. for line in pipe.stdout.readlines(): # Decode Python 3 byte arrays. if hasattr(line, 'decode'): line = line.decode() # Write. sys.stdout.write(line) # Write to stderr. for line in pipe.stderr.readlines(): # Decode Python 3 byte arrays. if hasattr(line, 'decode'): line = line.decode() # Write. sys.stderr.write(line) # Failure. except: # Change back to the original directory. chdir(orig_dir) # Reraise the error. raise # Change back to the original directory. chdir(orig_dir)
def test_dasha(self): """Test a complete model-free analysis using the program 'Dasha'.""" # Test for the presence of the Dasha binary (skip the test if not present). try: test_binary('dasha') except: return # Execute the script. self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'dasha.py') # Check the global data. self.assertEqual(len(cdp.ri_ids), 3) for ri_id in cdp.ri_ids: self.assertEqual(cdp.spectrometer_frq[ri_id], 600000000.0) self.assertEqual(cdp.ri_type['R1_600'], 'R1') self.assertEqual(cdp.ri_type['R2_600'], 'R2') self.assertEqual(cdp.ri_type['NOE_600'], 'NOE') # The spin data. select = [True, True, False, False] fixed = [False, False, False, False] isotope = ['15N', '15N', '15N', '15N'] model = ['m3', 'm3', 'm3', 'm3'] equation = ['mf_orig', 'mf_orig', 'mf_orig', 'mf_orig'] params = [['s2', 'rex'], ['s2', 'rex'], ['s2', 'rex'], ['s2', 'rex']] s2 = [0.71510, 0.64359, None, None] s2f = [None, None, None, None] s2s = [None, None, None, None] local_tm = [None, None, None, None] te = [None, None, None, None] tf = [None, None, None, None] ts = [None, None, None, None] rex_scale = 1.0 / (2.0 * pi * cdp.spectrometer_frq[cdp.ri_ids[0]]) ** 2 rex = [4.32701*rex_scale, 4.29432*rex_scale, None, None] csa = [-172e-6, -172e-6, -172e-6, -172e-6] chi2 = [1.9657, 0.63673, None, None] ri_data = [{'R1_600': 1.0, 'R2_600': 15.0, 'NOE_600': 0.9}, {'R1_600': 0.9, 'R2_600': 13.9, 'NOE_600': 0.79}, {'R2_600': 12.0, 'NOE_600': 0.6}, None] ri_data_err = [{'R1_600': 0.05, 'R2_600': 0.5, 'NOE_600': 0.05}, {'R1_600': 0.05, 'R2_600': 0.8, 'NOE_600': 0.05}, {'R2_600': 0.5, 'NOE_600': 0.05}, None] # Check the spin data. i = 0 for spin in spin_loop(): # Protons. if spin.isotope == '1H': self.assertEqual(spin.select, False) continue # Check the data. self.assertEqual(spin.select, select[i]) self.assertEqual(spin.fixed, fixed[i]) self.assertEqual(spin.isotope, isotope[i]) self.assertEqual(spin.model, model[i]) self.assertEqual(spin.equation, equation[i]) self.assertEqual(spin.params, params[i]) self.assertEqual(spin.s2, s2[i]) self.assertEqual(spin.s2f, s2f[i]) self.assertEqual(spin.s2s, s2s[i]) self.assertEqual(spin.local_tm, local_tm[i]) self.assertEqual(spin.te, te[i]) self.assertEqual(spin.tf, tf[i]) self.assertEqual(spin.ts, ts[i]) self.assertEqual(spin.rex, rex[i]) self.assertAlmostEqual(spin.csa, csa[i]) self.assertEqual(spin.chi2, chi2[i]) if ri_data[i] == None: self.assert_(not hasattr(spin, 'ri_data')) else: for ri_id in cdp.ri_ids: if ri_id in ri_data[i].keys(): self.assertEqual(spin.ri_data[ri_id], ri_data[i][ri_id]) # Increment the spin index. i += 1 # Check the interatomic data. r = [1.02e-10, 1.02e-10, 1.02e-10, 1.02e-10] i = 0 for interatom in interatomic_loop(): self.assertAlmostEqual(interatom.r, r[i]) i += 1
def execute(dir, force, binary): """Execute Dasha. @param dir: The optional directory where the script is located. @type dir: str or None @param force: A flag which if True will cause any pre-existing files to be overwritten by Dasha. @type force: bool @param binary: The name of the Dasha binary file. This can include the path to the binary. @type binary: str """ # Test the binary file string corresponds to a valid executable. test_binary(binary) # The current directory. orig_dir = getcwd() # The directory. if dir == None: dir = pipes.cdp_name() if not access(dir, F_OK): raise RelaxDirError('Dasha', dir) # Change to this directory. chdir(dir) # Catch failures and return to the correct directory. try: # Test if the 'dasha_script' script file exists. if not access('dasha_script', F_OK): raise RelaxFileError('dasha script', 'dasha_script') # Python 2.3 and earlier. if Popen == None: raise RelaxError("The subprocess module is not available in this version of Python.") # Execute Dasha. pipe = Popen(binary, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) # Get the contents of the script and pump it into Dasha. script = open('dasha_script') lines = script.readlines() script.close() for line in lines: # Encode to a Python 3 byte array. if hasattr(line, 'encode'): line = line.encode() # Write out. pipe.stdin.write(line) # Close the pipe. pipe.stdin.close() # Write to stdout. for line in pipe.stdout.readlines(): # Decode Python 3 byte arrays. if hasattr(line, 'decode'): line = line.decode() # Write. sys.stdout.write(line) # Write to stderr. for line in pipe.stderr.readlines(): # Decode Python 3 byte arrays. if hasattr(line, 'decode'): line = line.decode() # Write. sys.stderr.write(line) # Failure. except: # Change back to the original directory. chdir(orig_dir) # Reraise the error. raise # Change back to the original directory. chdir(orig_dir) # Print some blank lines (aesthetics) sys.stdout.write("\n\n")
def execute(dir, force, binary): """Execute Modelfree4. BUG: Control-C during execution causes the cwd to stay as dir. @param dir: The optional directory where the script is located. @type dir: str or None @param force: A flag which if True will cause any pre-existing files to be overwritten by Modelfree4. @type force: bool @param binary: The name of the Modelfree4 binary file. This can include the path to the binary. @type binary: str """ # Check for the diffusion tensor. if not hasattr(cdp, 'diff_tensor'): raise RelaxNoTensorError('diffusion') # The current directory. orig_dir = getcwd() # The directory. if dir == None: dir = pipes.cdp_name() if not access(dir, F_OK): raise RelaxDirError('Modelfree4', dir) # Change to this directory. chdir(dir) # Catch failures and return to the correct directory. try: # Python 2.3 and earlier. if Popen == None: raise RelaxError( "The subprocess module is not available in this version of Python." ) # Test if the 'mfin' input file exists. if not access('mfin', F_OK): raise RelaxFileError('mfin input', 'mfin') # Test if the 'mfdata' input file exists. if not access('mfdata', F_OK): raise RelaxFileError('mfdata input', 'mfdata') # Test if the 'mfmodel' input file exists. if not access('mfmodel', F_OK): raise RelaxFileError('mfmodel input', 'mfmodel') # Test if the 'mfpar' input file exists. if not access('mfpar', F_OK): raise RelaxFileError('mfpar input', 'mfpar') # Test if the 'PDB' input file exists. if cdp.diff_tensor.type != 'sphere': pdb = cdp.structure.structural_data[0].mol[0].file_name if not access(pdb, F_OK): raise RelaxFileError('PDB', pdb) else: pdb = None # Remove the file 'mfout' and '*.out' if the force flag is set. if force: for file in listdir(getcwd()): if search('out$', file) or search('rotate$', file): remove(file) # Test the binary file string corresponds to a valid executable. test_binary(binary) # Execute Modelfree4. if pdb: cmd = binary + ' -i mfin -d mfdata -p mfpar -m mfmodel -o mfout -e out -s ' + pdb else: cmd = binary + ' -i mfin -d mfdata -p mfpar -m mfmodel -o mfout -e out' pipe = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) out, err = pipe.communicate() # Close the pipe. pipe.stdin.close() # Write to stdout. if out: # Decode Python 3 byte arrays. if hasattr(out, 'decode'): out = out.decode() # Write. sys.stdout.write(out) # Write to stderr. if err: # Decode Python 3 byte arrays. if hasattr(err, 'decode'): err = err.decode() # Write. sys.stderr.write(err) # Catch errors. if pipe.returncode == -signal.SIGSEGV: raise RelaxError( "Modelfree4 return code 11 (Segmentation fault).\n") elif pipe.returncode: raise RelaxError("Modelfree4 return code %s.\n" % pipe.returncode) # Failure. except: # Change back to the original directory. chdir(orig_dir) # Reraise the error. raise # Change back to the original directory. chdir(orig_dir)
def execute(dir, force, binary): """Execute Dasha. @param dir: The optional directory where the script is located. @type dir: str or None @param force: A flag which if True will cause any pre-existing files to be overwritten by Dasha. @type force: bool @param binary: The name of the Dasha binary file. This can include the path to the binary. @type binary: str """ # Test the binary file string corresponds to a valid executable. test_binary(binary) # The current directory. orig_dir = getcwd() # The directory. if dir == None: dir = pipes.cdp_name() if not access(dir, F_OK): raise RelaxDirError('Dasha', dir) # Change to this directory. chdir(dir) # Catch failures and return to the correct directory. try: # Test if the 'dasha_script' script file exists. if not access('dasha_script', F_OK): raise RelaxFileError('dasha script', 'dasha_script') # Python 2.3 and earlier. if Popen == None: raise RelaxError( "The subprocess module is not available in this version of Python." ) # Execute Dasha. pipe = Popen(binary, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) # Get the contents of the script and pump it into Dasha. script = open('dasha_script') lines = script.readlines() script.close() for line in lines: # Encode to a Python 3 byte array. if hasattr(line, 'encode'): line = line.encode() # Write out. pipe.stdin.write(line) # Close the pipe. pipe.stdin.close() # Write to stdout. for line in pipe.stdout.readlines(): # Decode Python 3 byte arrays. if hasattr(line, 'decode'): line = line.decode() # Write. sys.stdout.write(line) # Write to stderr. for line in pipe.stderr.readlines(): # Decode Python 3 byte arrays. if hasattr(line, 'decode'): line = line.decode() # Write. sys.stderr.write(line) # Failure. except: # Change back to the original directory. chdir(orig_dir) # Reraise the error. raise # Change back to the original directory. chdir(orig_dir) # Print some blank lines (aesthetics) sys.stdout.write("\n\n")