Exemplo n.º 1
0
def test_average():
    structure = Structure(symbols=['C', 'O'], positions=[(0, 0, 0), (0.5, 0, 0)], unitcell=5)
    structure.repeat(5)

    four = Fourier()
    four.grid.bins = [2, 21]
    four.grid.set_corners(lr=[4.0, 0.0, 0.0],
                          ul=[0.0, 2.0, 0.0])
    four.structure = structure
    four._average = True
    results = four.calc()

    expected_result = [1.32348898e-23, 5.71594728e-24, 8.12875148e-56,
                       8.37681929e-25, 6.37686377e-56, 5.46068451e-25,
                       2.54939667e-55, 8.37681929e-25, 7.16891360e-55,
                       5.21188409e-24, 1.32348898e-23, 5.71594728e-24,
                       3.46656800e-54, 8.37681929e-25, 5.74150325e-55,
                       5.46068451e-25, 2.74171118e-55, 8.37681929e-25,
                       1.00428514e-54, 5.21188409e-24, 1.32348898e-23]
    assert_array_almost_equal(results[0, :, 0], expected_result)

    # Random move
    structure.rattle(seed=0)
    results = four.calc()

    expected_result = [1.32348898e-23, 8.88939203e-04, 7.27741076e-03,
                       1.91258313e-02, 5.94954973e-02, 1.26500450e-01,
                       1.34462469e-01, 1.04512735e-01, 1.17228978e-01,
                       7.24444566e-02, 5.87435134e-26, 1.06907925e-01,
                       2.60217008e-01, 3.57817285e-01, 7.25525103e-01,
                       1.13842501e+00, 9.60372378e-01, 6.18668588e-01,
                       5.97492048e-01, 3.24844518e-01, 2.34454638e-25]
    assert_array_almost_equal(results[0, :, 0], expected_result)
Exemplo n.º 2
0
def test_lots():
    import numpy as np
    np.random.seed(42)  # Make random lot selection not random

    structure = Structure(symbols=['C', 'O'], positions=[(0, 0, 0), (0.5, 0, 0)], unitcell=5)
    structure.repeat(5)

    four = Fourier()
    four.grid.bins = [2, 21]
    four.grid.set_corners(lr=[4.0, 0.0, 0.0],
                          ul=[0.0, 2.0, 0.0])
    four.structure = structure
    four.lots = None
    results = four.calc()

    expected_result = [2.42323706e+06, 1.01505872e+06, 1.46887112e-26,
                       1.48095071e+05, 1.16378024e-26, 9.69294822e+04,
                       5.01755975e-26, 1.48095071e+05, 1.35809407e-25,
                       1.01505872e+06, 2.42323706e+06, 1.01505872e+06,
                       6.70205900e-25, 1.48095071e+05, 1.03080955e-25,
                       9.69294822e+04, 5.35400081e-26, 1.48095071e+05,
                       1.77832044e-25, 1.01505872e+06, 2.42323706e+06]
    assert_allclose(results[0, :, 0], expected_result, atol=1e-25)

    four.lots = 3, 3, 3
    four.number_of_lots = 3
    results = four.calc()

    expected_result = [339175.64420172,  202125.69466616,   98663.70718625,
                       61677.5841574,   14394.84088099,   37686.18268908,
                       14394.84088099,   61677.5841574,   98663.70718625,
                       202125.69466616,  339175.64420172,  202125.69466616,
                       98663.70718625,   61677.5841574,   14394.84088099,
                       37686.18268908,   14394.84088099,   61677.5841574,
                       98663.70718625,  202125.69466616,  339175.64420172]
    assert_allclose(results[0, :, 0], expected_result)

    # Random move + average subtraction
    structure.rattle(seed=0)
    four._average = True
    results = four.calc()

    expected_result = [1.63820535e-24, 2.55360350e+05, 2.83431155e+05,
                       5.87063567e+04, 3.06182580e+04, 6.47880007e-03,
                       3.06274940e+04, 5.87242408e+04, 2.83411515e+05,
                       2.55140706e+05, 3.20451398e-01, 2.55556564e+05,
                       2.83427875e+05, 5.86850273e+04, 3.06047773e+04,
                       5.83516439e-02, 3.06324860e+04, 5.87386761e+04,
                       2.83368966e+05, 2.54897708e+05, 1.28156664e+00]
    assert_allclose(results[0, :, 0], expected_result)