def test_coloring_with_fixed_species(): lattice = Lattice(3.945 * np.eye(3)) species = ["Sr", "Ti", "O", "O", "O"] frac_coords = np.array([[0, 0, 0], [0.5, 0.5, 0.5], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]]) aristo = Structure(lattice, species, frac_coords) base_structure = aristo.copy() base_structure.remove_species(["Sr", "Ti"]) additional_species = species[:2] additional_frac_coords = frac_coords[:2] mapping_color_species = [DummySpecie("X"), "O"] num_types = len(mapping_color_species) index = 2 se = StructureEnumerator( base_structure, index, num_types, mapping_color_species=mapping_color_species, color_exchange=False, leave_superperiodic=False, use_all_colors=False, ) list_dstructs = se.generate(additional_species=additional_species, additional_frac_coords=additional_frac_coords) # with base_site_constraints mapping_color_species2 = [DummySpecie("X"), "O", "Sr", "Ti"] num_types2 = len(mapping_color_species2) base_site_constraints = [ [2], # Sr site [3], # Cu site [0, 1], # O or V [0, 1], # O or V [0, 1], # O or V ] se2 = StructureEnumerator( aristo, index, num_types2, mapping_color_species=mapping_color_species2, base_site_constraints=base_site_constraints, color_exchange=False, leave_superperiodic=False, use_all_colors=False, ) list_dstructs2 = se2.generate() # check uniqueness by StructureMatcher stm = StructureMatcher(ltol=1e-4, stol=1e-4) grouped = stm.group_structures(list_dstructs + list_dstructs2) assert len(grouped) == len(list_dstructs) assert all([(len(matched) == 2) for matched in grouped])
def test_coloring_with_fixed_species(sto_perovskite: Structure): base_structure = sto_perovskite.copy() base_structure.remove_species(["Sr", "Ti"]) additional_species = sto_perovskite.species[:2] additional_frac_coords = sto_perovskite.frac_coords[:2] mapping_color_species = [DummySpecie("X"), "O"] num_types = len(mapping_color_species) index = 2 se = StructureEnumerator( base_structure, index, num_types, mapping_color_species=mapping_color_species, color_exchange=False, remove_superperiodic=True, remove_incomplete=False, ) list_dstructs = se.generate(additional_species=additional_species, additional_frac_coords=additional_frac_coords) # with base_site_constraints mapping_color_species2 = [DummySpecie("X"), "O", "Sr", "Ti"] num_types2 = len(mapping_color_species2) base_site_constraints = [ [2], # Sr site [3], # Cu site [0, 1], # O or V [0, 1], # O or V [0, 1], # O or V ] se2 = StructureEnumerator( sto_perovskite, index, num_types2, mapping_color_species=mapping_color_species2, base_site_constraints=base_site_constraints, color_exchange=False, remove_superperiodic=True, remove_incomplete=False, ) list_dstructs2 = se2.generate() # check uniqueness by StructureMatcher stm = StructureMatcher(ltol=1e-4, stol=1e-4) grouped = stm.group_structures(list_dstructs + list_dstructs2) # type: ignore assert len(grouped) == len(list_dstructs) assert all([(len(matched) == 2) for matched in grouped])
def test_poscar_string(kind): base_structure = get_lattice(kind) num_type = 2 index = 4 species = [Element("Cu"), Element("Au")] se = StructureEnumerator( base_structure, index, num_type, species, color_exchange=True, remove_superperiodic=True, ) list_ds_mg = se.generate(output="pymatgen") list_ds_pc = se.generate(output="poscar") assert len(list_ds_mg) == len(list_ds_pc) for expect, poscar_str in zip(list_ds_mg, list_ds_pc): actual = Poscar.from_string(poscar_str).structure assert expect == actual
def check(base_structure, num_type, indices, species, name): for index in indices: se = StructureEnumerator( base_structure, index, num_type, species, color_exchange=True, leave_superperiodic=False, ) list_ds = se.generate() stm = StructureMatcher(ltol=1e-4, stol=1e-4) grouped = stm.group_structures(list_ds) assert len(grouped) == len(list_ds)
def test_basic_structure(kind, index): base_structure = get_lattice(kind) num_type = 2 species = ["Cu", "Au"] se = StructureEnumerator( base_structure, index, num_type, species, color_exchange=True, remove_superperiodic=True, ) list_ds = se.generate() stm = StructureMatcher(ltol=1e-4, stol=1e-4) grouped = stm.group_structures(list_ds) assert len(grouped) == len(list_ds)
[0, 1], # 4f [0, 1], # 4f [0, 1], # 4f ] # fmt: on dirname = os.path.join(os.path.dirname(os.path.abspath(__file__)), "SnO1-x") os.makedirs(dirname, exist_ok=True) for index in range(1, max_index + 1): se = StructureEnumerator( rutile, index, num_types, mapping_color_species=mapping_color_species, composition_constraints=composition_constraints, base_site_constraints=base_site_constraints, color_exchange=False, leave_superperiodic=False, use_all_colors=False, ) list_dstructs = se.generate() for i, dstruct in enumerate(list_dstructs): # remove void dstruct.remove_species([mapping_color_species[0]]) filename = os.path.join(dirname, f"SnO1-x_{index}_{i}.cif") write_cif(filename, dstruct, refine_cell=True)
additional_frac_coords = frac_coords[:2] mapping_color_species = [DummySpecie("X"), "O"] num_types = len(mapping_color_species) index = 2 se = StructureEnumerator( base_structure, index, num_types, mapping_color_species=mapping_color_species, color_exchange=False, leave_superperiodic=False, use_all_colors=False, ) list_dstructs = se.generate(additional_species=additional_species, additional_frac_coords=additional_frac_coords) # leave only SrTiO_{3-x} (0 <= x <= 1) num_oxygen_lb = index * 2 num_oxygen_ub = index * 3 structures = [] for ds in list_dstructs: num_oxygen = sum([(str(sp) == "O") for sp in ds.species]) if num_oxygen_lb <= num_oxygen and num_oxygen <= num_oxygen_ub: structures.append(ds) print(index, len(structures)) dirname = os.path.join(os.path.dirname(os.path.abspath(__file__)), "SrTiO3-x") os.makedirs(dirname, exist_ok=True) for i, dstruct in enumerate(structures):