gbasis
gbasis copied to clipboard
[BUG] Transforms are computed in `construct_array_mix` methods when they are not needed
Describe the bug
The method construct_array_mix
in base_two_symm.py
, base_two_asymm.py
and base_four.py
constructs transform_*
variables when they are not needed. When the wrapper to generate the basis set does not define the transformation, this will result in an unwarranted error message. This typically happens when loading wavefunction files with IOData from file formats that always work with Cartesian shells, but there are other cases too, see example below.
A similar problem was fixed in #104 for base_one.py
.
To Reproduce
The following script (with IOData installed) generates the exception:
from importlib.resources import path
from iodata import load_one
from gbasis.wrappers import from_iodata
from gbasis.integrals.overlap import overlap_integral
with path("iodata.test.data", "he2_ghost_psi4_1.0.molden") as fn_full:
iodata = load_one(str(fn_full))
basis, coord_types = from_iodata(iodata)
olp = overlap_integral(basis, coord_type=coord_types)
print(olp)
Exception:
Traceback (most recent call last):
File "example.py", line 9, in <module>
olp = overlap_integral(basis, coord_type=coord_types)
File "/home/toon/miniconda3/envs/horton3/lib/python3.7/site-packages/gbasis/integrals/overlap.py", line 145, in overlap_integral
return Overlap(basis).construct_array_mix(coord_type)
File "/home/toon/miniconda3/envs/horton3/lib/python3.7/site-packages/gbasis/base_two_symm.py", line 304, in construct_array_mix
cont_one.angmom_components_sph,
File "/home/toon/miniconda3/envs/horton3/lib/python3.7/site-packages/gbasis/wrappers.py", line 117, in angmom_components_sph
"momentum {0}".format(self.angmom)
ValueError: Given convention does not support spherical contractions for the angular momentum 0
Expected behaviour
[[1.00000146e+00 5.95216385e-01 2.59436827e-04 4.41546274e-02]
[5.95216385e-01 1.00000000e+00 4.41546274e-02 2.14669756e-01]
[2.59436827e-04 4.41546274e-02 1.00000146e+00 5.95216385e-01]
[4.41546274e-02 2.14669756e-01 5.95216385e-01 1.00000000e+00]]
Screenshots
System Information:
- OS: Fedora 32
- Python version: 3.7.7
- NumPy version: 1.18.5
- SciPy version: 1.5.0
Additional context
The fix for this problem should be relatively easy, essentially replicating the changes to base_one.py
(and its unit tests) made in #104 in all the other base_*.py
. The unit tests do not need to make use of iodata.