Beispiel #1
0
def calc_observable(pb=0.0, kex=0.0, dw_n=0.0, ppm_to_rads_n_1=1.0,
                    ppm_to_rads_n_2=1.0):
    """Returns: float"""

    dw_n_1 = dw_n * ppm_to_rads_n_1
    dw_n_2 = dw_n * ppm_to_rads_n_2

    shift_sq_1 = correct_chemical_shift(pb, kex, dw_n_1)[0] / ppm_to_rads_n_1
    shift_sq_2 = correct_chemical_shift(pb, kex, dw_n_2)[0] / ppm_to_rads_n_2

    return (shift_sq_1 - shift_sq_2) * 1e3
def calc_observable(pb=0.0, kex=0.0, dw_h=0.0, dw_n=0.0, ppm_to_rads_h=1.0,
                    ppm_to_rads_n=1.0):
    """ Returns: float """

    dw_h *= ppm_to_rads_h
    dw_n *= ppm_to_rads_n

    shift_sq = correct_chemical_shift(pb, kex, dw_n)[0]
    shift_mq = 0.5 * (correct_chemical_shift(pb, kex, dw_n + dw_h)[0] +
                      correct_chemical_shift(pb, kex, dw_n - dw_h)[0])

    return (shift_sq - shift_mq) / ppm_to_rads_n * 1e3
Beispiel #3
0
def calc_observable(pb=0.0,
                    kex=0.0,
                    dw_n=0.0,
                    ppm_to_rads_n_1=1.0,
                    ppm_to_rads_n_2=1.0):
    """Returns: float"""

    dw_n_1 = dw_n * ppm_to_rads_n_1
    dw_n_2 = dw_n * ppm_to_rads_n_2

    shift_sq_1 = correct_chemical_shift(pb, kex, dw_n_1)[0] / ppm_to_rads_n_1
    shift_sq_2 = correct_chemical_shift(pb, kex, dw_n_2)[0] / ppm_to_rads_n_2

    return (shift_sq_1 - shift_sq_2) * 1e3
Beispiel #4
0
    def _calc_observable(pb=0.0, kex=0.0, dw=0.0, r_cz=1.5, r_cxy=0.0, dr_cxy=0.0, cs=0.0):
        """
        Calculate the intensity in presence of exchange after a CEST block assuming
        initial intensity of 1.0.

        Parameters
        ----------
        pb : float
            Fractional population of state B,
            0.0 for 0%, 1.0 for 100%
        kex : float
            Exchange rate between state A and B in /s.
        dw : float
            Chemical shift difference between states A and B in rad/s.
        r_cz : float
            Longitudinal relaxation rate of state {a,b} in /s.
        r_cxy : float
            Transverse relaxation rate of state a in /s.
        dr_cxy : float
            Transverse relaxation rate difference between states a and b in /s.
        cs : float
            Resonance position in rad/s.

        Returns
        -------
        out : float
            Intensity after the CEST block

        """

        if abs(b1_offset) >= 10000.0:

            return 1.0 - pb

        else:

            dw *= ppm_to_rads
            mag_eq = compute_cz_eq(pb)
            exchange_induced_shift, _ = correct_chemical_shift(pb=pb, kex=kex, dw=dw,
                                                               r_ixy=r_cxy, dr_ixy=dr_cxy)
            wg = (cs - carrier) * ppm_to_rads - exchange_induced_shift

            liouvillians = base_liouvillians + compute_free_liouvillian(pb=pb, kex=kex, dw=dw,
                                                                        r_cxy=r_cxy, dr_cxy=dr_cxy,
                                                                        r_cz=r_cz, cs_offset=wg)

            propagator = sc.zeros_like(liouvillians[0])
            for liouvillian, weight in zip(liouvillians, weights):
                propagator += weight * expm(liouvillian * time_t1)
            propagator /= sum(weights)

            magz_a, _ = get_cz(sc.dot(propagator, mag_eq))

            return magz_a
Beispiel #5
0
    def _calc_observable(pb=0.0, kex=0.0, dw=0.0, r_nz=1.5, r_nxy=0.0,
                         dr_nxy=0.0, cs=0.0):
        """
        Calculate the intensity in presence of exchange after a CEST block assuming
        initial intensity of 1.0.

        Parameters
        ----------
        pb : float
            Fractional population of state B,
            0.0 for 0%, 1.0 for 100%
        kex : float
            Exchange rate between state A and B in /s.
        dw : float
            Chemical shift difference between states A and B in rad/s.
        r_nz : float
            Longitudinal relaxation rate of state {a,b} in /s.
        r_nxy : float
            Transverse relaxation rate of state a in /s.
        dr_nxy : float
            Transverse relaxation rate difference between states a and b in /s.
        cs : float
            Resonance position in rad/s.

        Returns
        -------
        out : float
            Intensity after the CEST block

        """

        if abs(b1_offset) >= 10000.0:

            magz_a = 1.0 - pb

        else:

            dw *= ppm_to_rads

            exchange_induced_shift, _ = correct_chemical_shift(
                pb=pb,
                kex=kex,
                dw=dw,
                r_ixy=r_nxy,
                dr_ixy=dr_nxy
            )

            wg = (
                (cs - carrier) * ppm_to_rads -
                exchange_induced_shift -
                w1_offset
            )

            magz_eq = sc.asarray([[1 - pb], [pb]])
            magz_a = 0.0

            for j, weight in multiplet:
                liouvillian = compute_liouvillian(
                    pb=pb,
                    kex=kex,
                    dw=dw,
                    r_nxy=r_nxy,
                    dr_nxy=dr_nxy,
                    r_nz=r_nz,
                    cs_offset=(wg + j),
                    w1=w1
                )

                s, vr = eig(liouvillian)
                vri = inv(vr)

                sl1 = [2, 5]
                sl2 = [i for i, w in enumerate(s.imag) if abs(w) < 1.0e-6]
                sl3 = [2]

                vri = vri[sc.ix_(sl2, sl1)].real
                t = diag(exp(s[sl2].real * time_t1))
                vr = vr[sc.ix_(sl3, sl2)].real

                magz_a += (
                    weight *
                    dot(dot(dot(vr, t), vri), magz_eq)[0, 0]
                )

        return magz_a
Beispiel #6
0
    def _calc_observable(pb=0.0,
                         kex=0.0,
                         dw_h=0.0,
                         dw_n=0.0,
                         r_nxy=5.0,
                         dr_nxy=None,
                         r_nz=1.5,
                         r_2hznz=None,
                         r_2hxynxy=0.0,
                         r_hxy=10.0,
                         r_hz=1.0,
                         etaxy=0.0,
                         etaz=0.0,
                         j_hn=JHN,
                         cs_n=0.0,
                         cs_h=0.0):
        """
        Calculate the intensity in presence of exchange during a cpmg-type pulse train.

        Keyword arguments:
        I0 -- Initial intensity,
              0.0 (default),
        pb -- population of state B,
              0.0 for 0% (default),
              1.0 for 100%
        kex -- exchange rate between state A and B in /s,
               0.0 (default)
        dw -- chemical shift difference between states A and B in /s,
              0.0 /s (default)
        r_Nxy -- transverse relaxation rate in /s,
                 5.0 (default)
        dr_Nxy -- transverse relaxation rate difference in /s between states a and b,
                  0.0 (default)
        r_Nz -- longitudinal relaxation rate in /s,
                1.5 (default)
        cs_offset -- chemical shift from the carrier in rad/s,
                     0.0 (default)
        B1_offset -- frequency offset of the applied B1 field in Hz,
                     0.0 Hz (default)
        B1_frq -- strength of the applied B1 field in Hz,
                  0.0 Hz (default)
        B1_inh -- B1 field inhomogeneity in Hz,
                  0.0 Hz (default)
        time_t1 -- time of the CW block,
                   0 ms (default)



        Returns: float
        """

        wg_h = (cs_h - carrier_h) * ppm_to_rads_h
        wg_n = (cs_n - carrier) * ppm_to_rads
        dw_h_rads = dw_h * ppm_to_rads_h
        dw_n_rads = dw_n * ppm_to_rads

        mag_eq = set_nz(pb)

        if abs(b1_offset) > 9999.0:

            mag = mag_eq

        else:

            exchange_induced_shift_n, _ = correct_chemical_shift(pb=pb,
                                                                 kex=kex,
                                                                 dw=dw_n_rads,
                                                                 r_ixy=r_nxy,
                                                                 dr_ixy=dr_nxy)

            offset_n = wg_n - exchange_induced_shift_n - b1_offset * 2.0 * pi

            liouvillian = compute_liouvillian_free_precession(
                pb=pb,
                kex=kex,
                dw_h=dw_h_rads,
                dw_n=dw_n_rads,
                r_nxy=r_nxy,
                dr_nxy=dr_nxy,
                r_nz=r_nz,
                r_2hznz=r_2hznz,
                r_2hxynxy=r_2hxynxy,
                r_hxy=r_hxy,
                r_hz=r_hz,
                etaxy=etaxy,
                etaz=etaz,
                cs_offset_h=wg_h,
                cs_offset_n=offset_n,
                j_hn=j_hn)

            b1_frq_n_list = linspace(-2.0, 2.0, b1_inh_res) * b1_inh + b1_frq
            b1_frq_n_scales = norm.pdf(b1_frq_n_list, b1_frq, b1_inh)
            b1_frq_n_scales /= b1_frq_n_scales.sum()

            mag = sum(
                scale * make_pulse_nh(liouvillian=liouvillian,
                                      w1_h=TWO_PI * b1_frq_h,
                                      phase_h=0.0,
                                      w1_n=TWO_PI * b1_frq_n,
                                      phase_n=0.0,
                                      pw=time_t1).dot(mag_eq)
                for b1_frq_n, scale in zip(b1_frq_n_list, b1_frq_n_scales))

        return get_nz(mag)[0]
Beispiel #7
0
    def _calc_observable(pb=0.0, kex=0.0, dw_h=0.0, dw_n=0.0, r_nxy=5.0,
                         dr_nxy=None, r_nz=1.5, r_2hznz=None, r_2hxynxy=0.0,
                         r_hxy=10.0, r_hz=1.0, etaxy=0.0, etaz=0.0, j_hn=JHN,
                         cs_n=0.0, cs_h=0.0):
        """
        Calculate the intensity in presence of exchange during a cpmg-type pulse train.

        Keyword arguments:
        I0 -- Initial intensity,
              0.0 (default),
        pb -- population of state B,
              0.0 for 0% (default),
              1.0 for 100%
        kex -- exchange rate between state A and B in /s,
               0.0 (default)
        dw -- chemical shift difference between states A and B in /s,
              0.0 /s (default)
        r_Nxy -- transverse relaxation rate in /s,
                 5.0 (default)
        dr_Nxy -- transverse relaxation rate difference in /s between states a and b,
                  0.0 (default)
        r_Nz -- longitudinal relaxation rate in /s,
                1.5 (default)
        cs_offset -- chemical shift from the carrier in rad/s,
                     0.0 (default)
        B1_offset -- frequency offset of the applied B1 field in Hz,
                     0.0 Hz (default)
        B1_frq -- strength of the applied B1 field in Hz,
                  0.0 Hz (default)
        B1_inh -- B1 field inhomogeneity in Hz,
                  0.0 Hz (default)
        time_t1 -- time of the CW block,
                   0 ms (default)



        Returns: float
        """

        wg_h = (cs_h - carrier_h) * ppm_to_rads_h
        wg_n = (cs_n - carrier) * ppm_to_rads
        dw_h_rads = dw_h * ppm_to_rads_h
        dw_n_rads = dw_n * ppm_to_rads

        mag_eq = set_nz(pb)

        if abs(b1_offset) > 9999.0:

            mag = mag_eq

        else:

            exchange_induced_shift_n, _ = correct_chemical_shift(
                pb=pb,
                kex=kex,
                dw=dw_n_rads,
                r_ixy=r_nxy,
                dr_ixy=dr_nxy
            )

            offset_n = wg_n - exchange_induced_shift_n - b1_offset * 2.0 * pi

            liouvillian = compute_liouvillian_free_precession(
                pb=pb,
                kex=kex,
                dw_h=dw_h_rads,
                dw_n=dw_n_rads,
                r_nxy=r_nxy,
                dr_nxy=dr_nxy,
                r_nz=r_nz,
                r_2hznz=r_2hznz,
                r_2hxynxy=r_2hxynxy,
                r_hxy=r_hxy,
                r_hz=r_hz,
                etaxy=etaxy,
                etaz=etaz,
                cs_offset_h=wg_h,
                cs_offset_n=offset_n,
                j_hn=j_hn
            )

            b1_frq_n_list = linspace(-2.0, 2.0, b1_inh_res) * b1_inh + b1_frq
            b1_frq_n_scales = norm.pdf(b1_frq_n_list, b1_frq, b1_inh)
            b1_frq_n_scales /= b1_frq_n_scales.sum()

            mag = sum(
                scale *
                make_pulse_nh(
                    liouvillian=liouvillian,
                    w1_h=TWO_PI * b1_frq_h,
                    phase_h=0.0,
                    w1_n=TWO_PI * b1_frq_n,
                    phase_n=0.0,
                    pw=time_t1
                ).dot(mag_eq)
                for b1_frq_n, scale in zip(b1_frq_n_list, b1_frq_n_scales)
            )

        return get_nz(mag)[0]
Beispiel #8
0
    def _calc_observable(pb=0.0,
                         kex=0.0,
                         dw=0.0,
                         r_cz=1.5,
                         r_cxy=0.0,
                         dr_cxy=0.0,
                         cs=0.0):
        """
        Calculate the intensity in presence of exchange after a CEST block assuming
        initial intensity of 1.0.

        Parameters
        ----------
        pb : float
            Fractional population of state B,
            0.0 for 0%, 1.0 for 100%
        kex : float
            Exchange rate between state A and B in /s.
        dw : float
            Chemical shift difference between states A and B in rad/s.
        r_cz : float
            Longitudinal relaxation rate of state {a,b} in /s.
        r_cxy : float
            Transverse relaxation rate of state a in /s.
        dr_cxy : float
            Transverse relaxation rate difference between states a and b in /s.
        cs : float
            Resonance position in rad/s.

        Returns
        -------
        out : float
            Intensity after the CEST block

        """

        if abs(b1_offset) >= 10000.0:

            return 1.0 - pb

        else:

            dw *= ppm_to_rads
            mag_eq = compute_cz_eq(pb)
            exchange_induced_shift, _ = correct_chemical_shift(pb=pb,
                                                               kex=kex,
                                                               dw=dw,
                                                               r_ixy=r_cxy,
                                                               dr_ixy=dr_cxy)
            wg = (cs - carrier) * ppm_to_rads - exchange_induced_shift

            liouvillians = base_liouvillians + compute_free_liouvillian(
                pb=pb,
                kex=kex,
                dw=dw,
                r_cxy=r_cxy,
                dr_cxy=dr_cxy,
                r_cz=r_cz,
                cs_offset=wg)

            propagator = sc.zeros_like(liouvillians[0])
            for liouvillian, weight in zip(liouvillians, weights):
                propagator += weight * expm(liouvillian * time_t1)
            propagator /= sum(weights)

            magz_a, _ = get_cz(sc.dot(propagator, mag_eq))

            return magz_a
Beispiel #9
0
    def _calc_observable(pb=0.0,
                         kex=0.0,
                         dw=0.0,
                         r_nz=1.5,
                         r_nxy=0.0,
                         dr_nxy=0.0,
                         cs=0.0):
        """
        Calculate the intensity in presence of exchange after a CEST block assuming
        initial intensity of 1.0.

        Parameters
        ----------
        pb : float
            Fractional population of state B,
            0.0 for 0%, 1.0 for 100%
        kex : float
            Exchange rate between state A and B in /s.
        dw : float
            Chemical shift difference between states A and B in rad/s.
        r_nz : float
            Longitudinal relaxation rate of state {a,b} in /s.
        r_nxy : float
            Transverse relaxation rate of state a in /s.
        dr_nxy : float
            Transverse relaxation rate difference between states a and b in /s.
        cs : float
            Resonance position in rad/s.

        Returns
        -------
        out : float
            Intensity after the CEST block

        """

        if abs(b1_offset) >= 10000.0:

            magz_a = 1.0 - pb

        else:

            dw *= ppm_to_rads

            exchange_induced_shift, _ = correct_chemical_shift(pb=pb,
                                                               kex=kex,
                                                               dw=dw,
                                                               r_ixy=r_nxy,
                                                               dr_ixy=dr_nxy)

            wg = ((cs - carrier) * ppm_to_rads - exchange_induced_shift -
                  w1_offset)

            magz_eq = sc.asarray([[1 - pb], [pb]])
            magz_a = 0.0

            for j, weight in multiplet:
                liouvillian = compute_liouvillian(pb=pb,
                                                  kex=kex,
                                                  dw=dw,
                                                  r_nxy=r_nxy,
                                                  dr_nxy=dr_nxy,
                                                  r_nz=r_nz,
                                                  cs_offset=(wg + j),
                                                  w1=w1)

                s, vr = eig(liouvillian)
                vri = inv(vr)

                sl1 = [2, 5]
                sl2 = [i for i, w in enumerate(s.imag) if abs(w) < 1.0e-6]
                sl3 = [2]

                vri = vri[sc.ix_(sl2, sl1)].real
                t = diag(exp(s[sl2].real * time_t1))
                vr = vr[sc.ix_(sl3, sl2)].real

                magz_a += (weight * dot(dot(dot(vr, t), vri), magz_eq)[0, 0])

        return magz_a
    def _calc_observable(pb=0.0, kex=0.0, dw_h=0.0, dw_n=0.0, r_nxy=5.0,
                         dr_nxy=None, r_nz=1.5, r_2hznz=None, r_2hxynxy=0.0,
                         r_hxy=10.0, r_hz=1.0, etaxy=0.0, etaz=0.0, j_hn=JHN,
                         cs_n=0.0, cs_h=0.0):
        """
        Calculate the intensity in presence of exchange during a cpmg-type pulse train.

        Keyword arguments:
        I0 -- Initial intensity,
              0.0 (default),
        pb -- population of state B,
              0.0 for 0% (default),
              1.0 for 100%
        kex -- exchange rate between state A and B in /s,
               0.0 (default)
        dw -- chemical shift difference between states A and B in /s,
              0.0 /s (default)
        r_Nxy -- transverse relaxation rate in /s,
                 5.0 (default)
        dr_Nxy -- transverse relaxation rate difference in /s between states a and b,
                  0.0 (default)
        r_Nz -- longitudinal relaxation rate in /s,
                1.5 (default)
        cs_offset -- chemical shift from the carrier in rad/s,
                     0.0 (default)
        B1_offset -- frequency offset of the applied B1 field in Hz,
                     0.0 Hz (default)
        B1_frq -- strength of the applied B1 field in Hz,
        time_t1 -- time of the CW block,
                   0 ms (default)

        Returns: float
        """

        wg_h = (cs_h - carrier_h) * ppm_to_rads_h
        wg_n = (cs_n - carrier) * ppm_to_rads
        dw_h_rads = dw_h * ppm_to_rads_h
        dw_n_rads = dw_n * ppm_to_rads

        if abs(b1_offset) > 9999.0:

            magz_a = 1.0 - pb

        else:

            exchange_induced_shift_n, _ = correct_chemical_shift(
                pb=pb,
                kex=kex,
                dw=dw_n_rads,
                r_ixy=r_nxy,
                dr_ixy=dr_nxy
            )

            offset_n = wg_n - exchange_induced_shift_n - b1_offset * TWO_PI

            liouvillian = compute_liouvillian(
                pb=pb,
                kex=kex,
                dw_h=dw_h_rads,
                dw_n=dw_n_rads,
                r_nxy=r_nxy,
                dr_nxy=dr_nxy,
                r_nz=r_nz,
                r_2hznz=r_2hznz,
                r_2hxynxy=r_2hxynxy,
                r_hxy=r_hxy,
                r_hz=r_hz,
                etaxy=etaxy,
                etaz=etaz,
                cs_offset_h=wg_h,
                cs_offset_n=offset_n,
                j_hn=j_hn,
                w1_h=TWO_PI * b1_frq_h,
                w1_n=TWO_PI * b1_frq,
            )

            s, vr = eig(liouvillian)
            vri = inv(vr)

            sl1 = [5, 20]
            sl2 = [i for i, w in enumerate(s.imag) if abs(w) < 1.0e-6]
            sl3 = [5]

            vri = vri[ix_(sl2, sl1)].real
            t = diag(exp(s[sl2].real * time_t1))
            vr = vr[ix_(sl3, sl2)].real
            magz_eq = asarray([[1 - pb], [pb]])

            magz_a = dot(dot(dot(vr, t), vri), magz_eq)[0, 0]

        return magz_a