def test_root_surf(): from ase.build import fcc111 from ase.build import bcc111 from ase.build import hcp0001 from ase.build import fcc111_root from ase.build import root_surface from ase.build import root_surface_analysis # Make samples of primitive cell prim_fcc111 = fcc111("H", (1, 1, 2), a=1) prim_bcc111 = bcc111("H", (1, 1, 2), a=1) prim_hcp0001 = hcp0001("H", (1, 1, 2), a=1) # Check valid roots up to root 21 (the 10th root cell) valid_fcc111 = root_surface_analysis(prim_fcc111, 21) valid_bcc111 = root_surface_analysis(prim_bcc111, 21) valid_hcp0001 = root_surface_analysis(prim_hcp0001, 21) # These should have different positions, but the same # cell geometry. assert valid_fcc111 == valid_bcc111 == valid_hcp0001 # Make an easy sample to check code errors atoms1 = root_surface(prim_fcc111, 7) # Ensure the valid roots are the roots are valid against # a set of manually checked roots for this system assert valid_fcc111 == [1.0, 3.0, 4.0, 7.0, 9.0, 12.0, 13.0, 16.0, 19.0, 21.0] # Remake easy sample using surface function atoms2 = fcc111_root("H", 7, (1, 1, 2), a=1) # Right number of atoms assert len(atoms1) == len(atoms2) == 14 # Same positions assert (atoms1.positions == atoms2.positions).all() # Same cell assert (atoms1.cell == atoms2.cell).all()
def test_root_surf(): from ase.build import fcc111 from ase.build import bcc111 from ase.build import hcp0001 from ase.build import fcc111_root from ase.build import bcc111_root from ase.build import hcp0001_root from ase.build import root_surface from ase.build import root_surface_analysis # Manually checked set of roots for FCC111 fcc111_21_set = set([1, 3, 4, 7, 9, 12, 13, 16, 19, 21]) # Keep pairs for testing bulk_root = ((fcc111, fcc111_root), (bcc111, bcc111_root), (hcp0001, hcp0001_root)) for bulk, root_surf in bulk_root: prim = bulk("H", (1, 1, 2), a=1) # Check valid roots up to root 21 (the 10th root cell) assert fcc111_21_set == root_surface_analysis(prim, 21) # Use internal function internal_func_atoms = root_surface(prim, 7) # Remake using surface function helper_func_atoms = root_surf("H", 7, (1, 1, 2), a=1) # Right number of atoms assert len(internal_func_atoms) == 14 assert len(helper_func_atoms) == 14 assert (internal_func_atoms.cell == helper_func_atoms.cell).all() # Try bad root with pytest.raises(ValueError): fcc111_root("H", 5, (1, 1, 2), a=1)
write(name + '.png', slab, show_unit_cell=2, radii=radii[name[:3]], scale=10) for name in surfaces: f = getattr(surface, name) for kwargs in [{}, {'orthogonal': False}, {'orthogonal': True}]: print(name, kwargs) try: slab = f(symbols[name[:3]], size=(3, 4, 5), vacuum=4, **kwargs) except (TypeError, NotImplementedError): continue try: for site in slab.adsorbate_info['sites']: if site.endswith('bridge'): h = 1.5 else: h = 1.2 surface.add_adsorbate(slab, adsorbates.get(site, 'F'), h, site) except KeyError: pass if kwargs.get('orthogonal', None): name += 'o' save(name, slab) for site, symbol in adsorbates.items(): write('%s-site.png' % site, Atoms(symbol), radii=1.08, scale=10) fcc111_primitive = fcc111("Ag", (1, 1, 3)) fcc111_root = root_surface(fcc111_primitive, 27) save("fcc111_root", fcc111_root)
# Make samples of primitive cell prim_fcc111 = fcc111("H", (1, 1, 2), a=1) prim_bcc111 = bcc111("H", (1, 1, 2), a=1) prim_hcp0001 = hcp0001("H", (1, 1, 2), a=1) # Check valid roots up to root 21 (the 10th root cell) valid_fcc111 = root_surface_analysis(prim_fcc111, 21) valid_bcc111 = root_surface_analysis(prim_bcc111, 21) valid_hcp0001 = root_surface_analysis(prim_hcp0001, 21) # These should have different positions, but the same # cell geometry. assert valid_fcc111 == valid_bcc111 == valid_hcp0001 # Make an easy sample to check code errors atoms1 = root_surface(prim_fcc111, 7) # Ensure the valid roots are the roots are valid against # a set of manually checked roots for this system assert valid_fcc111 == [1.0, 3.0, 4.0, 7.0, 9.0, 12.0, 13.0, 16.0, 19.0, 21.0] # Remake easy sample using surface function atoms2 = fcc111_root("H", 7, (1, 1, 2), a=1) # Right number of atoms assert len(atoms1) == len(atoms2) == 14 # Same positions assert (atoms1.positions == atoms2.positions).all()
write(name + '.png', slab, show_unit_cell=2, radii=radii[name[:3]], scale=10) for name in surfaces: f = getattr(surface, name) for kwargs in [{}, {'orthogonal': False}, {'orthogonal': True}]: print(name, kwargs) try: slab = f(symbols[name[:3]], size=(3, 4, 5), vacuum=4, **kwargs) except (TypeError, NotImplementedError): continue try: for site in slab.info['adsorbate_info']['sites']: if site.endswith('bridge'): h = 1.5 else: h = 1.2 surface.add_adsorbate(slab, adsorbates.get(site, 'F'), h, site) except KeyError: pass if kwargs.get('orthogonal', None): name += 'o' save(name, slab) for site, symbol in adsorbates.items(): write('%s-site.png' % site, Atoms(symbol), radii=1.08, scale=10) fcc111_primitive = fcc111("Ag", (1, 1, 3)) fcc111_root = root_surface(fcc111_primitive, 27) save("fcc111_root", fcc111_root)