Package pipe_control :: Module chemical_shift
[hide private]
[frames] | no frames]

Source Code for Module pipe_control.chemical_shift

  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  """Module containing functions for the handling of chemical shifts.""" 
 24   
 25   
 26  # Python module imports. 
 27  import sys 
 28  from warnings import warn 
 29   
 30  # relax module imports. 
 31  from lib.errors import RelaxError, RelaxNoSequenceError 
 32  from lib.io import write_data 
 33  from lib.spectrum.peak_list import read_peak_list 
 34  from lib.warnings import RelaxNoSpinWarning 
 35  from pipe_control import pipes 
 36  from pipe_control.mol_res_spin import exists_mol_res_spin_data, generate_spin_id_unique, return_spin 
 37   
 38   
39 -def read(file=None, dir=None, spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, sep=None, spin_id=None, verbose=True):
40 """Read the peak intensity data. 41 42 @keyword file: The name of the file containing the peak intensities. 43 @type file: str 44 @keyword dir: The directory where the file is located. 45 @type dir: str 46 @keyword spin_id_col: The column containing the spin ID strings (used by the generic intensity file format). If supplied, the mol_name_col, res_name_col, res_num_col, spin_name_col, and spin_num_col arguments must be none. 47 @type spin_id_col: int or None 48 @keyword mol_name_col: The column containing the molecule name information (used by the generic intensity file format). If supplied, spin_id_col must be None. 49 @type mol_name_col: int or None 50 @keyword res_name_col: The column containing the residue name information (used by the generic intensity file format). If supplied, spin_id_col must be None. 51 @type res_name_col: int or None 52 @keyword res_num_col: The column containing the residue number information (used by the generic intensity file format). If supplied, spin_id_col must be None. 53 @type res_num_col: int or None 54 @keyword spin_name_col: The column containing the spin name information (used by the generic intensity file format). If supplied, spin_id_col must be None. 55 @type spin_name_col: int or None 56 @keyword spin_num_col: The column containing the spin number information (used by the generic intensity file format). If supplied, spin_id_col must be None. 57 @type spin_num_col: int or None 58 @keyword sep: The column separator which, if None, defaults to whitespace. 59 @type sep: str or None 60 @keyword spin_id: The spin ID string used to restrict data loading to a subset of all spins. If 'auto' is provided for a NMRPipe seriesTab formatted file, the ID's are auto generated in form of Z_Ai. 61 @type spin_id: None or str 62 @keyword verbose: A flag which if True will cause all chemical shift data loaded to be printed out. 63 @type verbose: bool 64 """ 65 66 # Test if the current data pipe exists. 67 pipes.test() 68 69 # Test if sequence data is loaded. 70 if not exists_mol_res_spin_data(): 71 raise RelaxNoSequenceError 72 73 # Check the file name. 74 if file == None: 75 raise RelaxError("The file name must be supplied.") 76 77 # Read the peak list data. 78 peak_list = read_peak_list(file=file, dir=dir, spin_id_col=spin_id_col, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep, spin_id=spin_id) 79 80 # Loop over the assignments. 81 data = [] 82 data_flag = False 83 for assign in peak_list: 84 # Loop over the dimensions of the peak list. 85 for i in range(peak_list.dimensionality): 86 # Generate the spin_id. 87 spin_id = generate_spin_id_unique(res_num=assign.res_nums[i], spin_name=assign.spin_names[i]) 88 89 # Get the spin container. 90 spin = return_spin(spin_id) 91 if not spin: 92 warn(RelaxNoSpinWarning(spin_id)) 93 continue 94 95 # Skip deselected spins. 96 if not spin.select: 97 continue 98 99 # Store the shift. 100 spin.chemical_shift = assign.shifts[i] 101 102 # Switch the flag. 103 data_flag = True 104 105 # Append the data for printing out. 106 data.append([spin_id, repr(spin.chemical_shift)]) 107 108 # No data. 109 if not data_flag: 110 raise RelaxError("No chemical shifts could be loaded from the peak list") 111 112 # Print out. 113 if verbose: 114 print("\nThe following chemical shifts have been loaded into the relax data store:\n") 115 write_data(out=sys.stdout, headings=["Spin_ID", "Chemical shift"], data=data)
116