Using the Skala functional in PySCF#

The Skala functional can be used in PySCF by creating a new Kohn-Sham calculator based on the SkalaKS constructor. This allows to perform self-consistent field calculations with most of the features available in PySCF, such as density fitting and Newton’s method.

from pyscf import gto

from skala.pyscf import SkalaKS
/home/runner/micromamba/envs/skala/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

The Kohn-Sham calculator for the Skala functional is created from a regular PySCF molecule object. By specifying the xc parameter as "skala", the Skala functional is automatically loaded and used for the calculations.

mol = gto.M(
    atom="""H 0 0 0; H 0 0 1.4""",
    basis="def2-tzvp",
)
ks = SkalaKS(mol, xc="skala")
ks.kernel()

print(ks.dump_scf_summary())
converged SCF energy = -1.07091605077037
**** SCF Summaries ****
Total Energy =                          -1.070916050770366
Nuclear Repulsion Energy =               0.377654773327513
One-electron Energy =                   -1.897310625832218
Two-electron Coulomb Energy =            0.997543910495160
DFT Exchange-Correlation Energy =       -0.548804108760821
Empirical Dispersion Energy =           -0.000328948758201
None

Note that using the Skala functional will automatically enable the D3 dispersion correction, which is a part of the Skala functional. To disable the D3 correction, you can pass the with_dftd3 parameter as False when creating the Kohn-Sham calculator.

The Skala functional can be used with density fitting by calling the density_fit() method on the Kohn-Sham calculator or by setting the with_density_fit parameter to True when creating the calculator. This will set up the necessary integrals and approximations for efficient calculations.

mol = gto.M(
    atom="""H 0 0 0; H 0 0 1.4""",
    basis="def2-tzvp",
)
ks = SkalaKS(mol, xc="skala", with_density_fit=True)
ks.kernel()

print(ks.dump_scf_summary())
converged SCF energy = -1.07106374062215
**** SCF Summaries ****
Total Energy =                          -1.071063740622152
Nuclear Repulsion Energy =               0.377654773327513
One-electron Energy =                   -1.897672542527312
Two-electron Coulomb Energy =            0.998071986843154
DFT Exchange-Correlation Energy =       -0.549117958265507
Empirical Dispersion Energy =           -0.000328948758201
None
Overwritten attributes  Gradients nuc_grad_method  of <class 'pyscf.df.df_jk.DFSkalaRKS'>

For challenging to converge systems, the Newton’s method can be used by calling the newton() method on the Kohn-Sham calculator. Note, that you need to call density_fit() before using Newton’s method, to apply the density fitting to the Kohn-Sham calculator. The calculator will automatically use the density fitting integrals for the Newton’s method if the with_density_fit and with_newton parameters are set to True.

mol = gto.M(
    atom="""H 0 0 0; H 0 0 1.4""",
    basis="def2-tzvp",
)
ks = SkalaKS(mol, xc="skala", with_density_fit=True, with_newton=True)
ks.kernel()

print(ks.dump_scf_summary())
converged SCF energy = -1.07106373952623
**** SCF Summaries ****
Total Energy =                          -1.071063739526230
Nuclear Repulsion Energy =               0.377654773327513
One-electron Energy =                   -1.897671245569782
Two-electron Coulomb Energy =            0.998068851275272
DFT Exchange-Correlation Energy =       -0.549116118559232
Empirical Dispersion Energy =           -0.000328948758201
None
Overwritten attributes  Gradients nuc_grad_method  of <class 'pyscf.soscf.newton_ah.SecondOrderDFSkalaRKS'>

Using the Skala functional in GPU4PySCF#

The Skala functional can also be used in GPU4PySCF with an appropriate PyTorch CUDA version by creating a new Kohn-Sham calculator based on the SkalaKS constructor from the skala.gpu4pyscf.

from pyscf import gto

from skala.gpu4pyscf import SkalaKS

mol = gto.M(
    atom="""H 0 0 0; H 0 0 1.4""",
    basis="def2-tzvp",
)
ks = SkalaKS(mol, xc="skala")
ks.kernel()

print(ks.dump_scf_summary())
---------------------------------------------------------------------------
Skipped                                   Traceback (most recent call last)
Cell In[5], line 3
      1 from pyscf import gto
----> 3 from skala.gpu4pyscf import SkalaKS
      5 mol = gto.M(
      6     atom="""H 0 0 0; H 0 0 1.4""",
      7     basis="def2-tzvp",
      8 )
      9 ks = SkalaKS(mol, xc="skala")

File ~/work/skala/skala/src/skala/gpu4pyscf/__init__.py:18
     15 if not torch.cuda.is_available() and find_spec("pytest") is not None:
     16     import pytest
---> 18     pytest.skip(
     19         "Skipping gpu4pyscf doctests, because CUDA is not available.",
     20         allow_module_level=True,
     21     )
     23 try:
     24     import cupy  # noqa: F401

File ~/micromamba/envs/skala/lib/python3.12/site-packages/_pytest/outcomes.py:139, in _Skip.__call__(self, reason, allow_module_level)
    137 def __call__(self, reason: str = "", allow_module_level: bool = False) -> NoReturn:
    138     __tracebackhide__ = True
--> 139     raise Skipped(msg=reason, allow_module_level=allow_module_level)

Skipped: Skipping gpu4pyscf doctests, because CUDA is not available.