API¶
This covers all supported public API.
-
class
berny.
Berny
(geom, debug=False, restart=None, maxsteps=100, logger=None, **params)[source]¶ Generator that receives energy and gradients and yields the next geometry.
- Parameters
geom (
Geometry
) – geometry to start withdebug (bool) – if
True
, the generator yields debug info on receiving the energy and gradients, otherwise it yieldsNone
restart (dict) – start from a state saved from previous run using
debug=True
maxsteps (int) – abort after maximum number of steps
logger (
logging.Logger
) – alternative logger to useparams – parameters that override the
defaults
The Berny object is to be used as follows:
optimizer = Berny(geom) for geom in optimizer: # calculate energy and gradients (as N-by-3 matrix) debug = optimizer.send((energy, gradients))
-
property
converged
¶ Whether the optimized has converged.
-
property
trust
¶ Current trust radius.
-
berny.berny.
defaults
= {'dihedral': True, 'gradientmax': 0.00045, 'gradientrms': 0.00015, 'stepmax': 0.0018, 'steprms': 0.0012, 'superweakdih': False, 'trust': 0.3}¶ gradientmax
,gradientrms
,stepmax
,steprms
Convergence criteria in atomic units (“step” refers to the step in internal coordinates, assuming radian units for angles).
trust
Initial trust radius in atomic units. It is the maximum RMS of the quadratic step (see below).
dihedral
Form dihedral angles.
superweakdih
Form dihedral angles containing two or more noncovalent bonds.
-
berny.coords.
angstrom
= 1.8897261245650618¶ Can be imported directly as
berny.angstrom
.
-
berny.
optimize
(optimizer, solver, trajectory=None)[source]¶ Optimize a geometry with respect to a solver.
- Parameters
optimizer (
Generator
) – Optimizer object with the same generator interface asBerny
solver (
Generator
) –unprimed generator that receives geometry as a 2-tuple of a list of 2-tuples of the atom symbol and coordinate (as a 3-tuple), and of a list of lattice vectors (or
None
if molecule), and yields the energy and gradients (as a \(N\)-by-3 matrix or \((N+3)\)-by-3 matrix in case of a crystal geometry).See
MopacSolver
for an example.trajectory (str) – filename for the XYZ trajectory
- Returns
The optimized geometry.
The function is equivalent to:
next(solver) for geom in optimizer: energy, gradients = solver.send((list(geom), geom.lattice)) optimizer.send((energy, gradients))
Geometry operations¶
-
class
berny.
Geometry
(species, coords, lattice=None)[source]¶ Represents a single molecule or a crystal.
- Parameters
Iterating over a geometry yields 2-tuples of symbols and coordinates.
len()
returns the number of atoms in a geometry. The class supportsformat()
with the same available formats asdump()
.-
bondmatrix
(scale=1.3)[source]¶ Calculate the covalent connectedness matrix.
- Parameters
scale (float) – threshold for accepting a distance as a covalent bond
- Returns
\(b_{ij}:=R_{ij}<\text{scale}\times (R_i^\text{cov}+R_j^\text{cov})\).
-
property
cms
¶ Calculate the center of mass, \(\mathbf R_\text{CMS}\).
-
dist
(other=None)[source]¶ Alias for the first element of
dist_diff()
.
-
dist_diff
(other=None)[source]¶ Calculate distances and vectors between atoms.
- Parameters
other (
Geometry
) – calculate distances between two geometries if given or within a geometry if not- Returns
\(R_{ij}:=|\mathbf R_i-\mathbf R_j|\) and \(R_{ij\alpha}:=(\mathbf R_i)_\alpha-(\mathbf R_j)_\alpha\).
-
dump
(f, fmt)[source]¶ Save the geometry into a file.
- Parameters
f (file) – file object
fmt (str) – geometry format, one of
""
,"xyz"
,"aims"
,"mopac"
.
-
property
formula
¶ Chemical formula of the molecule or a unit cell.
-
property
inertia
¶ Calculate the moment of inertia.
\[I_{\alpha\beta}:= \sum_im_i\big(r_i^2\delta_{\alpha\beta}-(\mathbf r_i)_\alpha(\mathbf r_i)_\beta\big),\qquad \mathbf r_i=\mathbf R_i-\mathbf R_\text{CMS} \]
-
property
masses
¶ Numpy array of atomic masses.
-
rho
()[source]¶ Calculate a measure of covalentness.
- Returns
\(\rho_{ij}:=\exp\big(-R_{ij}/(R_i^\text{cov}+R_j^\text{cov})\big)\).
-
super_circum
(radius)[source]¶ Supercell dimensions such that the supercell circumsribes a sphere.
- Parameters
radius (float) – circumscribed radius in angstroms
Returns
None
when geometry is not a crystal.
-
berny.geomlib.
load
(fp, fmt)[source]¶ Read a geometry from a file object.
- Parameters
fp (file) – file object
fmt (str) – the format of the geometry file, can be one of
"xyz"
,"aims"
Returns
Geometry
.
Solvers¶
All functions in this module are coroutines that satisfy the solver interface
expected by optimize()
.