Package lib :: Module nmr
[hide private]
[frames] | no frames]

Source Code for Module lib.nmr

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2013 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  """Module containing functions related to basic NMR concepts.""" 
 25   
 26  # Python module imports. 
 27  from math import atan2, pi, sqrt 
 28   
 29  # relax module imports. 
 30  from lib.periodic_table import periodic_table 
 31   
 32   
33 -def frequency_to_Hz(frq=None, B0=None, isotope=None):
34 """Convert the given frequency from ppm to Hertz units. 35 36 @keyword frq: The frequency in ppm. 37 @type frq: float 38 @keyword B0: The magnetic field strength as the proton frequency in Hertz. 39 @type B0: float 40 @keyword isotope: The isotope type of the nucleus of interest. 41 @type isotope: str 42 @return: The frequency in Hertz. 43 @rtype: float 44 """ 45 46 # Convert and return. 47 return frq * B0 / periodic_table.gyromagnetic_ratio('1H') * periodic_table.gyromagnetic_ratio(isotope) * 1e-6
48 49
50 -def frequency_to_ppm(frq=None, B0=None, isotope=None):
51 """Convert the given frequency from Hertz to ppm units. 52 53 @keyword frq: The frequency in Hertz. 54 @type frq: float 55 @keyword B0: The magnetic field strength as the proton frequency in Hertz. 56 @type B0: float 57 @keyword isotope: The isotope type of the nucleus of interest. 58 @type isotope: str 59 @return: The frequency in ppm. 60 @rtype: float 61 """ 62 63 # Convert and return. 64 return frq / B0 * periodic_table.gyromagnetic_ratio('1H') / periodic_table.gyromagnetic_ratio(isotope) / 1e-6
65 66
67 -def frequency_to_ppm_from_rad(frq=None, B0=None, isotope=None):
68 """Convert the given frequency from rad/s to ppm units. 69 70 @keyword frq: The frequency in rad/s. 71 @type frq: float 72 @keyword B0: The magnetic field strength as the proton frequency in Hertz. 73 @type B0: float 74 @keyword isotope: The isotope type of the nucleus of interest. 75 @type isotope: str 76 @return: The frequency in ppm. 77 @rtype: float 78 """ 79 80 # Convert and return. 81 return frq / (2.0 * pi) / B0 * periodic_table.gyromagnetic_ratio('1H') / periodic_table.gyromagnetic_ratio(isotope) / 1e-6
82 83
84 -def frequency_to_rad_per_s(frq=None, B0=None, isotope=None):
85 """Convert the given frequency from ppm to rad/s units. 86 87 @keyword frq: The frequency in ppm. 88 @type frq: float 89 @keyword B0: The magnetic field strength as the proton frequency in Hertz. 90 @type B0: float 91 @keyword isotope: The isotope type of the nucleus of interest. 92 @type isotope: str 93 @return: The frequency in rad/s. 94 @rtype: float 95 """ 96 97 # Convert and return. 98 return frq * 2.0 * pi * B0 / periodic_table.gyromagnetic_ratio('1H') * periodic_table.gyromagnetic_ratio(isotope) * 1e-6
99 100
101 -def rotating_frame_params(chemical_shift=None, spin_lock_offset=None, omega1=None):
102 """Calculate the rotating frame paramaters. 103 104 @keyword chemical_shift: The chemical shift in rad/s. 105 @type chemical_shift: float 106 @keyword spin_lock_offset: spin-lock offset in rad/s. 107 @type spin_lock_offset: float 108 @keyword omega1: Spin-lock field strength in rad/s. 109 @type omega1: float 110 @return: The average resonance offset in the rotating frame, angle describing the tilted rotating frame relative to the laboratory, effective field in rotating frame. 111 @rtype: float, float, float 112 """ 113 114 # The average resonance offset in the rotating frame. 115 Delta_omega = chemical_shift - spin_lock_offset 116 117 # Calculate the theta angle describing the tilted rotating frame relative to the laboratory. 118 # theta = atan(omega1 / Delta_omega). 119 # If Delta_omega is negative, there follow the symmetry of atan, that atan(-x) = - atan(x). 120 # Then it should be: theta = pi + atan(-x) = pi - atan(x) = pi - abs(atan( +/- x)). 121 # This is taken care of with the atan2(y, x) function, which return atan(y / x), in radians, and the result is between -pi and pi. 122 if Delta_omega == 0.0: 123 theta = pi / 2.0 124 else: 125 theta = atan2(omega1, Delta_omega) 126 127 # Calculate effective field in rotating frame. 128 w_eff = sqrt( Delta_omega*Delta_omega + omega1*omega1 ) 129 130 return Delta_omega, theta, w_eff
131