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

Source Code for Module lib.nmr

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