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 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 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 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 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
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, fileout='stm1_1eV.cube') # ======================== # Creates: 2d.png, 2d_I.png, line.png, dIdV.png from ase.dft.stm import STM from ase.io.cube import read_cube_data