Tests that the padding used in constructing extended systems is sufficient.
()
| 784 | |
| 785 | |
| 786 | def test_padding(): |
| 787 | """Tests that the padding used in constructing extended systems is |
| 788 | sufficient. |
| 789 | """ |
| 790 | # Fix random seed for tests |
| 791 | np.random.seed(7) |
| 792 | |
| 793 | # Loop over different cell sizes |
| 794 | for ncells in range(1, 6): |
| 795 | ncells = int(ncells) |
| 796 | |
| 797 | # Loop over different radial cutoffs |
| 798 | for r_cut in np.linspace(2, 10, 11): |
| 799 | # Loop over different sigmas |
| 800 | for sigma in np.linspace(0.5, 2, 4): |
| 801 | # Create descriptor generators |
| 802 | soap_generator = SOAP( |
| 803 | r_cut=r_cut, |
| 804 | n_max=4, |
| 805 | l_max=4, |
| 806 | sigma=sigma, |
| 807 | species=["Ni", "Ti"], |
| 808 | periodic=True, |
| 809 | ) |
| 810 | |
| 811 | # Define unit cell |
| 812 | a = 2.993 |
| 813 | niti = Atoms( |
| 814 | "NiTi", |
| 815 | positions=[[0.0, 0.0, 0.0], [a / 2, a / 2, a / 2]], |
| 816 | cell=[a, a, a], |
| 817 | pbc=[1, 1, 1], |
| 818 | ) |
| 819 | |
| 820 | # Replicate system |
| 821 | niti = niti * ncells |
| 822 | a *= ncells |
| 823 | |
| 824 | # Add some noise to positions |
| 825 | positions = niti.get_positions() |
| 826 | noise = np.random.normal(scale=0.5, size=positions.shape) |
| 827 | niti.set_positions(positions + noise) |
| 828 | niti.wrap() |
| 829 | |
| 830 | # Evaluate descriptors for orthogonal unit cell |
| 831 | orthogonal_soaps = soap_generator.create(niti) |
| 832 | |
| 833 | # Redefine the cubic unit cell as monoclinic with a 45-degree |
| 834 | # angle, this should not affect the descriptors |
| 835 | niti.set_cell([[a, 0, 0], [0, a, 0], [a, 0, a]]) |
| 836 | niti.wrap() |
| 837 | |
| 838 | # Evaluate descriptors for new, monoclinic unit cell |
| 839 | non_orthogonal_soaps = soap_generator.create(niti) |
| 840 | |
| 841 | # Check that the relative or absolute error is small enough |
| 842 | assert np.allclose( |
| 843 | orthogonal_soaps, non_orthogonal_soaps, atol=1e-8, rtol=1e-6 |
nothing calls this directly
no test coverage detected