Example #1
0
def quad_1D_projection():
    quad_only = Method(
        channels=["87Rb"],
        magnetic_flux_density=9.4,  # in T
        rotor_angle=70.12 * np.pi / 180,  # in rads
        rotor_frequency=np.inf,
        spectral_dimensions=[
            SpectralDimension(
                count=512,
                spectral_width=8e3,
                reference_offset=-4e3,
                events=[
                    SpectralEvent(
                        fraction=1 / 4,
                        freq_contrib=["Quad2_0"],
                        transition_queries=[{
                            "ch1": {
                                "P": [3],
                                "D": [0]
                            }
                        }],
                    ),
                    MixingEvent(query={
                        "ch1": {
                            "angle": np.pi * 109.5 / 180,
                            "phase": 0
                        }
                    }),
                    SpectralEvent(
                        fraction=3 / 4,
                        freq_contrib=["Quad2_0", "Quad2_2"],
                        transition_queries=[{
                            "ch1": {
                                "P": [-1],
                                "D": [0]
                            }
                        }],
                    ),
                ],
            )
        ],
    )
    return process_spectrum(quad_only)
Example #2
0
def coaster_simulation():
    coaster = Method(
        name="COASTER",
        channels=["87Rb"],
        magnetic_flux_density=9.4,  # in T
        rotor_angle=70.12 * np.pi / 180,  # in rads
        rotor_frequency=np.inf,
        spectral_dimensions=[
            SpectralDimension(
                count=512,
                spectral_width=4e4,  # in Hz
                reference_offset=-8e3,  # in Hz
                label="$\\omega_1$ (CSA)",
                events=[
                    SpectralEvent(transition_queries=[{
                        "ch1": {
                            "P": [3],
                            "D": [0]
                        }
                    }]),
                    MixingEvent(query={"ch1": {
                        "angle": np.pi * 109.5 / 180
                    }}),
                ],
            ),
            SpectralDimension(
                count=512,
                spectral_width=8e3,  # in Hz
                reference_offset=-4e3,  # in Hz
                label="$\\omega_2$ (Q)",
                events=[
                    SpectralEvent(transition_queries=[{
                        "ch1": {
                            "P": [-1],
                            "D": [0]
                        }
                    }])
                ],
            ),
        ],
        affine_matrix=[[1, 0], [1 / 4, 3 / 4]],
    )
    return process_spectrum(coaster)
def hahn_method():
    return Method(
        channels=["1H"],
        magnetic_flux_density=9.4,  # in T
        rotor_angle=0,  # in rads
        spectral_dimensions=[
            SpectralDimension(
                count=512,
                spectral_width=2e4,  # in Hz
                events=[
                    SpectralEvent(fraction=0.5,
                                  transition_queries=positive_sq_tq),
                    MixingEvent(query={"ch1": {
                        "angle": np.pi,
                        "phase": 0
                    }}),
                    SpectralEvent(fraction=0.5,
                                  transition_queries=negative_sq_tq),
                ],
            )
        ],
    )
def test_mixing_query_connect_map():
    MX1 = MixingEvent(mixing_query={"ch1": {"tip_angle": 0.12}})
    MX2 = MixingEvent(mixing_query={"ch2": {"tip_angle": 1.12}})
    spectral_dimmensions = [
        SpectralDimension(events=[
            {
                "fraction": 0.5
            },  # 0
            MX1,
            {
                "duration": 0.5
            },  # 1
            {
                "fraction": 0.5
            },  # 2
            MX2,
            {
                "duration": 0.5
            },  # 3
        ]),
        SpectralDimension(events=[
            MX1,
            MX2,
            {
                "duration": 0.5
            },  # 4
            MX2,
            {
                "duration": 0.5
            },  # 5
            {
                "fraction": 1
            },  # 2
        ]),
    ]
    res = mixing_query_connect_map(spectral_dimmensions)
    assert res == [
        {
            "mixing_query": MX1.mixing_query,
            "near_index": [0, 1]
        },
        {
            "mixing_query": MX2.mixing_query,
            "near_index": [2, 3]
        },
        {
            "mixing_query": MX1.mixing_query,
            "near_index": [3, 4]
        },
        {
            "mixing_query": MX2.mixing_query,
            "near_index": [3, 4]
        },
        {
            "mixing_query": MX2.mixing_query,
            "near_index": [4, 5]
        },
    ]

    error = "SpectralDimension requires at least one SpectralEvent"
    with pytest.raises(MissingSpectralEventError, match=f".*{error}.*"):
        SpectralDimension(
            events=[MX1, MX2, {
                "duration": 0.5
            }, MX2, {
                "duration": 0.5
            }])
Example #5
0
def test_2D():
    site_Ni = Site(
        isotope="2H",
        isotropic_chemical_shift=-97,  # in ppm
        shielding_symmetric=dict(
            zeta=-551,
            eta=0.12,
            alpha=62 * np.pi / 180,
            beta=114 * np.pi / 180,
            gamma=171 * np.pi / 180,
        ),
        quadrupolar=dict(Cq=77.2e3, eta=0.9),  # Cq in Hz
    )
    spin_system = SpinSystem(sites=[site_Ni])

    data = []
    for angle, n_gamma in zip([0, np.pi / 4], [1, 500]):
        shifting_d = Method(
            name="Shifting-d",
            channels=["2H"],
            magnetic_flux_density=9.395,  # in T
            rotor_frequency=0,  # in Hz
            rotor_angle=angle,  # in Hz
            spectral_dimensions=[
                SpectralDimension(
                    count=512,
                    spectral_width=2.5e5,  # in Hz
                    label="Quadrupolar frequency",
                    events=[
                        SpectralEvent(
                            transition_queries=[{
                                "ch1": {
                                    "P": [-1]
                                }
                            }],
                            freq_contrib=["Quad1_2"],
                        ),
                        MixingEvent(query="NoMixing"),
                    ],
                ),
                SpectralDimension(
                    count=256,
                    spectral_width=2e5,  # in Hz
                    reference_offset=2e4,  # in Hz
                    label="Paramagnetic shift",
                    events=[
                        SpectralEvent(
                            transition_queries=[{
                                "ch1": {
                                    "P": [-1]
                                }
                            }],
                            freq_contrib=["Shielding1_0", "Shielding1_2"],
                        )
                    ],
                ),
            ],
        )

        sim = Simulator(spin_systems=[spin_system], methods=[shifting_d])
        sim.config.integration_volume = "hemisphere"
        sim.config.number_of_gamma_angles = n_gamma
        sim.run(auto_switch=False)

        res = sim.methods[0].simulation.y[0].components[0]
        data.append(res / res.max())

    # _, ax = plt.subplots(1, 2)
    # ax[0].imshow(data[0].real)
    # ax[1].imshow(data[1].real)
    # plt.show()

    np.testing.assert_almost_equal(data[0], data[1], decimal=1.8)
    channels=["1H"],
    magnetic_flux_density=9.4,  # in T
    spectral_dimensions=[
        SpectralDimension(
            count=512,
            spectral_width=2e4,  # in Hz
            events=[
                SpectralEvent(fraction=0.5,
                              transition_query=[{
                                  "ch1": {
                                      "P": [1]
                                  }
                              }]),
                MixingEvent(
                    mixing_query={"ch1": {
                        "tip_angle": np.pi,
                        "phase": 0
                    }}),
                SpectralEvent(fraction=0.5,
                              transition_query=[{
                                  "ch1": {
                                      "P": [-1]
                                  }
                              }]),
            ],
        )
    ],
)

# %%
# You may also visualize the method using the `plot` function.
 rotor_frequency=np.inf,
 spectral_dimensions=[
     SpectralDimension(
         **spectral_dims[0],
         events=[
             SpectralEvent(
                 fraction=0.5,
                 rotor_angle=37.38 * np.pi / 180,  # in rads
                 transition_queries=[{
                     "ch1": {
                         "P": [-1],
                         "D": [0]
                     }
                 }],
             ),
             MixingEvent(query="NoMixing"),
             SpectralEvent(
                 fraction=0.5,
                 rotor_angle=79.19 * np.pi / 180,  # in rads
                 transition_queries=[{
                     "ch1": {
                         "P": [-1],
                         "D": [0]
                     }
                 }],
             ),
             MixingEvent(query="NoMixing"),
         ],
     ),
     # The last spectral dimension block is the direct-dimension
     SpectralDimension(
Example #8
0
def test_mixing_query_connect_map():
    MX1 = MixingEvent(query={"ch1": {"angle": 0.12}})
    MX2 = MixingEvent(query={"ch2": {"angle": 1.12}})
    TOTAL_MX = MixingEvent(query="TotalMixing")

    # Use MixingEvents with non-enum queries
    spectral_dimensions = [
        SpectralDimension(events=[
            {
                "fraction": 0.5
            },  # 0
            MX1,
            {
                "duration": 0.5
            },  # 1
            {
                "fraction": 0.5
            },  # 2
            MX2,
            {
                "duration": 0.5
            },  # 3
        ]),
        SpectralDimension(events=[
            MX1,
            MX2,
            {
                "duration": 0.5
            },  # 4
            MX2,
            {
                "duration": 0.5
            },  # 5
            {
                "fraction": 1
            },  # 6
        ]),
    ]
    res = mixing_query_connect_map(spectral_dimensions)
    assert res == [
        {
            "mixing_query_list": [MX1.query],
            "near_index": [0, 1]
        },
        {
            "mixing_query_list": [MX2.query],
            "near_index": [2, 3]
        },
        {
            "mixing_query_list": [MX1.query, MX2.query],
            "near_index": [3, 4]
        },
        {
            "mixing_query_list": [MX2.query],
            "near_index": [4, 5]
        },
    ]

    # Combination of MixingEvents with dict queries and enum queries (total mixing)
    spectral_dimensions = [
        SpectralDimension(events=[
            # Connect all, should return no list
            {
                "fraction": 0.5
            },  # 0
            TOTAL_MX,
            {
                "duration": 0.5
            },  # 1
            # Just MX1
            {
                "fraction": 0.5
            },  # 2
            TOTAL_MX,
            MX1,
            {
                "duration": 0.5
            },  # 3
        ]),
        SpectralDimension(events=[
            # MX1 and MX2
            {
                "fraction": 0.5
            },  # 4
            MX1,
            TOTAL_MX,
            MX2,
            {
                "duration": 0.5
            },  # 5
            # MX1, MX2, MX1
            {
                "fraction": 0.5
            },  # 6
            MX1,
            TOTAL_MX,
            MX2,
            MX1,
            TOTAL_MX,
            {
                "duration": 0.5
            },  # 7
        ]),
    ]
    res = mixing_query_connect_map(spectral_dimensions)
    assert res == [
        {
            "mixing_query_list": [MX1.query],
            "near_index": [2, 3]
        },
        {
            "mixing_query_list": [MX1.query, MX2.query],
            "near_index": [4, 5]
        },
        {
            "mixing_query_list": [MX1.query, MX2.query, MX1.query],
            "near_index": [6, 7]
        },
    ]

    error = "SpectralDimension requires at least one SpectralEvent"
    with pytest.raises(MissingSpectralEventError, match=f".*{error}.*"):
        SpectralDimension(
            events=[MX1, MX2, {
                "duration": 0.5
            }, MX2, {
                "duration": 0.5
            }])
    magnetic_flux_density=9.4,  # in T
    rotor_angle=0,  # in rads
    rotor_frequency=0,  # in Hz
    spectral_dimensions=[
        SpectralDimension(
            count=512,
            spectral_width=2e4,  # in Hz
            events=[
                SpectralEvent(fraction=0.5,
                              transition_queries=[{
                                  "ch1": {
                                      "P": [1]
                                  }
                              }]),
                MixingEvent(query={"ch1": {
                    "angle": np.pi,
                    "phase": 0
                }}),
                SpectralEvent(fraction=0.5,
                              transition_queries=[{
                                  "ch1": {
                                      "P": [-1]
                                  }
                              }]),
            ],
        )
    ],
)

# %%
# In the above code, we define the two SpectralEvent objects with fraction 0.5 and
# the transition_queries on channel-1 of P=[1] and P=[-1], respectively. Notice, the
 spectral_dimensions=[
     SpectralDimension(
         count=512,
         spectral_width=4e4,  # in Hz
         reference_offset=-8e3,  # in Hz
         label="$\\omega_1$ (CSA)",
         events=[
             SpectralEvent(transition_queries=[{
                 "ch1": {
                     "P": [3],
                     "D": [0]
                 }
             }]),
             MixingEvent(
                 query={"ch1": {
                     "angle": np.pi * 109.5 / 180,
                     "phase": 0
                 }}),
         ],
     ),
     # The last spectral dimension block is the direct-dimension
     SpectralDimension(
         count=512,
         spectral_width=8e3,  # in Hz
         reference_offset=-4e3,  # in Hz
         label="$\\omega_2$ (Q)",
         events=[
             SpectralEvent(transition_queries=[{
                 "ch1": {
                     "P": [-1],
                     "D": [0]