1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module containing functions related to basic NMR concepts."""
25
26
27 from math import atan2, pi, sqrt
28
29
30 from lib.periodic_table import periodic_table
31
32
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
47 return frq * B0 / periodic_table.gyromagnetic_ratio('1H') * periodic_table.gyromagnetic_ratio(isotope) * 1e-6
48
49
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
64 return frq / B0 * periodic_table.gyromagnetic_ratio('1H') / periodic_table.gyromagnetic_ratio(isotope) / 1e-6
65
66
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
81 return frq / (2.0 * pi) / B0 * periodic_table.gyromagnetic_ratio('1H') / periodic_table.gyromagnetic_ratio(isotope) / 1e-6
82
83
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
98 return frq * 2.0 * pi * B0 / periodic_table.gyromagnetic_ratio('1H') * periodic_table.gyromagnetic_ratio(isotope) * 1e-6
99
100
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
115 Delta_omega = chemical_shift - spin_lock_offset
116
117
118
119
120
121
122 if Delta_omega == 0.0:
123 theta = pi / 2.0
124 else:
125 theta = atan2(omega1, Delta_omega)
126
127
128 w_eff = sqrt( Delta_omega*Delta_omega + omega1*omega1 )
129
130 return Delta_omega, theta, w_eff
131