Skip to content

Commit

Permalink
Add option to set the xtb_path
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
marcelmbn committed Aug 16, 2024
1 parent 06057c0 commit 5a007ea
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions mindlessgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ max_num_atoms = 100
max_frag_cycles = 100

[xtb]
xtb_path = "/path/to/xtb"
# TODO
# Specific configurations for the XTB engine (if needed)
# xtb_option_1 = "value1"
Expand Down
11 changes: 8 additions & 3 deletions src/mindlessgen/cli/cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ def cli_parser(argv: Sequence[str] | None = None) -> dict:
required=False,
help="Maximum number of fragment optimization cycles.",
)
# XTB specific arguments
# TODO: Add XTB specific arguments
# xTB specific arguments
parser.add_argument(
"--xtb-path",
type=str,
required=False,
help="Path to the xTB binary.",
)
# ORCA specific arguments
# TODO: Add ORCA specific arguments
args = parser.parse_args(argv)
Expand All @@ -101,7 +106,7 @@ def cli_parser(argv: Sequence[str] | None = None) -> dict:
"max_num_atoms": args_dict["max_num_atoms"],
}
# XTB specific arguments
rev_args_dict["xtb"] = {}
rev_args_dict["xtb"] = {"xtb_path": args_dict["xtb_path"]}
# ORCA specific arguments
rev_args_dict["orca"] = {}

Expand Down
2 changes: 1 addition & 1 deletion src/mindlessgen/generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def generator(config: ConfigManager) -> tuple[Molecule | None, int]:

if config.general.engine == "xtb":
try:
xtb_path = get_xtb_path(["xtb_dev", "xtb"])
xtb_path = get_xtb_path(config.xtb.xtb_path)
if not xtb_path:
raise ImportError("xtb not found.")
except ImportError as e:
Expand Down
17 changes: 17 additions & 0 deletions src/mindlessgen/prog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class XTBConfig(BaseConfig):

def __init__(self):
self._xtb_option: str = "dummy"
self._xtb_path: str | Path = "xtb"

def get_identifier(self) -> str:
return "xtb"
Expand All @@ -230,6 +231,22 @@ def xtb_option(self, xtb_option: str):
raise TypeError("xtb_option should be a string.")
self._xtb_option = xtb_option

@property
def xtb_path(self):
"""
Get the xtb path.
"""
return self._xtb_path

@xtb_path.setter
def xtb_path(self, xtb_path: str | Path):
"""
Set the xtb path.
"""
if not isinstance(xtb_path, str | Path):
raise TypeError("xtb_path should be a string.")
self._xtb_path = xtb_path


class ORCAConfig(BaseConfig):
"""
Expand Down
16 changes: 11 additions & 5 deletions src/mindlessgen/qm/xtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,21 @@ def run(self, temp_path: Path, arguments: list[str]) -> tuple[str, str, int]:
return xtb_log_out, xtb_log_err, e.returncode


def get_xtb_path(binary_names: list[str]) -> Path | None:
def get_xtb_path(binary_name: str | Path | None = None) -> Path:
"""
Get the path to the xtb binary based on different possible names
that are searched for in the PATH.
"""
default_xtb_names: list[str | Path] = ["xtb", "xtb_dev"]
# put binary name at the beginning of the lixt to prioritize it
if binary_name is not None:
binary_names = [binary_name] + default_xtb_names
else:
binary_names = default_xtb_names
# Get xtb path from 'which xtb' command
for binary_name in binary_names:
which_xtb = shutil.which(binary_name)
for binpath in binary_names:
which_xtb = shutil.which(binpath)
if which_xtb:
xtb_path = Path(which_xtb)
xtb_path = Path(which_xtb).resolve()
return xtb_path
raise ImportError("'xtb' or 'xtb_dev' not found.")
raise ImportError("'xtb' binary could not be found.")

0 comments on commit 5a007ea

Please sign in to comment.