def _set_force_constants(phonon, force_constants_filename, force_sets_filename, use_alm): natom = phonon.supercell.get_number_of_atoms() if force_constants_filename is not None: dot_split = force_constants_filename.split('.') p2s_map = phonon.primitive.get_primitive_to_supercell_map() if len(dot_split) > 1 and dot_split[-1] == 'hdf5': fc = read_force_constants_hdf5(filename=force_constants_filename, p2s_map=p2s_map) else: fc = parse_FORCE_CONSTANTS(filename=force_constants_filename, p2s_map=p2s_map) phonon.set_force_constants(fc) elif force_sets_filename is not None: force_sets = parse_FORCE_SETS(natom=natom, filename=force_sets_filename) if force_sets: phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants( calculate_full_force_constants=False, use_alm=use_alm) elif os.path.isfile("FORCE_SETS"): force_sets = parse_FORCE_SETS(natom=natom) if force_sets: phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants( calculate_full_force_constants=False, use_alm=use_alm)
def _compute_force_constants(phonon, dataset=None, force_constants_filename=None, force_sets_filename=None, calculator=None, fc_calculator=None): natom = phonon.supercell.get_number_of_atoms() _dataset = None if dataset is not None: _dataset = dataset elif force_constants_filename is not None: dot_split = force_constants_filename.split('.') p2s_map = phonon.primitive.p2s_map if len(dot_split) > 1 and dot_split[-1] == 'hdf5': fc = load_helper.read_force_constants_from_hdf5( filename=force_constants_filename, p2s_map=p2s_map, calculator=calculator) else: fc = parse_FORCE_CONSTANTS(filename=force_constants_filename, p2s_map=p2s_map) phonon.set_force_constants(fc) elif force_sets_filename is not None: _dataset = parse_FORCE_SETS(natom=natom, filename=force_sets_filename) elif os.path.isfile("FORCE_SETS"): _dataset = parse_FORCE_SETS(natom=natom) if _dataset is not None: phonon.dataset = _dataset _produce_force_constants(phonon, fc_calculator)
def set_dataset_and_force_constants( phonon, dataset, fc, # From phonopy_yaml force_constants_filename=None, force_sets_filename=None, fc_calculator=None, fc_calculator_options=None, produce_fc=True, symmetrize_fc=True, is_compact_fc=True, log_level=0): natom = len(phonon.supercell) # dataset and fc are those obtained from phonopy_yaml unless None. if dataset is not None: phonon.dataset = dataset if fc is not None: phonon.force_constants = fc _fc = None _dataset = None if force_constants_filename is not None: _fc = _read_force_constants_file(phonon, force_constants_filename) _force_constants_filename = force_constants_filename elif force_sets_filename is not None: _dataset = parse_FORCE_SETS(natom=natom, filename=force_sets_filename) _force_sets_filename = force_sets_filename elif phonon.forces is None and phonon.force_constants is None: # unless provided these from phonopy_yaml. if os.path.isfile("FORCE_CONSTANTS"): _fc = _read_force_constants_file(phonon, "FORCE_CONSTANTS") _force_constants_filename = "FORCE_CONSTANTS" elif os.path.isfile("force_constants.hdf5"): _fc = _read_force_constants_file(phonon, "force_constants.hdf5") _force_constants_filename = "force_constants.hdf5" elif os.path.isfile("FORCE_SETS"): _dataset = parse_FORCE_SETS(natom=natom) _force_sets_filename = "FORCE_SETS" if _fc is not None: phonon.force_constants = _fc if log_level: print("Force constants were read from \"%s\"." % _force_constants_filename) if phonon.force_constants is None: # Overwrite dataset if _dataset is not None: phonon.dataset = _dataset if log_level: print("Force sets were read from \"%s\"." % _force_sets_filename) if produce_fc: _produce_force_constants(phonon, fc_calculator, fc_calculator_options, symmetrize_fc, is_compact_fc, log_level)
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 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 _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_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 get_phonons(self): """ Calculate the phonon bandstructures along a path """ phonon = self.phonon #get forces force_sets = file_IO.parse_FORCE_SETS(filename='%s/FORCE_SETS' % self.material_id) phonon.set_displacement_dataset(force_sets) #get force constants phonon.produce_force_constants() phonon.symmetrize_force_constants_by_space_group() #get NAC nac_params = file_IO.parse_BORN(phonon.get_primitive(), filename="%s/BORN" % self.material_id) nac_factor = Hartree * Bohr if nac_params['factor'] == None: nac_params['factor'] = nac_factor phonon.set_nac_params(nac_params) #get band-structure phonon.set_band_structure(self.bands, is_eigenvectors=True, is_band_connection=True) phonon.get_band_structure()
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(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_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=os.path.join(data_dir,"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 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 _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_force_sets_from_file(file_name='FORCE_SETS', fs_supercell=None): # Just a wrapper to phonopy function force_sets = ForceSets(parse_FORCE_SETS(filename=file_name)) if fs_supercell is not None: force_sets.set_supercell(fs_supercell) return force_sets
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 __set_ForcesSets(self, filename, phonon): """ sets forces """ force_sets = parse_FORCE_SETS(filename=filename) phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants()
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_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) force_sets = parse_FORCE_SETS(filename=os.path.join(data_dir,"FORCE_SETS_%s" % spgtype)) phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() return 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 load(supercell_matrix, primitive_matrix=None, nac_params=None, unitcell=None, calculator="vasp", unitcell_filename=None, born_filename=None, force_sets_filename=None, force_constants_filename=None, factor=VaspToTHz, frequency_scale_factor=None, symprec=1e-5, is_symmetry=True, log_level=0): if unitcell is None: _unitcell, _ = read_crystal_structure(filename=unitcell_filename, interface_mode=calculator) else: _unitcell = unitcell # units keywords: factor, nac_factor, distance_to_A units = get_default_physical_units(calculator) phonon = Phonopy(_unitcell, supercell_matrix, primitive_matrix=primitive_matrix, factor=units['factor']) if nac_params is None: if born_filename is None: _nac_params = None else: _nac_params = parse_BORN(phonon.primitive, filename=born_filename) else: _nac_params = nac_params if _nac_params is not None: if _nac_params['factor'] is None: _nac_params['factor'] = units['nac_factor'] phonon.set_nac_params(_nac_params) if force_constants_filename is not None: dot_split = force_constants_filename.split('.') p2s_map = phonon.primitive.get_primitive_to_supercell_map() if len(dot_split) > 1 and dot_split[-1] == 'hdf5': fc = read_force_constants_hdf5(filename=force_constants_filename, p2s_map=p2s_map) else: fc = parse_FORCE_CONSTANTS(filename=force_constants_filename, p2s_map=p2s_map) phonon.set_force_constants(fc) elif force_sets_filename is not None: force_sets = parse_FORCE_SETS(filename=force_sets_filename) phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() return phonon
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 get_force_sets_from_file(file_name='FORCE_SETS', fs_supercell=None): # Just a wrapper to phonopy function force_sets = ForceSets(parse_FORCE_SETS(filename=file_name)) if fs_supercell is not None: force_sets.set_supercell(fs_supercell) else: print('No force sets supercell defined, set to identity') force_sets.set_supercell(np.identity(3)) return force_sets
def _get_dynmatrix(self): """Extracts the force constants from `FORCE_SETS` and constructs the dynamical matrix for the calculation. """ with chdir(self.folder): force_sets = file_IO.parse_FORCE_SETS() self.phonopy.set_displacement_dataset(force_sets) self.phonopy.produce_force_constants( calculate_full_force_constants=True, computation_algorithm="svd") self.phonopy._set_dynamical_matrix()
def test_parse_vasprun_xml(self): filename_vasprun = os.path.join(data_dir, "vasprun.xml.tar.bz2") self._tar = tarfile.open(filename_vasprun) filename = os.path.join(data_dir, "FORCE_SETS_NaCl") dataset = parse_FORCE_SETS(filename=filename) for i, member in enumerate(self._tar.getmembers()): vr = Vasprun(self._tar.extractfile(member), use_expat=True) # for force in vr.read_forces(): # print("% 15.8f % 15.8f % 15.8f" % tuple(force)) # print("") ref = dataset['first_atoms'][i]['forces'] np.testing.assert_allclose(ref, vr.read_forces(), atol=1e-8)
def create_FORCES_FC2_from_FORCE_SETS_then_exit(log_level): filename = 'FORCE_SETS' file_exists(filename, log_level) disp_dataset = parse_FORCE_SETS(filename=filename) write_FORCES_FC2(disp_dataset) write_disp_fc2_yaml(disp_dataset, None) if log_level: print("FORCES_FC2 and disp_fc2.yaml have been created from " "FORCE_SETS.") print_end() sys.exit(0)
def read_from_phonopy_file(self, filename): """ Read the force constants from a phonopy FORCE_SETS file :param filename: FORCE_SETS file name """ from phonopy.file_IO import parse_FORCE_SETS data_sets = parse_FORCE_SETS(filename=filename) self.set_data_sets(data_sets) self.set_forces([displacement['forces'] for displacement in data_sets['first_atoms']])
def set_force_constants( phonon, dataset=None, force_constants_filename=None, force_sets_filename=None, calculator=None, use_alm=False): natom = phonon.supercell.get_number_of_atoms() _dataset = None if dataset is not None: _dataset = dataset elif force_constants_filename is not None: dot_split = force_constants_filename.split('.') p2s_map = phonon.primitive.get_primitive_to_supercell_map() if len(dot_split) > 1 and dot_split[-1] == 'hdf5': fc = read_force_constants_from_hdf5( filename=force_constants_filename, p2s_map=p2s_map, calculator=calculator) else: fc = parse_FORCE_CONSTANTS(filename=force_constants_filename, p2s_map=p2s_map) phonon.set_force_constants(fc) elif force_sets_filename is not None: _dataset = parse_FORCE_SETS(natom=natom, filename=force_sets_filename) elif os.path.isfile("FORCE_SETS"): _dataset = parse_FORCE_SETS(natom=natom) if _dataset: phonon.set_displacement_dataset(_dataset) try: phonon.produce_force_constants( calculate_full_force_constants=False, use_alm=use_alm) except RuntimeError: pass
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() filename_born = os.path.join(data_dir, "..", "BORN_NaCl") nac_params = parse_BORN(phonon.get_primitive(), filename=filename_born) phonon.set_nac_params(nac_params) return phonon
def _get_phonon_NaCl(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() filename_born = os.path.join(data_dir, "..", "BORN_NaCl") nac_params = parse_BORN(phonon.get_primitive(), filename=filename_born) phonon.set_nac_params(nac_params) return phonon
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]]) 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() filename_born = os.path.join(data_dir, "../BORN_NaCl") nac_params = parse_BORN(phonon.get_primitive(), filename=filename_born) nac_params['method'] = 'wang' phonon.set_nac_params(nac_params) return phonon
def test_properties(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() dynmat = phonon.dynamical_matrix dynmat.set_dynamical_matrix([0, 0, 0]) self.assertTrue(id(dynmat.primitive) == id(dynmat.get_primitive())) self.assertTrue(id(dynmat.supercell) == id(dynmat.get_supercell())) np.testing.assert_allclose(dynmat.dynamical_matrix, dynmat.get_dynamical_matrix())
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() 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_phonons(self): # calculate the phonon dispersion folder = '%s/gruneisen-00' % material_id ph_yaml = phonopyYaml('%s/phonon.yaml' % folder) atoms = ph_yaml.get_atoms() supercell_matrix = ph_yaml._data['supercell_matrix'] self.phonon = Phonopy(atoms, supercell_matrix) phonon = self.phonon force_sets = file_IO.parse_FORCE_SETS(filename='%s/FORCE_SETS' % folder) phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() phonon.symmetrize_force_constants_by_space_group() phonon.set_band_structure(self.bands, is_eigenvectors=True, is_band_connection=True) phonon.get_band_structure()
def create_FORCES_FC2_from_FORCE_SETS_then_exit(log_level): """Convert FORCE_SETS to FORCES_FC2.""" filename = "FORCE_SETS" file_exists(filename, log_level) disp_dataset = parse_FORCE_SETS(filename=filename) write_FORCES_FC2(disp_dataset) if log_level: print("") print("FORCES_FC2 has been created from FORCE_SETS.") print("The following yaml lines should replace respective part of") print("phono3py_disp.yaml made with --dim-fc2=dim_of_FORCE_SETS.") print("") print("\n".join(displacements_yaml_lines_type1(disp_dataset))) if log_level: print_end() sys.exit(0)
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.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 supercell.get_chemical_symbols()] 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
#!/usr/bin/env python import numpy as np import phonopy.file_IO as file_IO import dynaphopy.interface.iofile as reading import dynaphopy.classes.controller as controller ################################## STRUCTURE FILES ####################################### # 1. Set the directory in where the FORCE_SETS and structure OUTCAR are placed # FORCE_SETS : force set file obtained from PHONOPY calculation # OUTCAR : Single Point calculation of the unit cell structure used in PHONOPY calculation directory ='/home/abel/VASP/Si-phonon/4x4x4B/' structure = reading.read_from_file_structure_poscar(directory+'POSCAR') structure.set_force_set(file_IO.parse_FORCE_SETS(filename=directory+'FORCE_SETS')) ############################### PHONOPY CELL INFORMATION #################################### # 2. Set primitive matrix, this matrix fulfills that: # Primitive_cell = Unit_cell x Primitive_matrix # This matrix is the same needed for PHONOPY calculation structure.set_primitive_matrix([[0.5, 0.0, 0.0], [0.0, 0.5, 0.0], [0.0, 0.0, 0.5]]) # 3. Set super cell phonon, this matrix denotes the super cell used in PHONOPY for creating # the finite displacements
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
from phonopy import Phonopy from phonopy.interface.vasp import read_vasp from phonopy.file_IO import parse_FORCE_SETS, parse_BORN import numpy as np cell = read_vasp("POSCAR") # Initialize phonon. Supercell matrix has to have the shape of (3, 3) phonon = Phonopy(cell, np.diag([2, 2, 1])) symmetry = phonon.get_symmetry() print "Space group:", symmetry.get_international_table() # Read and convert forces and displacements force_sets = parse_FORCE_SETS(cell.get_number_of_atoms() * 4) # Sets of forces have to be set before phonon.set_post_process or # at phonon.set_post_process(..., sets_of_forces=sets_of_forces, ...). phonon.set_force_sets(force_sets) # To activate non-analytical term correction. phonon.set_post_process(primitive_matrix=[[2./3, -1./3, -1./3], [1./3, 1./3, -2./3], [1./3, 1./3, 1./3]]) # Parameters for non-analytical term correction can be set # also after phonon.set_post_process born = parse_BORN(phonon.get_primitive()) phonon.set_nac_params(born) # Example to obtain dynamical matrix dmat = phonon.get_dynamical_matrix_at_q([0,0,0])
curses.endwin() if x2 == ord('3'): calculation.set_number_of_mem_coefficients( int(get_param(screen, "Insert number of coefficients"))) curses.endwin() curses.endwin() #Just for testing if __name__ == 'test_gui.py': import dynaphopy.classes.controller as controller import dynaphopy.functions.iofunctions as reading #Get data from input file input_parameters = reading.read_parameters_from_input_file(sys.argv[1]) structure = reading.read_from_file_structure_outcar(input_parameters['structure_file_name']) structure.set_force_set( file_IO.parse_FORCE_SETS(filename=input_parameters['force_constants_file_name'])) structure.set_primitive_matrix(input_parameters['primitive_matrix']) structure.set_super_cell_phonon(input_parameters['super_cell_matrix']) trajectory_file_name = sys.argv[2] trajectory = reading.read_from_file_trajectory(trajectory_file_name,structure,last_steps=5000) calculation = controller.Calculation(trajectory) calculation.set_band_ranges(input_parameters['bands'])
def get_force_sets_from_file(file_name='FORCE_SETS'): #Just a wrapper to phonopy function force_sets = parse_FORCE_SETS(filename=file_name) return force_sets
from phonopy import Phonopy from phonopy.interface.vasp import read_vasp from phonopy.file_IO import parse_FORCE_SETS from phonopy.file_IO import parse_FORCE_CONSTANTS, write_FORCE_CONSTANTS cell = read_vasp("POSCAR") phonon = Phonopy(cell, [[2, 0, 0], [0, 2, 0], [0, 0, 2]]) force_sets = parse_FORCE_SETS() phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() write_FORCE_CONSTANTS(phonon.get_force_constants(), filename="FORCE_CONSTANTS") force_constants = parse_FORCE_CONSTANTS() phonon.set_force_constants(force_constants) phonon.symmetrize_force_constants(iteration=1) write_FORCE_CONSTANTS(phonon.get_force_constants(), filename="FORCE_CONSTANTS_NEW")
for i in range(51): band.append(np.array(q_start) + (np.array(q_end) - np.array(q_start)) / 50 * i) bands.append(band) phonons = {} for vol in ("orig", "plus", "minus"): unitcell = read_vasp("%s/POSCAR-unitcell" % vol) 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="%s/FORCE_SETS" % vol) phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() phonons[vol] = phonon gruneisen = PhonopyGruneisen(phonons["orig"], phonons["plus"], phonons["minus"]) gruneisen.set_mesh([2, 2, 2]) q_points, _, frequencies, _, gammas = gruneisen.get_mesh() for q, freq, g in zip(q_points, frequencies, gammas): print(("%5.2f %5.2f %5.2f " + (" %7.3f" * len(freq))) % ((q[0], q[1], q[2]) + tuple(freq))) print(((" " * 18) + (" %7.3f" * len(g))) % tuple(g))