示例#1
0
文件: hcp.py 项目: fuulish/fuase
from ase.io import read, PickleTrajectory
from ase.lattice import bulk
from ase.calculators.emt import EMT

a0 = 3.52 / np.sqrt(2)
c0 = np.sqrt(8 / 3.0) * a0
print '%.4f %.3f' % (a0, c0 / a0)
for i in range(3):
    traj = PickleTrajectory('Ni.traj', 'w')
    eps = 0.01
    for a in a0 * np.linspace(1 - eps, 1 + eps, 4):
        for c in c0 * np.linspace(1 - eps, 1 + eps, 4):
            ni = bulk('Ni', 'hcp', a=a, covera=c / a)
            ni.set_calculator(EMT())
            ni.get_potential_energy()
            traj.write(ni)
    traj.close()

    configs = read('Ni.traj@:')
    energies = [config.get_potential_energy() for config in configs]
    ac = [(config.cell[0, 0], config.cell[2, 2]) for config in configs]
    from ase.optimize import polyfit
    p = polyfit(ac, energies, 2)
    from scipy.optimize import fmin_bfgs
    a0, c0 = fmin_bfgs(p, (a0, c0))
    print '%.4f %.3f' % (a0, c0 / a0)
assert abs(a0 - 2.466) < 0.001
assert abs(c0 / a0 - 1.632) < 0.005


示例#2
0
def sphereDynamics(R, T, params):
    
    d       =   params['d']         #2.934
    nk      =   params['nk']        #20
    fmax    =   params['fmax']      #1E-2
    fric    =   params['fric']      #0.002        # equilibration time tau = 10 fs/fric (= mdsteps*dt) 
    dt      =   params['dt']        #5.0
    mdsteps =   params['mdsteps']   #int(10/fric/dt)
    path    =   params['path']      #'/space/tohekorh/Au_bend/files/'
    uzsize  =   params['uz_size']
    
    print 'radius',R
    name    =   '%.1f' %R
    
    # ATOMS
    #atoms   =   fcc111('Au',size=uzsize,a=np.sqrt(2)*d)
    atoms       =   get_opmAtomsFlat(T, params)
    
    atoms.rotate((0,0,1), -np.pi/6, rotate_cell = True)
    
    length1 =   np.linalg.norm( atoms.get_cell()[0] )
    length2 =   np.linalg.norm( atoms.get_cell()[1] )
    
    n1      =   ( np.cos(np.pi/3),  np.sin(np.pi/3), 0)
    n2      =   (-np.cos(np.pi/3),  np.sin(np.pi/3), 0)
    angle1  =   length1/R
    angle2  =   length2/R
    
    #view(atoms)    
    # Scale the atoms close to ball
    Lx = np.linalg.norm(atoms.get_cell()[0] + atoms.get_cell()[1])
    Ly = np.linalg.norm(atoms.get_cell()[0] - atoms.get_cell()[1])
     
    phi_max     =   Ly/R
    theta_max   =   Lx/R
    for a in atoms:
        r0      =   a.position
        phi     =   r0[1]/Ly*phi_max
        theta   =   r0[0]/Lx*theta_max
        a.position[0]   =   R*np.sin(theta) #*np.sin(theta)
        a.position[1]   =   R*np.sin(phi) #a.position[1] #R*np.sin(phi) #*np.sin(theta)
        a.position[2]   =   R*np.cos(theta)
    #atoms.translate((0,0,R))
    # End scaling
    
    atoms   =   Atoms(atoms=atoms,container='Sphere')
    atoms.set_container(angle1=angle1,angle2=angle2,n1=n1,n2=n2,mode=4)
    
    #view(atoms.extended_copy((2,2,1)))
    
    # FOLDERS
    path_md =   path + 'sphere/md_data/T=%.0f/' %T
    path_opm=   path + 'sphere/opm/T=%.0f/' %T

    checkAndCreateFolder(path_md)
    checkAndCreateFolder(path_opm)
    
    # CALCULATOR
    calc    =   Hotbit(SCC=False, kpts=(nk,nk,1),txt= path_opm + 'optimization_%s.cal' %name,)
    atoms.set_calculator(calc)
    
    # RELAX
    opt     =   BFGS(atoms, trajectory= path_opm + 'optimization_%s.traj' %name)
    opt.run(fmax=fmax,steps=1000)
    
    #write(path_opm + 'opm_structure_R%.3f' %R, atoms, format='traj')
    
    # DYNAMICS
    traj        =   PickleTrajectory(path_md + 'md_R%.3f.traj' %R, 'w', atoms)   
    dyn         =   Langevin(atoms, dt*units.fs, units.kB*T,fric)
    
    dyn.attach(MDLogger(dyn, atoms, path_md + 'md_R%.3f.log' %R, header=True, stress=False,
           peratom=True, mode="w"), interval = 1)
    dyn.attach(traj.write)
    dyn.run(mdsteps)
    traj.close()
    
    # load the dynamics back.. To write the extended trajectory
    traj        =   PickleTrajectory(path_md + 'md_R%.3f.traj' %R)
    trajToExtTraj(traj, (2, 2, 1), R, T, angle1, angle2, n1, n2, path)
    

    
    
    
    
    
示例#3
0
def cylinderDynamics(R, T, params):
    
    nk      =   params['nk']        #20
    fmax    =   params['fmax']      #1E-2
    fric    =   params['fric']      #0.002         
    dt      =   params['dt']        #5.0
    mdsteps =   params['mdsteps']   #int(10/fric/dt)
    path    =   params['path']      #'/space/tohekorh/Au_bend/files/'
    
    print 'radius',R, '\n'
    name    =   '%.1f' %R
    
    # Get the optimal flat atoms , unit-cell config for this temperature:
    atoms       =   get_opmAtomsFlat(T, params)

    # Take the diagonal of the cell:
    L           =   atoms.get_cell().diagonal()

     
    atoms.set_cell(L) 
    
    # The wedge angle is:
    angle       =   L[1]/R
    
    # fiddle with atoms:
    atoms.rotate('y', np.pi/2)
    atoms.translate((-atoms[0].x, 0, 0) )
    
    #view(atoms)
    
    # Initial map for atoms, to get the on surface of cylinder:
    phi_max     =   angle
    for a in atoms:
        r0      =   a.position
        phi     =   r0[1]/L[1]*phi_max
        a.position[0]   =   R*np.cos(phi)
        a.position[1]   =   R*np.sin(phi)

    #view(atoms)
    
    # proper number of kappa points in angle direction, if angle >= 2*pi/3 the use genuine 
    # physical boundary conditions and proper kappa-points. With 64 atoms in unit cell souhld not 
    # happen as the radius -> very small if angle = 2*pi/3 or larger.
    
    # Check that the unit-cell angle is 2*pi/integer. This can be removed! 
    if (2*np.pi/angle)%1 > 0:
        raise 
    
    # This does not have any effect unless angle >= 2*pi/3:
    m           =   int(round(2*np.pi/angle))
    physical    =   False
    if m <= 3:
        nk1 =   m
        physical = True
    else:
        nk1     =   nk
    
    # Set up the wedge container:
    atoms       =   Atoms(atoms = atoms, container = 'Wedge')
    atoms.set_container(angle = angle, height = L[0], physical = physical, pbcz = True)
    
    # Check that everything looks good:
    #view(atoms.extended_copy((2,1,2)))
    
    
    # FOLDERS
    path_opm    =   path + 'cylinder/opm/T=%.0f/' %T
    path_md     =   path + 'cylinder/md_data/T=%.0f/' %T
    
    checkAndCreateFolder(path_opm)
    checkAndCreateFolder(path_md)
    
    
    # CALCULATOR
    calc        =   Hotbit(SCC=False, kpts=(nk1, 1, nk), physical_k = physical, \
                    txt= path_opm + 'optimization_%s.cal' %name)
    atoms.set_calculator(calc)
    
    # RELAX
    opt         =   BFGS(atoms, trajectory= path_opm + 'optimization_%s.traj' %name)
    opt.run(fmax=fmax, steps=1000)
    
    
    # DYNAMICS
    traj        =   PickleTrajectory(path_md + 'md_R%.3f.traj' %R,'w',atoms)   
    
    # Perform dynamics
    dyn         =   Langevin(atoms, dt*units.fs, units.kB*T, fric)
    dyn.attach(MDLogger(dyn, atoms, path_md + 'md_R%.3f.log' %R, header=True, stress=False,
           peratom=True, mode="w"), interval = 1)
    
    dyn.attach(traj.write)
    dyn.run(mdsteps)
    traj.close()
    
    # load the dynamics back, to make exteded trajectory:
    traj        =   PickleTrajectory(path_md + 'md_R%.3f.traj' %R)
    trajToExtTraj(traj, (2, 1, 2), R, T, angle, L[0], path)