def test_3Q_VAS_general(): """3Q-VAS method test""" mth = ThreeQ_VAS(channels=["87Rb"], spectral_dimensions=[{}, {}]) assert mth.name == "ThreeQ_VAS" assert mth.description == "Simulate a 3Q variable-angle spinning spectrum." assert mth.spectral_dimensions[0].events[0].transition_query == [ TransitionQuery(ch1={ "P": [-3], "D": [0] }) ] assert mth.spectral_dimensions[1].events[0].transition_query == [ TransitionQuery(ch1={ "P": [-1], "D": [0] }) ] assert ThreeQ_VAS.parse_dict_with_units(mth.json()) == mth assert np.allclose(mth.affine_matrix, [0.5625, 0.4375, 0.0, 1.0]) serialize = mth.json() _ = serialize.pop("affine_matrix") assert serialize == { "channels": ["87Rb"], "description": "Simulate a 3Q variable-angle spinning spectrum.", "name": "ThreeQ_VAS", **sample_test_output(-3), }
def test_3Q_VAS_general(): """3Q-VAS method test""" mth = ThreeQ_VAS(channels=["87Rb"], spectral_dimensions=[{}, {}]) assert mth.name == "ThreeQ_VAS" assert mth.description == "Simulate a 3Q variable-angle spinning spectrum." assert mth.spectral_dimensions[0].events[ 0].transition_query == TransitionQuery(P={"channel-1": [[-3]]}, D={"channel-1": [[0]]}) assert mth.spectral_dimensions[1].events[ 0].transition_query == TransitionQuery(P={"channel-1": [[-1]]}, D={"channel-1": [[0]]}) assert Method.parse_dict_with_units(mth.json()) == mth
def test_method_exp_sim(): 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 ) ]) data = cp.as_csdm(np.random.rand(1024, 512)) 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 }, ], experiment=data, ) sim = Simulator() sim.spin_systems = [spin_system] sim.methods = [method] sim.run()
def test_3QMAS(): """3Q MAS correlation method declaration""" mth = ThreeQ_VAS( channels=["87Rb"], magnetic_flux_density=9.4, # in T spectral_dimensions=[ { "count": 512, "spectral_width": 5e6 }, { "count": 128, "spectral_width": 5e4 }, ], ) assert np.allclose(mth.affine_matrix, [0.5625, 0.4375, 0, 1]) assert ThreeQ_VAS.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
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())
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())
sim = Simulator() # load the spin systems from url. filename = "https://sandbox.zenodo.org/record/687656/files/coesite.mrsys" sim.load_spin_systems(filename) method = ThreeQ_VAS( channels=["17O"], magnetic_flux_density=11.7, # in T spectral_dimensions=[ { "count": 256, "spectral_width": 5e3, # in Hz "reference_offset": -2.5e3, # in Hz "label": "Isotropic dimension", }, # The last spectral dimension block is the direct-dimension { "count": 256, "spectral_width": 2e4, # in Hz "reference_offset": 0, # in Hz "label": "MAS dimension", }, ], ) sim.methods = [method] # add the method. sim.run() # Run the simulation # %% # The plot of the simulation. data = sim.methods[0].simulation
abundance=pdf, ) len(spin_systems) # %% # Simulate a :math:`^{27}\text{Al}` 3Q-MAS spectrum by using the `ThreeQ_MAS` method. method = ThreeQ_VAS( channels=["87Rb"], magnetic_flux_density=9.4, # in T rotor_angle=54.735 * np.pi / 180, spectral_dimensions=[ dict( count=96, spectral_width=7e3, # in Hz reference_offset=-7e3, # in Hz label="Isotropic dimension", ), dict( count=256, spectral_width=1e4, # in Hz reference_offset=-4e3, # in Hz label="MAS dimension", ), ], ) # %% # Create the simulator object, add the spin systems and method, and run the simulation. sim = Simulator() sim.spin_systems = spin_systems # add the spin systems sim.methods = [method] # add the method
sites = [Rb87_1, Rb87_2, Rb87_3] # all sites spin_systems = [SpinSystem(sites=[s]) for s in sites] # %% # Select a Triple Quantum variable-angle spinning method. You may optionally # provide a `rotor_angle` to the method. The default `rotor_angle` is the magic-angle. method = ThreeQ_VAS( channels=["87Rb"], magnetic_flux_density=9.4, # in T spectral_dimensions=[ { "count": 128, "spectral_width": 7e3, # in Hz "reference_offset": -7e3, # in Hz "label": "Isotropic dimension", }, { "count": 256, "spectral_width": 1e4, # in Hz "reference_offset": -4e3, # in Hz "label": "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 = [method] # add the method.
) spin_systems = [SpinSystem(sites=[site])] # %% # Select a Triple Quantum variable-angle spinning method. You may optionally # provide a `rotor_angle` to the method. The default `rotor_angle` is the magic-angle. method = ThreeQ_VAS( channels=["27Al"], magnetic_flux_density=7, # in T spectral_dimensions=[ dict( count=256, spectral_width=1e4, # in Hz reference_offset=-3e3, # in Hz label="Isotropic dimension", ), dict( count=512, spectral_width=1e4, # in Hz reference_offset=4e3, # in Hz label="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 = [method] # add the method.
sim = Simulator() # load the spin systems from url. filename = "https://sandbox.zenodo.org/record/835664/files/coesite.mrsys" sim.load_spin_systems(filename) method = ThreeQ_VAS( channels=["17O"], magnetic_flux_density=11.74, # in T spectral_dimensions=[ dict( count=256, spectral_width=5e3, # in Hz reference_offset=-2.5e3, # in Hz label="Isotropic dimension", ), # The last spectral dimension block is the direct-dimension dict( count=256, spectral_width=2e4, # in Hz reference_offset=0, # in Hz label="MAS dimension", ), ], ) sim.methods = [method] # add the method. sim.run() # Run the simulation # %% # The plot of the simulation. data = sim.methods[0].simulation
) spin_systems = [SpinSystem(sites=[site])] # %% # Select a Triple Quantum variable-angle spinning method. You may optionally # provide a `rotor_angle` to the method. The default `rotor_angle` is the magic-angle. method = ThreeQ_VAS( channels=["27Al"], magnetic_flux_density=7, # in T spectral_dimensions=[ { "count": 256, "spectral_width": 1e4, # in Hz "reference_offset": -3e3, # in Hz "label": "Isotropic dimension", }, { "count": 512, "spectral_width": 1e4, # in Hz "reference_offset": 4e3, # in Hz "label": "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 = [method] # add the method.
"eta": eta }, abundance=abundance, ) # %% # **Method** # # Create the 3QMAS method. # Get the spectral dimension parameters from the experiment. spectral_dims = get_spectral_dimensions(experiment) MQMAS = ThreeQ_VAS( channels=["87Rb"], magnetic_flux_density=9.395, # in T 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 das method. for sys in spin_systems: sys.transition_pathways = MQMAS.get_transition_pathways(sys) # %% # **Guess Spectrum** # Simulation # ---------- sim = Simulator(spin_systems=spin_systems, methods=[MQMAS]) sim.config.number_of_sidebands = 1
quadrupolar={"Cq": Cq * 1e6, "eta": eta}, # Cq in Hz abundance=pdf, ) len(spin_systems) # %% # Simulate a :math:`^{27}\text{Al}` 3Q-MAS spectrum by using the `ThreeQ_MAS` method. mqvas = ThreeQ_VAS( channels=["27Al"], spectral_dimensions=[ dict( count=512, spectral_width=26718.475776, # in Hz reference_offset=-4174.76184, # in Hz label="Isotropic dimension", ), dict( count=512, spectral_width=2e4, # in Hz reference_offset=2e3, # in Hz label="MAS dimension", ), ], ) # %% # Create the simulator object, add the spin systems and method, and run the simulation. sim = Simulator() sim.spin_systems = spin_systems # add the spin systems sim.methods = [mqvas] # add the method sim.config.number_of_sidebands = 1
}, # Cq in Hz abundance=pdf, ) len(spin_systems) # %% # Simulate a :math:`^{27}\text{Al}` 3Q-MAS spectrum by using the `ThreeQ_MAS` method. mqvas = ThreeQ_VAS( channels=["27Al"], spectral_dimensions=[ { "count": 512, "spectral_width": 26718.475776, # in Hz "reference_offset": -4174.76184, # in Hz "label": "Isotropic dimension", }, { "count": 512, "spectral_width": 2e4, # in Hz "reference_offset": 2e3, # in Hz "label": "MAS dimension", }, ], ) # %% # Create the simulator object, add the spin systems and method, and run the simulation. sim = Simulator() sim.spin_systems = spin_systems # add the spin systems sim.methods = [mqvas] # add the method sim.config.number_of_sidebands = 1
sites = [Rb87_1, Rb87_2, Rb87_3] # all sites spin_systems = [SpinSystem(sites=[s]) for s in sites] # %% # Select a Triple Quantum variable-angle spinning method. You may optionally # provide a `rotor_angle` to the method. The default `rotor_angle` is the magic-angle. method = ThreeQ_VAS( channels=["87Rb"], magnetic_flux_density=9.4, # in T spectral_dimensions=[ dict( count=128, spectral_width=7e3, # in Hz reference_offset=-7e3, # in Hz label="Isotropic dimension", ), dict( count=256, spectral_width=1e4, # in Hz reference_offset=-4e3, # in Hz label="MAS dimension", ), ], ) # A graphical representation of the method object. plt.figure(figsize=(5, 3.5)) method.plot() plt.show() # %%