xTB (tblite)¶
GFN-xTB charges and optimisation through the optional tblite package.
Charges¶
tblite_available ¶
require_tblite ¶
Raise a clear ImportError if tblite is not installed.
Examples:
>>> from cage_isomer_builder.utils.tblite_charges import require_tblite
>>> require_tblite() # returns quietly when tblite is installed, else ImportError
Source code in cage_isomer_builder/utils/tblite_charges.py
predict_tblite_charges ¶
predict_tblite_charges(atoms: Atoms, method: str = DEFAULT_METHOD, charge: float = 0.0) -> np.ndarray
Predict per-atom partial charges for a non-periodic structure via tblite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Structure to charge. Atom order is preserved in the returned array. |
required |
method
|
str
|
tblite xTB Hamiltonian to use (e.g. "GFN1-xTB", "GFN2-xTB"). |
"GFN2-xTB"
|
charge
|
float
|
Total charge of the structure. |
0.0
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(len(atoms)))
|
Per-atom partial charges (elementary charge units), neutralised to
sum to exactly |
Examples:
>>> from ase.build import molecule
>>> from cage_isomer_builder.utils.tblite_charges import predict_tblite_charges
>>> q = predict_tblite_charges(molecule("H2O")) # needs tblite
>>> bool(q[0] < 0 < q[1]), round(float(q.sum()), 6) # O negative, neutral overall
(True, 0.0)
Source code in cage_isomer_builder/utils/tblite_charges.py
Optimisation¶
run_tblite_optimisation ¶
run_tblite_optimisation(atoms: Atoms, fmax: float = 0.05, steps: int = 500, optimizer_cls=None, trajectory: Optional[str] = None, charge: float = 0.0, method: str = DEFAULT_METHOD, logfile: Optional[str] = '-') -> tuple[Atoms, np.ndarray]
Relax a molecular geometry with ASE using a GFN-xTB (tblite) calculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Starting geometry. Any constraint already set on |
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
|
charge
|
float
|
Total charge of the structure. |
0.0
|
method
|
str
|
tblite xTB Hamiltonian to use (e.g. "GFN1-xTB", "GFN2-xTB"). |
"GFN2-xTB"
|
logfile
|
str or None
|
Where the optimiser writes its step log: |
"-"
|
Returns:
| Type | Description |
|---|---|
Atoms
|
Optimised structure (a copy; the input |
(ndarray, shape(len(atoms)))
|
Per-atom partial charges from the final electronic structure, obtained as a byproduct of the last energy/force evaluation. |
Examples:
>>> from ase.build import molecule
>>> from cage_isomer_builder.utils.tblite_optimise import run_tblite_optimisation
>>> relaxed, charges = run_tblite_optimisation(molecule("H2O"), logfile=None) # needs tblite
>>> round(float(relaxed.get_distance(0, 1)), 2), charges.shape
(0.96, (3,))