from ase.build import bulk from gpaw import GPAW, PW, FermiDirac calc = GPAW(mode=PW(600), xc='PBE', occupations=FermiDirac(0.01), kpts=(32, 32, 16), symmetry='off', parallel={ 'band': 1, 'domain': 1 }, txt='gs_Co.txt') bulk = bulk('Co', 'hcp') bulk.set_initial_magnetic_moments([1.0, 1.0]) bulk.set_calculator(calc) bulk.get_potential_energy() calc.write('gs_Co.gpw', mode='all')
# making dimer.traj traj = Trajectory('dimer.traj', 'w') # create Trajectory object dx = 0.1 #scaling factor list1 = [0, 0, 0] # position of first atom list2 = [0, 0, 0.5] # will store new position of second atom vec_2 = np.array(list2) - np.array(list1) # vector pointing from 1 to 2 norm_2 = np.linalg.norm(vec_2, ord=2) # get norm vec_2 = [x / norm_2 for x in vec_2] # get unit vector for i in range(4): ss = [dx * x for x in vec_2] #scale vector list2 = np.array(list2) + np.array(ss) # move second atom dimer = Atoms('CC', positions=[list1, list2]) # create ASE atom object dimer.calc = Espresso(pseudopotentials=pseudopotentials) dft_energy = dimer.get_potential_energy() traj.write(dimer, energy=(dft_energy)) # write dft energy to trajectory file dx += 0.1 # making bulk.traj #https://wiki.fysik.dtu.dk/ase/tutorials/deltacodesdft/deltacodesdft.html?highlight=dft%20calculatin#ase.utils.deltacodesdft.delta pseudopotentials = {'C': 'C.pbe-n-kjpaw_psl.1.0.0.UPF'} for symbol in ['C']: traj = Trajectory('bulk.traj'.format(symbol), 'w') for s in range(94, 108, 2): bulk = dcdft[symbol] bulk.set_cell(bulk.cell * (s / 100.0)**(1.0 / 3.0), scale_atoms=True) bulk.calc = Espresso(pseudopotentials=pseudopotentials, kpts=(6, 6, 6)) dft_energy = bulk.get_potential_energy() print s, dft_energy traj.write(bulk, energy=(dft_energy))
spin='none', k_grid=(9,9,9), vdw_correction_hirshfeld="True", relativistic=('atomic_zora','scalar'), #use_dipole_correction='True', compute_forces="true", output=['mulliken'], # elsi_restart=("write",1) ) bulk = Atoms('Pd', cell=[(0, b, b), (b, 0, b), (b, b, 0)], pbc=1, calculator=calc) # use EMT potential bulk.get_potential_energy() #traj.write(bulk) energy_bulk=bulk.get_potential_energy() print ("potential-energy-bulk", energy_bulk) #print (energy_bulk) ############SURFACE################################ from ase.io import write ## Edit these atomic_species='Pd' a2 = a unit_cell_depth=3 unit_cell_width=3 slab_depth=4 vacuum_region_size=10.0
def optimize_lattice_constant(bulk, lattice="fcc", a0=4.0, xc="PBEsol", encut=400, ediff=1.0e-5, ediffg=1.0e-6, npar=1, nsim=1): """ function to do bulk optimization """ from ase import Atoms from ase.calculators.vasp import Vasp import os, shutil # # directry things # cudir = os.getcwd() workdir = os.path.join(cudir, "lattice_opt") os.makedirs(workdir) os.chdir(workdir) os.system("mkdir work_bulk") # # compuational condition for Vasp # prec = "normal" potim = 0.1 nelmin = 5 kpts = [3, 3, 3] gamma = True nsw = 200 isif = 6 # or 6---freezing ions xc = xc.lower() if xc == "pbe" or xc == "pbesol" or xc == "rpbe": pp = "pbe" elif xc == "pw91": pp = "pw91" elif xc == "lda": pp = "lda" else: print("xc error") calc = Vasp(prec=prec, xc=xc, pp=pp, ispin=1, ismear=1, sigma=0.2, isif=isif, nelmin=nelmin, encut=encut, ibrion=2, nsw=nsw, potim=potim, ediff=ediff, ediffg=ediffg, kpts=kpts, gamma=gamma, isym=0, npar=npar, nsim=nsim, lreal=False) bulk.set_calculator(calc) bulk.get_potential_energy() cell = bulk.cell # optimized cell size os.chdir(cudir) shutil.rmtree(workdir)