from ase.build import fcc100, add_adsorbate from gpaw import GPAW, PW slab = fcc100('Al', (2, 2, 2), a=4.05, vacuum=7.5) add_adsorbate(slab, 'Na', 4.0) slab.center(axis=2) slab.calc = GPAW(mode=PW(300), poissonsolver={'dipolelayer': 'xy'}, txt='pwcorrected.txt', xc='PBE', setups={'Na': '1'}, kpts=(4, 4, 1)) e3 = slab.get_potential_energy() slab.calc.write('pwcorrected.gpw')
from gpaw.test import equal name = 'cristobalite' # no. 92 - tetragonal a = 5.0833674 c = 7.0984738 p0 = (0.2939118, 0.2939118, 0.0) p1 = (0.2412656, 0.0931314, 0.1739217) atoms = crystal(['Si', 'O'], basis=[p0, p1], spacegroup=92, cellpar=[a, a, c, 90, 90, 90]) ## with fractional translations calc = GPAW(mode=PW(), xc='LDA', kpts=(3, 3, 2), nbands=40, symmetry={'symmorphic': False}, gpts=(24, 24, 32), eigensolver='rmm-diis') atoms.set_calculator(calc) energy_fractrans = atoms.get_potential_energy() assert(len(calc.wfs.kd.ibzk_kc) == 3) assert(len(calc.wfs.kd.symmetry.op_scc) == 8) ## without fractional translations calc = GPAW(mode=PW(),
import numpy as np from ase import Atoms from ase.build import bulk from ase.io.trajectory import PickleTrajectory from ase.optimize.bfgs import BFGS from ase.db import connect import matplotlib.pyplot as plt from gpaw import GPAW from gpaw import PW from gpaw import FermiDirac copper = bulk('Cu', 'fcc', a=3.62) calc = GPAW(mode=PW(340), h=0.2, xc='PBE', nbands=-2, kpts=(8, 8, 8), occupations=FermiDirac(0.1), txt='cubulk_dos.txt') copper.set_calculator(calc) copper.get_potential_energy() calc.write('cu.gpw', mode='all') from ase import * from ase.dft.dos import DOS from gpaw import GPAW, restart import pylab as p slab, calc = restart('cu.gpw')
""" # 1. Structural relaxation. ################################################## #setup awal fo1 = '../optimize/step_1_catlearn.traj' fo2 = '../optimize/step_2_catlearn.traj' ecut = 250 xc = 'PBE' kpts = (4, 4, 4) # Setup logger logging.basicConfig(filename='time.log', filemode='a', format='%(message)s') # Setup calculator: calc = GPAW(mode=PW(ecut), xc=xc, kpts=kpts, parallel={'band': 1}, txt='gpaw.txt') # Set number of images n_images = 10 n_images = n_images - 2 # 1.1. Structures: slab_initial = read(fo1) slab_final = read(fo2) # 2.A. NEB using ASE
spath = elem_list[3] print("path = ",spath) nkpts = elem_list[4] print("kpts = ",nkpts) kpts = ast.literal_eval(nkpts) La = float(elem_list[5]) print("lattice constant a = ",La) Lb = float(elem_list[6]) print("lattice constant b = ",Lb) Lc = float(elem_list[7]) print("lattice constant c = ",Lc) Lalpha = float(elem_list[8]) print("alpha angle = ",Lalpha) # First perform a regular SCF run calc = GPAW(mode=PW(400), maxiter=1500, spinpol=True, kpts=kpts, xc=xc, txt='-', occupations=FermiDirac(0.02), mixer=Mixer(0.01, 11, 100.0), ) atoms = bulk(element,struct,a=La,b=Lb,c=Lc,alpha=Lalpha) # sc,fcc,bcc,tetragonal,bct,hcp,rhmbohedral,orthorhombic # mlc, diamond,zincblende,rocksalt,cesiumchloride, fluorite, wurtzite atoms.set_calculator(calc) atoms.get_potential_energy()
db = connect('fe_phon_band.db') db.write(my_atoms, data={ 'q': small_q, 'Q': big_q, 'omega_kn': Omega_kn, 'point_names': point_names, 'dos_e': Dos_e, 'omega_e': Omega_e }) # Setup crystal and EMT calculator atoms = bulk('Fe', 'bcc', a=2.86) calc = GPAW(mode=PW(600), nbands=-60, xc='PBE', kpts=(5, 5, 5), symmetry={'point_group': False}, occupations=FermiDirac(0.1)) # # # Phonon calculator N = 3 ph = Phonons(atoms, calc, supercell=(N, N, N), delta=0.05) ph.run() time.sleep(250) # Read forces and assemble the dynamical matrix ph.read()
frq_qw = [np.linspace(0.000, 0.200, 26), np.linspace(0.100, 0.300, 26)] Kxc = 'ALDA' ecut = 300 eta = 0.01 # ------------------- Script ------------------- # # Part 1: ground state calculation t1 = time.time() Febcc = bulk('Fe', 'bcc', a=a) Febcc.set_initial_magnetic_moments([mm]) calc = GPAW(xc=xc, mode=PW(pw), kpts=monkhorst_pack((kpts, kpts, kpts)), nbands=nb, txt=None) Febcc.set_calculator(calc) Febcc.get_potential_energy() calc.write('Fe', 'all') t2 = time.time() # Part 2: magnetic response calculation for q in range(2): tms = TransverseMagneticSusceptibility(calc='Fe', frequencies=frq_qw[q], eta=eta, ecut=ecut,
"""Bulk Al(fcc) test""" from __future__ import print_function from ase import Atoms from ase.visualize import view from gpaw import GPAW, PW name = 'Al-fcc' a = 4.05 # fcc lattice paramter b = a / 2 bulk = Atoms('Al', cell=[[0, b, b], [b, 0, b], [b, b, 0]], pbc=True) view(bulk) k = 4 calc = GPAW(mode=PW(300), # cutoff kpts=(k, k, k), # k-points txt=name + '.txt') # output file bulk.set_calculator(calc) energy = bulk.get_potential_energy() calc.write(name + '.gpw') print('Energy:', energy, 'eV')
for N_z in N_z_vec: if rank == 0: print 'Simulating ' + str(N_z) + 'atoms in z...' slab111 = fcc111('Al', size=(N_x, N_y, N_z), a=lattice_parameter, vacuum=7.5) slab111.center(axis=2) cell111 = slab111.get_cell() # Unit cell object of the Al FCC 111 area111 = np.linalg.norm(np.cross(cell111[0], cell111[1])) # Calc. surface area # Initialize new calculator that only considers k-space in xy-plane, # since we're only looking at the surface calc = GPAW( mode=PW(energy_cutoff), # use the LCAO basis mode h=0.18, # grid spacing xc='PBE', # XC-functional mixer=mixer, kpts=(n_k_points, n_k_points, 1), # k-point grid txt='simulate_surface_Al_6_GPAW.txt') # name of GPAW output text file slab111.set_calculator(calc) energy_slab = slab111.get_potential_energy() energies.append(energy_slab) sigmas.append((1 / (2.0 * area111)) * (energy_slab - N_z * energy_bulk)) with open(homedir + '/TIF035/HA2/surface/6_converge_surface_depth.txt', 'w') as textfile: textfile.write('atom depth, bulk_energy, surface_energy_density\n') for i in range(len(N_z_vec)):
if ('kspace' not in sys.argv): sys.exit('\"kspace\" not in argument variable') n_k = sys.argv.index('kspace') try: E_cut = [float(el) for el in sys.argv[n_cut + 1:n_k]] k_points = [float(el) for el in sys.argv[n_k + 1:]] except Exception as e: print e sys.exit('Format: python loop_lattice_param' + sys.argv[0] + 'cutoff E1 E2 ... ' + 'kspace k1 k2 ...') for energy in E_cut: for k in k_points: calc = GPAW( mode=PW(energy), # use the LCAO basis mode h=0.18, # grid spacing, recommended value in this course xc='PBE', # Exchange-correlation functional mixer=mixer, kpts=(k, k, k), # k-point grid - LOOP OVER LATER TO CHECK "CONVERGENCE" txt='out.txt') # name of GPAW output text file al.set_calculator(calc) if loop_lattice_param: # # # Find lattice constant with lowest energy # # # cell_0 = al.cell # Unit cell object of the Al bulk for eps in np.linspace(-0.02, 0.02, N_lattice_spacings): al.cell = ( 1 + eps) * cell_0 # Adjust lattice constant of unit cell # Calculate the potential energy for the Al bulk
from __future__ import print_function from ase.optimize import BFGS from ase.build import molecule from ase.parallel import paropen from gpaw import GPAW, PW from gpaw.xc.exx import EXX # N N = molecule('N') N.cell = (6, 6, 7) N.center() calc = GPAW(mode=PW(600, force_complex_dtype=True), nbands=8, maxiter=300, xc='PBE', hund=True, txt='N_pbe.txt', convergence={'density': 1.e-6}) N.calc = calc E1_pbe = N.get_potential_energy() calc.write('N.gpw', mode='all') exx = EXX('N.gpw', txt='N_exx.txt') exx.calculate() E1_hf = exx.get_total_energy() calc.diagonalize_full_hamiltonian(nbands=4800) calc.write('N.gpw', mode='all')
from gpaw import GPAW, PW, Davidson # Create tube of MoS2: atoms = mx2('MoS2', size=(3, 2, 1)) atoms.cell[1, 0] = 0 atoms = atoms.repeat((1, 10, 1)) p = atoms.positions p2 = p.copy() L = atoms.cell[1, 1] r0 = L / (2 * pi) angle = p[:, 1] / L * 2 * pi p2[:, 1] = (r0 + p[:, 2]) * np.cos(angle) p2[:, 2] = (r0 + p[:, 2]) * np.sin(angle) atoms.positions = p2 atoms.cell = [atoms.cell[0, 0], 0, 0] # setup calculator ecut = 800 kpoints = (4, 1, 1) atoms.center(vacuum=6, axis=[1, 2]) atoms.pbc = True tag = 'MoS2-benchmark' atoms.calc = GPAW(mode=PW(ecut), eigensolver=Davidson(2), xc='PBE', txt=tag + '.txt', kpts={'size': kpoints}, nbands='120%', parallel={'augment_grids': True}) forces = atoms.get_forces()
from ase.build import molecule from gpaw import GPAW, PW ncpus = 1 atoms = molecule('LiH') atoms.cell = [12, 12.01, 12.02] atoms.center() atoms.calc = GPAW(mode=PW(400), xc='PBE')
import numpy as np from ase.lattice import bulk from gpaw import GPAW, PW, FermiDirac, MethfesselPaxton a0 = 4.04 al = bulk('Al', 'fcc', a=a0) cell0 = al.cell for ecut in range(200, 501, 50): al.calc = GPAW(mode=PW(ecut), xc='PBE', kpts=(8, 8, 8), parallel={'band': 1}, basis='dzp', txt='Al-%d.txt' % ecut) for eps in np.linspace(-0.02, 0.02, 5): al.cell = (1 + eps) * cell0 al.get_potential_energy() al.calc.set(mode=PW(400)) for k in range(4, 17): al.calc.set(kpts=(k, k, k), txt='Al-%02d.txt' % k) for eps in np.linspace(-0.02, 0.02, 5): al.cell = (1 + eps) * cell0 al.get_potential_energy()
# physical sodium cell. a = 4.23 / 2.0 a1 = Atoms('Na', scaled_positions=[[0, 0, 0]], cell=(a, a, a), pbc=True) # Expanding along x-direction a2 = Atoms('Na2', scaled_positions=[[0, 0, 0], [0.5, 0, 0]], cell=(2 * a, a, a), pbc=True) a1.calc = GPAW(gpts=(10, 10, 10), mode=PW(300), kpts={'size': (8, 8, 8), 'gamma': True}, parallel={'band': 1}, txt='small.txt') # Kpoint sampling should be halved in the expanded direction. a2.calc = GPAW(gpts=(20, 10, 10), mode=PW(300), kpts={'size': (4, 8, 8), 'gamma': True}, parallel={'band': 1}, txt='large.txt') a1.get_potential_energy() a2.get_potential_energy() # Use twice as many bands for expanded structure
from ase import Atoms from gpaw import GPAW, PW a = 2.87 m = 2.2 fe = Atoms('Fe2', scaled_positions=[(0, 0, 0), (0.5, 0.5, 0.5)], magmoms=[m, m], cell=(a, a, a), pbc=True) calc = GPAW(mode=PW(350), kpts=(6, 6, 6), txt='ferro.txt') fe.set_calculator(calc) e = fe.get_potential_energy() calc.write('ferro.gpw')
from ase.build import bulk from gpaw import GPAW, PW a = 5.421 si = bulk('Si', 'fcc', a=a) # or equivalently: # b = a / 2 # from ase import Atoms # si = Atoms('Si2', cell=[[0, b, b], [b, 0, b], [b, b, 0]], pbc=True, # scaled_positions=[[0, 0, 0], [0.25, 0.25, 0.25]]) for x in [100, 200, 300, 400, 500, 600, 700, 800]: # for x in [0.24, 0.22, 0.20, 0.18, 0.16, 0.14, 0.12, 0.1]: calc = GPAW( mode=PW(x), # h=x, xc='PBE', kpts=(4, 4, 4), txt='convergence_%s.txt' % x) si.calc = calc print(x, si.get_potential_energy())
os.makedirs(os.path.dirname(filename)) except OSError as exc: # Guard against race condition if exc.errno != errno.EEXIST: raise bulk *= [2, 2, 2] distancebefore = bulk.get_distance(1, 2) bulk.pop(4) bulk.append(Atom('Co', [0.0, 1.96, 1.96])) bulk.pop(6) bulk.append( Atom('Co', [ 3.9199999999999999, 3.9199999999999999, 3.9199999999999999 ])) #bulk.set_initial_magnetic_moments([1,1,1,1]) calc = GPAW( mode=PW(ecut), # cutoff kpts=(k, k, k), # k-points xc='PBE', txt=filename) # output file bulk.set_calculator(calc) relax = QuasiNewton(bulk, logfile=c + '.log') relax.run(fmax=0.0001) #energy = bulk.get_potential_energy() #atomons = bulk.get_magnetic_moments() distanceafter = bulk.get_distance(0, 1) calc.write(name + '.gpw') #print('Lattice Constant:', a, 'eV''Energy:', energy, 'eV', ' Magnetic Momentes: ', atomons) print('Lattice Constant:', a, ' Distance Before: ', distancebefore, ' Distance After: ', distanceafter) print(' ')
from gpaw import restart from ase.parallel import paropen as open from ase.optimize import QuasiNewton from gpaw import GPAW, FermiDirac, PW from ase import Atoms from ase.visualize import view atoms = Atoms(symbols=myGpaw.symstr, pbc=[True, True, True], cell=myGpaw.gcell, positions=myGpaw.pos) # view(atoms) kpts = {'size': (4, 4, 4), 'gamma': True} calc = GPAW(#h=0.16, mode=PW(600), kpts=kpts, xc='PBE', txt=myGpaw.symstr+'_600_speed_test.out', occupations=FermiDirac(width=0.05), # nbands=-2, convergence={'energy': 0.0005, # eV / electron 'density': 1.0e-4, 'eigenstates': 4.0e-8, # eV^2 / electron 'bands': 'CBM+2.0', 'forces': float('inf')} # eV / Ang Max ) atoms.calc = calc e2 = atoms.get_potential_energy() d0 = atoms.get_distance(0, 1)
#Recover past done calculations if available bulk_mat, calc = restart(system_name + '_relaxed.gpw', txt=None) bulk_mat.set_calculator(calc) else: #Initialize new calculations bulk_mat = bulk('Fe', 'bcc', a) bulk_mat.set_initial_magnetic_moments([initial_magmom]) bulk_mat = bulk_mat * (atoms, atoms, atoms) if (str(sys.argv[8]) == 'True'): del bulk_mat[[atom.index for atom in bulk_mat if atom.index == 0]] calc = GPAW(mode=PW(e_cut), nbands=nbands, xc='PBE', spinpol=True, kpts=(k_pts, k_pts, k_pts), occupations=FermiDirac(smear), txt=system_name + '.out') bulk_mat.set_calculator(calc) #Save the initial state of the calculations #calc.write('Fe_relaxer_initial.gpw') save_atoms(bulk_mat, e_cut, nbands, k_pts, smear, a, initial_magmom, 1, str(sys.argv[6])) precon = Exp() saver = Gpw_save(calc, system_name + '_relaxed.gpw')
from gpaw.response.g0w0 import G0W0 from ase.build import mx2 from gpaw import GPAW, PW, FermiDirac structure = mx2(formula='MoS2', kind='2H', a=3.184, thickness=3.127, size=(1, 1, 1), vacuum=3.5) structure.pbc = (1, 1, 1) Ecut = 400 calc = GPAW(mode=PW(Ecut), parallel={'domain': 1}, xc='PBE', basis='dzp', kpts={ 'size': (9, 9, 1), 'gamma': True }, occupations=FermiDirac(0.01), txt='MoS2_out_gs.txt') structure.set_calculator(calc) structure.get_potential_energy() calc.write('MoS2_gs.gpw', 'all') calc.diagonalize_full_hamiltonian() calc.write('MoS2_fulldiag.gpw', 'all')
from gpaw import restart from ase.parallel import paropen as open from ase.optimize import QuasiNewton from gpaw import GPAW, FermiDirac, PW from ase import Atoms from ase.visualize import view atoms = Atoms(symbols=myGpaw.symstr, pbc=[True, True, True], cell=myGpaw.gcell, positions=myGpaw.pos) # view(atoms) kpts = {'size': (4, 4, 4), 'gamma': True} calc = GPAW(#h=0.16, mode=PW(800), kpts=kpts, xc='PBE', txt=myGpaw.symstr+'_800.out', occupations=FermiDirac(width=0.05), # nbands=-2, convergence={'energy': 0.0005, # eV / electron 'density': 1.0e-4, 'eigenstates': 4.0e-8, # eV^2 / electron 'bands': 'CBM+2.0', 'forces': float('inf')} # eV / Ang Max ) atoms.calc = calc e2 = atoms.get_potential_energy() d0 = atoms.get_distance(0, 1)
from ase.build import bulk from gpaw import GPAW, PW, FermiDirac # Perform standard ground state calculation (with plane wave basis) # Bemærk at 5.43 er lattice konstanten si = bulk('Si', 'diamond', 5.43) calc = GPAW( mode=PW(200), xc='PBE', kpts=(8, 8, 8), random=True, # random guess (needed if many empty bands required) occupations=FermiDirac(0.01), txt='Si_gs.txt') si.calc = calc si.get_potential_energy() calc.write('Si_gs.gpw')
def relaxGPAW(structure, label, forcemax=0.1, niter_max=1, steps=10): # Set calculator # loop a number of times to capture if minimization stops with high force # due to the VariansBreak calls niter = 0 # If the structure is already fully relaxed just return it traj = Trajectory(label + '_lcao.traj', 'w', structure) while (structure.get_forces()** 2).sum(axis=1).max()**0.5 > forcemax and niter < niter_max: dyn = BFGS(structure, logfile=label + '.log') vb = VariansBreak(structure, dyn, min_stdev=0.01, N=15) dyn.attach(traj) dyn.attach(vb) dyn.run(fmax=forcemax, steps=steps) niter += 1 #print('relaxgpaw over',flush=True) return structure calc = GPAW(mode=PW(500), xc='PBE', basis='dzp', kpts=(2, 2, 1)) traj = Trajectory('2VO3Htrans_initi_TiO21013by1cell2layer_DFTrelxd.traj', 'w') data = read('2VO3Htrans_starting_image_neb_cell3by1_2layer.traj@:') for i in range(0, len(data)): name = 'isomer_{}'.format(i) a = data[i] a.set_calculator(calc) a_relaxed = relaxGPAW(a, name, forcemax=0.01, niter_max=7, steps=100) traj.write(a_relaxed)
from gpaw import GPAW, PW, FermiDirac from ase.lattice import bulk si = bulk('Si') si.calc = GPAW(mode=PW(200), kpts={ 'size': (2, 2, 2), 'gamma': True }, occupations=FermiDirac(0.01)) si.get_potential_energy() si.calc.diagonalize_full_hamiltonian() si.calc.write('Si_gs', 'all') dct = {} execfile('Si_g0w0_ppa.py', dct) assert abs(dct['ks_gap'] - 0.404) < 0.01 assert abs(dct['qp_gap'] - 1.138) < 0.01
# Part 1: Ground state calculation a = 1.42 c = 3.355 # Generate graphite AB-stack structure: atoms = Atoms('C4', scaled_positions=[(1 / 3.0, 1 / 3.0, 0), (2 / 3.0, 2 / 3.0, 0), (0, 0, 0.5), (1 / 3.0, 1 / 3.0, 0.5)], pbc=(1, 1, 1), cell=[(sqrt(3) * a / 2, 3 / 2.0 * a, 0), (-sqrt(3) * a / 2, 3 / 2.0 * a, 0), (0, 0, 2 * c)]) # Part 2: Find ground state density and diagonalize full hamiltonian calc = GPAW( mode=PW(500), kpts=(6, 6, 3), parallel={'domain': 1}, # Use smaller Fermi-Dirac smearing to avoid intraband transitions: occupations=FermiDirac(0.05)) atoms.set_calculator(calc) atoms.get_potential_energy() calc.set(kpts=(20, 20, 7), fixdensity=True) atoms.get_potential_energy() # The result should also be converged with respect to bands: calc.diagonalize_full_hamiltonian(nbands=60) calc.write('graphite.gpw', 'all')
from ase.parallel import paropen as open from ase.optimize import QuasiNewton from gpaw import GPAW, FermiDirac, PW from ase import Atoms from ase.visualize import view atoms = Atoms(symbols=myGpaw.symstr, pbc=[ True, True, True], cell=myGpaw.gcell, positions=myGpaw.pos ) # view(atoms) kpts={'size': (4, 4, 4), 'gamma': True} calc = GPAW(#h=0.16, mode=PW(700), kpts=kpts, xc='PBE', txt=myGpaw.symstr+'.out', occupations=FermiDirac(width=0.05), # nbands=-2, convergence={'energy': 0.0005, # eV / electron 'density': 1.0e-4, 'eigenstates': 4.0e-8, # eV^2 / electron 'bands': 'CBM+2.0', 'forces': float('inf')}, # eV / Ang Max ) atoms.calc = calc e2 = atoms.get_potential_energy() d0 = atoms.get_distance(0, 1)
from ase import Atoms from gpaw import GPAW, PW h = Atoms('H', cell=(5, 5, 5)) h.center() h.calc = GPAW(setups='ae', txt='H.ae.txt') for ecut in range(200, 1001, 100): h.calc.set(mode=PW(ecut)) e = h.get_potential_energy()
print("path = ", spath) nkpts = elem_list[4] print("kpts = ", nkpts) kpts = ast.literal_eval(nkpts) La = float(elem_list[5]) print("lattice constant a = ", La) Lb = float(elem_list[6]) print("lattice constant b = ", Lb) Lc = float(elem_list[7]) print("lattice constant c = ", Lc) Lalpha = float(elem_list[8]) print("alpha angle = ", Lalpha) # First perform a regular SCF run calc = GPAW( mode=PW(400), maxiter=1500, spinpol=True, kpts=kpts, xc=xc, txt='-', occupations=FermiDirac(0.02), mixer=Mixer(0.01, 11, 100.0), ) atoms = bulk(element, struct, a=La, b=Lb, c=Lc, alpha=Lalpha) # sc,fcc,bcc,tetragonal,bct,hcp,rhmbohedral,orthorhombic # mlc, diamond,zincblende,rocksalt,cesiumchloride, fluorite, wurtzite atoms.set_calculator(calc) atoms.get_potential_energy()
from gpaw.mixer import Mixer from gpaw.factory import GPAWFactory from gpaw.mpi import serial_comm if len(sys.argv) == 1: optimizer = None else: optimizer = sys.argv[1] tag = 'htb_pw' if optimizer is not None: tag += '_%s' % optimizer calcfactory = GPAWFactory( mode=PW(), xc='PBE', width=0.1, maxiter=400, mixer=Mixer(0.10, 2), eigensolver='cg', # avoid problems with band parallelization communicator=serial_comm, ) taskopts = {'sfmax': 0.01, 'ssteps': 50} if optimizer is not None: taskopts.update({'soptimizer': optimizer}) task = Task(xc='LDA', calcfactory=calcfactory,