relax
Relaxing a structure to a local minimum.
from chmpy import Crystal
from chmpy.calc import Calculator
from chmpy.opt import relax
crystal = Crystal.load("structure.cif")
result = relax(crystal, calculator, fmax=0.01, smax=0.05)
result.structure.save("relaxed.cif")
relax picks the parameterisation: a Crystal varies its asymmetric unit and
the strains its space group allows, a Molecule varies its atoms, and a
System varies atoms and cell if it has one. Anything more particular is a
Coordinates object and a TrustRegion built by hand.
It runs a sequence of Stages, and by default that sequence is one. The
familiar protocol of settling the internal coordinates at fixed cell before
relaxing everything together is available as stages="two-stage" but is not
the default, because neither argument for it holds here. The first is that the
stress is expensive and should be deferred: for a model that differentiates its
energy it comes out of the same backward pass as the forces, measured at under
two percent of the call. The second is that the cell should not chase a
geometry that is still moving, which describes an optimiser that cannot tell
the two kinds of freedom apart; these are scaled to a common unit and the trust
region handles them together. Measured on a molecular crystal, splitting the
relaxation costs more calls than it saves.
A split still earns its keep when the stages differ in something other than
which freedoms move -- a cheap potential for the first pass and an expensive
one for the second -- and the Stage list is the right shape for that.
Stage
dataclass
One step of a relaxation protocol.
Attributes:
| Name | Type | Description |
|---|---|---|
cell |
bool
|
vary the cell during this stage |
fmax |
float
|
force convergence for this stage, eV/A |
smax |
float
|
stress convergence for this stage, GPa; ignored at fixed cell |
steps |
int
|
maximum iterations for this stage |
hessian |
object
|
"model" builds a stretch model from the geometry, "identity" starts blind, "carry" continues from the previous stage's learned curvature (falling back to "model" for the first stage), or pass an array |
name |
str
|
what to call it in the log |
Source code in chmpy/opt/relax.py
coordinates_for(structure, cell=True, symmetry=True, fixed=None, info=None)
The degrees of freedom to relax a structure with.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
a |
required | |
cell
|
bool
|
vary the cell. Ignored for anything not periodic. |
True
|
symmetry
|
bool
|
for a |
True
|
fixed
|
boolean mask of atoms to hold still -- over the asymmetric unit when symmetry is on, over the unit cell otherwise |
None
|
|
info
|
model inputs that are not geometry, e.g. a charge or a spin,
carried on the |
None
|
Returns:
| Type | Description |
|---|---|
|
a |
Source code in chmpy/opt/relax.py
relax(structure, calculator, *, cell=True, symmetry=True, fixed=None, info=None, fmax=0.01, smax=0.05, steps=200, pressure=0.0, options=None, hessian='model', stages=None, progress=None)
Relax a structure to a local minimum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
a |
required | |
calculator
|
a |
required | |
cell
|
bool
|
vary the cell as well as the atoms |
True
|
symmetry
|
bool
|
keep a crystal's space group, exactly, by making the asymmetric unit the degrees of freedom |
True
|
fixed
|
boolean mask of atoms to hold still |
None
|
|
info
|
model inputs that are not geometry -- a charge, a spin, an
external field -- carried on the |
None
|
|
fmax
|
float
|
force convergence in eV/A |
0.01
|
smax
|
float
|
stress convergence in GPa |
0.05
|
steps
|
int
|
maximum iterations per stage |
200
|
pressure
|
float
|
external hydrostatic pressure in GPa, so the objective is the
enthalpy |
0.0
|
options
|
|
None
|
|
hessian
|
the starting curvature model for a single-stage run: "model", "identity", or an array |
'model'
|
|
stages
|
a list of |
None
|
|
progress
|
True to print each step, or a callable given a
|
None
|
Returns:
| Type | Description |
|---|---|
Relaxation
|
a |
Relaxation
|
whose |
Relaxation
|
default protocol, and none for stages skipped as having no freedoms |
Source code in chmpy/opt/relax.py
135 136 137 138 139 140 141 142 143 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 | |
two_stage(fmax=0.01, smax=0.05, steps=200)
Settle the atoms at fixed cell, then relax the cell with them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmax
|
float
|
final force convergence, eV/A |
0.01
|
smax
|
float
|
final stress convergence, GPa |
0.05
|
steps
|
int
|
maximum iterations per stage |
200
|
Returns:
| Type | Description |
|---|---|
list[Stage]
|
two |