Example #1
0
def do_dynamics(mdlogf, atoms, dyn, rend_b, rend_t, v, dt, deltaY_old, theta, dtheta, \
                L, thres_Z, interval, traj, M, twist, save = True):
    
    write_line_own(mdlogf, '# Hysteresis simul begins \n', 'w')
    
    #kink_vanis  =   False
    
    y0          =   atoms.positions[rend_b, 1]      
    i,m         =   0, 0
    time        =   0.

    while 0 < theta:
        
        theta  -=   dtheta
        twist.set_angle(theta)
        dyn.run(1)
        
        if i % interval == 0:
            
            epot, ekin  =   saveAndPrint(atoms, traj, False)[:2]
            
            deltaY      =   deltaY_old + atoms.positions[rend_b, 1] - y0
            R           =   get_R(L, deltaY)
            hmax        =   np.max(atoms.positions[:,2]) - 3.4 #subsract the height of the plane
            data        =   [time, deltaY, R, theta, hmax, epot, ekin, epot + ekin]
            #data        =   [i * dt, deltaY, R, theta, epot, ekin, epot + ekin]
            
            
            if save:
                stringi =   ''
                for k,d in enumerate(data):
                    if k == 0:           
                        stringi += '%.2f ' %d
                    elif k == 1 or k == 2:
                        stringi += '%.4f ' %d
                    else:
                        stringi += '%.12f ' %d
                write_line_own(mdlogf, stringi +  '\n', 'a')
                  
            print i/interval, theta / (2*np.pi) * 360, R 
            
            if np.max(atoms.positions[:,2]) < thres_Z and m == 0:
                write_line_own(mdlogf, '# Kink vanish! ' +  '\n', 'a')
                print ' kink vanished! '
                m += 1
                #kink_vanis     =   True
                
                
        if i % int(M/100) == 0:    theta / (2 * np.pi) *360
        #if kink_vanis:  m   +=  1
        
        i      +=  1
        time   +=   dt       
Example #2
0
def do_dynamics(mdlogf, atoms, dyn, rend_b, rend_t, v, dt, deltaY_old, theta, dtheta, \
                L, thres_Z, interval, traj, M, twist, save = True):

    write_line_own(mdlogf, '# Hysteresis simul begins \n', 'w')

    #kink_vanis  =   False

    y0 = atoms.positions[rend_b, 1]
    i, m = 0, 0
    time = 0.

    while 0 < theta:

        theta -= dtheta
        twist.set_angle(theta)
        dyn.run(1)

        if i % interval == 0:

            epot, ekin = saveAndPrint(atoms, traj, False)[:2]

            deltaY = deltaY_old + atoms.positions[rend_b, 1] - y0
            R = get_R(L, deltaY)
            hmax = np.max(
                atoms.positions[:, 2]) - 3.4  #subsract the height of the plane
            data = [time, deltaY, R, theta, hmax, epot, ekin, epot + ekin]
            #data        =   [i * dt, deltaY, R, theta, epot, ekin, epot + ekin]

            if save:
                stringi = ''
                for k, d in enumerate(data):
                    if k == 0:
                        stringi += '%.2f ' % d
                    elif k == 1 or k == 2:
                        stringi += '%.4f ' % d
                    else:
                        stringi += '%.12f ' % d
                write_line_own(mdlogf, stringi + '\n', 'a')

            print i / interval, theta / (2 * np.pi) * 360, R

            if np.max(atoms.positions[:, 2]) < thres_Z and m == 0:
                write_line_own(mdlogf, '# Kink vanish! ' + '\n', 'a')
                print ' kink vanished! '
                m += 1
                #kink_vanis     =   True

        if i % int(M / 100) == 0: theta / (2 * np.pi) * 360
        #if kink_vanis:  m   +=  1

        i += 1
        time += dt
Example #3
0
def shearDyn(width, ratio, edge, save=False, force_dir_update=True):

    atoms, L, W, length_int, b_idxs = create_stucture(ratio,
                                                      width,
                                                      edge,
                                                      key='rib+base')

    view(atoms)
    # FIXES
    constraints, add_LJ, rend_b, rend_t = get_constraints(
        atoms, edge, bond, b_idxs)
    # END FIXES

    # CALCULATOR LAMMPS
    calc = LAMMPS(parameters=get_lammps_params())
    atoms.set_calculator(calc)
    # END CALCULATOR

    # TRAJECTORY
    add = ''
    if force_dir_update: add = '_ff'
    mdfile, mdlogfile, mdrelax, simulfile   =   get_fileName('LJ', edge + add, width, \
                                                 length_int, int(T), taito)

    if save: traj = PickleTrajectory(mdfile, 'w', atoms)
    else: traj = None

    #data    =   np.zeros((M/interval, 5))

    # RELAX
    atoms.set_constraint(add_LJ)
    dyn = BFGS(atoms, trajectory=mdrelax)
    dyn.run(fmax=0.05)

    # FIX AFTER RELAXATION
    atoms.set_constraint(constraints)

    # DYNAMICS
    dyn = Langevin(atoms, dt * units.fs, T * units.kB, fric)
    n = 0
    header = '#t [fs], shift y [Angstrom], Rad, epot_tot [eV], ekin_tot [eV], etot_tot [eV] \n'
    write_line_own(mdlogfile, header, 'w')

    if T != 0:
        # put initial MaxwellBoltzmann velocity distribution
        mbd(atoms, T * units.kB)

    deltaY = 0.
    eta = 1.1  # ratio between the lengths of the streched and compressed side of the ribbon.
    r = L / W  # length to width ratio.
    deltaYMax = W / 2. * (eta + 1) / (eta - 1) * (1 - np.cos(2 * r *
                                                             (eta - 1) /
                                                             (eta + 1)))

    # Estimate for the required shift
    dy = v * dt
    M = deltaYMax / dy
    interval = int(M / 1000)

    kink_formed = False
    dir_vec = np.array([0., 1., 0.])
    i, m = 0, 0
    print 'width = %i, length = %i' % (width, length_int)
    while m <= int(M / 30):

        if tau < i * dt:
            deltaY += dy * dir_vec[1]
            for ind in rend_b:
                atoms[ind].position[:] += dy * dir_vec

        dyn.run(1)

        if i % interval == 0:

            epot, ekin = saveAndPrint(atoms, traj, False)[:2]

            R = get_R(L, deltaY)
            if force_dir_update: dir_vec = get_dir(atoms, rend_b, rend_t)
            data = [i * dt, deltaY, R, epot, ekin, epot + ekin]

            if save:
                stringi = ''
                for k, d in enumerate(data):
                    if k == 0:
                        stringi += '%.2f ' % d
                    elif k == 1 or k == 2:
                        stringi += '%.4f ' % d
                    else:
                        stringi += '%.12f ' % d
                write_line_own(mdlogfile, stringi + '\n', 'a')

            n += 1

            if thres_Z < np.max(atoms.positions[:, 2]) and m == 0:
                idxs = np.where(thres_Z < atoms.positions[:, 2])
                write_line_own(mdlogfile,
                               '# Kink! at idxs %s' % str(idxs) + '\n', 'a')
                print ' kink formed! '
                kink_formed = True

        if save and T != 0 and i * dt == tau:
            write_line_own(mdlogfile, '# Thermalization complete. ' + '\n',
                           'a')

        if i % int(M / 100) == 0: print str(i / int(M / 100)) + ' ~ % done'
        if kink_formed: m += 1
        i += 1


    make_simul_param_file(simulfile, W, L, width, length_int, v, dy, T, \
                          dt, fric, thres_Z, interval, deltaY, M, edge)
Example #4
0
def shearDyn(params_set, pot_key, save = False):
    
    bond    =   params_set['bond']
    T       =   params_set['T']
    taito   =   params_set['taito']
    dt, fric=   params_set['dt'], params_set['fric']
    tau     =   params_set['tau']
    vmax    =   params_set['vmax']
    vMAX    =   params_set['vMAX']
    thres_Z =   params_set['thresZ']
    width   =   params_set['width']
    ratio   =   params_set['ratio']
    edge    =   params_set['edge']
    
    
    
    atoms, L, W, length_int, b_idxs     =   \
            create_stucture(ratio, width, edge, key = 'top', a = bond)
    
    mdfile, mdlogfile, mdrelax, simulfile, folder, relaxed \
                        =   get_fileName(pot_key, edge + '_twistRod', width, \
                                        length_int, vmax * 1000, int(T), taito)
    
    
    #view(atoms)
    # FIXES
    constraints, add_pot, twist, rend_b, rend_t =   \
            get_constraints(atoms, edge, bond, b_idxs, \
                            key = 'twist_p', pot = pot_key)
    # END FIXES

    if relaxed:
        atoms   =   PickleTrajectory(mdrelax, 'r')[-1]
    else:
        trans   =   trans_atomsKC(atoms.positions[rend_b], edge, bond)
        atoms.translate(trans) 
    
    #plot_posits(atoms, edge, bond)
    
    # CALCULATOR LAMMPS 
    calc    =   LAMMPS(parameters=get_lammps_params()) 
    atoms.set_calculator(calc)
    # END CALCULATOR
    
    # TRAJECTORY
    if save:    traj    =   PickleTrajectory(mdfile, 'w', atoms)
    else:       traj    =   None
    
    #data    =   np.zeros((M/interval, 5))
    
    # RELAX
    atoms.set_constraint(add_pot)
    dyn     =   BFGS(atoms, trajectory = mdrelax)
    dyn.run(fmax=0.05)

    dist    =   np.linalg.norm(atoms.positions[rend_b] - atoms.positions[rend_t])
    twist.set_dist(dist)
    # FIX AFTER RELAXATION
    atoms.set_constraint(constraints)
    
    # DYNAMICS
    dyn     =   Langevin(atoms, dt*units.fs, T*units.kB, fric)
    header  =   '#t [fs], shift y [Angstrom], Rad, theta [rad], hmax [A], epot_tot [eV], ekin_tot [eV], etot_tot [eV], F [eV/angst] \n'
    write_line_own(mdlogfile, header, 'w')

    if T != 0:
        # put initial MaxwellBoltzmann velocity distribution
        mbd(atoms, T*units.kB)
    
    y0          =   atoms.positions[rend_b, 1]
    
    kink_formed =   False
    kink_vanished   =   False
    i           =   0
    print 'width = %i, length = %i, v=%.6f' %(width, length_int, vmax)
    
    
    M_therm     =   int(tau / dt)
    dyn.run(M_therm)
    
    M               =   int(2 * L / (np.pi * dt * vmax))
    M_min           =   int(2 * L / (np.pi * dt * vMAX))
    dtheta          =   np.pi / 2 / M
    dtheta_max      =   np.pi / 2 / M_min
    
    interval        =   int( M / 1000 ) 
    theta, time, m  =   0., 0., 0
    i_kink          =   0
    
    
    while 0. <= theta:
        
        if not kink_formed:
            if theta < np.pi/4:
                theta      +=   dtheta_max
            else:
                theta      +=   dtheta
            twist.set_angle(theta)
        else:
            if i_kink / 10 < m: 
                theta      -=   dtheta
                twist.set_angle(theta)
            
        dyn.run(1)
        
        if i % interval == 0:
            epot, ekin  =   saveAndPrint(atoms, traj, False)[:2]
            deltaY      =   atoms.positions[rend_b, 1] - y0
            
            hmax        =   np.max(atoms.positions[:,2]) #substract the height of the plane?
            R           =   get_R(L, deltaY)
            data        =   [time, deltaY, R, theta, hmax, epot, ekin, epot + ekin]
            
            if save:
                stringi =   ''
                for k,d in enumerate(data):
                    if k == 0:           
                        stringi += '%.2f ' %d
                    elif k == 1 or k == 2:
                        stringi += '%.4f ' %d
                    else:
                        stringi += '%.12f ' %d
                write_line_own(mdlogfile, stringi +  '\n', 'a')
        
            if thres_Z  <   hmax and not kink_formed:
                idxs    =   np.where(thres_Z < atoms.positions[:,2])
                write_line_own(mdlogfile, '# Kink! at idxs %s' %str(idxs) +  '\n', 'a')
                print ' kink formed! ' + str(i / interval)
                kink_formed     =   True
                i_kink  =   i
                
            if hmax < 3.6 and kink_formed and not kink_vanished:
                write_line_own(mdlogfile, '# Kink vanished! \n', 'a')
                print ' kink vanished '
                kink_vanished   =   True


            print i/interval, theta / (2*np.pi) * 360, R
        
        if kink_formed: m += 1
        
        i      +=   1
        time   +=   dt     

    
    make_simul_param_file(simulfile, W, L, width, length_int, dtheta/dt, dtheta, T, \
                          dt, fric, thres_Z, interval, deltaY, theta, i, edge)
    
    return folder
Example #5
0
def shearDyn(params_set, pot_key, save=False):

    bond = params_set['bond']
    T = params_set['T']
    taito = params_set['taito']
    dt, fric = params_set['dt'], params_set['fric']
    tau = params_set['tau']
    vmax = params_set['vmax']
    vMAX = params_set['vMAX']
    thres_Z = params_set['thresZ']
    width = params_set['width']
    ratio = params_set['ratio']
    edge = params_set['edge']



    atoms, L, W, length_int, b_idxs     =   \
            create_stucture(ratio, width, edge, key = 'top', a = bond)

    mdfile, mdlogfile, mdrelax, simulfile, folder, relaxed \
                        =   get_fileName(pot_key, edge + '_twistRod', width, \
                                        length_int, vmax * 1000, int(T), taito)

    #view(atoms)
    # FIXES
    constraints, add_pot, twist, rend_b, rend_t =   \
            get_constraints(atoms, edge, bond, b_idxs, \
                            key = 'twist_p', pot = pot_key)
    # END FIXES

    if relaxed:
        atoms = PickleTrajectory(mdrelax, 'r')[-1]
    else:
        trans = trans_atomsKC(atoms.positions[rend_b], edge, bond)
        atoms.translate(trans)

    #plot_posits(atoms, edge, bond)

    # CALCULATOR LAMMPS
    calc = LAMMPS(parameters=get_lammps_params())
    atoms.set_calculator(calc)
    # END CALCULATOR

    # TRAJECTORY
    if save: traj = PickleTrajectory(mdfile, 'w', atoms)
    else: traj = None

    #data    =   np.zeros((M/interval, 5))

    # RELAX
    atoms.set_constraint(add_pot)
    dyn = BFGS(atoms, trajectory=mdrelax)
    dyn.run(fmax=0.05)

    dist = np.linalg.norm(atoms.positions[rend_b] - atoms.positions[rend_t])
    twist.set_dist(dist)
    # FIX AFTER RELAXATION
    atoms.set_constraint(constraints)

    # DYNAMICS
    dyn = Langevin(atoms, dt * units.fs, T * units.kB, fric)
    header = '#t [fs], shift y [Angstrom], Rad, theta [rad], hmax [A], epot_tot [eV], ekin_tot [eV], etot_tot [eV], F [eV/angst] \n'
    write_line_own(mdlogfile, header, 'w')

    if T != 0:
        # put initial MaxwellBoltzmann velocity distribution
        mbd(atoms, T * units.kB)

    y0 = atoms.positions[rend_b, 1]

    kink_formed = False
    kink_vanished = False
    i = 0
    print 'width = %i, length = %i, v=%.6f' % (width, length_int, vmax)

    M_therm = int(tau / dt)
    dyn.run(M_therm)

    M = int(2 * L / (np.pi * dt * vmax))
    M_min = int(2 * L / (np.pi * dt * vMAX))
    dtheta = np.pi / 2 / M
    dtheta_max = np.pi / 2 / M_min

    interval = int(M / 1000)
    theta, time, m = 0., 0., 0
    i_kink = 0

    while 0. <= theta:

        if not kink_formed:
            if theta < np.pi / 4:
                theta += dtheta_max
            else:
                theta += dtheta
            twist.set_angle(theta)
        else:
            if i_kink / 10 < m:
                theta -= dtheta
                twist.set_angle(theta)

        dyn.run(1)

        if i % interval == 0:
            epot, ekin = saveAndPrint(atoms, traj, False)[:2]
            deltaY = atoms.positions[rend_b, 1] - y0

            hmax = np.max(
                atoms.positions[:, 2])  #substract the height of the plane?
            R = get_R(L, deltaY)
            data = [time, deltaY, R, theta, hmax, epot, ekin, epot + ekin]

            if save:
                stringi = ''
                for k, d in enumerate(data):
                    if k == 0:
                        stringi += '%.2f ' % d
                    elif k == 1 or k == 2:
                        stringi += '%.4f ' % d
                    else:
                        stringi += '%.12f ' % d
                write_line_own(mdlogfile, stringi + '\n', 'a')

            if thres_Z < hmax and not kink_formed:
                idxs = np.where(thres_Z < atoms.positions[:, 2])
                write_line_own(mdlogfile,
                               '# Kink! at idxs %s' % str(idxs) + '\n', 'a')
                print ' kink formed! ' + str(i / interval)
                kink_formed = True
                i_kink = i

            if hmax < 3.6 and kink_formed and not kink_vanished:
                write_line_own(mdlogfile, '# Kink vanished! \n', 'a')
                print ' kink vanished '
                kink_vanished = True

            print i / interval, theta / (2 * np.pi) * 360, R

        if kink_formed: m += 1

        i += 1
        time += dt


    make_simul_param_file(simulfile, W, L, width, length_int, dtheta/dt, dtheta, T, \
                          dt, fric, thres_Z, interval, deltaY, theta, i, edge)

    return folder
Example #6
0
def shearDyn(width, ratio, edge, save=False):

    atoms, L, W, length_int, b_idxs = create_stucture(ratio,
                                                      width,
                                                      edge,
                                                      key='top')

    view(atoms)
    # FIXES
    constraints, add_LJ, twist, rend_b, rend_t = get_constraints(atoms,
                                                                 edge,
                                                                 bond,
                                                                 b_idxs,
                                                                 key='twist')
    # END FIXES

    # CALCULATOR LAMMPS
    calc = LAMMPS(parameters=get_lammps_params())
    atoms.set_calculator(calc)
    # END CALCULATOR

    # TRAJECTORY
    mdfile, mdlogfile, mdrelax, simulfile   =   get_fileName('LJ', edge + '_twist', width, \
                                                 length_int, int(T), taito)

    if save: traj = PickleTrajectory(mdfile, 'w', atoms)
    else: traj = None

    #data    =   np.zeros((M/interval, 5))

    # RELAX
    atoms.set_constraint(add_LJ)
    dyn = BFGS(atoms, trajectory=mdrelax)
    dyn.run(fmax=0.05)

    # FIX AFTER RELAXATION
    atoms.set_constraint(constraints)

    # DYNAMICS
    dyn = Langevin(atoms, dt * units.fs, T * units.kB, fric)
    header = '#t [fs], shift y [Angstrom], Rad, epot_tot [eV], \
                ekin_tot [eV], etot_tot [eV], F [eV/angst] \n'

    write_line_own(mdlogfile, header, 'w')

    if T != 0:
        # put initial MaxwellBoltzmann velocity distribution
        mbd(atoms, T * units.kB)

    y0 = atoms.positions[rend_b, 1][0]

    kink_formed = False
    dir_vec = np.array([0., 1., 0.])
    i, m = 0, 0
    interval = 20
    print 'width = %i, length = %i' % (width, length_int)

    M_therm = int(tau / dt)

    dyn.run(M_therm)
    F = 0.

    while not kink_formed:

        pos_0 = atoms.positions[rend_b][0]
        F_vec = F * np.array([dir_vec[1], -dir_vec[0], 0.])
        twist.set_F(F_vec)
        dyn.run(interval)

        i += interval
        epot, ekin = saveAndPrint(atoms, traj, False)[:2]
        pos_1 = atoms.positions[rend_b][0]
        deltaY = pos_1[1] - y0

        v = np.sign(pos_1[1] - pos_0[1]) * np.linalg.norm(
            (pos_1 - pos_0) / (interval * dt))
        R = get_R(L, deltaY)
        dir_vec = get_dir(atoms, rend_b, rend_t)
        data = [
            i * dt, deltaY, R, epot, ekin, epot + ekin, F_vec[0], F_vec[1],
            F_vec[2]
        ]

        #if      vmax/5 < v:   F   -=  .01
        if v < vmax / 5 and not kink_formed: F += .01

        print deltaY, v, F

        if save:
            stringi = ''
            for k, d in enumerate(data):
                if k == 0:
                    stringi += '%.2f ' % d
                elif k == 1 or k == 2:
                    stringi += '%.4f ' % d
                else:
                    stringi += '%.12f ' % d
            write_line_own(mdlogfile, stringi + '\n', 'a')

        if thres_Z < np.max(atoms.positions[:, 2]) and m == 0:
            idxs = np.where(thres_Z < atoms.positions[:, 2])
            write_line_own(mdlogfile, '# Kink! at idxs %s' % str(idxs) + '\n',
                           'a')
            print ' kink formed! '
            kink_formed = True
            F = 0

        if save and T != 0 and i * dt == tau:
            write_line_own(mdlogfile, '# Thermalization complete. ' + '\n',
                           'a')

        if i % 100 == 0: print i
        if kink_formed: m += 1


    make_simul_param_file(simulfile, W, L, width, length_int, v, deltaY/i, T, \
                          dt, fric, thres_Z, interval, deltaY, i, edge)