Skip to content

Commit

Permalink
Add option to change xTB parameterisation version and temperature (du…
Browse files Browse the repository at this point in the history
…artegroup#252)

* etemp and gfn options for xTB

* fix tests

* update changelog
  • Loading branch information
shoubhikraj authored Mar 20, 2023
1 parent 784b579 commit 7b89cd2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
9 changes: 9 additions & 0 deletions autode/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ class XTB:
# Force constant used for harmonic restraints in constrained
# optimisations (Ha/a0)
force_constant = 2
#
# Electronic temperature for all calculations (Kelvin)
# None means unset (default), set to 300.0 to have 300K for example
electronic_temp = None
#
# Version of xTB hamiltonian parameterisation: 0,1 or 2
# corresponding to GFN0-xTB, GFN1-xTB, GFN2-xTB respectively
# When unset, uses the default
gfn_version = None

class MOPAC:
# ---------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions autode/wrappers/XTB.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def __init__(self):
)

self.force_constant = Config.XTB.force_constant
self.electronic_temp = Config.XTB.electronic_temp
self.gfn_version = Config.XTB.gfn_version

def __repr__(self):
return f"XTB(available = {self.is_available})"
Expand Down Expand Up @@ -166,6 +168,10 @@ def execute(self, calc):
"--uhf",
str(calc.molecule.mult - 1),
]
if self.electronic_temp is not None:
flags.extend(["--etemp", str(float(self.electronic_temp))])
if self.gfn_version is not None:
flags.extend(["--gfn", str(self.gfn_version)])

if isinstance(calc.input.keywords, OptKeywords):
if calc.input.keywords.max_opt_cycles is not None:
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Usability improvements/Changes
******************************
- Adds full usability of autodE on Windows, including parallelisation with :code:`loky`
- Optional timeout for graph isomorphism test in Windows, turned on by :code:`Config.use_experimental_timeout=True` (default behaviour kept for Linux/macOS)
- The electronic temperature and the version of parameterisation for xTB calculations are made configurable
- A NEB :code:`Image` now derives from a :code:`Species` superclass
- Modifies NEB :code:`Image` constructor to be formed from an image
- Defines named constructors (:code:`from_endpoints(...)`, :code:`from_list(...)`) for :code:`NEB`
Expand Down
33 changes: 32 additions & 1 deletion tests/test_wrappers/test_xtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import pytest

from autode.utils import work_in_tmp_dir
from autode.utils import work_in_tmp_dir, temporary_config
from autode.atoms import Atom
from autode.wrappers.XTB import XTB
from autode.calculations import Calculation
Expand Down Expand Up @@ -216,6 +216,8 @@ def __init__(self):
implicit_solvation_type=None,
keywords_set=XTB().keywords,
)
self.electronic_temp = XTB().electronic_temp
self.gfn_version = XTB().gfn_version

def _energy_from(self, calc: "CalculationExecutor") -> PotentialEnergy:
return XTB._energy_from(self, calc)
Expand Down Expand Up @@ -387,3 +389,32 @@ def test_xtb_cartesian_constrained_opt():
# if the coordinates are constrained then the distance should be
# close to the initial
assert abs(h2.distance(0, 1) - init_r) < 0.1


@pytest.mark.parametrize("gfn_ver,etemp", [(1, 300.0), (2, 1200.1)])
@testutils.requires_with_working_xtb_install
@work_in_tmp_dir()
def test_xtb_etemp_and_gfn_var_params_recognised(gfn_ver, etemp):

# test that the electronic_temp and gfn_version Config params are recognised

mol = Molecule(smiles="O")
with temporary_config():
Config.XTB.gfn_version = gfn_ver
Config.XTB.electronic_temp = etemp

calc = Calculation(
name="water",
molecule=mol,
method=XTB(),
keywords=XTB().keywords.sp,
)
calc.run()

assert calc.output.filename is not None
output = "".join(calc.output.file_lines)

# xTB command line flags should be printed in the output
assert f"--gfn {gfn_ver}" in output
etemp_str = str(float(etemp)) # string repr may be different
assert f"--etemp {etemp_str}" in output

0 comments on commit 7b89cd2

Please sign in to comment.