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

Merging coord_type into GeneralizedContractionShell #140

Merged
merged 17 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
12 changes: 6 additions & 6 deletions gbasis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ def construct_array_lincomb(self, *transform, coord_type, **kwargs):
Transformation matrix that will be used for linearly combining the spherical
contractions.
Note that multiple instances may be needed to construct the array.
coord_type : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
Types of the coordinate system for the contractions.
If "cartesian", then all of the contractions are treated as Cartesian contractions.
If "spherical", then all of the contractions are treated as spherical contractions.
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
coordinate type of each `GeneralizedContractionShell` instance.
coord_type : list/tuple of str
Types of the coordinate system for each GeneralizedContractionShell.
Each entry must be one of "cartesian" or "spherical". If multiple
instances of GeneralizedContractionShell are given but only one string
("cartesian" or "spherical") is provided in the list/tuple, all of the
contractions will be treated according to that string.
kwargs : dict
Other keyword arguments that will be used to construct the array.

Expand Down
22 changes: 10 additions & 12 deletions gbasis/base_four_symm.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,12 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
Transformation is applied to the left.
Rows correspond to the linear combinations (i.e. MO) and the columns correspond to the
contractions (i.e. AO).
coord_type : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
Types of the coordinate system for the contractions.
If "cartesian", then all of the contractions are treated as Cartesian contractions.
If "spherical", then all of the contractions are treated as spherical contractions.
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
coordinate type of each `GeneralizedContractionShell` instance.
coord_type : list/tuple of str
Types of the coordinate system for each GeneralizedContractionShell.
Each entry must be one of "cartesian" or "spherical". If multiple
instances of GeneralizedContractionShell are given but only one string
("cartesian" or "spherical") is provided in the list/tuple, all of the
contractions will be treated according to that string.
kwargs : dict
Other keyword arguments that will be used to construct the array.
These keyword arguments are passed directly to `construct_array_spherical`, which will
Expand All @@ -592,20 +592,18 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
Raises
------
TypeError
If `coord_type` is not one of "cartesian", "spherical", or a list/tuple of these
strings.
If `coord_type` is not a list/tuple of the strings 'cartesian' or 'spherical'.

"""
if coord_type == "cartesian":
if all(ct == "cartesian" for ct in coord_type):
array = self.construct_array_cartesian(**kwargs)
elif coord_type == "spherical":
elif all(ct == "spherical" for ct in coord_type):
array = self.construct_array_spherical(**kwargs)
elif isinstance(coord_type, (list, tuple)):
array = self.construct_array_mix(coord_type, **kwargs)
else:
raise TypeError(
"`coord_type` must be one of 'cartesian', 'spherical', or a list/tuple of these "
"strings."
"`coord_type` must be a list/tuple of the strings 'cartesian' or 'spherical'"
)
array = np.tensordot(transform, array, (1, 0))
array = np.tensordot(transform, array, (1, 1))
Expand Down
22 changes: 10 additions & 12 deletions gbasis/base_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
Transformation is applied to the left.
Rows correspond to the linear combinationes (i.e. MO) and the columns correspond to the
contractions (i.e. AO).
coord_type : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
Types of the coordinate system for the contractions.
If "cartesian", then all of the contractions are treated as Cartesian contractions.
If "spherical", then all of the contractions are treated as spherical contractions.
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
coordinate type of each GeneralizedContractionShell instance.
coord_type : list/tuple of str
Types of the coordinate system for each GeneralizedContractionShell.
Each entry must be one of "cartesian" or "spherical". If multiple
instances of GeneralizedContractionShell are given but only one string
("cartesian" or "spherical") is provided in the list/tuple, all of the
contractions will be treated according to that string.
kwargs : dict
Other keyword arguments that will be used to construct the array.
These keyword arguments are passed directly to `construct_array_spherical`, which will
Expand All @@ -278,19 +278,17 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
Raises
------
TypeError
If `coord_type` is not one of "cartesian", "spherical", or a list/tuple of these
strings.
If `coord_type` is not a list/tuple of the strings 'cartesian' or 'spherical'.

"""
if coord_type == "cartesian":
if all(ct == "cartesian" for ct in coord_type):
array = self.construct_array_cartesian(**kwargs)
elif coord_type == "spherical":
elif all(ct == "spherical" for ct in coord_type):
array = self.construct_array_spherical(**kwargs)
elif isinstance(coord_type, (list, tuple)):
array = self.construct_array_mix(coord_type, **kwargs)
else:
raise TypeError(
"`coord_type` must be one of 'cartesian', 'spherical', or a list/tuple of these "
"strings."
"`coord_type` must be a list/tuple of the strings 'cartesian' or 'spherical'"
)
return np.tensordot(transform, array, (1, 0))
34 changes: 18 additions & 16 deletions gbasis/base_two_asymm.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,18 +384,18 @@ def construct_array_lincomb(
Array associated with the linear combinations of spherical Gaussians (LCAO's) associated
with the second index.
If None, then transformation is skipped.
coord_type_one : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
coord_type_one : list/tuple of string
Types of the coordinate system for the contractions associated with the first index.
If "cartesian", then all of the contractions are treated as Cartesian contractions.
If "spherical", then all of the contractions are treated as spherical contractions.
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
coordinate type of each `GeneralizedContractionShell` instance.
coord_type_two : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
Each entry must be one of "cartesian" or "spherical". If multiple
instances of GeneralizedContractionShell are given but only one string
("cartesian" or "spherical") is provided in the list/tuple, all of the
contractions will be treated according to that string.
coord_type_two : list/tuple of string
Types of the coordinate system for the contractions associated with the second index.
If "cartesian", then all of the contractions are treated as Cartesian contractions.
If "spherical", then all of the contractions are treated as spherical contractions.
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
coordinate type of each `GeneralizedContractionShell` instance.
Each entry must be one of "cartesian" or "spherical". If multiple
instances of GeneralizedContractionShell are given but only one string
("cartesian" or "spherical") is provided in the list/tuple, all of the
contractions will be treated according to that string.
kwargs : dict
Other keyword arguments that will be used to construct the array.
These keyword arguments are passed directly to `construct_array_spherical`, which will
Expand All @@ -418,13 +418,16 @@ def construct_array_lincomb(
Raises
------
TypeError
If `coord_type_one` and `coord_type_two` are not one of "cartesian", "spherical", or a
list/tuple of these strings.
If `coord_type` is not a list/tuple of the strings 'cartesian' or 'spherical'.

"""
if coord_type_one == "cartesian" and coord_type_two == "cartesian":
if all(ct_one == "cartesian" for ct_one in coord_type_one) and all(
ct_two == "cartesian" for ct_two in coord_type_two
):
array = self.construct_array_cartesian(**kwargs)
elif coord_type_one == "spherical" and coord_type_two == "spherical":
elif all(ct_one == "spherical" for ct_one in coord_type_one) and all(
ct_two == "spherical" for ct_two in coord_type_two
):
array = self.construct_array_spherical(**kwargs)
else:
if coord_type_one in ["cartesian", "spherical"]:
Expand All @@ -436,8 +439,7 @@ def construct_array_lincomb(
and isinstance(coord_type_two, (list, tuple))
):
raise TypeError(
"`coord_type` must be one of 'cartesian', 'spherical', or a list/tuple of these"
" strings."
"`coord_type` must be a list/tuple of the strings 'cartesian' or 'spherical'"
)
array = self.construct_array_mix(coord_type_one, coord_type_two, **kwargs)
if transform_one is not None:
Expand Down
22 changes: 10 additions & 12 deletions gbasis/base_two_symm.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,12 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
Transformation is applied to the left.
Rows correspond to the linear combinations (i.e. MO) and the columns correspond to the
contractions (i.e. AO).
coord_type : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
Types of the coordinate system for the contractions.
If "cartesian", then all of the contractions are treated as Cartesian contractions.
If "spherical", then all of the contractions are treated as spherical contractions.
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
coordinate type of each `GeneralizedContractionShell` instance.
coord_type : list/tuple of str
Types of the coordinate system for each GeneralizedContractionShell.
Each entry must be one of "cartesian" or "spherical". If multiple
instances of GeneralizedContractionShell are given but only one string
("cartesian" or "spherical") is provided in the list/tuple, all of the
contractions will be treated according to that string.
kwargs : dict
Other keyword arguments that will be used to construct the array.
These keyword arguments are passed directly to `construct_array_spherical`, which will
Expand All @@ -388,20 +388,18 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
Raises
------
TypeError
If `coord_type` is not one of "cartesian", "spherical", or a list/tuple of these
strings.
If `coord_type` is not a list/tuple of the strings 'cartesian' or 'spherical'.

"""
if coord_type == "cartesian":
if all(ct == "cartesian" for ct in coord_type):
array = self.construct_array_cartesian(**kwargs)
elif coord_type == "spherical":
elif all(ct == "spherical" for ct in coord_type):
array = self.construct_array_spherical(**kwargs)
elif isinstance(coord_type, (list, tuple)):
array = self.construct_array_mix(coord_type, **kwargs)
else:
raise TypeError(
"`coord_type` must be one of 'cartesian', 'spherical', or a list/tuple of these "
"strings."
"`coord_type` must be a list/tuple of the strings 'cartesian' or 'spherical'"
)
array = np.tensordot(transform, array, (1, 0))
array = np.tensordot(transform, array, (1, 1))
Expand Down
53 changes: 52 additions & 1 deletion gbasis/contractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class GeneralizedContractionShell:
Contraction coefficients, :math:`\{d_{ij}\}`, of the primitives.
First axis corresponds to the primitive and the second axis corresponds to the segmented
contraction shell.
coord_type : str
Type of the coordinate system used to specify the contractions.
norm_cont : np.ndarray(M, L)
Normalization constants of the Cartesian contractions of different angular momentum
components and segmented contraction shells.
Expand All @@ -114,7 +116,7 @@ class GeneralizedContractionShell:

"""

def __init__(self, angmom, coord, coeffs, exps):
def __init__(self, angmom, coord, coeffs, exps, coord_type="p"):
r"""Initialize a GeneralizedContractionShell instance.

Parameters
Expand All @@ -135,13 +137,17 @@ def __init__(self, angmom, coord, coeffs, exps):
dimension.
exps : np.ndarray(K,)
Exponents of the primitives, :math:`\{\alpha_i\}_{i=1}^K`.
coord_type : str, optional
Coordinate type of the contraction. Options include "cartesian" or "c" and
"spherical" or "p".

"""
self.angmom = angmom
self.coord = coord
self.coeffs = coeffs
self.exps = exps
self.assign_norm_cont()
self.coord_type = coord_type

@property
def coord(self):
Expand Down Expand Up @@ -479,3 +485,48 @@ def assign_norm_cont(self):

self.norm_cont = np.einsum("ijij->ij", Overlap.construct_array_contraction(self, self))
self.norm_cont **= -0.5

@property
def coord_type(self):
"""Return the coordinate type.

Returns
-------
coord_type : str
Coordinate type of the contraction.

"""
return self._coord_type

@coord_type.setter
def coord_type(self, coord_type):
"""Set the coordinate type.

Parameters
----------
coord_type : str
Coordinate type of the contraction.

Raises
------
TypeError
If `coord_type` is not a string.
ValueError
If `coord_type` is not one of the following:
- 'c' (cartesian)
- 'cartesian'
- 'p' (spherical)
- 'spherical'
"""


if not isinstance(coord_type, str):
raise TypeError("Coordinate type must be given as a string.")
if coord_type not in ["c", "cartesian", "p", "spherical"]:
raise ValueError("`coord_type` is incorrectly specified. It must be either 'c' "
"or 'cartesian' for Cartesian coordinates, or 'p' or 'spherical' "
"for spherical coordinates.")
self._coord_type = {"c": "cartesian",
"cartesian": "cartesian",
"spherical": "spherical",
"p": "spherical"}[coord_type]
Loading