示例#1
0
文件: examples.py 项目: delsuc/SpinEq
def Invn(n=5, sigma=-0.3, mode="inverse"):
    """
    spin inversion in a n coupled spins system in linear geometry
    sigma is the interspin cross relaxation, can be positive or negative
    mode can be "inverse" or "saturate"
    """
    # set-up equilibrium
    eq1 = NMR(1, n)
    #  add spin systems
    R1E = 1.0
    #        sigma = 0.2
    #        Relax = np.matrix([[R1E,sigma],[sigma,R1E]])
    Relax = R1E * np.eye(n) + sigma * (np.diag(np.ones(n - 1), 1) +
                                       np.diag(np.ones(n - 1), -1))
    Relax = np.matrix(Relax)
    print(Relax)
    eq1.set_spin(0, SpinSys(n, Relax))
    if mode == "inverse":
        eq1.set_magnetization(-1.0, 0, 0)  # inverse first spin
    else:
        eq1.saturate(0, 0)  # or saturate it
#        eq1.report()
    dt = 1e-2  # one step every 10msec.
    maxtime = 10.  # for 10 sec
    (t, res) = eq1.solve(maxtime=maxtime, step=maxtime / dt,
                         trajectory=True)  #,verbose=True)
    for i in range(1, n + 1):
        plt.plot(t, [r[i] for r in res], label="spin %d" % i)
    plt.title("$\sigma = %f$" % sigma)
    plt.legend()
    plt.show()
示例#2
0
文件: examples.py 项目: delsuc/SpinEq
def S2():
    """
    NOE in a 2 coupled spins system
    """
    # set-up equilibrium
    eq1 = NMR(1, 2)
    #  add spin systems
    R1E = 1.0
    sigma = -0.2
    Relax = np.matrix([[R1E, sigma], [sigma, R1E]])
    eq1.set_spin(0, SpinSys(2, Relax))
    eq1.saturate(0, 0)
    eq1.report()
    print()
    cf = eq1.solve(maxtime=1)  # maxtime=1E-4, step=100,verbose=True)
    print("saturate one spin, look at transfer after 1sec")
    print("sigma/rho: %.2f  noe: %.2f" % (sigma / R1E, cf[2] - 1.0))
示例#3
0
文件: examples.py 项目: delsuc/SpinEq
def Inv2():
    """
    spin inversion in a 2 coupled spins system
    """
    # set-up equilibrium
    eq1 = NMR(1, 2)
    #  add spin systems
    R1E = 1.0
    #        sigma = 0.2
    for sigma in (-0.5, ):  #0.25, 0.0, -0.25, -0.5, -0.8, -0.9, -0.95):
        Relax = np.matrix([[R1E, sigma], [sigma, R1E]])
        eq1.set_spin(0, SpinSys(2, Relax))
        eq1.set_magnetization(-1.0, 0, 0)  # inverse one spin
        eq1.report()
        st = 10. / 1e-2
        (t, res) = eq1.solve(maxtime=30.0, step=st,
                             trajectory=True)  #,verbose=True)
        plt.plot(t, [r[1] for r in res], label="$\sigma = %f$" % sigma)
        plt.plot(t, [r[2] for r in res])
    plt.legend()
    plt.show()
示例#4
0
文件: examples.py 项目: delsuc/SpinEq
def EL_STD_3s(Khigh=1 / 45E-6,
              Ltot=1E-3,
              Etot=1E-4,
              time=5.0,
              verbose=False,
              trajectory=False):
    """
    STD exp on
    E + L <-> EL equilibrium
    L (1 spin) + E (1 spin saturated) <--> EL (two spins)
    Same as EL_STD, but here a three spin model is used for the protein-ligand complex :
    EL : (L - E1 - E2) where only E2 is saturated
    """
    # set-up equilibrium
    print("K=", Khigh)
    eq1 = NMR(("E", "L", "EL"), 6)
    L = 0
    E = 1
    EL = 2
    eq1.set_K3(Khigh, L, E, EL)
    eq1.set_concentration(Ltot, L)
    eq1.set_concentration(Etot, E)
    eq1.set_massconserv(Ltot, [1, 0, 1])  # in L
    eq1.set_massconserv(Etot, [0, 1, 1])  # in E
    # then add spin systems
    R1L = R1E = 1.0
    sigma = -0.99
    RelaxE = np.matrix([[R1E, sigma], [sigma, R1E]])
    RelaxEL = np.matrix([[R1E, sigma, 0.0], [sigma, R1E, sigma],
                         [0.0, sigma, R1E]])
    eq1.set_spin(L, SpinSys(1, R1L))  #L
    eq1.set_spin(E, SpinSys(2, RelaxE))  #E
    eq1.set_spin(EL, SpinSys(3, RelaxEL))  #EL
    eq1.set_spinflux(E, 0, EL, 1)  # which is which
    eq1.set_spinflux(E, 1, EL, 2)  # which is which
    eq1.set_spinflux(L, 0, EL, 0)
    if verbose:
        print("\nDepart\n")
        eq1.report()
        print("state_dic", eq1.state_dic)
        print("dic_state", eq1.dic_state)
        print("species2spins")
        for i in range(eq1.Nspecies):
            print(i, list(eq1.species2spins(i)))
        print("spin2species")
        for i in range(eq1.Nspins):
            print(i, eq1.spin2species(i))
    # compute equilibrium
    cf = eq1.solve(maxtime=1E-2, step=100)
    # then apply saturation
    eq1.conc = cf[0:3]
    eq1.saturate(E, 1)  # we saturate the protein
    eq1.saturate(EL, 2)
    if verbose:
        print("\nsaturation\n")
        eq1.report()
    st = max(1, time / 1E-3)  # computes at 1ms resolution
    res = eq1.solve(maxtime=time,
                    step=st,
                    trajectory=trajectory,
                    verbose=verbose)
    if trajectory:
        (t, cf3) = res
        plt.plot(t, cf3[:, 3])
        (t, cf) = EL_STD(trajectory=True, time=time)
        plt.plot(t, cf[:, 3])
        plt.show()
    return res
示例#5
0
文件: examples.py 项目: delsuc/SpinEq
def EL_STD(Khigh=1 / 3E-4,
           Ltot=1E-3,
           Etot=1E-4,
           time=1.0,
           step=10,
           verbose=False,
           trajectory=False):
    """
    Saturation Difference Difference experience on the equilibrium
    E + L <-> EL 
    L (1 spin) + E (1 spin saturated) <--> EL (two spins - E spin saturated)
    
    """
    # set-up equilibrium
    Dprint("K=", Khigh)
    eq1 = NMR(("E", "L", "EL"), 4)
    L = 0
    E = 1
    EL = 2
    eq1.set_K3(Khigh, L, E, EL)
    eq1.set_concentration(Ltot, L)
    eq1.set_concentration(Etot, E)
    eq1.set_massconserv(Ltot, [1, 0, 1])  # in L
    eq1.set_massconserv(Etot, [0, 1, 1])  # in E
    # then add spin systems
    R1L = 1.0
    R1E = 10.0
    sigma = -0.5 * R1E
    eq1.set_spin(L, SpinSys(1, R1L))  #L
    eq1.set_spin(E, SpinSys(1, R1E))  #E
    Relax = np.matrix([[R1E, sigma], [sigma, R1E]])
    eq1.set_spin(EL, SpinSys(2, Relax))  #EL
    eq1.set_spinflux(E, 0, EL, 1)  # which is which
    eq1.set_spinflux(L, 0, EL, 0)
    if verbose:
        print(r"\Starting\n")
        eq1.report()
    # compute equilibrium
    cf = eq1.solve(maxtime=1E-3, step=10)
    #    eq1.Integrator = "odeint"
    # then apply saturation
    eq1.saturate(E, 0)  # we saturate the protein
    eq1.saturate(EL, 1)  # in both binding states !

    if verbose:
        print("\nsaturation\n")
        eq1.report()
    res = eq1.solve(maxtime=time,
                    step=step,
                    trajectory=trajectory,
                    verbose=verbose)
    finale = eq1.get_concentration_array()
    if verbose:
        print("\n final concentrations:")
        eq1.showconc()
        print("\n final magnetizations:")
        eq1.showmagn()
        print("fraction occupied %f %%" % (100 * finale[EL] /
                                           (finale[E] + finale[EL])))
    if not trajectory:
        print("EL_STD: Kd %.2g     STD : %.2f %%" % (1 / Khigh, 100 *
                                                     (1 - res[3])))
    return res
示例#6
0
文件: examples.py 项目: delsuc/SpinEq
def T1n(n=5):
    """
    compares selective and global T1 in n coupled spins system
    """
    # set-up equilibrium
    eq1 = NMR(1, n)
    #  add spin systems
    R1E = 0.5 * (n + 1)  # non selectif T1 : spin-lattice relaxation
    sigma = -0.5  # strong sigma, corresponding to a large prot
    Relax = np.matrix(sigma * np.ones((n, n)))  # set sigma everywhere
    for i in range(n):
        Relax[i, i] = R1E  # set diagonal to T1
    eq1.set_spin(0, SpinSys(n, Relax))
    eq1.set_magnetization(0.0, 0, 0)  # pulse on one spin
    eq1.report()
    st = 10. / 1e-2
    (t, res) = eq1.solve(maxtime=10.0, step=st,
                         trajectory=True)  #,verbose=True)
    plt.plot(t, [r[1] for r in res], label="selective pulse")
    # second exp
    for i in range(n):
        eq1.set_magnetization(0.0, 0, i)  # pulse on all spin
    eq1.report()
    st = 10. / 1e-2
    (t, res) = eq1.solve(maxtime=10.0, step=st,
                         trajectory=True)  #,verbose=True)
    plt.plot(t, [r[1] for r in res], label="global excitation")
    plt.title("magnetization recovery\nin a %d coupled spin system" % n)
    plt.legend()
    plt.show()
示例#7
0
文件: examples.py 项目: delsuc/SpinEq
def T1():
    """
    compares selective and global T1 in 2 coupled spins system
    """
    # set-up equilibrium
    eq1 = NMR(1, 2)
    #  add spin systems
    R1E = 1.0  # non selectif T1 : spin-lattice relaxation
    sigma = -0.5  # strong sigma, corresponding to a large prot
    Relax = np.matrix([[R1E, sigma], [sigma, R1E]])
    eq1.set_spin(0, SpinSys(2, Relax))
    eq1.set_magnetization(0.0, 0, 0)  # pulse on one spin
    eq1.report()
    st = 10. / 1e-2
    (t, res) = eq1.solve(maxtime=10.0, step=st,
                         trajectory=True)  #,verbose=True)
    plt.plot(t, [r[1] for r in res], label="selective pulse")
    # second exp
    eq1.set_magnetization(0.0, 0, 0)  # pulse on both spin
    eq1.set_magnetization(0.0, 0, 1)  # pulse on both spin
    eq1.report()
    st = 10. / 1e-2
    (t, res) = eq1.solve(maxtime=10.0, step=st,
                         trajectory=True)  #,verbose=True)
    plt.plot(t, [r[1] for r in res], label="global excitation")
    plt.title("magnetization recovery\nin a two coupled spin system")
    plt.legend()
    plt.show()