def get_force_constants(self): """ calculate the force constants with phonopy using lammps to calculate forces :return: ForceConstants type object containing force constants """ if self._force_constants is None: phonon = get_phonon(self._structure, setup_forces=False, super_cell_phonon=self._supercell_matrix) phonon.get_displacement_dataset() phonon.generate_displacements(distance=self._displacement_distance) cells_with_disp = phonon.get_supercells_with_displacements() cells_with_disp = [ cell.get_positions() for cell in cells_with_disp ] data_sets = phonon.get_displacement_dataset() # Get forces from lammps for i, cell in enumerate(cells_with_disp): if self._show_progress: print('displacement {} / {}'.format( i + 1, len(cells_with_disp))) forces = self.get_lammps_forces(cell) data_sets['first_atoms'][i]['forces'] = forces phonon.set_displacement_dataset(data_sets) phonon.produce_force_constants() self._force_constants = phonon.get_force_constants() return self._force_constants
def get_force_constants(self, include_data_set=False): """ calculate the force constants with phonopy using lammps to calculate forces :return: ForceConstants type object containing force constants """ if self._force_constants is None: phonon = get_phonon(self._structure, setup_forces=False, super_cell_phonon=self._supercell_matrix, primitive_matrix=self._primitive_matrix, NAC=self._NAC, symmetrize=self._symmetrize) phonon.get_displacement_dataset() phonon.generate_displacements(distance=self._displacement_distance) cells_with_disp = phonon.get_supercells_with_displacements() data_set = phonon.get_displacement_dataset() # Check forces for non displaced supercell forces_supercell = self.get_forces(phonon.get_supercell()) if np.max(forces_supercell) > 1e-1: warnings.warn( 'Large atomic forces found for non displaced structure: ' '{}. Make sure your unit cell is properly optimized'. format(np.max(forces_supercell))) # Get forces from lammps for i, cell in enumerate(cells_with_disp): if self._show_progress: print('displacement {} / {}'.format( i + 1, len(cells_with_disp))) forces = self.get_forces(cell) data_set['first_atoms'][i]['forces'] = forces phonon.set_displacement_dataset(data_set) phonon.produce_force_constants() self._force_constants = phonon.get_force_constants() self._data_set = data_set if include_data_set: return [self._force_constants, self._data_set] else: return self._force_constants
def get_phonopy_phonon(self): """ Return phonopy phonon object with unitcell, primitive cell and the force constants set. :return: """ phonon = get_phonon(self._structure, setup_forces=False, super_cell_phonon=self._supercell_matrix, primitive_matrix=self._primitive_matrix, NAC=self._NAC, symmetrize=self._symmetrize) phonon.set_force_constants(self.get_force_constants()) return phonon
return forces if __name__ == '__main__': structure = get_structure_from_txyz('structure_wrap_min.txyz', 'structure.key') print(structure) print(structure.get_connectivity()) print(generate_VASP_structure(structure)) print(structure.get_scaled_positions()) print(structure.get_chemical_symbols()) phonon = get_phonon(structure, setup_forces=False, super_cell_phonon=[[2, 0, 0], [0, 2, 0], [0, 0, 2]], NAC=False, symmetrize=True) phonon.get_displacement_dataset() phonon.generate_displacements(distance=0.0001) cells_with_disp = phonon.get_supercells_with_displacements() print(cells_with_disp[0]) print(generate_VASP_structure(cells_with_disp[0])) supercell_wd = rebuild_connectivity_tinker(structure, cells_with_disp[0], phonon.get_supercell_matrix()) print(generate_tinker_txyz_file(supercell_wd))