def test_geometry_sort_func_sort(): bi = sisl_geom.bilayer().tile(2, 0).repeat(2, 1) # Sort according to another cell fractional coordinates fcc = sisl_geom.fcc(2.4, Atom(6)) def fcc_fracs(axis): def _(geometry): return np.dot(geometry.xyz, fcc.icell.T)[:, axis] return _ out = bi.sort(func_sort=(fcc_fracs(0), fcc_fracs(2)))
def test_geometry_sanitize_atom(): bi = sisl_geom.bilayer(bottom_atoms=Atom[6], top_atoms=(Atom[5], Atom[7])).tile(2, 0).repeat(2, 1) C_idx = (bi.atoms.Z == 6).nonzero()[0] check_C = bi.axyz(C_idx) only_C = bi.axyz(Atom[6]) assert np.allclose(only_C, check_C) only_C = bi.axyz(bi.atoms.Z == 6) assert np.allclose(only_C, check_C) # with dict redirect only_C = bi.axyz({'Z': 6}) assert np.allclose(only_C, check_C) tup_01 = (0, 2) list_01 = [0, 2] ndarray_01 = np.array(list_01) assert np.allclose(bi._sanitize_atoms(tup_01), bi._sanitize_atoms(list_01)) assert np.allclose(bi._sanitize_atoms(ndarray_01), bi._sanitize_atoms(list_01))
def test_geometry_sort_func(): bi = sisl_geom.bilayer().tile(2, 0).repeat(2, 1) def reverse(geometry, atom, **kwargs): return atom[::-1] atom = [[2, 0], [3, 1]] out = bi.sort(func=reverse, atom=atom) all_atoms = np.arange(len(bi)) all_atoms[1] = 2 all_atoms[2] = 1 assert np.allclose(out.xyz, bi.sub(all_atoms).xyz) # Ensure that they are swapped atom = [2, 0] out = bi.sort(func=reverse, atom=atom) assert np.allclose(out.xyz, bi.xyz) out = bi.sort(func=reverse) all_atoms = np.arange(len(bi))[::-1] assert np.allclose(out.xyz, bi.sub(all_atoms).xyz)
def test_geometry_sort_fail_keyword(): sisl_geom.bilayer().sort(not_found_keyword=True)
def test_geometry_sort_fail_keyword(): with pytest.raises(ValueError): sisl_geom.bilayer().sort(not_found_keyword=True)