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