Skip to content

calculator

ASE calculator for xtb_ase

XTB

XTB(profile=None, directory='.', method='gfn2-xtb', charge=0, uhf=0, spinpol=None, **kwargs)

Bases: GenericFileIOCalculator

xTB calculator

Parameters:

  • profile (XTBProfile | None, default: None ) –

    An instantiated xtb_ase.calculator.XTBProfile object to use.

  • directory (Path | str, default: '.' ) –

    The path to the directory to run the xTB calculation in.

  • method (Literal['gfn0-xtb', 'gfn1-xtb', 'gfn2-xTB', 'gfn-ff'], default: 'gfn2-xtb' ) –

    The xTB method to use. Case-insensitive.

  • charge (int, default: 0 ) –

    The net charge of the system.

  • uhf (int, default: 0 ) –

    The number of unpaired electrons in the system.

  • spinpol (bool | None, default: None ) –

    Whether to use spin-polarized xTB. If None, spinpol will be automatically set to True if uhf > 0.

  • **kwargs

    Any additional xTB parameters to be written out to a detailed input file, e.g. in the format of scc={"temp": 500}. See https://github.com/grimme-lab/xtb/blob/main/man/xcontrol.7.adoc.

Returns:

  • None
Source code in xtb_ase/calculator.py
def __init__(
    self,
    profile: XTBProfile | None = None,
    directory: Path | str = ".",
    method: Literal["gfn0-xtb", "gfn1-xtb", "gfn2-xTB", "gfn-ff"] = "gfn2-xtb",
    charge: int = 0,
    uhf: int = 0,
    spinpol: bool | None = None,
    **kwargs,
) -> None:
    """
    Initialize the xTB calculator.

    Parameters
    ----------
    profile
        An instantiated [xtb_ase.calculator.XTBProfile][] object to use.
    directory
        The path to the directory to run the xTB calculation in.
    method
        The xTB method to use. Case-insensitive.
    charge
        The net charge of the system.
    uhf
        The number of unpaired electrons in the system.
    spinpol
        Whether to use spin-polarized xTB. If None, `spinpol` will be automatically
        set to True if `uhf` > 0.
    **kwargs
        Any additional xTB parameters to be written out to a detailed input file, e.g. in the format
        of `scc={"temp": 500}`. See https://github.com/grimme-lab/xtb/blob/main/man/xcontrol.7.adoc.

    Returns
    -------
    None
    """

    profile = profile or XTBProfile()

    profile.argv.extend(["--chrg", f"{charge}"])
    profile.argv.extend(["--uhf", f"{uhf}"])

    if spinpol is None and uhf > 0:
        profile.argv.append("--spinpol")
        if "--tblite" not in profile.argv:
            profile.argv.append("--tblite")

    if method.lower() in ["gfn0-xtb", "gfn1-xtb", "gfn2-xtb"]:
        profile.argv.extend(["--gfn", int(method[3])])
    elif method.lower() == "gfn-ff":
        profile.argv.extend(["--gfnff"])
    else:
        raise ValueError(f"Unsupported method {method}")

    if "--grad" not in profile.argv:
        profile.argv.append("--grad")

    super().__init__(
        template=_XTBTemplate(),
        profile=profile,
        directory=directory,
        parameters=kwargs,
    )

XTBProfile

XTBProfile(argv=None)

xTB profile

Parameters:

  • argv (list[str] | None, default: None ) –

    The command line arguments to the xTB executable, e.g. ["xtb", "--tblite"]. Do not specify an input file, i.e. --input (-I), or the geometry file, as these will be automatically added.

Returns:

  • None
Source code in xtb_ase/calculator.py
def __init__(self, argv: list[str] | None = None) -> None:
    """
    Initialize the xTB profile.

    Parameters
    ----------
    argv
        The command line arguments to the xTB executable, e.g. `["xtb", "--tblite"]`.
        Do not specify an input file, i.e. --input (-I), or the geometry file,
        as these will be automatically added.

    Returns
    -------
    None
    """
    default_argv = ["xtb"]
    self.argv = argv or default_argv

run

run(directory, input_filename, geom_filename, output_filename)

Run the xTB calculation.

Parameters:

  • directory (Path | str) –

    The directory where the calculation will be run.

  • input_filename (str) –

    The name of the input file present in the directory.

  • geom_filename (str) –

    The name of the coordinates file present in the directory.

  • output_filename (str) –

    The name of the log file to write to in the directory.

Returns:

  • None
Source code in xtb_ase/calculator.py
def run(
    self,
    directory: Path | str,
    input_filename: str,
    geom_filename: str,
    output_filename: str,
) -> None:
    """
    Run the xTB calculation.

    Parameters
    ----------
    directory
        The directory where the calculation will be run.
    input_filename
        The name of the input file present in the directory.
    geom_filename
        The name of the coordinates file present in the directory.
    output_filename
        The name of the log file to write to in the directory.

    Returns
    -------
    None
    """
    cmd = self.argv + ["--input", input_filename, geom_filename, "--json"]
    cmd = [str(arg) for arg in cmd]
    with open(output_filename, "w") as fd:
        check_call(cmd, stdout=fd, cwd=directory)