def __init__(self, calc=None, label=None, prefix=None, debug=False, colors=None): """Electronic Density Of States object. calc: quantum espresso calculator object label: the directory and prefix dos_energies print(pdos_info) to see the detail pdos_kinds[species][channel][ncomponents] """ if not calc and not label: raise ValueError('Please give one of them: calc or label') if label: calc = Espresso(label=label, prefix=prefix, debug=True) calc.read_results() self.debug = debug if self.debug: print(calc.results) self.directory = calc.directory self.label = calc.label self.prefix = calc.prefix self.efermi = calc.get_fermi_level() self.atoms = calc.results['atoms'] self.nspins = calc.get_number_of_spins() if self.nspins == 0: self.nspins = 1
def build_db(update='.', prefix='datas'): user = os.getenv('USER') print('Reading.....') dbfile = '%s.db' % prefix with connect(dbfile) as db: calc = Espresso() cwd = os.getcwd() for dire, j, y in os.walk(update): prefix = is_espresso(dire) if prefix: calc.prefix = prefix else: continue print(dire) label = dire inputfile = dire + '/%s.pwi' % calc.prefix calc.directory = os.path.join(cwd, dire) calc.prefix = prefix print(inputfile) atoms, input_data, pseudopotentials, kpts = read_espresso_input( inputfile) newcalc = Espresso(label=dire, prefix=prefix, pseudopotentials=pseudopotentials, input_data=input_data, kpts=kpts) converged, fromfile, meg0 = calc.read_convergence() calc.results = {} try: calc.read_results() atoms = calc.results['atoms'] except Exception as e: print('=' * 30, '\n', dire, e) # atoms.calc = newcalc print('dire: ', dire, converged) nid = 0 for row in db.select(label=label): dbid = row.id nid += 1 if nid > 0: db.write(atoms, id=dbid, label=label, converged=meg0) else: db.write(atoms, label=label) print('Finished')
def vib_zpe(self, job, atoms): from ase.vibrations import Vibrations self.log('-' * 60) self.log('Run ZEP calculation: {0}'.format(job)) label = os.path.join(self.label, job) label = os.path.join(label, 'vib') # copy file calculator = deepcopy(self.calculator) dip = dipole_correction(atoms, edir=3) calculator.update(dip) calculator.update({ 'calculation': 'scf', 'tstress': True, 'tprnfor': True, 'outdir': '../', 'prefix': '%s' % job, 'startingpot': 'file', 'startingwfc': 'file', 'etot_conv_thr': 1e-6, 'disk_io': 'none', }) # better to restart from previous geo_relax calculation calc = Espresso( label=label, **calculator, ) atoms.calc = calc if job[-1] == 'O': indices = [-1] elif job[-2:] == 'OH' and job[-3:] != 'OOH': indices = [-1, -2] elif job[-3:] == 'OOH': indices = [-1, -2, -3] elif job[-2:] == 'O2': indices = [-1, -2] else: indices = [] # print('%!!!') return job, 0 vib = Vibrations(atoms, name=os.path.join(label, job), indices=indices) vib.run() vib_energies = np.real(vib.get_energies()) zpe = 0. for energy in vib_energies: zpe += 0.5 * energy self.zpes[job] = zpe return job, zpe
def run_atoms(self, job, atoms): self.log('-'*60) self.log('Submit job {0}'.format(job)) self.log.print_atoms(atoms) calc = Espresso( label = os.path.join(self.label, job), **self.calculator, ) calc.parameters['input_data']['prefix'] = job # self.log(' Commnad: {0}'.format(calc.command)) atoms.calc = calc # atoms.get_potential_energy() calc.run(atoms = atoms, restart = 1) calc.read_results() self.results[job] = deepcopy(calc.results) calc.clean() return job, self.results[job]['energy']
def summary(updates=[], prefix='datas'): import pandas as pd columns = [ 'label', 'atoms', 'cell', 'positions', 'energy', 'forces', 'stress' ] file = '%s.pickle' % prefix db = '%s.db' % prefix if os.path.exists(file): with open(file, 'rb') as f: datas, df = pickle.load(f) else: datas = {} df = pd.DataFrame(columns=columns) calc = Espresso() print('Reading.....') for update in updates: cwd = os.getcwd() for i, j, y in os.walk(update): output = is_espresso(i) if output: os.chdir(i) print('dire:', i) calc.directory = cwd + '/' + i calc.prefix = output[0:-4] try: calc.results = {} calc.read_results() # gap, p1, p2 = bandgap(calc) # calc.results['gap'] = gap # t = calc.get_time() # calc.results['time'] = t datas[i] = calc.results atoms = calc.results['atoms'] atoms.write( os.path.join(calc.directory, '%s.cif' % calc.prefix)) # results = ana(i, calc) # df.loc[len(df)] = results except Exception as e: print('=' * 30, '\n', i, e) os.chdir(cwd) with open(file, 'wb') as f: pickle.dump([datas, df], f) print('Finished')
def __init__(self, calc = None, label = None, ): """Electronic Density Of States object. calc: quantum espresso calculator object label: the directory and prefix """ if not calc and not label: raise ValueError('Please give one of them: calc or label') if label: calc = Espresso(label = label) calc.read_results() self.directory = calc.directory self.label = calc.label self.prefix = calc.prefix self.efermi = calc.get_fermi_level() self.atoms = calc.atoms self.nspins = calc.get_number_of_spins() if self.nspins == 0: self.nspins = 1
def dfpt(self): ''' ''' atoms = self.atoms self.log('-'*60) self.log('Submit job {0}'.format(job)) self.log.print_atoms(atoms) calc = Espresso( label = os.path.join(self.label, job), **self.calculator, ) calc.parameters['input_data']['prefix'] = job atoms.calc = calc energy = atoms.get_potential_energy() # dos calc.post(queue = queue, package = 'ph', tr2_ph = 1e-14, ldisp = True, nq1 = 4, nq2 = 4, nq3 = 3, ) calc.post(queue = queue, fildyn = 'matdyn', package = 'q2r', zasr = 'simple', flfrc = '%s.fc'%job, ) calc.post(queue = queue, package = 'matdyn', asr = 'simple', dos = True, flfrc = '%s.fc'%job, fldos = '%s.phdos'%job, nk1 = 40, nk2 = 40, nk3 = 30, ) calc.plot_phdos(fldos = '%s'%job, output = 'images/%s-phdos.png'%job) pass
def cell_relax_espresso(self, job, atoms): """ """ self.log('-' * 60) self.log('Submit job {0}'.format(job)) self.log.print_atoms(atoms) calculator = deepcopy(self.calculator) calculator.update({ 'calculation': 'vc-relax', 'prefix': job, }) calc = Espresso( label=os.path.join(self.label, job), **calculator, ) atoms.calc = calc calc.run(atoms=atoms) calc.read_results() self.results[job] = deepcopy(calc.results) return job, self.results[job]['energy']
def geo_relax_espresso(self, job, atoms): """ """ self.log('-' * 60) self.log('Run geometry relaxtion: {0}'.format(job)) self.log.print_atoms(atoms) calculator = deepcopy(self.calculator) calculator.update({ 'calculation': 'relax', 'prefix': job, }) dip = dipole_correction(atoms, edir=3) calculator.update(dip) calc = Espresso( label=os.path.join(self.label, job), **calculator, ) atoms.calc = calc calc.run(atoms=atoms) calc.read_results() energy = calc.results['energy'] self.results[job] = deepcopy(calc.results) self.calcs[job] = calc return job, energy
'Hubbard_U': { 'Fe': 4.3, 'Fe1': 4.3 }, } input_data = { 'ecutwfc': 30.0, 'occupations': 'smearing', 'degauss': 0.03, 'nspin': 2, 'lda_plus_u': True, 'input_ntyp': input_ntyp, # 'mixing_beta': 0.3, 'conv_thr': 1.0e-8, } pseudopotentials = { 'Fe': 'Fe.pbe-spn-rrkjus_psl.1.0.0.UPF', 'Fe1': 'Fe.pbe-spn-rrkjus_psl.1.0.0.UPF', } calc = Espresso(pseudopotentials=pseudopotentials, label='scf/fe+u', input_data=input_data, kpts=(4, 4, 4)) atoms.calc = calc e = atoms.get_potential_energy() print('Energy {0:1.3f}'.format(e)) ''' Energy -10451.104 '''
from xespresso.cohp import COHP # build CO molecule atoms = molecule('CO') atoms.center(5) atoms.pbc = [True, True, True] pseudopotentials = {'O': 'O.pbe-n-kjpaw_psl.0.1.UPF', 'C': 'C.pbe-n-kjpaw_psl.1.0.0.UPF'} queue = None # start scf calculation calc = Espresso(label='scf/co', pseudopotentials=pseudopotentials, wf_collect=True, # for lobster run, make sure adding this outdir='.', # for lobster run, make sure adding this ecutwfc=30, occupations='smearing', degauss=0.03, kpts=(1, 1, 1), debug=True, ) atoms.calc = calc e = atoms.get_potential_energy() print('Energy = {0:1.3f} eV'.format(e)) # start COHP analysis cohp = COHP( directory='scf/co', # same as label in scf calculation prefix='co', # same as scf calculation index=[[1, 2]], # the bond of interest, multiple bond can be set as [[1,2],[3,5]] command='your lobster path' # path of lobster program # other arguments can also be parsed, such as follows
'occupations': 'smearing', 'smearing': 'gaussian', 'degauss': 0.03, 'nspin': 2, 'input_ntyp': input_ntyp, # 'mixing_beta': 0.3, 'conv_thr': 1.0e-8, } pseudopotentials = { 'Fe': 'Fe.pbe-spn-rrkjus_psl.1.0.0.UPF', 'Fe1': 'Fe.pbe-spn-rrkjus_psl.1.0.0.UPF', } calc = Espresso(pseudopotentials=pseudopotentials, label='scf/fe-afm', input_data=input_data, kpts=(6, 6, 6)) atoms.calc = calc e = atoms.get_potential_energy() calc.read_results() e = calc.results['energy'] print('Energy {0:1.3f}'.format(e)) parameters_hp = { 'nq1': 1, 'nq2': 1, 'nq3': 1, 'equiv_type': 0, 'conv_thr_chi': 1e-5, 'perturb_only_atom': { '1': True
'queue': queue, 'debug': True, 'parallel': '-nk 4', } # Build the Pt (001) surface atoms = bulk('Pt') atoms = surface(atoms, (0, 0, 1), 2, vacuum=1) atoms.pbc = [True, True, True] atoms = atoms * [2, 2, 1] atoms.positions[:, 2] -= min(atoms.positions[:, 2]) - 0.01 atoms.cell[2][2] = max(atoms.positions[:, 2]) + 10 atoms = fix_layers(atoms, (0, 0, 1), 1.0, [0, 2]) # calc = Espresso( label='relax/001-221-Pt', **parameters, ) atoms.calc = calc calc.run(atoms=atoms) calc.read_results() atoms_opt = calc.results['atoms'] del atoms_opt.info['species'] #========================================================================== # parameter for QE parameters = { 'pseudopotentials': mypseudo, 'calculation': 'relax', 'ecutwfc': 40.0, 'ecutrho': 320.0,
'ecutrho': 302.0, 'occupations': 'smearing', 'smearing': 'gaussian', 'degauss': 0.03, # 'mixing_beta': 0.3, 'conv_thr': 1.0e-8, } pseudopotentials = { 'Fe': 'Fe.pbe-spn-rrkjus_psl.1.0.0.UPF', } queue = { 'nodes': 1, 'ntasks-per-node': 4, 'account': 'dcb', 'partition': 'all', 'time': '0:10:00' } calc = Espresso( pseudopotentials=pseudopotentials, queue=queue, label='scf/fe', # 'scf/fe' is the directory, 'fe' is the prefix input_data=input_data, kpts=(6, 6, 6)) atoms.calc = calc e = atoms.get_potential_energy() print('Energy: {0:1.3f}'.format(e)) ''' Energy: -3368.435 '''
from ase.build import bulk, fcc111 from ase.visualize import view from xespresso import Espresso from xespresso.dos import DOS from xespresso.tools import get_nbnd import matplotlib.pyplot as plt atoms = fcc111('Al', size=(1, 1, 2), vacuum=4.0) view(atoms) print(atoms) pseudopotentials = { 'Al': 'Al.pbe-n-rrkjus_psl.1.0.0.UPF', } calc = Espresso(pseudopotentials=pseudopotentials, label='scf/al', ecutwfc=40, occupations='smearing', degauss=0.01, kpts=(4, 4, 1)) atoms.calc = calc e = atoms.get_potential_energy() calc.read_results() e = calc.results['energy'] fermi = calc.get_fermi_level() print('Energy: {0:1.3f}'.format(e)) #=============================================================== # post calculation calc.post(package='pp', plot_num=5, sample_bias=0.0735, iflag=3, output_format=6,
atoms.arrays['species'][0] = 'Fe' atoms.arrays['species'][1] = 'Fe1' print(atoms.arrays['species']) input_ntyp = { 'starting_magnetization': { 'Fe': 1.0, 'Fe1': -1.0, } } pseudopotentials = { 'Fe': 'Fe.pbe-spn-rrkjus_psl.1.0.0.UPF', 'Fe1': 'Fe.pbe-spn-rrkjus_psl.1.0.0.UPF', } calc = Espresso( pseudopotentials=pseudopotentials, label='scf/fe-afm', ecutwfc=40, occupations='smearing', degauss=0.02, nspin=2, input_data={'input_ntyp': input_ntyp}, kpts=(4, 4, 4), debug=True, ) atoms.calc = calc e = atoms.get_potential_energy() print('Energy {0:1.3f}'.format(e)) ''' Energy -6737.189 '''
from ase.build import molecule from xespresso import Espresso atoms = molecule('H2') atoms.center(5) atoms.pbc = [True, True, True] pseudopotentials = {'H': 'H.pbe-rrkjus_psl.1.0.0.UPF'} calc = Espresso( label='relax/h2', pseudopotentials=pseudopotentials, calculation='relax', ecutwfc=20, kpts=(1, 1, 1), debug=True, ) atoms.calc = calc e = atoms.get_potential_energy() print('Energy = {0:1.3f} eV'.format(e))
'ecutwfc': 70.0, 'ecutrho': 840.0, 'occupations': 'smearing', 'degauss': 0.01, 'nspin': 2, 'lda_plus_u': True, 'input_ntyp': input_ntyp, } queue = {'nodes': 1, 'ntasks-per-node': 4, 'account': 'dcb', 'partition': 'all', 'time': '0:10:00'} pseudopotentials = { 'Mn1': 'Mn.pbesol-spn-rrkjus_psl.0.3.1.UPF', 'Mn2': 'Mn.pbesol-spn-rrkjus_psl.0.3.1.UPF', 'Mn3': 'Mn.pbesol-spn-rrkjus_psl.0.3.1.UPF', 'Mn4': 'Mn.pbesol-spn-rrkjus_psl.0.3.1.UPF', 'O' : 'O.pbesol-n-rrkjus_psl.1.0.0.UPF', 'O1' : 'O.pbesol-n-rrkjus_psl.1.0.0.UPF', 'Sr' : 'Sr.pbesol-spn-rrkjus_psl.1.0.0.UPF', } # print(queue) calc = Espresso(pseudopotentials = pseudopotentials, package = 'pw', parallel = '-nk 2 -nt 4 -nd 144', # parallel parameters queue = queue, label = 'scf/mno', input_data = input_data, kpts=(6, 6, 6)) atoms.set_calculator(calc) e = atoms.get_potential_energy() print('Energy: ', e)
queue = {'nodes': 2, 'ntasks-per-node': 20, 'partition': 'debug', 'time': '00:10:00'} paras = { 'pseudopotentials': rrkjus_psl, 'calculation':'relax', 'ecutwfc': 40.0, 'ecutrho': 320.0, 'occupations': 'smearing', 'degauss': 0.02, 'kpts': (8, 8, 8), 'queue': queue, 'debug': True, 'parallel': '-nk 4', } atoms = bulk('Li') calc = Espresso(label = 'vc-relax/li', **paras) atoms.calc = calc e = atoms.get_potential_energy() print('energy: ', e) # paras.update({'calculation': 'scf', 'conv_thr': 1e-10}) atoms = calc.results['atoms'] calc = Espresso(label = 'scf/li', **paras) atoms.calc = calc e = atoms.get_potential_energy() print('energy: ', e) # Phonon calculations at gamma input = { 'tr2_ph':1.0e-14, 'epsil':True, }
'degauss': 0.03, 'nspin': 2, 'input_ntyp': input_ntyp, # 'mixing_beta': 0.3, 'conv_thr': 1.0e-8, } # queue = {'nodes': 1, 'ntasks-per-node': 4, 'account': 'dcb', 'partition': 'all', 'time': '0:59:00'} queue = None pseudopotentials = { 'H': 'H.pbe-rrkjus_psl.1.0.0.UPF', } calc = Espresso( pseudopotentials=pseudopotentials, # queue = queue, label='relax/initial', input_data=input_data, kpts=(1, 1, 1), debug=True, ) atoms.calc = calc e = atoms.get_potential_energy() print('Initial energy: ', e) #============================================================= # start NEB initial = calc.results['atoms'] final = initial.copy() final.positions[1] = [3.0 - final[1].x, 0, 0] images = [initial, final] # view images before neb calculation
from ase.build import bulk from xespresso import Espresso atoms = bulk('Fe') pseudopotentials = {'Fe': 'Fe.pbe-spn-rrkjus_psl.1.0.0.UPF'} input_data = {'smearing': 'gaussian'} calc = Espresso(pseudopotentials = pseudopotentials, label = 'scf/fe', # 'scf/fe' is the directory, 'fe' is the prefix ecutwfc = 40, occupations = 'smearing', degauss = 0.02, input_data = input_data, kpts=(6, 6, 6), debug = True, ) atoms.calc = calc calc.run(atoms = atoms) e = calc.results['energy'] print('Energy: {0:1.3f}'.format(e)) ''' Energy: -3368.401 '''
import matplotlib.pyplot as plt atoms = molecule('CO') atoms.center(5) atoms.pbc = [True, True, True] pseudopotentials = { 'O': 'O.pbe-n-rrkjus_psl.1.0.0.UPF', 'C': 'C.pbe-n-rrkjus_psl.1.0.0.UPF' } queue = None calc = Espresso( label='scf/co', pseudopotentials=pseudopotentials, ecutwfc=30, occupations='smearing', degauss=0.03, kpts=(1, 1, 1), debug=True, ) atoms.calc = calc e = atoms.get_potential_energy() print('Energy = {0:1.3f} eV'.format(e)) #=============================================================== # start nscf calculation fe = calc.get_fermi_level() print('fermi level: ', fe) calc.nscf(occupations='tetrahedra', kpts=(3, 3, 3)) calc.nscf_calculate() # dos, projwfc calc.post(package='dos', Emin=fe - 30, Emax=fe + 30, DeltaE=0.01)
from ase.build import molecule from xespresso import Espresso h2 = molecule('H2') h2.cell = [8, 8, 8] h2.pbc = [True, True, True] pseudopotentials = {'H': 'H.pbe-rrkjus_psl.1.0.0.UPF',} calc = Espresso(pseudopotentials = pseudopotentials, label = 'scf/h2', # 'scf/fe' is the directory, 'fe' is the prefix ecutwfc = 40, occupations = 'smearing', degauss = 0.03, kpts=(1, 1, 1)) h2.calc = calc e = h2.get_potential_energy() print('Energy: {0:1.3f}'.format(e)) ''' Energy: -3368.488 '''
from ase.build import molecule from xespresso import Espresso from xespresso.dos import DOS import matplotlib.pyplot as plt atoms = molecule('CO') atoms.center(5) atoms.pbc = [True, True, True] pseudopotentials = { 'O': 'O.pbe-n-rrkjus_psl.1.0.0.UPF', 'C': 'C.pbe-n-rrkjus_psl.1.0.0.UPF' } calc = Espresso( label='scf/co', pseudopotentials=pseudopotentials, ecutwfc=30, kpts=(1, 1, 1), ) atoms.calc = calc e = atoms.get_potential_energy() calc.read_results() print('Energy = {0:1.3f} eV'.format(e)) #=============================================================== # start nscf calculation, and dos, projwfc calc.read_results() fermi = calc.get_fermi_level() calc.nscf(kpts=(1, 1, 1)) calc.nscf_calculate() calc.post(package='dos', Emin=fermi - 20, Emax=fermi + 10, DeltaE=0.1) # DOS analysis dos = DOS(calc)