Ejemplo n.º 1
0
def test_epi(direction, cartesian):
  from numpy import abs
  from pylada.vff.functional import Functional

  vff = functional()
  vff.cartesian = cartesian
  vff.direction = direction
  structure = crystal()
  
  # gets functions for current structure
  x, jacobian, energy, make_structure                                          \
       = Functional(copy=vff)._getfuncs_epi(structure)
  stress, forces = vff.jacobian(structure)

  jac0 = jacobian(x)
  epsilon = 1e-7
  for i in xrange(0, len(x)):
    xminus = x.copy()
    xminus[i] = xminus[i] - epsilon * 0.5
    eminus = energy(xminus)
    xplus = x.copy()
    xplus[i] = xplus[i] + epsilon * 0.5
    eplus = energy(xplus)

    assert abs(jac0[i] - (eplus - eminus) / epsilon ) < 1e-6
Ejemplo n.º 2
0
def test_relaxall(cartesian):
    """ Tests gradients as implemented in the functional. """
    from numpy import abs
    from pylada.vff.functional import Functional

    vff = functional()
    vff.cartesian = cartesian
    structure = crystal()
    epsilon = 1e-5

    # gets functions for current structure
    x, jacobian, energy, make_structure = Functional(copy=vff)._getfuncs_relaxall(structure)
    stress, forces = vff.jacobian(structure)

    jac0 = jacobian(x)
    for i in xrange(6):
        xminus = x.copy()
        xminus[i] = xminus[i] - epsilon * 0.5
        eminus = energy(xminus)
        xplus = x.copy()
        xplus[i] = xplus[i] + epsilon * 0.5
        eplus = energy(xplus)

        assert abs(jac0[i] - (eplus - eminus) / epsilon) < 1e-6

    epsilon = 1e-7
    for i in xrange(6, len(x)):
        xminus = x.copy()
        xminus[i] = xminus[i] - epsilon * 0.5
        eminus = energy(xminus)
        xplus = x.copy()
        xplus[i] = xplus[i] + epsilon * 0.5
        eplus = energy(xplus)

        assert abs(jac0[i] - (eplus - eminus) / epsilon) < 1e-6