iodata.convert module

Functions to convert IOData-related objects.

This module includes the lower-level implementations to the functions in the prepare module. The functions in this module can be used without writing data to files. Most of them are used by the prepare module.

convert_conventions(molbasis, new_conventions, reverse=False)[source]

Return a permutation vector and sign changes to convert from 1 to 2.

The transformation from molbasis.convention to the new convention can be done applying the results of this function as follows:

vector2 = vector1[permutation]*signs

When using the option reverse=True, one can use the results to convert in the opposite sense:

vector1 = vector2[permutation]*signs
Parameters:
  • molbasis (MolecularBasis) – The description of a molecular basis set.

  • new_conventions (dict[str, list[str]]) – The new conventions for ordering and signs, to which data for the orbital basis needs to be converted.

  • reverse – When, true the conversion from 2 to 1 is returned.

Return type:

tuple[NDArray[int], NDArray[int]]

Returns:

  • permutation – An integer array that permutes basis function from 1 to 2.

  • signs – Sign changes when going from 1 to 2, must be applied after permutation

convert_to_cartesian(obasis, new_conventions)[source]

Convert a basis set to Cartesian functions with given conventions.

This is needed for file formats that do not support pure functions, such as WFN and WFX. The new basis spans the same space as the old one, so no information is lost. The Cartesian functions are ordered following the conventions of the destination format, so the Cartesian functions that were already in the basis may be reordered too.

Parameters:
  • obasis (MolecularBasis) – The basis set to convert.

  • new_conventions (dict[tuple[int, str], list[str]]) – The conventions of the destination format. It must have a Cartesian convention for every angular momentum in the basis set. There are no defaults for missing conventions.

Return type:

tuple[MolecularBasis, csr_array]

Returns:

  • obasis_cart – A new MolecularBasis instance in which all shells are Cartesian, with new_conventions as its conventions.

  • transform – A sparse matrix with shape (obasis_cart.nbasis, obasis.nbasis). The coefficients of a function in the old basis, coeffs, become transform @ coeffs in the new basis. The same function, expressed in the new basis, has identical values everywhere in space. An overlap matrix transforms as transform.T @ overlap_cart @ transform.

Raises:

ValueError – If new_conventions has no Cartesian convention for an angular momentum of the basis set, or if the basis has pure shells and the primitives are not L2 normalized.

convert_to_segmented(obasis, keep_sp=False)[source]

Convert basis with generalized contractions to one with only single contractions.

Parameters:
  • obasis (MolecularBasis) – The basis set to convert.

  • keep_sp (bool) – If True, SP shells are not split up. This can be useful for file formats only support SP-generalized contractions and no other ones.

Return type:

MolecularBasis

Returns:

A new MolecularBasis instance with separate single contractions.

convert_to_unrestricted(mo)[source]

Convert orbitals to kind="unrestricted".

Parameters:

mo (MolecularOrbitals) – Restricted molecular orbitals to be converted.

Return type:

MolecularOrbitals

Returns:

new_mo – The given object if the orbitals were already unrestricted or a new unrestricted copy.

Raises:

ValueError – When the given orbitals are generalized.

decontract(obasis)[source]

Convert a contracted basis set to one with only primitive functions.

Primitives that appear several times on the same center with the same angular momentum and kind, e.g. in a general contraction or in a shell that shares an exponent with another shell, are included only once in the new basis. The new basis spans a space that contains the old one, so no information is lost.

Parameters:

obasis (MolecularBasis) – The basis set to convert.

Return type:

tuple[MolecularBasis, csr_array]

Returns:

  • obasis_prim – A new MolecularBasis instance in which each shell has a single primitive and a single contraction.

  • transform – A sparse matrix with shape (obasis_prim.nbasis, obasis.nbasis). The coefficients of a function in the old basis, coeffs, become transform @ coeffs in the new basis. The same function, expressed in the new basis, has identical values everywhere in space. An overlap matrix transforms as transform.T @ overlap_prim @ transform and a density matrix as transform @ dm @ transform.T.

iter_cart_alphabet(n)[source]

Loop over powers of Cartesian basis functions in alphabetical order.

See https://theochem.github.io/horton/2.1.1/tech_ref_gaussian_basis.html for details.

Parameters:

n (int) – The angular momentum, i.e. sum of Cartesian powers in this case.

Return type:

NDArray[int]