Author: bugman Date: Wed Dec 4 19:19:04 2013 New Revision: 21785 URL: http://svn.gna.org/viewcvs/relax?rev=21785&view=rev Log: Created the new lib.nmr relax library module. This currently has a few simple functions for converting between ppm units and Hertz or rad/s units. Added: trunk/lib/nmr.py Modified: trunk/lib/__init__.py Modified: trunk/lib/__init__.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/__init__.py?rev=21785&r1=21784&r2=21785&view=diff ============================================================================== --- trunk/lib/__init__.py (original) +++ trunk/lib/__init__.py Wed Dec 4 19:19:04 2013 @@ -41,6 +41,7 @@ 'list', 'mathematics', 'model_selection', + 'nmr', 'order', 'periodic_table', 'physical_constants', Added: trunk/lib/nmr.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/nmr.py?rev=21785&view=auto ============================================================================== --- trunk/lib/nmr.py (added) +++ trunk/lib/nmr.py Wed Dec 4 19:19:04 2013 @@ -1,0 +1,80 @@ +############################################################################### +# # +# Copyright (C) 2013 Edward d'Auvergne # +# # +# This file is part of the program relax (http://www.nmr-relax.com). # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <http://www.gnu.org/licenses/>. # +# # +############################################################################### + +# Module docstring. +"""Module containing functions related to basic NMR concepts.""" + +# Python module imports. +from math import pi + +# relax module imports. +from lib.physical_constants import g1H, return_gyromagnetic_ratio + + +def frequency_to_Hz(frq=None, B0=None, isotope=None): + """Convert the given frequency from ppm to Hertz units. + + @keyword frq: The frequency in ppm. + @type frq: float + @keyword B0: The magnetic field strength as the proton frequency in Hertz. + @type B0: float + @keyword isotope: The isotope type of the nucleus of interest. + @type isotope: str + @return: The frequency in Hertz. + @rtype: float + """ + + # Convert and return. + return frq * B0 / g1H * return_gyromagnetic_ratio(isotope) * 1e-6 + + +def frequency_to_ppm(frq=None, B0=None, isotope=None): + """Convert the given frequency from Hertz to ppm units. + + @keyword frq: The frequency in Hertz. + @type frq: float + @keyword B0: The magnetic field strength as the proton frequency in Hertz. + @type B0: float + @keyword isotope: The isotope type of the nucleus of interest. + @type isotope: str + @return: The frequency in ppm. + @rtype: float + """ + + # Convert and return. + return frq / B0 * g1H / return_gyromagnetic_ratio(isotope) / 1e-6 + + +def frequency_to_rad_per_s(frq=None, B0=None, isotope=None): + """Convert the given frequency from ppm to rad/s units. + + @keyword frq: The frequency in ppm. + @type frq: float + @keyword B0: The magnetic field strength as the proton frequency in Hertz. + @type B0: float + @keyword isotope: The isotope type of the nucleus of interest. + @type isotope: str + @return: The frequency in rad/s. + @rtype: float + """ + + # Convert and return. + return frq * 2.0 * pi * B0 / g1H * return_gyromagnetic_ratio(isotope) * 1e-6