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)
def test_except(): from javelin.fourier import get_ff four = Fourier() with pytest.raises(ValueError): four.radiation = 'electron' with pytest.raises(ValueError): four.lots = 4, 1 with pytest.raises(ValueError): get_ff(10, 'electron')