qmctorch.wavefunction.orbitals package

Subpackages

Submodules

qmctorch.wavefunction.orbitals.atomic_orbitals module

class qmctorch.wavefunction.orbitals.atomic_orbitals.AtomicOrbitals(*args: Any, **kwargs: Any)[source]

Bases: Module

Computes the value of atomic orbitals

Parameters:
  • mol (Molecule) – Molecule object

  • cuda (bool, optional) – Turn GPU ON/OFF Defaults to False.

forward(pos: torch.Tensor, derivative: List[int] | None = [0], sum_grad: bool | None = True, sum_hess: bool | None = True, one_elec: bool | None = False) torch.Tensor[source]

Computes the values of the atomic orbitals.

\[\phi_i(r_j) = \sum_n c_n \text{Rad}^{i}_n(r_j) \text{Y}^{i}_n(r_j)\]

where Rad is the radial part and Y the spherical harmonics part. It is also possible to compute the first and second derivatives

\[ \begin{align}\begin{aligned}\nabla \phi_i(r_j) = \frac{d}{dx_j} \phi_i(r_j) + \frac{d}{dy_j} \phi_i(r_j) + \frac{d}{dz_j} \phi_i(r_j)\\\text{grad} \phi_i(r_j) = (\frac{d}{dx_j} \phi_i(r_j), \frac{d}{dy_j} \phi_i(r_j), \frac{d}{dz_j} \phi_i(r_j))\\\Delta \phi_i(r_j) = \frac{d^2}{dx^2_j} \phi_i(r_j) + \frac{d^2}{dy^2_j} \phi_i(r_j) + \frac{d^2}{dz^2_j} \phi_i(r_j)\end{aligned}\end{align} \]
Parameters:
  • pos (torch.tensor) – Positions of the electrons Size : Nbatch, Nelec x Ndim

  • derivative (int, optional) – order of the derivative (0,1,2,). Defaults to 0.

  • sum_grad (bool, optional) – Return the sum_grad (i.e. the sum of the derivatives) or the individual terms. Defaults to True. False only for derivative=1

  • sum_hess (bool, optional) – Return the sum_hess (i.e. the sum of 2nd the derivatives) or the individual terms. Defaults to True. False only for derivative=1

  • one_elec (bool, optional) – if only one electron is in input

Returns:

Value of the AO (or their derivatives)

size : Nbatch, Nelec, Norb (sum_grad = True)

size : Nbatch, Nelec, Norb, Ndim (sum_grad = False)

Return type:

torch.tensor

Examples::
>>> mol = Molecule('h2.xyz')
>>> ao = AtomicOrbitals(mol)
>>> pos = torch.rand(100,6)
>>> aovals = ao(pos)
>>> daovals = ao(pos,derivative=1)
update(ao: torch.Tensor, pos: torch.Tensor, idelec: int) torch.Tensor[source]

Update an AO matrix with the new positions of one electron

Parameters:
  • ao (torch.tensor) – initial AO matrix

  • pos (torch.tensor) – new positions of some electrons

  • idelec (int) – index of the electron that has moved

Returns:

new AO matrix

Return type:

torch.tensor

Examples::
>>> mol = Molecule('h2.xyz')
>>> ao = AtomicOrbitals(mol)
>>> pos = torch.rand(100,6)
>>> aovals = ao(pos)
>>> id = 0
>>> pos[:,:3] = torch.rand(100,3)
>>> ao.update(aovals, pos, 0)

qmctorch.wavefunction.orbitals.atomic_orbitals_backflow module

class qmctorch.wavefunction.orbitals.atomic_orbitals_backflow.AtomicOrbitalsBackFlow(*args: Any, **kwargs: Any)[source]

Bases: AtomicOrbitals

Computes the value of atomic orbitals

Parameters:
forward(pos: torch.Tensor, derivative: List[int] | None = [0], sum_grad: bool | None = True, sum_hess: bool | None = True, one_elec: bool | None = False) torch.Tensor[source]

Computes the values of the atomic orbitals.

\[\phi_i(q_j) = \sum_n c_n \text{Rad}^{i}_n(q_j) \text{Y}^{i}_n(q_j)\]

where :math: text{Rad}^{i}_n(r_j) is the radial part and :math: text{Y}^{i}_n(r_j) the spherical harmonics part.

The electronic positions are calculated via a backflow transformation :

\[q_i = r_i + \sum_{j\neq i} \text{Kernel}(r_{ij}) (r_i-r_j)\]

It is also possible to compute the first and second derivatives

\[ \begin{align}\begin{aligned}\nabla \phi_i(r_j) = \frac{d}{dx_j} \phi_i(r_j) + \frac{d}{dy_j} \phi_i(r_j) + \frac{d}{dz_j} \phi_i(r_j)\\\text{grad} \phi_i(r_j) = (\frac{d}{dx_j} \phi_i(r_j), \frac{d}{dy_j} \phi_i(r_j), \frac{d}{dz_j} \phi_i(r_j))\\\Delta \phi_i(r_j) = \frac{d^2}{dx^2_j} \phi_i(r_j) + \frac{d^2}{dy^2_j} \phi_i(r_j) + \frac{d^2}{dz^2_j} \phi_i(r_j)\end{aligned}\end{align} \]
Parameters:
  • pos (torch.tensor) – Positions of the electrons Size : Nbatch, Nelec x Ndim

  • derivative (int, optional) – order of the derivative (0,1,2,). Defaults to 0.

  • sum_grad (bool, optional) – Return the sum_grad (i.e. the sum of the derivatives) or the individual terms. Defaults to True.

  • sum_hess (bool, optional) – Return the sum_hess (i.e. the sum of the derivatives) or the individual terms. Defaults to True.

  • one_elec (bool, optional) – if only one electron is in input

Returns:

Value of the AO (or their derivatives)

size : Nbatch, Nelec, Norb (sum_grad = True)

size : Nbatch, Nelec, Norb, Ndim (sum_grad = False)

Return type:

torch.tensor

Examples::
>>> mol = Molecule('h2.xyz')
>>> ao = AtomicOrbitalsBackflow(mol)
>>> pos = torch.rand(100,6)
>>> aovals = ao(pos)
>>> daovals = ao(pos,derivative=1)

qmctorch.wavefunction.orbitals.molecular_orbitals module

class qmctorch.wavefunction.orbitals.molecular_orbitals.MolecularOrbitals(*args: Any, **kwargs: Any)[source]

Bases: Module

Parameters:
  • mol (Molecule) – molecule object

  • include_all_mo (bool) – If True all molecular orbitals are included in the optimization

  • highest_occ_mo (int) – If include_all_mo=False, the highest occupied molecular orbital that is included in the optimization

  • mix_mo (bool) – If True, the molecular orbitals are mixed according to the mixing weights

  • orthogonalize_mo (bool) – If True, the mixing weights are orthogonalized

  • cuda (bool) – If True, the computation is done on the GPU, if not, it is done on the CPU

get_mo_coeffs() torch.tensor[source]

Returns the molecular orbital coefficients. If include_all_mo=True, all the molecular orbitals are returned. If include_all_mo=False, only the highest occupied molecular orbitals are returned.

Returns:

Molecular orbital coefficients (Nmo, Nao)

Return type:

torch.tensor

forward(ao: torch.tensor) torch.tensor[source]

Transforms atomic orbital values into molecular orbital values using the molecular orbital coefficients, mo modifier and optinally a mixed.

Parameters:

ao (torch.tensor) – Atomic orbital values (Nbatch, Nelec, Nao).

Returns:

Transformed molecular orbital values (Nbatch, Nelec, Nmo).

Return type:

torch.tensor

qmctorch.wavefunction.orbitals.norm_orbital module

qmctorch.wavefunction.orbitals.norm_orbital.atomic_orbital_norm(basis: SimpleNamespace) torch.Tensor[source]

Computes the norm of the atomic orbitals

Parameters:

basis (Namespace) – basis object of the Molecule instance

Returns:

Norm of the atomic orbitals

Return type:

torch.tensor

Examples::
>>> mol = Molecule('h2.xyz', basis='dzp', calculator='adf')
>>> norm = atomic_orbital_norm(mol.basis)
qmctorch.wavefunction.orbitals.norm_orbital.norm_slater_spherical(bas_n: torch.Tensor, bas_exp: torch.Tensor) torch.Tensor[source]

Normalization of STOs with Spherical Harmonics.

References

  • www.theochem.ru.nl/~pwormer/Knowino/knowino.org/wiki/Slater_orbital

  • C Filippi, JCP 105, 213 1996

  • Monte Carlo Methods in Ab Initio Quantum Chemistry, B.L. Hammond

Parameters:
Returns:

Normalization factor

Return type:

torch.Tensor

qmctorch.wavefunction.orbitals.norm_orbital.norm_gaussian_spherical(bas_n: torch.Tensor, bas_exp: torch.Tensor) torch.Tensor[source]

Normlization of GTOs with spherical harmonics.

  • Computational Quantum Chemistry: An interactive Intrduction to basis set theory

    eq : 1.14 page 23.

Parameters:
  • bas_n (torch.tensor) – prinicpal quantum number

  • bas_exp (torch.tensor) – slater exponents

Returns:

normalization factor

Return type:

torch.tensor

qmctorch.wavefunction.orbitals.norm_orbital.norm_slater_cartesian(a: torch.Tensor, b: torch.Tensor, c: torch.Tensor, n: torch.Tensor, exp: torch.Tensor) torch.Tensor[source]

Normaliation of STos with cartesian harmonics.

  • Monte Carlo Methods in Ab Initio Quantum Chemistry page 279

Parameters:
  • a (torch.tensor) – exponent of x

  • b (torch.tensor) – exponent of y

  • c (torch.tensor) – exponent of z

  • n (torch.tensor) – exponent of r

  • exp (torch.tensor) – Sater exponent

Returns:

normalization factor

Return type:

torch.tensor

qmctorch.wavefunction.orbitals.norm_orbital.norm_gaussian_cartesian(a: torch.Tensor, b: torch.Tensor, c: torch.Tensor, exp: torch.Tensor) torch.Tensor[source]

Normaliation of GTOs with cartesian harmonics.

  • Monte Carlo Methods in Ab Initio Quantum Chemistry page 279

Parameters:
  • a (torch.tensor) – exponent of x

  • b (torch.tensor) – exponent of y

  • c (torch.tensor) – exponent of z

  • exp (torch.tensor) – Slater exponent

Returns:

normalization factor

Return type:

torch.tensor

qmctorch.wavefunction.orbitals.radial_functions module

qmctorch.wavefunction.orbitals.radial_functions.radial_slater(R: torch.Tensor, bas_n: torch.Tensor, bas_exp: torch.Tensor, xyz: torch.Tensor = None, derivative: int = 0, sum_grad: bool = True, sum_hess: bool = True) torch.Tensor | List[torch.Tensor][source]

Compute the radial part of STOs (or its derivative).

Parameters:
  • R (torch.tensor) – distance between each electron and each atom

  • bas_n (torch.tensor) – principal quantum number

  • bas_exp (torch.tensor) – exponents of the exponential

Keyword Arguments:
  • xyz (torch.tensor) – positions of the electrons (needed for derivative) (default: {None})

  • derivative (int) – degree of the derivative (default: {0}) 0 : value of the function 1 : first derivative 2 : pure second derivative 3 : mixed second derivative

  • sum_grad (bool) – return the sum_grad, i.e the sum of the gradients (default: {True})

  • sum_hess (bool) – return the sum_hess, i.e the sum of the diag hessian (default: {False})

Returns:

values of each orbital radial part at each position

Return type:

torch.tensor

qmctorch.wavefunction.orbitals.radial_functions.radial_gaussian(R: torch.Tensor, bas_n: torch.Tensor, bas_exp: torch.Tensor, xyz: torch.Tensor = None, derivative: list = [0], sum_grad: bool = True, sum_hess: bool = True) torch.Tensor | List[torch.Tensor][source]

Compute the radial part of GTOs (or its derivative).

\[gto = r^n exp(-lpha r^2)\]
Parameters:
Keyword Arguments:
  • xyz (torch.Tensor) – positions of the electrons (needed for derivative) (default: {None})

  • derivative (list) – degree of the derivative (default: {[0]}) 0: value of the function 1: first derivative 2: pure second derivative 3: mixed second derivative

  • sum_grad (bool) – return the sum of the gradients (default: {True})

  • sum_hess (bool) – return the sum of the hessian (default: {True})

Returns:

values of each orbital radial part at each position

Return type:

torch.Tensor

qmctorch.wavefunction.orbitals.radial_functions.radial_gaussian_pure(R: torch.Tensor, bas_n: torch.Tensor, bas_exp: torch.Tensor, xyz: torch.Tensor = None, derivative: List[int] = [0], sum_grad: bool = True, sum_hess: bool = True) torch.Tensor | List[torch.Tensor][source]

Compute the radial part of GTOs (or its derivative).

Parameters:
  • R (torch.Tensor) – distance between each electron and each atom

  • bas_n (torch.Tensor) – principal quantum number (not relevant here but kept for consistency)

  • bas_exp (torch.Tensor) – exponents of the exponential

Keyword Arguments:
  • xyz (torch.Tensor) – positions of the electrons (needed for derivative)(default: {None})

  • derivative (int) – degree of the derivative(default: {0})

  • sum_grad (bool) – return the sum_grad, i.e the sum of the gradients (default: {True})

  • sum_hess (bool) – return the sum_hess, i.e the sum of the lapacian (default: {True})

Returns:

values of each orbital radial part at each position

Return type:

torch.Tensor

qmctorch.wavefunction.orbitals.radial_functions.radial_slater_pure(R: torch.Tensor, bas_n: torch.Tensor, bas_exp: torch.Tensor, xyz: torch.Tensor = None, derivative: int | List[int] = 0, sum_grad: bool = True, sum_hess: bool = True) torch.Tensor | List[torch.Tensor][source]

Compute the radial part of STOs (or its derivative).

\[sto = exp(-lpha | r |)\]
Parameters:
  • R (torch.Tensor) – distance between each electron and each atom

  • bas_n (torch.Tensor) – principal quantum number (not relevant here but kept for consistency)

  • bas_exp (torch.Tensor) – exponents of the exponential

Keyword Arguments:
  • xyz (torch.Tensor) – positions of the electrons (needed for derivative)(default: {None})

  • derivative (Union[int, List[int]]) – degree of the derivative(default: {0})

  • sum_grad (bool) – return the sum_grad, i.e the sum of the gradients (default: {True})

  • sum_hess (bool) – return the sum_hess, i.e the sum of the laplacian (default: {True})

Returns:

values of each orbital radial part at each position

Return type:

torch.Tensor

qmctorch.wavefunction.orbitals.radial_functions.return_required_data(derivative: List[int], _kernel: Callable, _first_derivative_kernel: Callable, _second_derivative_kernel: Callable, _mixed_second_derivative_kernel: Callable) List | torch.Tensor[source]

Returns the data contained in derivative

Parameters:
  • derivative (List[int]) – list of the derivatives required

  • _kernel (Callable) – kernel of the values

  • _first_derivative_kernel (Callable) – kernel for 1st der

  • _second_derivative_kernel (Callable) – kernel for 2nd der

Returns:

values of the different der required

Return type:

Union[List, torch.Tensor]

qmctorch.wavefunction.orbitals.spherical_harmonics module

class qmctorch.wavefunction.orbitals.spherical_harmonics.Harmonics(type: str, **kwargs)[source]

Bases: object

Compute spherical or cartesian harmonics and their derivatives

Parameters:

type (str) – harmonics type (cart or sph)

Keyword Arguments:
  • bas_l (torch.tensor) – second quantum numbers (sph)

  • bas_m (torch.tensor) – third quantum numbers (sph)

  • bas_kx (torch.tensor) – x exponent (cart)

  • bas_ky (torch.tensor) – xy exponent (cart)

  • bas_kz (torch.tensor) – z exponent (cart)

  • cuda (bool) – use cuda (defaults False)

Examples::
>>> mol = Molecule('h2.xyz')
>>> harm = Harmonics(cart)
>>> pos = torch.rand(100,6)
>>> hvals = harm(pos)
>>> dhvals = harm(pos,derivative=1)
qmctorch.wavefunction.orbitals.spherical_harmonics.CartesianHarmonics(xyz: torch.Tensor, k: torch.Tensor, mask0: torch.Tensor, mask2: torch.Tensor, derivative: list = [0], sum_grad: bool = True, sum_hess: bool = True) torch.Tensor[source]

Computes Real Cartesian Harmonics

\[\begin{split}Y = x^{k_x} \\times y^{k_y} \\times z^{k_z}\end{split}\]
Parameters:
  • xyz (torch.Tensor) – Distance between sampling points and orbital centers size : (Nbatch, Nelec, Nbas, Ndim)

  • k (torch.Tensor) – (kx,ky,kz) exponents

  • mask0 (torch.Tensor) – Precomputed mask of k=0

  • mask2 (torch.Tensor) – Precomputed mask of k=2

  • derivative (list, optional) – Orders of the derivative. Defaults to [0].

  • sum_grad (bool, optional) – Returns the sum of the derivative if True. Defaults to True.

  • sum_hess (bool, optional) – Returns the sum of the 2nd derivative if True. Defaults to True.

Returns:

Values of the harmonics at the sampling points

Return type:

torch.Tensor

qmctorch.wavefunction.orbitals.spherical_harmonics.SphericalHarmonics(xyz: torch.Tensor, l: torch.Tensor, m: torch.Tensor, derivative: int | List[int] = 0, sum_grad: bool = True, sum_hess: bool = True) torch.Tensor | List[torch.Tensor][source]

Compute the Real Spherical Harmonics of the AO.

Parameters:
  • xyz (torch.Tensor) – distance between sampling points and orbital centers size : (Nbatch, Nelec, Nbas, Ndim)

  • l (torch.Tensor) – l quantum number

  • m (torch.Tensor) – m quantum number

  • derivative (Union[int, List[int]], optional) – order of the derivative. Defaults to 0.

  • sum_grad (bool, optional) – Return the sum of the derivative if True and individual components if False. Defaults to True.

  • sum_hess (bool, optional) – Not used. Defaults to True.

Returns:

value of each harmonics at each points (or derivative)

size : (Nbatch,Nelec,Nrbf) if sum_grad=True size : (Nbatch,Nelec,Nrbf, Ndim) if sum_grad=False

Return type:

Y (Union[torch.Tensor, List[torch.Tensor]])

qmctorch.wavefunction.orbitals.spherical_harmonics.get_spherical_harmonics(xyz: torch.Tensor, lval: torch.Tensor, m: torch.Tensor, derivative: int)[source]

Compute the Real Spherical Harmonics of the AO.

Parameters:
  • xyz (torch.tensor) – distance between sampling points and orbital centers n size : (Nbatch, Nelec, Nbas, Ndim)

  • l (torch.tensor) – l quantum number

  • m (torch.tensor) – m quantum number

  • derivative (int) – order of the derivative

Returns:

value of each harmonics at each points (or derivative) n

size : (Nbatch,Nelec,Nrbf)

Return type:

Y (torch.tensor)

qmctorch.wavefunction.orbitals.spherical_harmonics.get_grad_spherical_harmonics(xyz: torch.Tensor, lval: torch.Tensor, m: torch.Tensor) torch.Tensor[source]

Compute the gradient of the Real Spherical Harmonics of the AO.

Parameters:
  • xyz (torch.tensor) – distance between sampling points and orbital centers n size : (Nbatch, Nelec, Nbas, Ndim)

  • lval (torch.tensor) – l quantum number

  • m (torch.tensor) – m quantum number

Returns:

value of each harmonics at each points (or derivative) n

size : (Nbatch,Nelec,Nrbf,3)

Return type:

Y (torch.tensor)

Module contents