Optimisation¶
UFF4MOF geometry optimisation via gulp_setup's atom-typing backend:
cage_isomer_builder.utils.optimise.
For organic molecules the energy matches RDKit's UFF implementation, term by term. The tests check this on 16 molecules.
UFF4MOF geometry optimisation, built directly from an explicit bond-order matrix rather than distances alone.
Unlike GFN-xTB (see :mod:cage_isomer_builder.utils.tblite_optimise), UFF is
a classical, topology-based force field: every energy term (bond, angle,
torsion, van der Waals) is enumerated from the bond matrix and an explicit
per-atom UFF type name, so the intended connectivity from the STK-constructed
cage is respected exactly even when interatomic distances are atypical
(bulky multi-atom nodes, expanded cages, ...). xTB needs no bond matrix,
but it also cannot be held to one.
UFF4MOFCalculator evaluates energies and forces with OpenMM
(openmm.CustomBondForce / CustomAngleForce / CustomTorsionForce
for bond, angle and torsion terms, CustomCompoundBondForce for the
out-of-plane inversion term, and CustomNonbondedForce for van der Waals
and Coulomb beyond 1-3 neighbours), using the combining rules in
:mod:cage_isomer_builder.utils.uff4mof_params. The energy matches RDKit's
UFF implementation for organic molecules (see tests/test_uff4mof_backend.py).
UFF4MOFCalculator ¶
UFF4MOFCalculator(bond_matrix, mmtypes, uff_db, charges=None, platform=None, precision='mixed', **kwargs)
Bases: Calculator
ASE Calculator evaluating the UFF4MOF energy/forces via OpenMM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bond_matrix
|
(ndarray, shape(n_atoms, n_atoms))
|
Symmetric bond-order matrix (0 = no bond). |
required |
mmtypes
|
sequence of str
|
UFF4MOF type name for each atom (e.g. |
required |
uff_db
|
dict[str, UFFAtomParams]
|
Parameter table from
:func: |
required |
charges
|
(ndarray, shape(n_atoms))
|
Fixed partial charges (elementary charges). When given, a Coulomb
term |
None
|
platform
|
str
|
OpenMM platform name ("Reference", "CPU", "OpenCL", "CUDA"). Defaults to the fastest one available. |
None
|
precision
|
str
|
Precision for platforms that support it (OpenCL, CUDA): "single", "mixed" or "double". "mixed" computes forces in single precision and adds them up in double precision. The Reference platform is always double precision. |
"mixed"
|
Examples:
>>> import numpy as np
>>> from ase.build import molecule
>>> methane = molecule("CH4")
>>> bonds = np.zeros((5, 5))
>>> bonds[0, 1:] = bonds[1:, 0] = 1.0 # four C-H bonds
>>> from gulp_setup.mmanalysis import analyze_mm
>>> from cage_isomer_builder.utils.optimise import UFF4MOFCalculator
>>> from cage_isomer_builder.utils.uff4mof_params import load_uff4mof_db
>>> _, types = analyze_mm(methane, bond_order=bonds)
>>> methane.calc = UFF4MOFCalculator(bonds, types, load_uff4mof_db())
>>> [str(t) for t in types], methane.get_forces().shape
(['C_3', 'H_', 'H_', 'H_', 'H_'], (5, 3))
Source code in cage_isomer_builder/utils/optimise.py
calculate ¶
Evaluate the UFF4MOF energy (eV) and forces (eV/Angstrom) with OpenMM (ASE calculator interface).
Examples:
>>> import numpy as np
>>> from ase.build import molecule
>>> water = molecule("H2O")
>>> bonds = np.array([[0, 1, 1], [1, 0, 0], [1, 0, 0]], dtype=float)
>>> from gulp_setup.mmanalysis import analyze_mm
>>> from cage_isomer_builder.utils.optimise import UFF4MOFCalculator
>>> from cage_isomer_builder.utils.uff4mof_params import load_uff4mof_db
>>> _, types = analyze_mm(water, bond_order=bonds)
>>> water.calc = UFF4MOFCalculator(bonds, types, load_uff4mof_db())
>>> isinstance(water.get_potential_energy(), float) # calls calculate()
True
Source code in cage_isomer_builder/utils/optimise.py
run_uff4mof_optimisation ¶
run_uff4mof_optimisation(atoms, bond_matrix, fmax: float = 0.05, steps: int = 500, optimizer_cls=None, trajectory: Optional[str] = None, charges: Optional[ndarray] = None, logfile: Optional[str] = '-')
Relax a molecular geometry with ASE using a UFF4MOF (OpenMM) calculator.
UFF atom types are assigned automatically from bond_matrix via
:func:gulp_setup.mmanalysis.analyze_mm (a heuristic cost function over
local coordination number, angle and radius); the bond matrix is used as
given, never re-derived from the geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Starting geometry. Any constraint already set on |
required |
bond_matrix
|
(ndarray, shape(len(atoms), len(atoms)))
|
Symmetric bond-order matrix, e.g. from
:func: |
required |
fmax
|
float
|
Force convergence threshold in eV/Angstrom. |
0.05
|
steps
|
int
|
Maximum number of optimisation steps. |
500
|
optimizer_cls
|
ASE optimizer class
|
Any ASE |
None
|
trajectory
|
str
|
File path for an ASE |
None
|
charges
|
(ndarray, shape(len(atoms)))
|
Fixed partial charges, passed to :class: |
None
|
logfile
|
str or None
|
Where the optimiser writes its step log: |
"-"
|
Returns:
| Type | Description |
|---|---|
Atoms
|
Optimised structure (a copy; the input |
Examples:
>>> import numpy as np
>>> from ase.build import molecule
>>> methane = molecule("CH4")
>>> bonds = np.zeros((5, 5))
>>> bonds[0, 1:] = bonds[1:, 0] = 1.0 # four C-H bonds
>>> from cage_isomer_builder.utils.optimise import run_uff4mof_optimisation
>>> relaxed = run_uff4mof_optimisation(methane, bonds, logfile=None)
>>> round(float(relaxed.get_distance(0, 1)), 2), round(float(relaxed.get_angle(1, 0, 2)), 1)
(1.11, 109.5)
Source code in cage_isomer_builder/utils/optimise.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |