Пример #1
0
def integrate_euler(X, V, iparams, blist, sp):
    """
    Euler integration for Nt steps.
    Save each thermo-multiple step into xyz_frames.
    Mass set to 1.0. Input:
    * X: (N, 3) matrix
    * V: (N, 3) matrix
    * iparams: dict mapping bead type to a_ij
    * blist: list of bead types (bead list)
    * sp: system params
    """
    T, E = np.zeros(sp.Nt), np.zeros(sp.Nt)
    F = np.zeros(X.shape)
    N = len(X)
    ti = time.time()
    
    for i in range(sp.Nt):
        X = X + V * sp.dt
        V = V + F * sp.dt
        F = force_list(X, V, iparams, blist, sp)

        X = X % sp.L
        KE = tot_KE(V)
        E[i] = KE + tot_PE(X, iparams, blist, sp.rc)
        T[i] = KE / (3.0 / 2.0 * N)
        tf = time.time()
        if (i+1) % sp.thermo == 0:
            save_xyzmatrix("Dump/dump_%3i.xyz" % (i+1), blist, X)
            print("Step: %i | t: %.4f | T: %.5f | E: %.3e | Time: %.2f" % \
                (i+1, i * sp.dt, T[i], E[i], tf - ti))
    return T, E
Пример #2
0
def integrate_verlet(X, V, iparams, blist, sp):
    """
    Verlet integration for Nt steps.
    Save each thermo-multiple step into xyz_frames.
    Mass set to 1.0. Input:
    * X: (N, 3) matrix
    * V: (N, 3) matrix
    * iparams: dict mapping bead type to a_ij
    * blist: list of bead types (bead list)
    * sp: system params
    """
    T, E = np.zeros(sp.Nt), np.zeros(sp.Nt)
    N = len(X)
    Vtemp = np.zeros(X.shape)
    Fnew = np.zeros(X.shape)
    ti = time.time()

    F = force_list(X, V, iparams, blist, \
            sp.L, sp.gamma, sp.kT, sp.dt, sp.rc)
    T[0] = temperature(V)
    E[0] = tot_KE(V) + tot_PE(X, iparams, blist, sp.rc)
    save_xyzmatrix("Dump/dump_%i.xyz" % 0, blist, X)

    for i in range(1, sp.Nt):
        # 1. GW formulation DIVERGES TWICE AS MUCH AS 3rd!
#        X = X + V * sp.dt + F * sp.dt**2 / 2.0
#        Vtemp = V + F * sp.dt / 2.0
#        Fnew = force_list(X, Vtemp, iparams, blist, \
#                sp.L, sp.gamma, sp.kT, sp.dt, sp.rc)
#        V = Vtemp + (F + Fnew) * sp.dt / 2
#        F = Fnew

        # 2. Wiki formulation without half-step velocity
        X = X + V * sp.dt + F * sp.dt**2 / 2.0
        Fnew = force_list(X, V, iparams, blist, \
                sp.L, sp.gamma, sp.kT, sp.dt, sp.rc)
        V = V + (F + Fnew) * sp.dt / 2.0
        F = Fnew

        X = X % sp.L

        KE = tot_KE(V)
        E[i] = KE + tot_PE(X, iparams, blist, sp.rc)
        T[i] = KE / (3.0 / 2.0 * N)
        tf = time.time()
        if (i+1) % sp.thermo == 0:
            save_xyzmatrix("Dump/dump_%i.xyz" % (i+1), blist, X)
            print("Step: %i | t: %.3f | T: %.5f | E: %.3e | Time: %.2f" % \
                (i+1, i * sp.dt, T[i], E[i], tf - ti))
    return T, E
Пример #3
0
def integrate_verlet(X, V, iparams, blist, sp):
    """
    Verlet integration for Nt steps.
    Save each thermo-multiple step into xyz_frames.
    Mass set to 1.0. Input:
    * X: (N, 3) matrix
    * V: (N, 3) matrix
    * iparams: (Nbt, Nbt) matrix with interaction params
    * blist: list of bead types (bead list)
    * sp: misc system params
    """
    T, E = np.zeros(sp.Nt), np.zeros(sp.Nt)
    Vtemp = np.zeros(X.shape)
    Fnew = np.zeros(X.shape)
    ti = time.time()

    F = force_list(X, V, iparams, blist, sp)
    T[0] = temperature(V)
    E[0] = tot_KE(V) + tot_PE(X, iparams, blist, sp)
    save_xyzmatrix("Dump/dump_%i.xyz" % 0, blist, X)
    tf = time.time()

    for i in range(1, sp.Nt):
        X = X + V * sp.dt + F * sp.dt**2 / 2.0
        Fnew = force_list(X, V, iparams, blist, sp)
        V = V + (F + Fnew) * sp.dt / 2.0
        F = Fnew

        X = X % L

        T[i] = temperature(V)
        E[i] = tot_KE(V) + tot_PE(X, iparams, blist, sp)
        tf = time.time()
        if (i+1) % sp.thermo == 0:
            save_xyzmatrix("Dump/dump_%3i.xyz" % (i+1), blist, X)
            print("Step: %i | t: %.4f | T: %.5f | E: %.3e | Time: %.2f" % \
                (i+1, i * dt, T[i], E[i], tf - ti))
    return T, E