Skip to content

Commit 466ec1f

Browse files
committed
Merge pull request #140 from maximilianvz/address_issue_113
Merging coord_type into GeneralizedContractionShell Closes #140
2 parents f0ad9db + 449c21f commit 466ec1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+800
-835
lines changed

gbasis/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ def construct_array_lincomb(self, *transform, coord_type, **kwargs):
157157
Transformation matrix that will be used for linearly combining the spherical
158158
contractions.
159159
Note that multiple instances may be needed to construct the array.
160-
coord_type : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
161-
Types of the coordinate system for the contractions.
162-
If "cartesian", then all of the contractions are treated as Cartesian contractions.
163-
If "spherical", then all of the contractions are treated as spherical contractions.
164-
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
165-
coordinate type of each `GeneralizedContractionShell` instance.
160+
coord_type : list/tuple of str
161+
Types of the coordinate system for each GeneralizedContractionShell.
162+
Each entry must be one of "cartesian" or "spherical". If multiple
163+
instances of GeneralizedContractionShell are given but only one string
164+
("cartesian" or "spherical") is provided in the list/tuple, all of the
165+
contractions will be treated according to that string.
166166
kwargs : dict
167167
Other keyword arguments that will be used to construct the array.
168168

gbasis/base_four_symm.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,12 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
571571
Transformation is applied to the left.
572572
Rows correspond to the linear combinations (i.e. MO) and the columns correspond to the
573573
contractions (i.e. AO).
574-
coord_type : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
575-
Types of the coordinate system for the contractions.
576-
If "cartesian", then all of the contractions are treated as Cartesian contractions.
577-
If "spherical", then all of the contractions are treated as spherical contractions.
578-
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
579-
coordinate type of each `GeneralizedContractionShell` instance.
574+
coord_type : list/tuple of str
575+
Types of the coordinate system for each GeneralizedContractionShell.
576+
Each entry must be one of "cartesian" or "spherical". If multiple
577+
instances of GeneralizedContractionShell are given but only one string
578+
("cartesian" or "spherical") is provided in the list/tuple, all of the
579+
contractions will be treated according to that string.
580580
kwargs : dict
581581
Other keyword arguments that will be used to construct the array.
582582
These keyword arguments are passed directly to `construct_array_spherical`, which will
@@ -595,20 +595,18 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
595595
Raises
596596
------
597597
TypeError
598-
If `coord_type` is not one of "cartesian", "spherical", or a list/tuple of these
599-
strings.
598+
If `coord_type` is not a list/tuple of the strings 'cartesian' or 'spherical'.
600599
601600
"""
602-
if coord_type == "cartesian":
601+
if all(ct == "cartesian" for ct in coord_type):
603602
array = self.construct_array_cartesian(**kwargs)
604-
elif coord_type == "spherical":
603+
elif all(ct == "spherical" for ct in coord_type):
605604
array = self.construct_array_spherical(**kwargs)
606605
elif isinstance(coord_type, (list, tuple)):
607606
array = self.construct_array_mix(coord_type, **kwargs)
608607
else:
609608
raise TypeError(
610-
"`coord_type` must be one of 'cartesian', 'spherical', or a list/tuple of these "
611-
"strings."
609+
"`coord_type` must be a list/tuple of the strings 'cartesian' or 'spherical'"
612610
)
613611
array = np.tensordot(transform, array, (1, 0))
614612
array = np.tensordot(transform, array, (1, 1))

gbasis/base_one.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
257257
Transformation is applied to the left.
258258
Rows correspond to the linear combinationes (i.e. MO) and the columns correspond to the
259259
contractions (i.e. AO).
260-
coord_type : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
261-
Types of the coordinate system for the contractions.
262-
If "cartesian", then all of the contractions are treated as Cartesian contractions.
263-
If "spherical", then all of the contractions are treated as spherical contractions.
264-
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
265-
coordinate type of each GeneralizedContractionShell instance.
260+
coord_type : list/tuple of str
261+
Types of the coordinate system for each GeneralizedContractionShell.
262+
Each entry must be one of "cartesian" or "spherical". If multiple
263+
instances of GeneralizedContractionShell are given but only one string
264+
("cartesian" or "spherical") is provided in the list/tuple, all of the
265+
contractions will be treated according to that string.
266266
kwargs : dict
267267
Other keyword arguments that will be used to construct the array.
268268
These keyword arguments are passed directly to `construct_array_spherical`, which will
@@ -278,19 +278,17 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
278278
Raises
279279
------
280280
TypeError
281-
If `coord_type` is not one of "cartesian", "spherical", or a list/tuple of these
282-
strings.
281+
If `coord_type` is not a list/tuple of the strings 'cartesian' or 'spherical'.
283282
284283
"""
285-
if coord_type == "cartesian":
284+
if all(ct == "cartesian" for ct in coord_type):
286285
array = self.construct_array_cartesian(**kwargs)
287-
elif coord_type == "spherical":
286+
elif all(ct == "spherical" for ct in coord_type):
288287
array = self.construct_array_spherical(**kwargs)
289288
elif isinstance(coord_type, (list, tuple)):
290289
array = self.construct_array_mix(coord_type, **kwargs)
291290
else:
292291
raise TypeError(
293-
"`coord_type` must be one of 'cartesian', 'spherical', or a list/tuple of these "
294-
"strings."
292+
"`coord_type` must be a list/tuple of the strings 'cartesian' or 'spherical'"
295293
)
296294
return np.tensordot(transform, array, (1, 0))

gbasis/base_two_asymm.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,18 @@ def construct_array_lincomb(
386386
Array associated with the linear combinations of spherical Gaussians (LCAO's) associated
387387
with the second index.
388388
If None, then transformation is skipped.
389-
coord_type_one : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
389+
coord_type_one : list/tuple of string
390390
Types of the coordinate system for the contractions associated with the first index.
391-
If "cartesian", then all of the contractions are treated as Cartesian contractions.
392-
If "spherical", then all of the contractions are treated as spherical contractions.
393-
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
394-
coordinate type of each `GeneralizedContractionShell` instance.
395-
coord_type_two : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
391+
Each entry must be one of "cartesian" or "spherical". If multiple
392+
instances of GeneralizedContractionShell are given but only one string
393+
("cartesian" or "spherical") is provided in the list/tuple, all of the
394+
contractions will be treated according to that string.
395+
coord_type_two : list/tuple of string
396396
Types of the coordinate system for the contractions associated with the second index.
397-
If "cartesian", then all of the contractions are treated as Cartesian contractions.
398-
If "spherical", then all of the contractions are treated as spherical contractions.
399-
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
400-
coordinate type of each `GeneralizedContractionShell` instance.
397+
Each entry must be one of "cartesian" or "spherical". If multiple
398+
instances of GeneralizedContractionShell are given but only one string
399+
("cartesian" or "spherical") is provided in the list/tuple, all of the
400+
contractions will be treated according to that string.
401401
kwargs : dict
402402
Other keyword arguments that will be used to construct the array.
403403
These keyword arguments are passed directly to `construct_array_spherical`, which will
@@ -420,13 +420,16 @@ def construct_array_lincomb(
420420
Raises
421421
------
422422
TypeError
423-
If `coord_type_one` and `coord_type_two` are not one of "cartesian", "spherical", or a
424-
list/tuple of these strings.
423+
If `coord_type` is not a list/tuple of the strings 'cartesian' or 'spherical'.
425424
426425
"""
427-
if coord_type_one == "cartesian" and coord_type_two == "cartesian":
426+
if all(ct_one == "cartesian" for ct_one in coord_type_one) and all(
427+
ct_two == "cartesian" for ct_two in coord_type_two
428+
):
428429
array = self.construct_array_cartesian(**kwargs)
429-
elif coord_type_one == "spherical" and coord_type_two == "spherical":
430+
elif all(ct_one == "spherical" for ct_one in coord_type_one) and all(
431+
ct_two == "spherical" for ct_two in coord_type_two
432+
):
430433
array = self.construct_array_spherical(**kwargs)
431434
else:
432435
if coord_type_one in ["cartesian", "spherical"]:
@@ -438,8 +441,7 @@ def construct_array_lincomb(
438441
and isinstance(coord_type_two, (list, tuple))
439442
):
440443
raise TypeError(
441-
"`coord_type` must be one of 'cartesian', 'spherical', or a list/tuple of these"
442-
" strings."
444+
"`coord_type` must be a list/tuple of the strings 'cartesian' or 'spherical'"
443445
)
444446
array = self.construct_array_mix(coord_type_one, coord_type_two, **kwargs)
445447
if transform_one is not None:

gbasis/base_two_symm.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,12 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
365365
Transformation is applied to the left.
366366
Rows correspond to the linear combinations (i.e. MO) and the columns correspond to the
367367
contractions (i.e. AO).
368-
coord_type : {"cartesian", "spherical", list/tuple of "cartesian" or "spherical}
369-
Types of the coordinate system for the contractions.
370-
If "cartesian", then all of the contractions are treated as Cartesian contractions.
371-
If "spherical", then all of the contractions are treated as spherical contractions.
372-
If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the
373-
coordinate type of each `GeneralizedContractionShell` instance.
368+
coord_type : list/tuple of str
369+
Types of the coordinate system for each GeneralizedContractionShell.
370+
Each entry must be one of "cartesian" or "spherical". If multiple
371+
instances of GeneralizedContractionShell are given but only one string
372+
("cartesian" or "spherical") is provided in the list/tuple, all of the
373+
contractions will be treated according to that string.
374374
kwargs : dict
375375
Other keyword arguments that will be used to construct the array.
376376
These keyword arguments are passed directly to `construct_array_spherical`, which will
@@ -389,20 +389,18 @@ def construct_array_lincomb(self, transform, coord_type, **kwargs):
389389
Raises
390390
------
391391
TypeError
392-
If `coord_type` is not one of "cartesian", "spherical", or a list/tuple of these
393-
strings.
392+
If `coord_type` is not a list/tuple of the strings 'cartesian' or 'spherical'.
394393
395394
"""
396-
if coord_type == "cartesian":
395+
if all(ct == "cartesian" for ct in coord_type):
397396
array = self.construct_array_cartesian(**kwargs)
398-
elif coord_type == "spherical":
397+
elif all(ct == "spherical" for ct in coord_type):
399398
array = self.construct_array_spherical(**kwargs)
400399
elif isinstance(coord_type, (list, tuple)):
401400
array = self.construct_array_mix(coord_type, **kwargs)
402401
else:
403402
raise TypeError(
404-
"`coord_type` must be one of 'cartesian', 'spherical', or a list/tuple of these "
405-
"strings."
403+
"`coord_type` must be a list/tuple of the strings 'cartesian' or 'spherical'"
406404
)
407405
array = np.tensordot(transform, array, (1, 0))
408406
array = np.tensordot(transform, array, (1, 1))

gbasis/contractions.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class GeneralizedContractionShell:
9191
Contraction coefficients, :math:`\{d_{ij}\}`, of the primitives.
9292
First axis corresponds to the primitive and the second axis corresponds to the segmented
9393
contraction shell.
94+
coord_type : str
95+
Type of the coordinate system used to specify the contractions.
9496
norm_cont : np.ndarray(M, L)
9597
Normalization constants of the Cartesian contractions of different angular momentum
9698
components and segmented contraction shells.
@@ -114,7 +116,7 @@ class GeneralizedContractionShell:
114116
115117
"""
116118

117-
def __init__(self, angmom, coord, coeffs, exps):
119+
def __init__(self, angmom, coord, coeffs, exps, coord_type):
118120
r"""Initialize a GeneralizedContractionShell instance.
119121
120122
Parameters
@@ -134,13 +136,17 @@ def __init__(self, angmom, coord, coeffs, exps):
134136
dimension.
135137
exps : np.ndarray(K,)
136138
Exponents of the primitives, :math:`\{\alpha_i\}_{i=1}^K`.
139+
coord_type : str
140+
Coordinate type of the contraction. Options include "cartesian" or "c" and
141+
"spherical" or "p".
137142
138143
"""
139144
self.angmom = angmom
140145
self.coord = coord
141146
self.coeffs = coeffs
142147
self.exps = exps
143148
self.assign_norm_cont()
149+
self.coord_type = coord_type
144150

145151
@property
146152
def coord(self):
@@ -479,3 +485,48 @@ def assign_norm_cont(self):
479485

480486
self.norm_cont = np.einsum("ijij->ij", Overlap.construct_array_contraction(self, self))
481487
self.norm_cont **= -0.5
488+
489+
@property
490+
def coord_type(self):
491+
"""Return the coordinate type.
492+
493+
Returns
494+
-------
495+
coord_type : str
496+
Coordinate type of the contraction.
497+
498+
"""
499+
return self._coord_type
500+
501+
@coord_type.setter
502+
def coord_type(self, coord_type):
503+
"""Set the coordinate type.
504+
505+
Parameters
506+
----------
507+
coord_type : str
508+
Coordinate type of the contraction.
509+
510+
Raises
511+
------
512+
TypeError
513+
If `coord_type` is not a string.
514+
ValueError
515+
If `coord_type` is not one of the following:
516+
- 'c' (cartesian)
517+
- 'cartesian'
518+
- 'p' (spherical)
519+
- 'spherical'
520+
"""
521+
522+
523+
if not isinstance(coord_type, str):
524+
raise TypeError("Coordinate type must be given as a string.")
525+
if coord_type not in ["c", "cartesian", "p", "spherical"]:
526+
raise ValueError("`coord_type` is incorrectly specified. It must be either 'c' "
527+
"or 'cartesian' for Cartesian coordinates, or 'p' or 'spherical' "
528+
"for spherical coordinates.")
529+
self._coord_type = {"c": "cartesian",
530+
"cartesian": "cartesian",
531+
"spherical": "spherical",
532+
"p": "spherical"}[coord_type]

0 commit comments

Comments
 (0)