tequilahub / tequila

A High-Level Abstraction Framework for Quantum Algorithms
MIT License
369 stars 103 forks source link

fix heavy element formatting for periodictable #249

Closed jjgoings closed 2 years ago

jjgoings commented 2 years ago

Heavy elements won't work using periodictable due to a small formatting issue. For example, even after pip install periodictable, running, e.g.

import tequila as tq

geomstring="Zn 0.0 0.0 0.0"
molecule = tq.Molecule(geometry=geomstring, frozen_core=True, basis_set='cc-pvdz', backend='pyscf')

will fail with

tequila.utils.exceptions.TequilaException: can not assign atomic number to element zn
pip install periodictable will fix it

The issue lies in https://github.com/tequilahub/tequila/blob/d09a1ad6f161ee5f5b65c5ed4c83286d9973c217/src/tequila/quantumchemistry/chemistry_tools.py#L157 because you will get a TypeError: 'str' object does not support item assignment. The proposed fix is to convert to a list, make the first element uppercase, and then rejoin to str.

There is also a small issue with the return in https://github.com/tequilahub/tequila/blob/d09a1ad6f161ee5f5b65c5ed4c83286d9973c217/src/tequila/quantumchemistry/chemistry_tools.py#L159

because number is a parameter, not a callable. See, for example, the Element code here.

kottmanj commented 2 years ago

Thanks for fixing! Re-directed to devel branch to stay consistent with the changes from yesterday, and to not lose overview over changes in the next version.