def test_isolation_3D(): atoms = FaceCenteredCubic(size=(2, 2, 2), symbol='Cu', pbc=(1, 1, 1)) result = isolate_components(atoms) assert len(result) == 1 key, components = list(result.items())[0] assert key == '3D' assert len(components) == 1 bulk = components[0] assert bulk.get_chemical_formula() == atoms.get_chemical_formula()
def test_isolation_0D(): atoms = ase.build.molecule('H2O', vacuum=3.0) result = isolate_components(atoms, kcutoff=1.1) assert len(result) == 1 key, components = list(result.items())[0] assert key == '0D' assert len(components) == 1 molecule = components[0] assert molecule.get_chemical_formula() == atoms.get_chemical_formula()
def test_isolation_2D(): atoms = ase.build.mx2(formula='MoS2', kind='2H', a=3.18, thickness=3.19) atoms.cell[2, 2] = 7 atoms.set_pbc((1, 1, 1)) atoms *= 2 result = isolate_components(atoms) assert len(result) == 1 key, components = list(result.items())[0] assert key == '2D' assert len(components) == 2 for layer in components: empirical = atoms.get_chemical_formula(empirical=True) assert empirical == layer.get_chemical_formula(empirical=True) assert (layer.pbc == [True, True, False]).all()
def test_isolation_1D(): atoms = Atoms(symbols='Cl6Ti2', pbc=True, cell=[[6.27, 0, 0], [-3.135, 5.43, 0], [0, 0, 5.82]], positions=[[1.97505, 0, 1.455], [0.987525, 1.71044347, 4.365], [-0.987525, 1.71044347, 1.455], [4.29495, 0, 4.365], [2.147475, 3.71953581, 1.455], [-2.147475, 3.71953581, 4.365], [0, 0, 0], [0, 0, 2.91]]) result = isolate_components(atoms) assert len(result) == 1 key, components = list(result.items())[0] assert key == '1D' assert len(components) == 1 chain = components[0] assert (chain.pbc == [False, False, True]).all() assert chain.get_chemical_formula() == atoms.get_chemical_formula()
def get_components(atoms, kcutoff, viewer=False): """ A function to isolate individual components from the input structure and view if desired. Parameters Accepts: atoms (Atoms object) ASE atoms object of desired structure kcutoff (int) Cutoff of components to consider. Ideally, this should be the Lennard-Jones cutoff value used. viewer (bool) When True, returns the view of each component. Do not set True unless you only have a few components. Returns: comp (collections.defaultdict) """ comp = isolate_components(atoms, kcutoff=kcutoff) print("counts:", [(k, len(v)) for k, v in sorted(comp.items())]) if viewer == True: for dim, components in comp.items(): for atoms in components: view(atoms, block=True) return comp
import numpy as np import ase.build from ase import Atoms from ase.visualize import view from ase.geometry.dimensionality import isolate_components # build two slabs of different types of MoS2 rep = [4, 4, 1] a = ase.build.mx2(formula='MoS2', kind='2H', a=3.18, thickness=3.19) * rep b = ase.build.mx2(formula='MoS2', kind='1T', a=3.18, thickness=3.19) * rep positions = np.concatenate([a.get_positions(), b.get_positions() + [0, 0, 7]]) numbers = np.concatenate([a.numbers, b.numbers]) cell = a.cell atoms = Atoms(numbers=numbers, positions=positions, cell=cell, pbc=[1, 1, 1]) atoms.cell[2, 2] = 14.0 # isolate each component in the whole material result = isolate_components(atoms) print("counts:", [(k, len(v)) for k, v in sorted(result.items())]) for dim, components in result.items(): for atoms in components: print(dim) view(atoms, block=True)