def test_global_linear_nn_reactivity(): # E(N) = 0.0 - 0.7 * N, N <= 5 # E(N) = -1.5 - 0.4 * N, N >= 5 # build global tool model = LinearGlobalTool({5: -3.5, 6: -3.9, 4: -2.8}) # check ionization potential and electron affinity assert_almost_equal(model.ip, 0.7) assert_almost_equal(model.ea, 0.4) assert_almost_equal(model.ionization_potential, 0.7) assert_almost_equal(model.electron_affinity, 0.4) # check fundamental descriptors assert_almost_equal(model.mu_minus, -0.7) assert_almost_equal(model.mu_plus, -0.4) assert_almost_equal(model.mu_zero, -0.55) assert_equal(model.mu, None) assert_equal(model.chemical_potential, None) assert_equal(model.eta, None) assert_equal(model.chemical_hardness, None) assert_equal(model.hyper_hardness(2), None) assert_equal(model.hyper_hardness(3), None) assert_equal(model.hyper_hardness(4), None) # check derived descriptors assert_equal(model.electronegativity, None) assert_equal(model.electrofugality, None) assert_equal(model.electrophilicity, None) assert_equal(model.nucleofugality, None)
def test_global_linear_nn_grand_potential_reactivity(): # E(N) = 0.0 - 0.7 * N, N <= 5 # E(N) = -1.5 - 0.4 * N, N >= 5 # build global tool model = LinearGlobalTool({5: -3.5, 6: -3.9, 4: -2.8}) # check fundamental descriptors assert_equal(model.softness, None) assert_equal(model.hyper_softness(2), None) assert_equal(model.hyper_softness(3), None) assert_equal(model.hyper_softness(4), None) assert_equal(model.hyper_softness(8), None)
def test_global_linear_np_grand_potential_reactivity(): # E(N) = -1.0 - 0.5 * N, N <= 10 # E(N) = -7.0 + 0.1 * N, N >= 10 # build global tool model = LinearGlobalTool({10: -6.0, 11: -5.9, 9: -5.5}) # check fundamental descriptors assert_equal(model.softness, None) assert_equal(model.hyper_softness(2), None) assert_equal(model.hyper_softness(3), None) assert_equal(model.hyper_softness(4), None) assert_equal(model.hyper_softness(10), None)
def test_global_linear_raises(): # check invalid N0 assert_raises(ValueError, LinearGlobalTool, { 0.: -10.0, 1.: -15.0, -1.: -16.0 }) assert_raises(ValueError, LinearGlobalTool, { 0.5: -10.0, 1.5: -15.0, -0.5: -16.0 }) assert_raises(ValueError, LinearGlobalTool, { 0.9: -10.0, 1.9: -15.0, -0.1: -16.0 }) assert_raises(ValueError, LinearGlobalTool, { -5.0: -10.0, -4.0: -15.0, -6.0: -16.0 }) assert_raises(ValueError, LinearGlobalTool, { 0.9: 10.0, 0.5: 15.0, 1.2: 16.0 }) assert_raises(ValueError, LinearGlobalTool, { 1.0: 10.0, 0.5: 15.0, 1.5: 16.0 }) # check invalid N model = LinearGlobalTool({5.: -10.5, 6.: -11.7, 4.: -12.3}) assert_raises(ValueError, model.energy, -1.0) assert_raises(ValueError, model.energy, -2.3) assert_raises(ValueError, model.energy_derivative, -0.5, 1) assert_raises(ValueError, model.energy_derivative, -1.9, 2) # check invalid derivative order assert_raises(ValueError, model.energy_derivative, 0.5, 1.) assert_raises(ValueError, model.energy_derivative, 0.5, 0.2) assert_raises(ValueError, model.energy_derivative, 0.5, -1) assert_raises(ValueError, model.energy_derivative, 0.5, -3) assert_raises(ValueError, model.energy_derivative, 0.5, '1') assert_raises(ValueError, model.energy_derivative, 0.5, [1])
def test_global_linear_np_reactivity(): # E(N) = -1.0 - 0.5 * N, N <= 10 # E(N) = -7.0 + 0.1 * N, N >= 10 # build global tool model = LinearGlobalTool({10: -6.0, 11: -5.9, 9: -5.5}) # check ionization potential and electron affinity assert_almost_equal(model.ip, 0.5) assert_almost_equal(model.ea, -0.1) assert_almost_equal(model.ionization_potential, 0.5) assert_almost_equal(model.electron_affinity, -0.1) # check fundamental descriptors assert_almost_equal(model.mu_minus, -0.5) assert_almost_equal(model.mu_plus, 0.1) assert_almost_equal(model.mu_zero, -0.2) assert_equal(model.mu, None) assert_equal(model.chemical_potential, None) assert_equal(model.eta, None) assert_equal(model.chemical_hardness, None) assert_equal(model.electronegativity, None) # check derived descriptors assert_almost_equal(model.electrofugality, 0.5, decimal=6) assert_almost_equal(model.electrophilicity, 0.0, decimal=6) assert_almost_equal(model.nucleofugality, 0.1, decimal=6)
def test_global_linear_np_energy(): # E(N) = -1.0 - 0.5 * N, N <= 10 # E(N) = -7.0 + 0.1 * N, N >= 10 # build global tool model = LinearGlobalTool({10: -6.0, 11: -5.9, 9: -5.5}) # check parameters assert_equal(model.n0, 10) assert_equal(model.n_max, 10) # check E(N) assert_almost_equal(model.energy(10.), -6.0, decimal=6) assert_almost_equal(model.energy(11), -5.9, decimal=6) assert_almost_equal(model.energy(9.), -5.5, decimal=6) assert_almost_equal(model.energy(8.5), -5.25, decimal=6) assert_almost_equal(model.energy(11.2), -5.88, decimal=6) assert_almost_equal(model.energy(13.56), -5.644, decimal=6) assert_almost_equal(model.energy(5.01), -3.505, decimal=6) assert_almost_equal(model.energy(0), -1.0, decimal=6) assert_almost_equal(model.energy(model.n_max), -6.0, decimal=6) # check dE(N) assert_equal(model.energy_derivative(10.0, 1), None) assert_almost_equal(model.energy_derivative(9.0, 1), -0.5, decimal=6) assert_almost_equal(model.energy_derivative(7.25, 1), -0.5, decimal=6) assert_almost_equal(model.energy_derivative(11., 1), 0.1, decimal=6) assert_almost_equal(model.energy_derivative(10.45, 1), 0.1, decimal=6) # check d^nE(N) for n > 1 assert_equal(model.energy_derivative(10.0, 2), None) assert_equal(model.energy_derivative(9.5, 2), 0.) assert_equal(model.energy_derivative(10.9, 2), 0.) assert_equal(model.energy_derivative(10.0, 3), None) assert_equal(model.energy_derivative(8.9, 2), 0.) assert_equal(model.energy_derivative(11.3, 2), 0.)
def test_global_linear_nn_grand_potential_n(): # E(N) = 0.0 - 0.7 * N, N <= 5 # E(N) = -1.5 - 0.4 * N, N >= 5 # build global tool model = LinearGlobalTool({5: -3.5, 6: -3.9, 4: -2.8}) # check grand potential (as a function of N) assert_equal(model.grand_potential(None), None) assert_equal(model.grand_potential(5.), None) assert_almost_equal(model.grand_potential(5.1), -1.5, decimal=6) assert_almost_equal(model.grand_potential(6.0), -1.5, decimal=6) assert_almost_equal(model.grand_potential(4.1), 0.0, decimal=6) assert_almost_equal(model.grand_potential(3.9), 0.0, decimal=6) # check derivative of grand potential assert_almost_equal(model.grand_potential_derivative(5.0, 1), -5.0, decimal=6) assert_almost_equal(model.grand_potential_derivative(6.0, 1), -6.0, decimal=6) assert_almost_equal(model.grand_potential_derivative(4.0, 1), -4.0, decimal=6) assert_almost_equal(model.grand_potential_derivative(5.6, 1), -5.6, decimal=6) assert_almost_equal(model.grand_potential_derivative(3.3, 1), -3.3, decimal=6) assert_equal(model.grand_potential_derivative(5., 2), None) assert_equal(model.grand_potential_derivative(4., 3), None) assert_equal(model.grand_potential_derivative(5., 4), None) assert_equal(model.grand_potential_derivative(5.7, 5), None) assert_equal(model.grand_potential_derivative(4.2, 3), None) assert_equal(model.grand_potential_derivative(6.3, 2), None) assert_equal(model.grand_potential_derivative(3.6, 3), None) assert_equal(model.grand_potential_derivative(0.0, 4), None) assert_equal(model.grand_potential_derivative(None, 10), None)
def test_global_linear_nn_energy(): # E(N) = 0.0 - 0.7 * N, N <= 5 # E(N) = -1.5 - 0.4 * N, N >= 5 # build global tool model = LinearGlobalTool({5: -3.5, 6: -3.9, 4: -2.8}) # check parameters assert_equal(model.n0, 5.) assert_equal(model.n_max, None) # check E(N) assert_almost_equal(model.energy(5), -3.5, decimal=6) assert_almost_equal(model.energy(6), -3.9, decimal=6) assert_almost_equal(model.energy(4), -2.8, decimal=6) assert_almost_equal(model.energy(0.), 0.0, decimal=6) assert_almost_equal(model.energy(3.5), -2.45, decimal=6) assert_almost_equal(model.energy(5.7), -3.78, decimal=6) # check dE(N) assert_equal(model.energy_derivative(5., 1), None) assert_almost_equal(model.energy_derivative(4., 1), -0.7, decimal=6) assert_almost_equal(model.energy_derivative(6., 1), -0.4, decimal=6) assert_almost_equal(model.energy_derivative(4.99, 1), -0.7, decimal=6) assert_almost_equal(model.energy_derivative(5.01, 1), -0.4, decimal=6) # check d^nE(N) for n > 1 assert_equal(model.energy_derivative(5.0, 2), None) assert_equal(model.energy_derivative(4.5, 2), 0.) assert_equal(model.energy_derivative(3.9, 2), 0.) assert_equal(model.energy_derivative(5.0, 3), None) assert_equal(model.energy_derivative(6.1, 2), 0.) assert_equal(model.energy_derivative(7.0, 2), 0.)
def test_global_linear_np_grand_potential_n(): # E(N) = -1.0 - 0.5 * N, N <= 10 # E(N) = -7.0 + 0.1 * N, N >= 10 # build global tool model = LinearGlobalTool({10: -6.0, 11: -5.9, 9: -5.5}) # check grand potential (as a function of N) assert_equal(model.grand_potential(None), None) assert_equal(model.grand_potential(10.), None) assert_almost_equal(model.grand_potential(9.), -1.0, decimal=6) assert_almost_equal(model.grand_potential(6.3), -1.0, decimal=6) assert_almost_equal(model.grand_potential(11.), -7.0, decimal=6) assert_almost_equal(model.grand_potential(10.1), -7.0, decimal=6) # check grand potential derivative (as a function of N) assert_almost_equal(model.grand_potential_derivative(9.3, 1), -9.3, decimal=6) assert_almost_equal(model.grand_potential_derivative(10.0, 1), -10., decimal=6) assert_almost_equal(model.grand_potential_derivative(11.2, 1), -11.2, decimal=6) assert_almost_equal(model.grand_potential_derivative(10.7, 1), -10.7, decimal=6) assert_equal(model.grand_potential_derivative(10., 2), None) assert_equal(model.grand_potential_derivative(10., 3), None) assert_equal(model.grand_potential_derivative(10., 4), None) assert_equal(model.grand_potential_derivative(9.3, 2), None) assert_equal(model.grand_potential_derivative(8.2, 3), None) assert_equal(model.grand_potential_derivative(6.1, 4), None) assert_equal(model.grand_potential_derivative(9.8, 5), None) assert_equal(model.grand_potential_derivative(10.1, 10), None) assert_equal(model.grand_potential_derivative(11.5, 2), None) assert_equal(model.grand_potential_derivative(12.9, 3), None) assert_equal(model.grand_potential_derivative(0.0, 4), None) assert_equal(model.grand_potential_derivative(None, 10), None)