Skip to content

Commit

Permalink
Added alternative method handling for xtb
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelRobidas committed Feb 7, 2023
1 parent bc3344d commit b1731c5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ccinput/packages/xtb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from ccinput.constants import CalcType, ATOMIC_NUMBER, LOWERCASE_ATOMIC_SYMBOLS
from ccinput.utilities import get_solvent
from ccinput.utilities import get_solvent, get_method
from ccinput.exceptions import InvalidParameter, ImpossibleCalculation


Expand All @@ -17,6 +17,14 @@ class XtbCalculation:
CalcType.CONSTR_CONF_SEARCH: "crest",
}

GFN_KEYWORDS = {
"gfn2-xtb": "",
"gfn1-xtb": "--gfn 1 ",
"gfn0-xtb": "--gfn 0 ",
"gfn-ff": "--gfnff ",
"gfn2-xtb//gfn-ff": "--gfn2gfnff ",
}

def __init__(self, calc):
self.calc = calc
self.program = ""
Expand Down Expand Up @@ -50,6 +58,17 @@ def get_output_name(self):
return self.calc.name + ".xyz"

def handle_parameters(self):
method = get_method(self.calc.parameters.method, "xtb")

if method not in self.GFN_KEYWORDS:
raise InvalidParameter(
f"Unknown method for xtb: {self.calc.parameters.method}"
)

method_keyword = self.GFN_KEYWORDS[method]
if method_keyword != "":
self.main_command += method_keyword

if self.calc.parameters.solvent != "":
if (
self.calc.parameters.solvation_radii != ""
Expand Down
28 changes: 28 additions & 0 deletions ccinput/tests/test_xtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,20 @@ def test_gfn1(self):

self.assertTrue(self.is_equivalent(REF, xtb.command))

def test_gfn1_method(self):
params = {
"type": "Single-Point Energy",
"method": "gfn0",
"file": "ethanol.xyz",
"software": "xtb",
}

xtb = self.generate_calculation(**params)

REF = "xtb ethanol.xyz --gfn 0"

self.assertTrue(self.is_equivalent(REF, xtb.command))

def test_gfn2(self):
params = {
"type": "Single-Point Energy",
Expand Down Expand Up @@ -725,6 +739,20 @@ def test_gfnff(self):

self.assertTrue(self.is_equivalent(REF, xtb.command))

def test_gfnff_method(self):
params = {
"type": "Single-Point Energy",
"file": "ethanol.xyz",
"software": "xtb",
"method": "gfnff",
}

xtb = self.generate_calculation(**params)

REF = "xtb ethanol.xyz --gfnff"

self.assertTrue(self.is_equivalent(REF, xtb.command))

def test_unavailable_calc_type(self):
params = {
"type": "TS Optimisation",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
requires = [
"setuptools>=42",
"wheel",
"versioneer-518",
]
build-backend = "setuptools.build_meta"

0 comments on commit b1731c5

Please sign in to comment.