garlic#

Isotropic and fast-motion CW EPR spectra of radicals in solution.

torchspin.garlic(sys_or_list, exp, opt=None)[source]#

Isotropic or fast-motion CW EPR spectrum of S = 1/2 systems in solution.

Simulates the spectrum of one electron spin S = 1/2 with isotropic g and hyperfine couplings, either in the isotropic limit (no correlation time) or in the fast-motion regime (Sys.tcorr/Sys.logtcorr set), where every hyperfine line gets its own Kivelson/Freed Lorentzian width. Field sweeps and frequency sweeps are supported.

Parameters:
  • sys_or_list (SpinSystem or list of SpinSystem) –

    One spin system or a list of components. Every component is expanded into its isotopologues (element symbols such as 'Cu' use natural abundances, '(63,65)Cu' uses Sys.Abund), each is simulated and the spectra are summed with weight Sys.weight × abundance. Fields read from each system:

    • S: must be a single electron spin 1/2.

    • g: line positions use the isotropic value (mean of the principal values, or of the eigenvalues of a full matrix); the fast-motion widths use the full tensor.

    • Nucs, n (equivalent nuclei per entry, isotropic limit only), A (MHz; isotropic mean for the positions, anisotropic part for the fast-motion widths), gnscale; Q (MHz) enters only the fast-motion widths.

    • lw / lwpp: [GaussianFWHM, LorentzianFWHM], in mT for field sweeps and in MHz for frequency sweeps. In the fast-motion regime the Lorentzian part is added to every motional width and the Gaussian part is convolved.

    • tcorr (s) or logtcorr (log10 of s): rotational correlation time; selects the fast-motion regime when > 0. Must lie in [1e-13, 1e-3] s. Diff/logDiff (isotropic rotational diffusion rate, s^-1) may be given instead: tcorr = 1/(6 Diff).

    • gFrame, AFrame: tensor orientations, used by the fast-motion widths (which depend on the relative orientation of g and A).

    • weight, Abund: component weight and custom isotope abundances.

    Not used: QFrame (the quadrupole term depends only on the Q principal values), D, strains, sigma, initState. Rejected (ValueError): nonzero ee or nn, Ham, H0Extra.

  • exp (Experiment) – Field sweep: mwFreq (GHz) with Range or CenterSweep (mT). Frequency sweep: Field (mT, > 0) with mwRange or mwCenterSweep (GHz); also selected when Field is set and mwFreq is not. The sweep range may be omitted (single isotopologue only): it is then set from the line positions and widths (EasySpin’s automatic range, padded by Options.Stretch). Also read: nPoints; Harmonic (0, 1, 2; falls back to 0 when no broadening is given); ModAmp (mT, peak-to-peak field modulation, field sweeps only, requires Harmonic >= 1); mwPhase (rad, requires AccumMethod='explicit', the fast-motion default); Temperature (K; multiplies the intensities by the Boltzmann polarization, None or inf = no factor); Mode or mwMode ('perpendicular', or 'parallel', which gives an all-zero spectrum for S = 1/2; mwMode overrides Mode, other mwMode geometries raise NotImplementedError). Not used: SampleFrame, CrystalSymmetry, MolFrame, SampleRotation, Ordering, lightBeam, lightScatter, ExciteWidth, Orientations, OrientationWeights.

  • opt (Options, optional) –

    Default None = Options(). Fields read:

    • Method: 'exact' (Breit–Rabi, default; the Options default 'matrix' also means 'exact' here), 'perturb' (5th order) or 'perturb1'–'perturb5'. 'hybrid' raises.

    • AccumMethod: None (auto: 'binning' in the isotropic limit, 'explicit' in the fast-motion regime), 'binning', 'linear' (differentiable; chosen automatically instead of 'binning' when g, A, Q, tcorr or lw require grad) or 'explicit' (per-line Lorentzians).

    • Accuracy (default 1e-12) and MaxIterations (default 15): convergence controls of the Breit–Rabi / Newton solvers.

    • Stretch (automatic range padding), IsoCutoff (isotopologue abundance cutoff), separate (only 'components' is honored), Verbosity (>= 1 prints progress), QuadraticZeeman.

    Not used: grid, transition, hybrid and device options.

Returns:

  • x (torch.Tensor, shape (nPoints,)) – Abscissa, float64 on the CPU: magnetic field in mT for field sweeps, microwave frequency in GHz for frequency sweeps.

  • spec (torch.Tensor, shape (nPoints,) or (nComponents, nPoints)) – Spectrum (EasySpin’s garlic intensity scale, arbitrary units) at the requested harmonic. With Options(separate='components') one row per component and isotopologue, each already multiplied by its weight. On the autograd graph when inputs require grad.

Raises:
  • ValueError – System not a single S = 1/2, nonzero ee/nn, Ham, H0Extra, nuclei with I = 0 or zero isotropic coupling, Field <= 0, missing mwFreq for a field sweep, automatic range with several components, tcorr outside [1e-13, 1e-3] s, equivalent nuclei (n > 1) in the fast-motion regime, isotropic g and A without Q in the fast-motion regime, unknown Method (incl. 'hybrid'), 'binning' in the fast-motion regime, 'explicit' with a zero Lorentzian width, ModAmp with a frequency sweep, with Harmonic=0 or without broadening, Mode other than perpendicular/parallel, Temperature <= 0, negative line widths, or a Breit–Rabi/Newton solver that does not converge (hyperfine coupling too large for the microwave frequency: use torchspin.pepper()).

  • NotImplementedError – mwPhase != 0 with AccumMethod 'binning'/'linear', or Options.QuadraticZeeman=True with field-quadratic Sys.Ham terms.

Return type:

Tuple[Tensor, Tensor]

See also

torchspin.pepper

Rigid-limit (powder, crystal) spectra.

torchspin.chili

Slow-motion spectra (tcorr above about 1e-8 s).

torchspin.fastmotion

The fast-motion line widths alone.

Notes

Line positions are the exact Breit–Rabi solution by default and agree with EasySpin (MATLAB-validated to cosine similarity > 0.999). The algorithm and the accuracy of the perturbation orders are described in the module docstring. See KNOWN_LIMITATIONS.md, “Garlic — what is and is not ported”.

Examples

Nitroxide in the fast-motion regime:

>>> from torchspin import SpinSystem, Experiment, Options, garlic
>>> sys = SpinSystem(S=0.5, g=[2.0088, 2.0061, 2.0027], Nucs='14N',
...                  A=[16, 16, 95], tcorr=1e-10, lw=[0.05, 0.0])
>>> exp = Experiment(mwFreq=9.5, Range=[332, 346], nPoints=1024)
>>> B, spc = garlic(sys, exp)
>>> B.shape, spc.shape
(torch.Size([1024]), torch.Size([1024]))

Methyl radical (three equivalent protons) in the isotropic limit, second-order perturbation theory, automatic field range:

>>> sys = SpinSystem(S=0.5, g=2.0026, Nucs='1H', n=[3], A=65, lw=[0, 0.1])
>>> B, spc = garlic(sys, Experiment(mwFreq=9.7, nPoints=512),
...                 Options(Method='perturb2'))
>>> spc.shape
torch.Size([512])

Frequency sweep at a fixed field (line widths in MHz, axis in GHz):

>>> sys = SpinSystem(S=0.5, g=2.0, Nucs='1H', A=50, lw=[1.0, 0.0])
>>> nu, spc = garlic(sys, Experiment(Field=340, mwRange=[9.4, 9.6], nPoints=512))
>>> round(float(nu[0]), 3), round(float(nu[-1]), 3)
(9.4, 9.6)

See also

chili() for the slow-motion regime, fastmotion() for the fast-motion line widths on their own, and TorchSpin — EPR Simulation Quickstart for a worked example.