def get_force_constants_from_phonopy(structure, ph_settings, force_sets): """ Calculate the force constants locally using phonopy :param structure: :param phonopy_input: ParameterData object that contains phonopy settings :param force_sets: ForceSetsData object that contains the atomic forces and displacements info (datasets dict in phonopy) :return: ForceConstantsData object containing the 2nd order force constants calculated with phonopy """ from phonopy import Phonopy # Generate phonopy phonon object phonon = Phonopy(phonopy_bulk_from_structure(structure), ph_settings.dict.supercell, primitive_matrix=ph_settings.dict.primitive, symprec=ph_settings.dict.symmetry_precision) phonon.generate_displacements(distance=ph_settings.dict.distance) # Build data_sets from forces of supercells with displacments phonon.set_displacement_dataset(force_sets.get_force_sets()) phonon.produce_force_constants() force_constants = ForceConstantsData(data=phonon.get_force_constants()) return {'force_constants': force_constants}
def create_supercells_with_displacements_using_phonopy(structure, ph_settings): """ Use phonopy to create the supercells with displacements to calculate the force constants by using finite displacements methodology :param structure: StructureData object :param phonopy_input: ParametersData object containing a dictionary with the data needed for phonopy :return: A set of StructureData Objects containing the supercells with displacements """ from phonopy import Phonopy # Generate phonopy phonon object phonon = Phonopy(phonopy_bulk_from_structure(structure), supercell_matrix=ph_settings.dict.supercell, primitive_matrix=ph_settings.dict.primitive, symprec=ph_settings.dict.symmetry_precision) phonon.generate_displacements(distance=ph_settings.dict.distance) cells_with_disp = phonon.get_supercells_with_displacements() # Transform cells to StructureData and set them ready to return data_sets = phonon.get_displacement_dataset() data_sets_object = ForceSetsData(data_sets=data_sets) disp_cells = {'data_sets': data_sets_object} for i, phonopy_supercell in enumerate(cells_with_disp): supercell = StructureData(cell=phonopy_supercell.get_cell()) for symbol, position in zip(phonopy_supercell.get_chemical_symbols(), phonopy_supercell.get_positions()): supercell.append_atom(position=position, symbols=symbol) disp_cells["structure_{}".format(i)] = supercell return disp_cells
def get_thermal_properties(structure, ph_settings, force_constants_list): from phonopy import Phonopy from aiida_phonopy.workchains.phonon import phonopy_bulk_from_structure free_energy_list = [] entropy_list = [] cv_list = [] temperature = None for fc in force_constants_list: phonon = Phonopy(phonopy_bulk_from_structure(structure), ph_settings.dict.supercell, primitive_matrix=ph_settings.dict.primitive, symprec=ph_settings.dict.symmetry_precision) # Normalization factor primitive to unit cell normalization_factor = phonon.unitcell.get_number_of_atoms()/phonon.primitive.get_number_of_atoms() phonon.set_force_constants(fc) phonon.set_mesh(ph_settings.dict.mesh, is_eigenvectors=True, is_mesh_symmetry=False) phonon.set_thermal_properties() temperature, free_energy, entropy, cv = phonon.get_thermal_properties() free_energy_list.append(np.array(free_energy) * normalization_factor) entropy_list.append(np.array(entropy) * normalization_factor) cv_list.append(np.array(cv) * normalization_factor) return np.array(free_energy_list), np.array(entropy_list).T, np.array(cv_list).T, temperature
def _get_phonon(self): cell = read_vasp(os.path.join(data_dir, "..", "POSCAR_NaCl")) phonon = Phonopy(cell, np.diag([2, 2, 2]), primitive_matrix=[[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]) filename = os.path.join(data_dir, "FORCE_SETS_NaCl") force_sets = parse_FORCE_SETS(filename=filename) phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() born_elems = {'Na': [[1.08703, 0, 0], [0, 1.08703, 0], [0, 0, 1.08703]], 'Cl': [[-1.08672, 0, 0], [0, -1.08672, 0], [0, 0, -1.08672]]} born = [born_elems[s] for s in ['Na', 'Cl']] epsilon = [[2.43533967, 0, 0], [0, 2.43533967, 0], [0, 0, 2.43533967]] factors = 14.400 phonon.set_nac_params({'born': born, 'factor': factors, 'dielectric': epsilon}) return phonon
def get_phonon_band_structure_from_fc( structure: Structure, supercell_matrix: np.ndarray, force_constants: np.ndarray, mesh_density: float = 100.0, **kwargs, ) -> PhononBandStructure: """ Get a uniform phonon band structure from phonopy force constants. Args: structure: A structure. supercell_matrix: The supercell matrix used to generate the force constants. force_constants: The force constants in phonopy format. mesh_density: The density of the q-point mesh. See the docstring for the ``mesh`` argument in Phonopy.init_mesh() for more details. **kwargs: Additional kwargs passed to the Phonopy constructor. Returns: The uniform phonon band structure. """ structure_phonopy = get_phonopy_structure(structure) phonon = Phonopy(structure_phonopy, supercell_matrix=supercell_matrix, **kwargs) phonon.set_force_constants(force_constants) phonon.run_mesh(mesh_density, is_mesh_symmetry=False, is_gamma_center=True) mesh = phonon.get_mesh_dict() return PhononBandStructure(mesh["qpoints"], mesh["frequencies"], structure.lattice)
def get_properties_from_phonopy(structure, phonopy_input, force_constants): """ Calculate DOS and thermal properties using phonopy (locally) :param structure: Aiida StructureData Object :param phonopy_input: Aiida Parametersdata object containing a dictionary with the data needed to run phonopy: supercells matrix, primitive matrix and q-points mesh. :param force_constants: :return: """ from phonopy.structure.atoms import Atoms as PhonopyAtoms from phonopy import Phonopy # Generate phonopy phonon object bulk = PhonopyAtoms(symbols=[site.kind_name for site in structure.sites], positions=[site.position for site in structure.sites], cell=structure.cell) phonopy_input = phonopy_input.get_dict() force_constants = force_constants.get_array('force_constants') phonon = Phonopy(bulk, phonopy_input['supercell'], primitive_matrix=phonopy_input['primitive']) phonon.set_force_constants(force_constants) #Normalization factor primitive to unit cell normalization_factor = phonon.unitcell.get_number_of_atoms( ) / phonon.primitive.get_number_of_atoms() phonon.set_mesh(phonopy_input['mesh'], is_eigenvectors=True, is_mesh_symmetry=False) phonon.set_total_DOS() phonon.set_partial_DOS() # get DOS (normalized to unit cell) total_dos = phonon.get_total_DOS() * normalization_factor partial_dos = phonon.get_partial_DOS() * normalization_factor # Stores DOS data in DB as a workflow result dos = ArrayData() dos.set_array('frequency', total_dos[0]) dos.set_array('total_dos', total_dos[1]) dos.set_array('partial_dos', partial_dos[1]) #THERMAL PROPERTIES (per primtive cell) phonon.set_thermal_properties() t, free_energy, entropy, cv = phonon.get_thermal_properties() # Stores thermal properties (per unit cell) data in DB as a workflow result thermal_properties = ArrayData() thermal_properties.set_array('temperature', t) thermal_properties.set_array('free_energy', free_energy * normalization_factor) thermal_properties.set_array('entropy', entropy * normalization_factor) thermal_properties.set_array('cv', cv * normalization_factor) return {'thermal_properties': thermal_properties, 'dos': dos}
def _get_phonon(self, spgtype, dim, pmat): cell = read_vasp("POSCAR_%s" % spgtype) phonon = Phonopy(cell, np.diag(dim), primitive_matrix=pmat) force_sets = parse_FORCE_SETS(filename="FORCE_SETS_%s" % spgtype) phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() return phonon
def _get_phonon(self, cell): phonon = Phonopy(cell, np.diag([1, 1, 1])) force_sets = parse_FORCE_SETS( filename=os.path.join(data_dir, "FORCE_SETS")) phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() return phonon
def get_phonon_configs(calc, at, disps, scell, config_type): cell = PhonopyAtoms(symbols=at.get_chemical_symbols(), cell=at.get_cell(), positions=at.get_positions()) phonon = Phonopy(cell, np.eye(3) * scell) al = [] for disp in disps: print(disp, config_type) phonon.generate_displacements(distance=disp) supercells = phonon.get_supercells_with_displacements() for (i, scell) in enumerate(supercells): at = ase.Atoms(symbols=scell.get_chemical_symbols(), scaled_positions=scell.get_scaled_positions(), cell=scell.get_cell(), pbc=True) at.set_calculator(calc) e = at.get_potential_energy() f = at.get_forces() v = -1.0 * at.get_volume() * at.get_stress(voigt=False) at.arrays["force"] = f at.info["virial"] = v at.info["config_type"] = "PH_" + config_type at.info["energy_TB"] = e #write("PH_{}_{}_scell_{}.xyz".format(config_type, i, disp), at) al.append(at) return al
def run_phonolammps(): n = 2 phlammps = Phonolammps('in.graphene', supercell_matrix=[[n, 0, 0], [0, n, 0], [0, 0, n]]) unitcell = phlammps.get_unitcell() force_constants = phlammps.get_force_constants() supercell_matrix = phlammps.get_supercell_matrix() print('unitcell') print('*' * 50) print(unitcell) print('force const') print('*' * 50) print(force_constants) print('supercell') print('*' * 50) print(supercell_matrix) from phonopy import Phonopy phonon = Phonopy(unitcell, supercell_matrix) print(phonon) print(dir(phonon)) phonon.set_force_constants(force_constants) phonon.set_mesh([20, 20, 20]) # phonon.write_yaml_band_structure('band.conf') # phonon.set_band_structure('band.conf') # phonon.plot_band_structure().savefig('band.png') # phonon.set_total_DOS() # phonon.plot_total_DOS().savefig('dos.png') phonon.set_thermal_properties() # print(phonon.get_thermal_properties_dict()) phonon.plot_thermal_properties().savefig('therm.png')
def get_data_from_dir(directory, i_volume): data_sets = file_IO.parse_FORCE_SETS( filename=directory + '/phonon-{0:02d}/FORCE_SETS'.format(i_volume)) yaml_file = open( directory + '/phonon-{0:02d}/phonon.yaml'.format(i_volume), 'r') data = yaml.load_all(yaml_file).next() unit_cell = PhonopyAtoms( symbols=[item['symbol'] for item in data['points']], scaled_positions=[item['coordinates'] for item in data['points']], cell=data['lattice']) phonon = Phonopy(unit_cell, data['supercell_matrix']) phonon.set_displacement_dataset(data_sets) phonon.produce_force_constants() force_constants = phonon.get_force_constants() supercell = phonon.get_supercell() volume = unit_cell.get_volume() energy = data['electric_total_energy'] return supercell, volume, energy, force_constants, data['supercell_matrix']
def __init__(self, model=None, structure=None, atom_disp=0.015, **kwargs): self.model = model self.structure = structure self.atom_disp = atom_disp self.qpoints, self.vertices = get_qpoints_and_vertices(self.structure) is_plusminus = kwargs.get('is_plusminus', True) is_diagonal = kwargs.get('is_diagonal', True) is_trigonal = kwargs.get('is_diagonal', False) supercell_matrix = kwargs.get('is_diagonal', None) ph_structure = get_phonopy_structure(self.structure) if supercell_matrix is None: supercell_matrix = np.eye(3) * np.array((1, 1, 1)) self.phonon = Phonopy(unitcell=ph_structure, supercell_matrix=supercell_matrix) self.phonon.generate_displacements(distance=self.atom_disp, is_plusminus=is_plusminus, is_diagonal=is_diagonal, is_trigonal=is_trigonal) disp_supercells = self.phonon.get_supercells_with_displacements() # Perfect supercell structure init_supercell = self.phonon.get_supercell() # Structure list to be returned self.structure_list = [get_pmg_structure(init_supercell)] for c in disp_supercells: if c is not None: self.structure_list.append(get_pmg_structure(c)) forces = self.model.calculate_forces(self.structure_list) self.phonon.set_forces(forces[1:]) self.phonon.produce_force_constants() logging.info("Force constant produced")
def _get_supercell_phonon(self, ph_in): """Returns Phonopy instance of supercell as the primitive""" ph = Phonopy(ph_in.supercell, supercell_matrix=[1, 1, 1], primitive_matrix='P') fc_shape = ph_in.force_constants.shape if fc_shape[0] == fc_shape[1]: # assume full fc ph.force_constants = ph_in.force_constants.copy() else: ph.force_constants = compact_fc_to_full_fc(ph_in, ph_in.force_constants) if ph_in.nac_params: p2p = ph_in.primitive.p2p_map s2p = ph_in.primitive.s2p_map s2pp = [p2p[i] for i in s2p] born_in = ph_in.nac_params['born'] born = [born_in[i] for i in s2pp] nac_params = { 'born': np.array(born, dtype='double', order='C'), 'factor': ph_in.nac_params['factor'], 'dielectric': ph_in.nac_params['dielectric'].copy() } ph.nac_params = nac_params return ph
def setup(self): phonon = Phonopy(self._bulk, supercell_matrix=[[6, 0, 0], [0, 6, 0], [0, 0, 6]]) self._phonon = phonon self._symmetry = self._phonon.get_symmetry() self._force_sets = parse_FORCE_SETS() phonon.get_displacement_dataset()
def phonons(model, bulk, supercell, dx, mesh=None, points=None, n_points=50): import model unitcell = PhonopyAtoms(symbols=bulk.get_chemical_symbols(), cell=bulk.get_cell(), scaled_positions=bulk.get_scaled_positions()) phonon = Phonopy(unitcell, supercell) phonon.generate_displacements(distance=dx) sets_of_forces = [] for s in phonon.get_supercells_with_displacements(): at = Atoms(cell=s.get_cell(), symbols=s.get_chemical_symbols(), scaled_positions=s.get_scaled_positions(), pbc=3 * [True]) at.set_calculator(model.calculator) sets_of_forces.append(at.get_forces()) phonon.set_forces(sets_of_forces=sets_of_forces) phonon.produce_force_constants() properties = {} if mesh is not None: phonon.set_mesh(mesh, is_gamma_center=True) qpoints, weights, frequencies, eigvecs = phonon.get_mesh() properties["frequencies"] = frequencies.tolist() properties["weights"] = weights.tolist() if points is not None: bands = [] for i in range(len(points) - 1): band = [] for r in np.linspace(0, 1, n_points): band.append(points[i] + (points[i + 1] - points[i]) * r) bands.append(band) phonon.set_band_structure(bands, is_eigenvectors=True, is_band_connection=False) band_q_points, band_distances, band_frequencies, band_eigvecs = phonon.get_band_structure( ) band_distance_max = np.max(band_distances) band_distances = [(_b / band_distance_max).tolist() for _b in band_distances] band_frequencies = [_b.tolist() for _b in band_frequencies] properties["band_q_points"] = band_q_points properties["band_distances"] = band_distances properties["band_frequencies"] = band_frequencies properties["band_eigvecs"] = band_eigvecs properties["phonopy"] = phonon return properties
def get_force_sets_inline(**kwargs): from phonopy.structure.atoms import Atoms as PhonopyAtoms from phonopy import Phonopy structure = kwargs.pop('structure') phonopy_input = kwargs.pop('phonopy_input').get_dict() # Generate phonopy phonon object bulk = PhonopyAtoms(symbols=[site.kind_name for site in structure.sites], positions=[site.position for site in structure.sites], cell=structure.cell) phonon = Phonopy(bulk, phonopy_input['supercell'], primitive_matrix=phonopy_input['primitive'], symprec=phonopy_input['symmetry_precision']) phonon.generate_displacements(distance=phonopy_input['distance']) # Build data_sets from forces of supercells with displacments data_sets = phonon.get_displacement_dataset() for i, first_atoms in enumerate(data_sets['first_atoms']): first_atoms['forces'] = kwargs.pop( 'force_{}'.format(i)).get_array('forces')[-1] data = ArrayData() data.set_array('force_sets', np.array(data_sets)) return {'phonopy_output': data}
def read_phonopy(sposcar='SPOSCAR', sc_mat=np.eye(3), force_constants=None, disp_yaml=None, force_sets=None): if force_constants is None and (disp_yaml is None or force_sets is None): raise ValueError( "Either FORCE_CONSTANTS or (disp.yaml&FORCE_SETS) file should be provided." ) atoms = read(sposcar) #vesta_view(atoms) primitive_matrix = inv(sc_mat) bulk = PhonopyAtoms(symbols=atoms.get_chemical_symbols(), scaled_positions=atoms.get_scaled_positions(), cell=atoms.get_cell()) phonon = Phonopy( bulk, supercell_matrix=np.eye(3), primitive_matrix=primitive_matrix, #factor=factor, #symprec=symprec ) if disp_yaml is not None: disp = parse_disp_yaml(filename=disp_yaml) phonon.set_displacement_dataset(disp) if force_sets is not None: fc = parse_FORCE_SETS(filename=force_sets) phonon.set_forces(fc) fc = parse_FORCE_CONSTANTS(force_constants) phonon.set_force_constants(fc) return phonon
def create_supercells_with_displacements_inline(**kwargs): from phonopy.structure.atoms import Atoms as PhonopyAtoms from phonopy import Phonopy structure = kwargs.pop('structure') phonopy_input = kwargs.pop('phonopy_input').get_dict() # Generate phonopy phonon object bulk = PhonopyAtoms(symbols=[site.kind_name for site in structure.sites], positions=[site.position for site in structure.sites], cell=structure.cell) phonon = Phonopy(bulk, phonopy_input['supercell'], primitive_matrix=phonopy_input['primitive'], symprec=phonopy_input['symmetry_precision']) phonon.generate_displacements(distance=phonopy_input['distance']) cells_with_disp = phonon.get_supercells_with_displacements() # Transform cells to StructureData and set them ready to return disp_cells = {} for i, phonopy_supercell in enumerate(cells_with_disp): supercell = StructureData(cell=phonopy_supercell.get_cell()) for symbol, position in zip(phonopy_supercell.get_chemical_symbols(), phonopy_supercell.get_positions()): supercell.append_atom(position=position, symbols=symbol) disp_cells["structure_{}".format(i)] = supercell return disp_cells
def _get_supercell_phonon(self, ph_in): """Return Phonopy instance of supercell as the primitive.""" ph = Phonopy(ph_in.supercell, supercell_matrix=[1, 1, 1], primitive_matrix="P") fc_shape = ph_in.force_constants.shape if fc_shape[0] == fc_shape[1]: # assume full fc ph.force_constants = ph_in.force_constants.copy() else: ph.force_constants = compact_fc_to_full_fc(ph_in, ph_in.force_constants) if ph_in.nac_params: p2p = ph_in.primitive.p2p_map s2p = ph_in.primitive.s2p_map s2pp = [p2p[i] for i in s2p] born_in = ph_in.nac_params["born"] born = [born_in[i] for i in s2pp] nac_params = { "born": np.array(born, dtype="double", order="C"), "factor": ph_in.nac_params["factor"], "dielectric": ph_in.nac_params["dielectric"].copy(), } ph.nac_params = nac_params return ph
def do_phonons(strt=None, parameters=None, c_size=25): """ Setting up phonopy job using LAMMPS Args: strt: Structure object parameters: LAMMPS input file parameters c_size: cell-size """ p = get_phonopy_atoms(mat=strt) bulk = p dim1 = int((float(c_size) / float(max(abs(strt.lattice.matrix[0]))))) + 1 dim2 = int(float(c_size) / float(max(abs(strt.lattice.matrix[1])))) + 1 dim3 = int(float(c_size) / float(max(abs(strt.lattice.matrix[2])))) + 1 Poscar(strt).write_file("POSCAR") tmp = strt.copy() tmp.make_supercell([dim1, dim2, dim3]) Poscar(tmp).write_file("POSCAR-Super.vasp") phonon = Phonopy(bulk, [[dim1, 0, 0], [0, dim2, 0], [0, 0, dim3]]) # , print("[Phonopy] Atomic displacements:") disps = phonon.get_displacements() for d in disps: print("[Phonopy]", d[0], d[1:]) supercells = phonon.get_supercells_with_displacements() # Force calculations by calculator set_of_forces = [] disp = 0 for scell in supercells: cell = Atoms( symbols=scell.get_chemical_symbols(), scaled_positions=scell.get_scaled_positions(), cell=scell.get_cell(), pbc=True, ) disp = disp + 1 mat = Poscar(AseAtomsAdaptor().get_structure(cell)) mat.comment = str("disp-") + str(disp) parameters["min"] = "skip" parameters["control_file"] = "/users/knc6/in.phonon" # a,b,forces=run_job(mat=mat,parameters={'min':'skip','pair_coeff': '/data/knc6/JARVIS-FF-NEW/ALLOY4/Mishin-Ni-Al-2009.eam.alloy', 'control_file': '/users/knc6/in.phonon', 'pair_style': 'eam/alloy', 'atom_style': 'charge'}) a, b, forces = run_job(mat=mat, parameters=parameters) print("forces=", forces) drift_force = forces.sum(axis=0) print("drift forces=", drift_force) print("[Phonopy] Drift force:", "%11.5f" * 3 % tuple(drift_force)) # Simple translational invariance for force in forces: force -= drift_force / forces.shape[0] set_of_forces.append(forces) phonon.produce_force_constants(forces=set_of_forces) write_FORCE_CONSTANTS(phonon.get_force_constants(), filename="FORCE_CONSTANTS") print() print("[Phonopy] Phonon frequencies at Gamma:")
def _get_phonon(self, cell): phonon = Phonopy(cell, np.diag([2, 2, 2]), primitive_matrix=[[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]) force_sets = parse_FORCE_SETS(filename="FORCE_SETS_moment") phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() supercell = phonon.get_supercell() born_elems = {'Na': [[1.08703, 0, 0], [0, 1.08703, 0], [0, 0, 1.08703]], 'Cl': [[-1.08672, 0, 0], [0, -1.08672, 0], [0, 0, -1.08672]]} born = [born_elems[s] for s in ['Na', 'Cl']] epsilon = [[2.43533967, 0, 0], [0, 2.43533967, 0], [0, 0, 2.43533967]] factors = 14.400 phonon.set_nac_params({'born': born, 'factor': factors, 'dielectric': epsilon}) return phonon
def get_displaced_structures(pmg_structure, atom_disp=0.01, supercell_matrix=None, yaml_fname=None, **kwargs): r""" Generate a set of symmetrically inequivalent displaced structures for phonon calculations. Args: pmg_structure (Structure): A pymatgen structure object. atom_disp (float): Atomic displacement. Default is 0.01 $\\AA$. supercell_matrix (3x3 array): Scaling matrix for supercell. yaml_fname (string): If not None, it represents the full path to the outputting displacement yaml file, e.g. disp.yaml. **kwargs: Parameters used in Phonopy.generate_displacement method. Return: A list of symmetrically inequivalent structures with displacements, in which the first element is the perfect supercell structure. """ is_plusminus = kwargs.get("is_plusminus", "auto") is_diagonal = kwargs.get("is_diagonal", True) is_trigonal = kwargs.get("is_trigonal", False) ph_structure = get_phonopy_structure(pmg_structure) if supercell_matrix is None: supercell_matrix = np.eye(3) * np.array((1, 1, 1)) phonon = Phonopy(unitcell=ph_structure, supercell_matrix=supercell_matrix) phonon.generate_displacements( distance=atom_disp, is_plusminus=is_plusminus, is_diagonal=is_diagonal, is_trigonal=is_trigonal, ) if yaml_fname is not None: displacements = phonon.get_displacements() write_disp_yaml( displacements=displacements, supercell=phonon.get_supercell(), filename=yaml_fname, ) # Supercell structures with displacement disp_supercells = phonon.get_supercells_with_displacements() # Perfect supercell structure init_supercell = phonon.get_supercell() # Structure list to be returned structure_list = [get_pmg_structure(init_supercell)] for c in disp_supercells: if c is not None: structure_list.append(get_pmg_structure(c)) return structure_list
def _get_phonon(self, cell): phonon = Phonopy(cell, np.diag([1, 1, 1]), is_auto_displacements=False) force_sets = parse_FORCE_SETS() phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() return phonon
def _get_phonon(spgtype, dim, pmat): cell = read_vasp(os.path.join(data_dir, "POSCAR_%s" % spgtype)) phonon = Phonopy(cell, np.diag(dim), primitive_matrix=pmat) force_sets = parse_FORCE_SETS( filename=os.path.join(data_dir, "FORCE_SETS_%s" % spgtype)) phonon.dataset = force_sets phonon.produce_force_constants() return phonon
def input_files(self, path_POSCAR, path_FORCECONSTANT): bulk = read_vasp(path_POSCAR) self.phonon = Phonopy(bulk, self.super_cell, primitive_matrix=self.primitive_cell) force_constants = file_IO.parse_FORCE_CONSTANTS(path_FORCECONSTANT) self.phonon.set_force_constants(force_constants) return self.phonon
def get_frequency(poscar_filename, force_sets_filename): bulk = read_vasp(poscar_filename) volume = bulk.get_volume() phonon = Phonopy(bulk, [[2, 0, 0], [0, 2, 0], [0, 0, 2]], is_auto_displacements=False) force_sets = parse_FORCE_SETS(filename=force_sets_filename) phonon.set_force_sets(force_sets) phonon.set_post_process([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]) return phonon.get_frequencies([0.5, 0.5, 0]), volume
def _get_phonon(self, spgtype, dim, pmat): cell = read_vasp(os.path.join(data_dir, "POSCAR_%s" % spgtype)) phonon = Phonopy(cell, np.diag(dim), primitive_matrix=pmat) filename = os.path.join(data_dir, "FORCE_SETS_%s" % spgtype) force_sets = parse_FORCE_SETS(filename=filename) phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() print(phonon.get_symmetry().get_pointgroup()) return phonon
def get_phonopy(structure): from phonopy import Phonopy from phonopy.structure.atoms import Atoms as PhonopyAtoms phon_atoms = PhonopyAtoms(symbols=[str(s.specie) for s in structure], scaled_positions=structure.frac_coords) phon_atoms.set_cell(structure.lattice.matrix) # supercell size scell = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] return Phonopy(phon_atoms, scell)
def get_frequency(poscar_filename, force_sets_filename): unitcell = read_vasp(poscar_filename) volume = unitcell.get_volume() phonon = Phonopy(unitcell, [[2, 0, 0], [0, 2, 0], [0, 0, 2]], primitive_matrix=[[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]) force_sets = parse_FORCE_SETS(filename=force_sets_filename) phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() return phonon.get_frequencies([0.5, 0.5, 0]), volume
def _enable_phonopy(self): if self.phonopy is None: if self.structure is not None: self.phonopy = Phonopy(unitcell=self._phonopy_unit_cell, supercell_matrix=self._phonopy_supercell_matrix(), factor=self.input['factor']) self.phonopy.generate_displacements(distance=self.input['displacement']) self.to_hdf() else: raise ValueError('No reference job/ No reference structure found.')