ASRCalculator

class ase2sprkkr.asr.test.mocks.gpaw.calculator.ASRCalculator(restart=None, ignore_bad_restart_file=<object object>, label=None, atoms=None, directory='.', **kwargs)[source]

Mock of a generic ASE calculator.

This test calculator is specifically designed to look like the GPAW calculator, and to make additional monkey patching easy. Each of the public methods have an identical private method prefaced with underscore that can be easily patch using the pytest mocker.patch functionality. For example, ASRCalculator.get_fermi_level has an identical ASRCalculator._get_fermi_level method that can be easily mocked up.

By default, the eigenvalues set up the calculator has some valence bands with negative curvature and some conduction bands with positive curvature. Furthermore, if the return value of _get_band_gap is non-zero the valence and conduction bands will be separated by a band gap. This provides an easy way to manipulate the properties of a test material.

Class hierarchy

Inheritance diagram of ase2sprkkr.asr.test.mocks.gpaw.calculator.ASRCalculator

Constructor

__init__(restart=None, ignore_bad_restart_file=<object object>, label=None, atoms=None, directory='.', **kwargs)

Basic calculator implementation.

restart: str

Prefix for restart file. May contain a directory. Default is None: don’t restart.

ignore_bad_restart_file: bool

Deprecated, please do not use. Passing more than one positional argument to Calculator() is deprecated and will stop working in the future. Ignore broken or missing restart file. By default, it is an error if the restart file is missing or broken.

directory: str or PurePath

Working directory in which to read and write files and perform calculations.

label: str

Name used for all files. Not supported by all calculators. May contain a directory, but please use the directory parameter for that instead.

atoms: Atoms object

Optional Atoms object to which the calculator will be attached. When restarting, atoms will get its positions and unit-cell updated from file.

implemented_properties: List[str] = ['energy', 'forces', 'stress', 'dipole', 'magmom', 'magmoms', 'stresses', 'charges', 'fermi_level', 'gap', 'berry_phases']

Properties calculator can handle (energy, forces, …)

default_parameters: Dict[str, Any] = {'gridsize': 3, 'kpts': (4, 4, 4), 'nbands': 12, 'txt': None}

Default parameters

occupations = <ase2sprkkr.asr.test.mocks.gpaw.calculator.Occupations object>
wfs = <ase2sprkkr.asr.test.mocks.gpaw.calculator.WaveFunctions object>
world = namespace(size=1, rank=0, broadcast=<function broadcast>, barrier=<function barrier>, new_communicator=<function new_communicator>, sum=<function world_sum>)
calculate(atoms, *args, **kwargs)[source]

Calculate properties of atoms and set some necessary instance variables.

This is the main method that calculates the energy, forces and other properties of the given structure. This method should not be mocked. In stead mock the implementation of the specific property you need to amend.

set(**kwargs)[source]

Set parameters like set(key1=value1, key2=value2, …).

A dictionary containing the parameters that have been changed is returned.

Subclasses must implement a set() method that will look at the chaneged parameters and decide if a call to reset() is needed. If the changed parameters are harmless, like a change in verbosity, then there is no need to call reset().

The special keyword ‘parameters’ can be used to read parameters from a file.

property spos_ac
_get_scaled_positions()[source]

Get scaled positions.

_get_setups()[source]

Get all setups.

_get_setup_fingerprint(element_number)[source]

Get specific setup fingerprint.

Parameters:

element_number (int) – Atomic number of element.

Return type:

str

_get_setup_symbol(element_number)[source]

Get setup symbol.

_get_setup_nvalence(element_number)[source]

Get number of valence electrons.

This also dynamically controls the number of valence bands.

_get_setup(element_number)[source]

Get specific setup.

Parameters:

element_number (int) – Atomic number of element.

Returns:

A SimpleNamespace that resembles a GPAW Setups class.

Return type:

SimpleNamespace

_get_berry_phases(dir, spin)[source]

Return berry phases.

Parameters:
  • dir (int) – Which direction to return berry phases along.

  • spin (int) – Spin channel.

Returns:

Berry phases along a specific axis

Return type:

np.ndarray

_get_band_gap()[source]

Get band gap.

_get_dipole_moment()[source]
get_fermi_level(atoms=None)[source]

Get cached fermi level.

_get_fermi_level()[source]

Get formi level.

_get_forces()[source]

Get atomic forces.

_get_magmom()[source]

Get total magnetic moment.

_get_magmoms()[source]

Get atomic magnetic moments.

_get_potential_energy()[source]

Get potential energy.

_get_stress()[source]

Get cell stress.

get_all_eigenvalues()[source]

Get all eigenvalues.

Constructs all eigenvalues for the test calculator. The valence bands will have a negative curvature and the number of valence bands are determined by ASRCalculator.get_number_of_valence_electrons(). Conduction bands have positive curvature and are separated from the valence bands by a bandgap. The band gap is obtained from ASRCalculator._get_band_gap().

get_eigenvalues(kpt, spin=0)[source]

Return the eigenvalues of a specific k-point.

Parameters:
  • kpt (int) – K-point index.

  • spin (int) – Spin channel.

get_k_point_weights()[source]

Get all k-point weights.

get_ibz_k_points()[source]

Get an array of all irreducible k-points.

get_bz_k_points()[source]

Get an array of all k-points.

get_bz_to_ibz_map()[source]

Get BZ to IBZ map.

get_number_of_spins()[source]

Get number of spins in calculation.

get_number_of_bands()[source]

Get total number of bands in calculation.

get_number_of_conduction_electrons()[source]

Get number of conduction electrons per unit cell.

get_number_of_electrons()[source]

Get number of electrons.

get_number_of_valence_electrons()[source]

Get number of valence electrons.

The number of valence electrons exclude any extra doping there might exist due to any additional doping.

write(name, mode=None)[source]

Write calculator to file.

read(name)[source]

Read calculator from file.

get_electrostatic_potential()[source]

Get electrostatic potential.

diagonalize_full_hamiltonian(ecut=None)[source]

Diagonalize full Hamiltonian.

dos(soc=False, theta=0.0, phi=0.0, shift_fermi_level=True)[source]
fixed_density(**kwargs)[source]
_abc_impl = <_abc._abc_data object>