Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SelectiveFrequencyPulse

A SelectiveFrequencyPulse is defined by an angle an axis and a frequency. To create a selective frequency pulse the easiest way is to use the from_string method of NMRPulse class.

The str format for a selective frequency pulse is the angle followed by the axis then a |, and the frequency followed by the letter f.

The axis can be x, y or z. The angle can be any number and will be interpreted as an angle in degrees or pi expression just like rotation pulses. The frequency can be any float.

This pulse applies an instantaneous rotation to each spin. The angle of this rotation differs for each spin and is calculated based on how close the shift is to the targetted frequency using a gaussian centered on this frequency. So the targeted frequency shouldn’t be the actual frequency of the targeted spin but the difference between its frequency and the larmor frequency of the reference isotope.

The NMRCalculationParameters aswell as the NMRParameters needs to be provided to the apply_pulse_operator for this pulse.

from hqs_nmr.pulse_sequence import NMRPulse

selective_frequency_pulse = NMRPulse.from_string("90y|389f")
selective_frequency_pulse2 = NMRPulse.from_string("-pi/4x|2860.05f")

The user can also control the width of the gaussian by adding {width}w at the end of the string, where {width} is the full width at half maximum (FWHM) of the Gaussian in Hz. The default value is 10 Hz: smaller values produce a narrower, more selective peak, while larger values produce a broader one.

from hqs_nmr.pulse_sequence import NMRPulse

selective_frequency_pulse = NMRPulse.from_string("90y|389f0.005w") # very narrow, will only acts on spins with a shift very close to 389Hz
selective_frequency_pulse = NMRPulse.from_string("90y|389f1w") # wide, will also acts on spins with shifts close to 389Hz

How It Works

The selective frequency pulse applies a rotation to each spin in the system, but with the rotation angle modified based on how close each spin’s frequency is to the target frequency. The angle for each spin is calculated using a Gaussian function:

angle_per_spin[i] = theta * exp(-((shift_Hz[i] - target_Hz)^2) / (2 * sigma^2))

where:

  • theta is the specified rotation angle
  • shift_Hz[i] is the frequency shift of spin i in Hz (converted from ppm)
  • target_Hz is the target frequency
  • sigma is calculated from the fwhm_Hz parameter

The FWHM (Full Width at Half Maximum) in Hz is used directly to calculate sigma:

sigma = fwhm_Hz / (2 * sqrt(2 * ln(2)))

Methods

apply_pulse_operator

def apply_pulse_operator(
    self,
    density_mat: np.ndarray,
    **kwargs: Any,
) -> np.ndarray:
    """Apply the selective frequency pulse P on the density matrix.

    Args:
        density_mat (np.ndarray): The initial density matrix rho_0.
        **kwargs: Additional arguments (all required):
            num_spins (int): The number of spins in the system.
            nmr_parameters (NMRParameters): The NMR parameters containing the chemical 
                shifts (in ppm) for each spin. These are converted to Hz using the 
                calculation parameters.
            calculation_parameters (NMRCalculationParameters): The calculation parameters
                containing the reference frequency and other settings needed to convert
                chemical shifts from ppm to Hz.

    Returns:
        np.ndarray: The transformed density matrix P @ rho_0 @ P†, where P is the 
            product of individual rotation operators for each spin with frequency-dependent
            rotation angles.
        
    Raises:
        ValueError: If num_spins is not provided.
        ValueError: If nmr_parameters or calculation_parameters is not provided.
    """

Example:

from hqs_nmr.pulse_sequence.pulses import SelectiveFrequencyPulse
from hqs_nmr import NMRParameters, NMRCalculationParameters
import numpy as np

# Create a selective frequency pulse targeting 1000 Hz
pulse = SelectiveFrequencyPulse(
    spin_frequency_target_Hz=1000.0,
    theta=90.0,
    axis="x",
    fwhm_Hz=0.1
)

# Set up NMR parameters
nmr_params = NMRParameters(
    shifts=[5.0, 5.5, 6.0],  # Chemical shifts in ppm
    # ... other parameters
)
calc_params = NMRCalculationParameters(
    # ... calculation parameters including reference frequency
)

density_mat = np.eye(8, dtype=complex) / 8  # Example for 3 spins

# Apply the selective pulse
result = pulse.apply_pulse_operator(
    density_mat,
    num_spins=3,
    nmr_parameters=nmr_params,
    calculation_parameters=calc_params
)

get_pulse_operator

def get_pulse_operator(
    self,
    **kwargs: Any,
) -> np.ndarray:
    """Returns the total selective frequency pulse operator.

    Args:
        **kwargs: Additional arguments (all required):
            num_spins (int): The number of spins in the system.
            nmr_parameters (NMRParameters): The NMR parameters containing the chemical 
                shifts (in ppm) for each spin.
            calculation_parameters (NMRCalculationParameters): The calculation parameters
                for converting chemical shifts from ppm to Hz.

    Returns:
        np.ndarray: The total pulse operator P as a (2^num_spins × 2^num_spins) matrix.
            This is the product of all individual spin operators with frequency-dependent
            rotation angles: P = P_spin_n @ ... @ P_spin_1 @ P_spin_0
        
    Raises:
        ValueError: If num_spins is not provided.
        ValueError: If nmr_parameters or calculation_parameters is not provided.
    """

Example:

from hqs_nmr.pulse_sequence.pulses import SelectiveFrequencyPulse
from hqs_nmr import NMRParameters, NMRCalculationParameters

pulse = SelectiveFrequencyPulse(
    spin_frequency_target_Hz=1500.0,
    theta=180.0,
    axis="y",
    fwhm_Hz=0.05  # Narrow selectivity (FWHM in Hz)
)

# Get the pulse operator
P = pulse.get_pulse_operator(
    num_spins=4,
    nmr_parameters=nmr_params,
    calculation_parameters=calc_params
)

# Use it to transform states or density matrices
state = np.array([1, 0, 0, 0, ...], dtype=complex)  # 2^4 = 16 elements
evolved_state = P @ state