Exemple #1
0
 def check_delta(self, x=None, eps=1e-4, zero=None):
     """Test the analytical derivatives"""
     if x is None:
         x = self.x0
     dxs = np.random.uniform(-eps, eps, (100, len(x)))
     if zero is not None:
         dxs[:,zero] = 0.0
     check_delta(self.fun, x, dxs)
Exemple #2
0
 def check_delta(self, x=None, eps=1e-4, zero=None):
     """Test the analytical derivatives"""
     if x is None:
         x = self.x0
     dxs = np.random.uniform(-eps, eps, (100, len(x)))
     if zero is not None:
         dxs[:, zero] = 0.0
     check_delta(self.fun, x, dxs)
Exemple #3
0
def test_switch3_deriv():
    rcut = 10.0
    for width in 1.0, 2.0, 4.0:
        tr = Switch3(width)

        def fn(x, do_gradient):
            value, gradient = tr.trunc_fn(x[0], rcut)
            if do_gradient:
                return value, np.array([gradient])
            else:
                return value

        for d in 5.0, 9.5:
            x0 = np.array([d])
            dxs = np.random.normal(0, 1e-4, 100)
            check_delta(fn, x0, dxs)
Exemple #4
0
def test_hammer_deriv():
    rcut = 10.0
    for tau in 0.5, 1.0, 2.0:
        tr = Hammer(tau)

        def fn(x, do_gradient):
            value, gradient = tr.trunc_fn(x[0], rcut)
            if do_gradient:
                return value, np.array([gradient])
            else:
                return value

        for d in 5.0, 9.0, 9.9:
            x0 = np.array([d])
            dxs = np.random.normal(0, 1e-4, 100)
            check_delta(fn, x0, dxs)
Exemple #5
0
def check_cell_jacobian(ff, DOFClass, kwargs):
    kwargs['do_frozen'] = True
    dof = DOFClass(ff, **kwargs)

    def fun(celldofs, do_gradient=False):
        rvecs = dof._cellvars_to_rvecs(dof._expand_celldofs(celldofs))
        if do_gradient:
            dof._update(celldofs)
            return rvecs.ravel(), dof._get_celldofs_jacobian(celldofs)
        else:
            return rvecs.ravel()

    x = dof._reduce_cellvars(dof.cellvars0)
    eps = 1e-5
    dxs = np.random.uniform(-eps, eps, (100, len(x)))
    check_delta(fun, x, dxs)
Exemple #6
0
def check_cell_jacobian(ff, DOFClass, kwargs):
    kwargs['do_frozen'] = True
    dof = DOFClass(ff, **kwargs)

    def fun(celldofs, do_gradient=False):
        rvecs = dof._cellvars_to_rvecs(dof._expand_celldofs(celldofs))
        if do_gradient:
            dof._update(celldofs)
            return rvecs.ravel(), dof._get_celldofs_jacobian(celldofs)
        else:
            return rvecs.ravel()

    x = dof._reduce_cellvars(dof.cellvars0)
    eps = 1e-5
    dxs = np.random.uniform(-eps, eps, (100, len(x)))
    check_delta(fun, x, dxs)
Exemple #7
0
def test_switch3_deriv():
    rcut = 10.0
    for width in 1.0, 2.0, 4.0:
        tr = Switch3(width)

        def fn(x, do_gradient):
            value, gradient = tr.trunc_fn(x[0], rcut)
            if do_gradient:
                return value, np.array([gradient])
            else:
                return value

        for d in 5.0, 9.5:
            x0 = np.array([d])
            dxs = np.random.normal(0, 1e-4, 100)
            check_delta(fn, x0, dxs)
Exemple #8
0
def test_hammer_deriv():
    rcut = 10.0
    for tau in 0.5, 1.0, 2.0:
        tr = Hammer(tau)

        def fn(x, do_gradient):
            value, gradient = tr.trunc_fn(x[0], rcut)
            if do_gradient:
                return value, np.array([gradient])
            else:
                return value

        for d in 5.0, 9.0, 9.9:
            x0 = np.array([d])
            dxs = np.random.normal(0, 1e-4, 100)
            check_delta(fn, x0, dxs)