Exemplo n.º 1
0
def test_global_quadratic_pnp_energy():
    # E(N) = 30.0 + (-6.0)*N + 3*N^2, N0=10
    energy, deriv, _ = make_symbolic_quadratic_model(3.0, -6.0, 30.0)
    # build global tool
    model = QuadraticGlobalTool({5: 75.0, 6: 102.0, 4: 54.0})
    # check parameters
    assert_almost_equal(model.params[0], 30.0, decimal=6)
    assert_almost_equal(model.params[1], -6.0, decimal=6)
    assert_almost_equal(model.params[2], 3.0, decimal=6)
    assert_almost_equal(model.n0, 5, decimal=6)
    assert_almost_equal(model.n_max, 1, decimal=6)
    # check E(N)
    assert_almost_equal(model.energy(20), energy(20), decimal=6)
    assert_almost_equal(model.energy(10), energy(10), decimal=6)
    assert_almost_equal(model.energy(16.5), energy(16.5), decimal=6)
    # check dE(N)
    assert_almost_equal(model.energy_derivative(20), deriv(20), decimal=6)
    assert_almost_equal(model.energy_derivative(10), deriv(10), decimal=6)
    assert_almost_equal(model.energy_derivative(16.5), deriv(16.5), decimal=6)
    # check d2E(N)
    assert_almost_equal(model.energy_derivative(20, 2), 6.0, decimal=6)
    assert_almost_equal(model.energy_derivative(10, 2), 6.0, decimal=6)
    assert_almost_equal(model.energy_derivative(16.5, 2), 6.0, decimal=6)
    # check d^nE(N) for n > 2
    assert_almost_equal(model.energy_derivative(20, 3), 0.0, decimal=6)
    assert_almost_equal(model.energy_derivative(10, 4), 0.0, decimal=6)
    assert_almost_equal(model.energy_derivative(16.5, 5), 0.0, decimal=6)
Exemplo n.º 2
0
def test_global_quadratic_n0p_energy():
    # E(N) = -100 + 5*N^2, N0=5
    energy, deriv, _ = make_symbolic_quadratic_model(5.0, 0., -100.)
    # build global tool
    model = QuadraticGlobalTool({5: 25.0, 6: 80.0, 4: -20.0})
    # check parameters
    assert_almost_equal(model.params[0], -100.0, decimal=6)
    assert_almost_equal(model.params[1], 0.0, decimal=6)
    assert_almost_equal(model.params[2], 5.0, decimal=6)
    assert_almost_equal(model.n0, 5, decimal=6)
    assert_almost_equal(model.n_max, 0.0, decimal=6)
    # check E(N)
    assert_almost_equal(model.energy(20), energy(20), decimal=6)
    assert_almost_equal(model.energy(10), energy(10), decimal=6)
    assert_almost_equal(model.energy(16.5), energy(16.5), decimal=6)
    # check dE(N)
    assert_almost_equal(model.energy_derivative(20), deriv(20), decimal=6)
    assert_almost_equal(model.energy_derivative(10), deriv(10), decimal=6)
    assert_almost_equal(model.energy_derivative(16.5), deriv(16.5), decimal=6)
    # check d2E(N)
    assert_almost_equal(model.energy_derivative(20, 2), 10.0, decimal=6)
    assert_almost_equal(model.energy_derivative(10, 2), 10.0, decimal=6)
    assert_almost_equal(model.energy_derivative(16.5, 2), 10.0, decimal=6)
    # check d^nE(N) for n > 2
    assert_almost_equal(model.energy_derivative(20, 3), 0.0, decimal=6)
    assert_almost_equal(model.energy_derivative(10, 4), 0.0, decimal=6)
    assert_almost_equal(model.energy_derivative(16.5, 5), 0.0, decimal=6)
Exemplo n.º 3
0
def test_global_quadratic_nnp_energy():
    # E(N) = -9.0 + (-25.0)*N + N^2, N0=15
    energy, deriv, _ = make_symbolic_quadratic_model(1.0, -25.0, -9.0)
    # build global tool
    model = QuadraticGlobalTool({15: -159.0, 16: -153.0, 14: -163.0})
    # check parameters
    assert_almost_equal(model.params[0], -9.0, decimal=6)
    assert_almost_equal(model.params[1], -25.0, decimal=6)
    assert_almost_equal(model.params[2], 1.0, decimal=6)
    assert_almost_equal(model.n0, 15, decimal=6)
    assert_almost_equal(model.n_max, 12.5, decimal=6)
    # check E(N)
    assert_almost_equal(model.energy(20), energy(20), decimal=6)
    assert_almost_equal(model.energy(10), energy(10), decimal=6)
    assert_almost_equal(model.energy(16.5), energy(16.5), decimal=6)
    # check dE(N)
    assert_almost_equal(model.energy_derivative(20), deriv(20), decimal=6)
    assert_almost_equal(model.energy_derivative(10), deriv(10), decimal=6)
    assert_almost_equal(model.energy_derivative(16.5), deriv(16.5), decimal=6)
    # check d2E(N)
    assert_almost_equal(model.energy_derivative(20, 2), 2.0, decimal=6)
    assert_almost_equal(model.energy_derivative(10, 2), 2.0, decimal=6)
    assert_almost_equal(model.energy_derivative(16.5, 2), 2.0, decimal=6)
    # check d^nE(N) for n > 2
    assert_almost_equal(model.energy_derivative(20, 3), 0.0, decimal=6)
    assert_almost_equal(model.energy_derivative(10, 4), 0.0, decimal=6)
    assert_almost_equal(model.energy_derivative(16.5, 5), 0.0, decimal=6)