Exemplo n.º 1
0
def ACMD_instance(rng, N, beads, dpotential, beta, T, deltat):

    swarmobject = MD_System.swarm(N)
    MD_System.system_definition(beta, beads, 1, MD_System.dpotential)
    #gamma = 1.0
    #w_arr = beads**0.5/(beta*gamma)*np.ones(beads)
    #MD_System.w_arr = MD_System.rearrange(w_arr)
    #MD_System.w_arr[0] = 0.0

    importlib.reload(Velocity_verlet)

    swarmobject.q = np.zeros(
        (swarmobject.N, MD_System.dimension, MD_System.n_beads))
    rand_boltz = np.random.RandomState(rng)
    swarmobject.p = rand_boltz.normal(0.0, swarmobject.m / (MD_System.beta),
                                      np.shape(swarmobject.q))

    pool = mp.Pool(mp.cpu_count())
    Matsubara = 0
    CMD = 0

    n_inst = 10
    func = partial(corr_function_upgrade, CMD, Matsubara, beads, swarmobject,
                   dpotential, MD_System.pos_op, MD_System.pos_op, T, deltat)
    results = pool.map(func, range(n_inst))

    pool.close()
    pool.join()
    return np.sum(results, 0) / n_inst
Exemplo n.º 2
0
def mean_force_calculation(dpotential):
    print(MD_System.n_beads,MD_System.w_arr)
    N = 100
    deltat = 1e-2
    Q = np.linspace(-10,10,100)
    swarmobject = MD_System.swarm(N)
    rand_boltz = np.random.RandomState(1000)
    swarmobject.p = rand_boltz.normal(0.0,swarmobject.m/MD_System.beta,(swarmobject.N,MD_System.dimension,MD_System.n_beads))
    print(np.shape(swarmobject.p))
    n_sample = 10
    rng=np.random.RandomState(1000)
    CMD=1
    
    CMD_force = np.zeros((len(Q),MD_System.dimension))
    
    for j in range(len(Q)):
        
        swarmobject.q = np.zeros((swarmobject.N,MD_System.dimension,MD_System.n_beads)) + Q[j]
        #print(swarmobject.q)
        #print(np.shape(swarmobject.q))
        thermalize(CMD,0,0,swarmobject,dpotential,deltat,5,rng)
        
        for i in range(n_sample):
            CMD_force[j] += np.mean(dpotential(swarmobject.q))
            thermalize(CMD,0,0,swarmobject,dpotential,deltat,2,rng)
    
    
    CMD_force/=n_sample    
        
    f = open("CMD_Force_Morse_B_{}_NB_{}_100_10.dat".format(MD_System.beta,MD_System.n_beads),'w+')
    CMD_force = CMD_force[:,0]
    print(CMD_force)
    for x in zip(Q,CMD_force):
        f.write("{}\t{}\n".format(x[0],x[1]))
    f.close()
Exemplo n.º 3
0
def AQCMD_instance(rng, N, beads, dpotential, beta, T, deltat):
    swarmobject = MD_System.swarm(N)

    MD_System.system_definition(beta, beads, 2, MD_System.dpotential)
    importlib.reload(Velocity_verlet)

    rand_boltz = np.random.RandomState(2)
    print('beta', MD_System.beta, MD_System.beta_n)
    swarmobject.q = np.zeros(
        (swarmobject.N, MD_System.dimension, MD_System.n_beads)
    ) + 1.0  #np.random.rand(swarmobject.N,MD_System.dimension,MD_System.n_beads)
    swarmobject.p = rand_boltz.normal(0.0, swarmobject.m / (MD_System.beta_n),
                                      np.shape(swarmobject.q))

    # In the line above, 1.0 is should be replaced with beta, when required
    # Update: Done!!!
    QC_q = np.zeros((swarmobject.N, MD_System.dimension)) + 1.0
    QC_p = np.zeros_like(
        QC_q
    )  #rand_boltz.normal(0.0,swarmobject.m/(MD_System.beta),np.shape(QC_q))#np.zeros((swarmobject.N,MD_System.dimension))
    lambda_curr = np.zeros_like(swarmobject.q)

    pool = mp.Pool(mp.cpu_count())
    n_inst = 1
    func = partial(corr_function_QCMD, swarmobject, QC_q, QC_p, lambda_curr,
                   MD_System.pos_op, MD_System.pos_op, T, deltat, dpotential)
    results = pool.map(func, range(n_inst))
    #print('results',np.sum(results,0)/n_inst)
    pool.close()
    pool.join()
    return np.sum(results, 0) / n_inst
Exemplo n.º 4
0
def QC_MF_calculation(dpotential, N, n_sample):
    print(MD_System.n_beads, MD_System.w_arr)
    deltat = 5e-1
    Q = np.linspace(0.01, 3.0, 20)
    QC_MF = np.zeros((len(Q), MD_System.dimension))
    swarmobject = MD_System.swarm(N)
    rand_boltz = np.random.RandomState(1)
    swarmobject.p = rand_boltz.normal(
        0.0, swarmobject.m / MD_System.beta,
        (swarmobject.N, MD_System.dimension, MD_System.n_beads))
    rng = np.random.RandomState(1)

    for j in range(len(Q)):
        swarmobject.q = np.zeros(
            (swarmobject.N, MD_System.dimension, MD_System.n_beads)) + 1.0
        print('j', j, time.time() - start_time)
        QC_q = np.zeros((swarmobject.N, MD_System.dimension))
        QC_q[:, 0] = Q[j]
        #print(np.shape(QC_q[:,0]))
        QC_p = np.zeros_like(QC_q)
        lambda_curr = np.zeros_like(swarmobject.q)

        Langevin_thermostat.qcmd_thermalize(1, swarmobject, QC_q, QC_p,
                                            lambda_curr, dpotential, deltat,
                                            1000, rng)

        for i in range(n_sample):
            QC_MF[j] += np.mean(Velocity_verlet.dpotential_qcentroid(
                QC_q, swarmobject, dpotential),
                                axis=0)
            Langevin_thermostat.qcmd_thermalize(1, swarmobject, QC_q, QC_p,
                                                lambda_curr, dpotential,
                                                deltat, 500, rng)
            print('time', time.time() - start_time)
    QC_MF /= n_sample
    ### BE CAREFUL WITH THE SIGN OF THE POTENTIAL HERE. You have used
    #   force and gradient of potential interchangeably
    f = open(
        "/home/vgs23/Pickle_files/QCMD_Force_B_{}_NB_{}_N_{}_nsample_{}_deltat_{}_NQ_{}.dat"
        .format(MD_System.beta, MD_System.n_beads, N, n_sample, deltat,
                len(Q)), 'w+')
    QCMD_force = QC_MF[:, 0]
    for x in zip(Q, QCMD_force):
        f.write("{}\t{}\n".format(x[0], x[1]))
    f.close()

    plt.plot(Q, QC_MF[:, 0], color='r')
    plt.plot(Q, QC_MF[:, 1], color='b')
    plt.show()
Exemplo n.º 5
0
def Matsubara_instance(rng, N, M, dpotential, T, deltat):
    swarmobject = MD_System.swarm(N)
    MD_System.system_definition(8, M, 2, MD_System.dpotential)
    importlib.reload(Velocity_verlet)

    swarmobject.q = np.zeros(
        (swarmobject.N, MD_System.dimension, MD_System.n_beads))

    rand_boltz = np.random.RandomState(rng)
    swarmobject.p = rand_boltz.normal(0.0, swarmobject.m / MD_System.beta,
                                      np.shape(swarmobject.q))

    pool = mp.Pool(mp.cpu_count())
    Matsubara = 1
    CMD = 0

    n_inst = 10
    func = partial(corr_function_matsubara, CMD, Matsubara, M, swarmobject,
                   dpotential, MD_System.pos_op, MD_System.pos_op, T, deltat)
    results = pool.map(func, range(n_inst))
    pool.close()
    pool.join()
    return np.sum(results, 0) / n_inst
Exemplo n.º 6
0
            #thermalize(CMD,Matsubara,M,swarmobj,derpotential,deltat,4,rng)
            print(time.time() - start_time)
        Quan_arr /= (n_approx * swarmobj.N)

    for j in range(n_approx):
        traj_arr = Monodromy.ode_instance(swarmobj.q, swarmobj.p, tarr)
        Quan_arr += np.sum(Monodromy.detmqq(traj_arr), axis=1)
        thermalize(CMD, Matsubara, M, swarmobj, derpotential, deltat, 10, rng)

    return Quan_arr


N = 20
dim = 3
deltat = 1e-2
swarmobject = MD_System.swarm(N)
MD_System.system_definition(78943.7562025, 1, dim, MD_System.dpotential)
imp.reload(Velocity_verlet)
Monodromy.system_definition(N, dim)

rand_boltz = np.random.RandomState(1)
swarmobject.q = rand_boltz.rand(swarmobject.N, MD_System.dimension,
                                MD_System.n_beads)
swarmobject.p = rand_boltz.normal(0.0, swarmobject.m / (MD_System.beta),
                                  np.shape(swarmobject.q))

Matsubara = 0
CMD = 0
M = 0
T = 10.0
Marr = phase_space_average(CMD, Matsubara, M, swarmobject,
Exemplo n.º 7
0
def mean_force_calculation_2D(dpotential):
    print(MD_System.n_beads,MD_System.w_arr)
    N = 100
    deltat = 1e-2
    x = np.linspace(-5,5,101)
    y = np.linspace(-5,5,101)
    X,Y = np.meshgrid(x,y)
    
    swarmobject = MD_System.swarm(N)
    rand_boltz = np.random.RandomState(1000)
    swarmobject.p = rand_boltz.normal(0.0,swarmobject.m/MD_System.beta,(swarmobject.N,MD_System.dimension,MD_System.n_beads))
    print(np.amax(swarmobject.p))
    n_sample = 10
    rng=np.random.RandomState(1000)
    CMD=1
    
    
    CMD_force = np.zeros((len(x),len(y),MD_System.dimension))
    
    for i in range(len(x)):
        for j in range(len(y)):
            swarmobject.q = np.zeros((swarmobject.N,MD_System.dimension,MD_System.n_beads)) 
            
            swarmobject.q[:,0,:] = X[i][j]
            swarmobject.q[:,1,:] = Y[i][j]

        
            thermalize(CMD,0,0,swarmobject,dpotential,deltat,2,rng)
            for k in range(n_sample):
                #print(np.amax(swarmobject.p))
                force = np.mean(dpotential(swarmobject.q),axis=2)
                force = np.mean(force,axis=0)
                CMD_force[i][j] += force
                thermalize(CMD,0,0,swarmobject,dpotential,deltat,2,rng)
        print(time.time()-start_time)
    CMD_force/=n_sample
    
    f = open("CMD_Force_2D_B_{}_NB_{}_101_10.dat".format(MD_System.beta,MD_System.n_beads),'wb')
   
    plt.imshow(CMD_force[:,:,1],origin='lower')    
#    for i in range(len(x)):
#        for j in range(len(y)):
#            f.write("{}\t{}\t{}\n".format(X[i][j],Y[i][j],CMD_force[i][j]))
    

    pickle.dump(x,f)
    pickle.dump(y,f)
    pickle.dump(CMD_force,f)
    f.close()


#    l=64-15
#    u=64+15
#    plt.plot(Q[l:u],CMD_force[l:u])
#    ##plt.scatter(Q,CMD_force)
#    plt.plot(data[l:u,0],-data[l:u,1],color='r')
#    plt.show()
    #return CMF
#mean_force_calculation()
#print(mean_force(4.0))

#print(CMD_force)