qstack.io.metatensor

Equilibrium geometry and molecular structure I/O utilities.

qstack.io.metatensor.array_to_tensormap(mol, v, src='pyscf')[source]

Transform an array into a tensor map.

Wrapper for _vector_to_tensormap and _matrix_to_tensormap. Also reorders the AO.

Parameters:
  • mol (pyscf.gto.Mole) – pyscf Mole object.

  • v (numpy.ndarray) – Array to transform. Can be a vector (1D) or matrix (2D).

  • src (str) – Source AO ordering of the input array. Default is ‘pyscf’.

Returns:

Tensor map representation of the array.

Return type:

metatensor.TensorMap

Raises:

ValueError – If array dimension is not 1 or 2.

qstack.io.metatensor.join(tensors)[source]

Merge two or more tensors with the same label names avoiding information duplication.

Parameters:

tensors (list) – List of metatensor.TensorMap objects.

Returns:

Merged tensor containing information from all input tensors.

Return type:

metatensor.TensorMap

Raises:

RuntimeError – If tensors have different label names.

qstack.io.metatensor.split(tensor)[source]

Split a tensor based on the molecule information stored within the input TensorMap.

Parameters:

tensor (metatensor.TensorMap) – Tensor containing several molecules.

Returns:

Collection of metatensor.TensorMap objects, one per molecule. Returns list if molecule indices are continuous, dict otherwise.

Return type:

list or dict

Raises:

RuntimeError – If tensor does not contain multiple molecules.

qstack.io.metatensor.tensormap_to_array(mol, tensor, dest='pyscf', fast=False)[source]

Transform a tensor map into an array.

Wrapper for _tensormap_to_vector and _tensormap_to_matrix. Also reorders the AO.

Parameters:
  • mol (pyscf.gto.Mole) – pyscf Mole object.

  • tensor (metatensor.TensorMap) – Tensor to transform.

  • dest (str) – Destination AO ordering of the output array. Default is ‘pyscf’.

  • fast (bool) – Whether to use a faster approach for matrix conversion using assumptions on the internal ordering of the TensorMap (see _tensormap_to_matrix()). Default is False.

Returns:

Array representation (1D vector or 2D matrix).

Return type:

numpy.ndarray

Raises:

RuntimeError – If tensor key names don’t match expected format.