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_force_constants3(data_sets, structure, ph_settings): from phono3py.phonon3 import Phono3py from aiida_phonopy.workchains.phonon import phonopy_bulk_from_structure # Generate phonopy phonon object phono3py = Phono3py(phonopy_bulk_from_structure(structure), supercell_matrix=ph_settings.dict.supercell, primitive_matrix=ph_settings.dict.primitive, symprec=ph_settings.dict.symmetry_precision, log_level=1) phono3py.produce_fc3(data_sets.get_forces3(), displacement_dataset=data_sets.get_data_sets3(), is_translational_symmetry=True, is_permutation_symmetry=True, is_permutation_symmetry_fc2=True) fc3 = phono3py.get_fc3() fc2 = phono3py.get_fc2() force_constants_2 = ForceConstantsData(data=fc2) force_constants_3 = ForceConstantsData(data=fc3) return {'force_constants_2order': force_constants_2, 'force_constants_3order': force_constants_3}
def create_supercells_with_displacements_using_phono3py(structure, ph_settings, cutoff): """ Use phono3py 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 :param cutoff: FloatData object containing the value of the cutoff for 3rd order FC in Angstroms (if 0 no cutoff is applied) :return: A set of StructureData Objects containing the supercells with displacements """ from phono3py.phonon3 import Phono3py from aiida_phonopy.workchains.phonon import phonopy_bulk_from_structure # Generate phonopy phonon object phono3py = Phono3py(phonopy_bulk_from_structure(structure), supercell_matrix=ph_settings.dict.supercell, primitive_matrix=ph_settings.dict.primitive, symprec=ph_settings.dict.symmetry_precision, log_level=1) if float(cutoff) == 0: cutoff = None else: cutoff = float(cutoff) phono3py.generate_displacements(distance=ph_settings.dict.distance, cutoff_pair_distance=cutoff) cells_with_disp = phono3py.get_supercells_with_displacements() # Transform cells to StructureData and set them ready to return data_sets = phono3py.get_displacement_dataset() data_sets_object = ForceSetsData(data_sets3=data_sets) disp_cells = {'data_sets': data_sets_object} for i, phonopy_supercell in enumerate(cells_with_disp): if phonopy_supercell is None: print ('structure_{} cutoff skip'.format(i)) continue 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_commensurate(structure, ph_settings): from phonopy import Phonopy from phonopy.harmonic.dynmat_to_fc import DynmatToForceConstants from aiida_phonopy.workchains.phonon import phonopy_bulk_from_structure phonon = Phonopy(phonopy_bulk_from_structure(structure), ph_settings.dict.supercell, primitive_matrix=ph_settings.dict.primitive, symprec=ph_settings.dict.symmetry_precision) primitive = phonon.get_primitive() supercell = phonon.get_supercell() dynmat2fc = DynmatToForceConstants(primitive, supercell) commensurate = dynmat2fc.get_commensurate_points() return dynmat2fc, commensurate
def get_phonon(structure, force_constants, ph_settings, nac_data=None): from phonopy import Phonopy from aiida_phonopy.workchains.phonon import phonopy_bulk_from_structure phonon = Phonopy(phonopy_bulk_from_structure(structure), ph_settings.dict.supercell, primitive_matrix=ph_settings.dict.primitive, symprec=ph_settings.dict.symmetry_precision) if force_constants is not None: phonon.set_force_constants(force_constants.get_data()) if nac_data is not None: primitive = phonon.get_primitive() nac_parameters = nac_data.get_born_parameters_phonopy(primitive_cell=primitive.get_cell()) phonon.set_nac_params(nac_parameters) return phonon
def get_grid_points(structure, parameters): from phono3py.phonon3 import Phono3py from phono3py.cui.triplets_info import get_coarse_ir_grid_points from aiida_phonopy.workchains.phonon import phonopy_bulk_from_structure # Generate phonopy phonon object phono3py = Phono3py(phonopy_bulk_from_structure(structure), supercell_matrix=parameters.dict.supercell, primitive_matrix=parameters.dict.primitive, symprec=parameters.dict.symmetry_precision, log_level=1) primitive = phono3py.get_primitive() (ir_grid_points, grid_weights, bz_grid_address, grid_mapping_table) = get_coarse_ir_grid_points(primitive, parameters.dict.mesh, None, None, is_kappa_star=True, symprec=1e-5) return ir_grid_points
def get_disp_fc3_txt(structure, parameters_data, force_sets): from phono3py.file_IO import write_cell_yaml from phonopy.structure.cells import get_supercell from aiida_phonopy.workchains.phonon import phonopy_bulk_from_structure import StringIO dataset = force_sets.get_data_sets3() supercell = get_supercell(phonopy_bulk_from_structure(structure), parameters_data.dict.supercell, symprec=parameters_data.dict.symmetry_precision) w = StringIO.StringIO() w.write("natom: %d\n" % dataset['natom']) num_first = len(dataset['first_atoms']) w.write("num_first_displacements: %d\n" % num_first) if 'cutoff_distance' in dataset: w.write("cutoff_distance: %f\n" % dataset['cutoff_distance']) num_second = 0 num_disp_files = 0 for d1 in dataset['first_atoms']: num_disp_files += 1 num_second += len(d1['second_atoms']) for d2 in d1['second_atoms']: if 'included' in d2: if d2['included']: num_disp_files += 1 else: num_disp_files += 1 w.write("num_second_displacements: %d\n" % num_second) w.write("num_displacements_created: %d\n" % num_disp_files) w.write("first_atoms:\n") count1 = 1 count2 = num_first + 1 for disp1 in dataset['first_atoms']: disp_cart1 = disp1['displacement'] w.write("- number: %5d\n" % (disp1['number'] + 1)) w.write(" displacement:\n") w.write(" [%20.16f,%20.16f,%20.16f ] # %05d\n" % (disp_cart1[0], disp_cart1[1], disp_cart1[2], count1)) w.write(" second_atoms:\n") count1 += 1 included = None distance = 0.0 atom2 = -1 for disp2 in disp1['second_atoms']: if atom2 != disp2['number']: atom2 = disp2['number'] if 'included' in disp2: included = disp2['included'] pair_distance = disp2['pair_distance'] w.write(" - number: %5d\n" % (atom2 + 1)) w.write(" distance: %f\n" % pair_distance) if included is not None: if included: w.write(" included: %s\n" % "true") else: w.write(" included: %s\n" % "false") w.write(" displacements:\n") disp_cart2 = disp2['displacement'] w.write(" - [%20.16f,%20.16f,%20.16f ] # %05d\n" % (disp_cart2[0], disp_cart2[1], disp_cart2[2], count2)) count2 += 1 write_cell_yaml(w, supercell) w.seek(0) lines = w.read() w.close() return lines
################################ wc = load_node(int(sys.argv[1])) ################################ # get phono3py data from database force_sets = wc.out.force_sets structure = wc.out.final_structure ph_settings = wc.inp.ph_settings # If modifications in phonon parameters are necessary ph_settings_dict = ph_settings.get_dict() ph_settings_dict['mesh'] = [40, 40, 40] ph_settings = ParameterData(dict=ph_settings_dict) # Create phono3py and calculate as usual phono3py = Phono3py(phonopy_bulk_from_structure(structure), supercell_matrix=ph_settings.dict.supercell, primitive_matrix=ph_settings.dict.primitive, symprec=ph_settings.dict.symmetry_precision, mesh=ph_settings.dict.mesh, log_level=1) phono3py.produce_fc3(force_sets.get_forces3(), displacement_dataset=force_sets.get_data_sets3(), is_translational_symmetry=True, is_permutation_symmetry=True, is_permutation_symmetry_fc2=True) fc3 = phono3py.get_fc3() fc2 = phono3py.get_fc2()
if len(sys.argv) < 2: print('use: python get_phonon3py_inputs.py {pk_number}') exit() # Set WorkChain phonon3 PK number ################################ wc = load_node(int(sys.argv[1])) ################################ # get phono3py data from database force_sets = wc.out.force_sets structure = wc.out.final_structure ph_settings = wc.inp.ph_settings supercell = get_supercell(phonopy_bulk_from_structure(structure), ph_settings.dict.supercell, symprec=ph_settings.dict.symmetry_precision) write_disp_fc3_yaml(force_sets.get_data_sets3(), supercell, filename='disp_fc3.yaml') write_FORCES_FC3(force_sets.get_data_sets3(), force_sets.get_forces3(), filename='FORCES_FC3') with open('POSCAR-unitcell', mode='w') as f: f.writelines(get_poscar_txt(structure)) if 'nac_data' in wc.get_outputs_dict():
mode_kappa = wc.out.kappa.get_array('mode_kappa')[:] mesh = wc.out.kappa.get_array('mesh') qpoint = wc.out.kappa.get_array('qpoint') print mode_kappa.shape structure = wc.out.final_structure from phono3py.phonon3.triplets import (get_ir_grid_points, get_grid_points_by_rotations, get_grid_address, from_coarse_to_dense_grid_points) # May change grid_address = get_grid_address(mesh) ir_grid_points = np.arange(np.prod(mesh), dtype='intc') grid_mapping_table = np.arange(np.prod(mesh), dtype='intc') from aiida_phonopy.workchains.phonon import phonopy_bulk_from_structure kappados = KappaDOS(mode_kappa=mode_kappa, cell=phonopy_bulk_from_structure(structure), frequencies=frequency, mesh=mesh, grid_address=grid_address, ir_grid_points=ir_grid_points, grid_mapping_table=grid_mapping_table, num_sampling_points=100) print kappados.get_kdos()