def get_work_function(self, ax=None, inpfile='potential.cube', output=None, shift=False): import matplotlib.pyplot as plt from ase.io.cube import read_cube_data from ase.units import create_units if ax is None: import matplotlib.pyplot as plt ax = plt.gca() units = create_units('2006') # filename = os.path.join(self.directory, inpfile) data, atoms = read_cube_data(filename) data = data * units['Ry'] ef = self.get_fermi_level() # x, y, z, lp = calc.get_local_potential() nx, ny, nz = data.shape axy = np.array([np.average(data[:, :, z]) for z in range(nz)]) # setup the x-axis in realspace uc = atoms.get_cell() xaxis = np.linspace(0, uc[2][2], nz) if shift: ax.plot(xaxis, axy - ef) ef = 0 else: ax.plot(xaxis, axy) ax.plot([min(xaxis), max(xaxis)], [ef, ef], 'k:') ax.set_xlabel('Position along z-axis ($\AA$)') ax.set_ylabel('Potential (eV)') if output: plt.savefig('%s' % output) # plt.show() atoms = self.results['atoms'] pos = max(atoms.positions[:, 2] + 3) ind = (xaxis > pos) & (xaxis < pos + 3) wf = np.average(axy[ind]) - ef print('min: %s, max: %s' % (pos, pos + 3)) print('The workfunction is {0:1.2f} eV'.format(wf))
import numpy as np import xml.etree.ElementTree as ET from ase.io import Trajectory, cif from ase.io import espresso from ase.visualize import view from ase import Atoms, Atom from ase.calculators.singlepoint import (SinglePointDFTCalculator, SinglePointKPoint) from ase.units import create_units import matplotlib.pyplot as plt # Quantum ESPRESSO uses CODATA 2006 internally units = create_units('2006') # atoms = cif.read_cif('/home/mk/tetracene/tetracene.cif', None) def xstr(s): if s is None: return '' return str(s) def get_atoms_from_xml(xml_elem): atoms = [] for item in xml_elem.find('atomic_structure').find( 'atomic_positions').findall('atom'): coords = np.array(item.text.split(), dtype=np.float) * units['Bohr'] atom = Atom(symbol=item.items()[0][1], position=coords) atoms.append(atom)
def test_bad_codata(): name = 'my_bad_codata_version' with pytest.raises(NotImplementedError, match=name): create_units(name)
from __future__ import print_function from __future__ import absolute_import from __future__ import division from math import pi from numpy import empty, zeros, ones, identity from numpy import dot, cross, outer, arange, array, mod from numpy.linalg import norm from numpy.lib.twodim_base import triu_indices from gpaw import GPAW from gpaw import __version__ as gpaw_version from gpaw.mpi import world from gpaw.utilities.blas import gemm from ase.units import create_units, __codata_version__ from ase.parallel import parprint HA = create_units(__codata_version__)['Hartree'] class LCAOTDDFTq0(object): """Class for performing LCAO TDDFT in the optical limit q -> 0+""" def __init__(self, calc, eta=0.1, scissor=0.0, cutocc=1e-5, verbose=False, scalapack=False): """Creates a LCAOTDDFTq0 object. calc GPAW LCAO calculator or gpw filename eta Lorentzian broadening (0.1 eV)
from . import utils from ase.io.espresso import KEYS from ase.units import create_units import numpy as np import os import warnings import six KEYS['system'] += ['ensemble_energies', 'print_ensemble_energies'] Rydberg = create_units('2006')['Rydberg'] Bohr = create_units('2006')['Bohr'] variables = { # CONTROL 'outdir': '.', 'prefix': 'calc', 'etot_conv_thr': 1e12, 'forc_conv_thr': 0.05 / (Rydberg / Bohr), 'pseudo_dir': os.environ.get( 'ESP_PSP_PATH', os.path.join('/'.join(__file__.split('/')[:-2]), 'gbrv15pbe')), 'occupations': 'smearing', 'smearing': 'mp', 'ibrav': 0,
Units are converted using CODATA 2006, as used internally by Quantum ESPRESSO. """ import operator as op from collections import OrderedDict import numpy as np from ase.atoms import Atoms from ase.units import create_units from ase.calculators.singlepoint import SinglePointCalculator from ase.utils import basestring from ase.data import chemical_symbols # Quantum ESPRESSO uses CODATA 2006 internally units = create_units('2006') # Section identifiers _PW_START = 'Program PWSCF' _PW_END = 'End of self-consistent calculation' _PW_CELL = 'CELL_PARAMETERS' _PW_POS = 'ATOMIC_POSITIONS' _PW_MAGMOM = 'Magnetic moment per site' _PW_FORCE = 'Forces acting on atoms' _PW_TOTEN = '! total energy' _PW_STRESS = 'total stress' class Namelist(OrderedDict): """Case insensitive dict that emulates Fortran Namelists.""" def __contains__(self, key):
''' Objects to help track CSP structures through CrystalPredictor and CrystalOptimiser ''' from ase.units import create_units aseUnits = create_units('2014') HARTREE2KJPM = (aseUnits['Hartree'] * aseUnits['mol']) / aseUnits['kJ'] def generalCallErrorCatch(instance, function, argument): ''' Allows instance.function(argument) with generic errors ''' try: return getattr(instance, function)(argument) except: return None def processFile(summaryFilePointer, inDict): ''' read file, inDict has the info to look for particular lines and processes info (see below) ''' import os outDict = {} if not os.path.isfile(summaryFilePointer): return dict([[k, None] for k in inDict.keys()]) #for some reason the order of loops was wrong originally #also can only run readlines once, so save it with open(summaryFilePointer, 'r') as inFile: savedList = inFile.readlines() for k in inDict.keys(): try:
import ase except: raise ImportError("Error, ase library needed to run this script.") import sys, os import numpy as np import cellconstructor as CC import cellconstructor.Phonons import sscha import sscha.Ensemble # Create the units according to quantum-espresso from ase.units import create_units units = create_units("2006") #Rydberg, Bohr Rydberg = units["Ry"] Bohr = units["Bohr"] INFO = """ This script reads an incomplete ensemble from a given working directory and saves it in the binary format Usage: >>> read_incomplete_ensemble.py origin_dynmat PREFIX <save_dir> <population> [extension] The script takes 4 or 5 positional arguments. 1) The original dynamical matrix. Only the prefix of the matrix is required. The code will guess automatically how many irreducible q points must be read. 2) The calculation prefix. I.e. if we saved our espresso output files as data/ESP_X.pwo where X is the number of the calculation, PREFIX must be 'data/ESP_'