Пример #1
0
def corr_KC():

    atoms = graphene_nanoribbon(1,
                                1,
                                type='armchair',
                                C_C=bond,
                                saturated=False)
    atoms.rotate([1, 0, 0], np.pi / 2, rotate_cell=True)

    if edge == 'ac':
        atoms.rotate([0, 0, 1], -np.pi / 2, rotate_cell=True)
        del atoms[[0, 3]]
        trans_idx = 1
    elif edge == 'zz':
        del atoms[[1, 0]]
        trans_idx = 0

    atoms.set_cell([20, 20, 10])
    atoms.center()

    params = {}
    params['positions'] = atoms.positions
    params['chemical_symbols'] = atoms.get_chemical_symbols()
    params['ia_dist'] = 10
    params['edge'] = edge
    params['bond'] = bond
    params['ncores'] = 2
    add_KC = KC_potential_p(params, True)

    constraints = []
    for i in range(len(atoms)):
        fix_l = FixedLine(i, [0., 0., 1.])
        constraints.append(fix_l)

    constraints.append(add_KC)

    lamp_parameters = get_lammps_params(H=False)
    calc = LAMMPS(parameters=lamp_parameters)  #, files=['lammps.data'])
    atoms.set_calculator(calc)
    atoms.set_constraint(constraints)

    #dyn     =   BFGS(atoms, trajectory = 'test.traj')
    #dyn.run(fmax=0.05)

    #plot_posits(atoms, edge, bond)
    trans_vec = trans_atomsKC(atoms.positions[trans_idx], edge, bond)
    atoms.translate(trans_vec)

    #plot_posits(atoms, edge, bond)
    init_pos = atoms.positions.copy()
    r_around = init_pos[trans_idx]

    #thetas      =   np.linspace(0, np.pi/3, 7) #, endpoint = False)
    #thetas_deg  =   np.array([1,3,5,7,9,11,12,13,15,17,43,45,47,48,49,51,57,55,57,59])
    thetas_deg = np.array([
        .5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5,
        13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5
    ])

    traj        =   PickleTrajectory(path + '%s_corr_twist_thetas_(%.1f-%.1f).traj' \
                                     %(edge, np.min(thetas_deg),
                                       np.max(thetas_deg)), 'w', atoms)

    n = 100

    for i, theta_deg in enumerate(thetas_deg):
        fname = path + 'corr_%s_theta=%.2f.data' % (edge, theta_deg)
        print 'Calculating theta = %.2f' % (theta_deg)
        theta = theta_deg / 360 * np.pi * 2
        print 'time ' + str(datetime.now().time())
        atoms.positions = init_pos
        atoms.rotate([0, 0, 1], theta, center=r_around)
        rot_init_pos = atoms.positions.copy()

        lat_vec_theta1 = lat_vec1.copy()
        lat_vec_theta2 = lat_vec2.copy()

        trans_vec2 = lat_vec_theta2.copy() / n

        data = np.zeros((n, n))

        for k in range(n):
            atoms.positions = rot_init_pos
            atoms.translate(lat_vec_theta1 * float(k) / n)
            #plot_posits(atoms, edge, bond, vecs =  [lat_vec_theta1, lat_vec_theta2])
            print '%.1f percent done' % (100 * float(k) / n)
            for l in range(n):
                atoms.translate(trans_vec2)
                emin = get_optimal_h(atoms, len(atoms), dyn=False)[0]
                data[
                    k,
                    l] = emin  #atoms.get_potential_energy()/len(atoms) #emin #
                saveAndPrint(atoms, traj, False)


        header  =   '%s runs along x-dir, angle measured from x-axis, natoms = %i. x (Angs), e (eV/atom), hmin \n\
the lattice vectors are l1 = [%.5f, %.5f, %.5f] and l2 = [%.5f, %.5f, %.5f], they are divided in %i parts. data[i,j,:] \n\
-> atoms pos += l1/n*i + l2/n*j, initial position is such that atom1 is in middle if hexagon.' \
    %(edge, len(atoms), lat_vec_theta1[0], lat_vec_theta1[1], lat_vec_theta1[2], \
      lat_vec_theta2[0], lat_vec_theta2[1], lat_vec_theta2[2], n)
        np.savetxt(fname, data, header=header)
Пример #2
0
def corr_KC(width, edge):
    #width   =   5
    #edge    =   'ac'
    params0 = get_simulParams(edge)[-1]
    bond = params0['bond']

    atoms = create_stucture(1, width, edge, key='top', a=bond)[0]

    atoms.set_cell([40, 40, 20])
    atoms.center()
    atoms.positions[:, 2] = 3.4

    h_t = []
    for i in range(len(atoms)):
        if atoms[i].number == 1:
            h_t.append(i)

    del atoms[h_t]

    params = {}
    params['positions'] = atoms.positions
    params['chemical_symbols'] = atoms.get_chemical_symbols()
    params['ia_dist'] = 10
    params['edge'] = edge
    params['bond'] = bond
    params['ncores'] = 2
    add_KC = KC_potential_p(params)

    constraints = []
    for i in range(len(atoms)):
        fix_l = FixedLine(i, [0., 0., 1.])
        constraints.append(fix_l)

    constraints.append(add_KC)

    lamp_parameters = get_lammps_params(H=False)
    calc = LAMMPS(parameters=lamp_parameters)  #, files=['lammps.data'])
    atoms.set_calculator(calc)
    atoms.set_constraint(constraints)

    #dyn     =   BFGS(atoms, trajectory = 'test.traj')
    #dyn.run(fmax=0.05)

    trans_vec = trans_atomsKC(atoms.positions[0], edge, bond)
    atoms.translate(trans_vec)

    init_pos = atoms.positions.copy()
    middle = [
        np.average(init_pos[:, 0]),
        np.average(init_pos[:, 1]),
        np.average(init_pos[:, 2])
    ]

    thetas = np.linspace(np.pi / 2, np.pi, 91)
    L = 4 * bond
    ds = .05
    n = int(L / ds)

    for i, theta in enumerate(thetas):
        fname = path + 'corr_w=%02d_%s_theta=%.2f.data' % (width, edge, theta /
                                                           (2 * np.pi) * 360)
        if not os.path.isfile(fname):
            print 'Calculating w=%i, theta = %.2f' % (width, theta /
                                                      (2 * np.pi) * 360)

            atoms.positions = init_pos
            atoms.rotate([0, 0, 1], theta, center=middle)
            trans_vec = np.array([-np.sin(theta), np.cos(theta), 0])
            data = np.zeros((n, 3))

            for j in range(n):
                atoms.translate(ds * trans_vec)
                emin, hmin = get_optimal_h(atoms, len(atoms), dyn=False)
                data[j, :] = [j * ds, emin, hmin]
                #plot_posits(atoms, edge, bond)

            header = '%s runs along x-dir, angle measured from x-axis, natoms = %i. x (Angs), e (eV/atom), hmin' % (
                edge, len(atoms))
            np.savetxt(fname, data, header=header)
Пример #3
0
def runAndStudy(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']
    width   =   params_set['width']
    ratio   =   params_set['ratio']
    edge    =   params_set['edge']
    ncores  =   params_set['ncores']
    Ld_i    =   params_set['Ldilde_i']
    
    bend, straight, [matchL_idx, matchR_idx, vec], [L_bend, L_straight], [left_idxs, right_idxs]\
            =   create_bend_stucture(width, ratio, Ld_i, edge, bond)
    
    mdfile, mdlogfile, mdrelax, simulfile, folder, relaxed \
            =   get_fileName(pot_key, edge + '_corrStick', width, \
                             L_bend, L_straight, int(T), taito, key = 'corrStick')
            
    if relaxed:
        bend    =   PickleTrajectory(mdrelax, 'r')[-1]
    else:
        relaxBend(bend, left_idxs, right_idxs, edge, bond, mdrelax)
        bend.set_constraint([])
        
    shift_v =   -straight.positions[matchR_idx] + (bend.positions[matchL_idx] + vec) 
    straight.translate(shift_v)
    
    atoms   =   bend + straight
    cell    =   [1.5*(L_bend + L_straight), L_bend + L_straight, 20]   
    atoms.set_cell(cell)
    atoms.positions[:,2]    =   3.4
    
    trans_vec   =   trans_atomsKC(straight.positions[matchR_idx], edge, bond)
    atoms.translate(trans_vec)
    
    #plot_posits(atoms, edge, bond)
    
    if edge == 'ac':
        nx  =   int((cell[0]/5 - np.min(atoms.positions[:,0]))/(3*bond))  
        ny  =   int((cell[1]/5 - np.min(atoms.positions[:,1]))/(np.sqrt(3)*bond))  
        atoms.translate([nx*3.*bond, ny*np.sqrt(3)*bond, 0])
        width_f =   np.sqrt(3)/2.*bond*(width - 1)
    elif edge == 'zz':
        nx  =   int((cell[0]/5 - np.min(atoms.positions[:,0]))/(np.sqrt(3)*bond))  
        ny  =   int((cell[1]/5 - np.min(atoms.positions[:,1]))/(3*bond))  
        atoms.translate([nx*np.sqrt(3)*bond, ny*3*bond, 0])
        width_f =   (3./2.*width - 1)*bond
    
    cminx, cmaxx    =   strip_Hend(atoms, 'right')
    left_b          =   get_idxOfEnds(atoms, cminx, cmaxx)[0]
    
    # CONSTRAINTS
    constraints =   []
    constraints.append(FixAtoms(indices = left_b))
    
    params      =   {}
    params['positions']         =   atoms.positions
    params['chemical_symbols']  =   atoms.get_chemical_symbols()   
    params['ia_dist']           =   10
    params['edge']              =   edge
    params['bond']              =   bond    
    params['ncores']            =   ncores
    add_pot     =   KC_potential_p(params)
    constraints.append(add_pot)
    atoms.set_constraint(constraints)
    ##
    
    # CALCULATOR
    calc    =   LAMMPS(parameters=get_lammps_params()) 
    atoms.set_calculator(calc)
    ##
    
    # 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')
    traj    =   PickleTrajectory(mdfile, 'w', atoms)
    
    if T != 0:
        # put initial MaxwellBoltzmann velocity distribution
        mbd(atoms, T*units.kB)
    ####
    
    # SIMULATION PARAMS 
    nframes     =   1000
    M           =   int(20*tau/dt)
    interval    =   int(M/nframes)
    thres_cancel=   2*bond
    stick       =   'True'
    xmax_idx    =   np.where(atoms.positions[:,0] == np.max(atoms.positions[:,0]))[0][0]
    r_init      =   atoms.positions[xmax_idx].copy()  
    
    R   =   L_bend/np.pi*3.
    print '# data_line: width, length bend, length tail, tail/bend, theta'
    print width_f, L_bend, L_straight, L_straight/L_bend, width_f/(2*R)
    # SIMULATION LOOP
    for i in range(nframes):
        
        print float(i)/nframes*100.
        dyn.run(interval)
        
        epot, ekin  =   saveAndPrint(atoms, traj, False)[:2]
        data        =   [i*interval*dt, 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')
        
        #print np.linalg.norm(atoms.positions[xmax_idx] - r_init)
        if thres_cancel <   np.linalg.norm(atoms.positions[xmax_idx] - r_init):
            stick   =   'false'
            break 
    
    make_stick_simul_param_file(simulfile, width, L_bend, L_straight, T, \
                                dt, fric, interval, M, edge, stick)
    
    return stick == 'True'
        
    #plot_posits(atoms, edge, bond)
    #view(atoms)
Пример #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
Пример #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
Пример #6
0
def corr_KC(width, edge):

    params0 = get_simulParams(edge)[-1]
    bond = params0['bond']
    '''
    atoms   =   graphene_nanoribbon(1, 1, type= 'armchair', C_C=bond, saturated = False)
    atoms.rotate([1,0,0], np.pi/2, rotate_cell = True)
    atoms.rotate([0,0,1], -np.pi/2, rotate_cell = True)
    atoms.set_cell([20, 20, 10])
    atoms.center()
    del atoms[[2,3]]
    '''
    atoms = create_stucture(2, width, edge, key='top', a=bond)[0]

    atoms.set_cell([70, 70, 20])
    atoms.center()
    atoms.positions[:, 2] = 3.4

    h_t = []
    for i in range(len(atoms)):
        if atoms[i].number == 1:
            h_t.append(i)

    del atoms[h_t]

    #view(atoms)
    params = {}
    params['positions'] = atoms.positions
    params['chemical_symbols'] = atoms.get_chemical_symbols()
    params['ia_dist'] = 10
    params['edge'] = edge
    params['bond'] = bond
    params['ncores'] = 2
    params['no_edge_neigh'] = True
    add_KC = KC_potential_p(params)

    constraints = []
    for i in range(len(atoms)):
        fix_l = FixedLine(i, [0., 0., 1.])
        constraints.append(fix_l)

    constraints.append(add_KC)

    lamp_parameters = get_lammps_params(H=False)
    calc = LAMMPS(parameters=lamp_parameters)  #, files=['lammps.data'])
    atoms.set_calculator(calc)
    atoms.set_constraint(constraints)

    #dyn     =   BFGS(atoms, trajectory = 'test.traj')
    #dyn.run(fmax=0.05)

    #plot_posits(atoms, edge, bond)

    trans_vec = trans_atomsKC(atoms.positions[0], edge, bond)
    atoms.translate(trans_vec)

    #plot_posits(atoms, edge, bond)
    #exit()
    init_pos = atoms.positions.copy()
    r_around = init_pos[1]

    thetas = np.linspace(0, np.pi / 3, 61)
    n = 15

    lat_vec1 = np.array([3. / 2 * bond, np.sqrt(3) / 2 * bond, 0.])
    lat_vec2 = np.array([3. / 2 * bond, -np.sqrt(3) / 2 * bond, 0.])

    for i, theta in enumerate(thetas):
        fname = path + 'corr_%s_theta=%.2f.data' % (edge, theta /
                                                    (2 * np.pi) * 360)
        #if not os.path.isfile(fname):
        print 'Calculating theta = %.2f' % (theta / (2 * np.pi) * 360)
        atoms.positions = init_pos
        atoms.rotate([0, 0, 1], theta, center=r_around)

        R = np.array([[np.cos(theta), -np.sin(theta), 0.],
                      [np.sin(theta), np.cos(theta), 0.], [0., 0., 1.]])

        lat_vec_theta1 = np.dot(R, lat_vec1.copy())
        lat_vec_theta2 = np.dot(R, lat_vec2.copy())

        #trans_vec1      =   lat_vec_theta1.copy()/n
        trans_vec2 = lat_vec_theta2.copy() / n

        data = np.zeros((n, n))
        #plot_posits(atoms, edge, bond, vecs =  [lat_vec_theta1, lat_vec_theta2])

        for k in range(n):
            atoms.positions = init_pos
            atoms.translate(lat_vec_theta1 * float(k) / n)
            #plot_posits(atoms, edge, bond, vecs =  [lat_vec_theta1, lat_vec_theta2])
            #print trans_vec1*float(k)/n, k, n, float(k)/n

            for l in range(n):
                atoms.translate(trans_vec2)
                emin, hmin = get_optimal_h(atoms, len(atoms), dyn=False)
                #data[k,l,:]  =   [emin, hmin]
                data[k, l] = emin  #atoms.get_potential_energy()/len(atoms)

        header  =   '%s runs along x-dir, angle measured from x-axis, natoms = %i. x (Angs), e (eV/atom), hmin \n\
the lattice vectors are l1 = [%.5f, %.5f, %.5f] and l2 = [%.5f, %.5f, %.5f], they are divided in %i parts. data[i,j,:] \n\
-> atoms pos += l1/n*i + l2/n*j, initial position is such that atom1 is in middle if hexagon.' \
    %(edge, len(atoms), lat_vec_theta1[0], lat_vec_theta1[1], lat_vec_theta1[2], \
      lat_vec_theta2[0], lat_vec_theta2[1], lat_vec_theta2[2], n)
        np.savetxt(fname, data, header=header)
Пример #7
0
def runAndStudy(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']
    width = params_set['width']
    ratio = params_set['ratio']
    edge = params_set['edge']
    ncores = params_set['ncores']
    Ld_i = params_set['Ldilde_i']

    bend, straight, [matchL_idx, matchR_idx, vec], [L_bend, L_straight], [left_idxs, right_idxs]\
            =   create_bend_stucture(width, ratio, Ld_i, edge, bond)

    mdfile, mdlogfile, mdrelax, simulfile, folder, relaxed \
            =   get_fileName(pot_key, edge + '_corrStick', width, \
                             L_bend, L_straight, int(T), taito, key = 'corrStick')

    if relaxed:
        bend = PickleTrajectory(mdrelax, 'r')[-1]
    else:
        relaxBend(bend, left_idxs, right_idxs, edge, bond, mdrelax)
        bend.set_constraint([])

    shift_v = -straight.positions[matchR_idx] + (bend.positions[matchL_idx] +
                                                 vec)
    straight.translate(shift_v)

    atoms = bend + straight
    cell = [1.5 * (L_bend + L_straight), L_bend + L_straight, 20]
    atoms.set_cell(cell)
    atoms.positions[:, 2] = 3.4

    trans_vec = trans_atomsKC(straight.positions[matchR_idx], edge, bond)
    atoms.translate(trans_vec)

    #plot_posits(atoms, edge, bond)

    if edge == 'ac':
        nx = int((cell[0] / 5 - np.min(atoms.positions[:, 0])) / (3 * bond))
        ny = int((cell[1] / 5 - np.min(atoms.positions[:, 1])) /
                 (np.sqrt(3) * bond))
        atoms.translate([nx * 3. * bond, ny * np.sqrt(3) * bond, 0])
        width_f = np.sqrt(3) / 2. * bond * (width - 1)
    elif edge == 'zz':
        nx = int((cell[0] / 5 - np.min(atoms.positions[:, 0])) /
                 (np.sqrt(3) * bond))
        ny = int((cell[1] / 5 - np.min(atoms.positions[:, 1])) / (3 * bond))
        atoms.translate([nx * np.sqrt(3) * bond, ny * 3 * bond, 0])
        width_f = (3. / 2. * width - 1) * bond

    cminx, cmaxx = strip_Hend(atoms, 'right')
    left_b = get_idxOfEnds(atoms, cminx, cmaxx)[0]

    # CONSTRAINTS
    constraints = []
    constraints.append(FixAtoms(indices=left_b))

    params = {}
    params['positions'] = atoms.positions
    params['chemical_symbols'] = atoms.get_chemical_symbols()
    params['ia_dist'] = 10
    params['edge'] = edge
    params['bond'] = bond
    params['ncores'] = ncores
    add_pot = KC_potential_p(params)
    constraints.append(add_pot)
    atoms.set_constraint(constraints)
    ##

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

    # 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')
    traj = PickleTrajectory(mdfile, 'w', atoms)

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

    # SIMULATION PARAMS
    nframes = 1000
    M = int(20 * tau / dt)
    interval = int(M / nframes)
    thres_cancel = 2 * bond
    stick = 'True'
    xmax_idx = np.where(atoms.positions[:,
                                        0] == np.max(atoms.positions[:,
                                                                     0]))[0][0]
    r_init = atoms.positions[xmax_idx].copy()

    R = L_bend / np.pi * 3.
    print '# data_line: width, length bend, length tail, tail/bend, theta'
    print width_f, L_bend, L_straight, L_straight / L_bend, width_f / (2 * R)
    # SIMULATION LOOP
    for i in range(nframes):

        print float(i) / nframes * 100.
        dyn.run(interval)

        epot, ekin = saveAndPrint(atoms, traj, False)[:2]
        data = [i * interval * dt, 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')

        #print np.linalg.norm(atoms.positions[xmax_idx] - r_init)
        if thres_cancel < np.linalg.norm(atoms.positions[xmax_idx] - r_init):
            stick = 'false'
            break

    make_stick_simul_param_file(simulfile, width, L_bend, L_straight, T, \
                                dt, fric, interval, M, edge, stick)

    return stick == 'True'
Пример #8
0
def corr_KC():
    
    atoms   =   graphene_nanoribbon(1, 1, type= 'armchair', C_C=bond, saturated = False)
    atoms.rotate([1,0,0], np.pi/2, rotate_cell = True)
    
    if edge == 'ac':    
        atoms.rotate([0,0,1], -np.pi/2, rotate_cell = True)
        del atoms[[0,3]]
        trans_idx   =   1
    elif edge == 'zz':
        del atoms[[1,0]]
        trans_idx   =   0
    
    atoms.set_cell([20, 20, 10])
    atoms.center()
    
    params  =   {}
    params['positions']         =   atoms.positions
    params['chemical_symbols']  =   atoms.get_chemical_symbols()   
    params['ia_dist']           =   10
    params['edge']              =   edge
    params['bond']              =   bond    
    params['ncores']            =   2
    add_KC                      =   KC_potential_p(params, True)
    
    
    constraints =   []
    for i in range(len(atoms)):
        fix_l   =   FixedLine(i, [0., 0., 1.])
        constraints.append(fix_l)
    
    constraints.append(add_KC)
    
    lamp_parameters =   get_lammps_params(H=False)
    calc            =   LAMMPS(parameters = lamp_parameters) #, files=['lammps.data'])
    atoms.set_calculator(calc)
    atoms.set_constraint(constraints)
    
    #dyn     =   BFGS(atoms, trajectory = 'test.traj')
    #dyn.run(fmax=0.05)
    
    #plot_posits(atoms, edge, bond)
    trans_vec   =   trans_atomsKC(atoms.positions[trans_idx], edge, bond)
    atoms.translate(trans_vec)
    
    #plot_posits(atoms, edge, bond)
    init_pos    =   atoms.positions.copy()
    r_around    =   init_pos[trans_idx]
    
    #thetas      =   np.linspace(0, np.pi/3, 7) #, endpoint = False)
    #thetas_deg  =   np.array([1,3,5,7,9,11,12,13,15,17,43,45,47,48,49,51,57,55,57,59])
    thetas_deg  =   np.array([.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5,12.5,13.5,14.5,15.5,16.5,17.5,18.5,19.5])
    
    traj        =   PickleTrajectory(path + '%s_corr_twist_thetas_(%.1f-%.1f).traj' \
                                     %(edge, np.min(thetas_deg), 
                                       np.max(thetas_deg)), 'w', atoms)

    n           =   100
    
    for i, theta_deg in enumerate(thetas_deg):
        fname   =   path + 'corr_%s_theta=%.2f.data' %(edge, theta_deg)
        print 'Calculating theta = %.2f' %(theta_deg)
        theta   =   theta_deg/360*np.pi*2
        print 'time ' + str(datetime.now().time())
        atoms.positions =   init_pos
        atoms.rotate([0,0,1], theta, center = r_around)
        rot_init_pos    =   atoms.positions.copy()
        
        lat_vec_theta1  =   lat_vec1.copy()
        lat_vec_theta2  =   lat_vec2.copy()

                
        trans_vec2      =   lat_vec_theta2.copy()/n
        
        data            =   np.zeros((n,n))
        
        for k in range(n):
            atoms.positions =   rot_init_pos
            atoms.translate(lat_vec_theta1*float(k)/n)
            #plot_posits(atoms, edge, bond, vecs =  [lat_vec_theta1, lat_vec_theta2])
            print '%.1f percent done' %(100*float(k)/n)
            for l in range(n):
                atoms.translate(trans_vec2)
                emin        =   get_optimal_h(atoms, len(atoms), dyn = False)[0]
                data[k,l]   =   emin #atoms.get_potential_energy()/len(atoms) #emin #
                saveAndPrint(atoms, traj, False)
                
                
        header  =   '%s runs along x-dir, angle measured from x-axis, natoms = %i. x (Angs), e (eV/atom), hmin \n\
the lattice vectors are l1 = [%.5f, %.5f, %.5f] and l2 = [%.5f, %.5f, %.5f], they are divided in %i parts. data[i,j,:] \n\
-> atoms pos += l1/n*i + l2/n*j, initial position is such that atom1 is in middle if hexagon.' \
    %(edge, len(atoms), lat_vec_theta1[0], lat_vec_theta1[1], lat_vec_theta1[2], \
      lat_vec_theta2[0], lat_vec_theta2[1], lat_vec_theta2[2], n)
        np.savetxt(fname, data, header = header)
def corr_KC(width, edge):
    #width   =   5
    #edge    =   'ac'
    params0 =   get_simulParams(edge)[-1]
    bond    =   params0['bond']
    
    
    atoms   =   create_stucture(1, width, edge, key = 'top', a = bond)[0]
    
    atoms.set_cell([40, 40, 20])
    atoms.center()
    atoms.positions[:,2]    =   3.4
     
    h_t =   []
    for i in range(len(atoms)):
        if atoms[i].number == 1:
            h_t.append(i)
    
    del atoms[h_t]
    
    
    params  =   {}
    params['positions']         =   atoms.positions
    params['chemical_symbols']  =   atoms.get_chemical_symbols()   
    params['ia_dist']           =   10
    params['edge']              =   edge
    params['bond']              =   bond    
    params['ncores']            =   2
    add_KC                      =   KC_potential_p(params)
    
    
    constraints =   []
    for i in range(len(atoms)):
        fix_l   =   FixedLine(i, [0., 0., 1.])
        constraints.append(fix_l)
    
    constraints.append(add_KC)
    
    lamp_parameters =   get_lammps_params(H=False)
    calc            =   LAMMPS(parameters = lamp_parameters) #, files=['lammps.data'])
    atoms.set_calculator(calc)
    atoms.set_constraint(constraints)
    
    #dyn     =   BFGS(atoms, trajectory = 'test.traj')
    #dyn.run(fmax=0.05)
    
    trans_vec   =   trans_atomsKC(atoms.positions[0], edge, bond)
    atoms.translate(trans_vec)
    
    init_pos    =   atoms.positions.copy()
    middle      =   [np.average(init_pos[:,0]), 
                     np.average(init_pos[:,1]), 
                     np.average(init_pos[:,2])]
     
    
    thetas      =   np.linspace(np.pi/2, np.pi, 91)
    L           =   4*bond
    ds          =   .05
    n           =   int(L/ds)
    
    for i, theta in enumerate(thetas):
        fname   =   path + 'corr_w=%02d_%s_theta=%.2f.data' %(width, edge, theta/(2*np.pi)*360)
        if not os.path.isfile(fname): 
            print 'Calculating w=%i, theta = %.2f' %(width, theta/(2*np.pi)*360)
            
            atoms.positions =   init_pos
            atoms.rotate([0,0,1], theta, center = middle)
            trans_vec       =   np.array([-np.sin(theta), np.cos(theta), 0])
            data            =   np.zeros((n, 3))
            
            for j in range(n):
                atoms.translate(ds*trans_vec)
                emin, hmin  =   get_optimal_h(atoms, len(atoms), dyn = False)
                data[j, :]  =   [j*ds, emin, hmin]   
                #plot_posits(atoms, edge, bond)
            
            header  =   '%s runs along x-dir, angle measured from x-axis, natoms = %i. x (Angs), e (eV/atom), hmin' %(edge, len(atoms))
            np.savetxt(fname, data, header = header)
Пример #10
0
def corr_KC(width, edge):
    
    params0 =   get_simulParams(edge)[-1]
    bond    =   params0['bond']
    
    '''
    atoms   =   graphene_nanoribbon(1, 1, type= 'armchair', C_C=bond, saturated = False)
    atoms.rotate([1,0,0], np.pi/2, rotate_cell = True)
    atoms.rotate([0,0,1], -np.pi/2, rotate_cell = True)
    atoms.set_cell([20, 20, 10])
    atoms.center()
    del atoms[[2,3]]
    '''
    atoms   =   create_stucture(2, width, edge, key = 'top', a = bond)[0]
    
    atoms.set_cell([70, 70, 20])
    atoms.center()
    atoms.positions[:,2]    =   3.4
     
    h_t =   []
    for i in range(len(atoms)):
        if atoms[i].number == 1:
            h_t.append(i)
    
    del atoms[h_t]
    
    #view(atoms)
    params  =   {}
    params['positions']         =   atoms.positions
    params['chemical_symbols']  =   atoms.get_chemical_symbols()   
    params['ia_dist']           =   10
    params['edge']              =   edge
    params['bond']              =   bond    
    params['ncores']            =   2
    params['no_edge_neigh']     =   True
    add_KC                      =   KC_potential_p(params)
    
    
    constraints =   []
    for i in range(len(atoms)):
        fix_l   =   FixedLine(i, [0., 0., 1.])
        constraints.append(fix_l)
    
    constraints.append(add_KC)
    
    lamp_parameters =   get_lammps_params(H=False)
    calc            =   LAMMPS(parameters = lamp_parameters) #, files=['lammps.data'])
    atoms.set_calculator(calc)
    atoms.set_constraint(constraints)
    
    #dyn     =   BFGS(atoms, trajectory = 'test.traj')
    #dyn.run(fmax=0.05)
    
    #plot_posits(atoms, edge, bond)
    
    trans_vec   =   trans_atomsKC(atoms.positions[0], edge, bond)
    atoms.translate(trans_vec)
    
    #plot_posits(atoms, edge, bond)
    #exit()
    init_pos    =   atoms.positions.copy()
    r_around    =   init_pos[1]
    
    thetas      =   np.linspace(0, np.pi/3, 61)
    n           =   15
    
    lat_vec1    =   np.array([3./2*bond,  np.sqrt(3)/2*bond, 0.])   
    lat_vec2    =   np.array([3./2*bond, -np.sqrt(3)/2*bond, 0.])
    
    for i, theta in enumerate(thetas):
        fname   =   path + 'corr_%s_theta=%.2f.data' %(edge, theta/(2*np.pi)*360)
        #if not os.path.isfile(fname): 
        print 'Calculating theta = %.2f' %(theta/(2*np.pi)*360)
        atoms.positions =   init_pos
        atoms.rotate([0,0,1], theta, center = r_around)
        
        R               =   np.array([[np.cos(theta), -np.sin(theta), 0.],
                                      [np.sin(theta),  np.cos(theta), 0.],
                                      [0., 0., 1.]])
        
        lat_vec_theta1  =   np.dot(R, lat_vec1.copy())
        lat_vec_theta2  =   np.dot(R, lat_vec2.copy())
                
        #trans_vec1      =   lat_vec_theta1.copy()/n
        trans_vec2      =   lat_vec_theta2.copy()/n
        
        data            =   np.zeros((n,n))
        #plot_posits(atoms, edge, bond, vecs =  [lat_vec_theta1, lat_vec_theta2])
        
        for k in range(n):
            atoms.positions =   init_pos
            atoms.translate(lat_vec_theta1*float(k)/n)
            #plot_posits(atoms, edge, bond, vecs =  [lat_vec_theta1, lat_vec_theta2])
            #print trans_vec1*float(k)/n, k, n, float(k)/n 
            
            for l in range(n):
                atoms.translate(trans_vec2)
                emin, hmin   =   get_optimal_h(atoms, len(atoms), dyn = False)
                #data[k,l,:]  =   [emin, hmin]   
                data[k,l]  =  emin #atoms.get_potential_energy()/len(atoms)
                
        header  =   '%s runs along x-dir, angle measured from x-axis, natoms = %i. x (Angs), e (eV/atom), hmin \n\
the lattice vectors are l1 = [%.5f, %.5f, %.5f] and l2 = [%.5f, %.5f, %.5f], they are divided in %i parts. data[i,j,:] \n\
-> atoms pos += l1/n*i + l2/n*j, initial position is such that atom1 is in middle if hexagon.' \
    %(edge, len(atoms), lat_vec_theta1[0], lat_vec_theta1[1], lat_vec_theta1[2], \
      lat_vec_theta2[0], lat_vec_theta2[1], lat_vec_theta2[2], n)
        np.savetxt(fname, data, header = header)