coordinates
What an optimiser varies.
A Coordinates object is a parameterisation of a structure. It hands the
optimiser a vector, writes a new vector back into the structure, converts
forces and stress into a gradient with respect to that vector, and reports how
many Angstroms of atomic motion one unit of each degree of freedom is worth.
That last part is scale, and it is what lets one trust radius and one set of
tolerances cover degrees of freedom measured in different units. A cell strain
is dimensionless, a fractional coordinate spans a lattice vector, and a
rotation is in radians; scaled to Angstroms of displacement they are
comparable, and an optimiser step means the same thing in each. Convergence is
then tested on the quantities themselves -- force in eV/A, stress in GPa --
rather than on a norm over a mixed-unit array.
Atomic
Bases: Coordinates
Cartesian atomic positions at a fixed cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
the structure to vary |
required | |
fixed
|
(N,) boolean mask of atoms to hold still, or None |
None
|
Source code in chmpy/opt/coordinates.py
AtomicStrain
Bases: Strain
Atomic positions and the cell together.
The variables are the atomic positions in the undeformed frame plus the strain amplitudes. Holding the atoms in the undeformed frame is what keeps the two kinds of freedom from fighting: a change in strain moves them affinely, which is exactly the deformation the stress is the derivative with respect to, so neither gradient contains a term belonging to the other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
the structure to vary |
required | |
basis
|
(k, 3, 3) strain basis, or None for all six directions |
None
|
|
fixed
|
(N,) boolean mask of atoms to hold still in the undeformed frame. They still move with the cell. |
None
|
Source code in chmpy/opt/coordinates.py
n_atomic
property
How many degrees of freedom belong to the atoms
Coordinates
Bases: ABC
A set of degrees of freedom, and the structure they act on.
Attributes:
| Name | Type | Description |
|---|---|---|
system |
the |
|
wanted |
frozenset
|
the properties the gradient needs from a calculator |
Source code in chmpy/opt/coordinates.py
n_dof
abstractmethod
property
How many degrees of freedom
get()
abstractmethod
gradient(result)
abstractmethod
measures(result)
reanchor(x, force=False)
Re-express the current geometry about a new reference, or None.
The geometry is unchanged, only the variables describing it, so a
result computed at x is still valid at the vector this returns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
the current degrees of freedom |
required | |
force
|
bool
|
re-anchor even if the parameterisation has not drifted far. The optimiser passes this when a step has been clipped, which is the situation the re-anchor exists for. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | None
|
the new degree-of-freedom vector, or None if nothing was done |
Source code in chmpy/opt/coordinates.py
scale()
abstractmethod
set(x)
abstractmethod
step_fraction(x, dx)
How much of a proposed step keeps the parameterisation valid.
One factor for the whole step, never a per-component clamp: the optimiser has to evaluate the step its model predicted a reduction for.
Source code in chmpy/opt/coordinates.py
Strain
Bases: Coordinates
The cell alone, as amplitudes along a symmetry-adapted strain basis.
The atoms are carried along affinely, which is exactly the deformation the stress is the derivative with respect to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
the structure to vary |
required | |
basis
|
(k, 3, 3) strain basis, or None for all six directions. Build a
symmetry-adapted one with |
None
|
Source code in chmpy/opt/coordinates.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
deformation_gradient
property
(3, 3) F = I + eps, the deformation from the reference
reanchor(x, force=False)
Move the reference to the current cell once the strain is large.
The bounds in strain exist to stop one linearised step producing a
degenerate cell, not to cap how far a cell may travel over a whole
relaxation. Without a re-anchor a structure that reaches a bound
proposes zero-length steps for ever after, which a trust region reads
as failure and answers by shrinking the radius until the structure is
dead. That is why the optimiser also calls this with force the moment
a step is clipped, rather than only after one is accepted -- at a bound,
no step is ever accepted, so waiting for one waits for ever.
This is not a pure change of origin: deformations compose multiplicatively, so a model built in the old parameterisation is slightly wrong in the new one. It self-heals on the next gradient, and it only fires when the strain is already large.
Source code in chmpy/opt/coordinates.py
strain_gradient(result)
dE/dq for the strain amplitudes.
A further strain d about the current geometry takes F to
F (I + d), so dE = <F^T dE/dF, d> = V <sigma, d> and therefore
dE/dF = F^-T V sigma. Contracting with the basis, which is symmetric,
symmetrises it. At F = I this is just V <sigma, B>.
Source code in chmpy/opt/coordinates.py
pressure_term(coordinates, pressure_gpa)
The gradient contribution of an external hydrostatic pressure.
Minimising E + P V rather than E relaxes to a structure in equilibrium
with a pressure. dV/dq = V tr(F^-1 B) for a strain basis direction B.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coordinates
|
a |
required | |
pressure_gpa
|
float
|
applied pressure in GPa |
required |
Returns:
| Type | Description |
|---|---|
|
(n_dof,) gradient contribution in eV per unit degree of freedom |
Source code in chmpy/opt/coordinates.py
strain_basis_for(structure, symmetry=True)
The strain basis to use for a structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
a |
required | |
symmetry
|
bool
|
when False, or when the structure carries no space group, all six strain directions are allowed |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(k, 3, 3) orthonormal strain basis |