Exemplo n.º 1
0
def test_SSB_rotor_freq():
    e = "`rotor_frequency` cannot be zero for SSB2D method."
    with pytest.raises(ValueError, match=f".*{e}.*"):
        SSB2D(channels=["1H"], spectral_dimensions=[{}, {}])

    with pytest.raises(ValueError, match=f".*{e}.*"):
        SSB2D(channels=["1H"], rotor_frequency=0, spectral_dimensions=[{}, {}])
Exemplo n.º 2
0
def test_SSB_general():
    """Inner satellite-transition variable-angle spinning method"""
    mth = SSB2D(
        channels=["87Rb"],
        magnetic_flux_density=9.4,  # in T
        rotor_frequency=1200,
        spectral_dimensions=[
            {"count": 1024, "spectral_width": 5e4},
            {"count": 1024, "spectral_width": 5e4},
        ],
    )
    assert mth.name == "SSB2D"

    assert mth.description == "Simulate a 2D sideband separation method."

    # test transition query
    tq = TransitionQuery(ch1={"P": [-1], "D": [0]})
    assert mth.spectral_dimensions[0].events[0].transition_query[0] == tq
    assert mth.spectral_dimensions[1].events[0].transition_query[0] == tq

    # test rotor_frequency
    assert mth.spectral_dimensions[0].events[0].rotor_frequency == 1200
    assert mth.spectral_dimensions[1].events[0].rotor_frequency == 1e12

    # check serialization
    assert SSB2D.parse_dict_with_units(mth.json()) == mth

    assert np.allclose(mth.affine_matrix, [1, -1, 0.0, 1.0])

    serialize = mth.json()
    _ = serialize.pop("affine_matrix")

    assert serialize == {
        "channels": ["87Rb"],
        "description": mth.description,
        "magnetic_flux_density": "9.4 T",
        "name": "SSB2D",
        "rotor_angle": "0.9553166181245 rad",
        "rotor_frequency": "1200.0 Hz",
        "spectral_dimensions": [
            {
                "count": 1024,
                "spectral_width": "50000.0 Hz",
                "events": [{"transition_query": [{"ch1": {"P": [-1], "D": [0]}}]}],
            },
            {
                "count": 1024,
                "events": [
                    {
                        "rotor_frequency": "1000000000000.0 Hz",
                        "transition_query": [{"ch1": {"P": [-1], "D": [0]}}],
                    }
                ],
                "spectral_width": "50000.0 Hz",
            },
        ],
    }
Exemplo n.º 3
0
def test_SSB_general():
    """Inner satellite-transition variable-angle spinning method"""
    mth = SSB2D(
        channels=["87Rb"],
        magnetic_flux_density=9.4,  # in T
        rotor_frequency=1200,
        spectral_dimensions=[
            {
                "count": 1024,
                "spectral_width": 5e4,  # in Hz
                "reference_offset": 0,  # in Hz
            },
            {
                "count": 1024,
                "spectral_width": 5e4,  # in Hz
                "reference_offset": 0,  # in Hz
            },
        ],
    )
    assert mth.name == "SSB2D"

    assert mth.description == "Simulate a 2D sideband separation method."

    # test transition query
    tq = TransitionQuery(P={"channel-1": [[-1]]}, D={"channel-1": [[0]]})
    assert mth.spectral_dimensions[0].events[0].transition_query == tq
    assert mth.spectral_dimensions[1].events[0].transition_query == tq

    # test rotor_frequency
    assert mth.spectral_dimensions[0].events[0].rotor_frequency == 1200
    assert mth.spectral_dimensions[1].events[0].rotor_frequency == 1e9

    # check serialization
    assert Method.parse_dict_with_units(mth.json()) == mth
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
Exemplo n.º 5
0
def SSB2D_setup(ist, vr, method_type):
    sites = [
        Site(
            isotope=ist,
            isotropic_chemical_shift=29,
            shielding_symmetric={
                "zeta": -70,
                "eta": 0.000
            },
        ),
        Site(
            isotope=ist,
            isotropic_chemical_shift=44,
            shielding_symmetric={
                "zeta": -96,
                "eta": 0.166
            },
        ),
        Site(
            isotope=ist,
            isotropic_chemical_shift=57,
            shielding_symmetric={
                "zeta": -120,
                "eta": 0.168
            },
        ),
    ]
    spin_systems = [SpinSystem(sites=[s]) for s in sites]

    B0 = 11.7
    if method_type == "PASS":
        method = SSB2D(
            channels=[ist],
            magnetic_flux_density=B0,  # in T
            rotor_frequency=vr,
            spectral_dimensions=[
                {
                    "count": 32,
                    "spectral_width": 32 * vr,  # in Hz
                    "label": "Anisotropic dimension",
                },
                # The last spectral dimension block is the direct-dimension
                {
                    "count": 2048,
                    "spectral_width": 2e4,  # in Hz
                    "reference_offset": 5e3,  # in Hz
                    "label": "Fast MAS dimension",
                },
            ],
        )
    else:
        method = Method2D(
            channels=[ist],
            magnetic_flux_density=B0,  # in T
            spectral_dimensions=[
                {
                    "count": 64,
                    "spectral_width": 8e4,  # in Hz
                    "label": "Anisotropic dimension",
                    "events": [{
                        "rotor_angle": 90 * 3.14159 / 180
                    }],
                },
                # The last spectral dimension block is the direct-dimension
                {
                    "count": 2048,
                    "spectral_width": 2e4,  # in Hz
                    "reference_offset": 5e3,  # in Hz
                    "label": "Fast MAS dimension",
                },
            ],
            affine_matrix=[[1, -1], [0, 1]],
        )
    sim = Simulator()
    sim.spin_systems = spin_systems  # add spin systems
    sim.methods = [method]  # add the method.
    sim.run()

    data_ssb = sim.methods[0].simulation
    dim_ssb = data_ssb.x[0].coordinates.value

    if method_type == "PASS":
        bloch = BlochDecaySpectrum(
            channels=[ist],
            magnetic_flux_density=B0,  # in T
            rotor_frequency=vr,  # in Hz
            spectral_dimensions=[
                {
                    "count": 32,
                    "spectral_width": 32 * vr,  # in Hz
                    "reference_offset": 0,  # in Hz
                    "label": "MAS dimension",
                },
            ],
        )
    else:
        bloch = BlochDecaySpectrum(
            channels=[ist],
            magnetic_flux_density=B0,  # in T
            rotor_frequency=vr,  # in Hz
            rotor_angle=90 * 3.14159 / 180,
            spectral_dimensions=[
                {
                    "count": 64,
                    "spectral_width": 8e4,  # in Hz
                    "reference_offset": 0,  # in Hz
                    "label": "MAS dimension",
                },
            ],
        )

    for i in range(3):
        iso = spin_systems[i].sites[0].isotropic_chemical_shift
        sys = spin_systems[i].copy()
        sys.sites[0].isotropic_chemical_shift = 0
        sim2 = Simulator()
        sim2.spin_systems = [sys]  # add spin systems
        sim2.methods = [bloch]  # add the method.
        sim2.run()

        index = np.where(dim_ssb < iso)[0][-1]

        one_d_section = data_ssb.y[0].components[0][:, index]
        one_d_section /= one_d_section.max()

        one_d_sim = sim2.methods[0].simulation.y[0].components[0]
        one_d_sim /= one_d_sim.max()

        np.testing.assert_almost_equal(one_d_section, one_d_sim, decimal=6)
Exemplo n.º 6
0
# %%
# Use the ``SSB2D`` method to simulate a PASS, MAT, QPASS, QMAT, or any equivalent
# sideband separation spectrum. Here, we use the method to generate a QMAT spectrum.
# The QMAT method is created from the ``SSB2D`` method in the same as a PASS or MAT
# method. The difference is that the observed channel is a half-integer quadrupolar
# spin instead of a spin I=1/2.
qmat = SSB2D(
    channels=["87Rb"],
    magnetic_flux_density=9.4,
    rotor_frequency=2604,
    spectral_dimensions=[
        dict(
            count=32 * 4,
            spectral_width=2604 * 32,  # in Hz
            label="Anisotropic dimension",
        ),
        dict(
            count=512,
            spectral_width=50000,  # in Hz
            label="Fast MAS dimension",
        ),
    ],
)

# A graphical representation of the method object.
plt.figure(figsize=(5, 3.5))
qmat.plot()
plt.show()

# %%
Exemplo n.º 7
0
def test_SSB_affine():
    mth = SSB2D(channels=["13C"], rotor_frequency=1200)
    np.allclose(mth.affine_matrix, [1, -1, 0, 0])
    assert SSB2D.parse_dict_with_units(mth.json()) == mth
Exemplo n.º 8
0
filename = "https://sandbox.zenodo.org/record/687656/files/itraconazole_13C.mrsys"
sim.load_spin_systems(filename)

# %%
# Use the ``SSB2D`` method to simulate a PASS, MAT, QPASS, QMAT, or any equivalent
# sideband separation spectrum. Here, we use the method to generate a PASS spectrum.
PASS = SSB2D(
    channels=["13C"],
    magnetic_flux_density=11.74,
    rotor_frequency=2000,
    spectral_dimensions=[
        {
            "count": 20 * 4,
            "spectral_width": 2000 * 20,  # value in Hz
            "label": "Anisotropic dimension",
        },
        {
            "count": 1024,
            "spectral_width": 3e4,  # value in Hz
            "reference_offset": 1.1e4,  # value in Hz
            "label": "Isotropic dimension",
        },
    ],
)
sim.methods = [PASS]  # add the method.

# For 2D spinning sideband simulation, set the number of spinning sidebands in the
# Simulator.config object to `spectral_width/rotor_frequency` along the sideband
# dimension.
sim.config.number_of_sidebands = 20
Exemplo n.º 9
0
# %%
# Use the ``SSB2D`` method to simulate a PASS, MAT, QPASS, QMAT, or any equivalent
# sideband separation spectrum. Here, we use the method to generate a QMAT spectrum.
# The QMAT method is created from the ``SSB2D`` method in the same as a PASS or MAT
# method. The difference is that the observed channel is a half-integer quadrupolar
# spin instead of a spin I=1/2.
qmat = SSB2D(
    channels=["87Rb"],
    magnetic_flux_density=9.4,
    rotor_frequency=2604,
    spectral_dimensions=[
        {
            "count": 32 * 4,
            "spectral_width": 2604 * 32,  # in Hz
            "label": "Anisotropic dimension",
        },
        {
            "count": 512,
            "spectral_width": 50000,  # in Hz
            "label": "Fast MAS dimension",
        },
    ],
)

# %%
# Create the Simulator object, add the method and spin system objects, and
# run the simulation.
sim = Simulator()
sim.spin_systems = spin_systems  # add the spin systems
sim.methods = [qmat]  # add the method.
Exemplo n.º 10
0
    shielding_symmetric={"zeta": zeta, "eta": eta},
    abundance=100 / 6,
)

# %%
# **Method**
#
# Create the SSB2D method.

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

PASS = SSB2D(
    channels=["13C"],
    magnetic_flux_density=9.395,  # in T
    rotor_frequency=1500,  # in Hz
    spectral_dimensions=spectral_dims,
    experiment=mat_data,  # 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 = PASS.get_transition_pathways(sys)

# %%
# **Guess Spectrum**

# Simulation
# ----------
sim = Simulator(spin_systems=spin_systems, methods=[PASS])
Exemplo n.º 11
0
def test_SSB_setting_events():
    e = "`events` attribute cannot be modified for SSB2D method."
    with pytest.raises(AttributeError, match=f".*{e}.*"):
        SSB2D(spectral_dimensions=[{"events": [{}]}])
filename = "https://sandbox.zenodo.org/record/835664/files/itraconazole_13C.mrsys"
sim.load_spin_systems(filename)

# %%
# Use the ``SSB2D`` method to simulate a PASS, MAT, QPASS, QMAT, or any equivalent
# sideband separation spectrum. Here, we use the method to generate a PASS spectrum.
PASS = SSB2D(
    channels=["13C"],
    magnetic_flux_density=11.74,
    rotor_frequency=2000,
    spectral_dimensions=[
        dict(
            count=20 * 4,
            spectral_width=2000 * 20,  # value in Hz
            label="Anisotropic dimension",
        ),
        dict(
            count=1024,
            spectral_width=3e4,  # value in Hz
            reference_offset=1.1e4,  # value in Hz
            label="Isotropic dimension",
        ),
    ],
)
sim.methods = [PASS]  # add the method.

# A graphical representation of the method object.
plt.figure(figsize=(5, 3.5))
PASS.plot()
plt.show()