Package specific_analyses :: Package relax_disp :: Module sherekhan
[hide private]
[frames] | no frames]

Source Code for Module specific_analyses.relax_disp.sherekhan

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2013-2014 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """Functions for interfacing with Adam Mazur's ShereKhan program.""" 
 24   
 25  # Dependencies. 
 26  import dep_check 
 27   
 28  # Python module imports. 
 29  from os import sep 
 30  PIPE, Popen = None, None 
 31  if dep_check.subprocess_module: 
 32      from subprocess import PIPE, Popen 
 33   
 34  # relax module imports. 
 35  from lib.errors import RelaxError, RelaxNoSequenceError 
 36  from lib.io import mkdir_nofail, open_write_file 
 37  from lib.physical_constants import g1H, g15N 
 38  from pipe_control import pipes 
 39  from pipe_control.mol_res_spin import exists_mol_res_spin_data, return_residue 
 40  from specific_analyses.relax_disp.data import loop_cluster, loop_exp_frq, loop_offset_point, loop_time, return_param_key_from_data, spin_ids_to_containers 
 41   
 42   
43 -def sherekhan_input(spin_id=None, force=False, dir='ShereKhan'):
44 """Create the ShereKhan input files. 45 46 @keyword spin_id: The spin ID string to restrict the file creation to. 47 @type spin_id: str 48 @keyword force: A flag which if True will cause all pre-existing files to be overwritten. 49 @type force: bool 50 @keyword dir: The optional directory to place the files into. If None, then the files will be placed into the current directory. 51 @type dir: str or None 52 """ 53 54 # Test if the current pipe exists. 55 pipes.test() 56 57 # Test if sequence data is loaded. 58 if not exists_mol_res_spin_data(): 59 raise RelaxNoSequenceError 60 61 # Test if the experiment type has been set. 62 if not hasattr(cdp, 'exp_type'): 63 raise RelaxError("The relaxation dispersion experiment type has not been specified.") 64 65 # Test if the model has been set. 66 if not hasattr(cdp, 'model_type'): 67 raise RelaxError("The relaxation dispersion model has not been specified.") 68 69 # Directory creation. 70 if dir != None: 71 mkdir_nofail(dir, verbosity=0) 72 73 # Loop over the spin blocks. 74 cluster_index = 0 75 for spin_ids in loop_cluster(): 76 # The spin containers. 77 spins = spin_ids_to_containers(spin_ids) 78 79 # Loop over the magnetic fields. 80 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 81 # Loop over the time, and count it. 82 time_i = 0 83 for time, ti in loop_time(exp_type=exp_type, frq=frq, return_indices=True): 84 time_i += 1 85 86 # Check that not more than one time point is returned. 87 if time_i > 1: 88 raise RelaxError("Number of returned time poins is %i. Only 1 time point is expected."%time_i) 89 90 # The ShereKhan input file for the spin cluster. 91 file_name = 'sherekhan_frq%s.in' % (mi+1) 92 if dir != None: 93 dir_name = dir + sep + 'cluster%s' % (cluster_index+1) 94 else: 95 dir_name = 'cluster%s' % (cluster_index+1) 96 file = open_write_file(file_name=file_name, dir=dir_name, force=force) 97 98 # The B0 field for the nuclei of interest in MHz (must be positive to be accepted by the server). 99 file.write("%.10f\n" % abs(frq / g1H * g15N / 1e6)) 100 101 # The constant relaxation time for the CPMG experiment in seconds. 102 file.write("%s\n" % (time)) 103 104 # The comment line. 105 file.write("# %-18s %-20s %-20s\n" % ("nu_cpmg (Hz)", "R2eff (rad/s)", "Error")) 106 107 # Loop over the spins of the cluster. 108 for i in range(len(spins)): 109 # Get the residue container. 110 res = return_residue(spin_ids[i]) 111 112 # Name the residue if needed. 113 res_name = res.name 114 if res_name == None: 115 res_name = 'X' 116 117 # Initialise the lines to output (to be able to catch missing data). 118 lines = [] 119 120 # The residue ID line. 121 lines.append("# %s%s\n" % (res_name, res.num)) 122 123 # Loop over the dispersion points. 124 for offset, point in loop_offset_point(exp_type=exp_type, frq=frq, skip_ref=True): 125 # The parameter key. 126 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 127 128 # No data. 129 if param_key not in spins[i].r2eff: 130 continue 131 132 # Store the data. 133 lines.append("%20.15g %20.13g %20.13g\n" % (point, spins[i].r2eff[param_key], spins[i].r2eff_err[param_key])) 134 135 # No data. 136 if len(lines) == 1: 137 continue 138 139 # Write out the data. 140 for line in lines: 141 file.write(line) 142 143 # Close the file. 144 file.close() 145 146 # Increment the cluster index. 147 cluster_index += 1
148