Пример #1
0
def test_models(doctest_namespace):
    cz_model = CzjzekDistribution(0.5)
    doctest_namespace["cz_model"] = cz_model

    S0 = {"Cq": 1e6, "eta": 0.3}
    ext_cz_model = ExtCzjzekDistribution(S0, eps=0.35)
    doctest_namespace["ext_cz_model"] = ext_cz_model
def test_extended_czjzek_eta_distribution_3():
    filename = path.join(MODULE_DIR, "test_data", "eps=0.65.npy")
    with open(filename, "rb") as f:
        data = np.load(f)

    S0 = {"Cq": 1e6, "eta": 0.7}
    _, eta1 = ExtCzjzekDistribution(S0, eps=0.65).rvs(size=COUNT)
    hist1, _ = np.histogram(eta1, bins=100, range=[0, 1])

    message = "failed to compare values with file eps=0.05.npy"
    np.testing.assert_almost_equal(hist1 / COUNT, data[3], decimal=2, err_msg=message)
Пример #3
0
def get_prob_dist(iso, Cq, eta, eps, cov):
    pdf = 0
    for i in range(len(iso)):
        # The 2D amplitudes for Cq and eta is sampled from the extended Czjzek model.
        avg_tensor = {"Cq": Cq[i], "eta": eta[i]}
        _, _, amp = ExtCzjzekDistribution(avg_tensor,
                                          eps=eps[i]).pdf(pos=[Cq_r, eta_r])

        # The 1D amplitudes for isotropic chemical shifts is sampled as a Gaussian.
        iso_amp = multivariate_normal(mean=iso[i], cov=[cov[i]]).pdf(iso_r)

        # The 3D amplitude grid is generated as an uncorrelated distribution of the
        # above two distribution, which is the product of the two distributions.
        pdf_t = np.repeat(amp, iso_r.size).reshape(eta_r.size, Cq_r.size,
                                                   iso_r.size)
        pdf_t *= iso_amp
        pdf += pdf_t
    return pdf
Пример #4
0
# %%
# Symmetric shielding tensor
# --------------------------
#
# Create the extended Czjzek distribution
# '''''''''''''''''''''''''''''''''''''''
#
# First, create a distribution of the zeta and eta parameters of the shielding tensors
# using the :ref:`extended_czjzek_distribution` model as follows,

# The range of zeta and eta coordinates over which the distribution is sampled.
z_lim = np.arange(100) * 0.4 + 40  # in ppm
e_lim = np.arange(21) / 20

dominant = {"zeta": 60, "eta": 0.3}
z_dist, e_dist, amp = ExtCzjzekDistribution(dominant, eps=0.14).pdf(pos=[z_lim, e_lim])

# %%
# The following is the plot of the extended Czjzek distribution.
plt.figure(figsize=(4.25, 3.0))
plt.contourf(z_dist, e_dist, amp, levels=10)
plt.xlabel(r"$\zeta$ / ppm")
plt.ylabel(r"$\eta$")
plt.tight_layout()
plt.show()

# %%
# Simulate the spectrum
# '''''''''''''''''''''
#
# Create the spin systems from the above :math:`\zeta` and :math:`\eta` parameters.
def test_extended_czjzek_polar():
    S0 = {"zeta": 1, "eta": 0.1}
    x, y = ExtCzjzekDistribution(S0, eps=0.05, polar=True).rvs(size=COUNT)
    x1, y1 = x_y_from_zeta_eta(*x_y_to_zeta_eta(x, y))
    np.testing.assert_almost_equal(x, x1)
    np.testing.assert_almost_equal(y, y1)