Modules

Todo

  • Authors? I always think its nice to have authors defined in the module, so that when you want to contact the right person you know who to follow up with. -RJM

  • Imports seem to have a random order. Set lint to give us a specific order and then stick to that. -RJM

Non-interacting Solver

Summary

Solve non-interacting 1d system numerically on a grid (position-space basis). Each eigenstate will be occupied by one electron.

Module author: Ryan Pederson ORCID: 0000-0002-7228-9478, Chris (Jielun) Chen, Li Li

Note

Both solvers (EigenSolver, SparseEigenSolver) here are based on directly diagonalizing the Hamiltonian matrix.

Todo

  • Figure out what to do about joint copyright holders (Google + other)

  • Clean out unused example rst content in here.

class non_interacting_solver.SolverBase(grids, potential_fn=None, num_electrons=1, k_point=None, boundary_condition='open', n_point_stencil=3, perturbation=None)[source]

Bases: object

Base Solver for non-interacting 1d system. Subclasses should define solve_ground_state method.

is_solved()[source]

Returns whether this solver has been solved.

solve_ground_state()[source]

Solve ground state. Need to be implemented in subclasses.

Compute attributes: total_energy, kinetic_energy, potential_energy, density, wave_function.

class non_interacting_solver.EigenSolver(grids, potential_fn=None, num_electrons=1, k_point=None, boundary_condition='open', n_point_stencil=3, perturbation=None)[source]

Bases: non_interacting_solver.SolverBase

Represents the Hamiltonian as a matrix and diagonalizes it directly.

This is the most stable and accurate eigensolver. Use SparseEigenSolver for a faster iterative eigensolver.

update_potential(potential_fn)[source]

Replace the current potential grids with a new potential grids. Delete all attributes created by solving eigenvalues, set _solved to False.

Parameters

potential_fn – potential function taking grids as argument.

get_kinetic_matrix()[source]

Kinetic matrix. Here the finite difference method is used to generate a kinetic energy operator in discrete space while satisfying desired boundary conditions.

Returns

Kinetic matrix with shape (num_grids, num_grids)

Return type

ndarray

get_potential_matrix()[source]

Potential matrix. A diagonal matrix corresponding to the one-body potential input.

Returns

Potential matrix with shape (num_grids, num_grids)

Return type

ndarray

solve_ground_state()[source]

Solve ground state by diagonalize the Hamiltonian matrix directly.

Compute attributes: total_energy, kinetic_energy, potential_energy, density, wave_function.

Returns

self

class non_interacting_solver.SparseEigenSolver(grids, potential_fn=None, num_electrons=1, k_point=None, boundary_condition='open', n_point_stencil=3, tol=1e-06)[source]

Bases: non_interacting_solver.EigenSolver

Represents the Hamiltonian as a matrix and solve with sparse eigensolver.

This eigensolver is iterative and approximate. It is in general much faster than EigenSolver but less robust.

solve_ground_state()[source]

Solve ground state by sparse eigensolver.

Compute attributes: total_energy, kinetic_energy, potential_energy, density, wave_function.

Returns

self

External Potentials

ext_potentials.gaussian_dips(grids, coeff, sigma, mu)[source]

Potential of sum of Gaussian dips.

The i-th Gaussian dip is

-coeff[i] * np.exp(-(grids - mu[i]) ** 2 / (2 * sigma[i] ** 2))

Parameters
  • grids – numpy array of grid points for evaluating 1d potential. (num_grids,)

  • coeff – numpy array of coefficient for each gaussian dip. (num_dips,)

  • sigma – numpy array of standard deviation for each gaussian dip. (num_dips,)

  • mu – numpy array of mean for each gaussian dip. (num_dips,)

Returns

Potential on grid.

(num_grids,)

Return type

vp

ext_potentials.harmonic_oscillator(grids, k=1.0)[source]

Potential of quantum harmonic oscillator.

Parameters
  • grids – numpy array of grid points for evaluating 1d potential. (num_grids,)

  • k – strength constant for potential vp = 0.5 * k * grids ** 2.

Returns

Potential on grid.

(num_grid,)

Return type

vp

ext_potentials.quartic_oscillator(grids, k=1.0)[source]

Potential of quantum quartic oscillator.

Parameters
  • grids – numpy array of grid points for evaluating 1d potential. (num_grids,)

  • k – strength constant for potential.

Returns

Potential on grid.

(num_grid,)

Return type

vp

ext_potentials.kronig_penney(grids, a, b, v0)[source]

Kronig-Penney model potential. For more information, see:

https://en.wikipedia.org/wiki/Particle_in_a_one-dimensional_lattice#Kronig%E2%80%93Penney_model

Parameters
  • grids – numpy array of grid points for evaluating 1d potential. (num_grids,)

  • a – periodicity of 1d lattice

  • b – width of potential well

  • v0 – negative float. It is the depth of potential well.

Returns

Potential on grid.

(num_grid,)

Return type

vp

ext_potentials.exp_hydrogenic(grids, A=1.071295, k=0.4192265689030308, center=0, Z=1)[source]

Exponential potential for 1D Hydrogenic atom.

A 1D potential which can be used to mimic corresponding 3D electronic structure. Similar in form to the soft-Coulomb interaction, however there is a cusp occurring at x = 0 for a -> 0. Please refer to:

Thomas E Baker, E Miles Stoudenmire, Lucas O Wagner, Kieron Burke, and Steven R White. One-dimensional mimicking of electronic structure: The case for exponentials. Physical Review B,91(23):235141, 2015.

The cusp should lie exactly on a grid point to avoid missing any kinetic energy.

Parameters
  • grids – numpy array of grid points for evaluating 1d potential. (num_grids,)

  • A – fitting parameter.

  • k – fitting parameter.

  • Z – the “charge” felt by an electron from the nucleus.

  • center – the center of the potential.

Returns

Potential on grid.

(num_grid,)

Return type

vp

ext_potentials.poschl_teller(grids, lam, a=1.0, center=0.0)[source]

Poschl-Teller potential.

Poschl-Teller potential is a special class of potentials for which the one-dimensional Schrodinger equation can be solved in terms of Special functions.

https://en.wikipedia.org/wiki/P%C3%B6schl%E2%80%93Teller_potential

The general form of the potential is

v(x) = -frac{lambda(lambda + 1)}{2} a^2 frac{1}{cosh^2(a x)}

It holds M=ceil(lambda) levels, where lambda is a positive float.

Parameters
  • grids – numpy array of grid points for evaluating 1d potential. (num_grids,)

  • lam – float, lambda in the Poschl-Teller potential function.

  • a – float, coefficient in the Poschl-Teller potential function.

  • center – float, the center of the potential.

Returns

Potential on grid with shape (num_grid,)

Raises

ValueError – If lam is not positive.

ext_potentials.poschl_teller_energy(level, lam, a=1.0)[source]

Analytic solution of the total energy filled up to level-th eigenstate.

The solution can be found in second row of Table 1 in

Leading corrections to local approximations. II. The case with turning points Raphael F. Ribeiro and Kieron Burke, Phys. Rev. B 95, 115115 https://journals.aps.org/prb/abstract/10.1103/PhysRevB.95.115115

Parameters
  • level – positive integer, the ground state is level=1.

  • lam – positive float, lambda.

  • a – float, coefficient in Poschl-Teller potential.

Returns

Float, the total energy from first to the level-th eigenstate.

ext_potentials.poschl_teller_eigen_energy(level, lam, a=1.0)[source]

Analytic solution of the level-th eigen energy for Poschl-Teller potential.

This is the energy level for Poschl-Teller potential with float lambda. The solution can be found in second row of Table 1 in

Leading corrections to local approximations. II. The case with turning points Raphael F. Ribeiro and Kieron Burke, Phys. Rev. B 95, 115115 https://journals.aps.org/prb/abstract/10.1103/PhysRevB.95.115115

Parameters
  • level – positive integer, the ground state is level=1.

  • lam – positive float, lambda.

  • a – float, coefficient in Poschl-Teller potential.

Returns

Float, the energy of the level-th eigenstate.

Functionals

Summary

Defined grid-based exchange-correlation functionals, fock operator, and potentials for 1D systems.

Module author: Ryan Pederson ORCID: 0000-0002-7228-9478, Chris (Jielun) Chen, Johnny Kozlowski

Todo

  • hf: replace with Chris’ matrix muliplication code. Much cleaner.

  • Docs need love.

functionals.hartree_potential(grids, n, v_ee=functools.partial(<function exp_hydrogenic>))[source]
class functionals.BaseHartreeFock(grids)[source]

Bases: object

v_hf(grids, n, v_ext)[source]

Total HF potential, v_{eff}.

v_h()[source]
class functionals.ExponentialHF(grids, A=1.071295, k=0.4192265689030308)[source]

Bases: functionals.BaseHartreeFock

v_h()[source]
update_fock_matrix(wave_function)[source]
get_E_x(wave_function)[source]

Obtain E_x ‘exactly’ from double integral over HF orbitals

class functionals.BaseExchangeCorrelationFunctional(grids)[source]

Bases: object

v_s_up(grids, n, v_ext, v_xc_up, n_up, n_down)[source]

Total up KS potential, v_{s, up}.

v_s_down(grids, n, v_ext, v_xc_down, n_up, n_down)[source]

Total KS potential, v_{s, down}.

v_h()[source]
v_xc_up(n, n_up, n_down)[source]
v_xc_down(n, n_up, n_down)[source]
e_x(n, zeta)[source]
e_c(n, zeta)[source]
get_E_x(n, zeta)[source]

Total exchange energy functional.

get_E_c(n, zeta)[source]

Total correlation energy functional.

class functionals.ExponentialLDAFunctional(grids, A=1.071295, k=0.4192265689030308)[source]

Bases: functionals.BaseExchangeCorrelationFunctional

local density approximation (LDA) for exponentially repelling electrons. For more details see [Baker2015].

v_h()[source]
v_xc_up(n, n_up, n_down)[source]

Exchange-Correlation Potential for up electrons, \(v_{xc, \uparrow} = d/dn_{\uparrow} e_{xc}\).

Parameters
  • n – system density on a grid.

  • n_up – up spin density on a grid.

  • n_down – down spin density on a grid.

Returns

the up XC potential on a grid.

Return type

ndarray

v_xc_down(n, n_up, n_down)[source]

Exchange-Correlation Potential for up electrons, \(v_{xc, \downarrow} = d/dn_{\downarrow} e_{xc}\).

Parameters
  • n – system density on a grid.

  • n_up – up spin density on a grid.

  • n_down – down spin density on a grid.

Returns

the down XC potential on a grid.

Return type

ndarray

e_x(n, zeta)[source]

Exchange energy per length.

e_c(n, zeta)[source]

Correlation energy per length.

Kohn-Sham DFT solver

Summary

Kohn-Sham DFT solver for 1-dimensional systems on a grid.

Module author: Ryan Pederson ORCID: 0000-0002-7228-9478

Todo

  • Comments in KS solver funciton should be in doc format

  • solve_self_consistent_density needs summary sentence

  • Linting?

class ks_dft.KS_Solver(grids, v_ext, xc, num_electrons=1, boundary_condition='open')[source]

Bases: scf_base.SCF_SolverBase

KS-DFT solver for non-periodic systems.

init_v_s(v_s_up=None, v_s_down=None)[source]

Initialize starting v_s_up and v_s_down. The default corresponds to v_hxc_up = v_hxc_down = 0.

Parameters
  • v_s_up – initial v_s_up on a grid.

  • v_s_down – initial v_s_down on a grid.

solve_self_consistent_density(mixing_param=0.3, verbose=0)[source]

Solve KS equations self-consistently.

Parameters
  • mixing_param – linear mixing parameter, where 0.0 denotes no mixing.

  • verbose – convergence debug printing.

Returns

converged KS_Solver with results.

Return type

KS_Solver

Hartree-Fock solver

Summary

This is the summary

Module author: Ryan Pederson ORCID: 0000-0002-7228-9478

Todo

  • Comments in HF solver funciton should be in doc format

  • solve_self_consistent_density needs summary sentence

  • Clean out unused example rst content in here.

  • linting?

class hf_scf.HF_Solver(grids, v_ext, hf, num_electrons=1, boundary_condition='open')[source]

Bases: scf_base.SCF_SolverBase

HF solver for non-periodic systems.

init_v_eff(v_eff_up=None, v_eff_down=None, fock_mat_up=None, fock_mat_down=None)[source]

Initialize starting v_eff_up and v_eff_down.

get_E_x_HF()[source]
solve_self_consistent_density(mixing_param=0.3, verbose=0)[source]
Parameters
  • mixing_param – linear mixing parameter, where 0.0 denotes no mixing.

  • verbose – convergence debug printing.

Returns

self.

Default constants used in this library.

Exponential Coulomb interaction.

v(x) = amplitude * exp(-abs(x) * kappa)

See also ext_potentials.exp_hydrogenic. Further details in:

Thomas E Baker, E Miles Stoudenmire, Lucas O Wagner, Kieron Burke, and Steven R White. One-dimensional mimicking of electronic structure: The case for exponentials. Physical Review B,91(23):235141, 2015.

utils.get_dx(grids)[source]

Gets the grid spacing from a grids array.

Parameters

grids – Numpy array with shape (num_grids,).

Returns

Grid spacing.

Return type

h

utils.vw_grid(density, dx)[source]

von Weizsacker kinetic energy functional on grid.

Parameters
  • density – numpy array, density on grid. (num_grids,)

  • dx – grid spacing.

Returns

von Weizsacker kinetic energy.

Return type

kinetic_energy

utils.quadratic(mat, x)[source]

Compute the quadratic form of matrix and vector.

Parameters
  • mat – matrix. (n, n)

  • x – vector. (n,)

Returns

scalar value as result of x A x.T.

Return type

output

class utils.IntegralTool(grids, A=1.071295, k=0.4192265689030308, init=True)[source]

Bases: object

Containing integral matrices.

integral(func_grids)[source]
class utils.DerivativeTool(grids, n_point_stencil=5, init=True)[source]

Bases: object

Containing derivative matrices.