nanotools.mix module
This module defines the Mix
class.
- class nanotools.mix.Mix(alpha: float = 0.2, converged: bool = False, eres=None, etol: float = 1e-08, imem: int = 20, pp_period: int = 3, iter: int = 0, maxit: int = 100, method: str = 'pul', metric: str = 'eye', monitored_variables: list = [1], precond: str = 'eye', res=None, tol: float = 1e-08, type: str = 'den')[source]
Bases:
Base
Mix
class.- alpha
Mixing fraction.
alpha
should be a parameter in the interval [0, 1]. The closer it is to 0, the more stable the convergence of the solver. The closer it is to 1, the faster the convergence of the solver.Examples:
mix.alpha = 0.45
- Type:
float
- eres
On exit, array containing the total energy residuals.
- Type:
float
- etol
Total energy tolerance (in Hartree / electron).
- Type:
float
- imem
Maximal number of trial functions retained to compute the new trial function in the mixer. For example, in a calculation doing density mixing with mix.imem = 10, the mixer will estimate the next trial density based on the densities of the last 10 iterations.
Examples:
mix.imem = 10
- Type:
int
- pp_period
Period of the periodic Pulay mixer, namely one less than the number of linear mixing steps between Pulay mixing steps. Only used if mix.method = “per”.
Examples:
mix.pp_period = 3
- Type:
int
- maxit
Maximal number of iterations. Note that the Kohn-Sham solver will return an answer even if it has not converged, which can then be use for restart.
Examples:
mix.maxit = 50
- Type:
int
- method
method
takes the following values:“lin”: linear mixing.
“pul”: Pulay mixing.
“per”: Periodic Pulay mixing.
Examples:
mix.method = "pul"
- Type:
str
- metric
Quasi-Newton methods perform inner products, which can be calculated straightforwardly using the identity metric (“eye”). Kresse and Furthmuller have however suggested using the Kerker metric (“ker”) .
metric
takes the following values:eye
: identity metric.ker
: Kerker-like metric
Examples:
mix.metric = "eye"
- Type:
str
- monitored_variables
Array of integer giving which variables are monitored and used to determine convergence.
1: monitor density.
2: monitor total energy.
Examples:
mix.monitored_variables = [1] # monitor the density residual mix.monitored_variables = [2] # monitor the total energy residual mix.monitored_variables = [1, 2] # monitor both residuals
- Type:
list of int
- precond
Initial inverse Jacobian. The initial inverse Jacobian is necessary in quasi-Newton methods. It is by default “eye” (the identity), in which case the initial inverse Jacobian is
alpha I
, wherealpha
= mix.alpha. It can also be “ker” (for Kerker).Examples:
mix.precond = "ker"
- Type:
str
- res
On exit, array containing the density residuals.
- Type:
float
- tol
In self-consistent calculations, the convergence procedure stops if the change in density per electron becomes smaller than
tol
. In equations,\[\delta d = \int \|d_{i}^{out} - d_{i}^{in}\| / N^{el}.\]Examples:
mix.tol = 1e-6
- Type:
float
- type
Determine which quantity to mix. Only density (“den”) can be mixed currently.
Examples:
mix.type = "den"
- Type:
str
- set_alpha(alpha)[source]
Sets the mixing fraction.
alpha
should be a parameter in the interval [0, 1]. The closer it is to 0, the more stable the convergence of the solver. The closer it is to 1, the faster the convergence of the solver.
- set_imem(imem)[source]
Sets the mixer memory.
Maximal number of trial functions retained to compute the new trial function in the mixer. For example, in a calculation doing density mixing with
mix.imem = 10
, the mixer will estimate the next trial density based on the densities of the last 10 iterations.
- set_maxit(maxit)[source]
Sets the maximal number of iterations.
Maximal number of iterations. Note that the Kohn-Sham solver will return an answer even if it has not converged, which can then be use for restart.
- set_method(method)[source]
Sets the mixing method.
method
takes the following values:“lin”: linear mixing.
“pul”: Pulay mixing.
“per”: Periodic Pulay mixing.
- set_metric(metric)[source]
Sets the mixing metric.
Quasi-Newton methods perform inner products, which can be calculated straightforwardly using the identity metric (“eye”). Kresse and Furthmuller have however suggested using the Kerker metric (“ker”) .
metric
takes the following values:eye
: identity metric.ker
: Kerker-like metric.
- set_monitored_variables(var, tol=None)[source]
Sets the monitored variables. Allowed values are “density” and “energy”.
- set_pp_period(pp_period)[source]
Sets the period of the periodic Pulay mixer.
Period of the periodic Pulay mixer, namely one less than the number of linear mixing steps between Pulay mixing steps. Only used if
mix.method = "per"
.
- set_precond(precond)[source]
Sets the mixing precond.
The mixing preconditioner is an initial guess for the inverse Jacobian. The initial inverse Jacobian is necessary in quasi-Newton methods. It is by default “eye” (for identity), in which case the initial inverse Jacobian is
alpha I
, wherealpha
= mix.alpha. It can also be “ker” (for Kerker).precond
takes the following values:eye
: identity precond.ker
: Kerker precond.