def test_sim_coesite():
    # coesite
    O17_1 = Site(
        isotope="17O",
        isotropic_chemical_shift=29,
        quadrupolar=dict(Cq=6.05e6, eta=0.000),
    )
    O17_2 = Site(
        isotope="17O",
        isotropic_chemical_shift=41,
        quadrupolar=dict(Cq=5.43e6, eta=0.166),
    )
    O17_3 = Site(
        isotope="17O",
        isotropic_chemical_shift=57,
        quadrupolar=dict(Cq=5.45e6, eta=0.168),
    )
    O17_4 = Site(
        isotope="17O",
        isotropic_chemical_shift=53,
        quadrupolar=dict(Cq=5.52e6, eta=0.169),
    )
    O17_5 = Site(
        isotope="17O",
        isotropic_chemical_shift=58,
        quadrupolar=dict(Cq=5.16e6, eta=0.292),
    )

    sites = [O17_1, O17_2, O17_3, O17_4, O17_5]
    abundance = [0.83, 1.05, 2.16, 2.05, 1.90]  # abundance of each spin system
    spin_systems = [
        SpinSystem(sites=[s], abundance=a) for s, a in zip(sites, abundance)
    ]

    method = BlochDecayCTSpectrum(
        channels=["17O"],
        rotor_frequency=14000,
        spectral_dimensions=[{
            "count": 2048,
            "spectral_width": 50000
        }],
    )

    sim_coesite = Simulator()
    sim_coesite.spin_systems += spin_systems
    sim_coesite.methods += [method]

    sim_coesite.save("sample.mrsim")
    sim_load = Simulator.load("sample.mrsim")
    assert sim_coesite == sim_load

    os.remove("sample.mrsim")
def test_7():
    site = Site(isotope="23Na")
    sys = SpinSystem(sites=[site], abundance=50)
    sim = Simulator()
    sim.spin_systems = [sys, sys]
    sim.methods = [BlochDecayCTSpectrum(channels=["23Na"])]
    sim.methods[0].experiment = cp.as_csdm(np.zeros(1024))

    processor = sp.SignalProcessor(operations=[
        sp.IFFT(dim_index=0),
        sp.apodization.Gaussian(FWHM="0.2 kHz", dim_index=0),
        sp.FFT(dim_index=0),
    ])

    def test_array():
        sim.run()
        data = processor.apply_operations(sim.methods[0].simulation)

        data_sum = 0
        for dv in data.y:
            data_sum += dv.components[0]

        params = sf.make_LMFIT_params(sim, processor)
        a = sf.LMFIT_min_function(params, sim, processor)
        np.testing.assert_almost_equal(-a, data_sum, decimal=8)

        dat = sf.add_csdm_dvs(data.real)
        fits = sf.bestfit(sim, processor)
        assert sf.add_csdm_dvs(fits[0]) == dat

        res = sf.residuals(sim, processor)
        assert res[0] == -dat

    test_array()

    sim.config.decompose_spectrum = "spin_system"
    test_array()
def setup_simulator():
    site = Site(
        isotope="23Na",
        isotropic_chemical_shift=32,
        shielding_symmetric={
            "zeta": -120,
            "eta": 0.1
        },
        quadrupolar={
            "Cq": 1e5,
            "eta": 0.31,
            "beta": 5.12
        },
    )
    sys = SpinSystem(sites=[site], abundance=0.123)
    sim = Simulator()
    sim.spin_systems.append(sys)
    sim.methods.append(
        BlochDecayCTSpectrum(channels=["2H"], rotor_frequency=1e3))
    sim.methods.append(
        BlochDecaySpectrum(channels=["2H"], rotor_frequency=12.5e3))
    sim.methods.append(ThreeQ_VAS(channels=["27Al"]))
    sim.methods.append(SSB2D(channels=["17O"], rotor_frequency=35500))
    return sim
systems = single_site_system_generator(isotopes="71Ga",
                                       quadrupolar={
                                           "Cq": cq_dist * 1e6,
                                           "eta": e_dist
                                       },
                                       abundance=amp)

# %%
# Create a simulator object and add the above system.
sim = Simulator()
sim.spin_systems = systems  # add the systems
sim.methods = [
    BlochDecayCTSpectrum(
        channels=["71Ga"],
        magnetic_flux_density=9.4,  # in T
        spectral_dimensions=[{
            "count": 2048,
            "spectral_width": 2e5
        }],
    )
]  # add the method
sim.run()

# %%
# The following is a static spectrum arising from an extended Czjzek distribution of
# the second-rank traceless EFG tensors.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(sim.methods[0].simulation, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
plt.show()
        "eta": 0.15,
        "alpha": 5 * np.pi / 180,
        "beta": np.pi / 2,
        "gamma": 70 * np.pi / 180,
    },
)
spin_system = SpinSystem(sites=[site])

# %%
# **Step 2:** Create a central transition selective Bloch decay spectrum method.
method = BlochDecayCTSpectrum(
    channels=["17O"],
    magnetic_flux_density=11.74,  # in T
    rotor_frequency=0,  # in Hz
    spectral_dimensions=[{
        "count": 1024,
        "spectral_width": 1e5,  # in Hz
        "reference_offset": 22500,  # in Hz
        "label": r"$^{17}$O resonances",
    }],
)

# %%
# **Step 3:** Create the Simulator object and add method and spin system objects.
sim = Simulator()
sim.spin_systems = [spin_system]  # add the spin system
sim.methods = [method]  # add the method

# Since the spin system have non-zero Euler angles, set the integration_volume to
# hemisphere.
sim.config.integration_volume = "hemisphere"
Example #6
0
# %%
# **Step 2:** Create the spin systems from these sites. For optimum performance, we
# create five single-site spin systems instead of a single five-site spin system. The
# abundance of each spin system is taken from above reference.
abundance = [0.83, 1.05, 2.16, 2.05, 1.90]
spin_systems = [SpinSystem(sites=[s], abundance=a) for s, a in zip(sites, abundance)]

# %%
# **Step 3:** Create a central transition selective Bloch decay spectrum method.
method = BlochDecayCTSpectrum(
    channels=["17O"],
    rotor_frequency=14000,  # in Hz
    spectral_dimensions=[
        {
            "count": 2048,
            "spectral_width": 50000,  # in Hz
            "label": r"$^{17}$O resonances",
        }
    ],
)

# %%
# The above method is set up to record the :math:`^{17}\text{O}` resonances at the
# magic angle, spinning at 14 kHz and 9.4 T (default, if the value is not provided)
# external magnetic flux density. The resonances are recorded over 50 kHz spectral
# width using 2048 points.

# %%
# **Step 4:** Create the Simulator object and add the method and spin system objects.
sim = Simulator()
Example #7
0
systems = single_site_system_generator(isotopes="71Ga",
                                       quadrupolar={
                                           "Cq": cq_dist * 1e6,
                                           "eta": e_dist
                                       },
                                       abundance=amp)

# %%
# Create a simulator object and add the above system.
sim = Simulator()
sim.spin_systems = systems  # add the systems
sim.methods = [
    BlochDecayCTSpectrum(
        channels=["71Ga"],
        magnetic_flux_density=4.8,  # in T
        spectral_dimensions=[{
            "count": 2048,
            "spectral_width": 1.2e6
        }],
    )
]  # add the method
sim.run()

# %%
# The following is the static spectrum arising from a Czjzek distribution of the
# second-rank traceless EFG tensors.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(sim.methods[0].simulation, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
plt.show()
Example #8
0
def test_DAS():
    B0 = 11.7
    das = Method2D(
        channels=["17O"],
        magnetic_flux_density=B0,  # in T
        spectral_dimensions=[
            {
                "count":
                912,
                "spectral_width":
                5e3,  # in Hz
                "reference_offset":
                0,  # in Hz
                "label":
                "DAS isotropic dimension",
                "events": [
                    {
                        "fraction": 0.5,
                        "rotor_angle": 37.38 * 3.14159 / 180,
                        "transition_query": [{
                            "P": [-1],
                            "D": [0]
                        }],
                    },
                    {
                        "fraction": 0.5,
                        "rotor_angle": 79.19 * 3.14159 / 180,
                        "transition_query": [{
                            "P": [-1],
                            "D": [0]
                        }],
                    },
                ],
            },
            # The last spectral dimension block is the direct-dimension
            {
                "count":
                2048,
                "spectral_width":
                2e4,  # in Hz
                "reference_offset":
                0,  # in Hz
                "label":
                "MAS dimension",
                "events": [{
                    "rotor_angle": 54.735 * 3.14159 / 180,
                    "transition_query": [{
                        "P": [-1],
                        "D": [0]
                    }],
                }],
            },
        ],
    )

    sim = Simulator()
    sim.spin_systems = spin_systems  # add spin systems
    sim.methods = [das]  # add the method.
    sim.config.decompose_spectrum = "spin_system"
    sim.run(pack_as_csdm=False)

    data_das = sim.methods[0].simulation
    data_das_coords_ppm = das.spectral_dimensions[0].coordinates_ppm()

    # Bloch decay central transition method
    bloch = BlochDecayCTSpectrum(
        channels=["17O"],
        magnetic_flux_density=B0,  # in T
        rotor_frequency=1e9,  # in Hz
        rotor_angle=54.735 * 3.14159 / 180,
        spectral_dimensions=[
            {
                "count": 2048,
                "spectral_width": 2e4,  # in Hz
                "reference_offset": 0,  # in Hz
                "label": "MAS dimension",
            },
        ],
    )

    sim = Simulator()
    sim.spin_systems = spin_systems
    sim.methods = [bloch]
    sim.config.decompose_spectrum = "spin_system"
    sim.run(pack_as_csdm=False)

    data_bloch = sim.methods[0].simulation

    larmor_freq = das.channels[0].gyromagnetic_ratio * B0 * 1e6
    spin = das.channels[0].spin
    for i, sys in enumerate(spin_systems):
        for site in sys.sites:
            Cq = site.quadrupolar.Cq
            eta = site.quadrupolar.eta
            iso = site.isotropic_chemical_shift
            factor1 = -(3 / 40) * (Cq / larmor_freq)**2
            factor2 = (spin * (spin + 1) - 3 / 4) / (spin**2 *
                                                     (2 * spin - 1)**2)
            factor3 = 1 + (eta**2) / 3
            iso_obs = factor1 * factor2 * factor3 * 1e6 + iso

            # get the index where there is a signal
            id1 = data_das[i] / data_das[i].max()
            index = np.where(id1 == id1.max())[0]
            iso_spectrum = data_das_coords_ppm[
                index[0]]  # x[1].coords[index[0]]

            # test for the position of isotropic peaks.
            np.testing.assert_almost_equal(iso_obs, iso_spectrum, decimal=1)

            # test for the spectrum across the isotropic peaks.
            data_bloch_i = data_bloch[i] / data_bloch[i].max()
            assert np.allclose(id1[index[0]], data_bloch_i)
# channels, the magnetic flux density, rotor angle, rotor frequency, and the
# spectral/spectroscopic dimension.
#
# In the following example, we set up a central transition selective Bloch decay
# spectrum method where the spectral/spectroscopic dimension information, i.e., count,
# spectral_width, and the reference_offset, is extracted from the CSDM dimension
# metadata using the :func:`~mrsimulator.utils.get_spectral_dimensions` utility
# function. The remaining attribute values are set to the experimental conditions.

# get the count, spectral_width, and reference_offset information from the experiment.
spectral_dims = get_spectral_dimensions(experiment)

MAS_CT = BlochDecayCTSpectrum(
    channels=["17O"],
    magnetic_flux_density=9.395,  # in T
    rotor_frequency=14000,  # in Hz
    spectral_dimensions=spectral_dims,
    experiment=experiment,  # experimental dataset
)

# A method object queries every spin system for a list of transition pathways that are
# relevant for the given method. Since the method and the number of spin systems remain
# the same during the least-squares fit, a one-time query is sufficient. To avoid
# querying for the transition pathways at every iteration in a least-squares fitting,
# evaluate the transition pathways once and store it as follows
for sys in spin_systems:
    sys.transition_pathways = MAS_CT.get_transition_pathways(sys)

# %%
# **Step 3:** Create the Simulator object and add the method and spin system objects.
sim = Simulator(spin_systems=spin_systems, methods=[MAS_CT])
Example #10
0
def test_MQMAS():
    site = Site(
        isotope="87Rb",
        isotropic_chemical_shift=-9,
        shielding_symmetric={
            "zeta": 100,
            "eta": 0
        },
        quadrupolar={
            "Cq": 3.5e6,
            "eta": 0.36,
            "beta": 70 / 180 * np.pi
        },
    )
    spin_system = SpinSystem(sites=[site])

    method = Method2D(
        channels=["87Rb"],
        magnetic_flux_density=9.4,
        spectral_dimensions=[
            {
                "count": 128,
                "spectral_width": 20000,
                "events": [{
                    "transition_query": [{
                        "P": [-3],
                        "D": [0]
                    }]
                }],
            },
            {
                "count": 128,
                "spectral_width": 20000,
                "events": [{
                    "transition_query": [{
                        "P": [-1],
                        "D": [0]
                    }]
                }],
            },
        ],
    )

    sim = Simulator()
    sim.spin_systems = [spin_system]
    sim.methods = [method]
    sim.config.integration_volume = "hemisphere"
    sim.run()

    # process
    k = 21 / 27  # shear factor
    processor = sp.SignalProcessor(operations=[
        sp.IFFT(dim_index=1),
        aft.Shear(factor=-k, dim_index=1, parallel=0),
        aft.Scale(factor=1 + k, dim_index=1),
        sp.FFT(dim_index=1),
    ])
    processed_data = processor.apply_operations(
        data=sim.methods[0].simulation).real

    # Since there is a single site, after the shear and scaling transformations, there
    # should be a single perak along the isotropic dimension at index 70.
    # The isotropic coordinate of this peak is given by
    # w_iso = (17.8)*iso_shift + 1e6/8 * (vq/v0)^2 * (eta^2 / 3 + 1)
    # ref: D. Massiot et al. / Solid State Nuclear Magnetic Resonance 6 (1996) 73-83
    iso_slice = processed_data[40, :]
    assert np.argmax(iso_slice.y[0].components[0]) == 70

    # calculate the isotropic coordinate
    spin = method.channels[0].spin
    w0 = method.channels[0].gyromagnetic_ratio * 9.4 * 1e6
    wq = 3 * 3.5e6 / (2 * spin * (2 * spin - 1))
    w_iso = -9 * 17 / 8 + 1e6 / 8 * (wq / w0)**2 * ((0.36**2) / 3 + 1)

    # the coordinate from spectrum
    w_iso_spectrum = processed_data.x[1].coordinates[70].value
    np.testing.assert_almost_equal(w_iso, w_iso_spectrum, decimal=2)

    # The projection onto the  MAS dimension should be the 1D block decay central
    # transition spectrum
    mas_slice = processed_data.sum(axis=1).y[0].components[0]

    # MAS spectrum
    method = BlochDecayCTSpectrum(
        channels=["87Rb"],
        magnetic_flux_density=9.4,
        rotor_frequency=1e9,
        spectral_dimensions=[{
            "count": 128,
            "spectral_width": 20000
        }],
    )

    sim = Simulator()
    sim.spin_systems = [spin_system]
    sim.methods = [method]
    sim.config.integration_volume = "hemisphere"
    sim.run()

    data = sim.methods[0].simulation.y[0].components[0]
    np.testing.assert_almost_equal(data / data.max(),
                                   mas_slice / mas_slice.max(),
                                   decimal=2,
                                   err_msg="not equal")
Example #11
0
# **Step 2:** Create the spin systems from these sites. For optimum performance, we
# create five single-site spin systems instead of a single five-site spin system. The
# abundance of each spin system is taken from above reference. Here we are iterating
# over both the *sites* and *abundance* list concurrently using a list comprehension
# to construct a list of SpinSystens
abundance = [0.83, 1.05, 2.16, 2.05, 1.90]
spin_systems = [SpinSystem(sites=[s], abundance=a) for s, a in zip(sites, abundance)]

# %%
# **Step 3:** Create a central transition selective Bloch decay spectrum method.
method = BlochDecayCTSpectrum(
    channels=["17O"],
    rotor_frequency=14000,  # in Hz
    spectral_dimensions=[
        dict(
            count=2048,
            spectral_width=50000,  # in Hz
            label=r"$^{17}$O resonances",
        )
    ],
)

# %%
# The above method is set up to record the :math:`^{17}\text{O}` resonances at the
# magic angle, spinning at 14 kHz and 9.4 T (default, if the value is not provided)
# external magnetic flux density. The resonances are recorded over 50 kHz spectral
# width using 2048 points.

# %%
# **Step 4:** Create the Simulator object and add the method and spin system objects.
sim = Simulator()
        "Cq": 2.3e6,
        "eta": 0.03
    },  # Cq in Hz
)
spin_systems = [SpinSystem(sites=[Na23])]

# %%
# **Method**

# Get the spectral dimension parameters from the experiment.
spectral_dims = get_spectral_dimensions(experiment)

MAS_CT = BlochDecayCTSpectrum(
    channels=["23Na"],
    magnetic_flux_density=9.395,  # in T
    rotor_frequency=15000,  # in Hz
    spectral_dimensions=spectral_dims,
    experiment=experiment,  # add the measurement to the method.
)

# Optimize the script by pre-setting the transition pathways for each spin system from
# the method.
for sys in spin_systems:
    sys.transition_pathways = MAS_CT.get_transition_pathways(sys)

# %%
# **Guess Model Spectrum**

# Simulation
# ----------
sim = Simulator(spin_systems=spin_systems, methods=[MAS_CT])
Example #13
0
        alpha=5 * np.pi / 180,
        beta=np.pi / 2,
        gamma=70 * np.pi / 180,
    ),
)
spin_system = SpinSystem(sites=[site])

# %%
# **Step 2:** Create a central transition selective Bloch decay spectrum method.
method = BlochDecayCTSpectrum(
    channels=["17O"],
    magnetic_flux_density=11.74,  # in T
    rotor_frequency=0,  # in Hz
    spectral_dimensions=[
        dict(
            count=1024,
            spectral_width=1e5,  # in Hz
            reference_offset=22500,  # in Hz
            label=r"$^{17}$O resonances",
        )
    ],
)

# %%
# **Step 3:** Create the Simulator object and add method and spin system objects.
sim = Simulator()
sim.spin_systems = [spin_system]  # add the spin system
sim.methods = [method]  # add the method

# Since the spin system have non-zero Euler angles, set the integration_volume to
# hemisphere.
Example #14
0
def add_site(doctest_namespace):

    doctest_namespace["np"] = np
    doctest_namespace["plt"] = plt
    doctest_namespace["SpinSystem"] = SpinSystem
    doctest_namespace["Simulator"] = Simulator
    doctest_namespace["Site"] = Site
    doctest_namespace["Coupling"] = Coupling
    doctest_namespace["SymmetricTensor"] = SymmetricTensor
    doctest_namespace["st"] = SymmetricTensor
    doctest_namespace["pprint"] = pprint
    doctest_namespace["Isotope"] = Isotope
    doctest_namespace["sp"] = sp
    doctest_namespace["Method2D"] = Method2D

    site1 = Site(
        isotope="13C",
        isotropic_chemical_shift=20,
        shielding_symmetric=SymmetricTensor(zeta=10, eta=0.5),
    )
    doctest_namespace["site1"] = site1

    coupling1 = Coupling(
        site_index=[0, 1],
        isotropic_j=20,
        j_symmetric=SymmetricTensor(zeta=10, eta=0.5),
    )
    doctest_namespace["coupling1"] = coupling1

    site2 = Site(
        isotope="1H",
        isotropic_chemical_shift=-4,
        shielding_symmetric=SymmetricTensor(zeta=2.1, eta=0.1),
    )
    doctest_namespace["site2"] = site2

    site3 = Site(
        isotope="27Al",
        isotropic_chemical_shift=120,
        shielding_symmetric=SymmetricTensor(zeta=2.1, eta=0.1),
        quadrupole=SymmetricTensor(Cq=5.1e6, eta=0.5),
    )
    doctest_namespace["site3"] = site3

    spin_system_1H_13C = SpinSystem(sites=[site1, site2])
    doctest_namespace["spin_system_1H_13C"] = spin_system_1H_13C

    spin_system_1 = SpinSystem(sites=[site1])
    doctest_namespace["spin_system_1"] = spin_system_1

    doctest_namespace["spin_systems"] = SpinSystem(sites=[site1, site2, site3])

    spin_systems = [SpinSystem(sites=[site]) for site in [site1, site2, site3]]

    sim = Simulator()
    sim.spin_systems += spin_systems
    doctest_namespace["sim"] = sim

    # coesite
    O17_1 = Site(
        isotope="17O",
        isotropic_chemical_shift=29,
        quadrupolar=SymmetricTensor(Cq=6.05e6, eta=0.000),
    )
    O17_2 = Site(
        isotope="17O",
        isotropic_chemical_shift=41,
        quadrupolar=SymmetricTensor(Cq=5.43e6, eta=0.166),
    )
    O17_3 = Site(
        isotope="17O",
        isotropic_chemical_shift=57,
        quadrupolar=SymmetricTensor(Cq=5.45e6, eta=0.168),
    )
    O17_4 = Site(
        isotope="17O",
        isotropic_chemical_shift=53,
        quadrupolar=SymmetricTensor(Cq=5.52e6, eta=0.169),
    )
    O17_5 = Site(
        isotope="17O",
        isotropic_chemical_shift=58,
        quadrupolar=SymmetricTensor(Cq=5.16e6, eta=0.292),
    )

    sites = [O17_1, O17_2, O17_3, O17_4, O17_5]
    abundance = [0.83, 1.05, 2.16, 2.05, 1.90]  # abundance of each spin system
    spin_systems = [
        SpinSystem(sites=[s], abundance=a) for s, a in zip(sites, abundance)
    ]

    method = BlochDecayCTSpectrum(
        channels=["17O"],
        rotor_frequency=14000,
        spectral_dimensions=[{
            "count": 2048,
            "spectral_width": 50000
        }],
    )

    sim_coesite = Simulator()
    sim_coesite.spin_systems += spin_systems
    sim_coesite.methods += [method]

    doctest_namespace["sim_coesite"] = sim_coesite

    # Transitions
    t1 = Transition(initial=[0.5, 0.5], final=[0.5, -0.5])
    doctest_namespace["t1"] = t1

    t2 = Transition(initial=[0.5, 0.5], final=[-0.5, 0.5])
    doctest_namespace["t2"] = t2

    path = TransitionPathway([t1, t2])
    doctest_namespace["path"] = path
    name="33S",
    isotope="33S",
    isotropic_chemical_shift=335.7,  # in ppm
    quadrupolar=SymmetricTensor(Cq=0.959e6, eta=0.42),  # Cq is in Hz
)
spin_system = SpinSystem(sites=[site])

# %%
# **Step 2:** Create a central transition selective Bloch decay spectrum method.
method = BlochDecayCTSpectrum(
    channels=["33S"],
    magnetic_flux_density=21.14,  # in T
    rotor_frequency=14000,  # in Hz
    spectral_dimensions=[
        dict(
            count=2048,
            spectral_width=5000,  # in Hz
            reference_offset=22500,  # in Hz
            label=r"$^{33}$S resonances",
        )
    ],
)

# A graphical representation of the method object.
plt.figure(figsize=(4, 3))
method.plot()
plt.show()

# %%
# **Step 3:** Create the Simulator object and add method and spin system objects.
sim = Simulator()
Example #16
0
spin_systems = single_site_system_generator(
    isotope="27Al",
    isotropic_chemical_shift=iso,
    quadrupolar={
        "Cq": Cq * 1e6,
        "eta": eta
    },  # Cq in Hz
    abundance=pdf,
)

# %%
# Static spectrum
# ---------------
# Observe the static :math:`^{27}\text{Al}` NMR spectrum simulation. First,
# create a central transition selective Bloch decay spectrum method.
static_method = BlochDecayCTSpectrum(
    channels=["27Al"], spectral_dimensions=[dict(spectral_width=80000)])

# %%
# Create the simulator object and add the spin systems and method.
sim = Simulator()
sim.spin_systems = spin_systems  # add the spin systems
sim.methods = [static_method]  # add the method
sim.run()

# %%
# The plot of the corresponding spectrum.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(sim.methods[0].simulation.real, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
Example #17
0
def test_ThreeQ_VAS_spin_3halves():
    site = Site(
        isotope="87Rb",
        isotropic_chemical_shift=-9,
        shielding_symmetric={
            "zeta": 100,
            "eta": 0
        },
        quadrupolar={
            "Cq": 3.5e6,
            "eta": 0.36,
            "beta": 70 / 180 * np.pi
        },
    )
    spin_system = SpinSystem(sites=[site])

    method = ThreeQ_VAS(
        channels=["87Rb"],
        magnetic_flux_density=9.4,
        spectral_dimensions=[
            {
                "count": 1024,
                "spectral_width": 20000
            },
            {
                "count": 512,
                "spectral_width": 20000
            },
        ],
    )
    sim = Simulator()
    sim.spin_systems = [spin_system]
    sim.methods = [method]
    sim.config.integration_volume = "hemisphere"
    sim.run()

    data = sim.methods[0].simulation
    dat = data.y[0].components[0]
    index = np.where(dat == dat.max())[0]

    # The isotropic coordinate of this peak is given by
    # v_iso = (17/8)*iso_shift + 1e6/8 * (vq/v0)^2 * (eta^2 / 3 + 1)
    # ref: D. Massiot et al. / Solid State Nuclear Magnetic Resonance 6 (1996) 73-83
    spin = method.channels[0].spin
    v0 = method.channels[0].gyromagnetic_ratio * 9.4 * 1e6
    vq = (3 * 3.5e6) / (2 * spin * (2 * spin - 1))
    v_iso = -9 * 17 / 8 + 1e6 / 8 * ((vq / v0)**2) * ((0.36**2) / 3 + 1)

    # the coordinate from spectrum along the iso dimension must be equal to v_iso
    v_iso_spectrum = data.x[1].coordinates[index[0]].value
    np.testing.assert_almost_equal(v_iso, v_iso_spectrum, decimal=2)

    # The projection onto the  MAS dimension should be the 1D block decay central
    # transition spectrum
    mas_slice = data.sum(axis=1).y[0].components[0]

    # MAS spectrum
    method = BlochDecayCTSpectrum(
        channels=["87Rb"],
        magnetic_flux_density=9.4,
        rotor_frequency=1e9,
        spectral_dimensions=[{
            "count": 512,
            "spectral_width": 20000
        }],
    )

    sim = Simulator()
    sim.spin_systems = [spin_system]
    sim.methods = [method]
    sim.config.integration_volume = "hemisphere"
    sim.run()

    data = sim.methods[0].simulation.y[0].components[0]
    assert np.allclose(data / data.max(), mas_slice / mas_slice.max())
    name="33S",
    isotope="33S",
    isotropic_chemical_shift=335.7,  # in ppm
    quadrupolar={"Cq": 0.959e6, "eta": 0.42},  # Cq is in Hz
)
spin_system = SpinSystem(sites=[site])

# %%
# **Step 2:** Create a central transition selective Bloch decay spectrum method.
method = BlochDecayCTSpectrum(
    channels=["33S"],
    magnetic_flux_density=21.14,  # in T
    rotor_frequency=14000,  # in Hz
    spectral_dimensions=[
        {
            "count": 2048,
            "spectral_width": 5000,  # in Hz
            "reference_offset": 22500,  # in Hz
            "label": r"$^{33}$S resonances",
        }
    ],
)

# %%
# **Step 3:** Create the Simulator object and add method and spin system objects.
sim = Simulator()
sim.spin_systems += [spin_system]  # add the spin system
sim.methods += [method]  # add the method

# %%
# **Step 4:** Simulate the spectrum.
Example #19
0
def test_MQMAS_spin_5halves():
    spin_system = SpinSystem(sites=[
        Site(
            isotope="27Al",
            isotropic_chemical_shift=64.5,  # in ppm
            quadrupolar={
                "Cq": 3.22e6,
                "eta": 0.66
            },  # Cq is in Hz
        )
    ])

    method = ThreeQ_VAS(
        channels=["27Al"],
        magnetic_flux_density=7,
        spectral_dimensions=[
            {
                "count": 1024,
                "spectral_width": 5000,
                "reference_offset": -3e3
            },
            {
                "count": 512,
                "spectral_width": 10000,
                "reference_offset": 4e3
            },
        ],
    )

    sim = Simulator()
    sim.spin_systems = [spin_system]
    sim.methods = [method]
    sim.run()

    data = sim.methods[0].simulation
    dat = data.y[0].components[0]
    index = np.where(dat == dat.max())[0]

    # The isotropic coordinate of this peak is given by
    # v_iso = -(17/31)*iso_shift + 8e6/93 * (vq/v0)^2 * (eta^2 / 3 + 1)
    # ref: D. Massiot et al. / Solid State Nuclear Magnetic Resonance 6 (1996) 73-83
    spin = method.channels[0].spin
    v0 = method.channels[0].gyromagnetic_ratio * 7 * 1e6
    vq = 3 * 3.22e6 / (2 * spin * (2 * spin - 1))
    v_iso = -(17 / 31) * 64.5 - (8e6 / 93) * (vq / v0)**2 * ((0.66**2) / 3 + 1)

    # the coordinate from spectrum along the iso dimension must be equal to v_iso
    v_iso_spectrum = data.x[1].coordinates[index[0]].value
    np.testing.assert_almost_equal(v_iso, v_iso_spectrum, decimal=2)

    # The projection onto the  MAS dimension should be the 1D block decay central
    # transition spectrum
    mas_slice = data.sum(axis=1).y[0].components[0]

    # MAS spectrum
    method = BlochDecayCTSpectrum(
        channels=["27Al"],
        magnetic_flux_density=7,
        rotor_frequency=1e9,
        spectral_dimensions=[{
            "count": 512,
            "spectral_width": 10000,
            "reference_offset": 4e3
        }],
    )

    sim = Simulator()
    sim.spin_systems = [spin_system]
    sim.methods = [method]
    sim.config.integration_volume = "hemisphere"
    sim.run()

    data = sim.methods[0].simulation.y[0].components[0]
    assert np.allclose(data / data.max(), mas_slice / mas_slice.max())
    isotropic_chemical_shifts=iso,
    quadrupolar={
        "Cq": Cq * 1e6,
        "eta": eta
    },  # Cq in Hz
    abundance=pdf,
)

# %%
# Static spectrum
# ---------------
# Observe the static :math:`^{27}\text{Al}` NMR spectrum simulation. First,
# create a central transition selective Bloch decay spectrum method.
static_method = BlochDecayCTSpectrum(channels=["27Al"],
                                     spectral_dimensions=[{
                                         "spectral_width":
                                         80000
                                     }])

# %%
# Create the simulator object and add the spin systems and method.
sim = Simulator()
sim.spin_systems = spin_systems  # add the spin systems
sim.methods = [static_method]  # add the method
sim.run()

# %%
# The plot of the corresponding spectrum.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(sim.methods[0].simulation, color="black", linewidth=1)
Example #21
0
# Simulate the spectrum
# '''''''''''''''''''''
# **Static spectrum**
# Create the spin systems.
systems = single_site_system_generator(
    isotope="71Ga", quadrupolar={"Cq": cq_dist * 1e6, "eta": e_dist}, abundance=amp
)

# %%
# Create a simulator object and add the above system.
sim = Simulator()
sim.spin_systems = systems  # add the systems
sim.methods = [
    BlochDecayCTSpectrum(
        channels=["71Ga"],
        magnetic_flux_density=9.4,  # in T
        spectral_dimensions=[dict(count=2048, spectral_width=2e5)],
    )
]  # add the method
sim.run()

# %%
# The following is a static spectrum arising from an extended Czjzek distribution of
# the second-rank traceless EFG tensors.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(sim.methods[0].simulation.real, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
plt.show()
Example #22
0
# Simulate the spectrum
# '''''''''''''''''''''
#
# Create the spin systems.
systems = single_site_system_generator(
    isotope="71Ga", quadrupolar={"Cq": cq_dist * 1e6, "eta": e_dist}, abundance=amp
)

# %%
# Create a simulator object and add the above system.
sim = Simulator()
sim.spin_systems = systems  # add the systems
sim.methods = [
    BlochDecayCTSpectrum(
        channels=["71Ga"],
        magnetic_flux_density=4.8,  # in T
        spectral_dimensions=[dict(count=2048, spectral_width=1.2e6)],
    )
]  # add the method
sim.run()

# %%
# The following is the static spectrum arising from a Czjzek distribution of the
# second-rank traceless EFG tensors.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(sim.methods[0].simulation.real, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
plt.show()