diff --git a/horton/__init__.py b/horton/__init__.py
index 3682052d..c8bb6859 100644
--- a/horton/__init__.py
+++ b/horton/__init__.py
@@ -26,11 +26,8 @@
# Extensions are imported first to call fpufix as early as possible
from horton.cext import *
-
-from horton.cache import *
from horton.constants import *
from horton.context import *
-from horton.part import *
from horton.espfit import *
from horton.exceptions import *
from horton.gbasis import *
@@ -38,9 +35,11 @@
from horton.io import *
from horton.log import *
from horton.meanfield import *
+from horton.meanfield.cache import *
+from horton.meanfield.quadprog import *
+from horton.modelhamiltonians import *
from horton.moments import *
+from horton.part import *
from horton.periodic import *
-from horton.quadprog import *
from horton.units import *
from horton.utils import *
-from horton.modelhamiltonians import *
diff --git a/horton/exceptions.py b/horton/exceptions.py
index 75499638..e9f93ce4 100644
--- a/horton/exceptions.py
+++ b/horton/exceptions.py
@@ -26,14 +26,14 @@ class SymmetryError(Exception):
pass
-class ElectronCountError(ValueError):
- '''Exception raised when a negative number of electron is encountered, or
- when more electrons than basis functions are requested.
- '''
- pass
-
-
-class NoSCFConvergence(Exception):
- '''Exception raised when an SCF algorithm does not reach the convergence
- threshold in the specified number of iterations'''
- pass
+# class ElectronCountError(ValueError):
+# '''Exception raised when a negative number of electron is encountered, or
+# when more electrons than basis functions are requested.
+# '''
+# pass
+#
+#
+# class NoSCFConvergence(Exception):
+# '''Exception raised when an SCF algorithm does not reach the convergence
+# threshold in the specified number of iterations'''
+# pass
diff --git a/horton/meanfield/__init__.py b/horton/meanfield/__init__.py
index 9377c4fa..779eace3 100644
--- a/horton/meanfield/__init__.py
+++ b/horton/meanfield/__init__.py
@@ -18,27 +18,27 @@
# along with this program; if not, see
#
# --
-'''Mean-field electronic structure code'''
+"""Mean-field electronic structure code"""
-
-from horton.meanfield.bond_order import *
-from horton.meanfield.builtin import *
-from horton.meanfield.convergence import *
-from horton.meanfield.cext import *
-from horton.meanfield.gridgroup import *
-from horton.meanfield.guess import *
-from horton.meanfield.hamiltonian import *
-from horton.meanfield.indextransform import *
-from horton.meanfield.libxc import *
-from horton.meanfield.observable import *
-from horton.meanfield.occ import *
-from horton.meanfield.orbitals import *
-from horton.meanfield.project import *
-from horton.meanfield.rotate import *
-from horton.meanfield.response import *
-from horton.meanfield.scf import *
-from horton.meanfield.scf_oda import *
-from horton.meanfield.scf_cdiis import *
-from horton.meanfield.scf_ediis import *
-from horton.meanfield.scf_ediis2 import *
-from horton.meanfield.utils import *
+from .bond_order import *
+from .builtin import *
+from .cext import *
+from .convergence import *
+from .exceptions import *
+from .gridgroup import *
+from .guess import *
+from .hamiltonian import *
+from .indextransform import *
+from .libxc import *
+from .observable import *
+from .occ import *
+from .orbitals import *
+from .project import *
+from .response import *
+from .rotate import *
+from .scf import *
+from .scf_cdiis import *
+from .scf_ediis import *
+from .scf_ediis2 import *
+from .scf_oda import *
+from .utils import *
diff --git a/horton/meanfield/bond_order.py b/horton/meanfield/bond_order.py
index 37dd8d7e..a19ed0bf 100644
--- a/horton/meanfield/bond_order.py
+++ b/horton/meanfield/bond_order.py
@@ -18,10 +18,10 @@
# along with this program; if not, see
#
# --
-r'''Generic implementation of bond orders for mean-field wavefunctions
+r"""Generic implementation of bond orders for mean-field wavefunctions
- In the context bond orders and self-electron delocatization indices (SEDI's)
- are always one an the same thing. For two AIM overlap perators, :math:`S_A`
+ In the context bond orders and self-electron delocalization indices (SEDI's)
+ are always one an the same thing. For two AIM overlap operators, :math:`S_A`
and :math:`S_B`, the bond order is defined as:
.. math::
@@ -42,17 +42,15 @@
.. math::
F_A = V_A - \sum_{B \neq A} \text{BO}_{AB}
-'''
-
+"""
import numpy as np
-
__all__ = ['compute_bond_orders_cs', 'compute_bond_orders_os']
def compute_bond_orders_cs(dm_alpha, operators):
- '''Compute bond orders, valences and free valences (closed-shell case)
+ """Compute bond orders, valences and free valences (closed-shell case)
**Arguments:**
@@ -72,7 +70,7 @@ def compute_bond_orders_cs(dm_alpha, operators):
free_valences
A vector with atomic free valences
- '''
+ """
bond_orders, populations = _compute_bond_orders_low(dm_alpha, operators)
valences = _compute_valences_low(dm_alpha, populations, operators)
bond_orders *= 2
@@ -83,7 +81,7 @@ def compute_bond_orders_cs(dm_alpha, operators):
def compute_bond_orders_os(dm_alpha, dm_beta, operators):
- '''Compute bond orders, valences and free valences (open-shell case)
+ """Compute bond orders, valences and free valences (open-shell case)
**Arguments:**
@@ -103,18 +101,18 @@ def compute_bond_orders_os(dm_alpha, dm_beta, operators):
free_valences
A vector with atomic free valences
- '''
+ """
bond_orders_a, populations_a = _compute_bond_orders_low(dm_alpha, operators)
bond_orders_b, populations_b = _compute_bond_orders_low(dm_beta, operators)
bond_orders = bond_orders_a + bond_orders_b
populations = populations_a + populations_b
- valences = _compute_valences_low(dm_alpha + dm_beta, 2*populations, operators)/2
+ valences = _compute_valences_low(dm_alpha + dm_beta, 2 * populations, operators) / 2
free_valences = valences - (bond_orders.sum(axis=0) - np.diag(bond_orders))
return bond_orders, valences, free_valences
def _compute_bond_orders_low(dm, operators):
- '''Compute bond orders and populations
+ """Compute bond orders and populations
**Arguments:**
@@ -131,7 +129,7 @@ def _compute_bond_orders_low(dm, operators):
populations
A vector with atomic populations
- '''
+ """
n = len(operators)
bond_orders = np.zeros((n, n), float)
populations = np.zeros(n, float)
@@ -143,16 +141,16 @@ def _compute_bond_orders_low(dm, operators):
# precompute a dot product
tmp = np.dot(dm, operators[i0])
precomputed.append(tmp)
- for i1 in xrange(i0+1):
+ for i1 in xrange(i0 + 1):
# compute bond orders
- bond_orders[i0, i1] = 2*np.einsum('ab,ba', precomputed[i0], precomputed[i1])
+ bond_orders[i0, i1] = 2 * np.einsum('ab,ba', precomputed[i0], precomputed[i1])
bond_orders[i1, i0] = bond_orders[i0, i1]
return bond_orders, populations
def _compute_valences_low(dm, populations, operators):
- '''Computes the valences
+ """Computes the valences
**Arguments:**
@@ -165,11 +163,11 @@ def _compute_valences_low(dm, populations, operators):
operators
A list of one-body operators.
- '''
+ """
n = len(operators)
valences = np.zeros(n, float)
for i in xrange(n):
# valence for atom i
tmp = np.dot(dm, operators[i])
- valences[i] = 2*populations[i] - 2*np.einsum('ab,ba', tmp, tmp)
+ valences[i] = 2 * populations[i] - 2 * np.einsum('ab,ba', tmp, tmp)
return valences
diff --git a/horton/meanfield/builtin.py b/horton/meanfield/builtin.py
index 499bb0a1..9658e80d 100644
--- a/horton/meanfield/builtin.py
+++ b/horton/meanfield/builtin.py
@@ -20,14 +20,12 @@
# --
"""Built-in energy terms"""
-
import numpy as np
-from horton.meanfield.gridgroup import GridObservable, DF_LEVEL_LDA
from horton.grid.molgrid import BeckeMolGrid
from horton.grid.poisson import solve_poisson_becke
-from horton.utils import doc_inherit
-
+from .gridgroup import GridObservable, DF_LEVEL_LDA
+from .utils import doc_inherit
__all__ = ['RBeckeHartree', 'UBeckeHartree', 'RDiracExchange', 'UDiracExchange']
@@ -53,7 +51,8 @@ def _update_pot(self, cache, grid):
"""
# This only works under a few circumstances
if not isinstance(grid, BeckeMolGrid):
- raise TypeError('The BeckeHatree term only works for Becke-Lebedev molecular integration grids')
+ raise TypeError(
+ 'The BeckeHatree term only works for Becke-Lebedev molecular integration grids')
if grid.mode != 'keep':
raise TypeError('The mode option of the molecular grid must be \'keep\'.')
@@ -67,7 +66,9 @@ def _update_pot(self, cache, grid):
for atgrid in grid.subgrids:
end = begin + atgrid.size
becke_weights = grid.becke_weights[begin:end]
- density_decomposition = atgrid.get_spherical_decomposition(rho[begin:end], becke_weights, lmax=self.lmax)
+ density_decomposition = atgrid.get_spherical_decomposition(rho[begin:end],
+ becke_weights,
+ lmax=self.lmax)
hartree_decomposition = solve_poisson_becke(density_decomposition)
grid.eval_decomposition(hartree_decomposition, atgrid.center, pot)
begin = end
@@ -77,7 +78,7 @@ def _update_pot(self, cache, grid):
def compute_energy(self, cache, grid):
pot = self._update_pot(cache, grid)
rho = cache['rho_full']
- return 0.5*grid.integrate(pot, rho)
+ return 0.5 * grid.integrate(pot, rho)
class RBeckeHartree(BeckeHartree):
diff --git a/horton/cache.py b/horton/meanfield/cache.py
similarity index 100%
rename from horton/cache.py
rename to horton/meanfield/cache.py
diff --git a/horton/meanfield/cext.pyx b/horton/meanfield/cext.pyx
index da5aaf9b..dd609bb6 100644
--- a/horton/meanfield/cext.pyx
+++ b/horton/meanfield/cext.pyx
@@ -20,11 +20,10 @@
# --
"""C++ extensions"""
-
import numpy as np
cimport numpy as np
-np.import_array()
+np.import_array()
__all__ = [
'RLibXCWrapper', 'ULibXCWrapper'
@@ -41,12 +40,12 @@ cdef extern from "xc.h":
ctypedef struct xc_func_info_type:
int number
int kind
- char* name
+ char*name
int family
func_reference_type *refs[5]
ctypedef struct xc_func_type:
- xc_func_info_type* info
+ xc_func_info_type*info
int xc_functional_get_number(char *name)
bint xc_func_init(xc_func_type *p, int functional, int nspin)
@@ -62,8 +61,8 @@ cdef extern from "xc.h":
void xc_mgga_exc(xc_func_type *p, int npoint, double *rho, double *sigma,
double *lapl, double *tau, double *zk)
void xc_mgga_vxc(xc_func_type *p, int npoint, double *rho, double *sigma,
- double *lapl, double *tau, double* vrho, double* vsigma,
- double* vlapl, double* vtau);
+ double *lapl, double *tau, double*vrho, double*vsigma,
+ double*vlapl, double*vtau);
double xc_hyb_exx_coef(xc_func_type *p)
double xc_hyb_cam_coef(const xc_func_type *p, double *omega, double *alpha, double *beta)
@@ -118,7 +117,7 @@ cdef class LibXCWrapper(object):
property refs:
def __get__(self):
cdef int i
- cdef func_reference_type* ref
+ cdef func_reference_type*ref
result = []
for i in range(5):
ref = self._func.info[0].refs[i]
@@ -153,7 +152,6 @@ cdef class LibXCWrapper(object):
xc_hyb_cam_coef(&self._func, &omega, &alpha, &beta)
return omega, alpha, beta
-
cdef class RLibXCWrapper(LibXCWrapper):
def __cinit__(self, bytes key):
"""Initialize a RLibXCWrapper.
@@ -171,7 +169,7 @@ cdef class RLibXCWrapper(LibXCWrapper):
## LDA
def compute_lda_exc(self, np.ndarray[double, ndim=1] rho not None,
- np.ndarray[double, ndim=1] zk not None):
+ np.ndarray[double, ndim=1] zk not None):
"""Compute the LDA energy density.
Parameters
@@ -188,7 +186,7 @@ cdef class RLibXCWrapper(LibXCWrapper):
xc_lda_exc(&self._func, npoint, &rho[0], &zk[0])
def compute_lda_vxc(self, np.ndarray[double, ndim=1] rho not None,
- np.ndarray[double, ndim=1] vrho not None):
+ np.ndarray[double, ndim=1] vrho not None):
"""Compute the LDA potential.
Parameters
@@ -205,7 +203,7 @@ cdef class RLibXCWrapper(LibXCWrapper):
xc_lda_vxc(&self._func, npoint, &rho[0], &vrho[0])
def compute_lda_fxc(self, np.ndarray[double, ndim=1] rho not None,
- np.ndarray[double, ndim=1] v2rho2 not None):
+ np.ndarray[double, ndim=1] v2rho2 not None):
"""Compute the LDA hardness kernel.
Parameters
@@ -224,8 +222,8 @@ cdef class RLibXCWrapper(LibXCWrapper):
## GGA
def compute_gga_exc(self, np.ndarray[double, ndim=1] rho not None,
- np.ndarray[double, ndim=1] sigma not None,
- np.ndarray[double, ndim=1] zk not None):
+ np.ndarray[double, ndim=1] sigma not None,
+ np.ndarray[double, ndim=1] zk not None):
"""Compute the GGA energy density.
Parameters
@@ -246,9 +244,9 @@ cdef class RLibXCWrapper(LibXCWrapper):
xc_gga_exc(&self._func, npoint, &rho[0], &sigma[0], &zk[0])
def compute_gga_vxc(self, np.ndarray[double, ndim=1] rho not None,
- np.ndarray[double, ndim=1] sigma not None,
- np.ndarray[double, ndim=1] vrho not None,
- np.ndarray[double, ndim=1] vsigma not None):
+ np.ndarray[double, ndim=1] sigma not None,
+ np.ndarray[double, ndim=1] vrho not None,
+ np.ndarray[double, ndim=1] vsigma not None):
"""Compute the GGA functional derivatives.
For every input `x`, a functional derivative is computed, `vx`, stored in an array
@@ -277,10 +275,10 @@ cdef class RLibXCWrapper(LibXCWrapper):
xc_gga_vxc(&self._func, npoint, &rho[0], &sigma[0], &vrho[0], &vsigma[0])
def compute_gga_fxc(self, np.ndarray[double, ndim=1] rho not None,
- np.ndarray[double, ndim=1] sigma not None,
- np.ndarray[double, ndim=1] v2rho2 not None,
- np.ndarray[double, ndim=1] v2rhosigma not None,
- np.ndarray[double, ndim=1] v2sigma2 not None):
+ np.ndarray[double, ndim=1] sigma not None,
+ np.ndarray[double, ndim=1] v2rho2 not None,
+ np.ndarray[double, ndim=1] v2rhosigma not None,
+ np.ndarray[double, ndim=1] v2sigma2 not None):
"""Compute the GGA hardness kernel.
Parameters
@@ -306,15 +304,16 @@ cdef class RLibXCWrapper(LibXCWrapper):
assert v2rhosigma.shape[0] == npoint
assert v2sigma2.flags['C_CONTIGUOUS']
assert v2sigma2.shape[0] == npoint
- xc_gga_fxc(&self._func, npoint, &rho[0], &sigma[0], &v2rho2[0], &v2rhosigma[0], &v2sigma2[0])
+ xc_gga_fxc(&self._func, npoint, &rho[0], &sigma[0], &v2rho2[0], &v2rhosigma[0],
+ &v2sigma2[0])
## MGGA
def compute_mgga_exc(self, np.ndarray[double, ndim=1] rho not None,
- np.ndarray[double, ndim=1] sigma not None,
- np.ndarray[double, ndim=1] lapl not None,
- np.ndarray[double, ndim=1] tau not None,
- np.ndarray[double, ndim=1] zk not None):
+ np.ndarray[double, ndim=1] sigma not None,
+ np.ndarray[double, ndim=1] lapl not None,
+ np.ndarray[double, ndim=1] tau not None,
+ np.ndarray[double, ndim=1] zk not None):
"""Compute the MGGA energy density.
Parameters
@@ -343,13 +342,13 @@ cdef class RLibXCWrapper(LibXCWrapper):
xc_mgga_exc(&self._func, npoint, &rho[0], &sigma[0], &lapl[0], &tau[0], &zk[0])
def compute_mgga_vxc(self, np.ndarray[double, ndim=1] rho not None,
- np.ndarray[double, ndim=1] sigma not None,
- np.ndarray[double, ndim=1] lapl not None,
- np.ndarray[double, ndim=1] tau not None,
- np.ndarray[double, ndim=1] vrho not None,
- np.ndarray[double, ndim=1] vsigma not None,
- np.ndarray[double, ndim=1] vlapl not None,
- np.ndarray[double, ndim=1] vtau not None,):
+ np.ndarray[double, ndim=1] sigma not None,
+ np.ndarray[double, ndim=1] lapl not None,
+ np.ndarray[double, ndim=1] tau not None,
+ np.ndarray[double, ndim=1] vrho not None,
+ np.ndarray[double, ndim=1] vsigma not None,
+ np.ndarray[double, ndim=1] vlapl not None,
+ np.ndarray[double, ndim=1] vtau not None, ):
"""Compute the MGGA functional derivatives.
For every input `x`, a functional derivative is computed, `vx`, stored in an array
@@ -393,7 +392,6 @@ cdef class RLibXCWrapper(LibXCWrapper):
xc_mgga_vxc(&self._func, npoint, &rho[0], &sigma[0], &lapl[0], &tau[0], &vrho[0],
&vsigma[0], &vlapl[0], &vtau[0])
-
cdef class ULibXCWrapper(LibXCWrapper):
def __cinit__(self, bytes key):
"""Initialize a ULibXCWrapper.
@@ -411,7 +409,7 @@ cdef class ULibXCWrapper(LibXCWrapper):
## LDA
def compute_lda_exc(self, np.ndarray[double, ndim=2] rho not None,
- np.ndarray[double, ndim=1] zk not None):
+ np.ndarray[double, ndim=1] zk not None):
"""Compute the LDA energy density.
Parameters
@@ -429,7 +427,7 @@ cdef class ULibXCWrapper(LibXCWrapper):
xc_lda_exc(&self._func, npoint, &rho[0, 0], &zk[0])
def compute_lda_vxc(self, np.ndarray[double, ndim=2] rho not None,
- np.ndarray[double, ndim=2] vrho not None):
+ np.ndarray[double, ndim=2] vrho not None):
"""Compute the LDA potentials (alpha and beta).
Parameters
@@ -451,8 +449,8 @@ cdef class ULibXCWrapper(LibXCWrapper):
## GGA
def compute_gga_exc(self, np.ndarray[double, ndim=2] rho not None,
- np.ndarray[double, ndim=2] sigma not None,
- np.ndarray[double, ndim=1] zk not None):
+ np.ndarray[double, ndim=2] sigma not None,
+ np.ndarray[double, ndim=1] zk not None):
"""Compute the GGA energy density.
Parameters
@@ -476,9 +474,9 @@ cdef class ULibXCWrapper(LibXCWrapper):
xc_gga_exc(&self._func, npoint, &rho[0, 0], &sigma[0, 0], &zk[0])
def compute_gga_vxc(self, np.ndarray[double, ndim=2] rho not None,
- np.ndarray[double, ndim=2] sigma not None,
- np.ndarray[double, ndim=2] vrho not None,
- np.ndarray[double, ndim=2] vsigma not None):
+ np.ndarray[double, ndim=2] sigma not None,
+ np.ndarray[double, ndim=2] vrho not None,
+ np.ndarray[double, ndim=2] vsigma not None):
"""Compute the GGA functional derivatives.
For every input `x`, a functional derivative is computed, `vx`, stored in an array
@@ -514,10 +512,10 @@ cdef class ULibXCWrapper(LibXCWrapper):
## MGGA
def compute_mgga_exc(self, np.ndarray[double, ndim=2] rho not None,
- np.ndarray[double, ndim=2] sigma not None,
- np.ndarray[double, ndim=2] lapl not None,
- np.ndarray[double, ndim=2] tau not None,
- np.ndarray[double, ndim=1] zk not None):
+ np.ndarray[double, ndim=2] sigma not None,
+ np.ndarray[double, ndim=2] lapl not None,
+ np.ndarray[double, ndim=2] tau not None,
+ np.ndarray[double, ndim=1] zk not None):
"""Compute the MGGA energy density.
Parameters
@@ -551,13 +549,13 @@ cdef class ULibXCWrapper(LibXCWrapper):
&tau[0, 0], &zk[0])
def compute_mgga_vxc(self, np.ndarray[double, ndim=2] rho not None,
- np.ndarray[double, ndim=2] sigma not None,
- np.ndarray[double, ndim=2] lapl not None,
- np.ndarray[double, ndim=2] kin not None,
- np.ndarray[double, ndim=2] vrho not None,
- np.ndarray[double, ndim=2] vsigma not None,
- np.ndarray[double, ndim=2] vlapl not None,
- np.ndarray[double, ndim=2] vtau not None):
+ np.ndarray[double, ndim=2] sigma not None,
+ np.ndarray[double, ndim=2] lapl not None,
+ np.ndarray[double, ndim=2] kin not None,
+ np.ndarray[double, ndim=2] vrho not None,
+ np.ndarray[double, ndim=2] vsigma not None,
+ np.ndarray[double, ndim=2] vlapl not None,
+ np.ndarray[double, ndim=2] vtau not None):
"""Compute the MGGA functional derivatives.
For every input `x`, a functional derivative is computed, `vx`, stored in an array
@@ -572,7 +570,7 @@ cdef class ULibXCWrapper(LibXCWrapper):
lapl : np.ndarray, shape=(npoint, 2)
The laplacian of the alpha and beta density.
tau : np.ndarray, shape=(npoint, 2)
- The alph and beta kinetic energy density.
+ The alpha and beta kinetic energy density.
vrho : np.ndarray, shape=(npoint, 2)
The derivative of the energy w.r.t. the alpha and beta electron density.
vsigma : np.ndarray, shape=(npoint, 3)
diff --git a/horton/meanfield/convergence.py b/horton/meanfield/convergence.py
index ad50e890..f6bb2ad7 100644
--- a/horton/meanfield/convergence.py
+++ b/horton/meanfield/convergence.py
@@ -18,17 +18,15 @@
# along with this program; if not, see
#
# --
-'''Evaluation of convergence criteria
+"""Evaluation of convergence criteria
These implementations are independent of the SCF algorithms and can be used
to double check convergence.
-'''
-
+"""
import numpy as np
-from horton.meanfield.utils import compute_commutator
-
+from .utils import compute_commutator
__all__ = [
'convergence_error_eigen', 'convergence_error_commutator',
@@ -36,7 +34,7 @@
def convergence_error_eigen(ham, overlap, *orbs):
- '''Compute the self-consistency error
+ """Compute the self-consistency error
Parameters
----------
@@ -53,7 +51,7 @@ def convergence_error_eigen(ham, overlap, *orbs):
error: float
The SCF error. This measure (not this function) is also used in some SCF
algorithms to check for convergence.
- '''
+ """
if len(orbs) != ham.ndm:
raise TypeError('Expecting %i sets of orbitals, got %i.' % (ham.ndm, len(orbs)))
dms = [orb.to_dm() for orb in orbs]
@@ -67,7 +65,7 @@ def convergence_error_eigen(ham, overlap, *orbs):
def convergence_error_commutator(ham, overlap, *dms):
- '''Compute the commutator error
+ """Compute the commutator error
Parameters
----------
@@ -83,15 +81,14 @@ def convergence_error_commutator(ham, overlap, *dms):
error: float
The commutator error. This measure (not this function) is also used in some SCF
algorithms to check for convergence.
- '''
+ """
if len(dms) != ham.ndm:
raise TypeError('Expecting %i density matrices, got %i.' % (ham.ndm, len(dms)))
ham.reset(*dms)
focks = [np.zeros(dms[0].shape) for i in xrange(ham.ndm)]
ham.compute_fock(*focks)
- error = 0.0
errorsq = 0.0
for i in xrange(ham.ndm):
commutator = compute_commutator(dms[i], focks[i], overlap)
errorsq += np.einsum('ab,ab', commutator, commutator)
- return errorsq**0.5
+ return errorsq ** 0.5
diff --git a/horton/meanfield/exceptions.py b/horton/meanfield/exceptions.py
new file mode 100644
index 00000000..de28aea7
--- /dev/null
+++ b/horton/meanfield/exceptions.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+# HORTON: Helpful Open-source Research TOol for N-fermion systems.
+# Copyright (C) 2011-2017 The HORTON Development Team
+#
+# This file is part of HORTON.
+#
+# HORTON is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 3
+# of the License, or (at your option) any later version.
+#
+# HORTON is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see
+#
+# --
+"""Definition of all exceptions in Meanfield"""
+
+class ElectronCountError(ValueError):
+ """Exception raised when a negative number of electron is encountered, or
+ when more electrons than basis functions are requested.
+ """
+ pass
+
+
+class NoSCFConvergence(Exception):
+ """Exception raised when an SCF algorithm does not reach the convergence
+ threshold in the specified number of iterations"""
+ pass
diff --git a/horton/meanfield/gridgroup.py b/horton/meanfield/gridgroup.py
index e34df0c2..8303a025 100644
--- a/horton/meanfield/gridgroup.py
+++ b/horton/meanfield/gridgroup.py
@@ -20,17 +20,14 @@
# --
"""Container for observables involving numerical integration"""
-
-from horton.meanfield.observable import Observable
-from horton.utils import doc_inherit
-
+from .observable import Observable
+from .utils import doc_inherit
__all__ = [
'DF_LEVEL_LDA', 'DF_LEVEL_GGA', 'DF_LEVEL_MGGA',
'GridGroup', 'RGridGroup', 'UGridGroup', 'GridObservable'
]
-
# Define a few `levels` of density functionals. These are used to determine
# which properties need to be computed when using certain functionals. For LDA,
# only the density is needed. For GGA the density and the gradient are needed.
@@ -357,7 +354,7 @@ def _update_grid_data(self, cache):
if self.df_level >= DF_LEVEL_LDA:
rho_full, new = cache.load('rho_full', alloc=self.grid.size)
if new:
- rho_full[:] = 2*all_alpha[:, 0]
+ rho_full[:] = 2 * all_alpha[:, 0]
if self.df_level >= DF_LEVEL_GGA:
grad_rho_full, new = cache.load('grad_rho_full', alloc=(self.grid.size, 3))
if new:
@@ -365,14 +362,14 @@ def _update_grid_data(self, cache):
grad_rho_full *= 2
sigma_full, new = cache.load('sigma_full', alloc=self.grid.size)
if new:
- sigma_full[:] = 4*(all_alpha[:, 1:4]**2).sum(axis=1)
+ sigma_full[:] = 4 * (all_alpha[:, 1:4] ** 2).sum(axis=1)
if self.df_level >= DF_LEVEL_MGGA:
lapl_full, new = cache.load('lapl_full', alloc=self.grid.size)
if new:
- lapl_full[:] = 2*all_alpha[:, 4]
+ lapl_full[:] = 2 * all_alpha[:, 4]
tau_full, new = cache.load('tau_full', alloc=self.grid.size)
if new:
- tau_full[:] = 2*all_alpha[:, 5]
+ tau_full[:] = 2 * all_alpha[:, 5]
@doc_inherit(GridGroup)
def _update_delta_grid_data(self, cache):
@@ -382,17 +379,17 @@ def _update_delta_grid_data(self, cache):
delta_rho_full, new = cache.load('delta_rho_full',
alloc=self.grid.size, tags='d')
if new:
- delta_rho_full[:] = 2*delta_all_alpha[:, 0]
+ delta_rho_full[:] = 2 * delta_all_alpha[:, 0]
if self.df_level >= DF_LEVEL_GGA:
delta_grad_rho_full, new = cache.load('delta_grad_rho_full',
alloc=(self.grid.size, 3), tags='d')
if new:
- delta_grad_rho_full[:] = 2*delta_all_alpha[:, 1:4]
+ delta_grad_rho_full[:] = 2 * delta_all_alpha[:, 1:4]
delta_sigma_full, new = cache.load('delta_sigma_full',
alloc=self.grid.size, tags='d')
if new:
grad_rho_full = cache['grad_rho_full']
- delta_sigma_full[:] = 2*(delta_grad_rho_full*grad_rho_full).sum(axis=1)
+ delta_sigma_full[:] = 2 * (delta_grad_rho_full * grad_rho_full).sum(axis=1)
@doc_inherit(Observable)
def add_dot_hessian(self, cache, output_alpha):
@@ -503,9 +500,9 @@ def _update_grid_data(self, cache):
grad_rho_full += all_beta[:, 1:4]
sigma_all, new = cache.load('sigma_all', alloc=(self.grid.size, 3))
if new:
- sigma_all[:, 0] = (all_alpha[:, 1:4]**2).sum(axis=1)
- sigma_all[:, 1] = (all_alpha[:, 1:4]*all_beta[:, 1:4]).sum(axis=1)
- sigma_all[:, 2] = (all_beta[:, 1:4]**2).sum(axis=1)
+ sigma_all[:, 0] = (all_alpha[:, 1:4] ** 2).sum(axis=1)
+ sigma_all[:, 1] = (all_alpha[:, 1:4] * all_beta[:, 1:4]).sum(axis=1)
+ sigma_all[:, 2] = (all_beta[:, 1:4] ** 2).sum(axis=1)
if self.df_level >= DF_LEVEL_MGGA:
lapl_both, new = cache.load('lapl_both', alloc=(self.grid.size, 2))
if new:
@@ -531,6 +528,7 @@ def __init__(self, label):
A unique label for this contribution.
"""
self.label = label
+ self.biblio = []
def compute_energy(self, cache, grid):
"""Compute the expectation value using numerical integration.
diff --git a/horton/meanfield/guess.py b/horton/meanfield/guess.py
index b1e6ac4d..1bcf9d66 100644
--- a/horton/meanfield/guess.py
+++ b/horton/meanfield/guess.py
@@ -18,18 +18,13 @@
# along with this program; if not, see
#
# --
-'''Initial guesses for wavefunctions'''
-
-
-from horton.log import log, timer
-
+"""Initial guesses for wavefunctions"""
__all__ = ['guess_core_hamiltonian']
-@timer.with_section('Initial Guess')
def guess_core_hamiltonian(overlap, core, *orbs):
- '''Guess the orbitals by diagonalizing a core Hamiltonian.
+ """Guess the orbitals by diagonalizing a core Hamiltonian.
Parameters
----------
@@ -42,10 +37,8 @@ def guess_core_hamiltonian(overlap, core, *orbs):
A list of Orbitals objects (output arguments)
This method only modifies the expansion coefficients and the orbital energies.
- '''
- if log.do_medium:
- log('Performing a core Hamiltonian guess.')
- log.blank()
+ """
+ print('5: Performing a core Hamiltonian guess.')
if len(orbs) == 0:
raise TypeError('At least one set of orbitals.')
diff --git a/horton/meanfield/hamiltonian.py b/horton/meanfield/hamiltonian.py
index 2055fb81..864b70a6 100644
--- a/horton/meanfield/hamiltonian.py
+++ b/horton/meanfield/hamiltonian.py
@@ -20,11 +20,8 @@
# --
"""Mean-field DFT/HF Hamiltonian data structures"""
-
-from horton.log import log
-from horton.cache import Cache
-from horton.utils import doc_inherit
-
+from .cache import Cache
+from .utils import doc_inherit
__all__ = [
'REffHam', 'UEffHam'
@@ -122,18 +119,18 @@ def compute_energy(self):
def log(self):
"""Write an overview of the last computation on screen."""
- log('Contributions to the energy:')
- log.hline()
- log(' term Value')
- log.hline()
+ print('5: Contributions to the energy:')
+ print("5: " + "-" * 70)
+ print('5: term Value')
+ print("5: " + "-" * 70)
for term in self.terms:
energy = self.cache['energy_%s' % term.label]
- log('%50s %20.12f' % (term.label, energy))
+ print('5: %50s %20.12f' % (term.label, energy))
for key, energy in self.external.iteritems():
- log('%50s %20.12f' % (key, energy))
- log('%50s %20.12f' % ('total', self.cache['energy']))
- log.hline()
- log.blank()
+ print('5: %50s %20.12f' % (key, energy))
+ print('5: %50s %20.12f' % ('total', self.cache['energy']))
+ print("5: " + "-" * 70)
+ print("5: ")
def compute_fock(self, *focks):
"""Compute the fock matrices.
@@ -170,7 +167,7 @@ def compute_dot_hessian(self, *outputs):
A list of output TwoIndex objects in which the dot product of the energy
Hessian with the delta density matrices is stored.
- Note that the result must be multiplied by the feactor deriv_scale squared in
+ Note that the result must be multiplied by the factor deriv_scale squared in
order to obtain the proper second order derivative. This is due to conventions
related to the definition of the Fock matrix.
"""
@@ -199,7 +196,8 @@ def reset(self, in_dm_alpha):
def reset_delta(self, in_delta_dm_alpha):
self.cache.clear(tags='d')
# Take a copy of the input alpha delta density matrix in the cache.
- delta_dm_alpha = self.cache.load('delta_dm_alpha', alloc=in_delta_dm_alpha.shape, tags='d')[0]
+ delta_dm_alpha = self.cache.load('delta_dm_alpha', alloc=in_delta_dm_alpha.shape, tags='d')[
+ 0]
delta_dm_alpha[:] = in_delta_dm_alpha
@doc_inherit(EffHam)
@@ -229,7 +227,8 @@ def reset(self, in_dm_alpha, in_dm_beta):
def reset_delta(self, in_delta_dm_alpha, in_delta_dm_beta):
self.cache.clear(tags='d')
# Take a copy of the input alpha and beta delta density matrix in the cache.
- delta_dm_alpha = self.cache.load('delta_dm_alpha', alloc=in_delta_dm_alpha.shape, tags='d')[0]
+ delta_dm_alpha = self.cache.load('delta_dm_alpha', alloc=in_delta_dm_alpha.shape, tags='d')[
+ 0]
delta_dm_alpha[:] = in_delta_dm_alpha
delta_dm_beta = self.cache.load('delta_dm_beta', alloc=in_delta_dm_beta.shape, tags='d')[0]
delta_dm_beta[:] = in_delta_dm_beta
diff --git a/horton/meanfield/indextransform.py b/horton/meanfield/indextransform.py
index 1a7ccf37..e5f73ff4 100644
--- a/horton/meanfield/indextransform.py
+++ b/horton/meanfield/indextransform.py
@@ -20,14 +20,11 @@
# --
"""Utility functions for orbital modifications."""
-
import numpy as np
-from horton.log import timer
-
-
__all__ = ['four_index_transform', 'transform_integrals', 'split_core_active',
- 'four_index_transform_cholesky', 'transform_integrals_cholesky', 'split_core_active_cholesky']
+ 'four_index_transform_cholesky', 'transform_integrals_cholesky',
+ 'split_core_active_cholesky']
def _parse_four_index_transform_orbs(orb0, orb1, orb2, orb3):
@@ -64,7 +61,8 @@ def _parse_four_index_transform_orbs(orb0, orb1, orb2, orb3):
orb3 = orb2
elif orb1 is None or orb2 is None or orb3 is None:
# the only other allowed case is no symmetry.
- raise TypeError('It is not clear how to interpret the optional arguments orb1, orb2 and orb3.')
+ raise TypeError(
+ 'It is not clear how to interpret the optional arguments orb1, orb2 and orb3.')
return orb0, orb1, orb2, orb3
@@ -73,7 +71,7 @@ def four_index_transform(ao_integrals, orb0, orb1=None, orb2=None, orb3=None, me
Parameters
----------
- oa_integrals
+ ao_integrals
A four-index array with integrals over atomic orbitals.
orb0
A Orbitalas object with molecular orbitals
@@ -101,21 +99,20 @@ def four_index_transform(ao_integrals, orb0, orb1=None, orb2=None, orb3=None, me
elif method == 'tensordot':
# because the way tensordot works, the order of the dot products is
# not according to literature conventions.
- result[:] = np.tensordot(ao_integrals, orb0.coeffs, axes=([0],[0]))
- result[:] = np.tensordot(result, orb1.coeffs, axes=([0],[0]))
- result[:] = np.tensordot(result, orb2.coeffs, axes=([0],[0]))
- result[:] = np.tensordot(result, orb3.coeffs, axes=([0],[0]))
+ result[:] = np.tensordot(ao_integrals, orb0.coeffs, axes=([0], [0]))
+ result[:] = np.tensordot(result, orb1.coeffs, axes=([0], [0]))
+ result[:] = np.tensordot(result, orb2.coeffs, axes=([0], [0]))
+ result[:] = np.tensordot(result, orb3.coeffs, axes=([0], [0]))
else:
raise ValueError('The method must either be \'einsum\' or \'tensordot\'.')
# Symmetrize the result
- result[:] = result + result.transpose(1,0,3,2)
- result[:] = result + result.transpose(2,3,0,1)
- result[:] = result + result.transpose(0,3,2,1)
+ result[:] = result + result.transpose(1, 0, 3, 2)
+ result[:] = result + result.transpose(2, 3, 0, 1)
+ result[:] = result + result.transpose(0, 3, 2, 1)
result /= 8
return result
-@timer.with_section('Index Trans')
def transform_integrals(one, two, method='tensordot', *orbs):
"""Transform integrals to MO basis.
@@ -135,9 +132,9 @@ def transform_integrals(one, two, method='tensordot', *orbs):
list of transformed 1- and 2-electron integrals according to a list of Orbitals
instances. We distinguish between:
- * restricted orbitals: only one Ortbials instance (alpha=beta), returns
+ * restricted orbitals: only one Orbitals instance (alpha=beta), returns
one set of 1- and 2-body integrals
- * unrestricted orbitals: two Ortbials instances (alpha, beta), returns
+ * unrestricted orbitals: two Orbitals instances (alpha, beta), returns
two sets of 1-body, and three sets of 2-body integrals:
- one_{alpha,alpha} and
@@ -174,7 +171,7 @@ def split_core_active(one, two, ecore, orb, ncore, nactive, indextrans='tensordo
molecular system, this is the nuclear nuclear repulsion.
orb
The MO expansion coefficients. An Expansion instance. If None,
- integrals are assued to be already transformed into the mo basis
+ integrals are assumed to be already transformed into the mo basis
and no transformation is carried out in this function.
ncore
The number of frozen core orbitals (int)
@@ -210,9 +207,9 @@ def split_core_active(one, two, ecore, orb, ncore, nactive, indextrans='tensordo
# Core energy
# One body term
- ecore += 2*np.trace(one_mo[:ncore, :ncore])
+ ecore += 2 * np.trace(one_mo[:ncore, :ncore])
# Direct part
- ecore += 2*np.einsum('abab', two_mo[:ncore, :ncore, :ncore, :ncore])
+ ecore += 2 * np.einsum('abab', two_mo[:ncore, :ncore, :ncore, :ncore])
# Exchange part
ecore -= np.einsum('abba', two_mo[:ncore, :ncore, :ncore, :ncore])
@@ -220,7 +217,7 @@ def split_core_active(one, two, ecore, orb, ncore, nactive, indextrans='tensordo
norb = ncore + nactive
one_mo_small = one_mo[ncore:norb, ncore:norb].copy()
# Direct part
- one_mo_small += 2*np.einsum('abcb->ac', two_mo[ncore:norb, :ncore, ncore:norb, :ncore])
+ one_mo_small += 2 * np.einsum('abcb->ac', two_mo[ncore:norb, :ncore, ncore:norb, :ncore])
# Exchange part
one_mo_small -= np.einsum('abbc->ac', two_mo[ncore:norb, :ncore, :ncore, ncore:norb])
@@ -235,7 +232,7 @@ def four_index_transform_cholesky(ao_integrals, orb0, orb1=None, method='tensord
Parameters
----------
- oa_integrals : np.ndarray, shape=(nvec, nbasis, nbasis)
+ ao_integrals : np.ndarray, shape=(nvec, nbasis, nbasis)
Cholesky decomposition of four-index object in the AO basis.
orb0
A Orbitals object with molecular orbitals.
@@ -246,19 +243,17 @@ def four_index_transform_cholesky(ao_integrals, orb0, orb1=None, method='tensord
"""
if orb1 is None:
orb1 = orb0
- result = np.zeros(ao_integrals.shape)
if method == 'einsum':
result = np.einsum('ai,kac->kic', orb0.coeffs, ao_integrals)
result = np.einsum('cj,kic->kij', orb1.coeffs, result)
elif method == 'tensordot':
- result = np.tensordot(ao_integrals, orb0.coeffs, axes=([1],[0]))
- result = np.tensordot(result, orb1.coeffs, axes=([1],[0]))
+ result = np.tensordot(ao_integrals, orb0.coeffs, axes=([1], [0]))
+ result = np.tensordot(result, orb1.coeffs, axes=([1], [0]))
else:
raise ValueError('The method must either be \'einsum\' or \'tensordot\'.')
return result
-@timer.with_section('Index Trans')
def transform_integrals_cholesky(one, two, method='tensordot', *orbs):
"""Transform integrals to MO basis.
@@ -278,7 +273,7 @@ def transform_integrals_cholesky(one, two, method='tensordot', *orbs):
list of transformed 1- and 2-electron integrals according to a list of Orbitals
instances. We distinguish between:
- * restricted orbitals: only one Ortbials instance (alpha=beta), returns
+ * restricted orbitals: only one Orbitals instance (alpha=beta), returns
one set of 1- and 2-body integrals
* unrestricted orbitals: two expansion instances (alpha, beta), returns
two sets of 1-body, and two sets of 2-body integrals.
@@ -306,7 +301,7 @@ def split_core_active_cholesky(one, two, ecore, orb, ncore, nactive, indextrans=
molecular system, this is the nuclear nuclear repulsion.
orb
The MO expansion coefficients. An Expansion instance. If None,
- integrals are assued to be already transformed into the mo basis
+ integrals are assumed to be already transformed into the mo basis
and no transformation is carried out in this function.
ncore
The number of frozen core orbitals (int)
@@ -342,9 +337,9 @@ def split_core_active_cholesky(one, two, ecore, orb, ncore, nactive, indextrans=
# Core energy
# One body term
- ecore += 2*np.trace(one_mo[:ncore, :ncore])
+ ecore += 2 * np.trace(one_mo[:ncore, :ncore])
# Direct part
- ecore += 2*np.einsum('xaa,xbb', two_mo[:, :ncore, :ncore], two_mo[:, :ncore, :ncore])
+ ecore += 2 * np.einsum('xaa,xbb', two_mo[:, :ncore, :ncore], two_mo[:, :ncore, :ncore])
# Exchange part
ecore -= np.einsum('xab,xba', two_mo[:, :ncore, :ncore], two_mo[:, :ncore, :ncore])
@@ -352,9 +347,11 @@ def split_core_active_cholesky(one, two, ecore, orb, ncore, nactive, indextrans=
norb = ncore + nactive
one_mo_small = one_mo[ncore:norb, ncore:norb].copy()
# Direct part
- one_mo_small += 2*np.einsum('xac,xbb->ac', two_mo[:, ncore:norb, ncore:norb], two_mo[:, :ncore, :ncore])
+ one_mo_small += 2 * np.einsum('xac,xbb->ac', two_mo[:, ncore:norb, ncore:norb],
+ two_mo[:, :ncore, :ncore])
# Exchange part
- one_mo_small -= np.einsum('xab,xbc->ac', two_mo[:, ncore:norb, :ncore], two_mo[:, :ncore, ncore:norb])
+ one_mo_small -= np.einsum('xab,xbc->ac', two_mo[:, ncore:norb, :ncore],
+ two_mo[:, :ncore, ncore:norb])
# Active space two-body integrals
two_mo_small = two_mo[:, ncore:norb, ncore:norb]
diff --git a/horton/meanfield/libxc.py b/horton/meanfield/libxc.py
index 797ca381..4ab0635b 100644
--- a/horton/meanfield/libxc.py
+++ b/horton/meanfield/libxc.py
@@ -20,13 +20,10 @@
# --
"""Interface to LDA, GGA and hybrid functionals from LibXC"""
-
-from horton.log import timer, biblio
-from horton.utils import doc_inherit
-from horton.meanfield.gridgroup import GridObservable, DF_LEVEL_LDA, \
+from .cext import RLibXCWrapper, ULibXCWrapper
+from .gridgroup import GridObservable, DF_LEVEL_LDA, \
DF_LEVEL_GGA, DF_LEVEL_MGGA
-from horton.meanfield.cext import RLibXCWrapper, ULibXCWrapper
-
+from .utils import doc_inherit
__all__ = [
'LibXCEnergy',
@@ -56,8 +53,9 @@ def __init__(self, name):
name = '%s_%s' % (self.prefix, name)
self._name = name
self._libxc_wrapper = self.LibXCWrapper(name)
- biblio.cite('marques2012', 'using LibXC, the library of exchange and correlation functionals')
GridObservable.__init__(self, 'libxc_%s' % name)
+ self.biblio.append(
+ ['marques2012', 'using LibXC, the library of exchange and correlation functionals'])
class RLibXCLDA(LibXCEnergy):
@@ -67,7 +65,6 @@ class RLibXCLDA(LibXCEnergy):
prefix = 'lda'
LibXCWrapper = RLibXCWrapper
- @timer.with_section('LDA edens')
@doc_inherit(LibXCEnergy)
def compute_energy(self, cache, grid):
# LibXC expects the following input:
@@ -80,7 +77,6 @@ def compute_energy(self, cache, grid):
self._libxc_wrapper.compute_lda_exc(rho_full, edens)
return grid.integrate(edens, rho_full)
- @timer.with_section('LDA pot')
@doc_inherit(LibXCEnergy)
def add_pot(self, cache, grid, pots_alpha):
# LibXC expects the following input:
@@ -92,7 +88,6 @@ def add_pot(self, cache, grid, pots_alpha):
self._libxc_wrapper.compute_lda_vxc(cache['rho_full'], pot)
pots_alpha[:, 0] += pot
- @timer.with_section('LDA dot')
@doc_inherit(LibXCEnergy)
def add_dot(self, cache, grid, dots_alpha):
# LibXC expects the following input:
@@ -105,7 +100,7 @@ def add_dot(self, cache, grid, dots_alpha):
kernel, new = cache.load('kernel_libxc_%s_alpha' % self._name, alloc=grid.size)
if new:
self._libxc_wrapper.compute_lda_fxc(cache['rho_full'], kernel)
- dots_alpha[:, 0] += kernel*cache['delta_rho_full']
+ dots_alpha[:, 0] += kernel * cache['delta_rho_full']
class ULibXCLDA(LibXCEnergy):
@@ -115,7 +110,6 @@ class ULibXCLDA(LibXCEnergy):
prefix = 'lda'
LibXCWrapper = ULibXCWrapper
- @timer.with_section('LDA edens')
@doc_inherit(LibXCEnergy)
def compute_energy(self, cache, grid):
# LibXC expects the following input:
@@ -131,7 +125,6 @@ def compute_energy(self, cache, grid):
self._libxc_wrapper.compute_lda_exc(cache['rho_both'], edens)
return grid.integrate(edens, cache['rho_full'])
- @timer.with_section('LDA pot')
@doc_inherit(LibXCEnergy)
def add_pot(self, cache, grid, pots_alpha, pots_beta):
# LibXC expects the following input:
@@ -154,7 +147,6 @@ class RLibXCGGA(LibXCEnergy):
prefix = 'gga'
LibXCWrapper = RLibXCWrapper
- @timer.with_section('GGA edens')
@doc_inherit(LibXCEnergy)
def compute_energy(self, cache, grid):
# LibXC expects the following input:
@@ -170,7 +162,7 @@ def compute_energy(self, cache, grid):
return grid.integrate(edens, rho_full)
def _compute_dpot_spot(self, cache, grid):
- """Helper function to compute potential resutls with LibXC.
+ """Helper function to compute potential results with LibXC.
This is needed for add_pot and add_dot.
@@ -189,7 +181,6 @@ def _compute_dpot_spot(self, cache, grid):
self._libxc_wrapper.compute_gga_vxc(rho_full, sigma_full, dpot, spot)
return dpot, spot
- @timer.with_section('GGA pot')
@doc_inherit(LibXCEnergy)
def add_pot(self, cache, grid, pots_alpha):
# LibXC expects the following input:
@@ -207,13 +198,12 @@ def add_pot(self, cache, grid, pots_alpha):
if new:
my_gga_pot_alpha[:, 0] = dpot
grad_rho = cache['grad_rho_full']
- my_gga_pot_alpha[:, 1:4] = grad_rho*spot.reshape(-1, 1)
+ my_gga_pot_alpha[:, 1:4] = grad_rho * spot.reshape(-1, 1)
my_gga_pot_alpha[:, 1:4] *= 2
# Add to the output argument
pots_alpha[:, :4] += my_gga_pot_alpha
- @timer.with_section('GGA dot')
@doc_inherit(LibXCEnergy)
def add_dot(self, cache, grid, dots_alpha):
# LibXC expects the following input:
@@ -272,14 +262,14 @@ def add_dot(self, cache, grid, dots_alpha):
delta_rho = cache['delta_rho_full']
delta_grad_rho = cache['delta_grad_rho_full']
delta_sigma = cache['delta_sigma_full']
- my_gga_dot_alpha[:, 0] = kernel_dd*delta_rho + kernel_ds*delta_sigma
- my_gga_dot_alpha[:, 1:4] = 2*(kernel_ds*delta_rho +
- kernel_ss*delta_sigma).reshape(-1, 1) * \
+ my_gga_dot_alpha[:, 0] = kernel_dd * delta_rho + kernel_ds * delta_sigma
+ my_gga_dot_alpha[:, 1:4] = 2 * (kernel_ds * delta_rho +
+ kernel_ss * delta_sigma).reshape(-1, 1) * \
grad_rho
# the easy-to-forget contribution
spot = self._compute_dpot_spot(cache, grid)[1]
- my_gga_dot_alpha[:, 1:4] += 2*spot.reshape(-1, 1)*delta_grad_rho
+ my_gga_dot_alpha[:, 1:4] += 2 * spot.reshape(-1, 1) * delta_grad_rho
# Add to the output argument
dots_alpha[:, :4] += my_gga_dot_alpha
@@ -292,7 +282,6 @@ class ULibXCGGA(LibXCEnergy):
prefix = 'gga'
LibXCWrapper = ULibXCWrapper
- @timer.with_section('GGA edens')
@doc_inherit(LibXCEnergy)
def compute_energy(self, cache, grid):
# LibXC expects the following input:
@@ -311,7 +300,6 @@ def compute_energy(self, cache, grid):
rho_full = cache['rho_full']
return grid.integrate(edens, rho_full)
- @timer.with_section('GGA pot')
@doc_inherit(LibXCEnergy)
def add_pot(self, cache, grid, pots_alpha, pots_beta):
# LibXC expects the following input:
@@ -345,15 +333,15 @@ def add_pot(self, cache, grid, pots_alpha, pots_beta):
alloc=(grid.size, 4))
if new:
my_gga_pot_alpha[:, 0] = dpot_both[:, 0]
- my_gga_pot_alpha[:, 1:4] = (2*spot_all[:, 0].reshape(-1, 1))*grad_alpha
- my_gga_pot_alpha[:, 1:4] += (spot_all[:, 1].reshape(-1, 1))*grad_beta
+ my_gga_pot_alpha[:, 1:4] = (2 * spot_all[:, 0].reshape(-1, 1)) * grad_alpha
+ my_gga_pot_alpha[:, 1:4] += (spot_all[:, 1].reshape(-1, 1)) * grad_beta
my_gga_pot_beta, new = cache.load('gga_pot_libxc_%s_beta' % self._name,
alloc=(grid.size, 4))
if new:
my_gga_pot_beta[:, 0] = dpot_both[:, 1]
- my_gga_pot_beta[:, 1:4] = (2*spot_all[:, 2].reshape(-1, 1))*grad_beta
- my_gga_pot_beta[:, 1:4] += (spot_all[:, 1].reshape(-1, 1))*grad_alpha
+ my_gga_pot_beta[:, 1:4] = (2 * spot_all[:, 2].reshape(-1, 1)) * grad_beta
+ my_gga_pot_beta[:, 1:4] += (spot_all[:, 1].reshape(-1, 1)) * grad_alpha
pots_alpha[:, :4] += my_gga_pot_alpha
pots_beta[:, :4] += my_gga_pot_beta
@@ -394,7 +382,6 @@ class RLibXCMGGA(LibXCEnergy):
prefix = 'mgga'
LibXCWrapper = RLibXCWrapper
- @timer.with_section('MGGA edens')
@doc_inherit(LibXCEnergy)
def compute_energy(self, cache, grid):
# LibXC expects the following input:
@@ -414,7 +401,6 @@ def compute_energy(self, cache, grid):
tau_full, edens)
return grid.integrate(edens, rho_full)
- @timer.with_section('MGGA pot')
@doc_inherit(LibXCEnergy)
def add_pot(self, cache, grid, pots_alpha):
# LibXC expects the following input:
@@ -446,7 +432,7 @@ def add_pot(self, cache, grid, pots_alpha):
if new:
my_mgga_pot_alpha[:, 0] = dpot
grad_rho = cache['grad_rho_full']
- my_mgga_pot_alpha[:, 1:4] = grad_rho*spot.reshape(-1, 1)
+ my_mgga_pot_alpha[:, 1:4] = grad_rho * spot.reshape(-1, 1)
my_mgga_pot_alpha[:, 1:4] *= 2
my_mgga_pot_alpha[:, 4] = lpot
my_mgga_pot_alpha[:, 5] = tpot
@@ -462,7 +448,6 @@ class ULibXCMGGA(LibXCEnergy):
prefix = 'mgga'
LibXCWrapper = ULibXCWrapper
- @timer.with_section('MGGA edens')
@doc_inherit(LibXCEnergy)
def compute_energy(self, cache, grid):
# LibXC expects the following input:
@@ -488,7 +473,6 @@ def compute_energy(self, cache, grid):
rho_full = cache['rho_full']
return grid.integrate(edens, rho_full)
- @timer.with_section('MGGA pot')
@doc_inherit(LibXCEnergy)
def add_pot(self, cache, grid, pots_alpha, pots_beta):
# LibXC expects the following input:
@@ -533,8 +517,8 @@ def add_pot(self, cache, grid, pots_alpha, pots_beta):
alloc=(grid.size, 6))
if new:
my_mgga_pot_alpha[:, 0] = dpot_both[:, 0]
- my_mgga_pot_alpha[:, 1:4] = (2*spot_all[:, 0].reshape(-1, 1))*grad_alpha
- my_mgga_pot_alpha[:, 1:4] += (spot_all[:, 1].reshape(-1, 1))*grad_beta
+ my_mgga_pot_alpha[:, 1:4] = (2 * spot_all[:, 0].reshape(-1, 1)) * grad_alpha
+ my_mgga_pot_alpha[:, 1:4] += (spot_all[:, 1].reshape(-1, 1)) * grad_beta
my_mgga_pot_alpha[:, 4] = lpot_both[:, 0]
my_mgga_pot_alpha[:, 5] = tpot_both[:, 0]
@@ -542,8 +526,8 @@ def add_pot(self, cache, grid, pots_alpha, pots_beta):
alloc=(grid.size, 6))
if new:
my_mgga_pot_beta[:, 0] = dpot_both[:, 1]
- my_mgga_pot_beta[:, 1:4] = (2*spot_all[:, 2].reshape(-1, 1))*grad_beta
- my_mgga_pot_beta[:, 1:4] += (spot_all[:, 1].reshape(-1, 1))*grad_alpha
+ my_mgga_pot_beta[:, 1:4] = (2 * spot_all[:, 2].reshape(-1, 1)) * grad_beta
+ my_mgga_pot_beta[:, 1:4] += (spot_all[:, 1].reshape(-1, 1)) * grad_alpha
my_mgga_pot_beta[:, 4] = lpot_both[:, 1]
my_mgga_pot_beta[:, 5] = tpot_both[:, 1]
diff --git a/horton/meanfield/moments.py b/horton/meanfield/moments.py
new file mode 100644
index 00000000..b1a1939d
--- /dev/null
+++ b/horton/meanfield/moments.py
@@ -0,0 +1,809 @@
+import numpy as np
+
+# from horton.moments
+
+def get_ncart_cumul(lmax):
+ """The number of cartesian powers up to a given angular momentum, lmax."""
+ return ((lmax + 1) * (lmax + 2) * (lmax + 3)) / 6
+
+
+def get_cartesian_powers(lmax):
+ """Return an ordered list of power for x, y and z up to angular moment lmax
+
+ **Arguments:**
+
+ lmax
+ The maximum angular momentum (0=s, 1=p, 2=d, ...)
+
+ **Returns:** an array where each row corresponds to a multipole moment
+ and each column corresponds to a power of x, y and z respectively. The
+ rows are grouped per angular momentum, first s, them p, then d, and so
+ on. Within one angular momentum the rows are sorted 'alphabetically',
+ e.g. for l=2: xxx, xxy, xxz, xyy, xyz, xzz, yyy, yyz, yzz, zzz.
+ """
+ cartesian_powers = np.zeros((get_ncart_cumul(lmax), 3), dtype=int)
+ counter = 0
+ for l in xrange(0, lmax + 1):
+ for nx in xrange(l + 1, -1, -1):
+ for ny in xrange(l - nx, -1, -1):
+ nz = l - ny - nx
+ cartesian_powers[counter] = [nx, ny, nz]
+ counter += 1
+ return cartesian_powers
+
+
+cartesian_transforms = [
+ [
+ [[0, 1]],
+ ],
+ [
+ [[0, 1, 0],
+ [1, 1, 1],
+ [2, 1, 2]],
+ [[0, 1, 3],
+ [1, 1, 4],
+ [2, 1, 5]],
+ [[0, 1, 6],
+ [1, 1, 7],
+ [2, 1, 8]],
+ ],
+ [
+ [[0, 1, 0, 0],
+ [1, 2, 0, 1],
+ [2, 2, 0, 2],
+ [3, 1, 1, 1],
+ [4, 2, 1, 2],
+ [5, 1, 2, 2]],
+ [[0, 1, 0, 3],
+ [1, 1, 1, 3],
+ [1, 1, 0, 4],
+ [2, 1, 2, 3],
+ [2, 1, 0, 5],
+ [3, 1, 1, 4],
+ [4, 1, 2, 4],
+ [4, 1, 1, 5],
+ [5, 1, 2, 5]],
+ [[0, 1, 0, 6],
+ [1, 1, 1, 6],
+ [1, 1, 0, 7],
+ [2, 1, 2, 6],
+ [2, 1, 0, 8],
+ [3, 1, 1, 7],
+ [4, 1, 2, 7],
+ [4, 1, 1, 8],
+ [5, 1, 2, 8]],
+ [[0, 1, 3, 3],
+ [1, 2, 3, 4],
+ [2, 2, 3, 5],
+ [3, 1, 4, 4],
+ [4, 2, 4, 5],
+ [5, 1, 5, 5]],
+ [[0, 1, 3, 6],
+ [1, 1, 4, 6],
+ [1, 1, 3, 7],
+ [2, 1, 5, 6],
+ [2, 1, 3, 8],
+ [3, 1, 4, 7],
+ [4, 1, 5, 7],
+ [4, 1, 4, 8],
+ [5, 1, 5, 8]],
+ [[0, 1, 6, 6],
+ [1, 2, 6, 7],
+ [2, 2, 6, 8],
+ [3, 1, 7, 7],
+ [4, 2, 7, 8],
+ [5, 1, 8, 8]],
+ ],
+ [
+ [[0, 1, 0, 0, 0],
+ [1, 3, 0, 0, 1],
+ [2, 3, 0, 0, 2],
+ [3, 3, 0, 1, 1],
+ [4, 6, 0, 1, 2],
+ [5, 3, 0, 2, 2],
+ [6, 1, 1, 1, 1],
+ [7, 3, 1, 1, 2],
+ [8, 3, 1, 2, 2],
+ [9, 1, 2, 2, 2]],
+ [[0, 1, 0, 0, 3],
+ [1, 1, 0, 0, 4],
+ [1, 2, 0, 1, 3],
+ [2, 1, 0, 0, 5],
+ [2, 2, 0, 2, 3],
+ [3, 1, 1, 1, 3],
+ [3, 2, 0, 1, 4],
+ [4, 2, 1, 2, 3],
+ [4, 2, 0, 2, 4],
+ [4, 2, 0, 1, 5],
+ [5, 1, 2, 2, 3],
+ [5, 2, 0, 2, 5],
+ [6, 1, 1, 1, 4],
+ [7, 1, 1, 1, 5],
+ [7, 2, 1, 2, 4],
+ [8, 1, 2, 2, 4],
+ [8, 2, 1, 2, 5],
+ [9, 1, 2, 2, 5]],
+ [[0, 1, 0, 0, 6],
+ [1, 1, 0, 0, 7],
+ [1, 2, 0, 1, 6],
+ [2, 1, 0, 0, 8],
+ [2, 2, 0, 2, 6],
+ [3, 1, 1, 1, 6],
+ [3, 2, 0, 1, 7],
+ [4, 2, 1, 2, 6],
+ [4, 2, 0, 2, 7],
+ [4, 2, 0, 1, 8],
+ [5, 1, 2, 2, 6],
+ [5, 2, 0, 2, 8],
+ [6, 1, 1, 1, 7],
+ [7, 1, 1, 1, 8],
+ [7, 2, 1, 2, 7],
+ [8, 1, 2, 2, 7],
+ [8, 2, 1, 2, 8],
+ [9, 1, 2, 2, 8]],
+ [[0, 1, 0, 3, 3],
+ [1, 1, 1, 3, 3],
+ [1, 2, 0, 3, 4],
+ [2, 1, 2, 3, 3],
+ [2, 2, 0, 3, 5],
+ [3, 1, 0, 4, 4],
+ [3, 2, 1, 3, 4],
+ [4, 2, 2, 3, 4],
+ [4, 2, 1, 3, 5],
+ [4, 2, 0, 4, 5],
+ [5, 1, 0, 5, 5],
+ [5, 2, 2, 3, 5],
+ [6, 1, 1, 4, 4],
+ [7, 1, 2, 4, 4],
+ [7, 2, 1, 4, 5],
+ [8, 1, 1, 5, 5],
+ [8, 2, 2, 4, 5],
+ [9, 1, 2, 5, 5]],
+ [[0, 1, 0, 3, 6],
+ [1, 1, 1, 3, 6],
+ [1, 1, 0, 4, 6],
+ [1, 1, 0, 3, 7],
+ [2, 1, 2, 3, 6],
+ [2, 1, 0, 5, 6],
+ [2, 1, 0, 3, 8],
+ [3, 1, 1, 4, 6],
+ [3, 1, 1, 3, 7],
+ [3, 1, 0, 4, 7],
+ [4, 1, 2, 4, 6],
+ [4, 1, 2, 3, 7],
+ [4, 1, 1, 5, 6],
+ [4, 1, 1, 3, 8],
+ [4, 1, 0, 5, 7],
+ [4, 1, 0, 4, 8],
+ [5, 1, 2, 5, 6],
+ [5, 1, 2, 3, 8],
+ [5, 1, 0, 5, 8],
+ [6, 1, 1, 4, 7],
+ [7, 1, 2, 4, 7],
+ [7, 1, 1, 5, 7],
+ [7, 1, 1, 4, 8],
+ [8, 1, 2, 5, 7],
+ [8, 1, 2, 4, 8],
+ [8, 1, 1, 5, 8],
+ [9, 1, 2, 5, 8]],
+ [[0, 1, 0, 6, 6],
+ [1, 1, 1, 6, 6],
+ [1, 2, 0, 6, 7],
+ [2, 1, 2, 6, 6],
+ [2, 2, 0, 6, 8],
+ [3, 1, 0, 7, 7],
+ [3, 2, 1, 6, 7],
+ [4, 2, 2, 6, 7],
+ [4, 2, 1, 6, 8],
+ [4, 2, 0, 7, 8],
+ [5, 1, 0, 8, 8],
+ [5, 2, 2, 6, 8],
+ [6, 1, 1, 7, 7],
+ [7, 1, 2, 7, 7],
+ [7, 2, 1, 7, 8],
+ [8, 1, 1, 8, 8],
+ [8, 2, 2, 7, 8],
+ [9, 1, 2, 8, 8]],
+ [[0, 1, 3, 3, 3],
+ [1, 3, 3, 3, 4],
+ [2, 3, 3, 3, 5],
+ [3, 3, 3, 4, 4],
+ [4, 6, 3, 4, 5],
+ [5, 3, 3, 5, 5],
+ [6, 1, 4, 4, 4],
+ [7, 3, 4, 4, 5],
+ [8, 3, 4, 5, 5],
+ [9, 1, 5, 5, 5]],
+ [[0, 1, 3, 3, 6],
+ [1, 1, 3, 3, 7],
+ [1, 2, 3, 4, 6],
+ [2, 1, 3, 3, 8],
+ [2, 2, 3, 5, 6],
+ [3, 1, 4, 4, 6],
+ [3, 2, 3, 4, 7],
+ [4, 2, 4, 5, 6],
+ [4, 2, 3, 5, 7],
+ [4, 2, 3, 4, 8],
+ [5, 1, 5, 5, 6],
+ [5, 2, 3, 5, 8],
+ [6, 1, 4, 4, 7],
+ [7, 1, 4, 4, 8],
+ [7, 2, 4, 5, 7],
+ [8, 1, 5, 5, 7],
+ [8, 2, 4, 5, 8],
+ [9, 1, 5, 5, 8]],
+ [[0, 1, 3, 6, 6],
+ [1, 1, 4, 6, 6],
+ [1, 2, 3, 6, 7],
+ [2, 1, 5, 6, 6],
+ [2, 2, 3, 6, 8],
+ [3, 1, 3, 7, 7],
+ [3, 2, 4, 6, 7],
+ [4, 2, 5, 6, 7],
+ [4, 2, 4, 6, 8],
+ [4, 2, 3, 7, 8],
+ [5, 1, 3, 8, 8],
+ [5, 2, 5, 6, 8],
+ [6, 1, 4, 7, 7],
+ [7, 1, 5, 7, 7],
+ [7, 2, 4, 7, 8],
+ [8, 1, 4, 8, 8],
+ [8, 2, 5, 7, 8],
+ [9, 1, 5, 8, 8]],
+ [[0, 1, 6, 6, 6],
+ [1, 3, 6, 6, 7],
+ [2, 3, 6, 6, 8],
+ [3, 3, 6, 7, 7],
+ [4, 6, 6, 7, 8],
+ [5, 3, 6, 8, 8],
+ [6, 1, 7, 7, 7],
+ [7, 3, 7, 7, 8],
+ [8, 3, 7, 8, 8],
+ [9, 1, 8, 8, 8]],
+ ],
+ [
+ [[0, 1, 0, 0, 0, 0],
+ [1, 4, 0, 0, 0, 1],
+ [2, 4, 0, 0, 0, 2],
+ [3, 6, 0, 0, 1, 1],
+ [4, 12, 0, 0, 1, 2],
+ [5, 6, 0, 0, 2, 2],
+ [6, 4, 0, 1, 1, 1],
+ [7, 12, 0, 1, 1, 2],
+ [8, 12, 0, 1, 2, 2],
+ [9, 4, 0, 2, 2, 2],
+ [10, 1, 1, 1, 1, 1],
+ [11, 4, 1, 1, 1, 2],
+ [12, 6, 1, 1, 2, 2],
+ [13, 4, 1, 2, 2, 2],
+ [14, 1, 2, 2, 2, 2]],
+ [[0, 1, 0, 0, 0, 3],
+ [1, 1, 0, 0, 0, 4],
+ [1, 3, 0, 0, 1, 3],
+ [2, 1, 0, 0, 0, 5],
+ [2, 3, 0, 0, 2, 3],
+ [3, 3, 0, 1, 1, 3],
+ [3, 3, 0, 0, 1, 4],
+ [4, 3, 0, 0, 2, 4],
+ [4, 3, 0, 0, 1, 5],
+ [4, 6, 0, 1, 2, 3],
+ [5, 3, 0, 2, 2, 3],
+ [5, 3, 0, 0, 2, 5],
+ [6, 1, 1, 1, 1, 3],
+ [6, 3, 0, 1, 1, 4],
+ [7, 3, 1, 1, 2, 3],
+ [7, 3, 0, 1, 1, 5],
+ [7, 6, 0, 1, 2, 4],
+ [8, 3, 1, 2, 2, 3],
+ [8, 3, 0, 2, 2, 4],
+ [8, 6, 0, 1, 2, 5],
+ [9, 1, 2, 2, 2, 3],
+ [9, 3, 0, 2, 2, 5],
+ [10, 1, 1, 1, 1, 4],
+ [11, 1, 1, 1, 1, 5],
+ [11, 3, 1, 1, 2, 4],
+ [12, 3, 1, 2, 2, 4],
+ [12, 3, 1, 1, 2, 5],
+ [13, 1, 2, 2, 2, 4],
+ [13, 3, 1, 2, 2, 5],
+ [14, 1, 2, 2, 2, 5]],
+ [[0, 1, 0, 0, 0, 6],
+ [1, 1, 0, 0, 0, 7],
+ [1, 3, 0, 0, 1, 6],
+ [2, 1, 0, 0, 0, 8],
+ [2, 3, 0, 0, 2, 6],
+ [3, 3, 0, 1, 1, 6],
+ [3, 3, 0, 0, 1, 7],
+ [4, 3, 0, 0, 2, 7],
+ [4, 3, 0, 0, 1, 8],
+ [4, 6, 0, 1, 2, 6],
+ [5, 3, 0, 2, 2, 6],
+ [5, 3, 0, 0, 2, 8],
+ [6, 1, 1, 1, 1, 6],
+ [6, 3, 0, 1, 1, 7],
+ [7, 3, 1, 1, 2, 6],
+ [7, 3, 0, 1, 1, 8],
+ [7, 6, 0, 1, 2, 7],
+ [8, 3, 1, 2, 2, 6],
+ [8, 3, 0, 2, 2, 7],
+ [8, 6, 0, 1, 2, 8],
+ [9, 1, 2, 2, 2, 6],
+ [9, 3, 0, 2, 2, 8],
+ [10, 1, 1, 1, 1, 7],
+ [11, 1, 1, 1, 1, 8],
+ [11, 3, 1, 1, 2, 7],
+ [12, 3, 1, 2, 2, 7],
+ [12, 3, 1, 1, 2, 8],
+ [13, 1, 2, 2, 2, 7],
+ [13, 3, 1, 2, 2, 8],
+ [14, 1, 2, 2, 2, 8]],
+ [[0, 1, 0, 0, 3, 3],
+ [1, 2, 0, 1, 3, 3],
+ [1, 2, 0, 0, 3, 4],
+ [2, 2, 0, 2, 3, 3],
+ [2, 2, 0, 0, 3, 5],
+ [3, 1, 1, 1, 3, 3],
+ [3, 1, 0, 0, 4, 4],
+ [3, 4, 0, 1, 3, 4],
+ [4, 2, 1, 2, 3, 3],
+ [4, 2, 0, 0, 4, 5],
+ [4, 4, 0, 2, 3, 4],
+ [4, 4, 0, 1, 3, 5],
+ [5, 1, 2, 2, 3, 3],
+ [5, 1, 0, 0, 5, 5],
+ [5, 4, 0, 2, 3, 5],
+ [6, 2, 1, 1, 3, 4],
+ [6, 2, 0, 1, 4, 4],
+ [7, 2, 1, 1, 3, 5],
+ [7, 2, 0, 2, 4, 4],
+ [7, 4, 1, 2, 3, 4],
+ [7, 4, 0, 1, 4, 5],
+ [8, 2, 2, 2, 3, 4],
+ [8, 2, 0, 1, 5, 5],
+ [8, 4, 1, 2, 3, 5],
+ [8, 4, 0, 2, 4, 5],
+ [9, 2, 2, 2, 3, 5],
+ [9, 2, 0, 2, 5, 5],
+ [10, 1, 1, 1, 4, 4],
+ [11, 2, 1, 2, 4, 4],
+ [11, 2, 1, 1, 4, 5],
+ [12, 1, 2, 2, 4, 4],
+ [12, 1, 1, 1, 5, 5],
+ [12, 4, 1, 2, 4, 5],
+ [13, 2, 2, 2, 4, 5],
+ [13, 2, 1, 2, 5, 5],
+ [14, 1, 2, 2, 5, 5]],
+ [[0, 1, 0, 0, 3, 6],
+ [1, 1, 0, 0, 4, 6],
+ [1, 1, 0, 0, 3, 7],
+ [1, 2, 0, 1, 3, 6],
+ [2, 1, 0, 0, 5, 6],
+ [2, 1, 0, 0, 3, 8],
+ [2, 2, 0, 2, 3, 6],
+ [3, 1, 1, 1, 3, 6],
+ [3, 1, 0, 0, 4, 7],
+ [3, 2, 0, 1, 4, 6],
+ [3, 2, 0, 1, 3, 7],
+ [4, 1, 0, 0, 5, 7],
+ [4, 1, 0, 0, 4, 8],
+ [4, 2, 1, 2, 3, 6],
+ [4, 2, 0, 2, 4, 6],
+ [4, 2, 0, 2, 3, 7],
+ [4, 2, 0, 1, 5, 6],
+ [4, 2, 0, 1, 3, 8],
+ [5, 1, 2, 2, 3, 6],
+ [5, 1, 0, 0, 5, 8],
+ [5, 2, 0, 2, 5, 6],
+ [5, 2, 0, 2, 3, 8],
+ [6, 1, 1, 1, 4, 6],
+ [6, 1, 1, 1, 3, 7],
+ [6, 2, 0, 1, 4, 7],
+ [7, 1, 1, 1, 5, 6],
+ [7, 1, 1, 1, 3, 8],
+ [7, 2, 1, 2, 4, 6],
+ [7, 2, 1, 2, 3, 7],
+ [7, 2, 0, 2, 4, 7],
+ [7, 2, 0, 1, 5, 7],
+ [7, 2, 0, 1, 4, 8],
+ [8, 1, 2, 2, 4, 6],
+ [8, 1, 2, 2, 3, 7],
+ [8, 2, 1, 2, 5, 6],
+ [8, 2, 1, 2, 3, 8],
+ [8, 2, 0, 2, 5, 7],
+ [8, 2, 0, 2, 4, 8],
+ [8, 2, 0, 1, 5, 8],
+ [9, 1, 2, 2, 5, 6],
+ [9, 1, 2, 2, 3, 8],
+ [9, 2, 0, 2, 5, 8],
+ [10, 1, 1, 1, 4, 7],
+ [11, 1, 1, 1, 5, 7],
+ [11, 1, 1, 1, 4, 8],
+ [11, 2, 1, 2, 4, 7],
+ [12, 1, 2, 2, 4, 7],
+ [12, 1, 1, 1, 5, 8],
+ [12, 2, 1, 2, 5, 7],
+ [12, 2, 1, 2, 4, 8],
+ [13, 1, 2, 2, 5, 7],
+ [13, 1, 2, 2, 4, 8],
+ [13, 2, 1, 2, 5, 8],
+ [14, 1, 2, 2, 5, 8]],
+ [[0, 1, 0, 0, 6, 6],
+ [1, 2, 0, 1, 6, 6],
+ [1, 2, 0, 0, 6, 7],
+ [2, 2, 0, 2, 6, 6],
+ [2, 2, 0, 0, 6, 8],
+ [3, 1, 1, 1, 6, 6],
+ [3, 1, 0, 0, 7, 7],
+ [3, 4, 0, 1, 6, 7],
+ [4, 2, 1, 2, 6, 6],
+ [4, 2, 0, 0, 7, 8],
+ [4, 4, 0, 2, 6, 7],
+ [4, 4, 0, 1, 6, 8],
+ [5, 1, 2, 2, 6, 6],
+ [5, 1, 0, 0, 8, 8],
+ [5, 4, 0, 2, 6, 8],
+ [6, 2, 1, 1, 6, 7],
+ [6, 2, 0, 1, 7, 7],
+ [7, 2, 1, 1, 6, 8],
+ [7, 2, 0, 2, 7, 7],
+ [7, 4, 1, 2, 6, 7],
+ [7, 4, 0, 1, 7, 8],
+ [8, 2, 2, 2, 6, 7],
+ [8, 2, 0, 1, 8, 8],
+ [8, 4, 1, 2, 6, 8],
+ [8, 4, 0, 2, 7, 8],
+ [9, 2, 2, 2, 6, 8],
+ [9, 2, 0, 2, 8, 8],
+ [10, 1, 1, 1, 7, 7],
+ [11, 2, 1, 2, 7, 7],
+ [11, 2, 1, 1, 7, 8],
+ [12, 1, 2, 2, 7, 7],
+ [12, 1, 1, 1, 8, 8],
+ [12, 4, 1, 2, 7, 8],
+ [13, 2, 2, 2, 7, 8],
+ [13, 2, 1, 2, 8, 8],
+ [14, 1, 2, 2, 8, 8]],
+ [[0, 1, 0, 3, 3, 3],
+ [1, 1, 1, 3, 3, 3],
+ [1, 3, 0, 3, 3, 4],
+ [2, 1, 2, 3, 3, 3],
+ [2, 3, 0, 3, 3, 5],
+ [3, 3, 1, 3, 3, 4],
+ [3, 3, 0, 3, 4, 4],
+ [4, 3, 2, 3, 3, 4],
+ [4, 3, 1, 3, 3, 5],
+ [4, 6, 0, 3, 4, 5],
+ [5, 3, 2, 3, 3, 5],
+ [5, 3, 0, 3, 5, 5],
+ [6, 1, 0, 4, 4, 4],
+ [6, 3, 1, 3, 4, 4],
+ [7, 3, 2, 3, 4, 4],
+ [7, 3, 0, 4, 4, 5],
+ [7, 6, 1, 3, 4, 5],
+ [8, 3, 1, 3, 5, 5],
+ [8, 3, 0, 4, 5, 5],
+ [8, 6, 2, 3, 4, 5],
+ [9, 1, 0, 5, 5, 5],
+ [9, 3, 2, 3, 5, 5],
+ [10, 1, 1, 4, 4, 4],
+ [11, 1, 2, 4, 4, 4],
+ [11, 3, 1, 4, 4, 5],
+ [12, 3, 2, 4, 4, 5],
+ [12, 3, 1, 4, 5, 5],
+ [13, 1, 1, 5, 5, 5],
+ [13, 3, 2, 4, 5, 5],
+ [14, 1, 2, 5, 5, 5]],
+ [[0, 1, 0, 3, 3, 6],
+ [1, 1, 1, 3, 3, 6],
+ [1, 1, 0, 3, 3, 7],
+ [1, 2, 0, 3, 4, 6],
+ [2, 1, 2, 3, 3, 6],
+ [2, 1, 0, 3, 3, 8],
+ [2, 2, 0, 3, 5, 6],
+ [3, 1, 1, 3, 3, 7],
+ [3, 1, 0, 4, 4, 6],
+ [3, 2, 1, 3, 4, 6],
+ [3, 2, 0, 3, 4, 7],
+ [4, 1, 2, 3, 3, 7],
+ [4, 1, 1, 3, 3, 8],
+ [4, 2, 2, 3, 4, 6],
+ [4, 2, 1, 3, 5, 6],
+ [4, 2, 0, 4, 5, 6],
+ [4, 2, 0, 3, 5, 7],
+ [4, 2, 0, 3, 4, 8],
+ [5, 1, 2, 3, 3, 8],
+ [5, 1, 0, 5, 5, 6],
+ [5, 2, 2, 3, 5, 6],
+ [5, 2, 0, 3, 5, 8],
+ [6, 1, 1, 4, 4, 6],
+ [6, 1, 0, 4, 4, 7],
+ [6, 2, 1, 3, 4, 7],
+ [7, 1, 2, 4, 4, 6],
+ [7, 1, 0, 4, 4, 8],
+ [7, 2, 2, 3, 4, 7],
+ [7, 2, 1, 4, 5, 6],
+ [7, 2, 1, 3, 5, 7],
+ [7, 2, 1, 3, 4, 8],
+ [7, 2, 0, 4, 5, 7],
+ [8, 1, 1, 5, 5, 6],
+ [8, 1, 0, 5, 5, 7],
+ [8, 2, 2, 4, 5, 6],
+ [8, 2, 2, 3, 5, 7],
+ [8, 2, 2, 3, 4, 8],
+ [8, 2, 1, 3, 5, 8],
+ [8, 2, 0, 4, 5, 8],
+ [9, 1, 2, 5, 5, 6],
+ [9, 1, 0, 5, 5, 8],
+ [9, 2, 2, 3, 5, 8],
+ [10, 1, 1, 4, 4, 7],
+ [11, 1, 2, 4, 4, 7],
+ [11, 1, 1, 4, 4, 8],
+ [11, 2, 1, 4, 5, 7],
+ [12, 1, 2, 4, 4, 8],
+ [12, 1, 1, 5, 5, 7],
+ [12, 2, 2, 4, 5, 7],
+ [12, 2, 1, 4, 5, 8],
+ [13, 1, 2, 5, 5, 7],
+ [13, 1, 1, 5, 5, 8],
+ [13, 2, 2, 4, 5, 8],
+ [14, 1, 2, 5, 5, 8]],
+ [[0, 1, 0, 3, 6, 6],
+ [1, 1, 1, 3, 6, 6],
+ [1, 1, 0, 4, 6, 6],
+ [1, 2, 0, 3, 6, 7],
+ [2, 1, 2, 3, 6, 6],
+ [2, 1, 0, 5, 6, 6],
+ [2, 2, 0, 3, 6, 8],
+ [3, 1, 1, 4, 6, 6],
+ [3, 1, 0, 3, 7, 7],
+ [3, 2, 1, 3, 6, 7],
+ [3, 2, 0, 4, 6, 7],
+ [4, 1, 2, 4, 6, 6],
+ [4, 1, 1, 5, 6, 6],
+ [4, 2, 2, 3, 6, 7],
+ [4, 2, 1, 3, 6, 8],
+ [4, 2, 0, 5, 6, 7],
+ [4, 2, 0, 4, 6, 8],
+ [4, 2, 0, 3, 7, 8],
+ [5, 1, 2, 5, 6, 6],
+ [5, 1, 0, 3, 8, 8],
+ [5, 2, 2, 3, 6, 8],
+ [5, 2, 0, 5, 6, 8],
+ [6, 1, 1, 3, 7, 7],
+ [6, 1, 0, 4, 7, 7],
+ [6, 2, 1, 4, 6, 7],
+ [7, 1, 2, 3, 7, 7],
+ [7, 1, 0, 5, 7, 7],
+ [7, 2, 2, 4, 6, 7],
+ [7, 2, 1, 5, 6, 7],
+ [7, 2, 1, 4, 6, 8],
+ [7, 2, 1, 3, 7, 8],
+ [7, 2, 0, 4, 7, 8],
+ [8, 1, 1, 3, 8, 8],
+ [8, 1, 0, 4, 8, 8],
+ [8, 2, 2, 5, 6, 7],
+ [8, 2, 2, 4, 6, 8],
+ [8, 2, 2, 3, 7, 8],
+ [8, 2, 1, 5, 6, 8],
+ [8, 2, 0, 5, 7, 8],
+ [9, 1, 2, 3, 8, 8],
+ [9, 1, 0, 5, 8, 8],
+ [9, 2, 2, 5, 6, 8],
+ [10, 1, 1, 4, 7, 7],
+ [11, 1, 2, 4, 7, 7],
+ [11, 1, 1, 5, 7, 7],
+ [11, 2, 1, 4, 7, 8],
+ [12, 1, 2, 5, 7, 7],
+ [12, 1, 1, 4, 8, 8],
+ [12, 2, 2, 4, 7, 8],
+ [12, 2, 1, 5, 7, 8],
+ [13, 1, 2, 4, 8, 8],
+ [13, 1, 1, 5, 8, 8],
+ [13, 2, 2, 5, 7, 8],
+ [14, 1, 2, 5, 8, 8]],
+ [[0, 1, 0, 6, 6, 6],
+ [1, 1, 1, 6, 6, 6],
+ [1, 3, 0, 6, 6, 7],
+ [2, 1, 2, 6, 6, 6],
+ [2, 3, 0, 6, 6, 8],
+ [3, 3, 1, 6, 6, 7],
+ [3, 3, 0, 6, 7, 7],
+ [4, 3, 2, 6, 6, 7],
+ [4, 3, 1, 6, 6, 8],
+ [4, 6, 0, 6, 7, 8],
+ [5, 3, 2, 6, 6, 8],
+ [5, 3, 0, 6, 8, 8],
+ [6, 1, 0, 7, 7, 7],
+ [6, 3, 1, 6, 7, 7],
+ [7, 3, 2, 6, 7, 7],
+ [7, 3, 0, 7, 7, 8],
+ [7, 6, 1, 6, 7, 8],
+ [8, 3, 1, 6, 8, 8],
+ [8, 3, 0, 7, 8, 8],
+ [8, 6, 2, 6, 7, 8],
+ [9, 1, 0, 8, 8, 8],
+ [9, 3, 2, 6, 8, 8],
+ [10, 1, 1, 7, 7, 7],
+ [11, 1, 2, 7, 7, 7],
+ [11, 3, 1, 7, 7, 8],
+ [12, 3, 2, 7, 7, 8],
+ [12, 3, 1, 7, 8, 8],
+ [13, 1, 1, 8, 8, 8],
+ [13, 3, 2, 7, 8, 8],
+ [14, 1, 2, 8, 8, 8]],
+ [[0, 1, 3, 3, 3, 3],
+ [1, 4, 3, 3, 3, 4],
+ [2, 4, 3, 3, 3, 5],
+ [3, 6, 3, 3, 4, 4],
+ [4, 12, 3, 3, 4, 5],
+ [5, 6, 3, 3, 5, 5],
+ [6, 4, 3, 4, 4, 4],
+ [7, 12, 3, 4, 4, 5],
+ [8, 12, 3, 4, 5, 5],
+ [9, 4, 3, 5, 5, 5],
+ [10, 1, 4, 4, 4, 4],
+ [11, 4, 4, 4, 4, 5],
+ [12, 6, 4, 4, 5, 5],
+ [13, 4, 4, 5, 5, 5],
+ [14, 1, 5, 5, 5, 5]],
+ [[0, 1, 3, 3, 3, 6],
+ [1, 1, 3, 3, 3, 7],
+ [1, 3, 3, 3, 4, 6],
+ [2, 1, 3, 3, 3, 8],
+ [2, 3, 3, 3, 5, 6],
+ [3, 3, 3, 4, 4, 6],
+ [3, 3, 3, 3, 4, 7],
+ [4, 3, 3, 3, 5, 7],
+ [4, 3, 3, 3, 4, 8],
+ [4, 6, 3, 4, 5, 6],
+ [5, 3, 3, 5, 5, 6],
+ [5, 3, 3, 3, 5, 8],
+ [6, 1, 4, 4, 4, 6],
+ [6, 3, 3, 4, 4, 7],
+ [7, 3, 4, 4, 5, 6],
+ [7, 3, 3, 4, 4, 8],
+ [7, 6, 3, 4, 5, 7],
+ [8, 3, 4, 5, 5, 6],
+ [8, 3, 3, 5, 5, 7],
+ [8, 6, 3, 4, 5, 8],
+ [9, 1, 5, 5, 5, 6],
+ [9, 3, 3, 5, 5, 8],
+ [10, 1, 4, 4, 4, 7],
+ [11, 1, 4, 4, 4, 8],
+ [11, 3, 4, 4, 5, 7],
+ [12, 3, 4, 5, 5, 7],
+ [12, 3, 4, 4, 5, 8],
+ [13, 1, 5, 5, 5, 7],
+ [13, 3, 4, 5, 5, 8],
+ [14, 1, 5, 5, 5, 8]],
+ [[0, 1, 3, 3, 6, 6],
+ [1, 2, 3, 4, 6, 6],
+ [1, 2, 3, 3, 6, 7],
+ [2, 2, 3, 5, 6, 6],
+ [2, 2, 3, 3, 6, 8],
+ [3, 1, 4, 4, 6, 6],
+ [3, 1, 3, 3, 7, 7],
+ [3, 4, 3, 4, 6, 7],
+ [4, 2, 4, 5, 6, 6],
+ [4, 2, 3, 3, 7, 8],
+ [4, 4, 3, 5, 6, 7],
+ [4, 4, 3, 4, 6, 8],
+ [5, 1, 5, 5, 6, 6],
+ [5, 1, 3, 3, 8, 8],
+ [5, 4, 3, 5, 6, 8],
+ [6, 2, 4, 4, 6, 7],
+ [6, 2, 3, 4, 7, 7],
+ [7, 2, 4, 4, 6, 8],
+ [7, 2, 3, 5, 7, 7],
+ [7, 4, 4, 5, 6, 7],
+ [7, 4, 3, 4, 7, 8],
+ [8, 2, 5, 5, 6, 7],
+ [8, 2, 3, 4, 8, 8],
+ [8, 4, 4, 5, 6, 8],
+ [8, 4, 3, 5, 7, 8],
+ [9, 2, 5, 5, 6, 8],
+ [9, 2, 3, 5, 8, 8],
+ [10, 1, 4, 4, 7, 7],
+ [11, 2, 4, 5, 7, 7],
+ [11, 2, 4, 4, 7, 8],
+ [12, 1, 5, 5, 7, 7],
+ [12, 1, 4, 4, 8, 8],
+ [12, 4, 4, 5, 7, 8],
+ [13, 2, 5, 5, 7, 8],
+ [13, 2, 4, 5, 8, 8],
+ [14, 1, 5, 5, 8, 8]],
+ [[0, 1, 3, 6, 6, 6],
+ [1, 1, 4, 6, 6, 6],
+ [1, 3, 3, 6, 6, 7],
+ [2, 1, 5, 6, 6, 6],
+ [2, 3, 3, 6, 6, 8],
+ [3, 3, 4, 6, 6, 7],
+ [3, 3, 3, 6, 7, 7],
+ [4, 3, 5, 6, 6, 7],
+ [4, 3, 4, 6, 6, 8],
+ [4, 6, 3, 6, 7, 8],
+ [5, 3, 5, 6, 6, 8],
+ [5, 3, 3, 6, 8, 8],
+ [6, 1, 3, 7, 7, 7],
+ [6, 3, 4, 6, 7, 7],
+ [7, 3, 5, 6, 7, 7],
+ [7, 3, 3, 7, 7, 8],
+ [7, 6, 4, 6, 7, 8],
+ [8, 3, 4, 6, 8, 8],
+ [8, 3, 3, 7, 8, 8],
+ [8, 6, 5, 6, 7, 8],
+ [9, 1, 3, 8, 8, 8],
+ [9, 3, 5, 6, 8, 8],
+ [10, 1, 4, 7, 7, 7],
+ [11, 1, 5, 7, 7, 7],
+ [11, 3, 4, 7, 7, 8],
+ [12, 3, 5, 7, 7, 8],
+ [12, 3, 4, 7, 8, 8],
+ [13, 1, 4, 8, 8, 8],
+ [13, 3, 5, 7, 8, 8],
+ [14, 1, 5, 8, 8, 8]],
+ [[0, 1, 6, 6, 6, 6],
+ [1, 4, 6, 6, 6, 7],
+ [2, 4, 6, 6, 6, 8],
+ [3, 6, 6, 6, 7, 7],
+ [4, 12, 6, 6, 7, 8],
+ [5, 6, 6, 6, 8, 8],
+ [6, 4, 6, 7, 7, 7],
+ [7, 12, 6, 7, 7, 8],
+ [8, 12, 6, 7, 8, 8],
+ [9, 4, 6, 8, 8, 8],
+ [10, 1, 7, 7, 7, 7],
+ [11, 4, 7, 7, 7, 8],
+ [12, 6, 7, 7, 8, 8],
+ [13, 4, 7, 8, 8, 8],
+ [14, 1, 8, 8, 8, 8]],
+ ],
+]
+
+
+def rotate_cartesian_multipole(rmat, moments, mode):
+ """Compute rotated Cartesian multipole moment/expansion.
+
+ **Arguments:**
+
+ rmat
+ A (3,3) rotation matrix.
+
+ moments
+ A multipole moment/coeffs. The angular momentum is derived from the
+ length of this vector.
+
+ mode
+ A string containing either 'moments' or 'coeffs'. In case if
+ 'moments', a Cartesian multipole moment rotation is carried out. In
+ case of 'coeffs', the coefficients of a Cartesian multipole basis
+ are rotated.
+
+ **Returns:** rotated multipole.
+ """
+ l = ((9 + 8 * (len(moments) - 1)) ** 0.5 - 3) / 2
+ if l - np.round(l) > 1e-10:
+ raise ValueError('Could not determine l from number of moments.')
+ l = int(np.round(l))
+
+ if mode == 'coeffs':
+ rcoeffs = rmat.T.ravel()
+ elif mode == 'moments':
+ rcoeffs = rmat.ravel()
+ else:
+ raise NotImplementedError
+ result = np.zeros(len(moments))
+ for i0 in xrange(len(moments)):
+ rules = cartesian_transforms[l][i0]
+ for rule in rules:
+ i1 = rule[0]
+ factor = rule[1]
+ for j in rule[2:]:
+ factor *= rcoeffs[j]
+ if mode == 'coeffs':
+ result[i1] += moments[i0] * factor
+ elif mode == 'moments':
+ result[i0] += moments[i1] * factor
+ else:
+ raise NotImplementedError
+ return result
diff --git a/horton/meanfield/observable.py b/horton/meanfield/observable.py
index 3397a5ba..8482a046 100644
--- a/horton/meanfield/observable.py
+++ b/horton/meanfield/observable.py
@@ -20,11 +20,9 @@
# --
"""Base classes for energy terms and other observables of the wavefunction"""
-
import numpy as np
-from horton.utils import doc_inherit
-
+from .utils import doc_inherit
__all__ = [
'compute_dm_full',
@@ -205,8 +203,8 @@ def contract_direct(op, dm):
"""
if op.ndim == 3:
# Cholesky decomposition
- tmp = np.tensordot(op, dm, axes=([(1,2),(1,0)]))
- return np.tensordot(op, tmp, [0,0])
+ tmp = np.tensordot(op, dm, axes=([(1, 2), (1, 0)]))
+ return np.tensordot(op, tmp, [0, 0])
elif op.ndim == 4:
# Normal case
return np.einsum('abcd,bd->ac', op, dm)
@@ -353,8 +351,8 @@ def contract_exchange(op, dm):
"""
if op.ndim == 3:
# Cholesky decomposition
- tmp = np.tensordot(op, dm, axes=([1,1]))
- return np.tensordot(op, tmp, ([0,2],[0,2]))
+ tmp = np.tensordot(op, dm, axes=([1, 1]))
+ return np.tensordot(op, tmp, ([0, 2], [0, 2]))
elif op.ndim == 4:
return np.einsum('abcd,cb->ad', op, dm)
else:
@@ -406,12 +404,12 @@ def compute_energy(self, cache):
def add_fock(self, cache, fock_alpha):
self._update_exchange(cache)
exchange_alpha = cache['op_%s_alpha' % self.label]
- fock_alpha -= self.fraction*exchange_alpha
+ fock_alpha -= self.fraction * exchange_alpha
@doc_inherit(Observable)
def add_dot_hessian(self, cache, output_alpha):
delta_dm_alpha = cache.load('delta_dm_alpha')
- output_alpha -= (0.5*self.fraction)*contract_exchange(self.op_alpha, delta_dm_alpha)
+ output_alpha -= (0.5 * self.fraction) * contract_exchange(self.op_alpha, delta_dm_alpha)
class UExchangeTerm(Observable):
@@ -455,7 +453,7 @@ def _update_exchange(self, cache):
# beta
dm_beta = cache['dm_beta']
exchange_beta, new = cache.load('op_%s_beta' % self.label,
- alloc=dm_beta.shape)
+ alloc=dm_beta.shape)
if new:
exchange_beta[:] = contract_exchange(self.op_beta, dm_beta)
@@ -466,20 +464,20 @@ def compute_energy(self, cache):
exchange_beta = cache['op_%s_beta' % self.label]
dm_alpha = cache['dm_alpha']
dm_beta = cache['dm_beta']
- return (-0.5*self.fraction)*np.einsum('ab,ba', exchange_alpha, dm_alpha) + \
- (-0.5*self.fraction)*np.einsum('ab,ba', exchange_beta, dm_beta)
+ return (-0.5 * self.fraction) * np.einsum('ab,ba', exchange_alpha, dm_alpha) + \
+ (-0.5 * self.fraction) * np.einsum('ab,ba', exchange_beta, dm_beta)
@doc_inherit(Observable)
def add_fock(self, cache, fock_alpha, fock_beta):
self._update_exchange(cache)
exchange_alpha = cache['op_%s_alpha' % self.label]
- fock_alpha -= self.fraction*exchange_alpha
+ fock_alpha -= self.fraction * exchange_alpha
exchange_beta = cache['op_%s_beta' % self.label]
- fock_beta -= self.fraction*exchange_beta
+ fock_beta -= self.fraction * exchange_beta
@doc_inherit(Observable)
def add_dot_hessian(self, cache, output_alpha, output_beta):
delta_dm_alpha = cache.load('delta_dm_alpha')
- output_alpha -= self.fraction*contract_exchange(self.op_alpha, delta_dm_alpha)
+ output_alpha -= self.fraction * contract_exchange(self.op_alpha, delta_dm_alpha)
delta_dm_beta = cache.load('delta_dm_beta')
- output_beta -= self.fraction*contract_exchange(self.op_beta, delta_dm_beta)
+ output_beta -= self.fraction * contract_exchange(self.op_beta, delta_dm_beta)
diff --git a/horton/meanfield/occ.py b/horton/meanfield/occ.py
index 5bc544f5..cb929017 100644
--- a/horton/meanfield/occ.py
+++ b/horton/meanfield/occ.py
@@ -20,15 +20,12 @@
# --
"""Occupation number models"""
-
import numpy as np
-from horton.exceptions import ElectronCountError
-from horton.quadprog import find_1d_root
-from horton.constants import boltzmann
-from horton.log import biblio
-from horton.utils import doc_inherit
-
+from .quadprog import find_1d_root
+from .exceptions import ElectronCountError
+from .utils import boltzmann
+from .utils import doc_inherit
__all__ = [
'FixedOccModel', 'AufbauOccModel', 'AufbauSpinOccModel', 'FermiOccModel',
@@ -36,20 +33,20 @@
class OccModel(object):
- '''Base class for the occupation models'''
+ """Base class for the occupation models"""
def assign(self, *orbs):
- '''Assign occupation numbers to the Orbitals objects
+ """Assign occupation numbers to the Orbitals objects
**Arguments:**
orb_alpha, orb_beta, ...
Orbitals objects
- '''
+ """
raise NotImplementedError
def check_dms(self, overlap, *dms, **kwargs):
- '''Test if the given density matrices contain the right number of electrons
+ """Test if the given density matrices contain the right number of electrons
**Arguments:**
@@ -63,7 +60,7 @@ def check_dms(self, overlap, *dms, **kwargs):
eps (default=1e-4)
The allowed deviation.
- '''
+ """
raise NotImplementedError
@@ -91,26 +88,27 @@ def check_dms(self, overlap, *dms, **kwargs):
class AufbauOccModel(OccModel):
- '''The standard Aufbau occupation number model.
+ """The standard Aufbau occupation number model.
This model just fills up all the lowest lying orbitals. When the total
number of electrons in one channel is fractional, the fractional electron
is put in the HOMO orbital.
- '''
+ """
def __init__(self, *noccs):
- '''
+ """
**Arguments:**
nalpha, nbeta, ...
The number of electrons in each channel.
- '''
+ """
for nocc in noccs:
if nocc < 0:
raise ElectronCountError('Negative number of electrons is not allowed.')
if sum(noccs) == 0:
raise ElectronCountError('At least one electron is required.')
self.noccs = noccs
+ self.biblio = []
@doc_inherit(OccModel)
def assign(self, *orbs):
@@ -118,7 +116,8 @@ def assign(self, *orbs):
raise TypeError('Expected %i Orbitals objects, got %i.' % (len(self.nocc), len(orbs)))
for orb, nocc in zip(orbs, self.noccs):
if orb.nfn < nocc:
- raise ElectronCountError('The number of orbitals must not be lower than the number of alpha or beta electrons.')
+ raise ElectronCountError(
+ 'The number of orbitals must not be lower than the number of alpha or beta electrons.')
# It is assumed that the orbitals are sorted from low to high energy.
if nocc == int(nocc):
orb.occupations[:nocc] = 1.0
@@ -140,14 +139,15 @@ def check_dms(self, overlap, *dms, **kwargs):
class AufbauSpinOccModel(OccModel):
- '''This Aufbau model only applies to unrestricted wavefunctions'''
+ """This Aufbau model only applies to unrestricted wavefunctions"""
+
def __init__(self, nel):
- '''
+ """
**Arguments:**
nel
The total number of electrons (alpha + beta)
- '''
+ """
if nel <= 0:
raise ElectronCountError('The number of electron must be positive.')
self.nel = nel
@@ -175,9 +175,10 @@ def check_dms(self, overlap, *dms, **kwargs):
class FermiOccModel(AufbauOccModel):
- '''Fermi smearing electron occupation model'''
+ """Fermi smearing electron occupation model"""
+
def __init__(self, *noccs, **kwargs):
- r'''
+ r"""
**Arguments:**
nalpha, nbeta, ...
@@ -209,7 +210,7 @@ def __init__(self, *noccs, **kwargs):
where :math:`n_\text{occ}` can be set per (spin) channel. This is
only a part of the methodology presented in [rabuck1999]_.
- '''
+ """
temperature = kwargs.pop('temperature', 300)
eps = kwargs.pop('eps', 1e-8)
if len(kwargs) > 0:
@@ -221,28 +222,29 @@ def __init__(self, *noccs, **kwargs):
self.temperature = float(temperature)
self.eps = eps
AufbauOccModel.__init__(self, *noccs)
- biblio.cite('rabuck1999', 'the Fermi broading method to assign orbital occupations')
+ self.biblio.append(
+ ['rabuck1999', 'the Fermi broading method to assign orbital occupations'])
@doc_inherit(OccModel)
def assign(self, *orbs):
- beta = 1.0/self.temperature/boltzmann
+ beta = 1.0 / self.temperature / boltzmann
for orb, nocc in zip(orbs, self.noccs):
def get_occ(mu):
occ = np.zeros(orb.nfn)
mask = orb.energies < mu
- e = np.exp(beta*(orb.energies[mask] - mu))
- occ[mask] = 1.0/(e + 1.0)
+ e = np.exp(beta * (orb.energies[mask] - mu))
+ occ[mask] = 1.0 / (e + 1.0)
mask = ~mask
- e = np.exp(-beta*(orb.energies[mask] - mu))
- occ[mask] = e/(1.0 + e)
+ e = np.exp(-beta * (orb.energies[mask] - mu))
+ occ[mask] = e / (1.0 + e)
return occ
def error(mu):
return nocc - get_occ(mu).sum()
- mu0 = orb.energies[orb.nfn/2]
+ mu0 = orb.energies[orb.nfn / 2]
error0 = error(mu0)
- delta = 0.1*(1 - 2*(error0 < 0))
+ delta = 0.1 * (1 - 2 * (error0 < 0))
for i in xrange(100):
mu1 = mu0 + delta
error1 = error(mu1)
diff --git a/horton/meanfield/orbitals.py b/horton/meanfield/orbitals.py
index a335bdb9..e1fea4e9 100644
--- a/horton/meanfield/orbitals.py
+++ b/horton/meanfield/orbitals.py
@@ -20,15 +20,12 @@
# --
"""Orbital class."""
-
import numpy as np
from scipy.linalg import eigh
-from horton.utils import check_type
-from horton.log import log
-
+from .utils import check_type
-__all__ = ['Orbitals']
+__all__ = ['Orbitals', 'check_dm']
class Orbitals(object):
@@ -95,11 +92,11 @@ def _get_occupations(self):
def __eq__(self, other):
"""Compare self with other."""
return isinstance(other, Orbitals) and \
- other.nbasis == self.nbasis and \
- other.nfn == self.nfn and \
- (other._coeffs == self._coeffs).all() and \
- (other._energies == self._energies).all() and \
- (other._occupations == self._occupations).all()
+ other.nbasis == self.nbasis and \
+ other.nfn == self.nfn and \
+ (other._coeffs == self._coeffs).all() and \
+ (other._energies == self._energies).all() and \
+ (other._occupations == self._occupations).all()
@classmethod
def from_hdf5(cls, grp):
@@ -183,7 +180,7 @@ def permute_orbitals(self, permutation):
permutation : np.ndarray, dtype=int, shape=(nbasis,)
An array that defines the new order of the orbitals.
"""
- self._coeffs[:] = self.coeffs[:,permutation]
+ self._coeffs[:] = self.coeffs[:, permutation]
def change_basis_signs(self, signs):
"""Correct for different sign conventions of the basis functions.
@@ -193,7 +190,7 @@ def change_basis_signs(self, signs):
signs : np.ndarray, dtype=int, shape=(nbasis,)
An array with sign changes indicated by +1 and -1.
"""
- self._coeffs *= signs.reshape(-1,1)
+ self._coeffs *= signs.reshape(-1, 1)
def check_normalization(self, overlap, eps=1e-4):
"""Check that the occupied orbitals are normalized.
@@ -210,9 +207,9 @@ def check_normalization(self, overlap, eps=1e-4):
for i in xrange(self.nfn):
if self.occupations[i] == 0:
continue
- norm = np.dot(self._coeffs[:,i], np.dot(overlap, self._coeffs[:,i]))
- #print i, norm
- assert abs(norm-1) < eps, 'The orbitals are not normalized!'
+ norm = np.dot(self._coeffs[:, i], np.dot(overlap, self._coeffs[:, i]))
+ # print i, norm
+ assert abs(norm - 1) < eps, 'The orbitals are not normalized!'
def check_orthonormality(self, overlap, eps=1e-4):
"""Check that the occupied orbitals are orthogonal and normalized.
@@ -229,12 +226,12 @@ def check_orthonormality(self, overlap, eps=1e-4):
for i0 in xrange(self.nfn):
if self.occupations[i0] == 0:
continue
- for i1 in xrange(i0+1):
+ for i1 in xrange(i0 + 1):
if self.occupations[i1] == 0:
continue
- dot = np.dot(self._coeffs[:,i0], np.dot(overlap, self._coeffs[:,i1]))
+ dot = np.dot(self._coeffs[:, i0], np.dot(overlap, self._coeffs[:, i1]))
if i0 == i1:
- assert abs(dot-1) < eps
+ assert abs(dot - 1) < eps
else:
assert abs(dot) < eps
@@ -253,9 +250,9 @@ def error_eigen(self, fock, overlap):
error : float
The RMSD error on the orbital energies.
"""
- errors = np.dot(fock, (self.coeffs)) \
- - self.energies*np.dot(overlap, (self.coeffs))
- return np.sqrt((abs(errors)**2).mean())
+ errors = np.dot(fock, self.coeffs) \
+ - self.energies * np.dot(overlap, self.coeffs)
+ return np.sqrt((abs(errors) ** 2).mean())
def from_fock(self, fock, overlap):
"""Diagonalize a Fock matrix to obtain orbitals and energies.
@@ -271,7 +268,7 @@ def from_fock(self, fock, overlap):
"""
evals, evecs = eigh(fock, overlap)
self._energies[:] = evals[:self.nfn]
- self._coeffs[:] = evecs[:,:self.nfn]
+ self._coeffs[:] = evecs[:, :self.nfn]
def from_fock_and_dm(self, fock, dm, overlap, epstol=1e-8):
"""Combined diagonalization of a Fock and a density matrix.
@@ -307,7 +304,7 @@ def from_fock_and_dm(self, fock, dm, overlap, epstol=1e-8):
clusters = []
begin = 0
for ifn in xrange(1, self.nfn):
- if abs(self.energies[ifn] - self.energies[ifn-1]) > epstol:
+ if abs(self.energies[ifn] - self.energies[ifn - 1]) > epstol:
end = ifn
clusters.append([begin, end])
begin = ifn
@@ -318,20 +315,22 @@ def from_fock_and_dm(self, fock, dm, overlap, epstol=1e-8):
sds = np.dot(overlap.T, np.dot(dm, overlap))
for begin, end in clusters:
if end - begin == 1:
- self.occupations[begin] = np.dot(self.coeffs[:,begin], np.dot(sds, self.coeffs[:,begin]))
+ self.occupations[begin] = np.dot(self.coeffs[:, begin],
+ np.dot(sds, self.coeffs[:, begin]))
else:
# Build matrix
mat = np.dot(self.coeffs[:, begin:end].T, np.dot(sds, self.coeffs[:, begin:end]))
# Diagonalize and reverse order
evals, evecs = np.linalg.eigh(mat)
evals = evals[::-1]
- evecs = evecs[:,::-1]
+ evecs = evecs[:, ::-1]
# Rotate the orbitals
- self.coeffs[:,begin:end] = np.dot(self.coeffs[:,begin:end], evecs)
+ self.coeffs[:, begin:end] = np.dot(self.coeffs[:, begin:end], evecs)
# Compute expectation values
self.occupations[begin:end] = evals
- for i0 in xrange(end-begin):
- self.energies[begin+i0] = np.dot(self.coeffs[:,begin+i0], np.dot(fock, self.coeffs[:,begin+i0]))
+ for i0 in xrange(end - begin):
+ self.energies[begin + i0] = np.dot(self.coeffs[:, begin + i0],
+ np.dot(fock, self.coeffs[:, begin + i0]))
def derive_naturals(self, dm, overlap):
"""Derive natural orbitals from a given density matrix and assign the result to self.
@@ -347,7 +346,7 @@ def derive_naturals(self, dm, overlap):
sds = np.dot(overlap.T, np.dot(dm, overlap))
# Diagonalize and compute eigenvalues
evals, evecs = eigh(sds, overlap)
- self._coeffs[:] = evecs[:,:self.nfn]
+ self._coeffs[:] = evecs[:, :self.nfn]
self._occupations[:] = evals
self._energies[:] = 0.0
@@ -364,7 +363,7 @@ def get_homo_index(self, offset=0):
raise ValueError('Offset must be zero or positive.')
homo_indexes = self.occupations.nonzero()[0]
if len(homo_indexes) > offset:
- return homo_indexes[len(homo_indexes)-offset-1]
+ return homo_indexes[len(homo_indexes) - offset - 1]
homo_index = property(get_homo_index)
@@ -394,7 +393,7 @@ def get_lumo_index(self, offset=0):
"""
if offset < 0:
raise ValueError('Offset must be zero or positive.')
- lumo_indexes = (self.occupations==0.0).nonzero()[0]
+ lumo_indexes = (self.occupations == 0.0).nonzero()[0]
if len(lumo_indexes) > offset:
return lumo_indexes[offset]
@@ -429,9 +428,10 @@ def to_dm(self, other=None):
The density matrix.
"""
if other is None:
- return np.dot(self._coeffs*self.occupations, self._coeffs.T)
+ return np.dot(self._coeffs * self.occupations, self._coeffs.T)
else:
- return np.dot(self._coeffs*(self.occupations*other.occupations)**0.5, other._coeffs.T)
+ return np.dot(self._coeffs * (self.occupations * other.occupations) ** 0.5,
+ other._coeffs.T)
def rotate_random(self):
"""Apply random unitary transformation distributed with Haar measure.
@@ -454,14 +454,14 @@ def rotate_2orbitals(self, angle=0.7853981633974483, index0=None, index1=None):
The attributes ``energies`` and ``occupations`` are not altered.
"""
- if index0 == None:
+ if index0 is None:
index0 = self.homo_index
- if index1 == None:
+ if index1 is None:
index1 = self.lumo_index
- old0 = self.coeffs[:,index0].copy()
- old1 = self.coeffs[:,index1].copy()
- self.coeffs[:,index0] = np.cos(angle)*old0 - np.sin(angle)*old1
- self.coeffs[:,index1] = np.sin(angle)*old0 + np.cos(angle)*old1
+ old0 = self.coeffs[:, index0].copy()
+ old1 = self.coeffs[:, index1].copy()
+ self.coeffs[:, index0] = np.cos(angle) * old0 - np.sin(angle) * old1
+ self.coeffs[:, index1] = np.sin(angle) * old0 + np.cos(angle) * old1
def swap_orbitals(self, swaps):
"""Change the order of the orbitals using pair-exchange.
@@ -478,12 +478,41 @@ def swap_orbitals(self, swaps):
raise TypeError('The argument swaps has the wrong shape/type.')
for iswap in range(len(swaps)):
index0, index1 = swaps[iswap]
- if log.do_medium:
- log(' Swapping orbitals %i and %i' %(index0, index1))
- tmp = self.coeffs[:,index0].copy()
- self.coeffs[:,index0] = self.coeffs[:,index1]
- self.coeffs[:,index1] = tmp
- self.energies[index0], self.energies[index1] =\
+ print('5: Swapping orbitals %i and %i' % (index0, index1))
+ tmp = self.coeffs[:, index0].copy()
+ self.coeffs[:, index0] = self.coeffs[:, index1]
+ self.coeffs[:, index1] = tmp
+ self.energies[index0], self.energies[index1] = \
self.energies[index1], self.energies[index0]
- self.occupations[index0], self.occupations[index1] =\
+ self.occupations[index0], self.occupations[index1] = \
self.occupations[index1], self.occupations[index0]
+
+
+def check_dm(dm, overlap, eps=1e-4, occ_max=1.0):
+ """Check if the density matrix has eigenvalues in the proper range.
+
+ Parameters
+ ----------
+ dm : np.ndarray, shape=(nbasis, nbasis), dtype=float
+ The density matrix
+ overlap : np.ndarray, shape=(nbasis, nbasis), dtype=float
+ The overlap matrix
+ eps : float
+ The threshold on the eigenvalue inequalities.
+ occ_max : float
+ The maximum occupation.
+
+ Raises
+ ------
+ ValueError
+ When the density matrix has wrong eigenvalues.
+ """
+ # construct natural orbitals
+ orb = Orbitals(dm.shape[0])
+ orb.derive_naturals(dm, overlap)
+ if orb.occupations.min() < -eps:
+ raise ValueError('The density matrix has eigenvalues considerably smaller than '
+ 'zero. error=%e' % (orb.occupations.min()))
+ if orb.occupations.max() > occ_max + eps:
+ raise ValueError('The density matrix has eigenvalues considerably larger than '
+ 'max. error=%e' % (orb.occupations.max() - 1))
diff --git a/horton/meanfield/project.py b/horton/meanfield/project.py
index 899e3935..5cadf299 100644
--- a/horton/meanfield/project.py
+++ b/horton/meanfield/project.py
@@ -18,15 +18,15 @@
# along with this program; if not, see
#
# --
-'''Projection of 1-electron orbitals to a new basis set'''
+"""Projection of 1-electron orbitals to a new basis set"""
+# TODO: Move to gobasis?
import numpy as np
from scipy.linalg import sqrtm
from horton.gbasis.cext import GOBasis
-
__all__ = ['ProjectionError', 'project_orbitals_mgs', 'project_orbitals_ortho']
@@ -35,7 +35,7 @@ class ProjectionError(Exception):
def project_orbitals_mgs(obasis0, obasis1, orb0, orb1, eps=1e-10):
- '''Project the orbitals onto a new basis set with the modified Gram-Schmidt algorithm.
+ """Project the orbitals onto a new basis set with the modified Gram-Schmidt algorithm.
The orbitals in ``orb0`` (w.r.t. ``obasis0``) are projected onto ``obasis1`` and
stored in ``orb1``.
@@ -69,7 +69,7 @@ def project_orbitals_mgs(obasis0, obasis1, orb0, orb1, eps=1e-10):
If the number of orbitals in ``orb1`` is too small to store all projected
orbitals, an error is raised.
- '''
+ """
# Compute the overlap matrix of the combined orbital basis
obasis_both = GOBasis.concatenate(obasis0, obasis1)
olp_both = obasis_both.compute_overlap()
@@ -90,14 +90,14 @@ def project_orbitals_mgs(obasis0, obasis1, orb0, orb1, eps=1e-10):
if i1 > orb1.nfn:
raise ProjectionError('Not enough functions available in orb1 to store the '
'projected orbitals.')
- orb1.coeffs[:,i1] = np.dot(projector, orb0.coeffs[:,i0])
+ orb1.coeffs[:, i1] = np.dot(projector, orb0.coeffs[:, i0])
orb1.occupations[i1] = orb0.occupations[i0]
i1 += 1
# clear all parts of orb1 that were not touched by the projection loop
ntrans = i1
del i1
- orb1.coeffs[:,ntrans:] = 0.0
+ orb1.coeffs[:, ntrans:] = 0.0
orb1.occupations[ntrans:] = 0.0
orb1.energies[:] = 0.0
@@ -112,7 +112,7 @@ def dot22(a, b):
# Subtract overlap with previous orbitals
for j1 in xrange(i1):
other = orb1.coeffs[:, j1]
- orb -= other*dot22(other, orb)/np.sqrt(dot22(other, other))
+ orb -= other * dot22(other, orb) / np.sqrt(dot22(other, other))
# Renormalize
norm = np.sqrt(dot22(orb, orb))
@@ -123,7 +123,7 @@ def dot22(a, b):
def project_orbitals_ortho(olp0, olp1, orb0, orb1):
- r'''Re-orthogonalize the orbitals .
+ r"""Re-orthogonalize the orbitals .
The orbitals in ``orb0`` (w.r.t. ``obasis0``) are re-orthonormalized w.r.t.
``obasis1`` and stored in ``orb1``.
@@ -162,7 +162,8 @@ def project_orbitals_ortho(olp0, olp1, orb0, orb1):
orthogonalized atomic basis sets. The latter is only the case when the
old and new atomic basis sets are very similar, e.g. for small geometric
changes.
- '''
+ """
+
def helper_olp(olp):
if isinstance(olp, GOBasis):
obasis = olp
diff --git a/horton/quadprog.py b/horton/meanfield/quadprog.py
similarity index 100%
rename from horton/quadprog.py
rename to horton/meanfield/quadprog.py
diff --git a/horton/meanfield/response.py b/horton/meanfield/response.py
index f0879b1f..734cacb9 100644
--- a/horton/meanfield/response.py
+++ b/horton/meanfield/response.py
@@ -18,19 +18,15 @@
# along with this program; if not, see
#
# --
-'''Evaluation of response functions'''
+"""Evaluation of response functions"""
import numpy as np
-from horton.log import timer
-
-
__all__ = ['compute_noninteracting_response']
-@timer.with_section('KS Response')
def compute_noninteracting_response(orb, operators, work=None):
- '''Compute the non-interacting response matrix for a given orbital expansion
+ """Compute the non-interacting response matrix for a given orbital expansion
**Arguments:**
@@ -51,7 +47,7 @@ def compute_noninteracting_response(orb, operators, work=None):
orbitals are present at the fermi level. For example, in case of
fractional occupations in DFT, this method does not give the correct
non-interacting response matrix.
- '''
+ """
# Convert the operators to the orbital basis
coeffs = orb.coeffs
norb = orb.nfn
@@ -66,10 +62,11 @@ def compute_noninteracting_response(orb, operators, work=None):
energies = orb.energies
occupations = orb.occupations
with np.errstate(invalid='ignore'):
- prefacs = np.subtract.outer(occupations, occupations)/np.subtract.outer(energies, energies)
+ prefacs = np.subtract.outer(occupations, occupations) / np.subtract.outer(energies,
+ energies)
# Purge divisions by zero. If degeneracies occur at the fermi level, this
# way of computing the noninteracting response matrix is not correct anyway.
- #for iorb in xrange(norb):
+ # for iorb in xrange(norb):
# prefacs[iorb,iorb] = 0.0
mask = occupations == occupations.reshape(-1, 1)
mask |= energies == energies.reshape(-1, 1)
@@ -87,9 +84,9 @@ def compute_noninteracting_response(orb, operators, work=None):
# while the complex conjugate corresponds to the upper diagonal of prefacs.)
result = np.zeros((nop, nop), float)
for iop0 in xrange(nop):
- for iop1 in xrange(iop0+1):
+ for iop1 in xrange(iop0 + 1):
# evaluate the sum over states expression
- state_sum = (work[iop0]*work[iop1]*prefacs).sum()
+ state_sum = (work[iop0] * work[iop1] * prefacs).sum()
# store the state sum
result[iop0, iop1] = state_sum
diff --git a/horton/meanfield/rotate.py b/horton/meanfield/rotate.py
index 3677247a..84d8620f 100644
--- a/horton/meanfield/rotate.py
+++ b/horton/meanfield/rotate.py
@@ -18,19 +18,18 @@
# along with this program; if not, see
#
# --
-'''Rotation of orbitals'''
-
+"""Rotation of orbitals"""
import numpy as np
-from horton.gbasis.cext import fac2
-from horton.moments import rotate_cartesian_multipole, get_cartesian_powers
+from horton.meanfield.moments import get_cartesian_powers, rotate_cartesian_multipole
+from .utils import fac2
__all__ = ['rotate_coeffs']
-def rotate_coeffs(coeffs, obasis, rmat):
- '''Apply a rotation to all cartesian basis functions.
+def rotate_coeffs(coeffs, shell_types, rmat):
+ """Apply a rotation to all cartesian basis functions.
**Arguments:**
@@ -43,40 +42,44 @@ def rotate_coeffs(coeffs, obasis, rmat):
rmat
The rotation matrix.
- '''
- if obasis.nbasis != coeffs.shape[0]:
- raise TypeError('The shape of the coefficients array does not match the basis set size')
- if obasis.shell_types.min() < 0:
+ """
+ if shell_types.min() < 0:
raise TypeError('Pure functions are not supported in rotate_coeffs.')
+ nshell = shell_types.size
+
result = np.zeros(coeffs.shape)
# 1) undo the part normalization of the basis functions due to the cartesian powers
- lmax = obasis.shell_types.max()
+ lmax = shell_types.max()
powers = get_cartesian_powers(lmax)
factors = []
- for ishell in xrange(obasis.nshell):
- shell_type = obasis.shell_types[ishell]
- icart0 = ((shell_type+2)*(shell_type+1)*(shell_type))/6
- shellsize = ((shell_type+2)*(shell_type+1))/2
+ for ishell in xrange(nshell):
+ shell_type = shell_types[ishell]
+ icart0 = ((shell_type + 2) * (shell_type + 1) * shell_type) / 6
+ shellsize = ((shell_type + 2) * (shell_type + 1)) / 2
for ifn in xrange(shellsize):
- ipow = icart0+ifn
- factors.append(np.sqrt(fac2(2*powers[ipow,0]-1)*fac2(2*powers[ipow,1]-1)*fac2(2*powers[ipow,2]-1)))
+ ipow = icart0 + ifn
+ factors.append(np.sqrt(
+ fac2(2 * powers[ipow, 0] - 1) * fac2(2 * powers[ipow, 1] - 1) * fac2(
+ 2 * powers[ipow, 2] - 1)))
factors = np.array(factors)
# replace the array coeffs by the one with undone normalization
- coeffs = coeffs/factors.reshape(-1,1)
+ coeffs = coeffs / factors.reshape(-1, 1)
# 2) the actual rotation
ibasis0 = 0
- for ishell in xrange(obasis.nshell):
- shell_type = obasis.shell_types[ishell]
- icart0 = ((shell_type+2)*(shell_type+1)*(shell_type))/6
- shellsize = ((shell_type+2)*(shell_type+1))/2
+ for ishell in xrange(nshell):
+ shell_type = shell_types[ishell]
+ shellsize = ((shell_type + 2) * (shell_type + 1)) / 2
for iorb in xrange(coeffs.shape[1]):
- result[ibasis0:ibasis0+shellsize, iorb] = rotate_cartesian_multipole(rmat, coeffs[ibasis0:ibasis0+shellsize, iorb], 'coeffs')
+ result[ibasis0:ibasis0 + shellsize, iorb] = rotate_cartesian_multipole(rmat, coeffs[
+ ibasis0:ibasis0 + shellsize,
+ iorb],
+ 'coeffs')
ibasis0 += shellsize
# 3) apply the part of the normalization of the basis functions due to the cartesian powers
- result *= factors.reshape(-1,1)
+ result *= factors.reshape(-1, 1)
return result
diff --git a/horton/meanfield/scf.py b/horton/meanfield/scf.py
index 01108bf9..dbcc76c1 100644
--- a/horton/meanfield/scf.py
+++ b/horton/meanfield/scf.py
@@ -20,14 +20,11 @@
# --
"""Basic Self-Consistent Field (SCF) algorithm."""
-
import numpy as np
-from horton.log import log, timer
-from horton.exceptions import NoSCFConvergence
-from horton.meanfield.convergence import convergence_error_eigen
-from horton.meanfield.utils import get_level_shift
-
+from .exceptions import NoSCFConvergence
+from .convergence import convergence_error_eigen
+from .utils import get_level_shift
__all__ = ['PlainSCFSolver']
@@ -62,7 +59,6 @@ def __init__(self, threshold=1e-8, maxiter=128, skip_energy=False, level_shift=0
raise ValueError('The level_shift argument cannot be negative.')
self.level_shift = level_shift
- @timer.with_section('SCF')
def __call__(self, ham, overlap, occ_model, *orbs):
"""Find a self-consistent set of orbitals.
@@ -80,18 +76,18 @@ def __call__(self, ham, overlap, occ_model, *orbs):
"""
# Some type checking
if ham.ndm != len(orbs):
- raise TypeError('The number of initial orbital expansions does not match the Hamiltonian.')
+ raise TypeError(
+ 'The number of initial orbital expansions does not match the Hamiltonian.')
# Impose the requested occupation numbers
occ_model.assign(*orbs)
# Check the orthogonality of the orbitals
for orb in orbs:
orb.check_normalization(overlap)
- if log.do_medium:
- log('Starting plain SCF solver. ndm=%i' % ham.ndm)
- log.hline()
- log('Iter Error')
- log.hline()
+ print('Starting plain SCF solver. ndm=%i' % ham.ndm)
+ print("5: " + "-" * 70)
+ print('Iter Error')
+ print("5: " + "-" * 70)
focks = [np.zeros(overlap.shape) for i in xrange(ham.ndm)]
dms = [None] * ham.ndm
@@ -109,8 +105,7 @@ def __call__(self, ham, overlap, occ_model, *orbs):
error = 0.0
for i in xrange(ham.ndm):
error += orbs[i].error_eigen(focks[i], overlap)
- if log.do_medium:
- log('%4i %12.5e' % (counter, error))
+ print('5: %4i %12.5e' % (counter, error))
if error < self.threshold:
converged = True
break
@@ -118,26 +113,24 @@ def __call__(self, ham, overlap, occ_model, *orbs):
if self.level_shift > 0:
for i in xrange(ham.ndm):
# The normal behavior is to shift down the occupied levels.
- focks[i] += -self.level_shift*get_level_shift(dms[i], overlap)
+ focks[i] += -self.level_shift * get_level_shift(dms[i], overlap)
# Diagonalize the fock operators to obtain new orbitals and
for i in xrange(ham.ndm):
orbs[i].from_fock(focks[i], overlap)
# If requested, compensate for level-shift. This compensation
# is only correct when the SCF has converged.
if self.level_shift > 0:
- orbs[i].energies[:] += self.level_shift*orbs[i].occupations
+ orbs[i].energies[:] += self.level_shift * orbs[i].occupations
# Assign new occupation numbers.
occ_model.assign(*orbs)
# counter
counter += 1
- if log.do_medium:
- log.blank()
+ print("5: ")
if not self.skip_energy:
ham.compute_energy()
- if log.do_medium:
- ham.log()
+ print(ham)
if not converged:
raise NoSCFConvergence
@@ -145,5 +138,5 @@ def __call__(self, ham, overlap, occ_model, *orbs):
return counter
def error(self, ham, overlap, *orbs):
- '''See :py:func:`horton.meanfield.convergence.convergence_error_eigen`.'''
+ """See :py:func:`horton.meanfield.convergence.convergence_error_eigen`."""
return convergence_error_eigen(ham, overlap, *orbs)
diff --git a/horton/meanfield/scf_cdiis.py b/horton/meanfield/scf_cdiis.py
index a09564d2..0b99202c 100644
--- a/horton/meanfield/scf_cdiis.py
+++ b/horton/meanfield/scf_cdiis.py
@@ -18,25 +18,23 @@
# along with this program; if not, see
#
# --
-'''Commutator DIIS SCF algorithm'''
-
+"""Commutator DIIS SCF algorithm"""
import numpy as np
-from horton.log import biblio
-from horton.meanfield.scf_diis import DIISHistory, DIISSCFSolver
-from horton.quadprog import solve_safe
-from horton.utils import doc_inherit
-
+from .quadprog import solve_safe
+from .scf_diis import DIISHistory, DIISSCFSolver
+from .utils import doc_inherit
__all__ = ['CDIISSCFSolver']
class CDIISSCFSolver(DIISSCFSolver):
- '''The Commmutatator (or Pulay) DIIS SCF solver [pulay1980]_'''
+ """The Commutator (or Pulay) DIIS SCF solver [pulay1980]_"""
- def __init__(self, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False, prune_old_states=False):
- '''
+ def __init__(self, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False,
+ prune_old_states=False):
+ """
**Optional arguments:**
maxiter
@@ -56,21 +54,22 @@ def __init__(self, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False, pr
coefficient is zero. Pruning starts at the oldest state and stops
as soon as a state is encountered with a non-zero coefficient. Even
if some newer states have a zero coefficient.
- '''
- biblio.cite('pulay1980', 'the commutator DIIS SCF algorithm')
- DIISSCFSolver.__init__(self, CDIISHistory, threshold, maxiter, nvector, skip_energy, prune_old_states)
+ """
+ DIISSCFSolver.__init__(self, CDIISHistory, threshold, maxiter, nvector, skip_energy,
+ prune_old_states)
+ self.biblio.append(['pulay1980', 'the commutator DIIS SCF algorithm'])
class CDIISHistory(DIISHistory):
- '''A commutator DIIS history object that keeps track of previous SCF solutions
+ """A commutator DIIS history object that keeps track of previous SCF solutions
This type of DIIS is also called Pulay DIIS.
- '''
+ """
name = 'CDIIS'
need_energy = False
def __init__(self, nvector, ndm, deriv_scale, overlap):
- '''
+ """
**Arguments:**
nvector
@@ -85,30 +84,30 @@ def __init__(self, nvector, ndm, deriv_scale, overlap):
overlap
The overlap matrix.
- '''
+ """
self.cdots = np.empty((nvector, nvector))
self.cdots.fill(np.nan)
DIISHistory.__init__(self, nvector, ndm, deriv_scale, overlap, [self.cdots])
def _complete_cdots_matrix(self):
- '''Complete the matrix of dot products between commutators
+ """Complete the matrix of dot products between commutators
Even after multiple additions, this routine will fill up all the
missing dot products in self.cdots.
- '''
- for i0 in xrange(self.nused-1, -1, -1):
+ """
+ for i0 in xrange(self.nused - 1, -1, -1):
state0 = self.stack[i0]
- self.cdots[i0,i0] = state0.normsq
+ self.cdots[i0, i0] = state0.normsq
# Compute off-diagonal coefficients
for i1 in xrange(i0):
- if np.isfinite(self.cdots[i0,i1]):
+ if np.isfinite(self.cdots[i0, i1]):
return
state1 = self.stack[i1]
cdot = 0.0
for j in xrange(self.ndm):
cdot += np.einsum('ab,ab', state0.commutators[j], state1.commutators[j])
- self.cdots[i0,i1] = cdot
- self.cdots[i1,i0] = cdot
+ self.cdots[i0, i1] = cdot
+ self.cdots[i1, i0] = cdot
@doc_inherit(DIISHistory)
def solve(self, dms_output, focks_output):
@@ -116,18 +115,18 @@ def solve(self, dms_output, focks_output):
assert self.nused >= 2
# Fill in the missing commutators
self._complete_cdots_matrix()
- coeffs = solve_cdiis(self.cdots[:self.nused,:self.nused])
+ coeffs = solve_cdiis(self.cdots[:self.nused, :self.nused])
# get a condition number
- absevals = abs(np.linalg.eigvalsh(self.cdots[:self.nused,:self.nused]))
+ absevals = abs(np.linalg.eigvalsh(self.cdots[:self.nused, :self.nused]))
with np.errstate(divide='ignore'):
- cn = absevals.max()/absevals.min()
+ cn = absevals.max() / absevals.min()
# assign extrapolated fock
error = self._build_combinations(coeffs, dms_output, focks_output)
return None, coeffs, cn, 'C', error
def solve_cdiis(a):
- r'''Solve the linear equations found in the cdiis method
+ r"""Solve the linear equations found in the cdiis method
The following is minimized:
@@ -140,15 +139,15 @@ def solve_cdiis(a):
a
The matrix a, an array of size (N,N).
- '''
+ """
n = len(a)
assert a.shape == (n, n)
assert (a == a.T).all()
- a2 = np.zeros((n+1, n+1))
- a2[:n,:n] = a
- a2[n,:n] = 1
- a2[:n,n] = 1
- b2 = np.zeros(n+1)
+ a2 = np.zeros((n + 1, n + 1))
+ a2[:n, :n] = a
+ a2[n, :n] = 1
+ a2[:n, n] = 1
+ b2 = np.zeros(n + 1)
b2[n] = 1
x2 = solve_safe(a2, b2)
return x2[:n]
diff --git a/horton/meanfield/scf_diis.py b/horton/meanfield/scf_diis.py
index d3953418..831a2420 100644
--- a/horton/meanfield/scf_diis.py
+++ b/horton/meanfield/scf_diis.py
@@ -18,27 +18,25 @@
# along with this program; if not, see
#
# --
-'''Abstract DIIS code used by the different DIIS implementations'''
-
+"""Abstract DIIS code used by the different DIIS implementations"""
import numpy as np
-from horton.log import log, timer
-from horton.exceptions import NoSCFConvergence
-from horton.meanfield.convergence import convergence_error_commutator
-from horton.meanfield.utils import compute_commutator, check_dm
-from horton.meanfield.orbitals import Orbitals
-
+from .exceptions import NoSCFConvergence
+from .convergence import convergence_error_commutator
+from .orbitals import Orbitals, check_dm
+from .utils import compute_commutator
__all__ = []
class DIISSCFSolver(object):
- '''Base class for all DIIS SCF solvers'''
- kind = 'dm' # input/output variable is the density matrix
+ """Base class for all DIIS SCF solvers"""
+ kind = 'dm' # input/output variable is the density matrix
- def __init__(self, DIISHistoryClass, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False, prune_old_states=False):
- '''
+ def __init__(self, DIISHistoryClass, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False,
+ prune_old_states=False):
+ """
**Arguments:**
DIISHistoryClass
@@ -63,23 +61,22 @@ def __init__(self, DIISHistoryClass, threshold=1e-6, maxiter=128, nvector=6, ski
coefficient is zero. Pruning starts at the oldest state and stops
as soon as a state is encountered with a non-zero coefficient. Even
if some newer states have a zero coefficient.
- '''
+ """
self.DIISHistoryClass = DIISHistoryClass
self.threshold = threshold
self.maxiter = maxiter
self.nvector = nvector
self.skip_energy = skip_energy
self.prune_old_states = prune_old_states
- # Attributs where local variables of the __call__ method are stored:
+ # Attributes where local variables of the __call__ method are stored:
self._history = None
self._focks = []
self._orbs = []
self.commutator = None
+ self.biblio = []
-
- @timer.with_section('SCF')
def __call__(self, ham, overlap, occ_model, *dms):
- '''Find a self-consistent set of density matrices.
+ """Find a self-consistent set of density matrices.
**Arguments:**
@@ -95,10 +92,11 @@ def __call__(self, ham, overlap, occ_model, *dms):
dm1, dm2, ...
The initial density matrices. The number of dms must match
ham.ndm.
- '''
+ """
# Some type checking
if ham.ndm != len(dms):
- raise TypeError('The number of initial density matrices does not match the Hamiltonian.')
+ raise TypeError(
+ 'The number of initial density matrices does not match the Hamiltonian.')
# Check input density matrices.
for i in xrange(ham.ndm):
@@ -110,11 +108,10 @@ def __call__(self, ham, overlap, occ_model, *dms):
self._focks = [np.zeros(overlap.shape) for i in xrange(ham.ndm)]
self._orbs = [Orbitals(overlap.shape[0]) for i in xrange(ham.ndm)]
- if log.do_medium:
- log('Starting restricted closed-shell %s-SCF' % self._history.name)
- log.hline()
- log('Iter Error CN Last nv Method Energy Change')
- log.hline()
+ print('5: Starting restricted closed-shell %s-SCF' % self._history.name)
+ print("5: " + "-" * 70)
+ print('5: Iter Error CN Last nv Method Energy Change')
+ print("5: " + "-" * 70)
converged = False
counter = 0
@@ -127,29 +124,21 @@ def __call__(self, ham, overlap, occ_model, *dms):
ham.compute_fock(*self._focks)
# Compute the energy if needed by the history
energy = ham.compute_energy() if self._history.need_energy \
- else None
+ else None
# Add the current fock+dm pair to the history
error = self._history.add(energy, dms, self._focks)
# Screen logging
- if log.do_high:
- log(' DIIS add')
+ print('7: DIIS add')
if error < self.threshold:
converged = True
break
- if log.do_high:
- log.blank()
- if log.do_medium:
- energy_str = ' '*20 if energy is None else '% 20.13f' % energy
- log('%4i %12.5e %2i %20s' % (
- counter, error, self._history.nused, energy_str
- ))
- if log.do_high:
- log.blank()
- fock_interpolated = False
- else:
- energy = None
- fock_interpolated = True
+ print("7: ")
+ energy_str = ' ' * 20 if energy is None else '% 20.13f' % energy
+ print('5: %4i %12.5e %2i %20s' % (
+ counter, error, self._history.nused, energy_str
+ ))
+ print("7: ")
# Take a regular SCF step using the current fock matrix. Then
# construct a new density matrix and fock matrix.
@@ -163,8 +152,7 @@ def __call__(self, ham, overlap, occ_model, *dms):
ham.compute_fock(*self._focks)
# Add the current (dm, fock) pair to the history
- if log.do_high:
- log(' DIIS add')
+ print('7: DIIS add')
error = self._history.add(energy, dms, self._focks)
# break when converged
@@ -173,17 +161,14 @@ def __call__(self, ham, overlap, occ_model, *dms):
break
# Screen logging
- if log.do_high:
- log.blank()
- if log.do_medium:
- energy_str = ' '*20 if energy is None else '% 20.13f' % energy
- log('%4i %12.5e %2i %20s' % (
- counter, error, self._history.nused, energy_str
- ))
- if log.do_high:
- log.blank()
-
- # get extra/intra-polated Fock matrix
+ print("7: ")
+ energy_str = ' ' * 20 if energy is None else '% 20.13f' % energy
+ print('5: %4i %12.5e %2i %20s' % (
+ counter, error, self._history.nused, energy_str
+ ))
+ print("7: ")
+
+ # get extra/inter-polated Fock matrix
while True:
# The following method writes the interpolated dms and focks
# in-place.
@@ -194,33 +179,33 @@ def __call__(self, ham, overlap, occ_model, *dms):
if error < self.threshold:
converged = True
break
- #if coeffs[coeffs<0].sum() < -1:
- # if log.do_high:
- # log(' DIIS (coeffs too negative) -> drop %i and retry' % self._history.stack[0].identity)
+ # if coeffs[coeffs<0].sum() < -1:
+ # print('7: DIIS (coeffs too negative) -> drop %i and retry' % self._history.stack[0].identity)
# self._history.shrink()
if self._history.nused <= 2:
break
if coeffs[-1] == 0.0:
- if log.do_high:
- log(' DIIS (last coeff zero) -> drop %i and retry' % self._history.stack[0].identity)
+ print(
+ '7: DIIS (last coeff zero) -> drop %i and retry' %
+ self._history.stack[
+ 0].identity)
self._history.shrink()
else:
break
if False and len(coeffs) == 2:
dms_tmp = [dm.copy() for dm in dms]
- import matplotlib.pyplot as pt
xs = np.linspace(0.0, 1.0, 25)
a, b = self._history._setup_equations()
energies1 = []
energies2 = []
for x in xs:
- x_coeffs = np.array([1-x, x])
- energies1.append(np.dot(x_coeffs, 0.5*np.dot(a, x_coeffs) - b))
+ x_coeffs = np.array([1 - x, x])
+ energies1.append(np.dot(x_coeffs, 0.5 * np.dot(a, x_coeffs) - b))
self._history._build_combinations(x_coeffs, dms_tmp, None)
ham.reset(*dms_tmp)
energies2.append(ham.compute_energy())
- print x, energies1[-1], energies2[-1]
+ print(x, energies1[-1], energies2[-1])
pt.clf()
pt.plot(xs, energies1, label='est')
pt.plot(xs, energies2, label='ref')
@@ -234,25 +219,21 @@ def __call__(self, ham, overlap, occ_model, *dms):
energy_change = None
# log
- if log.do_high:
- self._history.log(coeffs)
-
- if log.do_medium:
- change_str = ' '*10 if energy_change is None else '% 12.7f' % energy_change
- log('%4i %10.3e %12.7f %2i %s %12s' % (
- counter, cn, coeffs[-1], self._history.nused, method,
- change_str
- ))
+ self._history.log(coeffs)
- if log.do_high:
- log.blank()
+ change_str = ' ' * 10 if energy_change is None else '% 12.7f' % energy_change
+ print('5: %4i %10.3e %12.7f %2i %s %12s' % (
+ counter, cn, coeffs[-1], self._history.nused, method,
+ change_str
+ ))
+ print("7: ")
if self.prune_old_states:
# get rid of old states with zero coeff
for i in xrange(self._history.nused):
if coeffs[i] == 0.0:
- if log.do_high:
- log(' DIIS insignificant -> drop %i' % self._history.stack[0].identity)
+ print('7: DIIS insignificant -> drop %i' % self._history.stack[
+ 0].identity)
self._history.shrink()
else:
break
@@ -260,16 +241,14 @@ def __call__(self, ham, overlap, occ_model, *dms):
# counter
counter += 1
- if log.do_medium:
- if converged:
- log('%4i %12.5e (converged)' % (counter, error))
- log.blank()
+ if converged:
+ print('5: %4i %12.5e (converged)' % (counter, error))
+ print("7: ")
if not self.skip_energy or self._history.need_energy:
if not self._history.need_energy:
ham.compute_energy()
- if log.do_medium:
- ham.log()
+ print(ham)
if not converged:
raise NoSCFConvergence
@@ -281,10 +260,10 @@ def error(self, ham, lf, overlap, *dms):
class DIISState(object):
- '''A single record (vector) in a DIIS history object.'''
+ """A single record (vector) in a DIIS history object."""
def __init__(self, ndm, overlap):
- '''
+ """
**Arguments:**
ndm
@@ -292,7 +271,7 @@ def __init__(self, ndm, overlap):
state.
overlap
The overlap matrix.
- '''
+ """
# Not all of these need to be used.
self.ndm = ndm
self.overlap = overlap
@@ -301,10 +280,10 @@ def __init__(self, ndm, overlap):
self.dms = [np.zeros(overlap.shape) for i in xrange(self.ndm)]
self.focks = [np.zeros(overlap.shape) for i in xrange(self.ndm)]
self.commutators = [np.zeros(overlap.shape) for i in xrange(self.ndm)]
- self.identity = None # every state has a different id.
+ self.identity = None # every state has a different id.
def clear(self):
- '''Reset this record.'''
+ """Reset this record."""
self.energy = np.nan
self.normsq = np.nan
for i in xrange(self.ndm):
@@ -313,7 +292,7 @@ def clear(self):
self.commutators[i][:] = 0.0
def assign(self, identity, energy, dms, focks):
- '''Assign a new state.
+ """Assign a new state.
**Arguments:**
@@ -328,7 +307,7 @@ def assign(self, identity, energy, dms, focks):
fock
The Fock matrix of the new state.
- '''
+ """
self.identity = identity
self.energy = energy
self.normsq = 0.0
@@ -340,12 +319,12 @@ def assign(self, identity, energy, dms, focks):
class DIISHistory(object):
- '''A base class of DIIS histories'''
+ """A base class of DIIS histories"""
name = None
need_energy = None
def __init__(self, nvector, ndm, deriv_scale, overlap, dots_matrices):
- '''
+ """
**Arguments:**
nvector
@@ -368,7 +347,7 @@ def __init__(self, nvector, ndm, deriv_scale, overlap, dots_matrices):
used
The actual number of vectors in the history.
- '''
+ """
self.stack = [DIISState(ndm, overlap) for i in xrange(nvector)]
self.ndm = ndm
self.deriv_scale = deriv_scale
@@ -378,7 +357,7 @@ def __init__(self, nvector, ndm, deriv_scale, overlap, dots_matrices):
self.idcounter = 0
def _get_nvector(self):
- '''The maximum size of the history'''
+ """The maximum size of the history"""
return len(self.stack)
nvector = property(_get_nvector)
@@ -386,19 +365,21 @@ def _get_nvector(self):
def log(self, coeffs):
eref = min(state.energy for state in self.stack[:self.nused])
if eref is None:
- log(' DIIS history normsq coeff id')
+ print('5: DIIS history normsq coeff id')
for i in xrange(self.nused):
state = self.stack[i]
- log(' DIIS history %12.5e %12.7f %8i' % (state.normsq, coeffs[i], state.identity))
+ print('5: DIIS history %12.5e %12.7f %8i' % (
+ state.normsq, coeffs[i], state.identity))
else:
- log(' DIIS history normsq energy coeff id')
+ print('5: DIIS history normsq energy coeff id')
for i in xrange(self.nused):
state = self.stack[i]
- log(' DIIS history %12.5e %12.5e %12.7f %8i' % (state.normsq, state.energy-eref, coeffs[i], state.identity))
- log.blank()
+ print('5: DIIS history %12.5e %12.5e %12.7f %8i' % (
+ state.normsq, state.energy - eref, coeffs[i], state.identity))
+ print("5: ")
def solve(self, dms_output, focks_output):
- '''Inter- or extrapolate new density and/or fock matrices.
+ """Inter- or extrapolate new density and/or fock matrices.
**Arguments:**
@@ -409,23 +390,23 @@ def solve(self, dms_output, focks_output):
focks_output
The output for the Fock matrices. If set to None, this is
argument is ignored.
- '''
+ """
raise NotImplementedError
def shrink(self):
- '''Remove the oldest item from the history'''
+ """Remove the oldest item from the history"""
self.nused -= 1
state = self.stack.pop(0)
state.clear()
self.stack.append(state)
for dots in self.dots_matrices:
dots[:-1] = dots[1:]
- dots[:,:-1] = dots[:,1:]
+ dots[:, :-1] = dots[:, 1:]
dots[-1] = np.nan
- dots[:,-1] = np.nan
+ dots[:, -1] = np.nan
def add(self, energy, dms, focks):
- '''Add new state to the history.
+ """Add new state to the history.
**Arguments:**
@@ -440,7 +421,7 @@ def add(self, energy, dms, focks):
**Returns**: the square root of commutator error for the given pairs
of density and Fock matrices.
- '''
+ """
if len(dms) != self.ndm or len(focks) != self.ndm:
raise TypeError('The number of density and Fock matrices must match the ndm parameter.')
# There must be a free spot. If needed, make one.
@@ -457,7 +438,7 @@ def add(self, energy, dms, focks):
return np.sqrt(state.normsq)
def _build_combinations(self, coeffs, dms_output, focks_output):
- '''Construct a linear combination of density/fock matrices
+ """Construct a linear combination of density/fock matrices
**Arguments:**
@@ -472,7 +453,7 @@ def _build_combinations(self, coeffs, dms_output, focks_output):
**Returns:** the commutator error, only when both dms_output and
focks_output are given.
- '''
+ """
if dms_output is not None:
if len(dms_output) != self.ndm:
raise TypeError('The number of density matrices must match the ndm parameter.')
@@ -490,10 +471,10 @@ def _build_combinations(self, coeffs, dms_output, focks_output):
for i in xrange(self.ndm):
self.commutator = compute_commutator(dms_output[i], focks_output[i], self.overlap)
errorsq += np.einsum('ab,ab', self.commutator, self.commutator)
- return errorsq**0.5
+ return errorsq ** 0.5
def _linear_combination(self, coeffs, ops, output):
- '''Make a linear combination of two-index objects
+ """Make a linear combination of two-index objects
**Arguments:**
@@ -505,7 +486,7 @@ def _linear_combination(self, coeffs, ops, output):
output
The output operator.
- '''
+ """
output[:] = 0
for i in xrange(self.nused):
- output += coeffs[i]*ops[i]
+ output += coeffs[i] * ops[i]
diff --git a/horton/meanfield/scf_ediis.py b/horton/meanfield/scf_ediis.py
index ad2b0fd1..92914594 100644
--- a/horton/meanfield/scf_ediis.py
+++ b/horton/meanfield/scf_ediis.py
@@ -18,25 +18,24 @@
# along with this program; if not, see
#
# --
-'''Energy DIIS SCF algorithm'''
+"""Energy DIIS SCF algorithm"""
import numpy as np
-from horton.log import biblio
-from horton.exceptions import NoSCFConvergence
-from horton.meanfield.scf_diis import DIISHistory, DIISSCFSolver
-from horton.quadprog import QPSolver
-from horton.utils import doc_inherit
-
+from .quadprog import QPSolver
+from .exceptions import NoSCFConvergence
+from .scf_diis import DIISHistory, DIISSCFSolver
+from .utils import doc_inherit
__all__ = ['EDIISSCFSolver']
class EDIISSCFSolver(DIISSCFSolver):
- '''The Energy DIIS SCF solver [kudin2002]_'''
+ """The Energy DIIS SCF solver [kudin2002]_"""
- def __init__(self, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False, prune_old_states=False):
- '''
+ def __init__(self, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False,
+ prune_old_states=False):
+ """
**Optional arguments:**
maxiter
@@ -56,18 +55,19 @@ def __init__(self, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False, pr
coefficient is zero. Pruning starts at the oldest state and stops
as soon as a state is encountered with a non-zero coefficient. Even
if some newer states have a zero coefficient.
- '''
- biblio.cite('kudin2002', 'the EDIIS method.')
- DIISSCFSolver.__init__(self, EDIISHistory, threshold, maxiter, nvector, skip_energy, prune_old_states)
+ """
+ DIISSCFSolver.__init__(self, EDIISHistory, threshold, maxiter, nvector, skip_energy,
+ prune_old_states)
+ self.biblio.append(['kudin2002', 'the EDIIS method.'])
class EDIISHistory(DIISHistory):
- '''A Energy DIIS history object that keeps track of previous SCF solutions'''
+ """A Energy DIIS history object that keeps track of previous SCF solutions"""
name = 'EDIIS'
need_energy = True
def __init__(self, nvector, ndm, deriv_scale, overlap):
- '''Initialize a EDIISHistory object.
+ """Initialize a EDIISHistory object.
Parameters
----------
@@ -79,7 +79,7 @@ def __init__(self, nvector, ndm, deriv_scale, overlap):
The deriv_scale attribute of the Effective Hamiltonian
overlap
The overlap matrix.
- '''
+ """
# A matrix with dot products of all density and fock matrices
# Note that the dots matrix is not symmetric!
self.edots = np.empty((nvector, nvector))
@@ -87,36 +87,38 @@ def __init__(self, nvector, ndm, deriv_scale, overlap):
DIISHistory.__init__(self, nvector, ndm, deriv_scale, overlap, [self.edots])
def _complete_edots_matrix(self):
- '''Complete the matrix of dot products between density and fock matrices
+ """Complete the matrix of dot products between density and fock matrices
Even after multiple additions, this routine will fill up all the
missing dot products in self.edots.
- '''
+ """
# This routine even works after multiple additions.
- for i0 in xrange(self.nused-1, -1, -1):
- if np.isfinite(self.edots[i0,i0]):
+ for i0 in xrange(self.nused - 1, -1, -1):
+ if np.isfinite(self.edots[i0, i0]):
return
# Compute off-diagonal coefficients
state0 = self.stack[i0]
- for i1 in xrange(i0+1):
+ for i1 in xrange(i0 + 1):
state1 = self.stack[i1]
- self.edots[i0,i1] = 0.0
+ self.edots[i0, i1] = 0.0
for j in xrange(self.ndm):
- self.edots[i0,i1] += np.einsum('ab,ba', state0.focks[j], state1.dms[j])
+ self.edots[i0, i1] += np.einsum('ab,ba', state0.focks[j], state1.dms[j])
if i0 != i1:
# Note that this matrix is not symmetric!
- self.edots[i1,i0] = 0.0
+ self.edots[i1, i0] = 0.0
for j in xrange(self.ndm):
- self.edots[i1,i0] += np.einsum('ab,ba', state1.focks[j], state0.dms[j])
+ self.edots[i1, i0] += np.einsum('ab,ba', state1.focks[j], state0.dms[j])
def _setup_equations(self):
- '''Compute the equations for the quadratic programming problem.'''
+ """Compute the equations for the quadratic programming problem."""
b = np.zeros((self.nused, self.nused), float)
e = np.zeros(self.nused, float)
for i0 in xrange(self.nused):
e[i0] = -self.stack[i0].energy
- for i1 in xrange(i0+1):
- b[i0, i1] = -0.5*self.deriv_scale*(self.edots[i0,i0] + self.edots[i1,i1] - self.edots[i0,i1] - self.edots[i1,i0])
+ for i1 in xrange(i0 + 1):
+ b[i0, i1] = -0.5 * self.deriv_scale * (
+ self.edots[i0, i0] + self.edots[i1, i1] - self.edots[i0, i1] - self.edots[
+ i1, i0])
if i0 != i1:
b[i1, i0] = b[i0, i1]
return b, e
@@ -127,14 +129,14 @@ def solve(self, dms_output, focks_output):
assert self.nused >= 2
# Fill in the missing commutators
self._complete_edots_matrix()
- assert not np.isnan(self.edots[:self.nused,:self.nused]).any()
+ assert not np.isnan(self.edots[:self.nused, :self.nused]).any()
# Setup the equations
b, e = self._setup_equations()
# Check if solving these equations makes sense.
if b.max() - b.min() == 0 and e.max() - e.min() == 0:
raise NoSCFConvergence('Convergence criteria too tight for EDIIS')
# solve the quadratic programming problem
- qps = QPSolver(b, e, np.ones((1,self.nused)), np.array([1.0]), eps=1e-6)
+ qps = QPSolver(b, e, np.ones((1, self.nused)), np.array([1.0]), eps=1e-6)
if self.nused < 10:
energy, coeffs = qps.find_brute()
guess = None
diff --git a/horton/meanfield/scf_ediis2.py b/horton/meanfield/scf_ediis2.py
index d18c7909..0bf61c53 100644
--- a/horton/meanfield/scf_ediis2.py
+++ b/horton/meanfield/scf_ediis2.py
@@ -18,26 +18,24 @@
# along with this program; if not, see
#
# --
-'''EDIIS+DIIS SCF algorithm'''
-
+"""EDIIS+DIIS SCF algorithm"""
import numpy as np
-from horton.log import biblio
-from horton.meanfield.scf_diis import DIISHistory, DIISSCFSolver
-from horton.meanfield.scf_cdiis import CDIISHistory
-from horton.meanfield.scf_ediis import EDIISHistory
-from horton.utils import doc_inherit
-
+from .scf_cdiis import CDIISHistory
+from .scf_diis import DIISHistory, DIISSCFSolver
+from .scf_ediis import EDIISHistory
+from .utils import doc_inherit
__all__ = ['EDIIS2SCFSolver']
class EDIIS2SCFSolver(DIISSCFSolver):
- '''The EDIIS+DIIS SCF solver [kudin2002]_'''
+ """The EDIIS+DIIS SCF solver [kudin2002]_"""
- def __init__(self, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False, prune_old_states=False):
- '''
+ def __init__(self, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False,
+ prune_old_states=False):
+ """
**Optional arguments:**
maxiter
@@ -57,22 +55,23 @@ def __init__(self, threshold=1e-6, maxiter=128, nvector=6, skip_energy=False, pr
coefficient is zero. Pruning starts at the oldest state and stops
as soon as a state is encountered with a non-zero coefficient. Even
if some newer states have a zero coefficient.
- '''
- biblio.cite('kudin2002', 'the EDIIS method.')
- DIISSCFSolver.__init__(self, EDIIS2History, threshold, maxiter, nvector, skip_energy, prune_old_states)
+ """
+ DIISSCFSolver.__init__(self, EDIIS2History, threshold, maxiter, nvector, skip_energy,
+ prune_old_states)
+ self.biblio.append(['kudin2002', 'the EDIIS method.'])
class EDIIS2History(EDIISHistory, CDIISHistory):
- '''A EDIIS+DIIS history object that keeps track of previous SCF solutions
+ """A EDIIS+DIIS history object that keeps track of previous SCF solutions
This method uses EDIIS for the first iterations and switches to CDIIS
to as soon as some initial degree of convergence is achieved.
- '''
+ """
name = 'EDIIS+DIIS'
need_energy = True
def __init__(self, nvector, ndm, deriv_scale, overlap):
- '''Initialize a EDIIS2History object.
+ """Initialize a EDIIS2History object.
Parameters
----------
@@ -84,7 +83,7 @@ def __init__(self, nvector, ndm, deriv_scale, overlap):
The deriv_scale attribute of the Effective Hamiltonian
overlap
The overlap matrix.
- '''
+ """
# for the EDIIS part
self.edots = np.empty((nvector, nvector))
self.edots.fill(np.nan)
@@ -103,6 +102,6 @@ def solve(self, dms_output, focks_output):
else:
energy1, coeffs1, cn1, method1, error = CDIISHistory.solve(self, None, None)
energy2, coeffs2, cn2, method2, error = EDIISHistory.solve(self, None, None)
- coeffs = 10*errmax*coeffs2 + (1-10*errmax)*coeffs1
+ coeffs = 10 * errmax * coeffs2 + (1 - 10 * errmax) * coeffs1
error = self._build_combinations(coeffs, dms_output, focks_output)
return None, coeffs, max(cn1, cn2), 'M', error
diff --git a/horton/meanfield/scf_oda.py b/horton/meanfield/scf_oda.py
index 183208fc..bf2eb25a 100644
--- a/horton/meanfield/scf_oda.py
+++ b/horton/meanfield/scf_oda.py
@@ -18,23 +18,20 @@
# along with this program; if not, see
#
# --
-'''Optimal Damping SCF algorithm'''
-
+"""Optimal Damping SCF algorithm"""
import numpy as np
-from horton.log import log, timer
-from horton.exceptions import NoSCFConvergence
-from horton.meanfield.convergence import convergence_error_commutator
-from horton.meanfield.orbitals import Orbitals
-from horton.meanfield.utils import check_dm, compute_commutator
-
+from .exceptions import NoSCFConvergence
+from .convergence import convergence_error_commutator
+from .orbitals import Orbitals, check_dm
+from .utils import compute_commutator
__all__ = ['ODASCFSolver', 'check_cubic']
def find_min_cubic(f0, f1, g0, g1):
- '''Find the minimum of a cubic polynomial in the range [0,1]
+ """Find the minimum of a cubic polynomial in the range [0,1]
**Arguments:**
@@ -46,41 +43,38 @@ def find_min_cubic(f0, f1, g0, g1):
The derivative at argument 0
g1
The derivative at argument 1
- '''
+ """
# coefficients of the polynomial a*x**3 + b*x**2 + c*x + d
d = f0
c = g0
- a = g1 - 2*f1 + c + 2*d
+ a = g1 - 2 * f1 + c + 2 * d
b = f1 - a - c - d
# find the roots of the derivative
- discriminant = b**2 - 3*a*c # simplified expression, not a mistake!
+ discriminant = b ** 2 - 3 * a * c # simplified expression, not a mistake!
if discriminant >= 0:
- if b*b < abs(3*a*c)*1e5:
- if log.do_high:
- log(' cubic')
- xa = (-b + np.sqrt(discriminant))/(3*a)
- xb = (-b - np.sqrt(discriminant))/(3*a)
+ if b * b < abs(3 * a * c) * 1e5:
+ print('7: cubic')
+ xa = (-b + np.sqrt(discriminant)) / (3 * a)
+ xb = (-b - np.sqrt(discriminant)) / (3 * a)
# test the solutions
for x in xa, xb:
- if x >= 0 and x <= 1:
+ if 0 <= x <= 1:
# compute the curvature at the solution
- curv = 6*a*x+2*b
+ curv = 6 * a * x + 2 * b
if curv > 0:
# Only one of two solutions has the right curvature, no
# need to compare the energy of both solutions
return x
- elif b > 0: # only b > 0 because b is also the curvature
- if log.do_high:
- log(' quadratic')
- x = -0.5*c/b
- if x >= 0 and x <= 1:
+ elif b > 0: # only b > 0 because b is also the curvature
+ print('7: quadratic')
+ x = -0.5 * c / b
+ if 0 <= x <= 1:
return x
# If we get here, no solution was found in the interval. One of the
# boundaries is then the minimum
- if log.do_high:
- log(' edge')
+ print('7: edge')
if f0 < f1:
return 0.0
else:
@@ -88,7 +82,7 @@ def find_min_cubic(f0, f1, g0, g1):
def find_min_quadratic(g0, g1):
- '''Find the minimum of a quadratic polynomial in the range [0,1]
+ """Find the minimum of a quadratic polynomial in the range [0,1]
**Arguments:**
@@ -96,7 +90,7 @@ def find_min_quadratic(g0, g1):
The derivative at argument 0
g1
The derivative at argument 1
- '''
+ """
if g0 > 0:
if g1 < -g0:
return 1.0
@@ -111,11 +105,11 @@ def find_min_quadratic(g0, g1):
class ODASCFSolver(object):
- '''Optimal damping SCF algorithm (with cubic interpolation)'''
- kind = 'dm' # input/output variable is the density matrix
+ """Optimal damping SCF algorithm (with cubic interpolation)"""
+ kind = 'dm' # input/output variable is the density matrix
def __init__(self, threshold=1e-8, maxiter=128, skip_energy=False, debug=False):
- '''
+ """
**Optional arguments:**
maxiter
@@ -131,15 +125,14 @@ def __init__(self, threshold=1e-8, maxiter=128, skip_energy=False, debug=False):
debug
When set to True, for each mixing step, a plot is made to double
check the cubic interpolation.
- '''
+ """
self.maxiter = maxiter
self.threshold = threshold
self.skip_energy = skip_energy
self.debug = debug
- @timer.with_section('SCF')
def __call__(self, ham, overlap, occ_model, *dm0s):
- '''Find a self-consistent set of density matrices.
+ """Find a self-consistent set of density matrices.
**Arguments:**
@@ -155,28 +148,26 @@ def __call__(self, ham, overlap, occ_model, *dm0s):
dm1, dm2, ...
The initial density matrices. The number of dms must match
ham.ndm.
- '''
+ """
# Some type checking
if ham.ndm != len(dm0s):
- raise TypeError('The number of initial density matrices does not match the Hamiltonian.')
+ raise TypeError(
+ 'The number of initial density matrices does not match the Hamiltonian.')
# Check input density matrices.
for i in xrange(ham.ndm):
check_dm(dm0s[i], overlap)
occ_model.check_dms(overlap, *dm0s)
- if log.do_medium:
- log('Starting SCF with optimal damping. ham.ndm=%i' % ham.ndm)
- log.hline()
- log(' Iter Energy Error Mixing')
- log.hline()
+ print('5: Starting SCF with optimal damping. ham.ndm=%i' % ham.ndm)
+ print("5: " + "-" * 70)
+ print('5: Iter Energy Error Mixing')
+ print("5: " + "-" * 70)
fock0s = [np.zeros(overlap.shape) for i in xrange(ham.ndm)]
fock1s = [np.zeros(overlap.shape) for i in xrange(ham.ndm)]
dm1s = [np.zeros(overlap.shape) for i in xrange(ham.ndm)]
orbs = [Orbitals(overlap.shape[0]) for i in xrange(ham.ndm)]
- work = np.zeros(dm0s[0].shape)
- commutator = np.zeros(dm0s[0].shape)
converged = False
counter = 0
mixing = None
@@ -189,11 +180,10 @@ def __call__(self, ham, overlap, occ_model, *dm0s):
# Compute the energy in point 0
energy0 = ham.compute_energy()
- if log.do_medium:
- if mixing is None:
- log('%5i %20.13f' % (counter, energy0))
- else:
- log('%5i %20.13f %12.5e %10.5f' % (counter, energy0, error, mixing))
+ if mixing is None:
+ print('5: %5i %20.13f' % (counter, energy0))
+ else:
+ print('5: %5i %20.13f %12.5e %10.5f' % (counter, energy0, error, mixing))
# go to point 1 by diagonalizing the fock matrices
for i in xrange(ham.ndm):
@@ -224,9 +214,8 @@ def __call__(self, ham, overlap, occ_model, *dm0s):
deriv1 *= ham.deriv_scale
# find the lambda that minimizes the cubic polynomial in the range [0,1]
- if log.do_high:
- log(' E0: % 10.5e D0: % 10.5e' % (energy0, deriv0))
- log(' E1-E0: % 10.5e D1: % 10.5e' % (energy1-energy0, deriv1))
+ print('5: E0: % 10.5e D0: % 10.5e' % (energy0, deriv0))
+ print('5: E1-E0: % 10.5e D1: % 10.5e' % (energy1 - energy0, deriv1))
mixing = find_min_cubic(energy0, energy1, deriv0, deriv1)
if self.debug:
@@ -235,27 +224,27 @@ def __call__(self, ham, overlap, occ_model, *dm0s):
# compute the mixed density and fock matrices (in-place in dm0s and fock0s)
for i in xrange(ham.ndm):
dm0s[i][:] *= 1 - mixing
- dm0s[i][:] += dm1s[i]*mixing
+ dm0s[i][:] += dm1s[i] * mixing
fock0s[i][:] *= 1 - mixing
- fock0s[i][:] += fock1s[i]*mixing
+ fock0s[i][:] += fock1s[i] * mixing
# Compute the convergence criterion.
errorsq = 0.0
for i in xrange(ham.ndm):
commutator = compute_commutator(dm0s[i], fock0s[i], overlap)
errorsq += np.einsum('ab,ab', commutator, commutator)
- error = errorsq**0.5
+ error = errorsq ** 0.5
if error < self.threshold:
converged = True
break
elif mixing == 0.0:
- raise NoSCFConvergence('The ODA algorithm made a zero step without reaching convergence.')
+ raise NoSCFConvergence(
+ 'The ODA algorithm made a zero step without reaching convergence.')
# counter
counter += 1
- if log.do_medium:
- ham.log()
+ print(ham) # TODO: add __repr__ to ham
if not converged:
raise NoSCFConvergence
@@ -263,12 +252,12 @@ def __call__(self, ham, overlap, occ_model, *dm0s):
return counter
def error(self, ham, lf, overlap, *dms):
- '''See :py:func:`horton.meanfield.convergence.convergence_error_commutator`.'''
+ """See :py:func:`horton.meanfield.convergence.convergence_error_commutator`."""
return convergence_error_commutator(ham, lf, overlap, *dms)
def check_cubic(ham, dm0s, dm1s, e0, e1, g0, g1, do_plot=True):
- '''Method to test the correctness of the cubic interpolation
+ """Method to test the correctness of the cubic interpolation
**Arguments:**
@@ -306,11 +295,11 @@ def check_cubic(ham, dm0s, dm1s, e0, e1, g0, g1, do_plot=True):
This function is mainly useful as a tool to double check the
implementation of Fock matrices.
- '''
+ """
# coefficients of the polynomial a*x**3 + b*x**2 + c*x + d
d = e0
c = g0
- a = g1 - 2*e1 + c + 2*d
+ a = g1 - 2 * e1 + c + 2 * d
b = e1 - a - c - d
ndm = len(dm0s)
@@ -320,7 +309,7 @@ def check_cubic(ham, dm0s, dm1s, e0, e1, g0, g1, do_plot=True):
energies = []
for x in xs:
for i in xrange(ndm):
- dm2s[i][:] = dm0s[i]*(1-x) + dm1s[i]*x
+ dm2s[i][:] = dm0s[i] * (1 - x) + dm1s[i] * x
ham.reset(*dm2s)
e2 = ham.compute_energy()
energies.append(e2)
@@ -329,28 +318,28 @@ def check_cubic(ham, dm0s, dm1s, e0, e1, g0, g1, do_plot=True):
if do_plot:
# make a nice figure
xxs = np.concatenate([np.linspace(0, 0.006, 60), np.linspace(0.994, 1.0, 60)])
- poly = a*xxs**3+b*xxs**2+c*xxs+d
- import matplotlib.pyplot as pt
+ poly = a * xxs ** 3 + b * xxs ** 2 + c * xxs + d
pt.clf()
pt.subplot(121)
pt.plot(xxs, poly, 'k-', label='cubic')
pt.plot(xs, energies, 'ro', label='ref')
- pt.plot([0,1],[e0,e1], 'b--', label='linear')
+ pt.plot([0, 1], [e0, e1], 'b--', label='linear')
pt.xlim(0, 0.006)
pt.ylim(min(energies[:5].min(), poly[:60].min()), max(energies[:5].max(), poly[:60].max()))
pt.legend(loc=0)
pt.subplot(122)
pt.plot(xxs, poly, 'k-', label='cubic')
pt.plot(xs, energies, 'ro', label='ref')
- pt.plot([0,1],[e0,e1], 'b--', label='linear')
+ pt.plot([0, 1], [e0, e1], 'b--', label='linear')
pt.xlim(0.994, 1.0)
- pt.ylim(min(energies[-5:].min(), poly[-60:].min()), max(energies[-5:].max(), poly[-60:].max()))
+ pt.ylim(min(energies[-5:].min(), poly[-60:].min()),
+ max(energies[-5:].max(), poly[-60:].max()))
pt.legend(loc=0)
pt.savefig('check_cubic_%+024.17f.png' % e0)
else:
# if not plotting, check that the errors are not too large
- poly = a*xs**3+b*xs**2+c*xs+d
- relative_errors = abs(poly[:5]-energies[:5])/(energies[:5] - e0)
+ poly = a * xs ** 3 + b * xs ** 2 + c * xs + d
+ relative_errors = abs(poly[:5] - energies[:5]) / (energies[:5] - e0)
assert relative_errors.max() < 0.03
- relative_errors = abs(poly[-5:]-energies[-5:])/(energies[-5:] - e1)
+ relative_errors = abs(poly[-5:] - energies[-5:]) / (energies[-5:] - e1)
assert relative_errors.max() < 0.03
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/chol.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/chol.npy
new file mode 100644
index 00000000..12003a06
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/dipoles.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/dipoles.npy
new file mode 100644
index 00000000..86360319
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/dm.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/dm.npy
new file mode 100644
index 00000000..ee673594
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/er.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/er.npy
new file mode 100644
index 00000000..fe65deda
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/kin.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/kin.npy
new file mode 100644
index 00000000..1743a0d1
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/na.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/na.npy
new file mode 100644
index 00000000..638b84b8
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/olp.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/olp.npy
new file mode 100644
index 00000000..ee673594
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..ca57591d
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..ca57591d
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..8e1473e8
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..1e6abfa1
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_coeffs.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_coeffs.npy
new file mode 100644
index 00000000..ca57591d
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_dms.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_dms.npy
new file mode 100644
index 00000000..76ac64bd
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_dms.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_energies.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_energies.npy
new file mode 100644
index 00000000..9454f688
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_energies.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_occs.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_occs.npy
new file mode 100644
index 00000000..d3b1ea49
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/orbs_b_occs.npy differ
diff --git a/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/quads.npy b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/quads.npy
new file mode 100644
index 00000000..ac83be3f
Binary files /dev/null and b/horton/meanfield/test/cached/atom_001_001_hf_sto3g_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/chol.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/chol.npy
new file mode 100644
index 00000000..9516b29c
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/dipoles.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/dipoles.npy
new file mode 100644
index 00000000..b5e1f9a9
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/dm.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/dm.npy
new file mode 100644
index 00000000..ad816547
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/er.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/er.npy
new file mode 100644
index 00000000..afd63883
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/kin.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/kin.npy
new file mode 100644
index 00000000..72cde229
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/na.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/na.npy
new file mode 100644
index 00000000..1930ad11
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/olp.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/olp.npy
new file mode 100644
index 00000000..6a1f3a3b
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..9268eb0d
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..8cb26486
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..ffecf548
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..04109930
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_coeffs.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_coeffs.npy
new file mode 100644
index 00000000..13f7051e
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_dms.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_dms.npy
new file mode 100644
index 00000000..ff8525b1
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_dms.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_energies.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_energies.npy
new file mode 100644
index 00000000..d1900b85
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_energies.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_occs.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_occs.npy
new file mode 100644
index 00000000..7d9a6cea
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/orbs_b_occs.npy differ
diff --git a/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/quads.npy b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/quads.npy
new file mode 100644
index 00000000..e413dde7
Binary files /dev/null and b/horton/meanfield/test/cached/ch3_hf_sto3g_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/chol.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/chol.npy
new file mode 100644
index 00000000..c5b67e02
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/dipoles.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/dipoles.npy
new file mode 100644
index 00000000..b0905c30
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/dm.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/dm.npy
new file mode 100644
index 00000000..b3c1eafc
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/er.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/er.npy
new file mode 100644
index 00000000..481da0ef
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/kin.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/kin.npy
new file mode 100644
index 00000000..ac830a9d
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/na.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/na.npy
new file mode 100644
index 00000000..3347bbbe
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/olp.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/olp.npy
new file mode 100644
index 00000000..f8187f2f
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..b38eb1cc
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..a16e61c0
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..6d2eccff
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..b8a56940
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/co_pbe_sto3g_fchk/quads.npy b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/quads.npy
new file mode 100644
index 00000000..f27db801
Binary files /dev/null and b/horton/meanfield/test/cached/co_pbe_sto3g_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/chol.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/chol.npy
new file mode 100644
index 00000000..255157b9
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/dipoles.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/dipoles.npy
new file mode 100644
index 00000000..6827f3d1
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/dm.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/dm.npy
new file mode 100644
index 00000000..e65cc8e9
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/er.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/er.npy
new file mode 100644
index 00000000..7cd5ddf0
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/kin.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/kin.npy
new file mode 100644
index 00000000..6ccf3ffc
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/na.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/na.npy
new file mode 100644
index 00000000..9f0c61ca
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/olp.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/olp.npy
new file mode 100644
index 00000000..56434c60
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..0786abe0
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..555b2766
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..ee7f43ed
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..f5b5c970
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_coeffs.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_coeffs.npy
new file mode 100644
index 00000000..e1276568
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_dms.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_dms.npy
new file mode 100644
index 00000000..b3d5ca49
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_dms.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_energies.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_energies.npy
new file mode 100644
index 00000000..b97c4c2c
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_energies.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_occs.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_occs.npy
new file mode 100644
index 00000000..4a51b934
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/orbs_b_occs.npy differ
diff --git a/horton/meanfield/test/cached/h3_hfs_321g_fchk/quads.npy b/horton/meanfield/test/cached/h3_hfs_321g_fchk/quads.npy
new file mode 100644
index 00000000..de7bcf6d
Binary files /dev/null and b/horton/meanfield/test/cached/h3_hfs_321g_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/chol.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/chol.npy
new file mode 100644
index 00000000..255157b9
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/dipoles.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/dipoles.npy
new file mode 100644
index 00000000..c42e4f3b
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/dm.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/dm.npy
new file mode 100644
index 00000000..08d3496d
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/er.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/er.npy
new file mode 100644
index 00000000..7cd5ddf0
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/kin.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/kin.npy
new file mode 100644
index 00000000..6ccf3ffc
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/na.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/na.npy
new file mode 100644
index 00000000..9f0c61ca
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/olp.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/olp.npy
new file mode 100644
index 00000000..56434c60
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..fdf86b71
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..2881a03d
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..6f075e80
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..f5b5c970
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_coeffs.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_coeffs.npy
new file mode 100644
index 00000000..f67131f4
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_dms.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_dms.npy
new file mode 100644
index 00000000..dec53a1a
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_dms.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_energies.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_energies.npy
new file mode 100644
index 00000000..c99a3537
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_energies.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_occs.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_occs.npy
new file mode 100644
index 00000000..4a51b934
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/orbs_b_occs.npy differ
diff --git a/horton/meanfield/test/cached/h3_pbe_321g_fchk/quads.npy b/horton/meanfield/test/cached/h3_pbe_321g_fchk/quads.npy
new file mode 100644
index 00000000..d586d111
Binary files /dev/null and b/horton/meanfield/test/cached/h3_pbe_321g_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/chol.npy b/horton/meanfield/test/cached/h_sto3g_fchk/chol.npy
new file mode 100644
index 00000000..a081f9de
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/dipoles.npy b/horton/meanfield/test/cached/h_sto3g_fchk/dipoles.npy
new file mode 100644
index 00000000..86360319
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/dm.npy b/horton/meanfield/test/cached/h_sto3g_fchk/dm.npy
new file mode 100644
index 00000000..ee673594
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/er.npy b/horton/meanfield/test/cached/h_sto3g_fchk/er.npy
new file mode 100644
index 00000000..458f9e4d
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/kin.npy b/horton/meanfield/test/cached/h_sto3g_fchk/kin.npy
new file mode 100644
index 00000000..a4f68d1d
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/na.npy b/horton/meanfield/test/cached/h_sto3g_fchk/na.npy
new file mode 100644
index 00000000..3d039137
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/olp.npy b/horton/meanfield/test/cached/h_sto3g_fchk/olp.npy
new file mode 100644
index 00000000..083ecfe9
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..ca57591d
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..ca57591d
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..8e1473e8
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..1e6abfa1
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_coeffs.npy b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_coeffs.npy
new file mode 100644
index 00000000..ca57591d
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_dms.npy b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_dms.npy
new file mode 100644
index 00000000..76ac64bd
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_dms.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_energies.npy b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_energies.npy
new file mode 100644
index 00000000..9454f688
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_energies.npy differ
diff --git a/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_occs.npy b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_occs.npy
new file mode 100644
index 00000000..d3b1ea49
Binary files /dev/null and b/horton/meanfield/test/cached/h_sto3g_fchk/orbs_b_occs.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/chol.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/chol.npy
new file mode 100644
index 00000000..766c695c
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/dipoles.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/dipoles.npy
new file mode 100644
index 00000000..86360319
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/dm.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/dm.npy
new file mode 100644
index 00000000..aa340fe8
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/er.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/er.npy
new file mode 100644
index 00000000..88498d2d
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/kin.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/kin.npy
new file mode 100644
index 00000000..7165c742
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/na.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/na.npy
new file mode 100644
index 00000000..b4b8e10a
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/olp.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/olp.npy
new file mode 100644
index 00000000..178d1efe
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..66130146
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..9e788556
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..179d0136
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..7e62f1c8
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/he_sp_orbital_fchk/quads.npy b/horton/meanfield/test/cached/he_sp_orbital_fchk/quads.npy
new file mode 100644
index 00000000..ac83be3f
Binary files /dev/null and b/horton/meanfield/test/cached/he_sp_orbital_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/chol.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/chol.npy
new file mode 100644
index 00000000..9ac339c0
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/dipoles.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/dipoles.npy
new file mode 100644
index 00000000..86360319
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/dm.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/dm.npy
new file mode 100644
index 00000000..368f4fae
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/er.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/er.npy
new file mode 100644
index 00000000..9daeef04
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/kin.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/kin.npy
new file mode 100644
index 00000000..3dd3c50e
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/na.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/na.npy
new file mode 100644
index 00000000..69f5ffc3
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/olp.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/olp.npy
new file mode 100644
index 00000000..dfbc4c2d
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..6ba9b6ba
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..c2b5a11c
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..6a02f0ec
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..83eaad3b
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/he_spdf_orbital_fchk/quads.npy b/horton/meanfield/test/cached/he_spdf_orbital_fchk/quads.npy
new file mode 100644
index 00000000..87ff9ff2
Binary files /dev/null and b/horton/meanfield/test/cached/he_spdf_orbital_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/chol.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/chol.npy
new file mode 100644
index 00000000..2c9f6bff
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/dipoles.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/dipoles.npy
new file mode 100644
index 00000000..86360319
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/dm.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/dm.npy
new file mode 100644
index 00000000..0bd708f1
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/er.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/er.npy
new file mode 100644
index 00000000..118016a2
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/kin.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/kin.npy
new file mode 100644
index 00000000..be042525
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/na.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/na.npy
new file mode 100644
index 00000000..1efba3e7
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/olp.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/olp.npy
new file mode 100644
index 00000000..9604069e
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..ca57591d
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..ca57591d
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..2a05eb8b
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..1e6abfa1
Binary files /dev/null and b/horton/meanfield/test/cached/helium_hf_sto3g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/chol.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/chol.npy
new file mode 100644
index 00000000..c9f39c32
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/dipoles.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/dipoles.npy
new file mode 100644
index 00000000..b7b13f06
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/dm.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/dm.npy
new file mode 100644
index 00000000..51758b10
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/er.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/er.npy
new file mode 100644
index 00000000..47c079df
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/kin.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/kin.npy
new file mode 100644
index 00000000..27ad1927
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/na.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/na.npy
new file mode 100644
index 00000000..9fe7f354
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/olp.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/olp.npy
new file mode 100644
index 00000000..30f8f907
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..44a0b943
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..01b3ea96
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..b9347d71
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..5b79bded
Binary files /dev/null and b/horton/meanfield/test/cached/hf_sto3g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/chol.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/chol.npy
new file mode 100644
index 00000000..7f6654d8
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/dipoles.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/dipoles.npy
new file mode 100644
index 00000000..056a65e9
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/dm.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/dm.npy
new file mode 100644
index 00000000..e0e7292d
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/er.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/er.npy
new file mode 100644
index 00000000..ab14a15b
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/kin.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/kin.npy
new file mode 100644
index 00000000..857e7e9f
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/na.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/na.npy
new file mode 100644
index 00000000..32b036ee
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/olp.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/olp.npy
new file mode 100644
index 00000000..dfb21cd1
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..d552faa3
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..53fe6e56
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..1c31ae97
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..17aac701
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_coeffs.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_coeffs.npy
new file mode 100644
index 00000000..50519e7d
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_dms.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_dms.npy
new file mode 100644
index 00000000..ee762c77
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_dms.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_energies.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_energies.npy
new file mode 100644
index 00000000..be7152b8
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_energies.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_occs.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_occs.npy
new file mode 100644
index 00000000..74f1aedc
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/orbs_b_occs.npy differ
diff --git a/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/quads.npy b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/quads.npy
new file mode 100644
index 00000000..5a1e32e4
Binary files /dev/null and b/horton/meanfield/test/cached/li_h_3_21G_hf_g09_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/chol.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/chol.npy
new file mode 100644
index 00000000..53506d61
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/dipoles.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/dipoles.npy
new file mode 100644
index 00000000..15ddbd67
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/dm.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/dm.npy
new file mode 100644
index 00000000..3995ed46
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/er.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/er.npy
new file mode 100644
index 00000000..ee770065
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/kin.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/kin.npy
new file mode 100644
index 00000000..7e0a2305
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/na.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/na.npy
new file mode 100644
index 00000000..c65d4d3f
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/olp.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/olp.npy
new file mode 100644
index 00000000..ff06d5fe
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..a56465cc
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..511d6428
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..a1dd85de
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..d21c9e78
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_coeffs.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_coeffs.npy
new file mode 100644
index 00000000..f74ded89
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_dms.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_dms.npy
new file mode 100644
index 00000000..2e436c6d
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_dms.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_energies.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_energies.npy
new file mode 100644
index 00000000..01ef81d4
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_energies.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_occs.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_occs.npy
new file mode 100644
index 00000000..aa655515
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/orbs_b_occs.npy differ
diff --git a/horton/meanfield/test/cached/methyl_tpss_321g_fchk/quads.npy b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/quads.npy
new file mode 100644
index 00000000..910060ac
Binary files /dev/null and b/horton/meanfield/test/cached/methyl_tpss_321g_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/chol.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/chol.npy
new file mode 100644
index 00000000..54b0f035
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/dipoles.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/dipoles.npy
new file mode 100644
index 00000000..3269861e
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/dm.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/dm.npy
new file mode 100644
index 00000000..dbafa357
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/er.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/er.npy
new file mode 100644
index 00000000..01ea9402
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/kin.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/kin.npy
new file mode 100644
index 00000000..1833f326
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/na.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/na.npy
new file mode 100644
index 00000000..a2615bf7
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/olp.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/olp.npy
new file mode 100644
index 00000000..5a3c8270
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..e43185d6
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..11eb3e5e
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..d09097e1
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..b8a56940
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/quads.npy b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/quads.npy
new file mode 100644
index 00000000..3491ef07
Binary files /dev/null and b/horton/meanfield/test/cached/n2_hfs_sto3g_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/neon_6_31gd_xyz/chol.npy b/horton/meanfield/test/cached/neon_6_31gd_xyz/chol.npy
new file mode 100644
index 00000000..f48351f4
Binary files /dev/null and b/horton/meanfield/test/cached/neon_6_31gd_xyz/chol.npy differ
diff --git a/horton/meanfield/test/cached/neon_6_31gd_xyz/er.npy b/horton/meanfield/test/cached/neon_6_31gd_xyz/er.npy
new file mode 100644
index 00000000..25d507ec
Binary files /dev/null and b/horton/meanfield/test/cached/neon_6_31gd_xyz/er.npy differ
diff --git a/horton/meanfield/test/cached/neon_6_31gd_xyz/kin.npy b/horton/meanfield/test/cached/neon_6_31gd_xyz/kin.npy
new file mode 100644
index 00000000..24b1c76c
Binary files /dev/null and b/horton/meanfield/test/cached/neon_6_31gd_xyz/kin.npy differ
diff --git a/horton/meanfield/test/cached/neon_6_31gd_xyz/na.npy b/horton/meanfield/test/cached/neon_6_31gd_xyz/na.npy
new file mode 100644
index 00000000..069e6545
Binary files /dev/null and b/horton/meanfield/test/cached/neon_6_31gd_xyz/na.npy differ
diff --git a/horton/meanfield/test/cached/neon_6_31gd_xyz/olp.npy b/horton/meanfield/test/cached/neon_6_31gd_xyz/olp.npy
new file mode 100644
index 00000000..8cc82c99
Binary files /dev/null and b/horton/meanfield/test/cached/neon_6_31gd_xyz/olp.npy differ
diff --git a/horton/meanfield/test/cached/rotation_orthonormal/olp.npy b/horton/meanfield/test/cached/rotation_orthonormal/olp.npy
new file mode 100644
index 00000000..62cd0c70
Binary files /dev/null and b/horton/meanfield/test/cached/rotation_orthonormal/olp.npy differ
diff --git a/horton/meanfield/test/cached/water_3_21G_xyz/er.npy b/horton/meanfield/test/cached/water_3_21G_xyz/er.npy
new file mode 100644
index 00000000..a1334ede
Binary files /dev/null and b/horton/meanfield/test/cached/water_3_21G_xyz/er.npy differ
diff --git a/horton/meanfield/test/cached/water_3_21G_xyz/kin.npy b/horton/meanfield/test/cached/water_3_21G_xyz/kin.npy
new file mode 100644
index 00000000..53b953f3
Binary files /dev/null and b/horton/meanfield/test/cached/water_3_21G_xyz/kin.npy differ
diff --git a/horton/meanfield/test/cached/water_3_21G_xyz/na.npy b/horton/meanfield/test/cached/water_3_21G_xyz/na.npy
new file mode 100644
index 00000000..1b127291
Binary files /dev/null and b/horton/meanfield/test/cached/water_3_21G_xyz/na.npy differ
diff --git a/horton/meanfield/test/cached/water_3_21G_xyz/olp.npy b/horton/meanfield/test/cached/water_3_21G_xyz/olp.npy
new file mode 100644
index 00000000..e4c94e4a
Binary files /dev/null and b/horton/meanfield/test/cached/water_3_21G_xyz/olp.npy differ
diff --git a/horton/meanfield/test/cached/water_6_31gd_xyz/chol.npy b/horton/meanfield/test/cached/water_6_31gd_xyz/chol.npy
new file mode 100644
index 00000000..3819f0d1
Binary files /dev/null and b/horton/meanfield/test/cached/water_6_31gd_xyz/chol.npy differ
diff --git a/horton/meanfield/test/cached/water_6_31gd_xyz/er.npy b/horton/meanfield/test/cached/water_6_31gd_xyz/er.npy
new file mode 100644
index 00000000..c68ad74f
Binary files /dev/null and b/horton/meanfield/test/cached/water_6_31gd_xyz/er.npy differ
diff --git a/horton/meanfield/test/cached/water_6_31gd_xyz/kin.npy b/horton/meanfield/test/cached/water_6_31gd_xyz/kin.npy
new file mode 100644
index 00000000..b3b3de7f
Binary files /dev/null and b/horton/meanfield/test/cached/water_6_31gd_xyz/kin.npy differ
diff --git a/horton/meanfield/test/cached/water_6_31gd_xyz/na.npy b/horton/meanfield/test/cached/water_6_31gd_xyz/na.npy
new file mode 100644
index 00000000..36e49362
Binary files /dev/null and b/horton/meanfield/test/cached/water_6_31gd_xyz/na.npy differ
diff --git a/horton/meanfield/test/cached/water_6_31gd_xyz/olp.npy b/horton/meanfield/test/cached/water_6_31gd_xyz/olp.npy
new file mode 100644
index 00000000..2e45cf37
Binary files /dev/null and b/horton/meanfield/test/cached/water_6_31gd_xyz/olp.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/chol.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/chol.npy
new file mode 100644
index 00000000..3075db43
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/dipoles.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/dipoles.npy
new file mode 100644
index 00000000..a5b85469
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/dm.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/dm.npy
new file mode 100644
index 00000000..ede5265e
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/er.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/er.npy
new file mode 100644
index 00000000..8043f3d1
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/kin.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/kin.npy
new file mode 100644
index 00000000..d69ac126
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/na.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/na.npy
new file mode 100644
index 00000000..f28ac0fc
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/olp.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/olp.npy
new file mode 100644
index 00000000..2459ef77
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..0734a98f
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..ce69e9bb
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..c1c8df2d
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..ad650d87
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/water_dimer_ghost_fchk/quads.npy b/horton/meanfield/test/cached/water_dimer_ghost_fchk/quads.npy
new file mode 100644
index 00000000..0e147db7
Binary files /dev/null and b/horton/meanfield/test/cached/water_dimer_ghost_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/chol.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/chol.npy
new file mode 100644
index 00000000..ff8dd1af
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/dipoles.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/dipoles.npy
new file mode 100644
index 00000000..b505f207
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/dm.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/dm.npy
new file mode 100644
index 00000000..195ac8e1
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/er.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/er.npy
new file mode 100644
index 00000000..d93c3820
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/kin.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/kin.npy
new file mode 100644
index 00000000..c0f5e851
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/na.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/na.npy
new file mode 100644
index 00000000..62b756d8
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/olp.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/olp.npy
new file mode 100644
index 00000000..541120ea
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..e74c2d4b
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..4be736fa
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..2a6c733e
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..d4076a9b
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/water_hfs_321g_fchk/quads.npy b/horton/meanfield/test/cached/water_hfs_321g_fchk/quads.npy
new file mode 100644
index 00000000..9251f4dd
Binary files /dev/null and b/horton/meanfield/test/cached/water_hfs_321g_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/chol.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/chol.npy
new file mode 100644
index 00000000..a34f198e
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/dipoles.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/dipoles.npy
new file mode 100644
index 00000000..71a2bbe0
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/dm.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/dm.npy
new file mode 100644
index 00000000..cabae381
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/er.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/er.npy
new file mode 100644
index 00000000..e747d4da
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/kin.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/kin.npy
new file mode 100644
index 00000000..2b44e147
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/na.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/na.npy
new file mode 100644
index 00000000..91af73c2
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/olp.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/olp.npy
new file mode 100644
index 00000000..b12a7869
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..a8bb1b23
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..864f24ab
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..b9dbfbd0
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..d4076a9b
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/cached/water_m05_321g_fchk/quads.npy b/horton/meanfield/test/cached/water_m05_321g_fchk/quads.npy
new file mode 100644
index 00000000..fb076a85
Binary files /dev/null and b/horton/meanfield/test/cached/water_m05_321g_fchk/quads.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/chol.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/chol.npy
new file mode 100644
index 00000000..75f543eb
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/chol.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/dipoles.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/dipoles.npy
new file mode 100644
index 00000000..e63bd033
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/dipoles.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/dm.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/dm.npy
new file mode 100644
index 00000000..c5ad4520
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/dm.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/er.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/er.npy
new file mode 100644
index 00000000..30e56a58
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/er.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/kin.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/kin.npy
new file mode 100644
index 00000000..0b4cd75c
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/kin.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/na.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/na.npy
new file mode 100644
index 00000000..4d4c8519
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/na.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/olp.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/olp.npy
new file mode 100644
index 00000000..62bb3f3f
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/olp.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_coeffs.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_coeffs.npy
new file mode 100644
index 00000000..19ca931d
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_coeffs.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_dms.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_dms.npy
new file mode 100644
index 00000000..a5ad0e8a
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_dms.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_energies.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_energies.npy
new file mode 100644
index 00000000..909da069
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_energies.npy differ
diff --git a/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_occs.npy b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_occs.npy
new file mode 100644
index 00000000..9393d6ae
Binary files /dev/null and b/horton/meanfield/test/cached/water_sto3g_hf_g03_fchk/orbs_a_occs.npy differ
diff --git a/horton/meanfield/test/common.py b/horton/meanfield/test/common.py
index 65c48852..09a2bced 100644
--- a/horton/meanfield/test/common.py
+++ b/horton/meanfield/test/common.py
@@ -18,29 +18,28 @@
# along with this program; if not, see
#
# --
+from contextlib import contextmanager
-
+import matplotlib.pyplot as pt
import numpy as np
+from os import path
-from horton.cext import compute_nucnuc
-from horton.context import context
-from horton.gbasis.gobasis import get_gobasis
+import gobasis_data
+import mol_data as mdata
+from horton import GOBasis
from horton.grid.molgrid import BeckeMolGrid
-from horton.io.iodata import IOData
-from horton.log import log
-from horton.meanfield.builtin import RDiracExchange, UDiracExchange
-from horton.meanfield.convergence import convergence_error_eigen
-from horton.meanfield.gridgroup import RGridGroup, UGridGroup
-from horton.meanfield.guess import guess_core_hamiltonian
-from horton.meanfield.hamiltonian import REffHam, UEffHam
-from horton.meanfield.libxc import RLibXCLDA, ULibXCLDA, RLibXCGGA, ULibXCGGA, \
+from ..builtin import RDiracExchange, UDiracExchange
+from ..convergence import convergence_error_eigen
+from ..gridgroup import RGridGroup, UGridGroup
+from ..guess import guess_core_hamiltonian
+from ..hamiltonian import REffHam, UEffHam
+from ..libxc import RLibXCLDA, ULibXCLDA, RLibXCGGA, ULibXCGGA, \
ULibXCMGGA, RLibXCHybridMGGA
-from horton.meanfield.observable import RTwoIndexTerm, RDirectTerm, RExchangeTerm
-from horton.meanfield.observable import UTwoIndexTerm, UDirectTerm, UExchangeTerm
-from horton.meanfield.orbitals import Orbitals
-from horton.meanfield.occ import AufbauOccModel, FixedOccModel
-from horton.meanfield.scf_oda import check_cubic
-
+from ..observable import RTwoIndexTerm, RDirectTerm, RExchangeTerm
+from ..observable import UTwoIndexTerm, UDirectTerm, UExchangeTerm
+from ..occ import AufbauOccModel
+from ..orbitals import Orbitals
+from ..scf_oda import check_cubic
__all__ = [
'check_cubic_wrapper', 'check_interpolation', 'check_dot_hessian',
@@ -48,7 +47,7 @@
'helper_compute',
'check_hf_cs_hf', 'check_lih_os_hf', 'check_water_cs_hfs',
'check_n2_cs_hfs', 'check_h3_os_hfs', 'check_h3_os_pbe', 'check_co_cs_pbe',
- 'check_vanadium_sc_hf', 'check_water_cs_m05', 'check_methyl_os_tpss',
+ 'check_water_cs_m05', 'check_methyl_os_tpss',
]
@@ -80,7 +79,7 @@ def check_cubic_wrapper(ham, dm0s, dm1s, do_plot=False):
def check_interpolation(ham, olp, kin, na, orbs, do_plot=False):
dm0s = [orb.to_dm() for orb in orbs]
- guess_core_hamiltonian(olp, kin+na, *orbs)
+ guess_core_hamiltonian(olp, kin + na, *orbs)
dm1s = [orb.to_dm() for orb in orbs]
check_cubic_wrapper(ham, dm0s, dm1s, do_plot)
@@ -119,8 +118,6 @@ def check_dot_hessian(ham, *dms0):
focks1 = [np.zeros((nbasis, nbasis)) for _i in xrange(ham.ndm)]
dots0 = [np.zeros((nbasis, nbasis)) for _i in xrange(ham.ndm)]
dots1 = [np.zeros((nbasis, nbasis)) for _i in xrange(ham.ndm)]
- tmp1 = np.zeros((nbasis, nbasis))
- tmp2 = np.zeros((nbasis, nbasis))
for irep in xrange(nrep):
delta_dms = [np.random.normal(0, eps, (nbasis, nbasis)) for _i in xrange(ham.ndm)]
for idm in xrange(ham.ndm):
@@ -140,20 +137,20 @@ def check_dot_hessian(ham, *dms0):
tmp1 = focks0[idm] - focks1[idm]
tmp2 = np.dot(tmp1, dms0[idm])
diffsq += np.einsum('ab,ab', tmp2, tmp2)
- tmp1 += (0.5*ham.deriv_scale)*dots0[idm]
- tmp1 += (0.5*ham.deriv_scale)*dots1[idm]
+ tmp1 += (0.5 * ham.deriv_scale) * dots0[idm]
+ tmp1 += (0.5 * ham.deriv_scale) * dots1[idm]
tmp2 = np.dot(tmp1, dms0[idm])
errorsq += np.einsum('ab,ab', tmp2, tmp2)
- diffs[irep] = diffsq**0.5
- errors[irep] = errorsq**0.5
+ diffs[irep] = diffsq ** 0.5
+ errors[irep] = errorsq ** 0.5
- threshold = np.median(diffs)*0.1
+ threshold = np.median(diffs) * 0.1
mask = diffs > threshold
assert abs(errors[mask]).max() < threshold, (
- 'The first order approximation off the difference between Fock matrices is too '
- 'wrong.\nThe threshold is %.1e.\nDiffs and Errors are:\n%s') % \
- (threshold, np.array([diffs, errors]).T)
+ 'The first order approximation off the difference between Fock matrices is too '
+ 'wrong.\nThe threshold is %.1e.\nDiffs and Errors are:\n%s') % \
+ (threshold, np.array([diffs, errors]).T)
def check_dot_hessian_polynomial(olp, core, ham, orbs, is_hf=True, extent=1.0,
@@ -212,8 +209,8 @@ def check(dms_a, dms_b):
energy_a_1 = 0.0
energy_a_2 = 0.0
for idm in xrange(ham.ndm):
- energy_a_1 += np.einsum('ab,ba', focks_a[idm], delta_dms[idm])*ham.deriv_scale
- energy_a_2 += np.einsum('ab,ba', dots_a[idm], delta_dms[idm])*ham.deriv_scale**2
+ energy_a_1 += np.einsum('ab,ba', focks_a[idm], delta_dms[idm]) * ham.deriv_scale
+ energy_a_2 += np.einsum('ab,ba', dots_a[idm], delta_dms[idm]) * ham.deriv_scale ** 2
# print 'energy_a_0', energy_a_0
# print 'energy_a_1', energy_a_1
@@ -228,7 +225,7 @@ def check(dms_a, dms_b):
x = xs[ipoint]
dms_x = []
for idm in xrange(ham.ndm):
- dm_x = dms_a[idm]*(1-x) + dms_b[idm]*x
+ dm_x = dms_a[idm] * (1 - x) + dms_b[idm] * x
dms_x.append(dm_x)
ham.reset(*dms_x)
energies_x[ipoint] = ham.compute_energy()
@@ -237,12 +234,11 @@ def check(dms_a, dms_b):
derivs_x[ipoint] += np.einsum('ab,ba', focks_a[idm], delta_dms[idm]) * \
ham.deriv_scale
- energies_2nd_order[ipoint] = energy_a_0 + x*energy_a_1 + 0.5*x*x*energy_a_2
- derivs_2nd_order[ipoint] = energy_a_1 + x*energy_a_2
+ energies_2nd_order[ipoint] = energy_a_0 + x * energy_a_1 + 0.5 * x * x * energy_a_2
+ derivs_2nd_order[ipoint] = energy_a_1 + x * energy_a_2
# print '%5.2f %15.8f %15.8f' % (x, energies_x[ipoint], energies_2nd_order[ipoint])
if do_plot: # pragma: no cover
- import matplotlib.pyplot as pt
pt.clf()
pt.plot(xs, energies_x, 'ro')
pt.plot(xs, energies_2nd_order, 'k-')
@@ -252,8 +248,8 @@ def check(dms_a, dms_b):
pt.plot(xs, derivs_2nd_order, 'k-')
pt.savefig('test_derivs.png')
- assert abs(energies_x - energies_2nd_order).max()/np.ptp(energies_x) < threshold
- assert abs(derivs_x - derivs_2nd_order).max()/np.ptp(derivs_x) < threshold
+ assert abs(energies_x - energies_2nd_order).max() / np.ptp(energies_x) < threshold
+ assert abs(derivs_x - derivs_2nd_order).max() / np.ptp(derivs_x) < threshold
return energy_a_0, energy_a_1, energy_a_2
# 1) using dms1 as reference point
@@ -301,7 +297,7 @@ def check_dot_hessian_cache(ham, *dms):
def check_solve(ham, scf_solver, occ_model, olp, kin, na, *orbs):
- guess_core_hamiltonian(olp, kin+na, *orbs)
+ guess_core_hamiltonian(olp, kin + na, *orbs)
if scf_solver.kind == 'orb':
occ_model.assign(*orbs)
assert scf_solver.error(ham, olp, *orbs) > scf_solver.threshold
@@ -330,16 +326,14 @@ def helper_compute(ham, *orbs):
return ham.cache['energy'], focks
-@log.with_level(log.high)
def check_hf_cs_hf(scf_solver):
- fn_fchk = context.get_fn('test/hf_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
-
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ fname = 'hf_sto3g_fchk'
+
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+ external = {'nn': load_nn(fname)}
terms = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
@@ -348,15 +342,16 @@ def check_hf_cs_hf(scf_solver):
]
ham = REffHam(terms, external)
occ_model = AufbauOccModel(5)
+ orb_alpha = load_orbs_alpha(fname)
- check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha)
+ check_solve(ham, scf_solver, occ_model, olp, kin, na, orb_alpha)
# test orbital energies
expected_energies = np.array([
-2.59083334E+01, -1.44689996E+00, -5.57467136E-01, -4.62288194E-01,
-4.62288194E-01, 5.39578910E-01,
])
- assert abs(mol.orb_alpha.energies - expected_energies).max() < 1e-5
+ assert abs(orb_alpha.energies - expected_energies).max() < 1e-5
ham.compute_energy()
# compare with g09
@@ -367,16 +362,14 @@ def check_hf_cs_hf(scf_solver):
assert abs(ham.cache['energy_nn'] - 4.7247965053) < 1e-8
-@log.with_level(log.high)
def check_lih_os_hf(scf_solver):
- fn_fchk = context.get_fn('test/li_h_3-21G_hf_g09.fchk')
- mol = IOData.from_file(fn_fchk)
-
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ fname = 'li_h_3_21G_hf_g09_fchk'
+
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+ external = {'nn': load_nn(fname)}
terms = [
UTwoIndexTerm(kin, 'kin'),
UDirectTerm(er, 'hartree'),
@@ -386,7 +379,10 @@ def check_lih_os_hf(scf_solver):
ham = UEffHam(terms, external)
occ_model = AufbauOccModel(2, 1)
- check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha, mol.orb_beta)
+ orb_alpha = load_orbs_alpha(fname)
+ orb_beta = load_orbs_beta(fname)
+
+ check_solve(ham, scf_solver, occ_model, olp, kin, na, orb_alpha, orb_beta)
expected_alpha_energies = np.array([
-2.76116635E+00, -7.24564188E-01, -1.79148636E-01, -1.28235698E-01,
@@ -398,8 +394,8 @@ def check_lih_os_hf(scf_solver):
-1.25264964E-01, -1.24605870E-02, 5.12761388E-03, 7.70499854E-03,
7.70499854E-03, 2.85176080E-02, 1.13197479E+00,
])
- assert abs(mol.orb_alpha.energies - expected_alpha_energies).max() < 1e-5
- assert abs(mol.orb_beta.energies - expected_beta_energies).max() < 1e-5
+ assert abs(orb_alpha.energies - expected_alpha_energies).max() < 1e-5
+ assert abs(orb_beta.energies - expected_beta_energies).max() < 1e-5
ham.compute_energy()
# compare with g09
@@ -410,38 +406,40 @@ def check_lih_os_hf(scf_solver):
assert abs(ham.cache['energy_nn'] - 0.6731318487) < 1e-8
-@log.with_level(log.high)
def check_water_cs_hfs(scf_solver):
- fn_fchk = context.get_fn('test/water_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ fname = 'water_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+
+ external = {'nn': load_nn(fname)}
terms = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
- RGridGroup(mol.obasis, grid, [
+ RGridGroup(get_obasis(fname), grid, [
RDiracExchange(),
]),
RTwoIndexTerm(na, 'ne'),
]
ham = REffHam(terms, external)
+ orb_alpha = load_orbs_alpha(fname)
# The convergence should be reasonable, not perfect because of limited
# precision in Gaussian fchk file and different integration grids:
- assert convergence_error_eigen(ham, olp, mol.orb_alpha) < 3e-5
+ assert convergence_error_eigen(ham, olp, orb_alpha) < 3e-5
# Recompute the orbitals and orbital energies. This should be reasonably OK.
- dm_alpha = mol.orb_alpha.to_dm()
+ dm_alpha = load_orbsa_dms(fname)
ham.reset(dm_alpha)
ham.compute_energy()
fock_alpha = np.zeros(dm_alpha.shape)
ham.compute_fock(fock_alpha)
- mol.orb_alpha.from_fock(fock_alpha, olp)
+ orb_alpha.from_fock(fock_alpha, olp)
expected_energies = np.array([
-1.83691041E+01, -8.29412411E-01, -4.04495188E-01, -1.91740814E-01,
@@ -450,40 +448,42 @@ def check_water_cs_hfs(scf_solver):
2.71995350E+00
])
- assert abs(mol.orb_alpha.energies - expected_energies).max() < 2e-4
+ assert abs(load_orbs_alpha(fname).energies - expected_energies).max() < 2e-4
assert abs(ham.cache['energy_ne'] - -1.977921986200E+02) < 1e-7
assert abs(ham.cache['energy_kin'] - 7.525067610865E+01) < 1e-9
- assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4
+ assert abs(
+ ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4
assert abs(ham.cache['energy'] - -7.474134898935590E+01) < 2e-4
assert abs(ham.cache['energy_nn'] - 9.1571750414) < 2e-8
# Converge from scratch and check energies
occ_model = AufbauOccModel(5)
- check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha)
+ check_solve(ham, scf_solver, occ_model, olp, kin, na, load_orbs_alpha(fname))
ham.compute_energy()
assert abs(ham.cache['energy_ne'] - -1.977921986200E+02) < 1e-4
assert abs(ham.cache['energy_kin'] - 7.525067610865E+01) < 1e-4
- assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4
+ assert abs(
+ ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4
assert abs(ham.cache['energy'] - -7.474134898935590E+01) < 2e-4
-@log.with_level(log.high)
def check_n2_cs_hfs(scf_solver):
- fn_fchk = context.get_fn('test/n2_hfs_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'veryfine', random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ fname = 'n2_hfs_sto3g_fchk'
+ mdata = load_mdata(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'], 'veryfine',
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+ external = {'nn': load_nn(fname)}
libxc_term = RLibXCLDA('x')
terms1 = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
- RGridGroup(mol.obasis, grid, [libxc_term]),
+ RGridGroup(get_obasis(fname), grid, [libxc_term]),
RTwoIndexTerm(na, 'ne'),
]
ham1 = REffHam(terms1, external)
@@ -492,14 +492,14 @@ def check_n2_cs_hfs(scf_solver):
terms2 = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
- RGridGroup(mol.obasis, grid, [builtin_term]),
+ RGridGroup(get_obasis(fname), grid, [builtin_term]),
RTwoIndexTerm(na, 'ne'),
]
ham2 = REffHam(terms2, external)
# Compare the potential computed by libxc with the builtin implementation
- energy1, focks1 = helper_compute(ham1, mol.orb_alpha)
- energy2, focks2 = helper_compute(ham2, mol.orb_alpha)
+ energy1, focks1 = helper_compute(ham1, load_orbs_alpha(fname))
+ energy2, focks2 = helper_compute(ham2, load_orbs_alpha(fname))
libxc_pot = ham1.cache.load('pot_libxc_lda_x_alpha')
builtin_pot = ham2.cache.load('pot_x_dirac_alpha')
# Libxc apparently approximates values of the potential below 1e-4 with zero.
@@ -512,13 +512,13 @@ def check_n2_cs_hfs(scf_solver):
# The convergence should be reasonable, not perfect because of limited
# precision in Gaussian fchk file:
- assert convergence_error_eigen(ham1, olp, mol.orb_alpha) < 1e-5
- assert convergence_error_eigen(ham2, olp, mol.orb_alpha) < 1e-5
+ assert convergence_error_eigen(ham1, olp, load_orbs_alpha(fname)) < 1e-5
+ assert convergence_error_eigen(ham2, olp, load_orbs_alpha(fname)) < 1e-5
occ_model = AufbauOccModel(7)
for ham in ham1, ham2:
# Converge from scratch
- check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha)
+ check_solve(ham, scf_solver, occ_model, olp, kin, na, load_orbs_alpha(fname))
# test orbital energies
expected_energies = np.array([
@@ -526,33 +526,35 @@ def check_n2_cs_hfs(scf_solver):
-3.16017655E-01, -3.16017655E-01, -2.12998316E-01, 6.84030479E-02,
6.84030479E-02, 7.50192517E-01,
])
- assert abs(mol.orb_alpha.energies - expected_energies).max() < 3e-5
+ assert abs(load_orbs_alpha(fname).energies - expected_energies).max() < 3e-5
ham.compute_energy()
assert abs(ham.cache['energy_ne'] - -2.981579553570E+02) < 1e-5
assert abs(ham.cache['energy_kin'] - 1.061620887711E+02) < 1e-5
assert abs(ham.cache['energy'] - -106.205213597) < 1e-4
assert abs(ham.cache['energy_nn'] - 23.3180604505) < 1e-8
- assert abs(ham1.cache['energy_hartree'] + ham1.cache['energy_libxc_lda_x'] - 6.247259253877E+01) < 1e-4
- assert abs(ham2.cache['energy_hartree'] + ham2.cache['energy_x_dirac'] - 6.247259253877E+01) < 1e-4
+ assert abs(
+ ham1.cache['energy_hartree'] + ham1.cache['energy_libxc_lda_x'] - 6.247259253877E+01) < 1e-4
+ assert abs(
+ ham2.cache['energy_hartree'] + ham2.cache['energy_x_dirac'] - 6.247259253877E+01) < 1e-4
-@log.with_level(log.high)
def check_h3_os_hfs(scf_solver):
- fn_fchk = context.get_fn('test/h3_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'veryfine', random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ fname = 'h3_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'], 'veryfine',
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+ external = {'nn': load_nn(fname)}
libxc_term = ULibXCLDA('x')
terms1 = [
UTwoIndexTerm(kin, 'kin'),
UDirectTerm(er, 'hartree'),
- UGridGroup(mol.obasis, grid, [libxc_term]),
+ UGridGroup(get_obasis(fname), grid, [libxc_term]),
UTwoIndexTerm(na, 'ne'),
]
ham1 = UEffHam(terms1, external)
@@ -561,15 +563,15 @@ def check_h3_os_hfs(scf_solver):
terms2 = [
UTwoIndexTerm(kin, 'kin'),
UDirectTerm(er, 'hartree'),
- UGridGroup(mol.obasis, grid, [builtin_term]),
+ UGridGroup(get_obasis(fname), grid, [builtin_term]),
UTwoIndexTerm(na, 'ne'),
]
ham2 = UEffHam(terms2, external)
# Compare the potential computed by libxc with the builtin implementation
- energy1, focks1 = helper_compute(ham1, mol.orb_alpha, mol.orb_beta)
- energy2, focks2 = helper_compute(ham2, mol.orb_alpha, mol.orb_beta)
- libxc_pot = ham1.cache.load('pot_libxc_lda_x_both')[:,0]
+ energy1, focks1 = helper_compute(ham1, load_orbs_alpha(fname), load_orbs_beta(fname))
+ energy2, focks2 = helper_compute(ham2, load_orbs_alpha(fname), load_orbs_beta(fname))
+ libxc_pot = ham1.cache.load('pot_libxc_lda_x_both')[:, 0]
builtin_pot = ham2.cache.load('pot_x_dirac_alpha')
# Libxc apparently approximates values of the potential below 1e-4 with zero.
assert abs(libxc_pot - builtin_pot).max() < 1e-4
@@ -581,25 +583,26 @@ def check_h3_os_hfs(scf_solver):
# The convergence should be reasonable, not perfect because of limited
# precision in Gaussian fchk file:
- assert convergence_error_eigen(ham1, olp, mol.orb_alpha, mol.orb_beta) < 1e-5
- assert convergence_error_eigen(ham2, olp, mol.orb_alpha, mol.orb_beta) < 1e-5
+ assert convergence_error_eigen(ham1, olp, load_orbs_alpha(fname), load_orbs_beta(fname)) < 1e-5
+ assert convergence_error_eigen(ham2, olp, load_orbs_alpha(fname), load_orbs_beta(fname)) < 1e-5
occ_model = AufbauOccModel(2, 1)
for ham in ham1, ham2:
# Converge from scratch
- check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha, mol.orb_beta)
+ check_solve(ham, scf_solver, occ_model, olp, kin, na, load_orbs_alpha(fname),
+ load_orbs_beta(fname))
# test orbital energies
expected_energies = np.array([
-4.93959157E-01, -1.13961330E-01, 2.38730924E-01, 7.44216538E-01,
8.30143356E-01, 1.46613581E+00
])
- assert abs(mol.orb_alpha.energies - expected_energies).max() < 1e-5
+ assert abs(load_orbs_alpha(fname).energies - expected_energies).max() < 1e-5
expected_energies = np.array([
-4.34824166E-01, 1.84114514E-04, 3.24300545E-01, 7.87622756E-01,
9.42415831E-01, 1.55175481E+00
])
- assert abs(mol.orb_beta.energies - expected_energies).max() < 1e-5
+ assert abs(load_orbs_beta(fname).energies - expected_energies).max() < 1e-5
ham.compute_energy()
# compare with g09
@@ -608,24 +611,26 @@ def check_h3_os_hfs(scf_solver):
assert abs(ham.cache['energy'] - -1.412556114057104E+00) < 1e-5
assert abs(ham.cache['energy_nn'] - 1.8899186021) < 1e-8
- assert abs(ham1.cache['energy_hartree'] + ham1.cache['energy_libxc_lda_x'] - 1.658810998195E+00) < 1e-6
- assert abs(ham2.cache['energy_hartree'] + ham2.cache['energy_x_dirac'] - 1.658810998195E+00) < 1e-6
+ assert abs(
+ ham1.cache['energy_hartree'] + ham1.cache['energy_libxc_lda_x'] - 1.658810998195E+00) < 1e-6
+ assert abs(
+ ham2.cache['energy_hartree'] + ham2.cache['energy_x_dirac'] - 1.658810998195E+00) < 1e-6
-@log.with_level(log.high)
def check_co_cs_pbe(scf_solver):
- fn_fchk = context.get_fn('test/co_pbe_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'fine', random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ fname = 'co_pbe_sto3g_fchk'
+ mdata = load_mdata(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'], 'fine',
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+ external = {'nn': load_nn(fname)}
terms = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
- RGridGroup(mol.obasis, grid, [
+ RGridGroup(get_obasis(fname), grid, [
RLibXCGGA('x_pbe'),
RLibXCGGA('c_pbe'),
]),
@@ -634,48 +639,49 @@ def check_co_cs_pbe(scf_solver):
ham = REffHam(terms, external)
# Test energy before scf
- energy, focks = helper_compute(ham, mol.orb_alpha)
+ energy, focks = helper_compute(ham, load_orbs_alpha(fname))
assert abs(energy - -1.116465967841901E+02) < 1e-4
# The convergence should be reasonable, not perfect because of limited
# precision in Gaussian fchk file:
- assert convergence_error_eigen(ham, olp, mol.orb_alpha) < 1e-5
+ assert convergence_error_eigen(ham, olp, load_orbs_alpha(fname)) < 1e-5
# Converge from scratch
occ_model = AufbauOccModel(7)
- check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha)
+ check_solve(ham, scf_solver, occ_model, olp, kin, na, load_orbs_alpha(fname))
# test orbital energies
expected_energies = np.array([
- -1.86831122E+01, -9.73586915E+00, -1.03946082E+00, -4.09331776E-01,
- -3.48686522E-01, -3.48686522E-01, -2.06049056E-01, 5.23730418E-02,
- 5.23730418E-02, 6.61093726E-01
+ -1.86831122E+01, -9.73586915E+00, -1.03946082E+00, -4.09331776E-01,
+ -3.48686522E-01, -3.48686522E-01, -2.06049056E-01, 5.23730418E-02,
+ 5.23730418E-02, 6.61093726E-01
])
- assert abs(mol.orb_alpha.energies - expected_energies).max() < 1e-2
+ assert abs(load_orbs_alpha(fname).energies - expected_energies).max() < 1e-2
ham.compute_energy()
# compare with g09
assert abs(ham.cache['energy_ne'] - -3.072370116827E+02) < 1e-2
assert abs(ham.cache['energy_kin'] - 1.103410779827E+02) < 1e-2
- assert abs(ham.cache['energy_hartree'] + ham.cache['energy_libxc_gga_x_pbe'] + ham.cache['energy_libxc_gga_c_pbe'] - 6.273115782683E+01) < 1e-2
+ assert abs(ham.cache['energy_hartree'] + ham.cache['energy_libxc_gga_x_pbe'] + ham.cache[
+ 'energy_libxc_gga_c_pbe'] - 6.273115782683E+01) < 1e-2
assert abs(ham.cache['energy'] - -1.116465967841901E+02) < 1e-4
assert abs(ham.cache['energy_nn'] - 22.5181790889) < 1e-7
-@log.with_level(log.high)
def check_h3_os_pbe(scf_solver):
- fn_fchk = context.get_fn('test/h3_pbe_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'veryfine', random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ fname = 'h3_pbe_321g_fchk'
+ mdata = load_mdata(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'], 'veryfine',
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+ external = {'nn': load_nn(fname)}
terms = [
UTwoIndexTerm(kin, 'kin'),
UDirectTerm(er, 'hartree'),
- UGridGroup(mol.obasis, grid, [
+ UGridGroup(get_obasis(fname), grid, [
ULibXCGGA('x_pbe'),
ULibXCGGA('c_pbe'),
]),
@@ -684,86 +690,81 @@ def check_h3_os_pbe(scf_solver):
ham = UEffHam(terms, external)
# compute the energy before converging
- dm_alpha = mol.orb_alpha.to_dm()
- dm_beta = mol.orb_beta.to_dm()
+ dm_alpha = load_orbsa_dms(fname)
+ dm_beta = load_orbsb_dms(fname)
ham.reset(dm_alpha, dm_beta)
ham.compute_energy()
assert abs(ham.cache['energy'] - -1.593208400939354E+00) < 1e-5
# The convergence should be reasonable, not perfect because of limited
# precision in Gaussian fchk file:
- assert convergence_error_eigen(ham, olp, mol.orb_alpha, mol.orb_beta) < 2e-6
+ assert convergence_error_eigen(ham, olp, load_orbs_alpha(fname), load_orbs_beta(fname)) < 2e-6
# Converge from scratch
occ_model = AufbauOccModel(2, 1)
- check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha, mol.orb_beta)
+ check_solve(ham, scf_solver, occ_model, olp, kin, na, load_orbs_alpha(fname),
+ load_orbs_beta(fname))
# test orbital energies
expected_energies = np.array([
-5.41141676E-01, -1.56826691E-01, 2.13089637E-01, 7.13565167E-01,
7.86810564E-01, 1.40663544E+00
])
- assert abs(mol.orb_alpha.energies - expected_energies).max() < 2e-5
+ assert abs(load_orbs_alpha(fname).energies - expected_energies).max() < 2e-5
expected_energies = np.array([
-4.96730336E-01, -5.81411249E-02, 2.73586652E-01, 7.41987185E-01,
8.76161160E-01, 1.47488421E+00
])
- assert abs(mol.orb_beta.energies - expected_energies).max() < 2e-5
+ assert abs(load_orbs_beta(fname).energies - expected_energies).max() < 2e-5
ham.compute_energy()
# compare with g09
assert abs(ham.cache['energy_ne'] - -6.934705182067E+00) < 1e-5
assert abs(ham.cache['energy_kin'] - 1.948808793424E+00) < 1e-5
- assert abs(ham.cache['energy_hartree'] + ham.cache['energy_libxc_gga_x_pbe'] + ham.cache['energy_libxc_gga_c_pbe'] - 1.502769385597E+00) < 1e-5
+ assert abs(ham.cache['energy_hartree'] + ham.cache['energy_libxc_gga_x_pbe'] + ham.cache[
+ 'energy_libxc_gga_c_pbe'] - 1.502769385597E+00) < 1e-5
assert abs(ham.cache['energy'] - -1.593208400939354E+00) < 1e-5
assert abs(ham.cache['energy_nn'] - 1.8899186021) < 1e-8
-@log.with_level(log.high)
-def check_vanadium_sc_hf(scf_solver):
- """Try to converge the SCF for the neutral vanadium atom with fixe fractional occupations.
-
- Parameters
- ----------
- scf_solver : one of the SCFSolver types in HORTON
- A configured SCF solver that must be tested.
- """
- # vanadium atoms
- numbers = np.array([23])
- pseudo_numbers = numbers.astype(float)
- coordinates = np.zeros((1, 3), float)
-
- # Simple basis set
- obasis = get_gobasis(coordinates, numbers, 'def2-tzvpd')
-
- # Compute integrals
- olp = obasis.compute_overlap()
- kin = obasis.compute_kinetic()
- na = obasis.compute_nuclear_attraction(coordinates, pseudo_numbers)
- er = obasis.compute_electron_repulsion()
-
- # Setup of restricted HF Hamiltonian
- terms = [
- RTwoIndexTerm(kin, 'kin'),
- RDirectTerm(er, 'hartree'),
- RExchangeTerm(er, 'x_hf'),
- RTwoIndexTerm(na, 'ne'),
- ]
- ham = REffHam(terms)
-
- # Define fractional occupations of interest. (Spin-compensated case)
- occ_model = FixedOccModel(np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
- 1.0, 1.0, 0.5]))
-
- # Allocate orbitals and make the initial guess
- orb_alpha = Orbitals(obasis.nbasis)
- guess_core_hamiltonian(olp, kin+na, orb_alpha)
-
- # SCF test
- check_solve(ham, scf_solver, occ_model, olp, kin, na, orb_alpha)
+# TODO: Move to higher level test (cached integrals are too big to isolate)
+# def check_vanadium_sc_hf(scf_solver):
+# """Try to converge the SCF for the neutral vanadium atom with fixed fractional occupations.
+#
+# Parameters
+# ----------
+# scf_solver : one of the SCFSolver types in HORTON
+# A configured SCF solver that must be tested.
+# """
+# fname = "vanadium_cs_hf"
+#
+# # Compute integrals
+# olp = load_olp(fname)
+# kin = load_kin(fname)
+# na = load_na(fname)
+# er = load_er(fname)
+#
+# # Setup of restricted HF Hamiltonian
+# terms = [
+# RTwoIndexTerm(kin, 'kin'),
+# RDirectTerm(er, 'hartree'),
+# RExchangeTerm(er, 'x_hf'),
+# RTwoIndexTerm(na, 'ne'),
+# ]
+# ham = REffHam(terms)
+#
+# # Define fractional occupations of interest. (Spin-compensated case)
+# occ_model = FixedOccModel(np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+# 1.0, 1.0, 0.5]))
+#
+# # Allocate orbitals and make the initial guess
+# orb_alpha = Orbitals(olp.shape[0])
+# guess_core_hamiltonian(olp, kin + na, orb_alpha)
+#
+# # SCF test
+# check_solve(ham, scf_solver, occ_model, olp, kin, na, orb_alpha)
-@log.with_level(log.high)
def check_water_cs_m05(scf_solver):
"""Try to converge the SCF for the water molecule with the M05 functional.
@@ -772,44 +773,45 @@ def check_water_cs_m05(scf_solver):
scf_solver : one of the SCFSolver types in HORTON
A configured SCF solver that must be tested.
"""
- fn_fchk = context.get_fn('test/water_m05_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'fine',
+ fname = 'water_m05_321g_fchk'
+ mdata = load_mdata(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'], 'fine',
random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+ external = {'nn': load_nn(fname)}
libxc_term = RLibXCHybridMGGA('xc_m05')
terms = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
- RGridGroup(mol.obasis, grid, [libxc_term]),
+ RGridGroup(get_obasis(fname), grid, [libxc_term]),
RExchangeTerm(er, 'x_hf', libxc_term.get_exx_fraction()),
RTwoIndexTerm(na, 'ne'),
]
ham = REffHam(terms, external)
# compute the energy before converging
- dm_alpha = mol.orb_alpha.to_dm()
+ dm_alpha = load_orbsa_dms(fname)
ham.reset(dm_alpha)
ham.compute_energy()
assert abs(ham.cache['energy'] - -75.9532086800) < 1e-3
# The convergence should be reasonable, not perfect because of limited
# precision in the molden file:
- assert convergence_error_eigen(ham, olp, mol.orb_alpha) < 1e-3
+ orb_alpha = load_orbs_alpha(fname)
+ assert convergence_error_eigen(ham, olp, orb_alpha) < 1e-3
# keep a copy of the orbital energies
- expected_alpha_energies = mol.orb_alpha.energies.copy()
+ expected_alpha_energies = orb_alpha.energies.copy()
# Converge from scratch
occ_model = AufbauOccModel(5)
- check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha)
+ check_solve(ham, scf_solver, occ_model, olp, kin, na, orb_alpha)
# test orbital energies
- assert abs(mol.orb_alpha.energies - expected_alpha_energies).max() < 2e-3
+ assert abs(orb_alpha.energies - expected_alpha_energies).max() < 2e-3
ham.compute_energy()
# compare with
@@ -821,7 +823,6 @@ def check_water_cs_m05(scf_solver):
assert abs(ham.cache['energy_nn'] - 9.1571750414) < 1e-5
-@log.with_level(log.high)
def check_methyl_os_tpss(scf_solver):
"""Try to converge the SCF for the methyl radical molecule with the TPSS functional.
@@ -830,19 +831,19 @@ def check_methyl_os_tpss(scf_solver):
scf_solver : one of the SCFSolver types in HORTON
A configured SCF solver that must be tested.
"""
- fn_fchk = context.get_fn('test/methyl_tpss_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'fine',
+ fname = 'methyl_tpss_321g_fchk'
+ mdata = load_mdata(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'], 'fine',
random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+ external = {'nn': load_nn(fname)}
terms = [
UTwoIndexTerm(kin, 'kin'),
UDirectTerm(er, 'hartree'),
- UGridGroup(mol.obasis, grid, [
+ UGridGroup(get_obasis(fname), grid, [
ULibXCMGGA('x_tpss'),
ULibXCMGGA('c_tpss'),
]),
@@ -851,27 +852,28 @@ def check_methyl_os_tpss(scf_solver):
ham = UEffHam(terms, external)
# compute the energy before converging
- dm_alpha = mol.orb_alpha.to_dm()
- dm_beta = mol.orb_beta.to_dm()
+ dm_alpha = load_orbsa_dms(fname)
+ dm_beta = load_orbsb_dms(fname)
ham.reset(dm_alpha, dm_beta)
ham.compute_energy()
assert abs(ham.cache['energy'] - -39.6216986265) < 1e-3
# The convergence should be reasonable, not perfect because of limited
# precision in the molden file:
- assert convergence_error_eigen(ham, olp, mol.orb_alpha, mol.orb_beta) < 1e-3
+ assert convergence_error_eigen(ham, olp, load_orbs_alpha(fname), load_orbs_beta(fname)) < 1e-3
# keep a copy of the orbital energies
- expected_alpha_energies = mol.orb_alpha.energies.copy()
- expected_beta_energies = mol.orb_beta.energies.copy()
+ expected_alpha_energies = load_orbs_alpha(fname).energies.copy()
+ expected_beta_energies = load_orbs_beta(fname).energies.copy()
# Converge from scratch
occ_model = AufbauOccModel(5, 4)
- check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha, mol.orb_beta)
+ check_solve(ham, scf_solver, occ_model, olp, kin, na, load_orbs_alpha(fname),
+ load_orbs_beta(fname))
# test orbital energies
- assert abs(mol.orb_alpha.energies - expected_alpha_energies).max() < 2e-3
- assert abs(mol.orb_beta.energies - expected_beta_energies).max() < 2e-3
+ assert abs(load_orbs_alpha(fname).energies - expected_alpha_energies).max() < 2e-3
+ assert abs(load_orbs_beta(fname).energies - expected_beta_energies).max() < 2e-3
ham.compute_energy()
# compare with
@@ -881,3 +883,132 @@ def check_methyl_os_tpss(scf_solver):
ham.cache['energy_libxc_mgga_c_tpss'] - 21.55131145126) < 1e-2
assert abs(ham.cache['energy'] - -39.6216986265) < 1e-3
assert abs(ham.cache['energy_nn'] - 9.0797839705) < 1e-5
+
+
+def _compose_fn(subpath, fn, ext=".npy"):
+ cur_pth = path.split(__file__)[0]
+ pth = cur_pth + "/cached/{}/{}{}".format(fn, subpath, ext)
+ return np.load(pth).astype(np.float64)
+
+
+def load_json(fn):
+ return _compose_fn("er", fn)
+ # cur_pth = path.split(__file__)[0]
+ # pth = cur_pth + "/cached/json/{}".format(fn)
+ # with open(pth) as fh:
+ # a = np.array(json.load(fh))
+ # return a
+
+
+def load_quad(fn):
+ return _compose_fn("quads", fn)
+
+
+def load_dipole(fn):
+ return _compose_fn("dipoles", fn)
+
+
+def load_dm(fn):
+ return _compose_fn("dm", fn)
+
+
+def load_olp(fn):
+ return _compose_fn("olp", fn)
+
+
+def load_na(fn):
+ return _compose_fn("na", fn)
+
+
+def load_nn(fn):
+ return getattr(mdata, fn)['nucnuc']
+
+
+def load_kin(fn):
+ return _compose_fn("kin", fn)
+
+
+def load_er(fn):
+ return _compose_fn("er", fn)
+
+
+def load_er_chol(fn):
+ return _compose_fn("chol", fn)
+
+
+def load_orbsa_energies(fn):
+ return _compose_fn("orbs_a_energies", fn)
+
+
+def load_orbsa_coeffs(fn):
+ return _compose_fn("orbs_a_coeffs", fn)
+
+
+def load_orbsa_occs(fn):
+ return _compose_fn("orbs_a_occs", fn)
+
+
+def load_orbsa_dms(fn):
+ return _compose_fn("orbs_a_dms", fn)
+
+
+def load_orbs_alpha(fn):
+ orb_coeffs = load_orbsa_coeffs(fn)
+ orb_occs = load_orbsa_occs(fn)
+ orb_energies = load_orbsa_energies(fn)
+ orb = Orbitals(*orb_coeffs.shape)
+ orb.coeffs[:] = orb_coeffs
+ orb.occupations[:] = orb_occs
+ orb.energies[:] = orb_energies
+ return orb
+
+
+def load_orbsb_coeffs(fn):
+ return _compose_fn("orbs_b_coeffs", fn)
+
+
+def load_orbsb_occs(fn):
+ return _compose_fn("orbs_b_occs", fn)
+
+
+def load_orbsb_dms(fn):
+ return _compose_fn("orbs_b_dms", fn)
+
+
+def load_orbsb_energies(fn):
+ return _compose_fn("orbs_b_energies", fn)
+
+
+def load_orbs_beta(fn):
+ orb_coeffs = load_orbsb_coeffs(fn)
+ orb_occs = load_orbsb_occs(fn)
+ orb_energies = load_orbsb_energies(fn)
+ orb = Orbitals(*orb_coeffs.shape)
+ orb.coeffs[:] = orb_coeffs
+ orb.occupations[:] = orb_occs
+ orb.energies[:] = orb_energies
+ return orb
+
+
+def load_mdata(fn):
+ return getattr(mdata, fn)
+
+
+def get_obasis(fn):
+ params = getattr(gobasis_data, fn)
+ return GOBasis(*params)
+
+
+@contextmanager
+def numpy_seed(seed=1):
+ """Temporarily set NumPy's random seed to a given number.
+
+ Parameters
+ ----------
+ seed : int
+ The seed for NumPy's random number generator.
+ """
+ state = np.random.get_state()
+ np.random.seed(seed)
+ yield None
+ np.random.set_state(state)
diff --git a/horton/meanfield/test/gobasis_data.py b/horton/meanfield/test/gobasis_data.py
new file mode 100644
index 00000000..38bffde8
--- /dev/null
+++ b/horton/meanfield/test/gobasis_data.py
@@ -0,0 +1,289 @@
+from numpy import array
+
+h3_hfs_321g_fchk = (array([[0.0000000000000000e+00, 0.0000000000000000e+00,
+ 1.3228082900000000e+00],
+ [0.0000000000000000e+00, 0.0000000000000000e+00,
+ 0.0000000000000000e+00],
+ [1.6199729399999999e-16, 0.0000000000000000e+00,
+ -1.3228082900000000e+00]]), array([0, 0, 1, 1, 2, 2]),
+ array([2, 1, 2, 1, 2, 1]), array([0, 0, 0, 0, 0, 0]),
+ array([5.4471780000000001, 0.82454724, 0.18319158,
+ 5.4471780000000001, 0.82454724, 0.18319158,
+ 5.4471780000000001, 0.82454724, 0.18319158]),
+ array([0.156284979, 0.9046908769999999, 1.,
+ 0.156284979, 0.9046908769999999, 1.,
+ 0.156284979, 0.9046908769999999, 1.]))
+water_dimer_ghost_fchk = (array([[-0.937840183, 0.868767289, 0.],
+ [0.208982201, 2.2744296799999999, 0.],
+ [-0.734015408, 3.8242198100000002, 0.],
+ [-0.937842198, -3.7089190200000002, 0.],
+ [0.208982201, -2.30325487, 0.],
+ [-0.7340174229999999, -0.753466502, 0.]]),
+ array([0, 1, 1, 1, 2, 3, 4, 4, 4, 5]),
+ array([3, 3, 3, 3, 3, 3, 3, 3, 3, 3]),
+ array([0, 0, 0, 1, 0, 0, 0, 0, 1, 0]),
+ array([3.4252509099999999, 0.6239137300000001, 0.168855404,
+ 130.7093209999999885, 23.8088660999999995, 6.4436083100000001,
+ 5.03315132, 1.16959612, 0.38038896,
+ 5.03315132, 1.16959612, 0.38038896,
+ 3.4252509099999999, 0.6239137300000001, 0.168855404,
+ 3.4252509099999999, 0.6239137300000001, 0.168855404,
+ 130.7093209999999885, 23.8088660999999995, 6.4436083100000001,
+ 5.03315132, 1.16959612, 0.38038896,
+ 5.03315132, 1.16959612, 0.38038896,
+ 3.4252509099999999, 0.6239137300000001, 0.168855404]),
+ array([0.154328967, 0.535328142, 0.444634542, 0.154328967,
+ 0.535328142, 0.444634542, -0.0999672292, 0.399512826,
+ 0.700115469, 0.155916275, 0.607683719, 0.391957393,
+ 0.154328967, 0.535328142, 0.444634542, 0.154328967,
+ 0.535328142, 0.444634542, 0.154328967, 0.535328142,
+ 0.444634542, -0.0999672292, 0.399512826, 0.700115469,
+ 0.155916275, 0.607683719, 0.391957393, 0.154328967,
+ 0.535328142, 0.444634542]))
+n2_hfs_sto3g_fchk = (array([[0.0000000000000000e+00, 0.0000000000000000e+00,
+ 1.0506877299999999e+00],
+ [1.2867213700000000e-16, 0.0000000000000000e+00,
+ -1.0506877299999999e+00]]), array([0, 0, 0, 1, 1, 1]),
+ array([3, 3, 3, 3, 3, 3]), array([0, 0, 1, 0, 0, 1]),
+ array([99.1061689999999942, 18.0523124000000017, 4.88566024,
+ 3.7804558799999999, 0.878496645, 0.285714374,
+ 3.7804558799999999, 0.878496645, 0.285714374,
+ 99.1061689999999942, 18.0523124000000017, 4.88566024,
+ 3.7804558799999999, 0.878496645, 0.285714374,
+ 3.7804558799999999, 0.878496645, 0.285714374]),
+ array([0.154328967, 0.535328142, 0.444634542, -0.0999672292,
+ 0.399512826, 0.700115469, 0.155916275, 0.607683719,
+ 0.391957393, 0.154328967, 0.535328142, 0.444634542,
+ -0.0999672292, 0.399512826, 0.700115469, 0.155916275,
+ 0.607683719, 0.391957393]))
+he_sp_orbital_fchk = (array([[0., 0., 0.]]), array([0, 0, 0, 0, 0, 0]), array([1, 1, 1, 1, 1, 1]),
+ array([0, 0, 0, 0, 0, 1]),
+ array([98.1243000000000052, 14.7689000000000004, 3.3188300000000002,
+ 0.874047, 0.244564, 0.75]), array([1., 1., 1., 1., 1., 1.]))
+he_spdf_orbital_fchk = (
+array([[0., 0., 0.]]), array([0, 0, 0, 0]), array([1, 1, 1, 1]), array([0, 1, 2, 3]),
+array([0.04819, 0.1626, 0.351, 0.6906]), array([1., 1., 1., 1.]))
+water_m05_321g_fchk = (array([[0.0000000000000000e+00, 1.4812372599999999e+00,
+ -8.3791363799999996e-01],
+ [0.0000000000000000e+00, 0.0000000000000000e+00,
+ 2.0947841000000000e-01],
+ [-1.8139924700000000e-16, -1.4812372599999999e+00,
+ -8.3791363799999996e-01]]), array([0, 0, 1, 1, 1, 1, 1, 2, 2]),
+ array([2, 1, 3, 2, 2, 1, 1, 2, 1]), array([0, 0, 0, 0, 1, 0, 1, 0, 0]),
+ array([5.4471780000000001e+00, 8.2454724000000001e-01,
+ 1.8319157999999999e-01, 3.2203699999999998e+02,
+ 4.8430799999999998e+01, 1.0420600000000000e+01,
+ 7.4029400000000001e+00, 1.5762000000000000e+00,
+ 7.4029400000000001e+00, 1.5762000000000000e+00,
+ 3.7368400000000002e-01, 3.7368400000000002e-01,
+ 5.4471780000000001e+00, 8.2454724000000001e-01,
+ 1.8319157999999999e-01]), array([0.156284979, 0.9046908769999999, 1.,
+ 0.0592393934, 0.351499961,
+ 0.707657921,
+ -0.404453583, 1.2215617599999999,
+ 0.244586107,
+ 0.853955373, 1., 1.,
+ 0.156284979, 0.9046908769999999,
+ 1.]))
+h3_pbe_321g_fchk = (array([[0.0000000000000000e+00, 0.0000000000000000e+00,
+ 1.3228082900000000e+00],
+ [0.0000000000000000e+00, 0.0000000000000000e+00,
+ 0.0000000000000000e+00],
+ [1.6199729399999999e-16, 0.0000000000000000e+00,
+ -1.3228082900000000e+00]]), array([0, 0, 1, 1, 2, 2]),
+ array([2, 1, 2, 1, 2, 1]), array([0, 0, 0, 0, 0, 0]),
+ array([5.4471780000000001, 0.82454724, 0.18319158,
+ 5.4471780000000001, 0.82454724, 0.18319158,
+ 5.4471780000000001, 0.82454724, 0.18319158]),
+ array([0.156284979, 0.9046908769999999, 1.,
+ 0.156284979, 0.9046908769999999, 1.,
+ 0.156284979, 0.9046908769999999, 1.]))
+helium_hf_sto3g_fchk = (array([[0., 0., 0.]]), array([0]), array([3]), array([0]),
+ array([6.3624213899999997, 1.1589229999999999, 0.313649791]),
+ array([0.154328967, 0.535328142, 0.444634542]))
+h_sto3g_fchk = (array([[0., 0., 0.]]), array([0]), array([3]), array([0]),
+ array([3.4252509099999999, 0.6239137300000001, 0.168855404]),
+ array([0.154328967, 0.535328142, 0.444634542]))
+# benzene_sto3g_fchk = (array([[0.0000000000000000e+00, 2.6456167499999999e+00,
+# 0.0000000000000000e+00],
+# [-2.2911713200000001e+00, 1.3228083799999999e+00,
+# 0.0000000000000000e+00],
+# [-2.2911713200000001e+00, -1.3228083799999999e+00,
+# 0.0000000000000000e+00],
+# [-8.8817842000000006e-16, -2.6456167499999999e+00,
+# 0.0000000000000000e+00],
+# [2.2911713200000001e+00, -1.3228083799999999e+00,
+# 0.0000000000000000e+00],
+# [2.2911713200000001e+00, 1.3228083799999999e+00,
+# 0.0000000000000000e+00],
+# [-4.0733756500000000e+00, 2.3517645300000001e+00,
+# -1.2631368700000000e-23],
+# [-4.0733756500000000e+00, -2.3517645300000001e+00,
+# -2.8800807799999998e-16],
+# [-1.3322676300000001e-15, -4.7035290600000002e+00,
+# -1.2631368700000000e-23],
+# [4.0733756500000000e+00, -2.3517645300000001e+00,
+# -1.2631368700000000e-23],
+# [4.0733756500000000e+00, 2.3517645300000001e+00,
+# 4.9884465800000005e-16],
+# [3.9968028900000001e-15, 4.7035290600000002e+00,
+# -1.2631368700000000e-23]]),
+# array([0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5,
+# 5, 6, 7, 8, 9, 10, 11]),
+# array([3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+# 3]),
+# array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0,
+# 0]),
+# array([71.6168373000000003, 13.0450963000000009, 3.5305121599999998,
+# 2.94124936, 0.683483096, 0.222289916,
+# 2.94124936, 0.683483096, 0.222289916,
+# 71.6168373000000003, 13.0450963000000009, 3.5305121599999998,
+# 2.94124936, 0.683483096, 0.222289916,
+# 2.94124936, 0.683483096, 0.222289916,
+# 71.6168373000000003, 13.0450963000000009, 3.5305121599999998,
+# 2.94124936, 0.683483096, 0.222289916,
+# 2.94124936, 0.683483096, 0.222289916,
+# 71.6168373000000003, 13.0450963000000009, 3.5305121599999998,
+# 2.94124936, 0.683483096, 0.222289916,
+# 2.94124936, 0.683483096, 0.222289916,
+# 71.6168373000000003, 13.0450963000000009, 3.5305121599999998,
+# 2.94124936, 0.683483096, 0.222289916,
+# 2.94124936, 0.683483096, 0.222289916,
+# 71.6168373000000003, 13.0450963000000009, 3.5305121599999998,
+# 2.94124936, 0.683483096, 0.222289916,
+# 2.94124936, 0.683483096, 0.222289916,
+# 3.4252509099999999, 0.6239137300000001, 0.168855404,
+# 3.4252509099999999, 0.6239137300000001, 0.168855404,
+# 3.4252509099999999, 0.6239137300000001, 0.168855404,
+# 3.4252509099999999, 0.6239137300000001, 0.168855404,
+# 3.4252509099999999, 0.6239137300000001, 0.168855404,
+# 3.4252509099999999, 0.6239137300000001, 0.168855404]),
+# array([0.154328967, 0.535328142, 0.444634542, -0.0999672292,
+# 0.399512826, 0.700115469, 0.155916275, 0.607683719,
+# 0.391957393, 0.154328967, 0.535328142, 0.444634542,
+# -0.0999672292, 0.399512826, 0.700115469, 0.155916275,
+# 0.607683719, 0.391957393, 0.154328967, 0.535328142,
+# 0.444634542, -0.0999672292, 0.399512826, 0.700115469,
+# 0.155916275, 0.607683719, 0.391957393, 0.154328967,
+# 0.535328142, 0.444634542, -0.0999672292, 0.399512826,
+# 0.700115469, 0.155916275, 0.607683719, 0.391957393,
+# 0.154328967, 0.535328142, 0.444634542, -0.0999672292,
+# 0.399512826, 0.700115469, 0.155916275, 0.607683719,
+# 0.391957393, 0.154328967, 0.535328142, 0.444634542,
+# -0.0999672292, 0.399512826, 0.700115469, 0.155916275,
+# 0.607683719, 0.391957393, 0.154328967, 0.535328142,
+# 0.444634542, 0.154328967, 0.535328142, 0.444634542,
+# 0.154328967, 0.535328142, 0.444634542, 0.154328967,
+# 0.535328142, 0.444634542, 0.154328967, 0.535328142,
+# 0.444634542, 0.154328967, 0.535328142, 0.444634542]))
+water_hfs_321g_fchk = (array([[0.0000000000000000e+00, 1.4812372599999999e+00,
+ -8.3791363799999996e-01],
+ [0.0000000000000000e+00, 0.0000000000000000e+00,
+ 2.0947841000000000e-01],
+ [-1.8139924700000000e-16, -1.4812372599999999e+00,
+ -8.3791363799999996e-01]]), array([0, 0, 1, 1, 1, 1, 1, 2, 2]),
+ array([2, 1, 3, 2, 2, 1, 1, 2, 1]), array([0, 0, 0, 0, 1, 0, 1, 0, 0]),
+ array([5.4471780000000001e+00, 8.2454724000000001e-01,
+ 1.8319157999999999e-01, 3.2203699999999998e+02,
+ 4.8430799999999998e+01, 1.0420600000000000e+01,
+ 7.4029400000000001e+00, 1.5762000000000000e+00,
+ 7.4029400000000001e+00, 1.5762000000000000e+00,
+ 3.7368400000000002e-01, 3.7368400000000002e-01,
+ 5.4471780000000001e+00, 8.2454724000000001e-01,
+ 1.8319157999999999e-01]), array([0.156284979, 0.9046908769999999, 1.,
+ 0.0592393934, 0.351499961,
+ 0.707657921,
+ -0.404453583, 1.2215617599999999,
+ 0.244586107,
+ 0.853955373, 1., 1.,
+ 0.156284979, 0.9046908769999999,
+ 1.]))
+water_sto3g_hf_g03_fchk = (array([[0., 0., 0.],
+ [0., 0., 1.7952398300000001],
+ [1.69257101, 0., -0.5984063469999999]]), array([0, 0, 0, 1, 2]),
+ array([3, 3, 3, 3, 3]), array([0, 0, 1, 0, 0]),
+ array([130.7093209999999885, 23.8088660999999995, 6.4436083100000001,
+ 5.03315132, 1.16959612, 0.38038896,
+ 5.03315132, 1.16959612, 0.38038896,
+ 3.4252509099999999, 0.6239137300000001, 0.168855404,
+ 3.4252509099999999, 0.6239137300000001, 0.168855404]),
+ array([0.154328967, 0.535328142, 0.444634542, -0.0999672292,
+ 0.399512826, 0.700115469, 0.155916275, 0.607683719,
+ 0.391957393, 0.154328967, 0.535328142, 0.444634542,
+ 0.154328967, 0.535328142, 0.444634542]))
+co_pbe_sto3g_fchk = (array([[0., 0., -1.2180634699999999],
+ [0., 0., 0.913547605]]), array([0, 0, 0, 1, 1, 1]),
+ array([3, 3, 3, 3, 3, 3]), array([0, 0, 1, 0, 0, 1]),
+ array([71.6168373000000003, 13.0450963000000009, 3.5305121599999998,
+ 2.94124936, 0.683483096, 0.222289916,
+ 2.94124936, 0.683483096, 0.222289916,
+ 130.7093209999999885, 23.8088660999999995, 6.4436083100000001,
+ 5.03315132, 1.16959612, 0.38038896,
+ 5.03315132, 1.16959612, 0.38038896]),
+ array([0.154328967, 0.535328142, 0.444634542, -0.0999672292,
+ 0.399512826, 0.700115469, 0.155916275, 0.607683719,
+ 0.391957393, 0.154328967, 0.535328142, 0.444634542,
+ -0.0999672292, 0.399512826, 0.700115469, 0.155916275,
+ 0.607683719, 0.391957393]))
+ch3_hf_sto3g_fchk = (array([[0.358528636, 0.360868439, 0.360868439],
+ [-0.307236803, -0.309472858, 2.16905613],
+ [-0.307236803, 2.16905613, -0.309472858],
+ [2.16078891, -0.315607772, -0.315607772]]), array([0, 0, 0, 1, 2, 3]),
+ array([3, 3, 3, 3, 3, 3]), array([0, 0, 1, 0, 0, 0]),
+ array([71.6168373000000003, 13.0450963000000009, 3.5305121599999998,
+ 2.94124936, 0.683483096, 0.222289916,
+ 2.94124936, 0.683483096, 0.222289916,
+ 3.4252509099999999, 0.6239137300000001, 0.168855404,
+ 3.4252509099999999, 0.6239137300000001, 0.168855404,
+ 3.4252509099999999, 0.6239137300000001, 0.168855404]),
+ array([0.154328967, 0.535328142, 0.444634542, -0.0999672292,
+ 0.399512826, 0.700115469, 0.155916275, 0.607683719,
+ 0.391957393, 0.154328967, 0.535328142, 0.444634542,
+ 0.154328967, 0.535328142, 0.444634542, 0.154328967,
+ 0.535328142, 0.444634542]))
+methyl_tpss_321g_fchk = (array([[0.0000000000000000e+00, 0.0000000000000000e+00,
+ 0.0000000000000000e+00],
+ [2.6469779600000001e-23, 2.1731850499999998e+00,
+ 6.2007975699999997e-24],
+ [-1.8820334599999999e+00, -1.0865925299999999e+00,
+ 6.2007975699999997e-24],
+ [1.8820334599999999e+00, -1.0865925299999999e+00,
+ 6.2007975699999997e-24]]),
+ array([0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3]),
+ array([3, 2, 2, 1, 1, 2, 1, 2, 1, 2, 1]),
+ array([0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0]),
+ array([172.2560000000000002, 25.9109000000000016, 5.5333500000000004,
+ 3.6649799999999999, 0.770545, 3.6649799999999999,
+ 0.770545, 0.195857, 0.195857,
+ 5.4471780000000001, 0.82454724, 0.18319158,
+ 5.4471780000000001, 0.82454724, 0.18319158,
+ 5.4471780000000001, 0.82454724, 0.18319158]),
+ array([0.0617669074, 0.358794043, 0.700713084,
+ -0.395895162, 1.2158343599999999, 0.236459947,
+ 0.860618806, 1., 1.,
+ 0.156284979, 0.9046908769999999, 1.,
+ 0.156284979, 0.9046908769999999, 1.,
+ 0.156284979, 0.9046908769999999, 1.]))
+li_h_3_21G_hf_g09_fchk = (array([[0., 0., 1.11419479],
+ [0., 0., -3.3425843799999999]]), array([0, 0, 0, 0, 0, 1, 1]),
+ array([3, 2, 2, 1, 1, 2, 1]), array([0, 0, 1, 0, 1, 0, 0]),
+ array([3.6838200000000001e+01, 5.4817200000000001e+00,
+ 1.1132700000000000e+00, 5.4020500000000005e-01,
+ 1.0225500000000000e-01, 5.4020500000000005e-01,
+ 1.0225500000000000e-01, 2.8564500000000000e-02,
+ 2.8564500000000000e-02, 5.4471780000000001e+00,
+ 8.2454724000000001e-01, 1.8319157999999999e-01]),
+ array([0.0696686638, 0.381346349, 0.681702624,
+ -0.263126406, 1.14338742, 0.161545971,
+ 0.915662835, 1., 1.,
+ 0.156284979, 0.9046908769999999, 1.]))
+hf_sto3g_fchk = (array([[0., 0., 0.190484394],
+ [0., 0., -1.71435955]]), array([0, 0, 0, 1]), array([3, 3, 3, 3]),
+ array([0, 0, 1, 0]),
+ array([166.6791340000000048, 30.3608122999999992, 8.2168206700000006,
+ 6.4648032500000001, 1.5022812400000001, 0.488588486,
+ 6.4648032500000001, 1.5022812400000001, 0.488588486,
+ 3.4252509099999999, 0.6239137300000001, 0.168855404]),
+ array([0.154328967, 0.535328142, 0.444634542, -0.0999672292,
+ 0.399512826, 0.700115469, 0.155916275, 0.607683719,
+ 0.391957393, 0.154328967, 0.535328142, 0.444634542]))
diff --git a/horton/meanfield/test/mol_data.py b/horton/meanfield/test/mol_data.py
new file mode 100644
index 00000000..652aebc3
--- /dev/null
+++ b/horton/meanfield/test/mol_data.py
@@ -0,0 +1,142 @@
+from numpy import array
+
+h3_hfs_321g_fchk = {'nucnuc': 1.889918606421797, 'numbers': array([1, 1, 1]),
+ 'coordinates': array([[0.0000000000000000e+00, 0.0000000000000000e+00,
+ 1.3228082900000000e+00],
+ [0.0000000000000000e+00, 0.0000000000000000e+00,
+ 0.0000000000000000e+00],
+ [1.6199729399999999e-16, 0.0000000000000000e+00,
+ -1.3228082900000000e+00]]),
+ 'pseudo_numbers': array([1., 1., 1.])}
+water_dimer_ghost_fchk = {'nucnuc': 9.1571789976254827, 'numbers': array([1, 8, 1]),
+ 'coordinates': array([[-0.937840183, 0.868767289, 0.],
+ [0.208982201, 2.2744296799999999, 0.],
+ [-0.734015408, 3.8242198100000002, 0.]]),
+ 'pseudo_numbers': array([1., 8., 1.])}
+# h2_azirine_xyz = {'nucnuc': 64.647801652969974, 'numbers': array([7, 6, 6, 1, 1, 1]),
+# 'coordinates': array([[-1.1393158861411228, 0.9913503298550888, 0.],
+# [1.6527544767275271, 0.2864824819024618, 0.],
+# [-0.5134385905864042, -1.2778328117575508, 0.],
+# [2.6146250788934444, 0.6708527775420444,
+# 1.7544217427324904],
+# [2.6144361062800523, 0.6710417501554367,
+# -1.7546107153458825],
+# [-0.9227532711937474, -3.2949264871050952, 0.]]),
+# 'pseudo_numbers': array([7., 6., 6., 1., 1., 1.])}
+n2_hfs_sto3g_fchk = {'nucnuc': 23.318060447893497, 'numbers': array([7, 7]),
+ 'coordinates': array([[0.0000000000000000e+00, 0.0000000000000000e+00,
+ 1.0506877299999999e+00],
+ [1.2867213700000000e-16, 0.0000000000000000e+00,
+ -1.0506877299999999e+00]]),
+ 'pseudo_numbers': array([7., 7.])}
+he_sp_orbital_fchk = {'nucnuc': 0.0, 'numbers': array([2]), 'coordinates': array([[0., 0., 0.]]),
+ 'pseudo_numbers': array([2.])}
+he_spdf_orbital_fchk = {'nucnuc': 0.0, 'numbers': array([2]), 'coordinates': array([[0., 0., 0.]]),
+ 'pseudo_numbers': array([2.])}
+water_m05_321g_fchk = {'nucnuc': 9.1571750519170614, 'numbers': array([1, 8, 1]),
+ 'coordinates': array([[0.0000000000000000e+00, 1.4812372599999999e+00,
+ -8.3791363799999996e-01],
+ [0.0000000000000000e+00, 0.0000000000000000e+00,
+ 2.0947841000000000e-01],
+ [-1.8139924700000000e-16, -1.4812372599999999e+00,
+ -8.3791363799999996e-01]]),
+ 'pseudo_numbers': array([1., 8., 1.])}
+h3_pbe_321g_fchk = {'nucnuc': 1.889918606421797, 'numbers': array([1, 1, 1]),
+ 'coordinates': array([[0.0000000000000000e+00, 0.0000000000000000e+00,
+ 1.3228082900000000e+00],
+ [0.0000000000000000e+00, 0.0000000000000000e+00,
+ 0.0000000000000000e+00],
+ [1.6199729399999999e-16, 0.0000000000000000e+00,
+ -1.3228082900000000e+00]]),
+ 'pseudo_numbers': array([1., 1., 1.])}
+helium_hf_sto3g_fchk = {'nucnuc': 0.0, 'numbers': array([2]), 'coordinates': array([[0., 0., 0.]]),
+ 'pseudo_numbers': array([2.])}
+h_sto3g_fchk = {'nucnuc': 0.0, 'numbers': array([1]), 'coordinates': array([[0., 0., 0.]]),
+ 'pseudo_numbers': array([1.])}
+# benzene_sto3g_fchk = {'nucnuc': 202.7136874711675,
+# 'numbers': array([6, 6, 6, 6, 6, 6, 1, 1, 1, 1, 1, 1]),
+# 'coordinates': array([[0.0000000000000000e+00, 2.6456167499999999e+00,
+# 0.0000000000000000e+00],
+# [-2.2911713200000001e+00, 1.3228083799999999e+00,
+# 0.0000000000000000e+00],
+# [-2.2911713200000001e+00, -1.3228083799999999e+00,
+# 0.0000000000000000e+00],
+# [-8.8817842000000006e-16, -2.6456167499999999e+00,
+# 0.0000000000000000e+00],
+# [2.2911713200000001e+00, -1.3228083799999999e+00,
+# 0.0000000000000000e+00],
+# [2.2911713200000001e+00, 1.3228083799999999e+00,
+# 0.0000000000000000e+00],
+# [-4.0733756500000000e+00, 2.3517645300000001e+00,
+# -1.2631368700000000e-23],
+# [-4.0733756500000000e+00, -2.3517645300000001e+00,
+# -2.8800807799999998e-16],
+# [-1.3322676300000001e-15, -4.7035290600000002e+00,
+# -1.2631368700000000e-23],
+# [4.0733756500000000e+00, -2.3517645300000001e+00,
+# -1.2631368700000000e-23],
+# [4.0733756500000000e+00, 2.3517645300000001e+00,
+# 4.9884465800000005e-16],
+# [3.9968028900000001e-15, 4.7035290600000002e+00,
+# -1.2631368700000000e-23]]),
+# 'pseudo_numbers': array([6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1.])}
+water_hfs_321g_fchk = {'nucnuc': 9.1571750519170614, 'numbers': array([1, 8, 1]),
+ 'coordinates': array([[0.0000000000000000e+00, 1.4812372599999999e+00,
+ -8.3791363799999996e-01],
+ [0.0000000000000000e+00, 0.0000000000000000e+00,
+ 2.0947841000000000e-01],
+ [-1.8139924700000000e-16, -1.4812372599999999e+00,
+ -8.3791363799999996e-01]]),
+ 'pseudo_numbers': array([1., 8., 1.])}
+water_sto3g_hf_g03_fchk = {'nucnuc': 9.2535671885715303, 'numbers': array([8, 1, 1]),
+ 'coordinates': array([[0., 0., 0.],
+ [0., 0., 1.7952398300000001],
+ [1.69257101, 0., -0.5984063469999999]]),
+ 'pseudo_numbers': array([8., 1., 1.])}
+co_pbe_sto3g_fchk = {'nucnuc': 22.518179119518791, 'numbers': array([6, 8]),
+ 'coordinates': array([[0., 0., -1.2180634699999999],
+ [0., 0., 0.913547605]]),
+ 'pseudo_numbers': array([6., 8.])}
+ch3_hf_sto3g_fchk = {'nucnuc': 9.6788934784715845, 'numbers': array([6, 1, 1, 1]),
+ 'coordinates': array([[0.358528636, 0.360868439, 0.360868439],
+ [-0.307236803, -0.309472858, 2.16905613],
+ [-0.307236803, 2.16905613, -0.309472858],
+ [2.16078891, -0.315607772, -0.315607772]]),
+ 'pseudo_numbers': array([6., 1., 1., 1.])}
+methyl_tpss_321g_fchk = {'nucnuc': 9.0797839763629522, 'numbers': array([6, 1, 1, 1]),
+ 'coordinates': array([[0.0000000000000000e+00, 0.0000000000000000e+00,
+ 0.0000000000000000e+00],
+ [2.6469779600000001e-23, 2.1731850499999998e+00,
+ 6.2007975699999997e-24],
+ [-1.8820334599999999e+00, -1.0865925299999999e+00,
+ 6.2007975699999997e-24],
+ [1.8820334599999999e+00, -1.0865925299999999e+00,
+ 6.2007975699999997e-24]]),
+ 'pseudo_numbers': array([6., 1., 1., 1.])}
+li_h_3_21G_hf_g09_fchk = {'nucnuc': 0.67313184826252004, 'numbers': array([3, 1]),
+ 'coordinates': array([[0., 0., 1.11419479],
+ [0., 0., -3.3425843799999999]]),
+ 'pseudo_numbers': array([3., 1.])}
+hf_sto3g_fchk = {'nucnuc': 4.7247965001798597, 'numbers': array([9, 1]),
+ 'coordinates': array([[0., 0., 0.190484394],
+ [0., 0., -1.71435955]]), 'pseudo_numbers': array([9., 1.])}
+water_xyz = {'nucnuc': 9.1571750364299866, 'numbers': array([1, 8, 1]),
+ 'coordinates': array([[1.4812372636344324, -0.9301912332568615, -0.],
+ [-0., 0.1172008148257961, -0.],
+ [-1.4812372636344324, -0.9301912332568615, -0.]]),
+ 'pseudo_numbers': array([1., 8., 1.])}
+neon_6_31gd_xyz = {'nucnuc': 0.0, 'numbers': array([10]), 'coordinates': array([[0., 0., 0.]]),
+ 'pseudo_numbers': array([10.])}
+water_6_31gd_xyz = {'nucnuc': 9.1571750364299866, 'numbers': array([1, 8, 1]),
+ 'coordinates': array([[1.48123726, -0.93019123, -0.],
+ [-0., 0.11720081, -0.],
+ [-1.48123726, -0.93019123, -0.]]),
+ 'pseudo_numbers': array([1., 8., 1.])}
+# h2_azirine_3_21g_xyz = {'nucnuc': 64.647801652969974, 'numbers': array([7, 6, 6, 1, 1, 1]),
+# 'coordinates': array([[-1.13931589, 0.99135033, 0.],
+# [1.65275448, 0.28648248, 0.],
+# [-0.51343859, -1.27783281, 0.],
+# [2.61462508, 0.67085278, 1.75442174],
+# [2.61443611, 0.67104175, -1.75461072],
+# [-0.92275327, -3.29492649, 0.]]),
+# 'pseudo_numbers': array([7., 6., 6., 1., 1., 1.])}
diff --git a/horton/meanfield/test/strip_io.py b/horton/meanfield/test/strip_io.py
new file mode 100755
index 00000000..d6bf2467
--- /dev/null
+++ b/horton/meanfield/test/strip_io.py
@@ -0,0 +1,173 @@
+#!/usr/bin/env python
+import json
+from glob import glob
+
+import numpy as np
+from os import mkdir
+
+from horton import *
+
+log.set_level(log.silent)
+np.set_printoptions(precision=16)
+
+
+def grep_file():
+ """Searches a test file for IOData and saves the data"""
+ filenames = []
+ skipped = []
+ for filename in glob("test_*.py"):
+ print("Processing: ", filename)
+ with open(filename) as fh:
+ for i in fh:
+ # if ".json" in i:
+ # skipped.append((filename, i))
+ # continue
+ if "%s" in i:
+ skipped.append((filename, i))
+ continue
+
+ if "test/" in i:
+ fn, san_fn = sanitize_fn(i)
+ print fn, san_fn
+ filenames.append((fn, san_fn))
+
+ # with open("test_utils.py") as fh:
+ # for i in fh:
+ # if ".fchk" in i:
+ # fn, san_fn = unsanitize_fn(i)
+ # print fn, san_fn
+ # filenames.append((fn, san_fn))
+
+ filenames = set(filenames)
+ filenames2 = set()
+ skipped = set(skipped)
+
+ for fn, san_fn in filenames:
+ try:
+ mkdir("cached/" + san_fn)
+ except OSError:
+ pass
+
+ if "json" in san_fn:
+ save_json(context.get_fn(fn), san_fn)
+ continue
+
+ if "fchk" in san_fn:
+ flog = fn[:-4] + "log"
+ print fn, flog
+ try:
+ mol = IOData.from_file(context.get_fn(fn), context.get_fn(flog))
+ save_ints(mol, san_fn)
+ except IOError:
+ print "No log file", flog
+ mol = IOData.from_file(context.get_fn(fn))
+ save_ints(mol, san_fn)
+ pass
+
+ filenames2.add((fn, san_fn))
+
+ for i in (save_gobasis_params, save_dms, save_exps, save_moldata, save_quads, save_dipoles):
+ for fn, san_fn in filenames2:
+ mol = IOData.from_file(context.get_fn(fn))
+ try:
+ i(mol, san_fn)
+ except AttributeError:
+ print "Error on", i, san_fn
+ pass
+ print "-" * 80
+
+ print("Processed:")
+ for f in filenames:
+ print(f)
+ print("Skipped:")
+ for s in skipped:
+ print(s)
+
+
+def unsanitize_fn(line):
+ fn = line.split("'")[1]
+ san_fn = fn.replace(".", "_").replace("-", "_")
+ return "test/" + fn, san_fn
+
+
+def sanitize_fn(line):
+ if "\'" in line:
+ fn = line.split("'")[1]
+ else:
+ fn = line.split('"')[1]
+ san_fn = fn.replace(".", "_").replace("-", "_").split("/")[1]
+ return fn, san_fn
+
+
+lookup = {"olp": "compute_overlap", "kin": "compute_kinetic", "na": "compute_nuclear_attraction",
+ "er": "compute_electron_repulsion", "chol": "compute_electron_repulsion_cholesky", }
+
+
+def save_ints(mol, san_fn):
+ for i in ("olp", "kin", "na", "er", "two_mo", "chol"):
+ try:
+ np.save("{}/{}".format("cached/" + san_fn, i), getattr(mol, i))
+ except AttributeError:
+ print "Generating ints", i, "on", san_fn
+ if i == "two_mo":
+ continue
+
+ if i == "na":
+ int = getattr(mol.obasis, lookup[i])(mol.coordinates, mol.pseudo_numbers)
+ else:
+ int = getattr(mol.obasis, lookup[i])()
+ np.save("{}/{}".format("cached/" + san_fn, i), int)
+ pass
+
+
+def save_gobasis_params(mol, san_fn):
+ obasis = mol.obasis
+ print san_fn + " = ",
+ print(obasis.centers, obasis.shell_map, obasis.nprims, obasis.shell_types, obasis.alphas,
+ obasis.con_coeffs)
+
+
+def save_dms(mol, san_fn):
+ dm = mol.get_dm_full().astype(np.float32)
+ np.save("cached/" + san_fn + "/dm", dm)
+
+
+def save_exps(mol, san_fn):
+ orba = mol.orb_alpha
+ np.save("cached/" + san_fn + "/orbs_a_coeffs", orba.coeffs)
+ np.save("cached/" + san_fn + "/orbs_a_occs", orba.occupations)
+ np.save("cached/" + san_fn + "/orbs_a_dms", orba.to_dm())
+ np.save("cached/" + san_fn + "/orbs_a_energies", orba.energies)
+ orbb = mol.orb_beta
+ np.save("cached/" + san_fn + "/orbs_b_coeffs", orbb.coeffs)
+ np.save("cached/" + san_fn + "/orbs_b_occs", orbb.occupations)
+ np.save("cached/" + san_fn + "/orbs_b_dms", orbb.to_dm())
+ np.save("cached/" + san_fn + "/orbs_b_energies", orbb.energies)
+
+
+def save_moldata(mol, san_fn):
+ d = {"coordinates": mol.coordinates,
+ "numbers": mol.numbers,
+ "pseudo_numbers": mol.pseudo_numbers,
+ "nucnuc": compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ print san_fn + "=",
+ print(d)
+
+
+def save_quads(mol, san_fn):
+ quad = mol.quadrupole_moment.astype(np.float32)
+ np.save("cached/" + san_fn + "/quads", quad)
+
+
+def save_dipoles(mol, san_fn):
+ dipole = mol.dipole_moment.astype(np.float32)
+ np.save("cached/" + san_fn + "/dipoles", dipole)
+
+
+def save_json(json_fn, san_fn):
+ with open(json_fn) as fh:
+ arr = np.array(json.load(fh))
+ np.save("cached/" + san_fn + "/er", arr)
+
+
+grep_file()
diff --git a/horton/meanfield/test/test_bond_order.py b/horton/meanfield/test/test_bond_order.py
deleted file mode 100644
index 5ea8e770..00000000
--- a/horton/meanfield/test/test_bond_order.py
+++ /dev/null
@@ -1,59 +0,0 @@
-# -*- coding: utf-8 -*-
-# HORTON: Helpful Open-source Research TOol for N-fermion systems.
-# Copyright (C) 2011-2017 The HORTON Development Team
-#
-# This file is part of HORTON.
-#
-# HORTON is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 3
-# of the License, or (at your option) any later version.
-#
-# HORTON is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see
-#
-# --
-
-
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-
-
-def check_bond_orders(fn):
- mol = IOData.from_file(fn)
- operators = get_mulliken_operators(mol.obasis)
- dm_full = mol.get_dm_full()
- if dm_full is not None:
- dm_spin = mol.get_dm_spin()
- if dm_spin is not None:
- dm_alpha = 0.5*(dm_full + dm_spin)
- dm_beta = 0.5*(dm_full - dm_spin)
- bond_orders, valences, free_valences = compute_bond_orders_os(dm_alpha, dm_beta, operators)
- else:
- dm_alpha = 0.5*dm_full
- bond_orders, valences, free_valences = compute_bond_orders_cs(dm_alpha, operators)
- else:
- raise NotImplementedError
- assert abs(bond_orders.sum() - 2*mol.numbers.sum()) < 1e-3
- assert bond_orders.shape == (mol.natom, mol.natom)
- assert valences.shape == (mol.natom,)
- assert free_valences.shape == (mol.natom,)
- assert (bond_orders == bond_orders.T).all()
- assert (valences > 0).all()
- return bond_orders, valences, free_valences
-
-
-def test_bond_order_water_sto3g():
- fn_fchk = context.get_fn('test/water_sto3g_hf_g03.fchk')
- bond_orders, valences, free_valences = check_bond_orders(fn_fchk)
- assert abs(free_valences).max() < 1e-5
-
-
-def test_bond_order_h3_321g():
- fn_fchk = context.get_fn('test/h3_hfs_321g.fchk')
- bond_orders, valences, free_valences = check_bond_orders(fn_fchk)
- assert (free_valences != 0).any()
diff --git a/horton/meanfield/test/test_builtin.py b/horton/meanfield/test/test_builtin.py
index 8a8e92fb..a2f90110 100644
--- a/horton/meanfield/test/test_builtin.py
+++ b/horton/meanfield/test/test_builtin.py
@@ -18,23 +18,27 @@
# along with this program; if not, see
#
# --
-
-
import numpy as np
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
+from horton.grid import BeckeMolGrid
+from horton.meanfield.test.common import load_mdata, load_er, load_orbsa_dms, load_orbsb_dms, \
+ get_obasis
+from .. import REffHam, RDirectTerm, RGridGroup, RBeckeHartree, UEffHam, UDirectTerm, UGridGroup, \
+ UBeckeHartree
def test_becke_hartree_n2_hfs_sto3g():
- fn_fchk = context.get_fn('test/n2_hfs_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False, mode='keep')
+ fname = 'n2_hfs_sto3g_fchk'
+ mdata = load_mdata(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False,
+ mode='keep')
- er = mol.obasis.compute_electron_repulsion()
+ er = load_er(fname)
ham1 = REffHam([RDirectTerm(er, 'hartree')])
- ham2 = REffHam([RGridGroup(mol.obasis, grid, [RBeckeHartree(8)])])
+ ham2 = REffHam([RGridGroup(get_obasis(fname), grid, [RBeckeHartree(8)])])
- dm_alpha = mol.orb_alpha.to_dm()
+ dm_alpha = load_orbsa_dms(fname)
ham1.reset(dm_alpha)
ham2.reset(dm_alpha)
energy1 = ham1.compute_energy()
@@ -49,16 +53,18 @@ def test_becke_hartree_n2_hfs_sto3g():
def test_becke_hartree_h3_hfs_321g():
- fn_fchk = context.get_fn('test/h3_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False, mode='keep')
+ fname = 'h3_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False,
+ mode='keep')
- er = mol.obasis.compute_electron_repulsion()
+ er = load_er(fname)
ham1 = UEffHam([UDirectTerm(er, 'hartree')])
- ham2 = UEffHam([UGridGroup(mol.obasis, grid, [UBeckeHartree(8)])])
+ ham2 = UEffHam([UGridGroup(get_obasis(fname), grid, [UBeckeHartree(8)])])
- dm_alpha = mol.orb_alpha.to_dm()
- dm_beta = mol.orb_beta.to_dm()
+ dm_alpha = load_orbsa_dms(fname)
+ dm_beta = load_orbsb_dms(fname)
ham1.reset(dm_alpha, dm_beta)
ham2.reset(dm_alpha, dm_beta)
energy1 = ham1.compute_energy()
diff --git a/horton/test/test_cache.py b/horton/meanfield/test/test_cache.py
similarity index 94%
rename from horton/test/test_cache.py
rename to horton/meanfield/test/test_cache.py
index c8cd0a9b..08f0f875 100644
--- a/horton/test/test_cache.py
+++ b/horton/meanfield/test/test_cache.py
@@ -20,10 +20,11 @@
# --
+
import numpy as np
from nose.tools import assert_raises
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
+from ..cache import JustOnceClass, just_once, Cache
class Example(JustOnceClass):
@@ -112,16 +113,16 @@ def test_alloc1():
def test_alloc2():
c = Cache()
- tmp, new = c.load('egg', alloc=(5,10))
+ tmp, new = c.load('egg', alloc=(5, 10))
assert new
assert (tmp == 0).all()
- assert tmp.shape == (5,10)
+ assert tmp.shape == (5, 10)
assert issubclass(tmp.dtype.type, float)
tmp[3] = 1
bis = c.load('egg')
assert bis is tmp
assert (bis[3] == 1).all()
- tris, new = c.load('egg', alloc=(5,10))
+ tris, new = c.load('egg', alloc=(5, 10))
assert not new
assert tris is tmp
@@ -137,17 +138,17 @@ def test_multiple():
def test_allocation():
c = Cache()
assert 'egg' not in c
- ar1, new = c.load('egg', alloc=(5,10))
+ ar1, new = c.load('egg', alloc=(5, 10))
assert new
assert (ar1 == 0).all()
- assert ar1.shape == (5,10)
+ assert ar1.shape == (5, 10)
assert issubclass(ar1.dtype.type, float)
assert 'egg' in c
assert 'bar' not in c
with assert_raises(TypeError):
c.load('egg', alloc=10)
with assert_raises(TypeError):
- c.load('egg', alloc=(10,5))
+ c.load('egg', alloc=(10, 5))
ar1[:] = 1.0
c.clear()
assert 'egg' not in c
@@ -156,18 +157,18 @@ def test_allocation():
with assert_raises(KeyError):
ar2 = c.load('egg')
# properly load it anew
- ar2, new = c.load('egg', alloc=(5,10))
+ ar2, new = c.load('egg', alloc=(5, 10))
assert new
- assert ar2 is ar1 # still the same array, just cleared.
+ assert ar2 is ar1 # still the same array, just cleared.
assert 'egg' in c
# simple load should now work
ar3 = c.load('egg')
assert ar3 is ar1
# clear again and use different alloc
c.clear()
- ar4, new = c.load('egg', alloc=(5,1,2))
+ ar4, new = c.load('egg', alloc=(5, 1, 2))
assert new
- assert ar4.shape == (5,1,2)
+ assert ar4.shape == (5, 1, 2)
assert not ar4 is ar1
diff --git a/horton/meanfield/test/test_gridgroup.py b/horton/meanfield/test/test_gridgroup.py
index d2b97e24..4480fa20 100644
--- a/horton/meanfield/test/test_gridgroup.py
+++ b/horton/meanfield/test/test_gridgroup.py
@@ -20,25 +20,28 @@
# --
"""Test horton/meanfield/gridgroup.py."""
-
from nose.tools import assert_raises
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
+from horton.grid import BeckeMolGrid
+from horton.meanfield.test.common import get_obasis, load_mdata, load_orbs_alpha
+from .. import RGridGroup, RLibXCMGGA, UGridGroup
+from ..cache import Cache
def test_gridgroup_density_cutoff():
# prepare some molecule
- fn_fchk = context.get_fn('test/co_pbe_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
+ fname = 'co_pbe_sto3g_fchk'
+ mdata = load_mdata(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
# make and populate a fake cache object (normally done by the effective
# hamiltonian)
cache = Cache()
- cache['dm_alpha'] = mol.orb_alpha.to_dm()
+ cache['dm_alpha'] = load_orbs_alpha(fname).to_dm()
# normal use case
- rgg = RGridGroup(mol.obasis, grid, [RLibXCMGGA('c_tpss')])
+ rgg = RGridGroup(get_obasis(fname), grid, [RLibXCMGGA('c_tpss')])
alpha_basics = rgg._update_grid_basics(cache, 'alpha')
mask1 = alpha_basics[:, 0] >= 1e-9
mask2 = alpha_basics[:, 0] == 0.0
@@ -46,16 +49,17 @@ def test_gridgroup_density_cutoff():
assert (alpha_basics[mask2, :] == 0.0).all()
# use all grid points
- rgg = RGridGroup(mol.obasis, grid, [RLibXCMGGA('c_tpss')], density_cutoff=0.0)
+ rgg = RGridGroup(get_obasis(fname), grid, [RLibXCMGGA('c_tpss')], density_cutoff=0.0)
alpha_basics = rgg._update_grid_basics(cache, 'alpha')
assert (alpha_basics[:, 0] >= 0.0).all()
def test_gridgroup_exceptions():
# prepare some molecule
- fn_fchk = context.get_fn('test/co_pbe_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
+ fname = 'co_pbe_sto3g_fchk'
+ mdata = load_mdata(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
# make and populate a fake cache object (normally done by the effective
# hamiltonian)
@@ -65,14 +69,14 @@ def test_gridgroup_exceptions():
go.df_level = -1 # trigger errors
# restricted case
- rgg = RGridGroup(mol.obasis, grid, [go])
+ rgg = RGridGroup(get_obasis(fname), grid, [go])
with assert_raises(ValueError):
rgg._update_grid_basics(cache, 'alpha')
with assert_raises(ValueError):
rgg._get_potentials(cache)
# unrestricted case
- ugg = UGridGroup(mol.obasis, grid, [go])
+ ugg = UGridGroup(get_obasis(fname), grid, [go])
with assert_raises(ValueError):
ugg._update_grid_basics(cache, 'alpha')
with assert_raises(ValueError):
diff --git a/horton/meanfield/test/test_guess.py b/horton/meanfield/test/test_guess.py
index 44c6642b..c192be76 100644
--- a/horton/meanfield/test/test_guess.py
+++ b/horton/meanfield/test/test_guess.py
@@ -22,31 +22,37 @@
import numpy as np
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
+from horton.meanfield.test.common import load_orbs_alpha, load_orbs_beta, get_obasis, load_na, \
+ load_kin, load_olp
+from .. import guess_core_hamiltonian
def test_guess_hamcore_cs():
- fn_fchk = context.get_fn('test/hf_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- guess_core_hamiltonian(olp, kin+na, mol.orb_alpha)
+ fname = 'hf_sto3g_fchk'
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ orb_alpha = load_orbs_alpha(fname)
+ guess_core_hamiltonian(olp, kin + na, orb_alpha)
# just a few simple checks
- assert abs(mol.orb_alpha.energies[0] - (-2.59083334E+01)) > 1e-5 # values from fchk must be overwritten
- assert (mol.orb_alpha.energies.argsort() == np.arange(mol.obasis.nbasis)).all()
+ assert abs(
+ orb_alpha.energies[0] - (-2.59083334E+01)) > 1e-5 # values from fchk must be overwritten
+ assert (orb_alpha.energies.argsort() == np.arange(olp.shape[0])).all()
def test_guess_hamcore_os():
- fn_fchk = context.get_fn('test/li_h_3-21G_hf_g09.fchk')
- mol = IOData.from_file(fn_fchk)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- guess_core_hamiltonian(olp, kin+na, mol.orb_alpha, mol.orb_beta)
+ fname = 'li_h_3_21G_hf_g09_fchk'
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ orb_alpha = load_orbs_alpha(fname)
+ orb_beta = load_orbs_beta(fname)
+ guess_core_hamiltonian(olp, kin + na, orb_alpha, orb_beta)
# just a few simple checks
- assert abs(mol.orb_alpha.energies[0] - (-2.76116635E+00)) > 1e-5 # values from fchk must be overwritten
- assert abs(mol.orb_beta.energies[0] - (-2.76031162E+00)) > 1e-5 # values from fchk must be overwritten
- assert (mol.orb_alpha.energies.argsort() == np.arange(mol.obasis.nbasis)).all()
- assert abs(mol.orb_alpha.energies - mol.orb_beta.energies).max() < 1e-10
- assert abs(mol.orb_alpha.coeffs - mol.orb_beta.coeffs).max() < 1e-10
+ assert abs(orb_alpha.energies[0] - (
+ -2.76116635E+00)) > 1e-5 # values from fchk must be overwritten
+ assert abs(
+ orb_beta.energies[0] - (-2.76031162E+00)) > 1e-5 # values from fchk must be overwritten
+ assert (orb_alpha.energies.argsort() == np.arange(get_obasis(fname).nbasis)).all()
+ assert abs(orb_alpha.energies - orb_beta.energies).max() < 1e-10
+ assert abs(orb_alpha.coeffs - orb_beta.coeffs).max() < 1e-10
diff --git a/horton/meanfield/test/test_hamiltonian.py b/horton/meanfield/test/test_hamiltonian.py
index 2c936539..5aee6cc2 100644
--- a/horton/meanfield/test/test_hamiltonian.py
+++ b/horton/meanfield/test/test_hamiltonian.py
@@ -20,60 +20,65 @@
# --
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.meanfield.test.common import check_interpolation, helper_compute
+from horton.grid import BeckeMolGrid
+from .common import check_interpolation, helper_compute, load_mdata, load_kin, load_na, load_er, \
+ load_nn, load_orbs_alpha, load_orbs_beta, get_obasis, load_olp
+from .. import UTwoIndexTerm, UDirectTerm, UExchangeTerm, UEffHam, RTwoIndexTerm, RDirectTerm, \
+ RGridGroup, RDiracExchange, REffHam, RExchangeTerm, PlainSCFSolver, AufbauOccModel, \
+ convergence_error_eigen
def test_energy_hydrogen():
- fn_fchk = context.get_fn('test/h_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
+ fname = 'h_sto3g_fchk'
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
terms = [
UTwoIndexTerm(kin, 'kin'),
UDirectTerm(er, 'hartree'),
UExchangeTerm(er, 'x_hf'),
UTwoIndexTerm(na, 'ne'),
]
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ external = {'nn': load_nn(fname)}
ham = UEffHam(terms, external)
- helper_compute(ham, mol.orb_alpha, mol.orb_beta)
+ helper_compute(ham, load_orbs_alpha(fname), load_orbs_beta(fname))
+ print ham.cache['energy'] - -4.665818503844346E-01
assert abs(ham.cache['energy'] - -4.665818503844346E-01) < 1e-8
def test_cubic_interpolation_hfs_cs():
- fn_fchk = context.get_fn('test/water_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
+ fname = 'water_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
terms = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
- RGridGroup(mol.obasis, grid, [
+ RGridGroup(get_obasis(fname), grid, [
RDiracExchange(),
]),
RTwoIndexTerm(na, 'ne'),
]
ham = REffHam(terms)
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha])
+ check_interpolation(ham, olp, kin, na, [load_orbs_alpha(fname)])
def test_perturbation():
- fn_fchk = context.get_fn('test/n2_hfs_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
+ fname = 'n2_hfs_sto3g_fchk'
+ mdata = load_mdata(fname)
scf_solver = PlainSCFSolver(maxiter=1024)
# Without perturbation
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
terms = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
@@ -83,26 +88,28 @@ def test_perturbation():
ham = REffHam(terms)
occ_model = AufbauOccModel(7)
- assert convergence_error_eigen(ham, olp, mol.orb_alpha) > 1e-8
- scf_solver(ham, olp, occ_model, mol.orb_alpha)
- assert convergence_error_eigen(ham, olp, mol.orb_alpha) < 1e-8
+ orb_alpha = load_orbs_alpha(fname)
+
+ assert convergence_error_eigen(ham, olp, orb_alpha) > 1e-8
+ scf_solver(ham, olp, occ_model, orb_alpha)
+ assert convergence_error_eigen(ham, olp, orb_alpha) < 1e-8
energy0 = ham.compute_energy()
# Construct a perturbation based on the Mulliken AIM operator
- assert mol.obasis.nbasis % 2 == 0
- nfirst = mol.obasis.nbasis / 2
- operator = mol.obasis.compute_overlap().copy()
- operator[:nfirst,nfirst:] *= 0.5
- operator[nfirst:,:nfirst] *= 0.5
- operator[nfirst:,nfirst:] = 0.0
-
- # Apply the perturbation with oposite signs and check that, because of
+ assert get_obasis(fname).nbasis % 2 == 0
+ nfirst = get_obasis(fname).nbasis / 2
+ operator = load_olp(fname).copy()
+ operator[:nfirst, nfirst:] *= 0.5
+ operator[nfirst:, :nfirst] *= 0.5
+ operator[nfirst:, nfirst:] = 0.0
+
+ # Apply the perturbation with opposite signs and check that, because of
# symmetry, the energy of the perturbed wavefunction is the same in both
# cases, and higher than the unperturbed.
energy1_old = None
for scale in 0.1, -0.1:
# Perturbation
- tmp = scale*operator
+ tmp = scale * operator
perturbation = RTwoIndexTerm(tmp, 'pert')
# Hamiltonian
terms = [
@@ -113,9 +120,10 @@ def test_perturbation():
perturbation,
]
ham = REffHam(terms)
- assert convergence_error_eigen(ham, olp, mol.orb_alpha) > 1e-8
- scf_solver(ham, olp, occ_model, mol.orb_alpha)
- assert convergence_error_eigen(ham, olp, mol.orb_alpha) < 1e-8
+ orb_alpha = load_orbs_alpha(fname)
+ assert convergence_error_eigen(ham, olp, orb_alpha) > 1e-8
+ scf_solver(ham, olp, occ_model, orb_alpha)
+ assert convergence_error_eigen(ham, olp, orb_alpha) < 1e-8
energy1 = ham.compute_energy()
energy1 -= ham.cache['energy_pert']
@@ -127,12 +135,12 @@ def test_perturbation():
def test_ghost_hf():
- fn_fchk = context.get_fn('test/water_dimer_ghost.fchk')
- mol = IOData.from_file(fn_fchk)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, )
- er = mol.obasis.compute_electron_repulsion()
+ fname = 'water_dimer_ghost_fchk'
+ mdata = load_mdata(fname)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
terms = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
@@ -142,4 +150,4 @@ def test_ghost_hf():
ham = REffHam(terms)
# The convergence should be reasonable, not perfect because of limited
# precision in Gaussian fchk file:
- assert convergence_error_eigen(ham, olp, mol.orb_alpha) < 1e-5
+ assert convergence_error_eigen(ham, olp, load_orbs_alpha(fname)) < 1e-5
diff --git a/horton/meanfield/test/test_indextransform.py b/horton/meanfield/test/test_indextransform.py
index 3e092e33..ee367e5c 100644
--- a/horton/meanfield/test/test_indextransform.py
+++ b/horton/meanfield/test/test_indextransform.py
@@ -23,8 +23,13 @@
import numpy as np
from nose.tools import assert_raises
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.meanfield.indextransform import _parse_four_index_transform_orbs
+from horton.meanfield.test.common import load_olp, load_kin, load_na, load_er, load_nn, load_mdata, \
+ load_er_chol
+from .. import Orbitals, guess_core_hamiltonian, RTwoIndexTerm, RDirectTerm, RExchangeTerm, REffHam, \
+ AufbauOccModel, CDIISSCFSolver
+from ..indextransform import _parse_four_index_transform_orbs, four_index_transform, \
+ four_index_transform_cholesky, split_core_active, split_core_active_cholesky
+
def test_parse_index_transform_orbs():
assert _parse_four_index_transform_orbs(0, 1, 2, 3) == (0, 1, 2, 3)
@@ -84,25 +89,25 @@ def helper_hf(olp, ecore, one, two, nocc):
return ham.cache['energy'], orb_alpha
-def prepare_hf(mol, basis_str):
+def prepare_hf(fname):
# Input structure
- obasis = get_gobasis(mol.coordinates, mol.numbers, basis_str)
+ mdata = load_mdata(fname)
# Compute Gaussian integrals
- olp = obasis.compute_overlap()
- kin = obasis.compute_kinetic()
- na = obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ olp = load_olp(fname) # FIXME: Doesn't take into account basis_str
+ kin = load_kin(fname)
+ na = load_na(fname)
one = kin + na
- two = obasis.compute_electron_repulsion()
+ two = load_er(fname)
- enucnuc = compute_nucnuc(mol.coordinates, mol.pseudo_numbers)
- return obasis, olp, kin, na, one, two, enucnuc
+ enucnuc = load_nn(fname)
+ return olp, kin, na, one, two, enucnuc
-def check_core_active_blank(mol, basis_str):
- obasis, olp, kin, na, one, two, enucnuc = prepare_hf(mol, basis_str)
+def check_core_active_blank(fname):
+ olp, kin, na, one, two, enucnuc = prepare_hf(fname)
ncore = 0
- nactive = obasis.nbasis
+ nactive = olp.shape[0]
one_small, two_small, ecore = \
split_core_active(one, two, enucnuc, None, ncore, nactive)
np.testing.assert_allclose(two, two_small)
@@ -110,16 +115,17 @@ def check_core_active_blank(mol, basis_str):
np.testing.assert_allclose(one, one_small)
-def check_core_active(mol, basis_str, ncore, nactive):
+def check_core_active(fname, ncore, nactive):
# A) Run a simple HF calculation on the given IOData in the given basis
- obasis, olp, kin, na, one, two, enucnuc = prepare_hf(mol, basis_str)
+ olp, kin, na, one, two, enucnuc = prepare_hf(fname)
+ mdata = load_mdata(fname)
# Decide how to occupy the orbitals
- assert mol.numbers.sum() % 2 == 0
- nocc = mol.numbers.sum()/2
+ assert mdata['numbers'].sum() % 2 == 0
+ nocc = mdata['numbers'].sum() / 2
assert ncore + nactive > nocc
- enucnuc = compute_nucnuc(mol.coordinates, mol.pseudo_numbers)
+ enucnuc = load_nn(fname)
energy1, orb_alpha1 = helper_hf(olp, enucnuc, one, two, nocc)
# B1) Get integrals for the active space, using tensordot transformation
@@ -127,7 +133,7 @@ def check_core_active(mol, basis_str, ncore, nactive):
one, two, enucnuc, orb_alpha1, ncore, nactive)
# C1) Verify the RHF energy using the active space integrals
energy2, orb_alpha2 = helper_hf(
- np.identity(len(one_small)), ecore, one_small, two_small, nocc-ncore)
+ np.identity(len(one_small)), ecore, one_small, two_small, nocc - ncore)
np.testing.assert_almost_equal(energy1, energy2)
# B2) Get integrals for the active space, using einsum transformation
@@ -135,29 +141,27 @@ def check_core_active(mol, basis_str, ncore, nactive):
one, two, enucnuc, orb_alpha1, ncore, nactive, indextrans='einsum')
# C2) Verify the RHF energy using the active space integrals
energy2, orb_alpha2 = helper_hf(
- np.identity(len(one_small)), ecore, one_small, two_small, nocc-ncore)
+ np.identity(len(one_small)), ecore, one_small, two_small, nocc - ncore)
np.testing.assert_almost_equal(energy1, energy2)
def test_core_active_neon():
- mol = IOData(
- coordinates=np.zeros((1, 3), float),
- numbers=np.array([10], int)
- )
- check_core_active_blank(mol, '6-31+g(d)')
- check_core_active(mol, '6-31+g(d)', 2, 6)
+ fname = "neon_6_31gd_xyz"
+ check_core_active_blank(fname)
+ check_core_active(fname, 2, 6)
def test_core_active_water():
- mol = IOData.from_file(context.get_fn('test/water.xyz'))
- check_core_active_blank(mol, '6-31+g(d)')
- check_core_active(mol, '6-31+g(d)', 1, 6)
+ fname = 'water_6_31gd_xyz'
+ check_core_active_blank(fname)
+ check_core_active(fname, 1, 6)
-def test_core_active_2h_azirine():
- mol = IOData.from_file(context.get_fn('test/2h-azirine.xyz'))
- check_core_active_blank(mol, '3-21g')
- check_core_active(mol, '3-21g', 3, 15)
+# TODO: Move to higher level test
+# def test_core_active_h2_azirine():
+# fname = 'h2_azirine_3_21g_xyz'
+# check_core_active_blank(fname)
+# check_core_active(fname, 3, 15)
def helper_hf_cholesky(olp, ecore, one, two_vecs, nocc):
@@ -190,25 +194,25 @@ def helper_hf_cholesky(olp, ecore, one, two_vecs, nocc):
return ham.cache['energy'], orb_alpha
-def prepare_hf_cholesky(mol, basis_str):
+def prepare_hf_cholesky(fname):
# Input structure
- obasis = get_gobasis(mol.coordinates, mol.numbers, basis_str)
+ mdata = load_mdata(fname)
# Compute Gaussian integrals
- olp = obasis.compute_overlap()
- kin = obasis.compute_kinetic()
- na = obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
one = kin + na
- two_vecs = obasis.compute_electron_repulsion_cholesky()
+ two_vecs = load_er_chol(fname)
- enucnuc = compute_nucnuc(mol.coordinates, mol.pseudo_numbers)
- return obasis, olp, kin, na, one, two_vecs, enucnuc
+ enucnuc = load_nn(fname)
+ return olp, kin, na, one, two_vecs, enucnuc
-def check_core_active_cholesky_blank(mol, basis_str):
- obasis, olp, kin, na, one, two_vecs, enucnuc = prepare_hf_cholesky(mol, basis_str)
+def check_core_active_cholesky_blank(fname):
+ olp, kin, na, one, two_vecs, enucnuc = prepare_hf_cholesky(fname)
ncore = 0
- nactive = obasis.nbasis
+ nactive = olp.shape[0]
one_small, two_vecs_small, ecore = \
split_core_active_cholesky(one, two_vecs, enucnuc, None, ncore, nactive)
np.testing.assert_allclose(two_vecs, two_vecs_small)
@@ -216,13 +220,14 @@ def check_core_active_cholesky_blank(mol, basis_str):
np.testing.assert_allclose(one, one_small)
-def check_core_active_cholesky(mol, basis_str, ncore, nactive):
+def check_core_active_cholesky(fname, ncore, nactive):
# A) Run a simple HF calculation on the given IOData in the given basis
- obasis, olp, kin, na, one, two_vecs, enucnuc = prepare_hf_cholesky(mol, basis_str)
+ olp, kin, na, one, two_vecs, enucnuc = prepare_hf_cholesky(fname)
+ mdata = load_mdata(fname)
# Decide how to occupy the orbitals
- assert mol.numbers.sum() % 2 == 0
- nocc = mol.numbers.sum()/2
+ assert mdata['numbers'].sum() % 2 == 0
+ nocc = mdata['numbers'].sum() / 2
assert ncore + nactive > nocc
energy1, orb_alpha1 = helper_hf_cholesky(olp, enucnuc, one, two_vecs, nocc)
@@ -232,7 +237,7 @@ def check_core_active_cholesky(mol, basis_str, ncore, nactive):
one, two_vecs, enucnuc, orb_alpha1, ncore, nactive)
# C1) Verify the RHF energy using the active space integrals
energy2, orb_alpha2 = helper_hf_cholesky(
- np.identity(len(one_small)), ecore, one_small, two_vecs_small, nocc-ncore)
+ np.identity(len(one_small)), ecore, one_small, two_vecs_small, nocc - ncore)
np.testing.assert_almost_equal(energy1, energy2)
# B2) Get integrals for the active space, using einsum transformation
@@ -240,26 +245,23 @@ def check_core_active_cholesky(mol, basis_str, ncore, nactive):
one, two_vecs, enucnuc, orb_alpha1, ncore, nactive, indextrans='einsum')
# C2) Verify the RHF energy using the active space integrals
energy2, orb_alpha2 = helper_hf_cholesky(
- np.identity(len(one_small)), ecore, one_small, two_vecs_small, nocc-ncore)
+ np.identity(len(one_small)), ecore, one_small, two_vecs_small, nocc - ncore)
np.testing.assert_almost_equal(energy1, energy2)
def test_core_active_neon_cholesky():
- mol = IOData(
- coordinates=np.zeros((1, 3), float),
- numbers=np.array([10], int)
- )
- check_core_active_cholesky_blank(mol, '6-31+g(d)')
- check_core_active_cholesky(mol, '6-31+g(d)', 2, 6)
+ fname = "neon_6_31gd_xyz"
+ check_core_active_cholesky_blank(fname)
+ check_core_active_cholesky(fname, 2, 6)
def test_core_active_water_cholesky():
- mol = IOData.from_file(context.get_fn('test/water.xyz'))
- check_core_active_cholesky_blank(mol, '6-31+g(d)')
- check_core_active_cholesky(mol, '6-31+g(d)', 1, 6)
-
-
-def test_core_active_2h_azirine_cholesky():
- mol = IOData.from_file(context.get_fn('test/2h-azirine.xyz'))
- check_core_active_cholesky_blank(mol, '3-21g')
- check_core_active_cholesky(mol, '3-21g', 3, 15)
+ fname = 'water_6_31gd_xyz'
+ check_core_active_cholesky_blank(fname)
+ check_core_active_cholesky(fname, 1, 6)
+
+# TODO: Move to higher level test
+# def test_core_active_h2_azirine_cholesky():
+# fname = 'h2_azirine_3_21g_xyz'
+# check_core_active_cholesky_blank(fname)
+# check_core_active_cholesky(fname, 3, 15)
diff --git a/horton/meanfield/test/test_libxc.py b/horton/meanfield/test/test_libxc.py
index d7be19cc..74b16f9b 100644
--- a/horton/meanfield/test/test_libxc.py
+++ b/horton/meanfield/test/test_libxc.py
@@ -20,363 +20,387 @@
# --
-from nose.tools import assert_raises
+
from nose.plugins.skip import SkipTest
+from nose.tools import assert_raises
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.meanfield.test.common import check_interpolation, \
- check_dot_hessian, check_dot_hessian_polynomial, check_dot_hessian_cache
+from horton.grid import BeckeMolGrid
+from .common import check_interpolation, \
+ check_dot_hessian, check_dot_hessian_polynomial, check_dot_hessian_cache, load_olp, load_kin, \
+ load_na, get_obasis, load_mdata, load_orbs_alpha, load_orbsa_dms, load_orbs_beta, \
+ load_orbsb_dms, load_er
+from .. import RGridGroup, RLibXCGGA, REffHam, RLibXCLDA, RLibXCHybridGGA, UGridGroup, ULibXCGGA, \
+ RLibXCMGGA, UEffHam, ULibXCLDA, ULibXCHybridGGA, UExchangeTerm, ULibXCMGGA, RLibXCWrapper, \
+ RLibXCHybridMGGA, ULibXCHybridMGGA
def setup_gga_cs(name):
- """Prepare datastructures for R-GGA calculation in CO."""
- fn_fchk = context.get_fn('test/co_pbe_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- mol.dm_alpha = mol.orb_alpha.to_dm()
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ """Prepare data structures for R-GGA calculation in CO."""
+ fname = 'co_pbe_sto3g_fchk'
+ mdata = load_mdata(fname)
+ dm_alpha = load_orbsa_dms(fname)
+ orb_alpha = load_orbs_alpha(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
terms = [
- RGridGroup(mol.obasis, grid, [
+ RGridGroup(get_obasis(fname), grid, [
RLibXCGGA(name),
]),
]
ham = REffHam(terms)
- return mol, olp, kin, na, ham
+ return dm_alpha, olp, kin, na, ham, orb_alpha
def test_cubic_interpolation_c_pbe_cs():
- mol, olp, kin, na, ham = setup_gga_cs('c_pbe')
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha])
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_gga_cs('c_pbe')
+ check_interpolation(ham, olp, kin, na, [orb_alpha])
def test_dot_hessian_c_pbe_cs():
- mol, _olp, _kin, _na, ham = setup_gga_cs('c_pbe')
- check_dot_hessian(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_gga_cs('c_pbe')
+ check_dot_hessian(ham, dm_alpha)
def test_dot_hessian_c_pbe_cs_polynomial():
- mol, olp, kin, na, ham = setup_gga_cs('c_pbe')
- check_dot_hessian_polynomial(olp, kin+na, ham, [mol.orb_alpha], is_hf=False, extent=0.00005)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_gga_cs('c_pbe')
+ check_dot_hessian_polynomial(olp, kin + na, ham, [orb_alpha], is_hf=False, extent=0.00005)
def test_dot_hessian_c_pbe_cs_cache():
- mol, _olp, _kin, _na, ham = setup_gga_cs('c_pbe')
- check_dot_hessian_cache(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_gga_cs('c_pbe')
+ check_dot_hessian_cache(ham, dm_alpha)
def test_cubic_interpolation_x_pbe_cs():
- mol, olp, kin, na, ham = setup_gga_cs('x_pbe')
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha])
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_gga_cs('x_pbe')
+ check_interpolation(ham, olp, kin, na, [orb_alpha])
def test_dot_hessian_x_pbe_cs():
- mol, _olp, _kin, _na, ham = setup_gga_cs('x_pbe')
- check_dot_hessian(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_gga_cs('x_pbe')
+ check_dot_hessian(ham, dm_alpha)
def test_dot_hessian_x_pbe_cs_polynomial():
- mol, olp, kin, na, ham = setup_gga_cs('x_pbe')
- check_dot_hessian_polynomial(olp, kin+na, ham, [mol.orb_alpha], is_hf=False, extent=0.00005)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_gga_cs('x_pbe')
+ check_dot_hessian_polynomial(olp, kin + na, ham, [orb_alpha], is_hf=False, extent=0.00005)
def test_dot_hessian_x_pbe_cs_cache():
- mol, _olp, _kin, _na, ham = setup_gga_cs('x_pbe')
- check_dot_hessian_cache(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_gga_cs('x_pbe')
+ check_dot_hessian_cache(ham, dm_alpha)
def setup_hfs_cs():
- """Prepare datastructures for R-HFS (x-functional-only) calculation on CO."""
- fn_fchk = context.get_fn('test/co_pbe_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- mol.dm_alpha = mol.orb_alpha.to_dm()
+ """Prepare data structures for R-HFS (x-functional-only) calculation on CO."""
+ fname = 'co_pbe_sto3g_fchk'
+ mdata = load_mdata(fname)
+ dm_alpha = load_orbsa_dms(fname)
+ orb_alpha = load_orbs_alpha(fname)
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers,
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
'coarse', random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
terms = [
- RGridGroup(mol.obasis, grid, [
+ RGridGroup(get_obasis(fname), grid, [
RLibXCLDA('x'),
]),
]
ham = REffHam(terms)
- return mol, olp, kin, na, ham
+ return dm_alpha, olp, kin, na, ham, orb_alpha
def test_cubic_interpolation_hfs_cs():
- mol, olp, kin, na, ham = setup_hfs_cs()
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha])
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_hfs_cs()
+ check_interpolation(ham, olp, kin, na, [orb_alpha])
def test_dot_hessian_hfs_cs():
- mol, _olp, _kin, _na, ham = setup_hfs_cs()
- check_dot_hessian(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_hfs_cs()
+ check_dot_hessian(ham, dm_alpha)
def test_dot_hessian_hfs_cs_polynomial():
- mol, olp, kin, na, ham = setup_hfs_cs()
- check_dot_hessian_polynomial(olp, kin+na, ham, [mol.orb_alpha], is_hf=False, extent=0.00005)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_hfs_cs()
+ check_dot_hessian_polynomial(olp, kin + na, ham, [orb_alpha], is_hf=False, extent=0.00005)
def test_dot_hessian_hfs_cs_cache():
- mol, _olp, _kin, _na, ham = setup_hfs_cs()
- check_dot_hessian_cache(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_hfs_cs()
+ check_dot_hessian_cache(ham, dm_alpha)
def setup_x_pbe_c_vwn_cs():
- """Setup datastructure for mixed GGA+LDA calculation."""
+ """Setup data structure for mixed GGA+LDA calculation."""
# mixing of GGA and LDA
- fn_fchk = context.get_fn('test/water_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- mol.dm_alpha = mol.orb_alpha.to_dm()
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ fname = 'water_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+ dm_alpha = load_orbsa_dms(fname)
+ orb_alpha = load_orbs_alpha(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
terms = [
- RGridGroup(mol.obasis, grid, [
+ RGridGroup(get_obasis(fname), grid, [
RLibXCGGA('x_pbe'),
RLibXCLDA('c_vwn'),
]),
]
ham = REffHam(terms)
- return mol, olp, kin, na, ham
+ return dm_alpha, olp, kin, na, ham, orb_alpha
def test_cubic_interpolation_x_pbe_c_vwn_cs():
- mol, olp, kin, na, ham = setup_x_pbe_c_vwn_cs()
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha])
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_x_pbe_c_vwn_cs()
+ check_interpolation(ham, olp, kin, na, [orb_alpha])
def test_dot_hessian_x_pbe_c_vwn_cs():
- mol, _olp, _kin, _na, ham = setup_x_pbe_c_vwn_cs()
- check_dot_hessian(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_x_pbe_c_vwn_cs()
+ check_dot_hessian(ham, dm_alpha)
def test_dot_hessian_x_pbe_c_vwn_cs_polynomial():
- mol, olp, kin, na, ham = setup_x_pbe_c_vwn_cs()
- check_dot_hessian_polynomial(olp, kin+na, ham, [mol.orb_alpha], is_hf=False, extent=0.00005)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_x_pbe_c_vwn_cs()
+ check_dot_hessian_polynomial(olp, kin + na, ham, [orb_alpha], is_hf=False, extent=0.00005)
def test_dot_hessian_x_pbe_c_vwn_cs_cache():
- mol, _olp, _kin, _na, ham = setup_x_pbe_c_vwn_cs()
- check_dot_hessian_cache(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_x_pbe_c_vwn_cs()
+ check_dot_hessian_cache(ham, dm_alpha)
def setup_c_vwn_cs():
- """Prepare datastructures for R-VWN (c-functional-only) calculation on water."""
- fn_fchk = context.get_fn('test/water_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- mol.dm_alpha = mol.orb_alpha.to_dm()
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ """Prepare data structures for R-VWN (c-functional-only) calculation on water."""
+ fname = 'water_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+ dm_alpha = load_orbsa_dms(fname)
+ orb_alpha = load_orbs_alpha(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
terms = [
- RGridGroup(mol.obasis, grid, [
+ RGridGroup(get_obasis(fname), grid, [
RLibXCLDA('c_vwn'),
]),
]
ham = REffHam(terms)
- return mol, olp, kin, na, ham
+ return dm_alpha, olp, kin, na, ham, orb_alpha
def test_cubic_interpolation_c_vwn_cs():
- mol, olp, kin, na, ham = setup_c_vwn_cs()
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha])
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_c_vwn_cs()
+ check_interpolation(ham, olp, kin, na, [orb_alpha])
def test_dot_hessian_c_vwn_cs():
- mol, _olp, _kin, _na, ham = setup_c_vwn_cs()
- check_dot_hessian(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_c_vwn_cs()
+ check_dot_hessian(ham, dm_alpha)
def test_dot_hessian_c_vwn_cs_polynomial():
- mol, olp, kin, na, ham = setup_c_vwn_cs()
- check_dot_hessian_polynomial(olp, kin+na, ham, [mol.orb_alpha], is_hf=False, extent=0.00005)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_c_vwn_cs()
+ check_dot_hessian_polynomial(olp, kin + na, ham, [orb_alpha], is_hf=False, extent=0.00005)
def test_dot_hessian_c_vwn_cs_cache():
- mol, _olp, _kin, _na, ham = setup_c_vwn_cs()
- check_dot_hessian_cache(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_c_vwn_cs()
+ check_dot_hessian_cache(ham, dm_alpha)
def setup_o3lyp_cs():
- """Prepare datastructures for R-O3LYP (xc-functional-only) calculation on water."""
- fn_fchk = context.get_fn('test/water_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- mol.dm_alpha = mol.orb_alpha.to_dm()
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ """Prepare data structures for R-O3LYP (xc-functional-only) calculation on water."""
+ fname = 'water_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+ dm_alpha = load_orbsa_dms(fname)
+ orb_alpha = load_orbs_alpha(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
libxc_term = RLibXCHybridGGA('xc_o3lyp')
terms = [
- RGridGroup(mol.obasis, grid, [libxc_term]),
+ RGridGroup(get_obasis(fname), grid, [libxc_term]),
]
ham = REffHam(terms)
- return mol, olp, kin, na, ham
+ return dm_alpha, olp, kin, na, ham, orb_alpha
def test_cubic_interpolation_o3lyp_cs():
- mol, olp, kin, na, ham = setup_o3lyp_cs()
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha])
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_o3lyp_cs()
+ check_interpolation(ham, olp, kin, na, [orb_alpha])
def test_dot_hessian_o3lyp_cs():
- mol, _olp, _kin, _na, ham = setup_o3lyp_cs()
- check_dot_hessian(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_o3lyp_cs()
+ check_dot_hessian(ham, dm_alpha)
def test_dot_hessian_o3lyp_cs_polynomial():
raise SkipTest("We should use more robust tests for derivatives.")
- # mol, olp, kin, na, ham = setup_o3lyp_cs()
- # check_dot_hessian_polynomial(olp, kin+na, ham, [mol.orb_alpha], is_hf=False, extent=0.00001)
+ # dm_alpha, olp, kin, na, ham, orb_alpha = setup_o3lyp_cs()
+ # check_dot_hessian_polynomial(olp, kin+na, ham, [orb_alpha], is_hf=False, extent=0.00001)
def test_dot_hessian_o3lyp_cs_cache():
- mol, _olp, _kin, _na, ham = setup_o3lyp_cs()
- check_dot_hessian_cache(ham, mol.dm_alpha)
+ dm_alpha, olp, kin, na, ham, orb_alpha = setup_o3lyp_cs()
+ check_dot_hessian_cache(ham, dm_alpha)
def test_cubic_interpolation_x_tpss_cs():
- fn_fchk = context.get_fn('test/water_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ fname = 'water_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
terms = [
- RGridGroup(mol.obasis, grid, [RLibXCMGGA('x_tpss')]),
+ RGridGroup(get_obasis(fname), grid, [RLibXCMGGA('x_tpss')]),
]
ham = REffHam(terms)
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha])
+ check_interpolation(ham, olp, kin, na, [load_orbs_alpha(fname)])
def test_cubic_interpolation_c_pbe_os():
- fn_fchk = context.get_fn('test/h3_pbe_321g.fchk')
- mol = IOData.from_file(fn_fchk)
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ fname = 'h3_pbe_321g_fchk'
+ mdata = load_mdata(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
terms = [
- UGridGroup(mol.obasis, grid, [
+ UGridGroup(get_obasis(fname), grid, [
ULibXCGGA('c_pbe'),
]),
]
ham = UEffHam(terms)
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha, mol.orb_beta])
+ check_interpolation(ham, olp, kin, na, [load_orbs_alpha(fname), load_orbs_beta(fname)])
def test_cubic_interpolation_x_pbe_os():
- fn_fchk = context.get_fn('test/h3_pbe_321g.fchk')
- mol = IOData.from_file(fn_fchk)
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ fname = 'h3_pbe_321g_fchk'
+ mdata = load_mdata(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
terms = [
- UGridGroup(mol.obasis, grid, [
+ UGridGroup(get_obasis(fname), grid, [
ULibXCGGA('x_pbe'),
]),
]
ham = UEffHam(terms)
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha, mol.orb_beta])
+ check_interpolation(ham, olp, kin, na, [load_orbs_alpha(fname), load_orbs_beta(fname)])
def setup_hfs_os():
- """Prepare datastructures for U_HFS (x-functional-only) calculation in H3 radical."""
- fn_fchk = context.get_fn('test/h3_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- mol.dm_alpha = mol.orb_alpha.to_dm()
- mol.dm_beta = mol.orb_beta.to_dm()
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ """Prepare data structures for U_HFS (x-functional-only) calculation in H3 radical."""
+ fname = 'h3_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+ dm_alpha = load_orbsa_dms(fname)
+ dm_beta = load_orbsb_dms(fname)
+ orb_alpha = load_orbs_alpha(fname)
+ orb_beta = load_orbs_beta(fname)
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
terms = [
- UGridGroup(mol.obasis, grid, [
+ UGridGroup(get_obasis(fname), grid, [
ULibXCLDA('x'),
]),
]
ham = UEffHam(terms)
- return mol, olp, kin, na, ham
+ return dm_alpha, dm_beta, olp, kin, na, ham, orb_alpha, orb_beta
def test_cubic_interpolation_hfs_os():
- mol, olp, kin, na, ham = setup_hfs_os()
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha, mol.orb_beta])
+ dm_alpha, dm_beta, olp, kin, na, ham, orb_alpha, orb_beta = setup_hfs_os()
+ check_interpolation(ham, olp, kin, na, [orb_alpha, orb_beta])
def test_cubic_interpolation_x_pbe_c_vwn_os():
# mixing of LDA and GGA
- fn_fchk = context.get_fn('test/h3_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ fname = 'h3_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
terms = [
- UGridGroup(mol.obasis, grid, [
+ UGridGroup(get_obasis(fname), grid, [
ULibXCGGA('x_pbe'),
ULibXCLDA('c_vwn'),
]),
]
ham = UEffHam(terms)
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha, mol.orb_beta])
+ check_interpolation(ham, olp, kin, na, [load_orbs_alpha(fname), load_orbs_beta(fname)])
def test_cubic_interpolation_o3lyp_os():
- fn_fchk = context.get_fn('test/h3_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
+ fname = 'h3_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
libxc_term = ULibXCHybridGGA('xc_o3lyp')
terms = [
- UGridGroup(mol.obasis, grid, [libxc_term]),
+ UGridGroup(get_obasis(fname), grid, [libxc_term]),
UExchangeTerm(er, 'x_hf', libxc_term.get_exx_fraction()),
]
ham = UEffHam(terms)
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha, mol.orb_beta])
+ check_interpolation(ham, olp, kin, na, [load_orbs_alpha(fname), load_orbs_beta(fname)])
def test_cubic_interpolation_x_tpss_os():
# mixing of LDA and GGA
- fn_fchk = context.get_fn('test/h3_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
-
- grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ fname = 'h3_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+
+ grid = BeckeMolGrid(mdata['coordinates'], mdata['numbers'], mdata['pseudo_numbers'],
+ random_rotate=False)
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
terms = [
- UGridGroup(mol.obasis, grid, [ULibXCMGGA('x_tpss')]),
+ UGridGroup(get_obasis(fname), grid, [ULibXCMGGA('x_tpss')]),
]
ham = UEffHam(terms)
- check_interpolation(ham, olp, kin, na, [mol.orb_alpha, mol.orb_beta])
+ check_interpolation(ham, olp, kin, na, [load_orbs_alpha(fname), load_orbs_beta(fname)])
def test_functionals_present():
- t1 = RLibXCLDA('c_vwn') # The VWN 5 functional
+ t1 = RLibXCLDA('c_vwn') # The VWN 5 functional
assert t1._libxc_wrapper.key == 'lda_c_vwn'
- t2 = RLibXCLDA('c_vwn_4') # The VWN 4 functional
+ t2 = RLibXCLDA('c_vwn_4') # The VWN 4 functional
assert t2._libxc_wrapper.key == 'lda_c_vwn_4'
t3 = RLibXCHybridGGA('xc_wb97x')
assert t3._libxc_wrapper.key == 'hyb_gga_xc_wb97x'
@@ -397,7 +421,6 @@ def test_functionals_present():
URL = {http://journals.cambridge.org/article_S0305004100016108}
}"""
-
ref_lda_x_2 = """\
@article{Bloch1929_545,
title = {Bemerkung zur Elektronentheorie des Ferromagnetismus und der elektrischen \
diff --git a/horton/meanfield/test/test_observable.py b/horton/meanfield/test/test_observable.py
index 48dfd006..293c6ed5 100644
--- a/horton/meanfield/test/test_observable.py
+++ b/horton/meanfield/test/test_observable.py
@@ -20,26 +20,28 @@
# --
"""Unit tests for horton/meanfield/observable.py."""
+from .common import check_dot_hessian, \
+ check_dot_hessian_polynomial, check_dot_hessian_cache, load_orbsa_dms, load_orbsb_dms, load_olp, \
+ load_kin, load_na, load_er, load_er_chol, load_orbs_alpha, load_orbs_beta
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.meanfield.test.common import check_dot_hessian, \
- check_dot_hessian_polynomial, check_dot_hessian_cache
+from .. import RTwoIndexTerm, RDirectTerm, RExchangeTerm, REffHam, UTwoIndexTerm, UDirectTerm, \
+ UExchangeTerm, UEffHam
def setup_rhf_case(cholesky=False):
- """Prepare datastructures for R-HF calculation on Water."""
- fn_fchk = context.get_fn('test/water_sto3g_hf_g03.fchk')
- mol = IOData.from_file(fn_fchk)
- mol.dm_alpha = mol.orb_alpha.to_dm()
+ """Prepare data structures for R-HF calculation on Water."""
+ fname = 'water_sto3g_hf_g03_fchk'
+ dm_alpha = load_orbsa_dms(fname)
+ orb_alpha = load_orbs_alpha(fname)
# RHF Effective Hamiltonian
- olp = mol.obasis.compute_overlap()
- core = mol.obasis.compute_kinetic()
- mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, core)
+ olp = load_olp(fname)
+ core = load_kin(fname)
+ core += load_na(fname)
if cholesky:
- er = mol.obasis.compute_electron_repulsion_cholesky()
+ er = load_er_chol(fname)
else:
- er = mol.obasis.compute_electron_repulsion()
+ er = load_er(fname)
terms = [
RTwoIndexTerm(core, 'core'),
RDirectTerm(er, 'hartree'),
@@ -47,51 +49,53 @@ def setup_rhf_case(cholesky=False):
]
ham = REffHam(terms)
- return mol, olp, core, ham
+ return dm_alpha, olp, core, ham, orb_alpha
def test_dot_hessian_rhf_polynomial():
- mol, olp, core, ham = setup_rhf_case()
- check_dot_hessian_polynomial(olp, core, ham, [mol.orb_alpha])
+ dma, olp, core, ham, orb_alpha = setup_rhf_case()
+ check_dot_hessian_polynomial(olp, core, ham, [orb_alpha])
def test_dot_hessian_rhf_fd():
- mol, _olp, _core, ham = setup_rhf_case()
- check_dot_hessian(ham, mol.dm_alpha)
+ dma, olp, core, ham, orb_alpha = setup_rhf_case()
+ check_dot_hessian(ham, dma)
def test_cache_dot_hessian_rhf():
- mol, _olp, _core, ham = setup_rhf_case()
- check_dot_hessian_cache(ham, mol.dm_alpha)
+ dma, olp, core, ham, orb_alpha = setup_rhf_case()
+ check_dot_hessian_cache(ham, dma)
def test_dot_hessian_rhf_polynomial_cholesky():
- mol, olp, core, ham = setup_rhf_case(True)
- check_dot_hessian_polynomial(olp, core, ham, [mol.orb_alpha])
+ dma, olp, core, ham, orb_alpha = setup_rhf_case(True)
+ check_dot_hessian_polynomial(olp, core, ham, [orb_alpha])
def test_dot_hessian_rhf_fd_cholesky():
- mol, _olp, _core, ham = setup_rhf_case(True)
- check_dot_hessian(ham, mol.dm_alpha)
+ dma, olp, core, ham, orb_alpha = setup_rhf_case(True)
+ check_dot_hessian(ham, dma)
def test_cache_dot_hessian_rhf_cholesky():
- mol, _olp, _core, ham = setup_rhf_case(True)
- check_dot_hessian_cache(ham, mol.dm_alpha)
+ dma, olp, core, ham, orb_alpha = setup_rhf_case(True)
+ check_dot_hessian_cache(ham, dma)
def setup_uhf_case(cholesky=False):
- """Prepare datastructures for UHF calculation."""
- fn_fchk = context.get_fn('test/h3_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- mol.dm_alpha = mol.orb_alpha.to_dm()
- mol.dm_beta = mol.orb_beta.to_dm()
+ """Prepare data structures for UHF calculation."""
+ fname = 'h3_hfs_321g_fchk'
+ dma = load_orbsa_dms(fname)
+ dmb = load_orbsb_dms(fname)
+
+ orb_alpha = load_orbs_alpha(fname)
+ orb_beta = load_orbs_beta(fname)
# UHF Effective Hamiltonian
- olp = mol.obasis.compute_overlap()
- core = mol.obasis.compute_kinetic()
- mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, core)
- er = mol.obasis.compute_electron_repulsion()
+ olp = load_olp(fname)
+ core = load_kin(fname)
+ core += load_na(fname)
+ er = load_er(fname)
terms = [
UTwoIndexTerm(core, 'core'),
UDirectTerm(er, 'hartree'),
@@ -99,34 +103,34 @@ def setup_uhf_case(cholesky=False):
]
ham = UEffHam(terms)
- return mol, olp, core, ham
+ return dma, dmb, olp, core, ham, orb_alpha, orb_beta
def test_dot_hessian_uhf_polynomial():
- mol, olp, core, ham = setup_uhf_case()
- check_dot_hessian_polynomial(olp, core, ham, [mol.orb_alpha, mol.orb_beta])
+ dma, dmb, olp, core, ham, orb_alpha, orb_beta = setup_uhf_case()
+ check_dot_hessian_polynomial(olp, core, ham, [orb_alpha, orb_beta])
def test_dot_hessian_uhf_fd():
- mol, _olp, _core, ham = setup_uhf_case()
- check_dot_hessian(ham, mol.dm_alpha, mol.dm_beta)
+ dma, dmb, olp, core, ham, orb_alpha, orb_beta = setup_uhf_case()
+ check_dot_hessian(ham, dma, dmb)
def test_cache_dot_hessian_uhf():
- mol, _olp, _core, ham = setup_uhf_case()
- check_dot_hessian_cache(ham, mol.dm_alpha, mol.dm_beta)
+ dma, dmb, olp, core, ham, orb_alpha, orb_beta = setup_uhf_case()
+ check_dot_hessian_cache(ham, dma, dmb)
def test_dot_hessian_uhf_polynomial_cholesky():
- mol, olp, core, ham = setup_uhf_case(True)
- check_dot_hessian_polynomial(olp, core, ham, [mol.orb_alpha, mol.orb_beta])
+ dma, dmb, olp, core, ham, orb_alpha, orb_beta = setup_uhf_case(True)
+ check_dot_hessian_polynomial(olp, core, ham, [orb_alpha, orb_beta])
def test_dot_hessian_uhf_fd_cholesky():
- mol, _olp, _core, ham = setup_uhf_case(True)
- check_dot_hessian(ham, mol.dm_alpha, mol.dm_beta)
+ dma, dmb, olp, core, ham, orb_alpha, orb_beta = setup_uhf_case(True)
+ check_dot_hessian(ham, dma, dmb)
def test_cache_dot_hessian_uhf_cholesky():
- mol, _olp, _core, ham = setup_uhf_case(True)
- check_dot_hessian_cache(ham, mol.dm_alpha, mol.dm_beta)
+ dma, dmb, olp, core, ham, orb_alpha, orb_beta = setup_uhf_case(True)
+ check_dot_hessian_cache(ham, dma, dmb)
diff --git a/horton/meanfield/test/test_occ.py b/horton/meanfield/test/test_occ.py
index 03722682..e3b53e74 100644
--- a/horton/meanfield/test/test_occ.py
+++ b/horton/meanfield/test/test_occ.py
@@ -22,7 +22,8 @@
import numpy as np
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
+from .common import load_orbs_alpha, load_orbs_beta
+from .. import Orbitals, AufbauOccModel, FermiOccModel, FixedOccModel
def test_occ_aufbau_cs():
@@ -62,47 +63,47 @@ def test_occ_aufbau_os():
def test_fermi_occ_model_cs_helium():
- fn_fchk = context.get_fn('test/helium_hf_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
+ fname = 'helium_hf_sto3g_fchk'
occ_model = FermiOccModel(1.0)
- occ_model.assign(mol.orb_alpha)
- assert (mol.orb_alpha.occupations == [1.0]).all()
+ occ_model.assign(load_orbs_alpha(fname))
+ assert (load_orbs_alpha(fname).occupations == [1.0]).all()
def test_fermi_occ_model_cs():
- fn_fchk = context.get_fn('test/water_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
+ fname = 'water_hfs_321g_fchk'
for temperature in 300, 3000, 10000, 30000:
occ_model = FermiOccModel(5.0, temperature=temperature)
- occ_model.assign(mol.orb_alpha)
- occ = mol.orb_alpha.occupations
+ occ_model.assign(load_orbs_alpha(fname))
+ occ = load_orbs_alpha(fname).occupations
assert abs(occ.sum() - 5.0) < 1e-8
assert (occ[1:] <= occ[:-1]).all()
def test_fermi_occ_model_os():
- fn_fchk = context.get_fn('test/li_h_3-21G_hf_g09.fchk')
- mol = IOData.from_file(fn_fchk)
+ fname = 'li_h_3_21G_hf_g09_fchk'
for temperature in 300, 3000, 10000, 30000:
occ_model = FermiOccModel(1.9, 1.1, temperature=temperature)
- occ_model.assign(mol.orb_alpha, mol.orb_beta)
- occ_a = mol.orb_alpha.occupations
+ orb_alpha = load_orbs_alpha(fname)
+ orb_beta = load_orbs_beta(fname)
+ occ_model.assign(orb_alpha, orb_beta)
+ occ_a = orb_alpha.occupations
assert abs(occ_a.sum() - 1.9) < 1e-8
assert (occ_a[1:] <= occ_a[:-1]).all()
- occ_b = mol.orb_beta.occupations
+ occ_b = orb_beta.occupations
assert abs(occ_b.sum() - 1.1) < 1e-8
assert (occ_b[1:] <= occ_b[:-1]).all()
def test_fixed_occ_model_os():
- fn_fchk = context.get_fn('test/li_h_3-21G_hf_g09.fchk')
- mol = IOData.from_file(fn_fchk)
+ fname = 'li_h_3_21G_hf_g09_fchk'
occs_alpha = np.array([2.0, 0.0, 0.5])
occs_beta = np.array([0.0, 0.5, 0.0, 0.0])
occ_model = FixedOccModel(occs_alpha, occs_beta)
- mol.orb_alpha.occupations[:] = 0.2
- occ_model.assign(mol.orb_alpha, mol.orb_beta)
- assert (mol.orb_alpha.occupations[:len(occs_alpha)] == occs_alpha).all()
- assert (mol.orb_alpha.occupations[len(occs_alpha):] == 0.0).all()
- assert (mol.orb_beta.occupations[:len(occs_beta)] == occs_beta).all()
- assert (mol.orb_beta.occupations[len(occs_beta):] == 0.0).all()
+ load_orbs_alpha(fname).occupations[:] = 0.2
+ orb_alpha = load_orbs_alpha(fname)
+ orb_beta = load_orbs_beta(fname)
+ occ_model.assign(orb_alpha, orb_beta)
+ assert (orb_alpha.occupations[:len(occs_alpha)] == occs_alpha).all()
+ assert (orb_alpha.occupations[len(occs_alpha):] == 0.0).all()
+ assert (orb_beta.occupations[:len(occs_beta)] == occs_beta).all()
+ assert (orb_beta.occupations[len(occs_beta):] == 0.0).all()
diff --git a/horton/meanfield/test/test_orbitals.py b/horton/meanfield/test/test_orbitals.py
index dcb52952..f0b089e4 100644
--- a/horton/meanfield/test/test_orbitals.py
+++ b/horton/meanfield/test/test_orbitals.py
@@ -20,12 +20,14 @@
# --
-import numpy as np
import h5py as h5
+import numpy as np
from nose.tools import assert_raises
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
+from horton.meanfield.test.common import load_mdata, load_olp, load_orbs_alpha, load_orbs_beta, \
+ load_dm
from horton.test.common import numpy_seed
+from .. import Orbitals
#
@@ -64,7 +66,7 @@ def get_signs(n):
It is guaranteed that not all signs are positive.
"""
while True:
- signs = np.random.randint(0, 1, n)*2 -1
+ signs = np.random.randint(0, 1, n) * 2 - 1
if (signs < 0).any():
return signs
@@ -76,7 +78,7 @@ def get_random_orbitals(nbasis):
a = a + a.T
evals, evecs = np.linalg.eigh(a)
orb.coeffs[:] = evecs
- orb.occupations[:nbasis/2] = 1.0
+ orb.occupations[:nbasis / 2] = 1.0
orb.energies[:] = np.random.uniform(-1, 1, nbasis)
orb.energies.sort()
olp = np.identity(nbasis)
@@ -91,7 +93,8 @@ def test_orbitals_hdf5():
for args in (4,), (6, 3):
a = Orbitals(*args)
a.randomize()
- with h5.File('horton.meanfield.test.test_orbitals.test_orbitals_hdf5', driver='core', backing_store=False) as f:
+ with h5.File('horton.meanfield.test.test_orbitals.test_orbitals_hdf5', driver='core',
+ backing_store=False) as f:
a.to_hdf5(f)
b = Orbitals.from_hdf5(f)
assert a == b
@@ -108,7 +111,7 @@ def test_orbitals_copy_new_randomize_clear_assign():
assert a != b
c = b.copy()
assert b == c
- assert not( b is c)
+ assert not (b is c)
d = Orbitals(*args)
assert a == d
b.clear()
@@ -180,7 +183,7 @@ def test_orbitals_error_eigen():
with numpy_seed(1):
orb = Orbitals(5)
a = np.random.normal(0, 1, (5, 5))
- fock = a+a.T
+ fock = a + a.T
evals, evecs = np.linalg.eigh(fock)
orb.coeffs[:] = evecs
orb.energies[:] = evals
@@ -193,7 +196,7 @@ def test_orbitals_error_eigen():
def test_orbitals_from_fock():
with numpy_seed(1):
a = np.random.normal(0, 1, (5, 5))
- fock = a+a.T
+ fock = a + a.T
a = np.random.normal(0, 1, (5, 5))
olp = np.dot(a, a.T)
orb = Orbitals(5)
@@ -209,11 +212,11 @@ def test_orbitals_from_fock_and_dm():
olp = np.zeros((natom, natom))
for i in xrange(natom):
fock[i, i] = 0.6
- fock[i, (i+1) % natom] = -0.2
- fock[(i+1) % natom, i] = -0.2
+ fock[i, (i + 1) % natom] = -0.2
+ fock[(i + 1) % natom, i] = -0.2
olp[i, i] = 1.0
- olp[i, (i+1) % natom] = 0.2
- olp[(i+1) % natom, i] = 0.2
+ olp[i, (i + 1) % natom] = 0.2
+ olp[(i + 1) % natom, i] = 0.2
# Create orbitals that will be used to construct various density matrices
orb = Orbitals(natom)
@@ -241,78 +244,77 @@ def check_case(orb0):
# Case 3: incompatible degeneracies and rotated degenerate orbitals
orb.occupations[:] = [2, 1, 0, 0, 0]
for i in xrange(36):
- orb.rotate_2orbitals(np.pi/18.0, 1, 2)
+ orb.rotate_2orbitals(np.pi / 18.0, 1, 2)
check_case(orb)
# Case 4: incompatible degeneracies, fractional occupations and rotated
# degenerate orbitals
orb.occupations[:] = [1.5, 0.7, 0.3, 0, 0]
for i in xrange(36):
- orb.rotate_2orbitals(np.pi/18.0, 1, 2)
+ orb.rotate_2orbitals(np.pi / 18.0, 1, 2)
check_case(orb)
def test_orbitals_naturals():
- fn_fchk = context.get_fn('test/ch3_hf_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- overlap = mol.obasis.compute_overlap()
- dm = mol.orb_alpha.to_dm()
+ fname = 'ch3_hf_sto3g_fchk'
+ mdata = load_mdata(fname)
+ overlap = load_olp(fname)
+ dm = load_orbs_alpha(fname).to_dm()
orb = Orbitals(dm.shape[0])
orb.derive_naturals(dm, overlap)
assert orb.occupations.min() > -1e-6
- assert orb.occupations.max() < 1+1e-6
+ assert orb.occupations.max() < 1 + 1e-6
orb.check_normalization(overlap)
def test_orbitals_homo_lumo_ch3_hf():
- fn_fchk = context.get_fn('test/ch3_hf_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- assert mol.orb_alpha.get_homo_index() == 4
- assert mol.orb_beta.get_homo_index() == 3
- assert mol.orb_alpha.get_lumo_index() == 5
- assert mol.orb_beta.get_lumo_index() == 4
- assert mol.orb_alpha.get_homo_index(1) == 3
- assert mol.orb_beta.get_homo_index(1) == 2
- assert mol.orb_alpha.get_lumo_index(1) == 6
- assert mol.orb_beta.get_lumo_index(1) == 5
- assert abs(mol.orb_alpha.get_homo_energy() - -3.63936540E-01) < 1e-8
- assert abs(mol.orb_alpha.get_homo_energy(1) - -5.37273275E-01) < 1e-8
- assert abs(mol.orb_alpha.get_lumo_energy() - 6.48361367E-01) < 1e-8
- assert abs(mol.orb_beta.get_homo_energy() - -5.18988806E-01) < 1e-8
- assert abs(mol.orb_beta.get_homo_energy(1) - -5.19454722E-01) < 1e-8
- assert abs(mol.orb_beta.get_lumo_energy() - 3.28562907E-01) < 1e-8
- assert abs(mol.orb_alpha.homo_energy - -3.63936540E-01) < 1e-8
- assert abs(mol.orb_alpha.lumo_energy - 6.48361367E-01) < 1e-8
- assert abs(mol.orb_beta.homo_energy - -5.18988806E-01) < 1e-8
- assert abs(mol.orb_beta.lumo_energy - 3.28562907E-01) < 1e-8
+ fname = 'ch3_hf_sto3g_fchk'
+ mdata = load_mdata(fname)
+ assert load_orbs_alpha(fname).get_homo_index() == 4
+ assert load_orbs_beta(fname).get_homo_index() == 3
+ assert load_orbs_alpha(fname).get_lumo_index() == 5
+ assert load_orbs_beta(fname).get_lumo_index() == 4
+ assert load_orbs_alpha(fname).get_homo_index(1) == 3
+ assert load_orbs_beta(fname).get_homo_index(1) == 2
+ assert load_orbs_alpha(fname).get_lumo_index(1) == 6
+ assert load_orbs_beta(fname).get_lumo_index(1) == 5
+ assert abs(load_orbs_alpha(fname).get_homo_energy() - -3.63936540E-01) < 1e-8
+ assert abs(load_orbs_alpha(fname).get_homo_energy(1) - -5.37273275E-01) < 1e-8
+ assert abs(load_orbs_alpha(fname).get_lumo_energy() - 6.48361367E-01) < 1e-8
+ assert abs(load_orbs_beta(fname).get_homo_energy() - -5.18988806E-01) < 1e-8
+ assert abs(load_orbs_beta(fname).get_homo_energy(1) - -5.19454722E-01) < 1e-8
+ assert abs(load_orbs_beta(fname).get_lumo_energy() - 3.28562907E-01) < 1e-8
+ assert abs(load_orbs_alpha(fname).homo_energy - -3.63936540E-01) < 1e-8
+ assert abs(load_orbs_alpha(fname).lumo_energy - 6.48361367E-01) < 1e-8
+ assert abs(load_orbs_beta(fname).homo_energy - -5.18988806E-01) < 1e-8
+ assert abs(load_orbs_beta(fname).lumo_energy - 3.28562907E-01) < 1e-8
with assert_raises(ValueError):
- mol.orb_alpha.get_homo_index(-1)
+ load_orbs_alpha(fname).get_homo_index(-1)
with assert_raises(ValueError):
- mol.orb_alpha.get_lumo_index(-1)
+ load_orbs_alpha(fname).get_lumo_index(-1)
def test_orbitals_to_dm1():
- fn_fchk = context.get_fn('test/water_hfs_321g.fchk')
- mol = IOData.from_file(fn_fchk)
- dm = mol.orb_alpha.to_dm()
+ fname = 'water_hfs_321g_fchk'
+ mdata = load_mdata(fname)
+ dm = load_orbs_alpha(fname).to_dm()
dm *= 2
- np.testing.assert_almost_equal(dm, mol.get_dm_full())
+ np.testing.assert_almost_equal(dm, load_dm(fname))
np.testing.assert_almost_equal(dm, dm.T)
def test_orbitals_to_dm2():
- fn_fchk = context.get_fn('test/ch3_hf_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- dm = mol.orb_alpha.to_dm() + mol.orb_beta.to_dm()
- olp = mol.obasis.compute_overlap()
- np.testing.assert_almost_equal(dm, mol.get_dm_full())
+ fname = 'ch3_hf_sto3g_fchk'
+ mdata = load_mdata(fname)
+ dm = load_orbs_alpha(fname).to_dm() + load_orbs_beta(fname).to_dm()
+ np.testing.assert_almost_equal(dm, load_dm(fname))
np.testing.assert_almost_equal(dm, dm.T)
def test_orbitals_to_dm3():
- fn_fchk = context.get_fn('test/ch3_hf_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- dm = mol.orb_alpha.to_dm(other=mol.orb_beta)
+ fname = 'ch3_hf_sto3g_fchk'
+ mdata = load_mdata(fname)
+ dm = load_orbs_alpha(fname).to_dm(other=load_orbs_beta(fname))
assert (dm != dm.T).any()
@@ -332,13 +334,12 @@ def test_orbitals_two_index_rotate_2orbitals():
orb1 = orb0.copy()
orb1.rotate_2orbitals()
orb1.check_normalization(olp)
- check = np.identity(4, float)
dots = np.dot(orb0.coeffs.T, orb1.coeffs)
check = np.identity(4)
- check[1,1] = 1.0/np.sqrt(2)
- check[1,2] = 1.0/np.sqrt(2)
- check[2,1] = -1.0/np.sqrt(2)
- check[2,2] = 1.0/np.sqrt(2)
+ check[1, 1] = 1.0 / np.sqrt(2)
+ check[1, 2] = 1.0 / np.sqrt(2)
+ check[2, 1] = -1.0 / np.sqrt(2)
+ check[2, 2] = 1.0 / np.sqrt(2)
np.testing.assert_almost_equal(dots, check)
@@ -349,10 +350,10 @@ def test_orbitals_swap_orbitals():
orb1.swap_orbitals(np.array([[0, 1], [2, 3]]))
dots = np.dot(orb0.coeffs.T, orb1.coeffs)
check = np.zeros((4, 4))
- check[0,1] = 1.0
- check[1,0] = 1.0
- check[2,3] = 1.0
- check[3,2] = 1.0
+ check[0, 1] = 1.0
+ check[1, 0] = 1.0
+ check[2, 3] = 1.0
+ check[3, 2] = 1.0
np.testing.assert_almost_equal(dots, check)
with assert_raises(TypeError):
orb1.swap_orbitals(np.zeros((3, 3), dtype=int))
diff --git a/horton/meanfield/test/test_project.py b/horton/meanfield/test/test_project.py
index f1fa0f94..6b8e5282 100644
--- a/horton/meanfield/test/test_project.py
+++ b/horton/meanfield/test/test_project.py
@@ -20,54 +20,51 @@
# --
-import numpy as np
-
from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.meanfield.test.common import helper_compute
+from .common import helper_compute
def test_project_msg_identical():
- mol = IOData.from_file(context.get_fn('test/water_sto3g_hf_g03.fchk'))
+ mol = IOData.from_file(context.get_fn('test/water_sto3g_hf_g03_fchk'))
orb = Orbitals(mol.obasis.nbasis)
- project_orbitals_mgs(mol.obasis, mol.obasis, mol.orb_alpha, orb)
+ project_orbitals_mgs(mol.obasis, mol.obasis, load_orbs_alpha(fname), orb)
assert (orb.energies == 0.0).all()
- assert (orb.occupations == mol.orb_alpha.occupations).all()
- assert abs(orb.coeffs[:,:-2] - mol.orb_alpha.coeffs[:,:-2]).max() < 1e-9
- assert (orb.coeffs[:,-2:] == 0.0).all()
+ assert (orb.occupations == load_orbs_alpha(fname).occupations).all()
+ assert abs(orb.coeffs[:, :-2] - load_orbs_alpha(fname).coeffs[:, :-2]).max() < 1e-9
+ assert (orb.coeffs[:, -2:] == 0.0).all()
def test_project_ortho_basis_identical():
- mol = IOData.from_file(context.get_fn('test/water_sto3g_hf_g03.fchk'))
+ mol = IOData.from_file(context.get_fn('test/water_sto3g_hf_g03_fchk'))
orb = Orbitals(mol.obasis.nbasis)
- project_orbitals_ortho(mol.obasis, mol.obasis, mol.orb_alpha, orb)
+ project_orbitals_ortho(mol.obasis, mol.obasis, load_orbs_alpha(fname), orb)
assert (orb.energies == 0.0).all()
- assert (orb.occupations == mol.orb_alpha.occupations).all()
- assert abs(orb.coeffs - mol.orb_alpha.coeffs).max() < 1e-9
+ assert (orb.occupations == load_orbs_alpha(fname).occupations).all()
+ assert abs(orb.coeffs - load_orbs_alpha(fname).coeffs).max() < 1e-9
def test_project_ortho_olp_identical():
- mol = IOData.from_file(context.get_fn('test/water_sto3g_hf_g03.fchk'))
- olp = np.identity(mol.obasis.nbasis)
+ mol = IOData.from_file(context.get_fn('test/water_sto3g_hf_g03_fchk'))
orb = Orbitals(mol.obasis.nbasis)
- project_orbitals_ortho(mol.obasis, mol.obasis, mol.orb_alpha, orb)
+ project_orbitals_ortho(mol.obasis, mol.obasis, load_orbs_alpha(fname), orb)
assert (orb.energies == 0.0).all()
- assert (orb.occupations == mol.orb_alpha.occupations).all()
- assert abs(orb.coeffs - mol.orb_alpha.coeffs).max() < 1e-9
+ assert (orb.occupations == load_orbs_alpha(fname).occupations).all()
+ assert abs(orb.coeffs - load_orbs_alpha(fname).coeffs).max() < 1e-9
def test_project_msg_larger():
# Load STO3G system and keep essential results
- mol = IOData.from_file(context.get_fn('test/water_sto3g_hf_g03.fchk'))
+ mol = IOData.from_file(context.get_fn('test/water_sto3g_hf_g03_fchk'))
obasis0 = mol.obasis
- orb0 = mol.orb_alpha
+ orb0 = load_orbs_alpha(fname)
# Upgrade the basis to 3-21G and project
- obasis1 = get_gobasis(mol.coordinates, mol.numbers, '3-21G')
+ obasis1 = get_gobasis(mdata['coordinates'], mdata['numbers'], '3-21G')
orb1 = Orbitals(obasis1.nbasis)
project_orbitals_mgs(obasis0, obasis1, orb0, orb1)
assert (orb1.energies == 0.0).all()
assert orb0.occupations.sum() == orb1.occupations.sum()
- assert (orb1.coeffs[:,5:] == 0.0).all()
+ assert (orb1.coeffs[:, 5:] == 0.0).all()
# Check the normalization of the projected orbitals
olp = obasis1.compute_overlap()
@@ -75,7 +72,7 @@ def test_project_msg_larger():
# Setup HF hamiltonian and compute energy
kin = obasis1.compute_kinetic()
- na = obasis1.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ na = obasis1.compute_nuclear_attraction(mdata['coordinates'], mdata['pseudo_numbers'])
er = obasis1.compute_electron_repulsion()
terms = [
RTwoIndexTerm(kin, 'kin'),
@@ -93,23 +90,23 @@ def test_project_msg_larger():
occ_model = AufbauOccModel(5)
scf_solver(ham, olp, occ_model, orb1)
energy2 = ham.cache['energy']
- assert energy2 < energy1 # the energy should decrease after scf convergence
+ assert energy2 < energy1 # the energy should decrease after scf convergence
# Construct a core initial guess
- guess_core_hamiltonian(olp, kin+na, orb1)
+ guess_core_hamiltonian(olp, kin + na, orb1)
energy3 = helper_compute(ham, orb1)[0]
- assert energy3 > energy1 # the projected guess should be better than the core guess
+ assert energy3 > energy1 # the projected guess should be better than the core guess
def test_project_msg_smaller():
# Load 3-21G system and keep essential results
- mol = IOData.from_file(context.get_fn('test/li_h_3-21G_hf_g09.fchk'))
+ mol = IOData.from_file(context.get_fn('test/li_h_3_21G_hf_g09_fchk'))
obasis0 = mol.obasis
- orb0_alpha = mol.orb_alpha
- orb0_beta = mol.orb_beta
+ orb0_alpha = load_orbs_alpha(fname)
+ orb0_beta = load_orbs_beta(fname)
# Downgrade the basis to sto-3g and project
- obasis1 = get_gobasis(mol.coordinates, mol.numbers, 'sto-3g')
+ obasis1 = get_gobasis(mdata['coordinates'], mdata['numbers'], 'sto-3g')
orb1_alpha = Orbitals(obasis1.nbasis)
orb1_beta = Orbitals(obasis1.nbasis)
project_orbitals_mgs(obasis0, obasis1, orb0_alpha, orb1_alpha)
@@ -118,8 +115,8 @@ def test_project_msg_smaller():
assert (orb1_beta.energies == 0.0).all()
assert orb1_alpha.occupations.sum() == 2
assert orb1_beta.occupations.sum() == 1
- assert (orb1_alpha.coeffs[:,2:] == 0.0).all()
- assert (orb1_beta.coeffs[:,1:] == 0.0).all()
+ assert (orb1_alpha.coeffs[:, 2:] == 0.0).all()
+ assert (orb1_beta.coeffs[:, 1:] == 0.0).all()
# Check the normalization of the projected orbitals
olp = obasis1.compute_overlap()
@@ -128,7 +125,7 @@ def test_project_msg_smaller():
# Setup HF hamiltonian and compute energy
kin = obasis1.compute_kinetic()
- na = obasis1.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
+ na = obasis1.compute_nuclear_attraction(mdata['coordinates'], mdata['pseudo_numbers'])
er = obasis1.compute_electron_repulsion()
terms = [
UTwoIndexTerm(kin, 'kin'),
@@ -145,14 +142,14 @@ def test_project_msg_smaller():
occ_model = AufbauOccModel(2, 1)
scf_solver(ham, olp, occ_model, orb1_alpha, orb1_beta)
energy2 = ham.cache['energy']
- assert energy2 < energy1 # the energy should decrease after scf convergence
+ assert energy2 < energy1 # the energy should decrease after scf convergence
def get_basis_pair_geometry():
- '''Prepare two basis sets that only differ in geometry'''
+ """Prepare two basis sets that only differ in geometry"""
# Create initial system
mol = IOData.from_file(context.get_fn('test/water.xyz'))
- obasis0 = get_gobasis(mol.coordinates, mol.numbers, 'sto-3g')
+ obasis0 = get_gobasis(mdata['coordinates'], mdata['numbers'], 'sto-3g')
orb0 = Orbitals(obasis0.nbasis)
# Occupy all orbitals such that orthogonality is well tested
@@ -161,24 +158,23 @@ def get_basis_pair_geometry():
# core-hamiltonian guess
olp = obasis0.compute_overlap()
kin = obasis0.compute_kinetic()
- na = obasis0.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = obasis0.compute_electron_repulsion()
- guess_core_hamiltonian(olp, kin+na, orb0)
+ na = obasis0.compute_nuclear_attraction(mdata['coordinates'], mdata['pseudo_numbers'])
+ guess_core_hamiltonian(olp, kin + na, orb0)
# Internal consistency check
orb0.check_orthonormality(obasis0.compute_overlap())
# Change geometry
- mol.coordinates[1,2] += 0.5
- mol.coordinates[0,1] -= 1.5
- obasis1 = get_gobasis(mol.coordinates, mol.numbers, 'sto-3g')
+ mdata['coordinates'][1, 2] += 0.5
+ mdata['coordinates'][0, 1] -= 1.5
+ obasis1 = get_gobasis(mdata['coordinates'], mdata['numbers'], 'sto-3g')
orb1 = Orbitals(obasis1.nbasis)
return obasis0, obasis1, orb0, orb1
def test_project_msg_geometry():
- obasis0, obasis1, orb0, orb1= get_basis_pair_geometry()
+ obasis0, obasis1, orb0, orb1 = get_basis_pair_geometry()
# Project from one to other:
project_orbitals_mgs(obasis0, obasis1, orb0, orb1)
@@ -186,7 +182,7 @@ def test_project_msg_geometry():
# Basic checks
assert (orb1.energies == 0.0).all()
assert (orb1.occupations == orb0.occupations).all()
- assert abs(orb1.coeffs[:,:5] - orb0.coeffs[:,:5]).max() > 1e-3 # something should change
+ assert abs(orb1.coeffs[:, :5] - orb0.coeffs[:, :5]).max() > 1e-3 # something should change
# Check orthonormality
orb1.check_orthonormality(obasis1.compute_overlap())
@@ -201,7 +197,7 @@ def test_project_ortho_basis_geometry():
# Basic checks
assert (orb1.energies == 0.0).all()
assert (orb1.occupations == orb0.occupations).all()
- assert abs(orb1.coeffs[:,:5] - orb0.coeffs[:,:5]).max() > 1e-3 # something should change
+ assert abs(orb1.coeffs[:, :5] - orb0.coeffs[:, :5]).max() > 1e-3 # something should change
# Check orthonormality
orb1.check_orthonormality(obasis1.compute_overlap())
@@ -218,7 +214,7 @@ def test_project_ortho_olp_geometry():
# Basic checks
assert (orb1.energies == 0.0).all()
assert (orb1.occupations == orb0.occupations).all()
- assert abs(orb1.coeffs[:,:5] - orb0.coeffs[:,:5]).max() > 1e-3 # something should change
+ assert abs(orb1.coeffs[:, :5] - orb0.coeffs[:, :5]).max() > 1e-3 # something should change
# Check orthonormality
orb1.check_orthonormality(obasis1.compute_overlap())
diff --git a/horton/test/test_quadprog.py b/horton/meanfield/test/test_quadprog.py
similarity index 57%
rename from horton/test/test_quadprog.py
rename to horton/meanfield/test/test_quadprog.py
index 2cb3f62b..362cdb25 100644
--- a/horton/test/test_quadprog.py
+++ b/horton/meanfield/test/test_quadprog.py
@@ -20,16 +20,15 @@
# --
+
import numpy as np
-from nose.tools import assert_raises
from nose.plugins.attrib import attr
+from nose.tools import assert_raises
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.quadprog import FeasibilityError, BoundedError, ConvergenceError, \
+from common import numpy_seed
+from ..quadprog import FeasibilityError, BoundedError, ConvergenceError, \
_counter_to_free, find_1d_root, solve_safe, diagonal_form, \
- solve_constrained, solve_radius
-
-from horton.test.common import numpy_seed
+ solve_constrained, solve_radius, QPSolver
def test_counter_to_free():
@@ -49,16 +48,16 @@ def test_find_1d_root():
# at least 1.0. (See 'this is why'.)
cases = [
(-0.5, 0.1, np.sin, 0.0),
- (-10.0, 10.0, (lambda x: 2*(x-5)), 5.0),
- (-1.0, 2.0, (lambda x: np.exp(x)-1), 0.0),
- (-1.0, 2.0, (lambda x: np.exp(x)-2), np.log(2.0)),
- (0.0, 3.0, np.cos, np.pi/2),
+ (-10.0, 10.0, (lambda x: 2 * (x - 5)), 5.0),
+ (-1.0, 2.0, (lambda x: np.exp(x) - 1), 0.0),
+ (-1.0, 2.0, (lambda x: np.exp(x) - 2), np.log(2.0)),
+ (0.0, 3.0, np.cos, np.pi / 2),
]
eps = 1e-5
for x0, x2, fn, solution in cases:
x1, y1 = find_1d_root(fn, (x0, fn(x0)), (x2, fn(x2)), eps)
assert abs(y1) < eps
- assert abs(x1-solution) < eps # <--- this is why
+ assert abs(x1 - solution) < eps # <--- this is why
def test_solve_safe():
@@ -89,7 +88,7 @@ def get_random_problem(nx=8, nl=None, posdef=False, epscn=1e-4):
The maximum condition number for a and r.
'''
if nl is None:
- nl = np.random.randint(0, nx/2)
+ nl = np.random.randint(0, nx / 2)
while True:
# construct a
a = np.random.normal(0, 1, (nx, nx))
@@ -97,17 +96,17 @@ def get_random_problem(nx=8, nl=None, posdef=False, epscn=1e-4):
a = np.dot(a, a.T)
# resymmetrize in all cases because some blas implementations do not return
# an exactly symmetric a times a^T.
- a = 0.5*(a + a.T)
+ a = 0.5 * (a + a.T)
# avoid too ill-conditioned problems (rarely happens)
absevals = abs(np.linalg.eigvalsh(a))
- if absevals.min() < epscn*absevals.max():
+ if absevals.min() < epscn * absevals.max():
continue
b = np.random.normal(0, 1, nx)
r = np.random.normal(0, 1, (nl, nx))
if nl > 0:
# avoid too ill-conditioned problems (rarely happens)
abssingvals = abs(np.linalg.svd(r, full_matrices=False)[1])
- if abssingvals.min() < epscn*abssingvals.max():
+ if abssingvals.min() < epscn * abssingvals.max():
continue
s = np.random.normal(0, 1, nl)
return a, b, r, s
@@ -118,12 +117,12 @@ def test_diagonal_form_nl0():
# nl = 0
a, b, r, s = get_random_problem(nl=0)
x0, basis, evals, evecs, b_diag = diagonal_form(a, b, r, s)
- x1 = np.dot(evecs, b_diag/evals)
+ x1 = np.dot(evecs, b_diag / evals)
x2 = solve_constrained(a, b, r, s)
- assert abs(x1 - x2).max() < 1e-8*abs(x1).max()
+ assert abs(x1 - x2).max() < 1e-8 * abs(x1).max()
assert x0 is None
assert basis is None
- assert abs(np.dot(evecs*evals, evecs.T) - a).max() < 1e-10
+ assert abs(np.dot(evecs * evals, evecs.T) - a).max() < 1e-10
assert abs(np.dot(evecs, b_diag) - b).max() < 1e-10
@@ -137,10 +136,10 @@ def test_diagonal_form_nl4():
assert evals.shape == (3,)
assert evecs.shape == (3, 3)
assert b_diag.shape == (3,)
- x3 = x0 + np.dot(basis.T, np.dot(evecs, b_diag/evals))
+ x3 = x0 + np.dot(basis.T, np.dot(evecs, b_diag / evals))
x4 = solve_constrained(a, b, r, s)
try:
- assert abs(x3 - x4).max() < 1e-8*abs(x3).max()
+ assert abs(x3 - x4).max() < 1e-8 * abs(x3).max()
except:
print i, 5
print np.linalg.eigvalsh(a)
@@ -170,7 +169,7 @@ def test_diagonal_form_nl8():
assert b_diag is None
x5 = solve_constrained(a, b, r, s)
try:
- assert abs(x0 - x5).max() < 1e-8*abs(x0).max()
+ assert abs(x0 - x5).max() < 1e-8 * abs(x0).max()
except:
print i, 8
print np.linalg.eigvalsh(a)
@@ -185,47 +184,47 @@ def test_solve_radius_posdef_nl0():
for i in xrange(100):
a, b, r, s = get_random_problem(nl=0, posdef=True)
radius = np.random.uniform(1e-5, 1e2)
- center = np.random.normal(0, 0.3*radius, len(b))
+ center = np.random.normal(0, 0.3 * radius, len(b))
x1 = solve_radius(a, b, center, radius, r, s)
- assert np.linalg.norm(x1 - center) < radius*(1 + 1e-3)
+ assert np.linalg.norm(x1 - center) < radius * (1 + 1e-3)
x2 = solve_constrained(a, b, r, s)
- cost1 = np.dot(x1, 0.5*np.dot(a, x1) - b)
- cost2 = np.dot(x2, 0.5*np.dot(a, x2) - b)
+ cost1 = np.dot(x1, 0.5 * np.dot(a, x1) - b)
+ cost2 = np.dot(x2, 0.5 * np.dot(a, x2) - b)
assert cost2 - cost1 < 1e-10
- if np.linalg.norm(x2 - center) < radius*(1 - 1e-3):
- assert abs(x1 - x2).max() < 1e-6*abs(x1).max()
+ if np.linalg.norm(x2 - center) < radius * (1 - 1e-3):
+ assert abs(x1 - x2).max() < 1e-6 * abs(x1).max()
def test_solve_radius_posdef_nl4():
for i in xrange(100):
a, b, r, s = get_random_problem(nl=4, posdef=True)
radius = np.random.uniform(1e-5, 1e2)
- center = np.random.normal(0, 0.5*radius, len(b))
+ center = np.random.normal(0, 0.5 * radius, len(b))
try:
x1 = solve_radius(a, b, center, radius, r, s)
except FeasibilityError:
continue
- assert np.linalg.norm(x1 - center) < radius*(1 + 1e-3)
+ assert np.linalg.norm(x1 - center) < radius * (1 + 1e-3)
x2 = solve_constrained(a, b, r, s)
- cost1 = np.dot(x1, 0.5*np.dot(a, x1) - b)
- cost2 = np.dot(x2, 0.5*np.dot(a, x2) - b)
+ cost1 = np.dot(x1, 0.5 * np.dot(a, x1) - b)
+ cost2 = np.dot(x2, 0.5 * np.dot(a, x2) - b)
assert cost2 - cost1 < 1e-10
- if np.linalg.norm(x2 - center) < radius*(1 - 1e-3):
- assert abs(x1 - x2).max() < 1e-6*abs(x1).max()
+ if np.linalg.norm(x2 - center) < radius * (1 - 1e-3):
+ assert abs(x1 - x2).max() < 1e-6 * abs(x1).max()
def test_solve_radius_posdef_nl8():
for i in xrange(100):
a, b, r, s = get_random_problem(nl=8, posdef=True)
radius = np.random.uniform(1e-5, 1e2)
- center = np.random.normal(0, 0.5*radius, len(b))
+ center = np.random.normal(0, 0.5 * radius, len(b))
try:
x1 = solve_radius(a, b, center, radius, r, s)
except FeasibilityError:
continue
- assert np.linalg.norm(x1 - center) < radius*(1 + 1e-3)
+ assert np.linalg.norm(x1 - center) < radius * (1 + 1e-3)
x2 = solve_safe(r, s)
- assert abs(x1 - x2).max() < 1e-6*abs(x1).max()
+ assert abs(x1 - x2).max() < 1e-6 * abs(x1).max()
def test_qps_infeasible():
@@ -234,8 +233,8 @@ def test_qps_infeasible():
a = np.diag(np.random.uniform(2.0, 5.0, nx))
b = np.random.normal(0.0, 1.0, nx)
r = np.zeros((nl, nx))
- r[:,:2] = np.random.normal(0.0, 1.0, (nl, 2))
- s = np.random.normal(0.0, 1.0, nl)
+ r[:, :2] = np.random.normal(0.0, 1.0, (nl, 2))
+ s = np.random.normal(0.0, 1.0, nl)
qps = QPSolver(a, b, r, s)
free = np.array([False, False, True, True])
with assert_raises(FeasibilityError):
@@ -248,8 +247,8 @@ def test_qps_infeasible_radius():
a = np.diag(np.random.uniform(2.0, 5.0, nx))
b = np.random.normal(0.0, 1.0, nx)
r = np.zeros((nl, nx))
- r[:,:2] = np.random.normal(0.0, 1.0, (nl, 2))
- s = np.random.normal(0.0, 1.0, nl)
+ r[:, :2] = np.random.normal(0.0, 1.0, (nl, 2))
+ s = np.random.normal(0.0, 1.0, nl)
center = np.random.normal(0, 1, nx)
qps = QPSolver(a, b, r, s)
free = np.array([False, False, True, True])
@@ -284,7 +283,7 @@ def get_random_free(qps):
def test_get_free_problem():
for i0 in xrange(100):
qps = QPSolver(*get_random_problem())
- for i1 in xrange(max(1, qps.nl), qps.nx+1):
+ for i1 in xrange(max(1, qps.nl), qps.nx + 1):
free = np.zeros(qps.nx, dtype=bool)
free[:i1] = True
a_free, b_free, r_free, s_free = qps.get_free_problem(free)
@@ -319,7 +318,7 @@ def test_solve_qps():
if i1 == 0:
free = np.ones(qps.nx, dtype=bool)
else:
- with numpy_seed(i0*100 + i1):
+ with numpy_seed(i0 * 100 + i1):
free = get_random_free(qps)
x = qps.solve(free)
qps.check_feasible(x, free)
@@ -339,7 +338,7 @@ def test_solve_qps_radius_posdef():
qps.check_feasible(x, free)
cost_x = qps.compute_cost(x)
assert cost_x < cost_center
- assert np.linalg.norm(x - center) <= radius*1.001
+ assert np.linalg.norm(x - center) <= radius * 1.001
def test_solve_qps_radius():
@@ -356,12 +355,12 @@ def test_solve_qps_radius():
qps.check_feasible(x, free)
cost_x = qps.compute_cost(x)
assert cost_x < cost_center
- assert np.linalg.norm(x - center) <= radius*1.001
+ assert np.linalg.norm(x - center) <= radius * 1.001
def test_brute_simple():
a = np.identity(5)
- b = -2*np.ones(5)
+ b = -2 * np.ones(5)
r = np.ones((1, 5))
s = np.array([5])
qps = QPSolver(a, b, r, s)
@@ -462,17 +461,26 @@ def test_brute_local():
def test_brute_case1():
qps = QPSolver(
np.array([
- [5.8818949999422374, -0.77419795370541555, 0.39341617187739442, 2.0623472342526616, 0.70305696723217903, 0.43927082926019057],
- [-0.77419795370541555, 1.2417514864801085, -0.87970058018596486, -2.2750064483132406, -0.53127538666014551, 0.54723718046867531],
- [0.39341617187739442, -0.87970058018596486, 8.1424259636396421, 2.0743354833933023, -0.8451551155934458, -0.87608149252282963],
- [2.0623472342526616, -2.2750064483132406, 2.0743354833933023, 6.0910659702544807, -1.0972631644140005, -0.23028504167149105],
- [0.70305696723217903, -0.53127538666014551, -0.8451551155934458, -1.0972631644140005, 5.565314789423871, -3.7575632324834198],
- [0.43927082926019057, 0.54723718046867531, -0.87608149252282963, -0.23028504167149105, -3.7575632324834198, 5.2499593294744216],
+ [5.8818949999422374, -0.77419795370541555, 0.39341617187739442, 2.0623472342526616,
+ 0.70305696723217903, 0.43927082926019057],
+ [-0.77419795370541555, 1.2417514864801085, -0.87970058018596486, -2.2750064483132406,
+ -0.53127538666014551, 0.54723718046867531],
+ [0.39341617187739442, -0.87970058018596486, 8.1424259636396421, 2.0743354833933023,
+ -0.8451551155934458, -0.87608149252282963],
+ [2.0623472342526616, -2.2750064483132406, 2.0743354833933023, 6.0910659702544807,
+ -1.0972631644140005, -0.23028504167149105],
+ [0.70305696723217903, -0.53127538666014551, -0.8451551155934458, -1.0972631644140005,
+ 5.565314789423871, -3.7575632324834198],
+ [0.43927082926019057, 0.54723718046867531, -0.87608149252282963, -0.23028504167149105,
+ -3.7575632324834198, 5.2499593294744216],
]),
- np.array([0.79794082940662259, 1.7133727997077115, 0.52660856271888534, 0.87508447140496493, 1.4399900959090817, 1.890635603184891]),
+ np.array([0.79794082940662259, 1.7133727997077115, 0.52660856271888534, 0.87508447140496493,
+ 1.4399900959090817, 1.890635603184891]),
np.array([
- [-0.3066400060217162, 0.4347344395513979, -2.3801164580913214, -0.090650765867039226, 0.086345721171055323, 1.1449625586344025],
- [-0.279502458226559, 0.59702302554570619, 0.21989715465365572, -0.11013881571319613, 0.16478641607527697, 0.93466512224244058],
+ [-0.3066400060217162, 0.4347344395513979, -2.3801164580913214, -0.090650765867039226,
+ 0.086345721171055323, 1.1449625586344025],
+ [-0.279502458226559, 0.59702302554570619, 0.21989715465365572, -0.11013881571319613,
+ 0.16478641607527697, 0.93466512224244058],
]),
np.array([-0.99746332627189982, 1.1089528830442121]),
)
@@ -483,17 +491,27 @@ def test_brute_case1():
def test_brute_case2():
qps = QPSolver(
np.array([
- [7.7777678491839488, -4.1394215100441691, -0.93496478768154112, -2.5636063412433505, 0.4152351107141245, 2.1325362349317176],
- [-4.1394215100441691, 5.3966791477501044, -0.078655286246388428, 0.84760054283629427, 0.85251884466077499, -4.1538822573446677],
- [-0.93496478768154112, -0.078655286246388428, 3.2776150136403599, 0.66562278015287957, -2.01031234900845, -1.3170956617298368],
- [-2.5636063412433505, 0.84760054283629427, 0.66562278015287957, 8.0220111474488096, -2.8503515897516283, -1.2294009495541263],
- [0.4152351107141245, 0.85251884466077499, -2.01031234900845, -2.8503515897516283, 2.3078909975036965, 0.51158004287230041],
- [2.1325362349317176, -4.1538822573446677, -1.3170956617298368, -1.2294009495541263, 0.51158004287230041, 4.753207067427045],
+ [7.7777678491839488, -4.1394215100441691, -0.93496478768154112, -2.5636063412433505,
+ 0.4152351107141245, 2.1325362349317176],
+ [-4.1394215100441691, 5.3966791477501044, -0.078655286246388428, 0.84760054283629427,
+ 0.85251884466077499, -4.1538822573446677],
+ [-0.93496478768154112, -0.078655286246388428, 3.2776150136403599, 0.66562278015287957,
+ -2.01031234900845, -1.3170956617298368],
+ [-2.5636063412433505, 0.84760054283629427, 0.66562278015287957, 8.0220111474488096,
+ -2.8503515897516283, -1.2294009495541263],
+ [0.4152351107141245, 0.85251884466077499, -2.01031234900845, -2.8503515897516283,
+ 2.3078909975036965, 0.51158004287230041],
+ [2.1325362349317176, -4.1538822573446677, -1.3170956617298368, -1.2294009495541263,
+ 0.51158004287230041, 4.753207067427045],
]),
- np.array([0.084122796400789776, 0.13248005552515144, -0.011337219032290116, -0.32808318842735468, -0.1942335218652631, 0.42946358838556126]),
+ np.array(
+ [0.084122796400789776, 0.13248005552515144, -0.011337219032290116, -0.32808318842735468,
+ -0.1942335218652631, 0.42946358838556126]),
np.array([
- [0.058947500030390558, 2.8343622100824701, 1.3178663807154574, 0.63164184657317068, 0.83782836334183131, -0.051926442369153891],
- [-0.31073645606613759, -0.50172261649450467, 0.1826071399900123, 1.5181979800166607, -0.67838760926895592, -0.40545902742915829],
+ [0.058947500030390558, 2.8343622100824701, 1.3178663807154574, 0.63164184657317068,
+ 0.83782836334183131, -0.051926442369153891],
+ [-0.31073645606613759, -0.50172261649450467, 0.1826071399900123, 1.5181979800166607,
+ -0.67838760926895592, -0.40545902742915829],
]),
np.array([-0.57685125471751075, -1.2399862660238066]),
)
@@ -504,17 +522,27 @@ def test_brute_case2():
def test_brute_case3():
qps = QPSolver(
np.array([
- [10.949643502677578, -6.4848706832640168, -2.2855976904588635, 6.2603152305513392, -1.0445724421867459, 2.9962572283103555],
- [-6.4848706832640168, 8.3170212543577193, 0.27469715271157841, -4.6215940087176399, 2.712716602561124, -4.8477069972400084],
- [-2.2855976904588635, 0.27469715271157841, 14.769272405279011, -0.051505059995286595, -0.49106152710130235, -2.1282377916520616],
- [6.2603152305513392, -4.6215940087176399, -0.051505059995286595, 6.772933209165914, 0.31613657279823015, 4.2766554080787502],
- [-1.0445724421867459, 2.712716602561124, -0.49106152710130235, 0.31613657279823015, 3.741204058931006, -1.7853429804383523],
- [2.9962572283103555, -4.8477069972400084, -2.1282377916520616, 4.2766554080787502, -1.7853429804383523, 6.9502814568206386],
+ [10.949643502677578, -6.4848706832640168, -2.2855976904588635, 6.2603152305513392,
+ -1.0445724421867459, 2.9962572283103555],
+ [-6.4848706832640168, 8.3170212543577193, 0.27469715271157841, -4.6215940087176399,
+ 2.712716602561124, -4.8477069972400084],
+ [-2.2855976904588635, 0.27469715271157841, 14.769272405279011, -0.051505059995286595,
+ -0.49106152710130235, -2.1282377916520616],
+ [6.2603152305513392, -4.6215940087176399, -0.051505059995286595, 6.772933209165914,
+ 0.31613657279823015, 4.2766554080787502],
+ [-1.0445724421867459, 2.712716602561124, -0.49106152710130235, 0.31613657279823015,
+ 3.741204058931006, -1.7853429804383523],
+ [2.9962572283103555, -4.8477069972400084, -2.1282377916520616, 4.2766554080787502,
+ -1.7853429804383523, 6.9502814568206386],
]),
- np.array([0.81811916699197473, -0.2839108577501086, -0.52580285068573052, 1.1168945191958584, 0.51473677332239764, 0.40132813088081393]),
+ np.array(
+ [0.81811916699197473, -0.2839108577501086, -0.52580285068573052, 1.1168945191958584,
+ 0.51473677332239764, 0.40132813088081393]),
np.array([
- [0.60693853800344977, -1.602707177915851, -0.045461208556361564, -1.3574337407982444, -1.0194532203245703, -0.11007054336981964],
- [0.41595858414246062, 0.20880157188047851, -1.1189280276138425, -1.3021514511281107, 0.10768134383771397, 1.7556828215121263],
+ [0.60693853800344977, -1.602707177915851, -0.045461208556361564, -1.3574337407982444,
+ -1.0194532203245703, -0.11007054336981964],
+ [0.41595858414246062, 0.20880157188047851, -1.1189280276138425, -1.3021514511281107,
+ 0.10768134383771397, 1.7556828215121263],
]),
np.array([0.51812694007155591, -0.82287154751311653]),
)
@@ -525,16 +553,25 @@ def test_brute_case3():
def test_brute_case4():
qps = QPSolver(
np.array([
- [0.7990546151426382, 0.60159970689434261, 0.25038104422335095, 0.9107186394321235, -0.057596715716904341, 0.36415173883112567],
- [0.60159970689434261, 0.071406318978636474, -0.18682517604341942, 0.1408876305178936, -1.4706046610777006, 0.95698263756937496],
- [0.25038104422335095, -0.18682517604341942, -0.76023253647318112, -0.65971813975561078, 0.091128703324063975, 0.72341372601515963],
- [0.9107186394321235, 0.1408876305178936, -0.65971813975561078, -1.3564464302489747, 0.14486671746488211, 0.37478117023135221],
- [-0.057596715716904341, -1.4706046610777006, 0.091128703324063975, 0.14486671746488211, -0.44189735537298425, 0.77868082771555558],
- [0.36415173883112567, 0.95698263756937496, 0.72341372601515963, 0.37478117023135221, 0.77868082771555558, 0.15083792086070447],
+ [0.7990546151426382, 0.60159970689434261, 0.25038104422335095, 0.9107186394321235,
+ -0.057596715716904341, 0.36415173883112567],
+ [0.60159970689434261, 0.071406318978636474, -0.18682517604341942, 0.1408876305178936,
+ -1.4706046610777006, 0.95698263756937496],
+ [0.25038104422335095, -0.18682517604341942, -0.76023253647318112, -0.65971813975561078,
+ 0.091128703324063975, 0.72341372601515963],
+ [0.9107186394321235, 0.1408876305178936, -0.65971813975561078, -1.3564464302489747,
+ 0.14486671746488211, 0.37478117023135221],
+ [-0.057596715716904341, -1.4706046610777006, 0.091128703324063975, 0.14486671746488211,
+ -0.44189735537298425, 0.77868082771555558],
+ [0.36415173883112567, 0.95698263756937496, 0.72341372601515963, 0.37478117023135221,
+ 0.77868082771555558, 0.15083792086070447],
]),
- np.array([-2.1492020469280524, 1.5260662967668095, 0.91429181277522631, -0.26822566090243904, -0.34729383842661415, 0.67908749141704505]),
+ np.array(
+ [-2.1492020469280524, 1.5260662967668095, 0.91429181277522631, -0.26822566090243904,
+ -0.34729383842661415, 0.67908749141704505]),
np.array([
- [-0.41015693790806101, -0.3029115511740868, -0.68741014841460135, 0.16295599958248516, -0.8286427429967762, -0.22428931788921946],
+ [-0.41015693790806101, -0.3029115511740868, -0.68741014841460135, 0.16295599958248516,
+ -0.8286427429967762, -0.22428931788921946],
]),
np.array([-0.75113559150400466]),
)
@@ -563,15 +600,22 @@ def test_brute_case6():
# all fixed is not a good idea ...
qps = QPSolver(
np.array([
- [-1.6170622392405418, -1.1110660450798633, 0.15534256626761522, -0.035521902704618108, -0.7461985258486824, 0.10251918427316184],
- [-1.1110660450798633, -0.34288398900411249, -0.87112101192198466, -1.0723409286884387, 0.77890683895688473, 0.64749152585353753],
- [0.15534256626761522, -0.87112101192198466, -0.47456930397068336, 1.0664188304998987, 0.52494441816706661, -1.1798151543302824],
- [-0.035521902704618108, -1.0723409286884387, 1.0664188304998987, -0.062964411407941484, -0.2032160752170718, 1.7280732016323954],
- [-0.7461985258486824, 0.77890683895688473, 0.52494441816706661, -0.2032160752170718, -1.6672524270549614, -0.0079015689549524204],
- [0.10251918427316184, 0.64749152585353753, -1.1798151543302824, 1.7280732016323954, -0.0079015689549524204, -2.4093790812393414],
+ [-1.6170622392405418, -1.1110660450798633, 0.15534256626761522, -0.035521902704618108,
+ -0.7461985258486824, 0.10251918427316184],
+ [-1.1110660450798633, -0.34288398900411249, -0.87112101192198466, -1.0723409286884387,
+ 0.77890683895688473, 0.64749152585353753],
+ [0.15534256626761522, -0.87112101192198466, -0.47456930397068336, 1.0664188304998987,
+ 0.52494441816706661, -1.1798151543302824],
+ [-0.035521902704618108, -1.0723409286884387, 1.0664188304998987, -0.062964411407941484,
+ -0.2032160752170718, 1.7280732016323954],
+ [-0.7461985258486824, 0.77890683895688473, 0.52494441816706661, -0.2032160752170718,
+ -1.6672524270549614, -0.0079015689549524204],
+ [0.10251918427316184, 0.64749152585353753, -1.1798151543302824, 1.7280732016323954,
+ -0.0079015689549524204, -2.4093790812393414],
]),
- np.array([-1.628027986608761, -1.680081567157873, 0.12815213529315533, -0.38201939028605525, 0.77151603852902884, 0.50875081807696942]),
- np.zeros((0,6)),
+ np.array([-1.628027986608761, -1.680081567157873, 0.12815213529315533, -0.38201939028605525,
+ 0.77151603852902884, 0.50875081807696942]),
+ np.zeros((0, 6)),
np.array([]),
)
with assert_raises(BoundedError):
@@ -600,17 +644,27 @@ def test_brute_case8():
# find_brute returns a solution that is not exactly on the equality constraints.
qps = QPSolver(
np.array([
- [-0.70841731236733996, -1.2971293403402491, 0.90762745129580269, 0.086526845993940282, 0.83018921812606727, 0.31381838847861343],
- [-1.2971293403402491, -1.9408646843381616, -0.89540919308959155, -0.024479335288883169, 1.0775985944280677, -0.52650657733203432],
- [0.90762745129580269, -0.89540919308959155, 0.40612490363321968, 0.014668804820934134, 0.5370600831832697, -0.39964394635396933],
- [0.086526845993940282, -0.024479335288883169, 0.014668804820934134, 0.015929091021452374, -0.79212879441047745, 0.016890690484653692],
- [0.83018921812606727, 1.0775985944280677, 0.5370600831832697, -0.79212879441047745, -0.88786447750589015, -0.034978317332826636],
- [0.31381838847861343, -0.52650657733203432, -0.39964394635396933, 0.016890690484653692, -0.034978317332826636, -0.18343755938048792],
+ [-0.70841731236733996, -1.2971293403402491, 0.90762745129580269, 0.086526845993940282,
+ 0.83018921812606727, 0.31381838847861343],
+ [-1.2971293403402491, -1.9408646843381616, -0.89540919308959155, -0.024479335288883169,
+ 1.0775985944280677, -0.52650657733203432],
+ [0.90762745129580269, -0.89540919308959155, 0.40612490363321968, 0.014668804820934134,
+ 0.5370600831832697, -0.39964394635396933],
+ [0.086526845993940282, -0.024479335288883169, 0.014668804820934134,
+ 0.015929091021452374, -0.79212879441047745, 0.016890690484653692],
+ [0.83018921812606727, 1.0775985944280677, 0.5370600831832697, -0.79212879441047745,
+ -0.88786447750589015, -0.034978317332826636],
+ [0.31381838847861343, -0.52650657733203432, -0.39964394635396933, 0.016890690484653692,
+ -0.034978317332826636, -0.18343755938048792],
]),
- np.array([-0.97667398736166677, -0.26674955274778495, 1.3971837428664151, -0.7548208542900311, 0.20143172017397515, 0.70870382939012788]),
+ np.array(
+ [-0.97667398736166677, -0.26674955274778495, 1.3971837428664151, -0.7548208542900311,
+ 0.20143172017397515, 0.70870382939012788]),
np.array([
- [0.23201895073676565, 1.2815806707407724, -0.48070981450845679, -0.086198330259237302, -0.24520586286913254, -0.17363911537396109],
- [-0.68428995101920931, -1.0316773608304244, -0.17545371137719318, -0.2729594433963799, 0.19735403185101402, -0.97249697065508856],
+ [0.23201895073676565, 1.2815806707407724, -0.48070981450845679, -0.086198330259237302,
+ -0.24520586286913254, -0.17363911537396109],
+ [-0.68428995101920931, -1.0316773608304244, -0.17545371137719318, -0.2729594433963799,
+ 0.19735403185101402, -0.97249697065508856],
]),
np.array([0.41079612937870091, -1.6343480803544916]),
eps=1e-6,
@@ -623,17 +677,27 @@ def test_brute_case9():
# mismatch equality constraints (posdef)
qps = QPSolver(
np.array([
- [4.3206954954195442, 1.0995193491529669, -1.8495021618983287, 0.72617849172585236, -1.7933578310574625, -3.3858794413657338],
- [1.0995193491529669, 7.4747802231556353, -7.4921796351274246, -1.5044955980863084, -2.9385575178317112, -2.5930622344533512],
- [-1.8495021618983287, -7.4921796351274246, 11.271691407429426, -0.13747973098167873, 3.0801710797885811, 2.9305864693055015],
- [0.72617849172585236, -1.5044955980863084, -0.13747973098167873, 7.1223220952346562, 6.3309090398866426, 0.89431284768332786],
- [-1.7933578310574625, -2.9385575178317112, 3.0801710797885811, 6.3309090398866426, 10.48601433755171, 2.3729785411834676],
- [-3.3858794413657338, -2.5930622344533512, 2.9305864693055015, 0.89431284768332786, 2.3729785411834676, 3.6504940434519155],
+ [4.3206954954195442, 1.0995193491529669, -1.8495021618983287, 0.72617849172585236,
+ -1.7933578310574625, -3.3858794413657338],
+ [1.0995193491529669, 7.4747802231556353, -7.4921796351274246, -1.5044955980863084,
+ -2.9385575178317112, -2.5930622344533512],
+ [-1.8495021618983287, -7.4921796351274246, 11.271691407429426, -0.13747973098167873,
+ 3.0801710797885811, 2.9305864693055015],
+ [0.72617849172585236, -1.5044955980863084, -0.13747973098167873, 7.1223220952346562,
+ 6.3309090398866426, 0.89431284768332786],
+ [-1.7933578310574625, -2.9385575178317112, 3.0801710797885811, 6.3309090398866426,
+ 10.48601433755171, 2.3729785411834676],
+ [-3.3858794413657338, -2.5930622344533512, 2.9305864693055015, 0.89431284768332786,
+ 2.3729785411834676, 3.6504940434519155],
]),
- np.array([-0.20354699990469935, 1.8853961326540016, -0.7319189254058831, 0.065576550436379791, -0.94479064660325729, 1.0746348777770884]),
+ np.array(
+ [-0.20354699990469935, 1.8853961326540016, -0.7319189254058831, 0.065576550436379791,
+ -0.94479064660325729, 1.0746348777770884]),
np.array([
- [1.2485461200060213, 1.2175464308211492, 1.0092841327024706, 2.7899706809845943, -0.92878294027396968, -0.35937248238222808],
- [-0.31042069923722482, 1.3203168967639625, 0.71261924983670422, 1.199582577635893, 0.2304738785590868, 0.15518540117148097],
+ [1.2485461200060213, 1.2175464308211492, 1.0092841327024706, 2.7899706809845943,
+ -0.92878294027396968, -0.35937248238222808],
+ [-0.31042069923722482, 1.3203168967639625, 0.71261924983670422, 1.199582577635893,
+ 0.2304738785590868, 0.15518540117148097],
]),
np.array([0.40260474485255499, -0.48930086847135434]),
eps=1e-6,
@@ -645,17 +709,27 @@ def test_brute_case9():
def test_local_case1():
qps = QPSolver(
np.array([
- [12.98721885864512, -4.6588586635198244, -0.91546482655448469, -5.9789922145586925, 2.7503595102379421, 1.5317082550812957],
- [-4.6588586635198244, 7.0326437030982909, -1.2068162572718182, 4.1152385083361009, -0.486080361964501, -0.92288125639729679],
- [-0.91546482655448469, -1.2068162572718182, 7.0824548119378132, -3.4096249540917754, -0.9217331851519901, -1.5005654709949769],
- [-5.9789922145586925, 4.1152385083361009, -3.4096249540917754, 11.89628880624144, -3.6316543061999216, 0.42944160122592212],
- [2.7503595102379421, -0.486080361964501, -0.9217331851519901, -3.6316543061999216, 3.3531338144290426, 0.49086672463256498],
- [1.5317082550812957, -0.92288125639729679, -1.5005654709949769, 0.42944160122592212, 0.49086672463256498, 0.86607069729952701],
+ [12.98721885864512, -4.6588586635198244, -0.91546482655448469, -5.9789922145586925,
+ 2.7503595102379421, 1.5317082550812957],
+ [-4.6588586635198244, 7.0326437030982909, -1.2068162572718182, 4.1152385083361009,
+ -0.486080361964501, -0.92288125639729679],
+ [-0.91546482655448469, -1.2068162572718182, 7.0824548119378132, -3.4096249540917754,
+ -0.9217331851519901, -1.5005654709949769],
+ [-5.9789922145586925, 4.1152385083361009, -3.4096249540917754, 11.89628880624144,
+ -3.6316543061999216, 0.42944160122592212],
+ [2.7503595102379421, -0.486080361964501, -0.9217331851519901, -3.6316543061999216,
+ 3.3531338144290426, 0.49086672463256498],
+ [1.5317082550812957, -0.92288125639729679, -1.5005654709949769, 0.42944160122592212,
+ 0.49086672463256498, 0.86607069729952701],
]),
- np.array([-1.7640856679361303, -0.57087943458650181, -0.13374131333031397, 0.34522781648137341, 0.068577833332047478, -0.11172137814018418]),
+ np.array(
+ [-1.7640856679361303, -0.57087943458650181, -0.13374131333031397, 0.34522781648137341,
+ 0.068577833332047478, -0.11172137814018418]),
np.array([
- [0.43101465265031758, 0.086243316821451532, 0.056467524174045318, -0.83513643817703564, -0.95396057797839307, -1.1277118607292189],
- [-0.063668029637385076, 1.2248051747709392, 0.17965412995933414, -0.55365467576520333, -0.42904406085688018, -1.9683318875692319],
+ [0.43101465265031758, 0.086243316821451532, 0.056467524174045318, -0.83513643817703564,
+ -0.95396057797839307, -1.1277118607292189],
+ [-0.063668029637385076, 1.2248051747709392, 0.17965412995933414, -0.55365467576520333,
+ -0.42904406085688018, -1.9683318875692319],
]),
np.array([0.65794380142477105, 0.038165380592388352]),
)
@@ -668,18 +742,28 @@ def test_local_case2():
# problem with new_cost < cost
qps = QPSolver(
np.array([
- [7.4629736594322331, -0.78748447995959669, 0.39350017508027152, -0.68307208660912533, 4.9135859685012173, 1.3191440233541152],
- [-0.78748447995959669, 2.8455612103600143, -2.3777176627456003, -2.0647887688885893, -0.8494420668115783, 1.0362029379461384],
- [0.39350017508027152, -2.3777176627456003, 7.1282320417634413, 1.1073706764518034, 1.6754999335349345, 0.24762190846137289],
- [-0.68307208660912533, -2.0647887688885893, 1.1073706764518034, 2.4252041096631261, -0.69785432183912288, -0.55618812054465072],
- [4.9135859685012173, -0.8494420668115783, 1.6754999335349345, -0.69785432183912288, 4.4961443889941322, 0.56183256135502446],
- [1.3191440233541152, 1.0362029379461384, 0.24762190846137289, -0.55618812054465072, 0.56183256135502446, 1.9755149613389364],
+ [7.4629736594322331, -0.78748447995959669, 0.39350017508027152, -0.68307208660912533,
+ 4.9135859685012173, 1.3191440233541152],
+ [-0.78748447995959669, 2.8455612103600143, -2.3777176627456003, -2.0647887688885893,
+ -0.8494420668115783, 1.0362029379461384],
+ [0.39350017508027152, -2.3777176627456003, 7.1282320417634413, 1.1073706764518034,
+ 1.6754999335349345, 0.24762190846137289],
+ [-0.68307208660912533, -2.0647887688885893, 1.1073706764518034, 2.4252041096631261,
+ -0.69785432183912288, -0.55618812054465072],
+ [4.9135859685012173, -0.8494420668115783, 1.6754999335349345, -0.69785432183912288,
+ 4.4961443889941322, 0.56183256135502446],
+ [1.3191440233541152, 1.0362029379461384, 0.24762190846137289, -0.55618812054465072,
+ 0.56183256135502446, 1.9755149613389364],
]),
- np.array([-0.036326161624374083, 0.93442606896402636, 2.3465206569805046, 0.60013364713670336, -0.065360649313220678, 0.74605936179230847]),
- np.zeros((0,6)),
+ np.array(
+ [-0.036326161624374083, 0.93442606896402636, 2.3465206569805046, 0.60013364713670336,
+ -0.065360649313220678, 0.74605936179230847]),
+ np.zeros((0, 6)),
np.array([]),
)
- guess = np.array([0.060781020807135232, 0.094832047408032777, 1.1736098312337082, 0.27679006326937744, 0.08915412896212016, 2.7251320294146675])
+ guess = np.array(
+ [0.060781020807135232, 0.094832047408032777, 1.1736098312337082, 0.27679006326937744,
+ 0.08915412896212016, 2.7251320294146675])
cost, x = qps.find_local(guess, 1.0)
qps.check_solution(x)
@@ -688,21 +772,33 @@ def test_local_case3():
# problem with tmin > 0
qps = QPSolver(
np.array([
- [3.0416282731277371, -1.4216164332936789, 0.46036692207941887, 0.8646633606722256, 0.37224511445850084, 0.49853885743325299],
- [-1.4216164332936789, 10.48010471548946, -5.0724948663530656, 0.51685701382721216, -5.7757019664518729, -2.654913315245504],
- [0.46036692207941887, -5.0724948663530656, 4.6454659562180787, -2.8459087108315506, 2.2400328467875963, 3.5852631057103288],
- [0.8646633606722256, 0.51685701382721216, -2.8459087108315506, 6.9625681947633717, 0.0065222059726193216, -4.072767567818075],
- [0.37224511445850084, -5.7757019664518729, 2.2400328467875963, 0.0065222059726193216, 7.0132899829952953, -0.99707593216694956],
- [0.49853885743325299, -2.654913315245504, 3.5852631057103288, -4.072767567818075, -0.99707593216694956, 4.6945205762054307],
+ [3.0416282731277371, -1.4216164332936789, 0.46036692207941887, 0.8646633606722256,
+ 0.37224511445850084, 0.49853885743325299],
+ [-1.4216164332936789, 10.48010471548946, -5.0724948663530656, 0.51685701382721216,
+ -5.7757019664518729, -2.654913315245504],
+ [0.46036692207941887, -5.0724948663530656, 4.6454659562180787, -2.8459087108315506,
+ 2.2400328467875963, 3.5852631057103288],
+ [0.8646633606722256, 0.51685701382721216, -2.8459087108315506, 6.9625681947633717,
+ 0.0065222059726193216, -4.072767567818075],
+ [0.37224511445850084, -5.7757019664518729, 2.2400328467875963, 0.0065222059726193216,
+ 7.0132899829952953, -0.99707593216694956],
+ [0.49853885743325299, -2.654913315245504, 3.5852631057103288, -4.072767567818075,
+ -0.99707593216694956, 4.6945205762054307],
]),
- np.array([-0.45709100400275965, -1.8550340629069841, -0.22415042613116959, 0.42530295591391204, 0.99077132382609068, 0.44684458290517975]),
+ np.array(
+ [-0.45709100400275965, -1.8550340629069841, -0.22415042613116959, 0.42530295591391204,
+ 0.99077132382609068, 0.44684458290517975]),
np.array([
- [-0.32925296164525752, 0.34285843523483472, -1.1876007007262734, -0.34405996689960999, -0.48748723186183124, -0.84790951916486579],
- [0.34748864320332279, -1.4306241151049646, 0.48663092329413032, 0.36880547559765398, 0.5830781797631559, 0.56629405720887827],
+ [-0.32925296164525752, 0.34285843523483472, -1.1876007007262734, -0.34405996689960999,
+ -0.48748723186183124, -0.84790951916486579],
+ [0.34748864320332279, -1.4306241151049646, 0.48663092329413032, 0.36880547559765398,
+ 0.5830781797631559, 0.56629405720887827],
]),
np.array([-0.8042070619771764, -0.8113771733846965]),
)
- guess = np.array([0.33919202323040087, 1.4357688663259185, 0.128273057926652, 0.84509497913350029, 0.99165656530820734, 0.30459867095075666])
+ guess = np.array(
+ [0.33919202323040087, 1.4357688663259185, 0.128273057926652, 0.84509497913350029,
+ 0.99165656530820734, 0.30459867095075666])
cost, x = qps.find_local(guess, 1.0)
qps.check_solution(x)
@@ -711,20 +807,30 @@ def test_local_case4():
# Impossible to converge
qps = QPSolver(
np.array([
- [-0.41833209771758612, 0.062887697148893529, -0.016088048200215366, -0.050445141412105376, 0.28111333503256047, 0.34422748081701854],
- [0.062887697148893529, -0.37785375633297413, 0.95384534852986791, -0.17966631075461084, -0.54690073408327788, 0.74422105092988078],
- [-0.016088048200215366, 0.95384534852986791, -0.93407522326505077, 0.46787002711838876, 0.87574341703436942, -0.74308895418662135],
- [-0.050445141412105376, -0.17966631075461084, 0.46787002711838876, 0.095602896288350628, -0.43330607692880641, -0.09673966777597498],
- [0.28111333503256047, -0.54690073408327788, 0.87574341703436942, -0.43330607692880641, 0.08109348599752926, 1.8753235082158164],
- [0.34422748081701854, 0.74422105092988078, -0.74308895418662135, -0.09673966777597498, 1.8753235082158164, -0.29575516753680142],
+ [-0.41833209771758612, 0.062887697148893529, -0.016088048200215366,
+ -0.050445141412105376, 0.28111333503256047, 0.34422748081701854],
+ [0.062887697148893529, -0.37785375633297413, 0.95384534852986791, -0.17966631075461084,
+ -0.54690073408327788, 0.74422105092988078],
+ [-0.016088048200215366, 0.95384534852986791, -0.93407522326505077, 0.46787002711838876,
+ 0.87574341703436942, -0.74308895418662135],
+ [-0.050445141412105376, -0.17966631075461084, 0.46787002711838876, 0.095602896288350628,
+ -0.43330607692880641, -0.09673966777597498],
+ [0.28111333503256047, -0.54690073408327788, 0.87574341703436942, -0.43330607692880641,
+ 0.08109348599752926, 1.8753235082158164],
+ [0.34422748081701854, 0.74422105092988078, -0.74308895418662135, -0.09673966777597498,
+ 1.8753235082158164, -0.29575516753680142],
]),
- np.array([-1.369335961961399, 1.167500700090857, 0.21414477811997978, 2.5649100860678695, -1.9806821349849604, -1.5754238007215169]),
+ np.array([-1.369335961961399, 1.167500700090857, 0.21414477811997978, 2.5649100860678695,
+ -1.9806821349849604, -1.5754238007215169]),
np.array([
- [-0.41956342254107903, 0.71674035950201276, -1.5770905037800305, 0.43181073722954405, -0.97223306449577329, -0.62828793519627313],
+ [-0.41956342254107903, 0.71674035950201276, -1.5770905037800305, 0.43181073722954405,
+ -0.97223306449577329, -0.62828793519627313],
]),
np.array([-0.33651216328153544]),
)
- guess = np.array([1.4532630642344062, 0.72265262030217081, 0.065281886690390367, 0.1839421913168558, 0.20535723808514028, 0.03429655200129661])
+ guess = np.array(
+ [1.4532630642344062, 0.72265262030217081, 0.065281886690390367, 0.1839421913168558,
+ 0.20535723808514028, 0.03429655200129661])
with assert_raises(ConvergenceError):
qps.find_local(guess, 1.0)
@@ -733,21 +839,33 @@ def test_local_case5():
# slow convergence
qps = QPSolver(
np.array([
- [0.79079907934182903, 0.011808066578099186, -1.0980998280784657, -0.68897546615676319, -0.10555819609322133, -0.0094175398403186783],
- [0.011808066578099186, -1.2570947595949307, -0.25176742901500682, 0.43452314945243631, -0.51301954393280846, -0.31209650217715923],
- [-1.0980998280784657, -0.25176742901500682, 1.6781911482939742, -0.70553038981825766, 0.54040995405217274, 0.10204140147104501],
- [-0.68897546615676319, 0.43452314945243631, -0.70553038981825766, 0.12542537761324651, 0.40866389380559537, 0.18486598005512384],
- [-0.10555819609322133, -0.51301954393280846, 0.54040995405217274, 0.40866389380559537, -0.92415498156459686, 0.95932603388371385],
- [-0.0094175398403186783, -0.31209650217715923, 0.10204140147104501, 0.18486598005512384, 0.95932603388371385, 0.23569100050886349],
+ [0.79079907934182903, 0.011808066578099186, -1.0980998280784657, -0.68897546615676319,
+ -0.10555819609322133, -0.0094175398403186783],
+ [0.011808066578099186, -1.2570947595949307, -0.25176742901500682, 0.43452314945243631,
+ -0.51301954393280846, -0.31209650217715923],
+ [-1.0980998280784657, -0.25176742901500682, 1.6781911482939742, -0.70553038981825766,
+ 0.54040995405217274, 0.10204140147104501],
+ [-0.68897546615676319, 0.43452314945243631, -0.70553038981825766, 0.12542537761324651,
+ 0.40866389380559537, 0.18486598005512384],
+ [-0.10555819609322133, -0.51301954393280846, 0.54040995405217274, 0.40866389380559537,
+ -0.92415498156459686, 0.95932603388371385],
+ [-0.0094175398403186783, -0.31209650217715923, 0.10204140147104501, 0.18486598005512384,
+ 0.95932603388371385, 0.23569100050886349],
]),
- np.array([-0.46333818345367495, 0.21257179073800472, 0.62688340581190316, 2.2623297911779567, 0.50819379925975028, -0.6943526670820328]),
+ np.array(
+ [-0.46333818345367495, 0.21257179073800472, 0.62688340581190316, 2.2623297911779567,
+ 0.50819379925975028, -0.6943526670820328]),
np.array([
- [-1.2657558954797123, -0.58071957697534726, 1.7286979572389156, 0.79253342400981885, -0.92638488825515308, 0.42858228723662439],
- [-0.91371314768106349, -0.33354701632644296, 0.29090276846263258, 0.025115507692647247, -1.4686929816358802, 0.12857290086890488],
+ [-1.2657558954797123, -0.58071957697534726, 1.7286979572389156, 0.79253342400981885,
+ -0.92638488825515308, 0.42858228723662439],
+ [-0.91371314768106349, -0.33354701632644296, 0.29090276846263258, 0.025115507692647247,
+ -1.4686929816358802, 0.12857290086890488],
]),
np.array([2.7532334775271505, -0.48328722498961846]),
)
- guess = np.array([0.17076836616570085, 0.11727673011988589, 1.1886537627251008, 1.675822839903278, 0.48066423537800507, 0.23286211070422069])
+ guess = np.array(
+ [0.17076836616570085, 0.11727673011988589, 1.1886537627251008, 1.675822839903278,
+ 0.48066423537800507, 0.23286211070422069])
cost, x = qps.find_local(guess, 1.0)
qps.check_solution(x)
@@ -757,18 +875,28 @@ def test_local_case6():
# the trust radius should not be too small... solved.
qps = QPSolver(
np.array([
- [3.049138030515488, -2.267339701331577, 1.6452178953594849, -1.1114025762214919, -1.4683391262333996, -2.8949938905463575],
- [-2.267339701331577, 4.0639013616185977, -0.85512669477123537, 0.16765289716466125, 0.54721401159266114, 2.3075404741986758],
- [1.6452178953594849, -0.85512669477123537, 4.4883269223774871, -5.4322963136631426, -2.5999282829704065, -4.2203649379170152],
- [-1.1114025762214919, 0.16765289716466125, -5.4322963136631426, 11.291537524605506, 2.1266925840689384, -0.15939236254485001],
- [-1.4683391262333996, 0.54721401159266114, -2.5999282829704065, 2.1266925840689384, 3.3080344785127451, 2.7570212908688965],
- [-2.8949938905463575, 2.3075404741986758, -4.2203649379170152, -0.15939236254485001, 2.7570212908688965, 10.413810265914657],
+ [3.049138030515488, -2.267339701331577, 1.6452178953594849, -1.1114025762214919,
+ -1.4683391262333996, -2.8949938905463575],
+ [-2.267339701331577, 4.0639013616185977, -0.85512669477123537, 0.16765289716466125,
+ 0.54721401159266114, 2.3075404741986758],
+ [1.6452178953594849, -0.85512669477123537, 4.4883269223774871, -5.4322963136631426,
+ -2.5999282829704065, -4.2203649379170152],
+ [-1.1114025762214919, 0.16765289716466125, -5.4322963136631426, 11.291537524605506,
+ 2.1266925840689384, -0.15939236254485001],
+ [-1.4683391262333996, 0.54721401159266114, -2.5999282829704065, 2.1266925840689384,
+ 3.3080344785127451, 2.7570212908688965],
+ [-2.8949938905463575, 2.3075404741986758, -4.2203649379170152, -0.15939236254485001,
+ 2.7570212908688965, 10.413810265914657],
]),
- np.array([2.1051178688693808, 0.77034513234528068, -0.066413262422188549, -1.161467599974259, -1.145284458324215, 1.9115896887435808]),
- np.zeros((0,6)),
+ np.array(
+ [2.1051178688693808, 0.77034513234528068, -0.066413262422188549, -1.161467599974259,
+ -1.145284458324215, 1.9115896887435808]),
+ np.zeros((0, 6)),
np.array([]),
)
- guess = np.array([1.1218006104444309, 0.055845280862766397, 0.5678162968457573, 0.64202055422478232, 0.79817332647621919, 0.4492255175376717])
+ guess = np.array(
+ [1.1218006104444309, 0.055845280862766397, 0.5678162968457573, 0.64202055422478232,
+ 0.79817332647621919, 0.4492255175376717])
cost, x = qps.find_local(guess, 10.0)
qps.check_solution(x)
@@ -777,22 +905,33 @@ def test_local_case7():
# local search seems to beat global one?
qps = QPSolver(
np.array([
- [-0.70579902180480114, -0.4327726229988561, 0.24228757421240607, 0.51418623618564996, 1.0632780675093283, -1.2852213384501507],
- [-0.4327726229988561, -1.0084276903656637, 0.27249303018293985, 1.3760173009608194, 0.67570216250059412, 0.52160016838454792],
- [0.24228757421240607, 0.27249303018293985, -0.125476715180112, -0.21437197456564006, 0.92014307041811716, 0.77230951003769155],
- [0.51418623618564996, 1.3760173009608194, -0.21437197456564006, 0.11169101328138263, -0.58757562610076719, 0.54870518654715494],
- [1.0632780675093283, 0.67570216250059412, 0.92014307041811716, -0.58757562610076719, 1.3791708665173121, -0.44585251609595422],
- [-1.2852213384501507, 0.52160016838454792, 0.77230951003769155, 0.54870518654715494, -0.44585251609595422, -1.5140735372378349],
+ [-0.70579902180480114, -0.4327726229988561, 0.24228757421240607, 0.51418623618564996,
+ 1.0632780675093283, -1.2852213384501507],
+ [-0.4327726229988561, -1.0084276903656637, 0.27249303018293985, 1.3760173009608194,
+ 0.67570216250059412, 0.52160016838454792],
+ [0.24228757421240607, 0.27249303018293985, -0.125476715180112, -0.21437197456564006,
+ 0.92014307041811716, 0.77230951003769155],
+ [0.51418623618564996, 1.3760173009608194, -0.21437197456564006, 0.11169101328138263,
+ -0.58757562610076719, 0.54870518654715494],
+ [1.0632780675093283, 0.67570216250059412, 0.92014307041811716, -0.58757562610076719,
+ 1.3791708665173121, -0.44585251609595422],
+ [-1.2852213384501507, 0.52160016838454792, 0.77230951003769155, 0.54870518654715494,
+ -0.44585251609595422, -1.5140735372378349],
]),
- np.array([-2.2854963174099305, -0.70412551963528325, -0.20443019124351977, -1.750838749153953, 0.92664898509539495, -1.3205815413488067]),
+ np.array(
+ [-2.2854963174099305, -0.70412551963528325, -0.20443019124351977, -1.750838749153953,
+ 0.92664898509539495, -1.3205815413488067]),
np.array([
- [-1.4834034545177326, 0.61696635160928115, 1.2902252770986995, -0.96826004067118876, -1.865873147282245, 2.1304980879954329],
+ [-1.4834034545177326, 0.61696635160928115, 1.2902252770986995, -0.96826004067118876,
+ -1.865873147282245, 2.1304980879954329],
]),
np.array([-1.8919484511303895]),
)
cost0, x0 = qps.find_brute()
qps.check_solution(x0)
- guess = np.array([0.66874113007080915, 0.38269689497818871, 0.43551620861147256, 1.7616957362635119, 0.87395834895248681, 0.76907570723573859])
+ guess = np.array(
+ [0.66874113007080915, 0.38269689497818871, 0.43551620861147256, 1.7616957362635119,
+ 0.87395834895248681, 0.76907570723573859])
cost1, x1 = qps.find_local(guess, 10.0)
qps.check_solution(x1)
assert cost0 - cost1 < qps.eps
@@ -804,18 +943,40 @@ def test_local_case8():
# this also works.
qps = QPSolver(
np.array([
- [-0, -0.80335249114943963, -0.4810486491314947, -0.089239349136249757, -0.15436494944003698, -0.35230777891029419, -0.28555315037639062, -0.19177912108670014, -0.21585294726538962, -0.26476652332778627],
- [-0.80335249114943963, -0, -0.040921462946748477, -0.38027796950886028, -0.2660150289073222, -0.098718781279508505, -0.13982199557364083, -0.22452799188664585, -0.19912180157206549, -0.15608175980106864],
- [-0.4810486491314947, -0.040921462946748477, -0, -0.17321382433037158, -0.099670821942954291, -0.014896131374744215, -0.031613318232015075, -0.075875344294711766, -0.061676589860272912, -0.039439435052052829],
- [-0.089239349136249757, -0.38027796950886028, -0.17321382433037158, -0, -0.010168990909519948, -0.092711943454681034, -0.059610136408235093, -0.02078877416074576, -0.029532988876905364, -0.049855163352130916],
- [-0.15436494944003698, -0.2660150289073222, -0.099670821942954291, -0.010168990909519948, -0, -0.041590858093009331, -0.020646513109756626, -0.0020336615488893983, -0.0051892404310116547, -0.015133796800792965],
- [-0.35230777891029419, -0.098718781279508505, -0.014896131374744215, -0.092711943454681034, -0.041590858093009331, -0, -0.0036392226383412662, -0.025764057353654835, -0.017631978012037308, -0.0066142161822391188],
- [-0.28555315037639062, -0.13982199557364083, -0.031613318232015075, -0.059610136408235093, -0.020646513109756626, -0.0036392226383412662, -0, -0.010041713436219624, -0.0052548807969650113, -0.00044679245518608468],
- [-0.19177912108670014, -0.22452799188664585, -0.075875344294711766, -0.02078877416074576, -0.0020336615488893983, -0.025764057353654835, -0.010041713436219624, -0, -0.00076870247709948103, -0.006272367939274659],
- [-0.21585294726538962, -0.19912180157206549, -0.061676589860272912, -0.029532988876905364, -0.0051892404310116547, -0.017631978012037308, -0.0052548807969650113, -0.00076870247709948103, -0, -0.0026493882418954229],
- [-0.26476652332778627, -0.15608175980106864, -0.039439435052052829, -0.049855163352130916, -0.015133796800792965, -0.0066142161822391188, -0.00044679245518608468, -0.006272367939274659, -0.0026493882418954229, -0],
+ [-0, -0.80335249114943963, -0.4810486491314947, -0.089239349136249757,
+ -0.15436494944003698, -0.35230777891029419, -0.28555315037639062, -0.19177912108670014,
+ -0.21585294726538962, -0.26476652332778627],
+ [-0.80335249114943963, -0, -0.040921462946748477, -0.38027796950886028,
+ -0.2660150289073222, -0.098718781279508505, -0.13982199557364083, -0.22452799188664585,
+ -0.19912180157206549, -0.15608175980106864],
+ [-0.4810486491314947, -0.040921462946748477, -0, -0.17321382433037158,
+ -0.099670821942954291, -0.014896131374744215, -0.031613318232015075,
+ -0.075875344294711766, -0.061676589860272912, -0.039439435052052829],
+ [-0.089239349136249757, -0.38027796950886028, -0.17321382433037158, -0,
+ -0.010168990909519948, -0.092711943454681034, -0.059610136408235093,
+ -0.02078877416074576, -0.029532988876905364, -0.049855163352130916],
+ [-0.15436494944003698, -0.2660150289073222, -0.099670821942954291,
+ -0.010168990909519948, -0, -0.041590858093009331, -0.020646513109756626,
+ -0.0020336615488893983, -0.0051892404310116547, -0.015133796800792965],
+ [-0.35230777891029419, -0.098718781279508505, -0.014896131374744215,
+ -0.092711943454681034, -0.041590858093009331, -0, -0.0036392226383412662,
+ -0.025764057353654835, -0.017631978012037308, -0.0066142161822391188],
+ [-0.28555315037639062, -0.13982199557364083, -0.031613318232015075,
+ -0.059610136408235093, -0.020646513109756626, -0.0036392226383412662, -0,
+ -0.010041713436219624, -0.0052548807969650113, -0.00044679245518608468],
+ [-0.19177912108670014, -0.22452799188664585, -0.075875344294711766,
+ -0.02078877416074576, -0.0020336615488893983, -0.025764057353654835,
+ -0.010041713436219624, -0, -0.00076870247709948103, -0.006272367939274659],
+ [-0.21585294726538962, -0.19912180157206549, -0.061676589860272912,
+ -0.029532988876905364, -0.0051892404310116547, -0.017631978012037308,
+ -0.0052548807969650113, -0.00076870247709948103, -0, -0.0026493882418954229],
+ [-0.26476652332778627, -0.15608175980106864, -0.039439435052052829,
+ -0.049855163352130916, -0.015133796800792965, -0.0066142161822391188,
+ -0.00044679245518608468, -0.006272367939274659, -0.0026493882418954229, -0],
]),
- np.array([96.74931669030984, 97.210304973486174, 97.2575693294621, 97.462260931861223, 97.472700776115133, 97.518784700439411, 97.5224733817101, 97.535582111324103, 97.536350310192589, 97.539372850065561]),
+ np.array([96.74931669030984, 97.210304973486174, 97.2575693294621, 97.462260931861223,
+ 97.472700776115133, 97.518784700439411, 97.5224733817101, 97.535582111324103,
+ 97.536350310192589, 97.539372850065561]),
np.array([
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
]),
@@ -830,19 +991,43 @@ def test_local_case9():
# yet another hard case for convergence
qps = QPSolver(
np.array([
- [-0, -241.45520097844334, -81.025811808215622, -66.646386842604926, -90.984366008742555, -52.004805821364386, -70.425468607943742, -57.366620069719914, -55.1877804833006, -53.705769566242907, -56.391096977161254],
- [-241.45520097844334, -0, -162.135903992414, -90.262677632643232, -70.276892079044018, -92.875705599218321, -72.28463739472835, -79.197990735263048, -82.586075985622472, -83.994287707438332, -78.796070159949906],
- [-81.025811808215622, -162.135903992414, -0, -87.28951414271836, -48.242358569534147, -28.742953020160229, -49.101136904866735, -32.105000819299548, -40.850665783027893, -30.057423682337586, -33.735044181468567],
- [-66.646386842604926, -90.262677632643232, -87.28951414271836, -0, -57.659521455279005, -24.69684419657078, -20.307639293415008, -21.441458536207293, -11.199312043260591, -19.974590362450328, -17.916540652877458],
- [-90.984366008742555, -70.276892079044018, -48.242358569534147, -57.659521455279005, -0, -27.948974737346248, -13.712164271081321, -14.218021097302355, -30.862156391808355, -19.790364207820602, -17.217970999822271],
- [-52.004805821364386, -92.875705599218321, -28.742953020160229, -24.69684419657078, -27.948974737346248, -0, -18.060952321337993, -4.025388940084369, -3.8482396016948144, -1.8363489948160066, -3.644582361475031],
- [-70.425468607943742, -72.28463739472835, -49.101136904866735, -20.307639293415008, -13.712164271081321, -18.060952321337993, -0, -5.93835013335962, -10.593591943371536, -8.6487068864670533, -5.644151180036971],
- [-57.366620069719914, -79.197990735263048, -32.105000819299548, -21.441458536207293, -14.218021097302355, -4.025388940084369, -5.93835013335962, -0, -4.241229635355424, -0.7847837230720387, -0.29680249521985047],
- [-55.1877804833006, -82.586075985622472, -40.850665783027893, -11.199312043260591, -30.862156391808355, -3.8482396016948144, -10.593591943371536, -4.241229635355424, -0, -2.1191260827439748, -2.4949817756629358],
- [-53.705769566242907, -83.994287707438332, -30.057423682337586, -19.974590362450328, -19.790364207820602, -1.8363489948160066, -8.6487068864670533, -0.7847837230720387, -2.1191260827439748, -0, -0.46855762948329982],
- [-56.391096977161254, -78.796070159949906, -33.735044181468567, -17.916540652877458, -17.217970999822271, -3.644582361475031, -5.644151180036971, -0.29680249521985047, -2.4949817756629358, -0.46855762948329982, -0],
+ [-0, -241.45520097844334, -81.025811808215622, -66.646386842604926, -90.984366008742555,
+ -52.004805821364386, -70.425468607943742, -57.366620069719914, -55.1877804833006,
+ -53.705769566242907, -56.391096977161254],
+ [-241.45520097844334, -0, -162.135903992414, -90.262677632643232, -70.276892079044018,
+ -92.875705599218321, -72.28463739472835, -79.197990735263048, -82.586075985622472,
+ -83.994287707438332, -78.796070159949906],
+ [-81.025811808215622, -162.135903992414, -0, -87.28951414271836, -48.242358569534147,
+ -28.742953020160229, -49.101136904866735, -32.105000819299548, -40.850665783027893,
+ -30.057423682337586, -33.735044181468567],
+ [-66.646386842604926, -90.262677632643232, -87.28951414271836, -0, -57.659521455279005,
+ -24.69684419657078, -20.307639293415008, -21.441458536207293, -11.199312043260591,
+ -19.974590362450328, -17.916540652877458],
+ [-90.984366008742555, -70.276892079044018, -48.242358569534147, -57.659521455279005, -0,
+ -27.948974737346248, -13.712164271081321, -14.218021097302355, -30.862156391808355,
+ -19.790364207820602, -17.217970999822271],
+ [-52.004805821364386, -92.875705599218321, -28.742953020160229, -24.69684419657078,
+ -27.948974737346248, -0, -18.060952321337993, -4.025388940084369, -3.8482396016948144,
+ -1.8363489948160066, -3.644582361475031],
+ [-70.425468607943742, -72.28463739472835, -49.101136904866735, -20.307639293415008,
+ -13.712164271081321, -18.060952321337993, -0, -5.93835013335962, -10.593591943371536,
+ -8.6487068864670533, -5.644151180036971],
+ [-57.366620069719914, -79.197990735263048, -32.105000819299548, -21.441458536207293,
+ -14.218021097302355, -4.025388940084369, -5.93835013335962, -0, -4.241229635355424,
+ -0.7847837230720387, -0.29680249521985047],
+ [-55.1877804833006, -82.586075985622472, -40.850665783027893, -11.199312043260591,
+ -30.862156391808355, -3.8482396016948144, -10.593591943371536, -4.241229635355424, -0,
+ -2.1191260827439748, -2.4949817756629358],
+ [-53.705769566242907, -83.994287707438332, -30.057423682337586, -19.974590362450328,
+ -19.790364207820602, -1.8363489948160066, -8.6487068864670533, -0.7847837230720387,
+ -2.1191260827439748, -0, -0.46855762948329982],
+ [-56.391096977161254, -78.796070159949906, -33.735044181468567, -17.916540652877458,
+ -17.217970999822271, -3.644582361475031, -5.644151180036971, -0.29680249521985047,
+ -2.4949817756629358, -0.46855762948329982, -0],
]),
- np.array([219.88503892388073, 206.47122847047703, 264.95062224390711, 282.07819206858949, 285.59235059522575, 303.26503791957691, 298.61126236074369, 307.14088474324785, 304.05986518939471, 307.14000745089061, 307.31174519920341]),
+ np.array([219.88503892388073, 206.47122847047703, 264.95062224390711, 282.07819206858949,
+ 285.59235059522575, 303.26503791957691, 298.61126236074369, 307.14088474324785,
+ 304.05986518939471, 307.14000745089061, 307.31174519920341]),
np.array([
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
]),
@@ -858,18 +1043,28 @@ def test_local_case10():
# This turned out to be a trust radius that was too small.
qps = QPSolver(
np.array([
- [3.6420954087755524, -3.0520276574272556, 0.8600212081041877, -0.27002779932504622, -1.4149411955120152, -1.7656114953692559],
- [-3.0520276574272556, 5.2980117879019053, -0.51863311310056681, -3.1078082667477691, 1.2965118123600228, 2.5974001710229837],
- [0.8600212081041877, -0.51863311310056681, 2.2859933272503223, 0.38632978005515767, 0.24074547614702529, -2.5864818874051134],
- [-0.27002779932504622, -3.1078082667477691, 0.38632978005515767, 4.5718542781367075, 0.31035781257497425, -2.2997148639134855],
- [-1.4149411955120152, 1.2965118123600228, 0.24074547614702529, 0.31035781257497425, 3.592559354700823, -0.32310839292740823],
- [-1.7656114953692559, 2.5974001710229837, -2.5864818874051134, -2.2997148639134855, -0.32310839292740823, 4.1635594436043855],
+ [3.6420954087755524, -3.0520276574272556, 0.8600212081041877, -0.27002779932504622,
+ -1.4149411955120152, -1.7656114953692559],
+ [-3.0520276574272556, 5.2980117879019053, -0.51863311310056681, -3.1078082667477691,
+ 1.2965118123600228, 2.5974001710229837],
+ [0.8600212081041877, -0.51863311310056681, 2.2859933272503223, 0.38632978005515767,
+ 0.24074547614702529, -2.5864818874051134],
+ [-0.27002779932504622, -3.1078082667477691, 0.38632978005515767, 4.5718542781367075,
+ 0.31035781257497425, -2.2997148639134855],
+ [-1.4149411955120152, 1.2965118123600228, 0.24074547614702529, 0.31035781257497425,
+ 3.592559354700823, -0.32310839292740823],
+ [-1.7656114953692559, 2.5974001710229837, -2.5864818874051134, -2.2997148639134855,
+ -0.32310839292740823, 4.1635594436043855],
]),
- np.array([0.6827237762636329, 0.61262449970997035, -0.10526820438669089, -0.3423860463506388, -0.60158021270458772, -0.32020790415623457]),
- np.zeros((0,6)),
+ np.array(
+ [0.6827237762636329, 0.61262449970997035, -0.10526820438669089, -0.3423860463506388,
+ -0.60158021270458772, -0.32020790415623457]),
+ np.zeros((0, 6)),
np.array([]),
)
- guess = np.array([0.4183733839886043, 1.685868545495764, 0.91029464030598595, 0.20609014773347709, 0.41772085105136075, 0.21627704946572152])
+ guess = np.array(
+ [0.4183733839886043, 1.685868545495764, 0.91029464030598595, 0.20609014773347709,
+ 0.41772085105136075, 0.21627704946572152])
cost, x = qps.find_local(guess, 100.0)
qps.check_solution(x)
@@ -879,23 +1074,34 @@ def test_local_case11():
# current eps parameters.
qps = QPSolver(
np.array([
- [2.9180906444949501, -1.2533029767785395, 0.90478564555244811, 1.2787545043913675, 0.021113032381065766, -0.4116750982169069],
- [-1.2533029767785395, 5.6632299906311987, 1.4008760670203191, -2.0390934015965536, -0.85045793596990116, 0.73218455692376505],
- [0.90478564555244811, 1.4008760670203191, 5.2855381382892999, 2.677903087938867, 1.9188439544442164, -1.9709008178264937],
- [1.2787545043913675, -2.0390934015965536, 2.677903087938867, 4.993172076325008, 1.4299089422151234, -0.74354828220123381],
- [0.021113032381065766, -0.85045793596990116, 1.9188439544442164, 1.4299089422151234, 3.1450801244239486, -0.0036684167027846853],
- [-0.4116750982169069, 0.73218455692376505, -1.9709008178264937, -0.74354828220123381, -0.0036684167027846853, 2.5434283210738671],
+ [2.9180906444949501, -1.2533029767785395, 0.90478564555244811, 1.2787545043913675,
+ 0.021113032381065766, -0.4116750982169069],
+ [-1.2533029767785395, 5.6632299906311987, 1.4008760670203191, -2.0390934015965536,
+ -0.85045793596990116, 0.73218455692376505],
+ [0.90478564555244811, 1.4008760670203191, 5.2855381382892999, 2.677903087938867,
+ 1.9188439544442164, -1.9709008178264937],
+ [1.2787545043913675, -2.0390934015965536, 2.677903087938867, 4.993172076325008,
+ 1.4299089422151234, -0.74354828220123381],
+ [0.021113032381065766, -0.85045793596990116, 1.9188439544442164, 1.4299089422151234,
+ 3.1450801244239486, -0.0036684167027846853],
+ [-0.4116750982169069, 0.73218455692376505, -1.9709008178264937, -0.74354828220123381,
+ -0.0036684167027846853, 2.5434283210738671],
]),
- np.array([-0.29192463967063931, -1.8024178730096532, 0.88758128602009223, 2.3598192316830855, -1.1550614364716303, 0.31271490996557316]),
+ np.array(
+ [-0.29192463967063931, -1.8024178730096532, 0.88758128602009223, 2.3598192316830855,
+ -1.1550614364716303, 0.31271490996557316]),
np.array([
- [-1.5989252225397905, 0.81244820675095797, -1.6307964553181504, -0.4456644455138748, 3.3167580671951278, -0.73081081535097092],
+ [-1.5989252225397905, 0.81244820675095797, -1.6307964553181504, -0.4456644455138748,
+ 3.3167580671951278, -0.73081081535097092],
]),
np.array([1.7184957352780219]),
eps=1e-6,
)
cost0, x0 = qps.find_brute()
qps.check_solution(x0)
- guess = np.array([0.5527936565693109, 1.2295737022405098, 0.68854432659855258, 0.11250382959013361, 0.84458517701828661, 0.0340219228211837])
+ guess = np.array(
+ [0.5527936565693109, 1.2295737022405098, 0.68854432659855258, 0.11250382959013361,
+ 0.84458517701828661, 0.0340219228211837])
cost, x1 = qps.find_local(guess, 100.0)
qps.check_solution(x1)
assert abs(x0 - x1).max() < qps.eps
diff --git a/horton/meanfield/test/test_response.py b/horton/meanfield/test/test_response.py
index 94f6a55a..33dcf99f 100644
--- a/horton/meanfield/test/test_response.py
+++ b/horton/meanfield/test/test_response.py
@@ -20,17 +20,22 @@
# --
+
import numpy as np
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
+from horton.meanfield.test.common import get_obasis, load_orbs_alpha, load_orbs_beta
+from horton.part import get_mulliken_operators
+from .. import compute_noninteracting_response
+
+def check_response(fname):
+ operators = get_mulliken_operators(get_obasis(fname))
+ orbs = [load_orbs_alpha(fname)]
+ try:
+ orbs.append(load_orbs_beta(fname))
+ except IOError:
+ pass
-def check_response(fn):
- mol = IOData.from_file(fn)
- operators = get_mulliken_operators(mol.obasis)
- orbs = [mol.orb_alpha]
- if hasattr(mol, 'orb_beta'):
- orbs.append(mol.orb_beta)
for orb in orbs:
response = compute_noninteracting_response(orb, operators)
assert np.isfinite(response).all()
@@ -41,15 +46,15 @@ def check_response(fn):
def test_response_water_sto3g():
- fn_fchk = context.get_fn('test/water_sto3g_hf_g03.fchk')
- check_response(fn_fchk)
+ fname = 'water_sto3g_hf_g03_fchk'
+ check_response(fname)
def test_response_h3_321g():
- fn_fchk = context.get_fn('test/h3_hfs_321g.fchk')
- check_response(fn_fchk)
-
+ fname = 'h3_hfs_321g_fchk'
+ check_response(fname)
-def test_response_benzene():
- fn_fchk = context.get_fn('test/benzene-sto3g.fchk')
- check_response(fn_fchk)
+# TODO: Move to higher level test
+# def test_response_benzene():
+# fname = 'benzene_sto3g_fchk'
+# check_response(fname)
diff --git a/horton/meanfield/test/test_rotate.py b/horton/meanfield/test/test_rotate.py
index a92009cf..47192c82 100644
--- a/horton/meanfield/test/test_rotate.py
+++ b/horton/meanfield/test/test_rotate.py
@@ -20,61 +20,70 @@
# --
+
import numpy as np
from nose.plugins.attrib import attr
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
+from common import load_kin, load_orbs_alpha, load_olp, get_obasis
+from horton.grid import get_random_rotation # TODO: Remove random rotation?
+from .. import Orbitals
+from ..rotate import rotate_coeffs
@attr('slow')
def test_rotation_energy():
- mol = IOData.from_file(context.get_fn('test/he_spdf_orbital.fchk'))
- kin = mol.obasis.compute_kinetic()
- e0 = np.einsum('ab,ba', kin, mol.orb_alpha.to_dm())
+ fname = 'he_spdf_orbital_fchk'
+ kin = load_kin(fname)
+ e0 = np.einsum('ab,ba', kin, load_orbs_alpha(fname).to_dm())
for irep in xrange(100):
rmat = get_random_rotation()
- mol.orb_alpha.coeffs[:] = rotate_coeffs(mol.orb_alpha.coeffs, mol.obasis, rmat)
- e1 = np.einsum('ab,ba', kin, mol.orb_alpha.to_dm())
+ orb_alpha = load_orbs_alpha(fname)
+ orb_alpha.coeffs[:] = rotate_coeffs(load_orbs_alpha(fname).coeffs,
+ get_obasis(fname).shell_types, rmat)
+ e1 = np.einsum('ab,ba', kin, load_orbs_alpha(fname).to_dm())
assert abs(e0 - e1) < 1e-10
def test_rotation_sp():
- mol = IOData.from_file(context.get_fn('test/he_sp_orbital.fchk'))
+ fname = 'he_sp_orbital_fchk'
rmat = np.array([[0.0, -1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]])
- assert (mol.orb_alpha.coeffs[5:7,3:5] == [[0, 1], [1, 0]]).all()
- mol.orb_alpha.coeffs[:] = rotate_coeffs(mol.orb_alpha.coeffs, mol.obasis, rmat)
- assert (mol.orb_alpha.coeffs[5:7,3:5] == [[-1, 0], [0, 1]]).all()
+ assert (load_orbs_alpha(fname).coeffs[5:7, 3:5] == [[0, 1], [1, 0]]).all()
+ orb_alpha = load_orbs_alpha(fname)
+ orb_alpha.coeffs[:] = rotate_coeffs(load_orbs_alpha(fname).coeffs,
+ get_obasis(fname).shell_types, rmat)
+ assert (orb_alpha.coeffs[5:7, 3:5] == [[-1, 0], [0, 1]]).all()
-def test_rotation_orhonormal():
- obasis = get_gobasis(np.zeros((1, 3)), np.array([10]), 'cc-pvtz', pure=False)
- overlap = obasis.compute_overlap()
+def test_rotation_orthonormal():
+ # obasis = get_gobasis(np.zeros((1, 3)), np.array([10]), 'cc-pvtz', pure=False)
+ overlap = load_olp("rotation_orthonormal")
def helper(begin, end):
# prepare random orbitals in selected range
norb = end - begin
assert norb > 0
- orb = Orbitals(obasis.nbasis)
+ orb = Orbitals(overlap.shape[0])
orb.occupations[:norb] = 1
# fill with random orbitals and lowdin orthogonalize
- #orb.coeffs[begin:end,:norb] = np.random.normal(0, 1, (norb, norb))
- orb.coeffs[begin:end,:norb] = np.identity(norb)
- grammian = np.dot(orb.coeffs[:,:norb].T, np.dot(overlap, orb.coeffs[:,:norb]))
+ # orb.coeffs[begin:end,:norb] = np.random.normal(0, 1, (norb, norb))
+ orb.coeffs[begin:end, :norb] = np.identity(norb)
+ grammian = np.dot(orb.coeffs[:, :norb].T, np.dot(overlap, orb.coeffs[:, :norb]))
evals, evecs = np.linalg.eigh(grammian)
- orb.coeffs[:,:norb] = np.dot(orb.coeffs[:,:norb], evecs)/evals**0.5
- assert (orb.coeffs[:begin,:norb] == 0.0).all()
- assert (orb.coeffs[end:,:norb] == 0.0).all()
+ orb.coeffs[:, :norb] = np.dot(orb.coeffs[:, :norb], evecs) / evals ** 0.5
+ assert (orb.coeffs[:begin, :norb] == 0.0).all()
+ assert (orb.coeffs[end:, :norb] == 0.0).all()
orb.check_normalization(overlap)
# apply rotation and check normalization again
rmat = get_random_rotation()
- #rmat = np.array([[0, 1, 0], [0, 0, 1], [1, 0, 0]])
- #rmat = get_rotation_matrix(np.array([0, 0, 1]), np.pi/4)
- orb.coeffs[:,:norb] = rotate_coeffs(orb.coeffs[:,:norb], obasis, rmat)
+ # rmat = np.array([[0, 1, 0], [0, 0, 1], [1, 0, 0]])
+ # rmat = get_rotation_matrix(np.array([0, 0, 1]), np.pi/4)
+ shell_types = np.array([0, 0, 0, 0, 1, 1, 1, 2, 2, 3]) # From test system
+ orb.coeffs[:, :norb] = rotate_coeffs(orb.coeffs[:, :norb], shell_types, rmat)
orb.check_normalization(overlap)
- helper( 0, 4) # all s-type basis functions
- helper( 4, 13) # all p-type basis functions
- helper(13, 14) # just one d-type basis function
- helper(13, 19) # first set of d-type basis functions
- helper(13, 25) # all d-type basis functions
- helper(25, 35) # all f-type basis functions
+ helper(0, 4) # all s-type basis functions
+ helper(4, 13) # all p-type basis functions
+ helper(13, 14) # just one d-type basis function
+ helper(13, 19) # first set of d-type basis functions
+ helper(13, 25) # all d-type basis functions
+ helper(25, 35) # all f-type basis functions
diff --git a/horton/meanfield/test/test_scf.py b/horton/meanfield/test/test_scf.py
index 7d7089f7..d71f7872 100644
--- a/horton/meanfield/test/test_scf.py
+++ b/horton/meanfield/test/test_scf.py
@@ -20,13 +20,12 @@
# --
-import numpy as np
-
from nose.tools import assert_raises
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.meanfield.test.common import check_hf_cs_hf, check_lih_os_hf, \
- check_vanadium_sc_hf
+from .common import check_hf_cs_hf, check_lih_os_hf, \
+ load_olp, load_kin, load_na, load_er
+from .. import PlainSCFSolver, AufbauOccModel, Orbitals, RTwoIndexTerm, \
+ RDirectTerm, RExchangeTerm, REffHam
def test_hf_cs_hf():
@@ -37,9 +36,10 @@ def test_lih_os_hf():
check_lih_os_hf(PlainSCFSolver(threshold=1e-10))
-def test_vanadium_sc_hf():
- with assert_raises(NoSCFConvergence):
- check_vanadium_sc_hf(PlainSCFSolver(threshold=1e-10, maxiter=10))
+# TODO: Move to higher level test
+# def test_vanadium_sc_hf():
+# with assert_raises(NoSCFConvergence):
+# check_vanadium_sc_hf(PlainSCFSolver(threshold=1e-10, maxiter=10))
def test_hf_cs_hf_level_shift():
@@ -50,23 +50,21 @@ def test_lih_os_hf_level_shift():
check_lih_os_hf(PlainSCFSolver(threshold=1e-10, level_shift=0.02))
-def test_vanadium_sc_hf_level_shift():
- with assert_raises(ValueError):
- check_vanadium_sc_hf(PlainSCFSolver(threshold=1e-10, level_shift=-0.1))
+# TODO: Move to higher level test
+# def test_vanadium_sc_hf_level_shift():
+# with assert_raises(ValueError):
+# check_vanadium_sc_hf(PlainSCFSolver(threshold=1e-10, level_shift=-0.1))
def test_hf_water_321g_mistake():
# When one forgets to construct the initial guess, some error must be
# raised...
- fn_xyz = context.get_fn('test/water.xyz')
- mol = IOData.from_file(fn_xyz)
- obasis = get_gobasis(mol.coordinates, mol.numbers, '3-21G')
+ fname = 'water_3_21G_xyz'
occ_model = AufbauOccModel(5)
- orb_alpha = Orbitals(obasis.nbasis)
- olp = obasis.compute_overlap()
- kin = obasis.compute_kinetic()
- na = obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = obasis.compute_electron_repulsion()
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
terms = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
@@ -75,5 +73,6 @@ def test_hf_water_321g_mistake():
]
ham = REffHam(terms)
scf_solver = PlainSCFSolver()
+ orb_alpha = Orbitals(olp.shape[0])
with assert_raises(AssertionError):
scf_solver(ham, olp, occ_model, orb_alpha)
diff --git a/horton/meanfield/test/test_scf_cdiis.py b/horton/meanfield/test/test_scf_cdiis.py
index 6a00da0c..7c33f8fc 100644
--- a/horton/meanfield/test/test_scf_cdiis.py
+++ b/horton/meanfield/test/test_scf_cdiis.py
@@ -20,16 +20,13 @@
# --
-import numpy as np
-
-from nose.tools import assert_raises
-
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.meanfield.test.common import check_hf_cs_hf, check_lih_os_hf, \
+from .common import check_hf_cs_hf, check_lih_os_hf, \
check_water_cs_hfs, check_n2_cs_hfs, check_h3_os_hfs, check_h3_os_pbe, \
- check_co_cs_pbe, check_vanadium_sc_hf, check_water_cs_m05, \
+ check_co_cs_pbe, check_water_cs_m05, \
check_methyl_os_tpss
+from .. import CDIISSCFSolver
+
def test_hf_cs_hf():
check_hf_cs_hf(CDIISSCFSolver(threshold=1e-7))
@@ -59,9 +56,10 @@ def test_h3_os_pbe():
check_h3_os_pbe(CDIISSCFSolver(threshold=1e-6))
-def test_vanadium_sc_hf():
- with assert_raises(NoSCFConvergence):
- check_vanadium_sc_hf(CDIISSCFSolver(threshold=1e-10, maxiter=10))
+# TODO: Move to higher level test
+# def test_vanadium_sc_hf():
+# with assert_raises(NoSCFConvergence):
+# check_vanadium_sc_hf(CDIISSCFSolver(threshold=1e-10, maxiter=10))
def test_water_cs_m05():
diff --git a/horton/meanfield/test/test_scf_ediis.py b/horton/meanfield/test/test_scf_ediis.py
index e7e0e4c0..eb06b419 100644
--- a/horton/meanfield/test/test_scf_ediis.py
+++ b/horton/meanfield/test/test_scf_ediis.py
@@ -21,15 +21,15 @@
import numpy as np
-
from nose.plugins.attrib import attr
-from nose.tools import assert_raises
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.meanfield.test.common import check_hf_cs_hf, check_lih_os_hf, \
+from .common import check_hf_cs_hf, check_lih_os_hf, \
check_water_cs_hfs, check_n2_cs_hfs, check_h3_os_hfs, check_h3_os_pbe, \
- check_co_cs_pbe, check_vanadium_sc_hf, check_water_cs_m05, \
- check_methyl_os_tpss
+ check_co_cs_pbe, check_water_cs_m05, \
+ check_methyl_os_tpss, load_mdata, load_olp, load_kin, load_na, load_er, load_nn, \
+ load_orbs_alpha, load_orbs_beta
+from .. import EDIISSCFSolver, NoSCFConvergence, RTwoIndexTerm, RDirectTerm, RExchangeTerm, REffHam, \
+ AufbauOccModel, UTwoIndexTerm, UDirectTerm, UExchangeTerm, UEffHam, guess_core_hamiltonian
def test_hf_cs_hf():
@@ -64,9 +64,10 @@ def test_h3_os_pbe():
check_h3_os_pbe(EDIISSCFSolver(threshold=1e-6))
-def test_vanadium_sc_hf():
- with assert_raises(NoSCFConvergence):
- check_vanadium_sc_hf(EDIISSCFSolver(threshold=1e-10, maxiter=10))
+# TODO: Move to higher level test
+# def test_vanadium_sc_hf():
+# with assert_raises(NoSCFConvergence):
+# check_vanadium_sc_hf(EDIISSCFSolver(threshold=1e-10, maxiter=10))
def test_water_cs_m05():
@@ -78,14 +79,14 @@ def test_methyl_os_tpss():
def test_interpol_hf_cs_hf():
- fn_fchk = context.get_fn('test/hf_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
-
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ fname = 'hf_sto3g_fchk'
+ mdata = load_mdata(fname)
+
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+ external = {'nn': load_nn(fname)}
terms = [
RTwoIndexTerm(kin, 'kin'),
RDirectTerm(er, 'hartree'),
@@ -95,19 +96,19 @@ def test_interpol_hf_cs_hf():
ham = REffHam(terms, external)
occ_model = AufbauOccModel(5)
- orbs = [mol.orb_alpha]
+ orbs = [load_orbs_alpha(fname)]
check_interpol_hf(ham, orbs, olp, kin, na, occ_model)
def test_interpol_lih_os_hf():
- fn_fchk = context.get_fn('test/li_h_3-21G_hf_g09.fchk')
- mol = IOData.from_file(fn_fchk)
-
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
- external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
+ fname = 'li_h_3_21G_hf_g09_fchk'
+ mdata = load_mdata(fname)
+
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
+ external = {'nn': load_nn(fname)}
terms = [
UTwoIndexTerm(kin, 'kin'),
UDirectTerm(er, 'hartree'),
@@ -117,12 +118,12 @@ def test_interpol_lih_os_hf():
ham = UEffHam(terms, external)
occ_model = AufbauOccModel(2, 1)
- orbs = [mol.orb_alpha, mol.orb_beta]
+ orbs = [load_orbs_alpha(fname), load_orbs_beta(fname)]
check_interpol_hf(ham, orbs, olp, kin, na, occ_model)
def check_interpol_hf(ham, orbs, olp, kin, na, occ_model):
- guess_core_hamiltonian(olp, kin+na, *orbs)
+ guess_core_hamiltonian(olp, kin + na, *orbs)
dms = [exp.to_dm() for exp in orbs]
scf_solver = EDIISSCFSolver(maxiter=4)
try:
@@ -139,9 +140,9 @@ def check_interpol_hf(ham, orbs, olp, kin, na, occ_model):
energies_approx = np.zeros(npt)
energies_hf = np.zeros(npt)
for ipt in xrange(npt):
- x[0] = 1-alphas[ipt]
+ x[0] = 1 - alphas[ipt]
x[1] = alphas[ipt]
- energies_approx[ipt] = np.dot(x, 0.5*np.dot(b, x)-e)
+ energies_approx[ipt] = np.dot(x, 0.5 * np.dot(b, x) - e)
# compute the hf energy
scf_solver._history._build_combinations(x, dms, None)
ham.reset(*dms)
diff --git a/horton/meanfield/test/test_scf_ediis2.py b/horton/meanfield/test/test_scf_ediis2.py
index bea7eb52..59bd1ff6 100644
--- a/horton/meanfield/test/test_scf_ediis2.py
+++ b/horton/meanfield/test/test_scf_ediis2.py
@@ -20,16 +20,13 @@
# --
-import numpy as np
-
from nose.plugins.attrib import attr
-from nose.tools import assert_raises
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.meanfield.test.common import check_hf_cs_hf, check_lih_os_hf, \
+from .common import check_hf_cs_hf, check_lih_os_hf, \
check_water_cs_hfs, check_n2_cs_hfs, check_h3_os_hfs, check_h3_os_pbe, \
- check_co_cs_pbe, check_vanadium_sc_hf, check_water_cs_m05, \
+ check_co_cs_pbe, check_water_cs_m05, \
check_methyl_os_tpss
+from .. import EDIIS2SCFSolver
def test_hf_cs_hf():
@@ -63,9 +60,10 @@ def test_h3_os_pbe():
check_h3_os_pbe(EDIIS2SCFSolver(threshold=1e-6))
-def test_vanadium_sc_hf():
- with assert_raises(NoSCFConvergence):
- check_vanadium_sc_hf(EDIIS2SCFSolver(threshold=1e-10, maxiter=10))
+# TODO: move to higher level test. Integrals too big
+# def test_vanadium_sc_hf():
+# with assert_raises(NoSCFConvergence):
+# check_vanadium_sc_hf(EDIIS2SCFSolver(threshold=1e-10, maxiter=10))
def test_water_cs_m05():
diff --git a/horton/meanfield/test/test_scf_oda.py b/horton/meanfield/test/test_scf_oda.py
index c0a170da..8c612744 100644
--- a/horton/meanfield/test/test_scf_oda.py
+++ b/horton/meanfield/test/test_scf_oda.py
@@ -21,15 +21,16 @@
import numpy as np
-
-from nose.tools import assert_raises
from nose.plugins.attrib import attr
+from nose.tools import assert_raises
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
-from horton.meanfield.test.common import check_hf_cs_hf, check_lih_os_hf, \
+from .common import check_hf_cs_hf, check_lih_os_hf, \
check_water_cs_hfs, check_n2_cs_hfs, check_h3_os_hfs, check_h3_os_pbe, \
- check_co_cs_pbe, check_vanadium_sc_hf, check_water_cs_m05, \
- check_methyl_os_tpss
+ check_co_cs_pbe, check_water_cs_m05, \
+ check_methyl_os_tpss, load_mdata, load_olp, load_kin, load_na, load_er, load_orbs_alpha, \
+ load_orbs_beta
+from .. import ODASCFSolver, AufbauSpinOccModel, UTwoIndexTerm, UDirectTerm, \
+ UExchangeTerm, UEffHam, guess_core_hamiltonian, check_dm
def test_hf_cs_hf():
@@ -64,9 +65,10 @@ def test_h3_os_pbe():
check_h3_os_pbe(ODASCFSolver(threshold=1e-6))
-def test_vanadium_sc_hf():
- with assert_raises(NoSCFConvergence):
- check_vanadium_sc_hf(ODASCFSolver(threshold=1e-10, maxiter=10))
+# TODO: Move to higher level test
+# def test_vanadium_sc_hf():
+# with assert_raises(NoSCFConvergence):
+# check_vanadium_sc_hf(ODASCFSolver(threshold=1e-10, maxiter=10))
def test_water_cs_m05():
@@ -78,7 +80,7 @@ def test_methyl_os_tpss():
def test_find_min_cubic():
- from horton.meanfield.scf_oda import find_min_cubic
+ from ..scf_oda import find_min_cubic
assert find_min_cubic(0.2, 0.5, 3.0, -0.7) == 0.0
assert abs(find_min_cubic(2.1, -5.2, -3.0, 2.8) - 0.939645667705) < 1e-8
assert abs(find_min_cubic(0.0, 1.0, -0.1, -0.1) - 0.0153883154024) < 1e-8
@@ -91,7 +93,7 @@ def test_find_min_cubic():
def test_find_min_quadratic():
- from horton.meanfield.scf_oda import find_min_quadratic
+ from ..scf_oda import find_min_quadratic
assert find_min_quadratic(0.0, -0.7) == 1.0
assert abs(find_min_quadratic(-3.0, 2.8) - 0.51724137931) < 1e-8
assert abs(find_min_quadratic(-0.2, 0.1) - 0.666666666667) < 1e-8
@@ -103,37 +105,38 @@ def test_find_min_quadratic():
def test_aufbau_spin():
- fn_fchk = context.get_fn('test/li_h_3-21G_hf_g09.fchk')
- mol = IOData.from_file(fn_fchk)
+ fname = 'li_h_3_21G_hf_g09_fchk'
+ mdata = load_mdata(fname)
occ_model = AufbauSpinOccModel(3)
- olp = mol.obasis.compute_overlap()
- kin = mol.obasis.compute_kinetic()
- na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
- er = mol.obasis.compute_electron_repulsion()
+ olp = load_olp(fname)
+ kin = load_kin(fname)
+ na = load_na(fname)
+ er = load_er(fname)
terms = [
UTwoIndexTerm(kin, 'kin'),
UDirectTerm(er, 'hartree'),
- UExchangeTerm(er,'x_hf'),
+ UExchangeTerm(er, 'x_hf'),
UTwoIndexTerm(na, 'ne'),
]
ham = UEffHam(terms)
- # Construct an initial state with instable spin polarization
- guess_core_hamiltonian(olp, kin+na, mol.orb_alpha, mol.orb_beta)
- mol.orb_alpha.occupations[:3] = 1
- mol.orb_beta.occupations[:] = 0
- dms = [mol.orb_alpha.to_dm(), mol.orb_beta.to_dm()]
+ # Construct an initial state with unstable spin polarization
+ orb_alpha = load_orbs_alpha(fname)
+ orb_beta = load_orbs_beta(fname)
+ guess_core_hamiltonian(olp, kin + na, orb_alpha, orb_beta)
+ orb_alpha.occupations[:3] = 1
+ orb_beta.occupations[:] = 0
+ dms = [orb_alpha.to_dm(), orb_beta.to_dm()]
# converge scf and check the spins
- scf_solver = ODASCFSolver(1e-6) # On some machines, 1e-8 does not work.
+ scf_solver = ODASCFSolver(1e-6) # On some machines, 1e-8 does not work.
scf_solver(ham, olp, occ_model, *dms)
assert scf_solver.error(ham, olp, *dms) < scf_solver.threshold
assert abs(np.einsum('ab,ba', olp, dms[0]) - 2) < 1e-10
assert abs(np.einsum('ab,ba', olp, dms[1]) - 1) < 1e-10
-
def test_check_dm():
# create random orthogonal vectors
v1 = np.random.uniform(1, 2, 2)
@@ -143,14 +146,14 @@ def test_check_dm():
olp = np.identity(2)
- op1 = np.dot(v*[-0.1, 0.5], v.T)
+ op1 = np.dot(v * [-0.1, 0.5], v.T)
with assert_raises(ValueError):
check_dm(op1, olp)
- op1 = np.dot(v*[0.1, 1.5], v.T)
+ op1 = np.dot(v * [0.1, 1.5], v.T)
with assert_raises(ValueError):
check_dm(op1, olp)
- op1 = np.dot(v*[-0.1, 1.5], v.T)
+ op1 = np.dot(v * [-0.1, 1.5], v.T)
with assert_raises(ValueError):
check_dm(op1, olp)
- op1 = np.dot(v*[0.1, 0.5], v.T)
+ op1 = np.dot(v * [0.1, 0.5], v.T)
check_dm(op1, olp)
diff --git a/horton/meanfield/test/test_utils.py b/horton/meanfield/test/test_utils.py
index fcebaee8..de1712ae 100644
--- a/horton/meanfield/test/test_utils.py
+++ b/horton/meanfield/test/test_utils.py
@@ -19,53 +19,58 @@
#
# --
-
import numpy as np
+from nose.plugins.skip import SkipTest
-from horton import * # pylint: disable=wildcard-import,unused-wildcard-import
+from common import load_olp, load_orbs_alpha, load_orbs_beta
+from ..moments import get_ncart_cumul, get_cartesian_powers
+from ..utils import get_spin, get_homo_lumo, get_level_shift
-def check_spin(fn_fchk, sz0, ssq0, eps):
- path_fchk = context.get_fn('test/%s' % fn_fchk)
- mol = IOData.from_file(path_fchk)
- olp = mol.obasis.compute_overlap()
- if hasattr(mol, 'orb_beta'):
- sz, ssq = get_spin(mol.orb_alpha, mol.orb_beta, olp)
+def check_spin(fname, sz0, ssq0, eps):
+ olp = load_olp(fname)
+ orb_alpha = load_orbs_alpha(fname)
+ try:
+ orb_beta = load_orbs_beta(fname)
+ sz, ssq = get_spin(orb_alpha, orb_beta, olp)
assert abs(sz - sz0) < eps
assert abs(ssq - ssq0) < eps
- sz, ssq = get_spin(mol.orb_beta, mol.orb_alpha, olp)
+ sz, ssq = get_spin(orb_beta, orb_alpha, olp)
assert abs(sz + sz0) < eps
assert abs(ssq - ssq0) < eps
- sz, ssq = get_spin(mol.orb_alpha, mol.orb_alpha, olp)
+ except IOError:
+ pass
+ sz, ssq = get_spin(orb_alpha, orb_alpha, olp)
assert abs(sz) < eps
assert abs(ssq) < eps
def test_spin_li_h():
- check_spin('li_h_3-21G_hf_g09.fchk', 0.5, 0.75, 1e-7)
+ check_spin('li_h_3_21G_hf_g09_fchk', 0.5, 0.75, 1e-7)
def test_spin_h3_hfs():
- check_spin('h3_hfs_321g.fchk', 0.5, 0.7530, 1e-4)
+ check_spin('h3_hfs_321g_fchk', 0.5, 0.7530, 1e-4)
def test_spin_h3_pbe():
- check_spin('h3_pbe_321g.fchk', 0.5, 0.7530, 1e-4)
+ check_spin('h3_pbe_321g_fchk', 0.5, 0.7530, 1e-4)
def test_spin_ch3_hf():
- check_spin('ch3_hf_sto3g.fchk', 0.5, 0.7632, 1e-4)
+ check_spin('ch3_hf_sto3g_fchk', 0.5, 0.7632, 1e-4)
def test_spin_water_hf():
- check_spin('water_sto3g_hf_g03.fchk', 0.0, 0.0, 1e-8)
+ check_spin('water_sto3g_hf_g03_fchk', 0.0, 0.0, 1e-8)
-def check_homo_lumo(fn_fchk, homo_energy0, lumo_energy0, eps=1e-8):
- mol = IOData.from_file(context.get_fn('test/%s' % fn_fchk))
- orbs = [mol.orb_alpha]
- if hasattr(mol, 'orb_beta'):
- orbs.append(mol.orb_beta)
+def check_homo_lumo(fname, homo_energy0, lumo_energy0, eps=1e-8):
+ orbs = [load_orbs_alpha(fname)]
+ try:
+ orbs.append(load_orbs_beta(fname))
+ except IOError:
+ pass
homo_energy, lumo_energy = get_homo_lumo(*orbs)
assert abs(homo_energy - homo_energy0) < eps
if lumo_energy0 is None:
@@ -75,27 +80,58 @@ def check_homo_lumo(fn_fchk, homo_energy0, lumo_energy0, eps=1e-8):
def test_homo_lumo_water_hf():
- check_homo_lumo('water_sto3g_hf_g03.fchk', -3.87671783E-01, 6.03082408E-01)
+ check_homo_lumo('water_sto3g_hf_g03_fchk', -3.87671783E-01, 6.03082408E-01)
def test_homo_lumo_ch3_hf():
- check_homo_lumo('ch3_hf_sto3g.fchk', -3.63936540E-01, 3.28562907E-01)
+ check_homo_lumo('ch3_hf_sto3g_fchk', -3.63936540E-01, 3.28562907E-01)
def test_homo_lumo_h():
- check_homo_lumo('atom_001_001_hf_sto3g.fchk', -4.66581850E-01, 3.08024094E-01)
+ check_homo_lumo('atom_001_001_hf_sto3g_fchk', -4.66581850E-01, 3.08024094E-01)
def test_homo_lumo_he():
- check_homo_lumo('helium_hf_sto3g.fchk', -8.76035508E-01, None)
+ check_homo_lumo('helium_hf_sto3g_fchk', -8.76035508E-01, None)
def test_level_shift():
- fn_fchk = context.get_fn('test/helium_hf_sto3g.fchk')
- mol = IOData.from_file(fn_fchk)
- overlap = mol.obasis.compute_overlap()
- dm_alpha1 = mol.orb_alpha.to_dm()
+ fname = 'helium_hf_sto3g_fchk'
+ overlap = load_olp(fname)
+ dm_alpha1 = load_orbs_alpha(fname).to_dm()
ls_alpha = get_level_shift(dm_alpha1, overlap)
- mol.orb_alpha.from_fock(ls_alpha, overlap)
- dm_alpha2 = mol.orb_alpha.to_dm()
+ load_orbs_alpha(fname).from_fock(ls_alpha, overlap)
+ dm_alpha2 = load_orbs_alpha(fname).to_dm()
np.testing.assert_allclose(dm_alpha1, dm_alpha2)
+
+
+def test_get_ncart_cumul():
+ assert get_ncart_cumul(0) == 1
+ assert get_ncart_cumul(1) == 4
+ assert get_ncart_cumul(2) == 10
+ assert get_ncart_cumul(3) == 20
+
+
+def test_get_cartesian_powers():
+ lmax = 4
+ cartesian_powers = get_cartesian_powers(lmax)
+ assert issubclass(cartesian_powers.dtype.type, int)
+ assert cartesian_powers.shape == (get_ncart_cumul(lmax), 3)
+ assert (cartesian_powers[0] == [0, 0, 0]).all()
+ assert (cartesian_powers[1] == [1, 0, 0]).all()
+ assert (cartesian_powers[4] == [2, 0, 0]).all()
+ assert (cartesian_powers[5] == [1, 1, 0]).all()
+ assert (cartesian_powers[6] == [1, 0, 1]).all()
+ assert (cartesian_powers[10] == [3, 0, 0]).all()
+ assert (cartesian_powers[11] == [2, 1, 0]).all()
+ assert (cartesian_powers[19] == [0, 0, 3]).all()
+ assert (cartesian_powers[-1] == [0, 0, 4]).all()
+
+ for lmax in xrange(4):
+ tmp = get_cartesian_powers(lmax)
+ assert tmp.shape == (get_ncart_cumul(lmax), 3)
+ assert (tmp == cartesian_powers[:len(tmp)]).all()
+
+
+def test_rotate_cartesian_moments():
+ raise SkipTest("Need a rotate cartesian moment test")
diff --git a/horton/meanfield/utils.py b/horton/meanfield/utils.py
index 786f7ccf..04893f30 100644
--- a/horton/meanfield/utils.py
+++ b/horton/meanfield/utils.py
@@ -20,50 +20,18 @@
# --
"""Utility functions"""
-
import numpy as np
-from horton.meanfield.orbitals import Orbitals
-
-
__all__ = [
- 'check_dm', 'get_level_shift', 'get_spin', 'get_homo_lumo',
+ 'get_level_shift', 'get_spin', 'get_homo_lumo',
'compute_commutator',
]
-
-def check_dm(dm, overlap, eps=1e-4, occ_max=1.0):
- '''Check if the density matrix has eigenvalues in the proper range.
-
- Parameters
- ----------
- dm : np.ndarray, shape=(nbasis, nbasis), dtype=float
- The density matrix
- overlap : np.ndarray, shape=(nbasis, nbasis), dtype=float
- The overlap matrix
- eps : float
- The threshold on the eigenvalue inequalities.
- occ_max : float
- The maximum occupation.
-
- Raises
- ------
- ValueError
- When the density matrix has wrong eigenvalues.
- '''
- # construct natural orbitals
- orb = Orbitals(dm.shape[0])
- orb.derive_naturals(dm, overlap)
- if orb.occupations.min() < -eps:
- raise ValueError('The density matrix has eigenvalues considerably smaller than '
- 'zero. error=%e' % (orb.occupations.min()))
- if orb.occupations.max() > occ_max+eps:
- raise ValueError('The density matrix has eigenvalues considerably larger than '
- 'max. error=%e' % (orb.occupations.max()-1))
+boltzmann = 3.1668154051341965e-06
def get_level_shift(dm, overlap):
- '''Construct a level shift operator.
+ """Construct a level shift operator.
**Arguments:**
@@ -74,12 +42,12 @@ def get_level_shift(dm, overlap):
The overlap matrix
**Returns:** The level-shift operator.
- '''
+ """
return np.dot(overlap.T, np.dot(dm, overlap))
def get_spin(orb_alpha, orb_beta, overlap):
- '''Returns the expectation values of the projected and squared spin
+ """Returns the expectation values of the projected and squared spin
**Arguments:**
@@ -90,10 +58,10 @@ def get_spin(orb_alpha, orb_beta, overlap):
The overlap matrix
**Returns:** sz, ssq
- '''
+ """
nalpha = orb_alpha.occupations.sum()
nbeta = orb_beta.occupations.sum()
- sz = (nalpha - nbeta)/2
+ sz = (nalpha - nbeta) / 2
correction = 0.0
for ialpha in xrange(orb_alpha.nfn):
if orb_alpha.occupations[ialpha] == 0.0:
@@ -102,16 +70,16 @@ def get_spin(orb_alpha, orb_beta, overlap):
if orb_beta.occupations[ibeta] == 0.0:
continue
correction += np.dot(
- orb_alpha.coeffs[:,ialpha],
- np.dot(overlap, orb_beta.coeffs[:,ibeta]))**2
+ orb_alpha.coeffs[:, ialpha],
+ np.dot(overlap, orb_beta.coeffs[:, ibeta])) ** 2
- ssq = sz*(sz+1) + nbeta - correction
+ ssq = sz * (sz + 1) + nbeta - correction
print sz, ssq
return sz, ssq
def get_homo_lumo(*orbs):
- '''Return the HOMO and LUMO energy for the given expansion
+ """Return the HOMO and LUMO energy for the given expansion
**Arguments:**
@@ -120,7 +88,7 @@ def get_homo_lumo(*orbs):
**Returns:** homo_energy, lumo_energy. (The second is None when all
orbitals are occupied.)
- '''
+ """
homo_energy = max(orb.homo_energy for orb in orbs)
lumo_energies = [orb.lumo_energy for orb in orbs]
lumo_energies = [lumo_energy for lumo_energy in lumo_energies if lumo_energy is not None]
@@ -132,7 +100,7 @@ def get_homo_lumo(*orbs):
def compute_commutator(dm, fock, overlap):
- '''Compute the dm-fock commutator, including an overlap matrix
+ """Compute the dm-fock commutator, including an overlap matrix
Parameters
----------
@@ -146,5 +114,78 @@ def compute_commutator(dm, fock, overlap):
Return
------
commutator
- '''
+ """
return np.dot(overlap, np.dot(dm, fock)) - np.dot(fock, np.dot(dm, overlap))
+
+
+def doc_inherit(base_class):
+ """Docstring inheriting method descriptor
+
+ doc_inherit decorator
+
+ Usage:
+
+ .. code-block:: python
+
+ class Foo(object):
+ def foo(self):
+ "Frobber"
+ pass
+
+ class Bar(Foo):
+ @doc_inherit(Foo)
+ def foo(self):
+ pass
+
+ Now, ``Bar.foo.__doc__ == Bar().foo.__doc__ == Foo.foo.__doc__ ==
+ "Frobber"``
+ """
+
+ def decorator(method):
+ overridden = getattr(base_class, method.__name__, None)
+ if overridden is None:
+ raise NameError('Can\'t find method \'%s\' in base class.')
+ method.__doc__ = overridden.__doc__
+ return method
+
+ return decorator
+
+
+def check_type(name, instance, *Classes):
+ """Check type of argument with given name against list of types
+
+ **Arguments:**
+
+ name
+ The name of the argument being checked.
+
+ instance
+ The object being checked.
+
+ Classes
+ A list of allowed types.
+ """
+ if len(Classes) == 0:
+ raise TypeError('Type checking with an empty list of classes. This is a simple bug!')
+ match = False
+ for Class in Classes:
+ if isinstance(instance, Class):
+ match = True
+ break
+ if not match:
+ classes_parts = ['\'', Classes[0].__name__, '\'']
+ for Class in Classes[1:-1]:
+ classes_parts.extend([', ``', Class.__name__, '\''])
+ if len(Classes) > 1:
+ classes_parts.extend(['or \'', Class.__name__, '\''])
+ raise TypeError('The argument \'%s\' must be an instance of %s. Got a \'%s\' instance instead.' % (
+ name, ''.join(classes_parts), instance.__class__.__name__
+ ))
+
+
+def fac2(n):
+ result = 1
+ while n > 1:
+ result *= n
+ n -= 2
+ return result
diff --git a/horton/part/base.py b/horton/part/base.py
index 92635413..3aae2074 100644
--- a/horton/part/base.py
+++ b/horton/part/base.py
@@ -23,13 +23,12 @@
import numpy as np
-from horton.cache import JustOnceClass, just_once, Cache
+from horton.grid.atgrid import AtomicGrid
+from horton.grid.poisson import solve_poisson_becke
from horton.log import log
+from horton.meanfield.cache import JustOnceClass, just_once, Cache
from horton.moments import get_ncart_cumul, get_npure_cumul
from horton.utils import typecheck_geo
-from horton.grid.atgrid import AtomicGrid
-from horton.grid.poisson import solve_poisson_becke
-
__all__ = ['Part', 'WPart']
diff --git a/horton/part/hirshfeld.py b/horton/part/hirshfeld.py
index f89d4d11..380dd5cc 100644
--- a/horton/part/hirshfeld.py
+++ b/horton/part/hirshfeld.py
@@ -21,11 +21,10 @@
'''Hirshfeld partitioning'''
-from horton.cache import just_once
from horton.log import log, biblio
+from horton.meanfield.cache import just_once
from horton.part.stockholder import StockholderWPart
-
__all__ = ['HirshfeldWPart']
diff --git a/horton/part/iterstock.py b/horton/part/iterstock.py
index ad11cbe8..34e71220 100644
--- a/horton/part/iterstock.py
+++ b/horton/part/iterstock.py
@@ -22,11 +22,11 @@
import numpy as np
-from horton.cache import just_once
+
from horton.log import log, biblio
+from horton.meanfield.cache import just_once
from horton.part.stockholder import StockholderWPart
-
__all__ = ['IterativeProatomMixin', 'IterativeStockholderWPart']