def phonopyAtoms_to_aseAtoms(PhonopyAtoms, pbc=[True, True, True]): aseAtoms = ase.Atoms(symbols=PhonopyAtoms.get_chemical_symbols(), positions=PhonopyAtoms.get_positions(), cell=PhonopyAtoms.get_cell()) aseAtoms.set_pbc(pbc) aseAtoms.set_masses(PhonopyAtoms.get_masses()) Atomic_numbers = PhonopyAtoms.get_atomic_numbers() Atomic_type_tags = np.zeros(np.shape(Atomic_numbers)) atomic_type_unique = np.unique(Atomic_numbers) for i, iZ in enumerate(atomic_type_unique): Atomic_type_tags[Atomic_numbers == iZ] = i aseAtoms.set_tags(Atomic_type_tags) aseAtoms.set_initial_charges() return aseAtoms
def get_cell_from_phonopy_structure(ph_structure: PhonopyAtoms, use_atomic_number: bool = False) -> tuple: """ Get cell from phonopy structure Args: ph_structure: PhonopyAtoms object use_atomic_number: if True, use atomic number intead of atomic symbol Returns: tuple: (lattice, scaled_positions, symbols). """ lattice = ph_structure.get_cell() scaled_positions = ph_structure.get_scaled_positions() if use_atomic_number: elements = list(ph_structure.get_atomic_numbers()) else: elements = ph_structure.get_chemical_symbols() return (lattice, scaled_positions, elements)
def assert_same_phonopy_atoms(actual: PhonopyAtoms, expected: PhonopyAtoms): assert (actual.get_cell() == expected.get_cell()).all() assert (actual.get_scaled_positions() == expected.get_scaled_positions() ).all() assert actual.symbols == expected.symbols