riigid.optimizer package

riigid.optimizer.GDWAS module

class riigid.optimizer.GDWAS.GDWAS(stepsize_factor_up=1.2, stepsize_factor_dn=0.2, max_trans=1.0, max_rot=30.0, max_trans_0=0.1, max_rot_0=3.0, start_with_random_step=True, displacement_r0=0.01, angle_r0=0.3, respect_restrictions_r0=True, seed_r0=1234, max_iter=500)[source]

Bases: Optimizer

RIIGID optimizer: Gradient Descent with Adaptive Stepsize

Calculates force and torque on each fragment and moves them accordingly (like rigid bodies).

The goal of this optimizer is to converge to the nearest minimum. To achieve this, in case the last update of the atomic positions lead to higher energies, it is dropped and the calculation is continued from the previous structure. This way, climbing upwards in the potential energy surface (PES) is prohibited and the probability for jumping into a different potential well is lowered. Additionally, a hard cap on the movement of individual fragments is enforced by max_trans and max_rot. This again helps in reducing the probability of the structure leaving a local minimum.

The stepsize is adaptive and can change for two reasons:

1.) If the last update performed on the atomic positions lowered the total energy (i.e a larger negative number), the stepsize is increased by multiplying with stepsize_factor_up. On the other hand, if the energy increased, the stepsize is lowered by multiplying with stepsize_factor_dn.

2.) As described above, a hard cap on the movement of individual fragments is enforced by max_trans and max_rot. If a fragment is found to translate more than max_trans, the stepsize is lowered in such a way, that the maximal displacement of the fragments is exactly max_trans. On the other hand, if a fragment is rotated by more than max_rot, the stepsize is adapted, such that the maximal rotation (i.e. the rotation of the fragment that rotates the most) is max_rot.

The user never needs to interact directly with the stepsize. Instead, via max_trans_0 and max_rot_0, the user specifies how much the fragments (at most) shall move in the first optimization step. The stepsize is then initialized accordingly and from there on adapted automatically, as described above.

optimization_history

The history of the optimization, which shall be checked for convergence.

Type:

list of riigid.Optimization_Step

iteration

Counts the number of finished optimization steps

Type:

int

stepsize

Timestep; [Da*Å**2/eV]

Type:

number

stepsize_factor_up

Increase stepsize by this factor, if last optimization step lowered the total energy

Type:

number > 1

stepsize_factor_dn

Decrease stepsize by this factor, if last optimization step increased the total energy

Type:

number < 1

max_trans

The maximum distance fragments are allowed to translate per optimization step; [Å]

Type:

number

max_rot

The maximum angle fragments are allowed to rotate per optimization step; [°]

Type:

number

max_trans_0, max_rot_0

In the first optimization step, the stepsize is chosen such that the fragment(s) translating/rotating the most, translate/rotate by (one of) these value; [Å], [°]

Type:

number, number

start_with_random_step

Shall the fragments forming the structure be randomly translated and rotated before the first optimization step? This can be used to escape a saddle point starting-geometry. The attributes with ‘_r0’ at the end further specify this random step before the first optimization step.

Type:

bool

displacement_r0

How far shall the fragments be translated; [Å]

Type:

number

angle_r0

How much shall the fragments be rotated; [°]

Type:

number

respect_restrictions_r0

If True, fragment.allowed_translation/rotation is respected. If False, rotation and translation in arbitrary directions is allowed temporarily. (After the random step, the restrictions are respected again.)

Type:

bool

seed_r0

The random seed used to generate the translation directions and rotation axes

Type:

int

max_iter

The maximal number of optimization steps to be performed. If the calculation does not converge within this limit, it is stopped.

Type:

int

start_structure

The structure to be optimized

Type:

riigid.Structure

calculator

The used ASE calculator object

Type:

ase.calculators.calculator.Calculator

convergence_criterion

The used convergence criterion object

Type:

riigid.convergence.Criterion

current_structure

The structure currently used by the optimizer

Type:

riigid.Structure

current_energy

The energy of current_structure; [eV]

Type:

number

current_forces

The forces in current_structure; [eV/Å]

Type:

numpy.ndarray of shape (n_atoms_in_current_structure, 3)

adapt_stepsize_to_energy_change()[source]

Adapt the stepsize according to the last update step.

If the last update performed on the atomic positions lowered the total energy (i.e a larger negative number), the stepsize is increased by multiplying with stepsize_factor_up. On the other hand, if the energy increased, the stepsize is lowered by multiplying with stepsize_factor_dn.

adapt_stepsize_to_prevent_too_large_steps()[source]

Prevent too large movement of the fragments.

If a fragment is found to translate more than self.max_trans, the stepsize is lowered in such a way, that the maximal displacement of the fragments is exactly self.max_trans. On the other hand, if a fragment is rotated by more than self.max_rot, the stepsize is adapted, such that the maximal rotation (i.e. the rotation of the fragment that rotates the most) is self.max_rot. (The weaker condition is fulfilled, i.e. the one with less movement/smaller stepsize.)

Note

Translation distances and rotation angles of fragments are directly proportional to the stepsize. This is used here to turn down too large stepsizes.

drop_last_step_if_energy_got_larger()[source]

Drop last update step if it increased the total energy.

initialize_stepsize_in_first_iteration()[source]

Initialize the stepsize in the first iteration of the optimization.

During the first iteration of the optimizations, this function adapts the stepsize such that the maximum displacement of the fragments is exactly self.max_trans_0 or the maximum rotation is exactly self.max_rot_0. (The weaker condition is fulfilled, i.e. the one with less movement/smaller stepsize.)

Note

Translation distances and rotation angles of fragments are directly proportional to the stepsize. This is used here to turn down too large stepsizes.

run(start_structure, calculator, convergence_criterion, callback=None)[source]

Let the optimizer run its optimization on the structure.

Parameters:
  • start_structure (riigid.Structure) – The structure to be optimized

  • calculator (ase.calculators.calculator.Calculator) – The used ASE calculator object

  • convergence_criterion (riigid.convergence.criterion) – The used convergence criterion object

  • callback (function, default:None) – A callback function can be used to safe the optimization progress after each step.

riigid.optimizer.optimizer module

class riigid.optimizer.optimizer.Optimizer(max_iter)[source]

Bases: object

Base class for RIIGID optimizers

optimization_history

The history of the optimization, which shall be checked for convergence.

Type:

list of riigid.Optimization_Step

iteration

Counts the number of finished optimization steps

Type:

int

max_iter

The maximal number of optimization steps to be performed. If the calculation does not converge within this limit, it is stopped.

Type:

int

Note

Depending on the optimizer, iteration and len(optimization_history) may not be the same. This can e.g. happen, if the optimizer drops optimization steps, where the energy grew.

print_reason_for_end_of_optimization()[source]

Prints the reason why the optimization has ended.

Call this function when the optimization is finished.

run(start_structure, calculator, convergence_criterion, callback=None)[source]

Let the optimizer run its optimization on the structure.

Parameters:
  • start_structure (riigid.Structure) – The structure to be optimized

  • calculator (ase.calculators.calculator.Calculator) – The used ASE calculator object

  • convergence_criterion (riigid.convergence.Criterion) – The used convergence criterion object

  • callback (function, default:None) – A callback function can be used to safe the optimization progress after each step.

riigid.optimizer.Deprecated_GDWAS module