Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend screening overlap to IOData wrapper #171

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gbasis/contractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(
"spherical" or "p".
icenter : np.int64 or None (optional)
Index for the atomic center for the contraction
ovr_tol : float
tol : float
Tolerance used in overlap screening.
ovr_screen : boolean
Flag used for activating overlap screening.
Expand Down
2 changes: 1 addition & 1 deletion gbasis/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def make_contractions(basis_dict, atoms, coords, coord_types, tol=1e-20, overlap
if not isinstance(tol, float):
raise TypeError("Tolerance must be provided as a float.")
if not isinstance(overlap, bool):
raise TypeError("Tolerance must be provided as True or False.")
raise TypeError("Overlap must be provided as True or False.")
if len(atoms) != coords.shape[0]:
raise ValueError("Number of atoms must be equal to the number of rows in the coordinates.")

Expand Down
12 changes: 11 additions & 1 deletion gbasis/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import numpy as np


def from_iodata(mol):
def from_iodata(mol, tol=1e-20, overlap=False):
"""Return basis set stored within the `IOData` instance in `iodata`.
Parameters
----------
mol : iodata.iodata.IOData
`IOData` instance from `iodata` module.
tol : float
Tolerance used in overlap screening.
overlap : bool
Flag for performing overlap screening between contractions.
Returns
-------
Expand Down Expand Up @@ -114,6 +118,10 @@ def angmom_components_sph(self):
"Only L2 normalization scheme is supported in `gbasis`. Given `IOData` instance uses "
"primitive normalization scheme, {}".format(molbasis.primitive_normalization)
)
if not isinstance(tol, float):
raise TypeError("Tolerance must be provided as a float.")
if not isinstance(overlap, bool):
raise TypeError("Overlap must be provided as True or False.")

basis = []
for shell in molbasis.shells:
Expand All @@ -133,6 +141,8 @@ def angmom_components_sph(self):
shell.exponents,
shell.kinds[0],
icenter=shell.icenter,
tol=tol,
ovr_screen=overlap,
)
)

Expand Down
31 changes: 31 additions & 0 deletions tests/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def test_from_iodata():
coord_types = [type for type in [shell.coord_type for shell in basis]]

assert coord_types == ["cartesian"] * 5
assert basis[0].ovr_screen == False
assert basis[0].ovr_tol == 1e-20
assert all(isinstance(i, GeneralizedContractionShell) for i in basis)
assert basis[0].angmom == 0
assert np.allclose(basis[0].coord, mol.atcoords[0])
Expand All @@ -28,6 +30,8 @@ def test_from_iodata():
assert np.allclose(basis[0].norm_cont, 1.0)

assert basis[1].angmom == 0
assert basis[1].ovr_screen == False
assert basis[1].ovr_tol == 1e-20
assert np.allclose(basis[1].coord, mol.atcoords[0])
assert np.allclose(basis[1].exps, np.array([5.033151319, 1.169596125, 0.3803889600]))
assert np.allclose(
Expand All @@ -36,6 +40,8 @@ def test_from_iodata():
assert np.allclose(basis[1].norm_cont, 1.0)

assert basis[2].angmom == 1
assert basis[2].ovr_screen == False
assert basis[2].ovr_tol == 1e-20
assert np.allclose(basis[2].coord, mol.atcoords[0])
assert np.allclose(basis[2].exps, np.array([5.033151319, 1.169596125, 0.3803889600]))
assert np.allclose(
Expand All @@ -44,6 +50,8 @@ def test_from_iodata():
assert np.allclose(basis[2].norm_cont, 1.0)

assert basis[3].angmom == 0
assert basis[3].ovr_screen == False
assert basis[3].ovr_tol == 1e-20
assert np.allclose(basis[3].coord, mol.atcoords[1])
assert np.allclose(basis[3].exps, np.array([3.425250914, 0.6239137298, 0.1688554040]))
assert np.allclose(
Expand All @@ -52,6 +60,8 @@ def test_from_iodata():
assert np.allclose(basis[3].norm_cont, 1.0)

assert basis[4].angmom == 0
assert basis[4].ovr_screen == False
assert basis[4].ovr_tol == 1e-20
assert np.allclose(basis[4].coord, mol.atcoords[2])
assert np.allclose(basis[4].exps, np.array([3.425250914, 0.6239137298, 0.1688554040]))
assert np.allclose(
Expand Down Expand Up @@ -114,6 +124,27 @@ def test_from_iodata():
basis, coord_types = from_iodata(mol)


def test_from_iodata_ovlp():
"""Test gbasis.wrapper.from_iodata only for the ovr_screen and tol attributes"""
pytest.importorskip("iodata")
from iodata import load_one

mol = load_one(find_datafile("data_iodata_water_sto3g_hf_g03.fchk"))

basis = from_iodata(mol, tol=0.001, overlap=True)

assert basis[0].ovr_screen == True
assert basis[0].ovr_tol == 0.001
assert basis[1].ovr_screen == True
assert basis[1].ovr_tol == 0.001
assert basis[2].ovr_screen == True
assert basis[2].ovr_tol == 0.001
assert basis[3].ovr_screen == True
assert basis[3].ovr_tol == 0.001
assert basis[4].ovr_screen == True
assert basis[4].ovr_tol == 0.001


def test_from_pyscf():
"""Test gbasis.wrapper.from_pyscf."""
pytest.importorskip("pyscf")
Expand Down
Loading