Exemplo n.º 1
0
def test_01():
    system = SpinSystem(sites=[{"isotope": "13C"}, {"isotope": "1H"}])
    tr = method1.get_transition_pathways(system)
    expected = [
        TransitionPathway([{"final": [-0.5, -0.5], "initial": [0.5, -0.5]}]),
        TransitionPathway([{"final": [-0.5, 0.5], "initial": [0.5, 0.5]}]),
    ]
    check_transition_set(tr, expected)
Exemplo n.º 2
0
    def get_transition_pathways(self, spin_system) -> List[TransitionPathway]:
        """Return a list of transition pathways from the given spin system that satisfy
        the query selection criterion of the method.

        Args:
            SpinSystem spin_system: A SpinSystem object.

        Returns:
            A list of :ref:`transition_pathway_api` objects. Each TransitionPathway
            object is an ordered collection of Transition objects.

        Example:
            >>> from mrsimulator import SpinSystem
            >>> from mrsimulator.method.lib import ThreeQ_VAS
            >>> sys = SpinSystem(sites=[{'isotope': '27Al'}, {'isotope': '29Si'}])
            >>> method = ThreeQ_VAS(channels=['27Al'])
            >>> pprint(method.get_transition_pathways(sys))
            [|1.5, -0.5⟩⟨-1.5, -0.5| ⟶ |-0.5, -0.5⟩⟨0.5, -0.5|, weight=(1+0j),
             |1.5, -0.5⟩⟨-1.5, -0.5| ⟶ |-0.5, 0.5⟩⟨0.5, 0.5|, weight=(1+0j),
             |1.5, 0.5⟩⟨-1.5, 0.5| ⟶ |-0.5, -0.5⟩⟨0.5, -0.5|, weight=(1+0j),
             |1.5, 0.5⟩⟨-1.5, 0.5| ⟶ |-0.5, 0.5⟩⟨0.5, 0.5|, weight=(1+0j)]
        """
        segments, weights = self._get_transition_pathway_and_weights_np(spin_system)
        return [
            TransitionPathway(
                [
                    Transition(initial=tr[0].tolist(), final=tr[1].tolist())
                    for tr in item
                ],
                weight=w,
            )
            for item, w in zip(segments, weights)
            if w != 0
        ]
Exemplo n.º 3
0
def test_cosy():
    system = SpinSystem(sites=[{"isotope": "1H"}, {"isotope": "1H"}])
    cosy = Method2D(
        channels=["1H"],
        spectral_dimensions=[
            {
                "events": [
                    {"fraction": 1, "transition_query": {"P": [-1]}},
                    {"mixing_query": {"ch1": {"tip_angle": np.pi / 2, "phase": 0}}},
                ],
            },
            {
                "events": [{"fraction": 1, "transition_query": {"P": [-1]}}],
            },
        ],
    )
    tr = cosy.get_transition_pathways(system)

    weights = np.asarray([1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1]) * 0.25
    transition_pathways = 0.5 * np.asarray(
        [
            [[[-1, 1], [-1, -1]], [[-1, 1], [-1, -1]]],
            [[[-1, 1], [-1, -1]], [[1, -1], [-1, -1]]],
            [[[-1, 1], [-1, -1]], [[1, 1], [-1, 1]]],
            [[[-1, 1], [-1, -1]], [[1, 1], [1, -1]]],
            #
            [[[1, -1], [-1, -1]], [[-1, 1], [-1, -1]]],
            [[[1, -1], [-1, -1]], [[1, -1], [-1, -1]]],
            [[[1, -1], [-1, -1]], [[1, 1], [-1, 1]]],
            [[[1, -1], [-1, -1]], [[1, 1], [1, -1]]],
            #
            [[[1, 1], [-1, 1]], [[-1, 1], [-1, -1]]],
            [[[1, 1], [-1, 1]], [[1, -1], [-1, -1]]],
            [[[1, 1], [-1, 1]], [[1, 1], [-1, 1]]],
            [[[1, 1], [-1, 1]], [[1, 1], [1, -1]]],
            #
            [[[1, 1], [1, -1]], [[-1, 1], [-1, -1]]],
            [[[1, 1], [1, -1]], [[1, -1], [-1, -1]]],
            [[[1, 1], [1, -1]], [[1, 1], [-1, 1]]],
            [[[1, 1], [1, -1]], [[1, 1], [1, -1]]],
        ]
    )

    expected = [
        TransitionPathway(
            pathway=[
                {"initial": list(states[0]), "final": list(states[1])}
                for states in transitions
            ],
            weight=w,
        )
        for transitions, w in zip(transition_pathways, weights)
    ]

    assert tr == expected
Exemplo n.º 4
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),
    )
    site2 = Site(
        isotope="1H",
        isotropic_chemical_shift=-4,
        shielding_symmetric=SymmetricTensor(zeta=2.1, eta=0.1),
    )
    site3 = Site(
        isotope="27Al",
        isotropic_chemical_shift=120,
        shielding_symmetric=SymmetricTensor(zeta=2.1, eta=0.1),
        quadrupolar=SymmetricTensor(Cq=5.1e6, eta=0.5),
    )

    doctest_namespace["spin_system_1H_13C"] = SpinSystem(sites=[site1, site2])
    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

    # 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
Exemplo n.º 5
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