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 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  PIPE, Popen = None, None 
 30  if dep_check.subprocess_module: 
 31      from subprocess import PIPE, Popen 
 32   
 33  # relax module imports. 
 34  from lib.errors import RelaxError, RelaxNoSequenceError 
 35  from lib.io import open_write_file 
 36  from lib.physical_constants import g1H, g15N 
 37  from pipe_control import pipes 
 38  from pipe_control.mol_res_spin import exists_mol_res_spin_data, return_residue 
 39  from specific_analyses.relax_disp.disp_data import loop_cluster, loop_exp_frq, loop_offset_point, return_param_key_from_data, spin_ids_to_containers 
 40   
 41   
42 -def sherekhan_input(spin_id=None, force=False):
43 """Create the ShereKhan input files. 44 45 @keyword spin_id: The spin ID string to restrict the file creation to. 46 @type spin_id: str 47 @keyword force: A flag which if True will cause all pre-existing files to be overwritten. 48 @type force: bool 49 """ 50 51 # Test if the current pipe exists. 52 pipes.test() 53 54 # Test if sequence data is loaded. 55 if not exists_mol_res_spin_data(): 56 raise RelaxNoSequenceError 57 58 # Test if the experiment type has been set. 59 if not hasattr(cdp, 'exp_type'): 60 raise RelaxError("The relaxation dispersion experiment type has not been specified.") 61 62 # Test if the model has been set. 63 if not hasattr(cdp, 'model_type'): 64 raise RelaxError("The relaxation dispersion model has not been specified.") 65 66 # Test that this is a fixed time period experiment. 67 if len(cdp.relax_time_list) != 1: 68 raise RelaxError("ShereKhan only supports the fixed time relaxation dispersion experiments.") 69 70 # Loop over the spin blocks. 71 cluster_index = 0 72 for spin_ids in loop_cluster(): 73 # The spin containers. 74 spins = spin_ids_to_containers(spin_ids) 75 76 # Loop over the magnetic fields. 77 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 78 # The ShereKhan input file for the spin cluster. 79 file_name = 'sherekhan_frq%s.in' % (mi+1) 80 dir_name = 'cluster%s' % (cluster_index+1) 81 file = open_write_file(file_name=file_name, dir=dir_name, force=force) 82 83 # The B0 field for the nuclei of interest in MHz (must be positive to be accepted by the server). 84 file.write("%s\n" % abs(frq / g1H * g15N / 1e6)) 85 86 # The constant relaxation time for the CPMG experiment in seconds. 87 file.write("%s\n" % (cdp.relax_time_list[0])) 88 89 # The comment line. 90 file.write("# %-18s %-20s %-20s\n" % ("nu_cpmg (Hz)", "R2eff (rad/s)", "Error")) 91 92 # Loop over the spins of the cluster. 93 for i in range(len(spins)): 94 # Get the residue container. 95 res = return_residue(spin_ids[i]) 96 97 # Name the residue if needed. 98 res_name = res.name 99 if res_name == None: 100 res_name = 'X' 101 102 # Initialise the lines to output (to be able to catch missing data). 103 lines = [] 104 105 # The residue ID line. 106 lines.append("# %s%s\n" % (res_name, res.num)) 107 108 # Loop over the dispersion points. 109 for offset, point in loop_offset_point(exp_type=exp_type, frq=frq, skip_ref=True): 110 # The parameter key. 111 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 112 113 # No data. 114 if param_key not in spins[i].r2eff: 115 continue 116 117 # Store the data. 118 lines.append("%20.15g %20.15g %20.15g\n" % (point, spins[i].r2eff[param_key], spins[i].r2eff_err[param_key])) 119 120 # No data. 121 if len(lines) == 1: 122 continue 123 124 # Write out the data. 125 for line in lines: 126 file.write(line) 127 128 # Close the file. 129 file.close() 130 131 # Increment the cluster index. 132 cluster_index += 1
133