def set_mixer(self, mixer): if mixer is not None: if self.nspins == 1 and isinstance(mixer, MixerSum): raise RuntimeError('Cannot use MixerSum with nspins==1') self.mixer = mixer else: if self.gd.pbc_c.any(): beta = 0.1 weight = 50.0 else: beta = 0.25 weight = 1.0 if self.nspins == 2: self.mixer = MixerSum(beta=beta, weight=weight) else: self.mixer = Mixer(beta=beta, weight=weight) self.mixer.initialize(self)
def create_calc(name, spinpol, pbc): # Bond lengths between H-C and C-C for ethyne (acetylene) cf. # CRC Handbook of Chemistry and Physics, 87th ed., p. 9-28 dhc = 1.060 dcc = 1.203 atoms = Atoms([ Atom('H', (0, 0, 0)), Atom('C', (dhc, 0, 0)), Atom('C', (dhc + dcc, 0, 0)), Atom('H', (2 * dhc + dcc, 0, 0)) ], pbc=pbc) atoms.center(vacuum=2.0) # Number of occupied and unoccupied bands to converge nbands = int(10 / 2.0) nextra = 3 #TODO use pbc and cell to calculate nkpts kwargs = {} if spinpol: kwargs['mixer'] = MixerSum(nmaxold=5, beta=0.1, weight=100) else: kwargs['mixer'] = Mixer(nmaxold=5, beta=0.1, weight=100) calc = GPAW(h=0.3, nbands=nbands+nextra, xc='PBE', spinpol=spinpol, eigensolver='cg', convergence={'energy':1e-4/len(atoms), 'density':1e-5, \ 'eigenstates': 1e-9, 'bands':-1}, txt=name+'.txt', **kwargs) atoms.set_calculator(calc) atoms.get_potential_energy() calc.write(name + '.gpw', mode='all')
exx.calculate() E0_hf = exx.get_total_energy() calc.diagonalize_full_hamiltonian() calc.write('CO.ralda.pbe_wfcs_CO.gpw', mode='all') # C C = Atoms('C') C.set_pbc(True) C.set_cell(CO.cell) C.center() calc = GPAW(mode=PW(600, force_complex_dtype=True), parallel={'domain': 1}, xc='PBE', mixer=MixerSum(beta=0.1, nmaxold=5, weight=50.0), hund=True, occupations=FermiDirac(0.01, fixmagmom=True), txt='CO.ralda_01_C_pbe.txt', convergence={'density': 1.e-6}) C.set_calculator(calc) E1_pbe = C.get_potential_energy() exx = EXX(calc, txt='CO.ralda_01_C_exx.txt') exx.calculate() E1_hf = exx.get_total_energy() f = paropen('CO.ralda.PBE_HF_C.dat', 'w') print(E1_pbe, E1_hf, file=f) f.close()
spinpol=True, convergence={ 'energy': 100, 'density': 100, 'eigenstates': 1.0e-9, 'bands': 'occupied' }, txt='CO_homo.txt') calc = GPAW(nbands=80, h=0.2, xc='RPBE', kpts=(8, 6, 1), eigensolver='cg', spinpol=True, mixer=MixerSum(nmaxold=5, beta=0.1, weight=100), convergence={ 'energy': 100, 'density': 100, 'eigenstates': 1.0e-7, 'bands': -10 }, txt=filename + '.txt') # Import Slab with relaxed CO slab = fcc111('Pt', size=(1, 2, 3), orthogonal=True) add_adsorbate(slab, 'C', 2.0, 'ontop') add_adsorbate(slab, 'O', 3.15, 'ontop') slab.center(axis=2, vacuum=4.0) view(slab)
def calculate(element, h, vacuum, xc, magmom): atom = Atoms([Atom(element, (0, 0, 0))]) if magmom > 0.0: mms = [magmom for i in range(len(atom))] atom.set_initial_magnetic_moments(mms) atom.center(vacuum=vacuum) mixer = MixerSum(beta=0.4) if element == 'O': mixer = MixerSum(0.4, nmaxold=1, weight=100) atom.set_positions(atom.get_positions() + [0.0, 0.0, 0.0001]) calc_atom = GPAW(h=h, xc=_xc(data[element][xc][2]), experimental={'niter_fixdensity': 2}, eigensolver='rmm-diis', occupations=FermiDirac(0.0, fixmagmom=True), mixer=mixer, parallel=dict(augment_grids=True), nbands=-2, txt='%s.%s.txt' % (element, xc)) atom.set_calculator(calc_atom) mixer = Mixer(beta=0.4, weight=100) compound = molecule(element + '2') if compound == 'O2': mixer = MixerSum(beta=0.4) mms = [1.0 for i in range(len(compound))] compound.set_initial_magnetic_moments(mms) calc = GPAW(h=h, xc=_xc(data[element][xc][2]), experimental={'niter_fixdensity': 2}, eigensolver='rmm-diis', mixer=mixer, parallel=dict(augment_grids=True), txt='%s2.%s.txt' % (element, xc)) compound.set_distance(0, 1, data[element]['R_AA_B3LYP']) compound.center(vacuum=vacuum) compound.set_calculator(calc) if data[element][xc][3] == 'hyb_gga': # only for hybrids e_atom = atom.get_potential_energy() e_compound = compound.get_potential_energy() calc_atom.set(xc=_xc(xc)) calc.set(xc=_xc(xc)) e_atom = atom.get_potential_energy() e_compound = compound.get_potential_energy() dHf_0 = (e_compound - 2 * e_atom + data[element]['ZPE_AA_B3LYP'] + 2 * data[element]['dHf_0_A']) dHf_298 = (dHf_0 + data[element]['H_298_H_0_AA_B3LYP'] - 2 * data[element]['H_298_H_0_A']) * (mol / kcal) de = dHf_298 - data[element][xc][1] E[element][xc] = de if rank == 0: print((xc, h, vacuum, dHf_298, data[element][xc][1], de, de / data[element][xc][1])) if element == 'H': equal(dHf_298, data[element][xc][1], 0.25, msg=xc + ': ') # kcal/mol elif element == 'O': equal(dHf_298, data[element][xc][1], 7.5, msg=xc + ': ') # kcal/mol else: equal(dHf_298, data[element][xc][1], 2.15, msg=xc + ': ') # kcal/mol equal(de, E_ref[element][xc], 0.06, msg=xc + ': ') # kcal/mol
from ase.lattice import bulk modes = ['gpw'] try: import _gpaw_hdf5 modes.append('hdf5') except ImportError: pass # bulk Fe with k-point, band, and domain parallelization a = 2.87 atoms = bulk('Fe', 'bcc', a=a) atoms.set_initial_magnetic_moments([2.2,]) calc = GPAW(h=0.20, eigensolver=RMM_DIIS(), mixer=MixerSum(0.1,3), nbands=6, kpts=(4,4,4), parallel={'band' : 2, 'domain' : (2,1,1)}, maxiter=4) atoms.set_calculator(calc) try: atoms.get_potential_energy() except ConvergenceError: pass for mode in modes: calc.write('tmp.%s' % mode, mode='all') # Continue calculation for few iterations for mode in modes: atoms, calc = restart('tmp.%s' % mode,
def calculate(element, h, vacuum, xc, magmom): atom = Atoms([Atom(element, (0, 0, 0))]) if magmom > 0.0: mms = [magmom for i in range(len(atom))] atom.set_initial_magnetic_moments(mms) atom.center(vacuum=vacuum) mixer = MixerSum(beta=0.2) if element == 'O': mixer = MixerSum(nmaxold=1, weight=100) atom.set_positions(atom.get_positions() + [0.0, 0.0, 0.0001]) calc_atom = GPAW(h=h, xc=data[element][xc][2], occupations=FermiDirac(0.0, fixmagmom=True), mixer=mixer, nbands=-2, txt='%s.%s.txt' % (element, xc)) atom.set_calculator(calc_atom) mixer = Mixer(beta=0.2, weight=100) compound = molecule(element + '2') if compound == 'O2': mixer = MixerSum(beta=0.2) mms = [1.0 for i in range(len(compound))] compound.set_initial_magnetic_moments(mms) calc = GPAW(h=h, xc=data[element][xc][2], mixer=mixer, txt='%s2.%s.txt' % (element, xc)) compound.set_distance(0, 1, data[element]['R_AA_B3LYP']) compound.center(vacuum=vacuum) compound.set_calculator(calc) if data[element][xc][3] == 'hyb_gga': # only for hybrids e_atom = atom.get_potential_energy() e_compound = compound.get_potential_energy() calc_atom.set(xc=xc) calc.set(xc=xc) if 0: qn = QuasiNewton(compound) qn.attach( PickleTrajectory(element + '2' + '_' + xc + '.traj', 'w', compound).write) qn.run(fmax=0.02) e_atom = atom.get_potential_energy() e_compound = compound.get_potential_energy() dHf_0 = (e_compound - 2 * e_atom + data[element]['ZPE_AA_B3LYP'] + 2 * data[element]['dHf_0_A']) dHf_298 = (dHf_0 + data[element]['H_298_H_0_AA_B3LYP'] - 2 * data[element]['H_298_H_0_A']) * (mol / kcal) dist_compound = compound.get_distance(0, 1) de = dHf_298 - data[element][xc][1] E[element][xc] = de if rank == 0: print(xc, h, vacuum, dHf_298, data[element][xc][1], de, de / data[element][xc][1]) if element == 'H': equal(dHf_298, data[element][xc][1], 0.25, msg=xc + ': ') # kcal/mol elif element == 'O': equal(dHf_298, data[element][xc][1], 7.5, msg=xc + ': ') # kcal/mol else: equal(dHf_298, data[element][xc][1], 2.15, msg=xc + ': ') # kcal/mol equal(de, E_ref[element][xc], 0.06, msg=xc + ': ') # kcal/mol
try: m.get_potential_energy() except ConvergenceError: pass assert not calc.scf.converged del calc # converges (fortuitously) # C2 really needs broken spin-symmetry to converge calc = GPAW(h=0.18, xc='PBE', basis='dzp', maxiter=550, mixer=MixerSum(0.02, 3), eigensolver='cg', spinpol=True, txt='C2_conv1.txt') m.set_calculator(calc) try: e1 = m.get_potential_energy() except ConvergenceError: e1 = None pass del calc # or with broken symmetry magnetic moments, to a different solution m.set_initial_magnetic_moments([-0.5, 0.5])
from ase import Atoms from gpaw import GPAW from gpaw.mixer import MixerSum a = 2.87 m = 2.2 bulk = Atoms('Fe2', positions=[(0, 0, 0), (a / 2, a / 2, a / 2)], magmoms=[m, -m], cell=(a, a, a), pbc=True) calc = GPAW(kpts=(6, 6, 6), h=0.20, nbands=18, mixer=MixerSum(beta=0.2, nmaxold=5), eigensolver='dav', txt='anti.txt') bulk.set_calculator(calc) print bulk.get_potential_energy() calc.write('anti.gpw')