def _convert_unit_in_dataset(dataset, calculator): physical_units = get_default_physical_units(calculator) force_to_eVperA = physical_units['force_to_eVperA'] distance_to_A = physical_units['distance_to_A'] if 'first_atoms' in dataset: for d1 in dataset['first_atoms']: if distance_to_A is not None: disp = _to_ndarray(d1['displacement']) d1['displacement'] = disp * distance_to_A if force_to_eVperA is not None and 'forces' in d1: forces = _to_ndarray(d1['forces']) d1['forces'] = forces * force_to_eVperA if 'second_atoms' in d1: for d2 in d1['second_atoms']: if distance_to_A is not None: disp = _to_ndarray(d2['displacement']) d2['displacement'] = disp * distance_to_A if force_to_eVperA is not None and 'forces' in d2: forces = _to_ndarray(d2['forces']) d2['forces'] = forces * force_to_eVperA else: if distance_to_A is not None and 'displacements' in dataset: disp = _to_ndarray(dataset['displacements']) dataset['displacements'] = disp * distance_to_A if force_to_eVperA is not None and 'forces' in dataset: forces = _to_ndarray(dataset['forces']) dataset['forces'] = forces * force_to_eVperA
def _convert_unit_in_dataset(dataset, calculator): physical_units = get_default_physical_units(calculator) force_to_eVperA = physical_units["force_to_eVperA"] distance_to_A = physical_units["distance_to_A"] if "first_atoms" in dataset: for d1 in dataset["first_atoms"]: if distance_to_A is not None: disp = _to_ndarray(d1["displacement"]) d1["displacement"] = disp * distance_to_A if force_to_eVperA is not None and "forces" in d1: forces = _to_ndarray(d1["forces"]) d1["forces"] = forces * force_to_eVperA if "second_atoms" in d1: for d2 in d1["second_atoms"]: if distance_to_A is not None: disp = _to_ndarray(d2["displacement"]) d2["displacement"] = disp * distance_to_A if force_to_eVperA is not None and "forces" in d2: forces = _to_ndarray(d2["forces"]) d2["forces"] = forces * force_to_eVperA else: if distance_to_A is not None and "displacements" in dataset: disp = _to_ndarray(dataset["displacements"]) dataset["displacements"] = disp * distance_to_A if force_to_eVperA is not None and "forces" in dataset: forces = _to_ndarray(dataset["forces"]) dataset["forces"] = forces * force_to_eVperA
def init_phono3py(settings, cell_info, interface_mode, output_filename, symprec, log_level): physical_units = get_default_physical_units(interface_mode) distance_to_A = physical_units['distance_to_A'] # Change unit of lattice parameters to angstrom unitcell = cell_info['unitcell'].copy() if distance_to_A is not None: lattice = unitcell.cell lattice *= distance_to_A unitcell.cell = lattice # updated_settings keys # ('grid_points', 'sigmas', 'temperature_points', 'temperatures', # 'frequency_factor_to_THz', 'num_frequency_points', # 'frequency_step', 'frequency_scale_factor', # 'cutoff_frequency') updated_settings = get_default_values(settings) phono3py = Phono3py( unitcell, cell_info['supercell_matrix'], primitive_matrix=cell_info['primitive_matrix'], phonon_supercell_matrix=cell_info['phonon_supercell_matrix'], masses=settings.masses, mesh=settings.mesh_numbers, band_indices=settings.band_indices, sigmas=updated_settings['sigmas'], sigma_cutoff=settings.sigma_cutoff_width, cutoff_frequency=updated_settings['cutoff_frequency'], frequency_factor_to_THz=updated_settings['frequency_factor_to_THz'], is_symmetry=settings.is_symmetry, is_mesh_symmetry=settings.is_mesh_symmetry, symmetrize_fc3q=settings.is_symmetrize_fc3_q, symprec=symprec, calculator=interface_mode, log_level=log_level, lapack_zheev_uplo=settings.lapack_zheev_uplo) check_supercell_in_yaml(cell_info, phono3py, log_level) if cell_info['phonopy_yaml'] is not None: if (cell_info['phonopy_yaml'].phonon_supercell is not None and phono3py.phonon_supercell is not None): if not cells_isclose(cell_info['phonopy_yaml'].phonon_supercell, phono3py.phonon_supercell): if log_level: print("Generated phonon supercell is inconsistent with " "that in \"%s\"." % cell_info['optional_structure_info'][0]) print_error() sys.exit(1) return phono3py, updated_settings
def finalize_phono3py( phono3py: Phono3py, confs_dict, log_level, displacements_mode=False, filename=None, ): """Write phono3py.yaml and then exit. Parameters ---------- phono3py : Phono3py Phono3py instance. confs_dict : dict This contains the settings and command options that the user set. log_level : int Log level. 0 means quiet. displacements_mode : Bool When True, crystal structure is written in the length unit of calculator interface in phono3py_disp.yaml. Otherwise, the default unit (angstrom) is used. filename : str, optional phono3py.yaml is written in this filename. """ if filename is None: yaml_filename = "phono3py.yaml" else: yaml_filename = filename if displacements_mode: _calculator = phono3py.calculator else: _calculator = None _physical_units = get_default_physical_units(_calculator) yaml_settings = {"force_sets": False, "displacements": displacements_mode} ph3py_yaml = Phono3pyYaml(configuration=confs_dict, physical_units=_physical_units, settings=yaml_settings) ph3py_yaml.set_phonon_info(phono3py) ph3py_yaml.calculator = _calculator with open(yaml_filename, "w") as w: w.write(str(ph3py_yaml)) if log_level > 0: print("") if displacements_mode: print(f'Displacement dataset was written in "{yaml_filename}".') else: print(f'Summary of calculation was written in "{yaml_filename}".') print_end() sys.exit(0)
def get_phonopy_instance(structure, phonon_settings_dict, params): from phonopy import Phonopy phonon = Phonopy(phonopy_atoms_from_structure(structure), supercell_matrix=phonon_settings_dict['supercell_matrix'], primitive_matrix='auto', symprec=phonon_settings_dict['symmetry_tolerance']) if 'nac_params' in params: from phonopy.interface.calculator import get_default_physical_units units = get_default_physical_units('vasp') factor = units['nac_factor'] nac_params = { 'born': params['nac_params'].get_array('born_charges'), 'dielectric': params['nac_params'].get_array('epsilon'), 'factor': factor } phonon.nac_params = nac_params return phonon
def init_phono3py(settings, cell_info, interface_mode, symprec, log_level): """Initialize phono3py and update settings by default values.""" physical_units = get_default_physical_units(interface_mode) distance_to_A = physical_units["distance_to_A"] # Change unit of lattice parameters to angstrom unitcell = cell_info["unitcell"].copy() if distance_to_A is not None: lattice = unitcell.cell lattice *= distance_to_A unitcell.cell = lattice # updated_settings keys # ('sigmas', 'temperature_points', 'temperatures', # 'frequency_factor_to_THz', 'num_frequency_points', # 'frequency_step', 'frequency_scale_factor', # 'cutoff_frequency') updated_settings = get_default_values(settings) phono3py = Phono3py( unitcell, cell_info["supercell_matrix"], primitive_matrix=cell_info["primitive_matrix"], phonon_supercell_matrix=cell_info["phonon_supercell_matrix"], cutoff_frequency=updated_settings["cutoff_frequency"], frequency_factor_to_THz=updated_settings["frequency_factor_to_THz"], is_symmetry=settings.is_symmetry, is_mesh_symmetry=settings.is_mesh_symmetry, use_grg=settings.use_grg, store_dense_gp_map=(not settings.emulate_v1), store_dense_svecs=(not settings.emulate_v1), symprec=symprec, calculator=interface_mode, log_level=log_level, ) phono3py.masses = settings.masses phono3py.band_indices = settings.band_indices phono3py.sigmas = updated_settings["sigmas"] phono3py.sigma_cutoff = settings.sigma_cutoff_width check_supercell_in_yaml(cell_info, phono3py, distance_to_A, log_level) return phono3py, updated_settings
def run_task(self, fw_spec): unitcell = read_vasp("POSCAR-unitcell") phonon = phonopy.Phonopy(unitcell, self.get("supercell")) supercell = phonon.get_supercell() phonon.generate_displacements() supercells = phonon.supercells_with_displacements ids = np.arange(len(supercells)) + 1 write_supercells_with_displacements(supercell, supercells, ids) units = get_default_physical_units("vasp") phpy_yaml = PhonopyYaml(physical_units=units, settings={ 'force_sets': False, 'born_effective_charge': False, 'dielectric_constant': False, 'displacements': True }) phpy_yaml.set_phonon_info(phonon) with open("phonopy_disp.yaml", 'w') as w: w.write(str(phpy_yaml))
# g_min = -12.4 g_max = None g_min = None # f_max = 5.5 # f_min = -0.25 f_max = None f_min = None if nac: from phonopy.interface.vasp import get_born_vasprunxml born_chg, eps, _ = get_born_vasprunxml( is_symmetry=False, symmetrize_tensors=True, ) from phonopy.interface.calculator import get_default_physical_units nac_factor = get_default_physical_units('vasp')['nac_factor'] nac_params = { 'born': born_chg, 'dielectric': eps, 'factor': nac_factor, # 'method':'wang', } else: nac_params = None from os import environ environ['CUDA_VISIBLE_DEVICES'] = '' from phonopy.interface import vasp atoms = vasp.read_vasp(unitcell_f) from phono3py import Phono3py
def phonopy_to_abinit(unit_cell, supercell_matrix, out_ddb_path, ngqpt=None, qpt_list=None, force_constants=None, force_sets=None, born=None, primitive_matrix="auto", symprec=1e-5, tolsym=None, supercell=None, calculator=None, manager=None, workdir=None, pseudos=None, verbose=False): """ Converts the data from phonopy to an abinit DDB file. The data can be provided in form of arrays or paths to the phonopy files that should be parsed. The minimal input should contains the FORCE_CONSTANTS or FORCE_SETS. If BORN is present the Born effective charges (BEC) and dielectric tensor will also be added to the DDB. The best agreement is obtained with supercell_matrix and ngqpt being equivalent (i.e. supercell_matrix a diagonal matrix with ngqpt as diagonal elements). Non diagonal supercell_matrix are allowed as well, but the information encoded in the DDB will be the result of an interpolation done through phonopy. Phonopy is used to convert the IFC to the dynamical matrix. However, in order to determine the list of q-points in the irreducible Brillouin zone and to prepare the base for the final DDB file, abinit will be called for a very short and inexpensive run. Performs a check to verify if the two codes identify the same symmetries and it gives a warning in case of failure. Mismatching symmetries may lead to incorrect conversions. Args: unit_cell: a |Structure| object that identifies the unit cell used for the phonopy calculation. supercell_matrix: a 3x3 array representing the supercell matrix used to generated the forces with phonopy. out_ddb_path: a full path to the file where the new DDB will be written ngqpt: a list of 3 elements indicating the grid of q points that will be used in the DDB. qpt_list: alternatively to ngqpt an explicit list of q-points can be provided here. At least one among ngqpt and qpt_list should be defined. force_constants: an array with shape (num atoms unit cell, num atoms supercell, 3, 3) containing the force constants. Alternatively a string with the path to the FORCE_CONSTANTS file. This or force_set should be defined. If both given this has precedence. force_sets: a dictionary obtained from the force sets generated with phonopy. Alternatively a string with the path to the FORCE_SETS file. This or force_constants should be defined. born: a dictionary with "dielectric" and "born" keywords as obtained from the nac_params in phonopy. Alternatively a string with the path to the BORN file. Notice that the "factor" attribute is not taken into account, so the values should be in default phonopy units. primitive_matrix: a 3x3 array with the primitive matrix passed to Phonopy. "auto" will use spglib to try to determine it automatically. If the DDB file should contain the actual unit cell this should be the identity matrix. symprec: distance tolerance in Cartesian coordinates to find crystal symmetry in phonopy. It might be that the value should be tuned so that it leads to the the same symmetries as in the abinit calculation. tolsym: Gives the tolerance to identify symmetries in abinit. See abinit documentation for more details. supercell: if given it should represent the supercell used to get the force constants, without any perturbation. It will be used to match it to the phonopy supercell and sort the IFC in the correct order. calculator: a string with the name of the calculator. Will be used to set the conversion factor for the force constants coming from phonopy. manager: |TaskManager| object. If None, the object is initialized from the configuration file pseudos: List of filenames or list of |Pseudo| objects or |PseudoTable| object. It will be used by abinit to generate the base DDB file. If None the abipy.data.hgh_pseudos.HGH_TABLE table will be used. verbose: verbosity level. Set it to a value > 0 to get more information workdir: path to the directory where the abinit calculation will be executed. Returns: a DdbFile instance of the file written in out_ddb_path. """ if ngqpt is None and qpt_list is None: raise ValueError( "at least one among nqgpt and qpt_list should be defined") if force_sets is None and force_constants is None: raise ValueError( "at least one of force_sets and force_constants should be provided" ) phon_at = get_phonopy_structure(unit_cell) if isinstance(force_constants, str): force_constants = parse_FORCE_CONSTANTS(filename=force_constants) elif force_constants is not None: force_constants = np.array(force_constants) force_sets = None if isinstance(force_sets, str): force_sets = parse_FORCE_SETS(filename=force_sets) # no nac_params here, otherwise they will be used for the interpolation phonon = Phonopy(phon_at, supercell_matrix, primitive_matrix=primitive_matrix, nac_params=None, symprec=symprec, calculator=calculator) primitive = get_pmg_structure(phonon.primitive) if isinstance(born, str): born = parse_BORN(phonon.primitive, filename=born) if supercell is not None: ph_supercell = get_pmg_structure(phonon.supercell) if not np.allclose(supercell.lattice.matrix, ph_supercell.lattice.matrix): raise RuntimeError("The lattice of the supercells do not match") sc_mapping = [] for i, site_orig in enumerate(supercell): for j, site_ph in enumerate(ph_supercell): d = supercell.lattice.get_distance_and_image( site_orig.frac_coords, site_ph.frac_coords)[0] if d < 1e-5: sc_mapping.append(j) break else: raise RuntimeError( f"Could not find a match for site {i} with coords " f"{site_orig.cart_coords} in the supercell.") # cross check that the same atom was not matched twice n_matches = len(set(sc_mapping)) if n_matches < len(supercell): raise RuntimeError( f"Found matches for {n_matches} different atoms in the supercell: {sc_mapping}" ) force_constants = force_constants[:, sc_mapping] if force_constants is not None: phonon.set_force_constants(force_constants) else: phonon.dataset = force_sets phonon.produce_force_constants() if calculator: units = get_default_physical_units(calculator) fc_factor = get_force_constant_conversion_factor( units["force_constants_unit"], None) phonon.set_force_constants(phonon.force_constants * fc_factor) if pseudos is None: from abipy.data.hgh_pseudos import HGH_TABLE pseudos = HGH_TABLE inp = minimal_scf_input(primitive, pseudos) # get the qpoints list if not defined if qpt_list is None: inp["ngkpt"] = ngqpt qpt_list = inp.abiget_ibz(verbose=verbose)[0] dm_list = get_dm(phonon, qpt_list, primitive) if born is not None: # for the conversion of the BEC the zion (i.e. the ionic charge of the pseudo) # it is an additive factor and should be the same that goes in the header of the DDB, # so take it from the pseudos used to generate it. zion = inp.valence_electrons_per_atom born_data = generate_born_deriv(born, zion, primitive) else: born_data = None inp = minimal_scf_input(primitive, pseudos) if tolsym is not None: inp["tolsym"] = tolsym task = inp.run_in_shell(workdir=workdir, manager=manager, verbose=verbose) # use the output of abinit to check that the spacegroup identified by # phonopy and abinit are the same. with GsrFile(task.opath_from_ext("GSR.nc")) as gsr: abi_spg = gsr.structure.abi_spacegroup.spgid spglib_spg = phonon.symmetry.dataset["number"] if abi_spg != spglib_spg: warnings.warn( "The space group number obtained based on the DDB symmetries differs " f"from the one calculated with spglib: {abi_spg} versus " f"{spglib_spg}. The convertion may be incorrect. Try changing symprec or tolsym." ) tmp_ddb_path = task.opath_from_ext("DDB") ddb = DdbFile(tmp_ddb_path) # remove the blocks generated by the calculation and that are meaningless ddb.remove_block(dord=0) ddb.remove_block(dord=1) add_data_ddb(ddb, dm_list, qpt_list, born_data) ddb.write(out_ddb_path) new_ddb = DdbFile(out_ddb_path) return new_ddb
def load( phonopy_yaml=None, # phonopy.yaml-like must be the first argument. supercell_matrix=None, primitive_matrix=None, is_nac=True, calculator=None, unitcell=None, supercell=None, nac_params=None, unitcell_filename=None, supercell_filename=None, born_filename=None, force_sets_filename=None, force_constants_filename=None, fc_calculator=None, factor=None, frequency_scale_factor=None, symprec=1e-5, is_symmetry=True, log_level=0): """Create Phonopy instance from parameters and/or input files. When unitcell and unitcell_filename are not given, file name that is default for the chosen calculator is looked for in the current directory as the default behaviour. When force_sets_filename and force_constants_filename are not given, 'FORCE_SETS' is looked for in the current directory as the default behaviour. Parameters ---------- phonopy_yaml : str, optional Filename of "phonopy.yaml"-like file. If this is given, the data in the file are parsed. Default is None. supercell_matrix : array_like, optional Supercell matrix multiplied to input cell basis vectors. shape=(3, ) or (3, 3), where the former is considered a diagonal matrix. Default is the unit matrix. dtype=int primitive_matrix : array_like or str, optional Primitive matrix multiplied to input cell basis vectors. Default is the identity matrix. shape=(3, 3) dtype=float When 'F', 'I', 'A', 'C', or 'R' is given instead of a 3x3 matrix, the primitive matrix defined at https://atztogo.github.io/spglib/definition.html is used. is_nac : bool, optional If True, look for 'BORN' file. If False, NAS is turned off. The priority for NAC is nac_params > born_filename > is_nac ('BORN'). Default is True. calculator : str, optional. Calculator used for computing forces. This is used to switch the set of physical units. Default is None, which is equivalent to "vasp". unitcell : PhonopyAtoms, optional Input unit cell. Default is None. The priority for cell is unitcell_filename > supercell_filename > unitcell > supercell. supercell : PhonopyAtoms, optional Input supercell cell. Default value of primitive_matrix is set to 'auto' (can be overwitten). supercell_matrix is ignored. Default is None. The priority for cell is unitcell_filename > supercell_filename > unitcell > supercell. nac_params : dict, optional Parameters required for non-analytical term correction. Default is None. The priority for NAC is nac_params > born_filename > is_nac. {'born': Born effective charges (array_like, shape=(primitive cell atoms, 3, 3), dtype=float), 'dielectric': Dielectric constant matrix (array_like, shape=(3, 3), dtype=float), 'factor': unit conversion facotr (float)} unitcell_filename : str, optional Input unit cell filename. Default is None. The priority for cell is unitcell_filename > supercell_filename > unitcell > supercell. supercell_filename : str, optional Input supercell filename. Default value of primitive_matrix is set to 'auto' (can be overwitten). supercell_matrix is ignored. Default is None. The priority for cell is unitcell_filename > supercell_filename > unitcell > supercell. born_filename : str, optional Filename corresponding to 'BORN', a file contains non-analytical term correction parameters. The priority for NAC is nac_params > born_filename > is_nac ('BORN'). force_sets_filename : str, optional Filename of a file corresponding to 'FORCE_SETS', a file contains sets of forces and displacements. Default is None. The priority for force constants is force_constants_filename > force_sets_filename > 'FORCE_SETS'. force_constants_filename : str, optional Filename of a file corresponding to 'FORCE_CONSTANTS' or 'force_constants.hdf5', a file contains force constants. Default is None. The priority for force constants is force_constants_filename > force_sets_filename > 'FORCE_SETS'. fc_calculator : str, optional Force constants calculator. Currently only 'alm'. Default is None. factor : float, optional Phonon frequency unit conversion factor. Unless specified, default unit conversion factor for each calculator is used. frequency_scale_factor : float, optional Factor multiplied to calculated phonon frequency. Default is None, i.e., effectively 1. symprec : float, optional Tolerance used to find crystal symmetry. Default is 1e-5. is_symmetry : bool, optional Setting False, crystal symmetry except for lattice translation is not considered. Default is True. log_level : int, optional Verbosity control. Default is 0. """ if phonopy_yaml is None: cell, smat, pmat = load_helper.get_cell_settings( supercell_matrix=supercell_matrix, primitive_matrix=primitive_matrix, unitcell=unitcell, supercell=supercell, unitcell_filename=unitcell_filename, supercell_filename=supercell_filename, calculator=calculator, symprec=symprec) _nac_params = nac_params _dataset = None _fc = None else: phpy_yaml = PhonopyYaml() phpy_yaml.read(phonopy_yaml) cell = phpy_yaml.unitcell smat = phpy_yaml.supercell_matrix if smat is None: smat = np.eye(3, dtype='intc', order='C') if primitive_matrix is 'auto': pmat = 'auto' else: pmat = phpy_yaml.primitive_matrix if is_nac: _nac_params = phpy_yaml.nac_params else: _nac_params = None _dataset = phpy_yaml.dataset _fc = phpy_yaml.force_constants # units keywords: factor, nac_factor, distance_to_A units = get_default_physical_units(calculator) if factor is None: _factor = units['factor'] else: _factor = factor phonon = Phonopy(cell, smat, primitive_matrix=pmat, factor=_factor, frequency_scale_factor=frequency_scale_factor, symprec=symprec, is_symmetry=is_symmetry, calculator=calculator, log_level=log_level) load_helper.set_nac_params(phonon, _nac_params, born_filename, is_nac, units['nac_factor']) if _fc is None: load_helper.set_force_constants( phonon, dataset=_dataset, force_constants_filename=force_constants_filename, force_sets_filename=force_sets_filename, calculator=calculator, fc_calculator=fc_calculator) else: phonon.force_constants = _fc return phonon
force_gap_scells = api_q.calc_force_sets_GAP(gp_xml_file, Scells_quippy) #parse force set and calc force constants phonon_scell.set_forces(force_gap_scells) PhonIO.write_FORCE_SETS(phonon_scell.get_displacement_dataset() ) # write forces & displacements to FORCE_SET force_set = PhonIO.parse_FORCE_SETS() # parse force_sets phonon_scell.set_displacement_dataset( force_set) # force_set is a list of forces and displacements if NAC == True: nac_params = PhonIO.get_born_parameters( open("BORN"), phonon_scell.get_primitive(), phonon_scell.get_primitive_symmetry()) if nac_params['factor'] == None: physical_units = get_default_physical_units(interface_mode) nac_params['factor'] = physical_units['nac_factor'] phonon_scell._nac_params = nac_params phonon_scell.produce_force_constants() phonon_scell.symmetrize_force_constants() api_ph.write_ShengBTE_FC2(phonon_scell.get_force_constants(), filename='FORCE_CONSTANTS_2ND') # phonopy 2.7 changed format, ShengBTE won't read, use the file in api_qpv to write. # calc and plot bandstructure bands = api_ph.qpoints_Band_paths(Qpoints, Band_points) phonon_scell.set_band_structure(bands, is_eigenvectors=True, labels=band_labels) phonon_scell.write_yaml_band_structure()
def load( phono3py_yaml=None, # phono3py.yaml-like must be the first argument. supercell_matrix=None, primitive_matrix=None, phonon_supercell_matrix=None, mesh=None, is_nac=True, calculator=None, unitcell=None, supercell=None, nac_params=None, unitcell_filename=None, supercell_filename=None, born_filename=None, forces_fc3_filename=None, forces_fc2_filename=None, fc3_filename=None, fc2_filename=None, fc_calculator=None, factor=None, frequency_scale_factor=None, is_symmetry=True, is_mesh_symmetry=True, symprec=1e-5, log_level=0): """Create Phono3py instance from parameters and/or input files. When unitcell and unitcell_filename are not given, file name that is default for the chosen calculator is looked for in the current directory as the default behaviour. When force_sets_filename and force_constants_filename are not given, 'FORCES_FC3' and 'FORCES_FC2' are looked for in the current directory as the default behaviour. Parameters ---------- phono3py_yaml : str, optional Filename of "phono3py.yaml"-like file. If this is given, the data in the file are parsed. Default is None. supercell_matrix : array_like, optional Supercell matrix multiplied to input cell basis vectors. shape=(3, ) or (3, 3), where the former is considered a diagonal matrix. Default is the unit matrix. dtype=int primitive_matrix : array_like or str, optional Primitive matrix multiplied to input cell basis vectors. Default is the identity matrix. Default is None, which is equivalent to 'auto'. shape=(3, 3), dtype=float. When 'F', 'I', 'A', 'C', or 'R' is given instead of a 3x3 matrix, the primitive matrix defined at https://atztogo.github.io/spglib/definition.html is used. phonon_supercell_matrix : array_like, optional Supercell matrix used for fc2. In phono3py, supercell matrix for fc3 and fc2 can be different to support longer range interaction of fc2 than that of fc3. Unless setting this, supercell_matrix is used. This is only valide when unitcell or unitcell_filename is given. Default is None. mesh : array_like, optional Grid mesh numbers in reciprocal cell. shape=(3,), dtype='intc' is_nac : bool, optional If True, look for 'BORN' file. If False, NAS is turned off. The priority for NAC is nac_params > born_filename > is_nac ('BORN'). Default is True. calculator : str, optional. Calculator used for computing forces. This is used to switch the set of physical units. Default is None, which is equivalent to "vasp". unitcell : PhonopyAtoms, optional Input unit cell. Default is None. The priority for cell is unitcell_filename > supercell_filename > unitcell > supercell. supercell : PhonopyAtoms, optional Input supercell. Default value of primitive_matrix is set to 'auto' (can be overwitten). supercell_matrix is ignored. Default is None. The priority for cell is unitcell_filename > supercell_filename > unitcell > supercell. nac_params : dict, optional Parameters required for non-analytical term correction. Default is None. The priority for NAC is nac_params > born_filename > is_nac. {'born': Born effective charges (array_like, shape=(primitive cell atoms, 3, 3), dtype=float), 'dielectric': Dielectric constant matrix (array_like, shape=(3, 3), dtype=float), 'factor': unit conversion facotr (float)} unitcell_filename : str, optional Input unit cell filename. Default is None. The priority for cell is unitcell_filename > supercell_filename > unitcell > supercell. supercell_filename : str, optional Input supercell filename. When this is specified, supercell_matrix is ignored. Default is None. The priority for cell is 1. unitcell_filename (with supercell_matrix) 2. supercell_filename 3. unitcell (with supercell_matrix) 4. supercell. born_filename : str, optional Filename corresponding to 'BORN', a file contains non-analytical term correction parameters. The priority for NAC is nac_params > born_filename > is_nac ('BORN'). forces_fc3_filename : str, optional Filename of a file corresponding to 'FORCES_FC3', a file contains sets of forces or optionally displacements (type-2). Default is None. The priority for force constants is fc3_filename > forces_fc3_filename > 'fc3.hdf5' > 'FORCES_FC3'. forces_fc2_filename : str, optional Filename of a file corresponding to 'FORCES_FC2', a file contains sets of forces or optionally displacements (type-2). Default is None. The priority for force constants is fc2_filename > forces_fc2_filename > 'fc2.hdf5' > 'FORCES_FC2'. fc3_filename : str, optional Filename of a file corresponding to 'fc3.hdf5', a file contains third-order force constants. Default is None. The priority for force constants is fc3_filename > forces_fc3_filename > 'fc3.hdf5' > 'FORCES_FC3'. fc2_filename : str, optional Filename of a file corresponding to 'fc2.hdf5', a file contains second-order force constants. Default is None. The priority for force constants is fc2_filename > forces_fc2_filename > 'fc2.hdf5' > 'FORCES_FC2'. fc_calculator : str, optional Force constants calculator. Currently only 'alm'. Default is None. factor : float, optional Phonon frequency unit conversion factor. Unless specified, default unit conversion factor for each calculator is used. frequency_scale_factor : float, optional Factor multiplied to calculated phonon frequency. Default is None, i.e., effectively 1. is_symmetry : bool, optional Setting False, crystal symmetry except for lattice translation is not considered. Default is True. is_mesh_symmetry : bool, optional Setting False, reciprocal mesh symmetry is not considered. Default is True. symprec : float, optional Tolerance used to find crystal symmetry. Default is 1e-5. log_level : int, optional Verbosity control. Default is 0. """ if phono3py_yaml is None: cell, smat, pmat = load_helper.get_cell_settings( supercell_matrix=supercell_matrix, primitive_matrix=primitive_matrix, unitcell=unitcell, supercell=supercell, unitcell_filename=unitcell_filename, supercell_filename=supercell_filename, calculator=calculator, symprec=symprec) if phonon_supercell_matrix is not None: if unitcell is None and unitcell_filename is None: msg = ("phonon_supercell_matrix can be used only when " "unitcell or unitcell_filename is given.") raise RuntimeError(msg) ph_smat = load_helper.get_supercell_matrix(phonon_supercell_matrix) else: ph_smat = None _nac_params = nac_params else: ph3py_yaml = Phono3pyYaml() ph3py_yaml.read(phono3py_yaml) cell = ph3py_yaml.unitcell smat = ph3py_yaml.supercell_matrix ph_smat = ph3py_yaml.phonon_supercell_matrix if smat is None: smat = np.eye(3, dtype='intc', order='C') if primitive_matrix == 'auto': pmat = 'auto' else: pmat = ph3py_yaml.primitive_matrix if is_nac: _nac_params = ph3py_yaml.nac_params else: _nac_params = None # units keywords: factor, nac_factor, distance_to_A units = get_default_physical_units(calculator) if factor is None: _factor = units['factor'] else: _factor = factor ph3py = Phono3py(cell, smat, primitive_matrix=pmat, phonon_supercell_matrix=ph_smat, mesh=mesh, frequency_factor_to_THz=_factor, symprec=symprec, is_symmetry=is_symmetry, is_mesh_symmetry=is_mesh_symmetry, calculator=calculator, log_level=log_level) _nac_params = load_helper.get_nac_params(ph3py.primitive, _nac_params, born_filename, is_nac, units['nac_factor']) _set_force_constants(ph3py, dataset=None, fc3_filename=fc3_filename, fc2_filename=fc2_filename, forces_fc3_filename=forces_fc3_filename, forces_fc2_filename=forces_fc2_filename, fc_calculator=fc_calculator) if mesh is not None: ph3py.set_phph_interaction( nac_params=_nac_params, frequency_scale_factor=frequency_scale_factor) return ph3py
def load(phonopy_yaml=None, # phonopy.yaml-like must be the first argument. supercell_matrix=None, primitive_matrix=None, is_nac=True, calculator=None, unitcell=None, supercell=None, nac_params=None, unitcell_filename=None, supercell_filename=None, born_filename=None, force_sets_filename=None, force_constants_filename=None, fc_calculator=None, fc_calculator_options=None, factor=None, frequency_scale_factor=None, produce_fc=True, is_symmetry=True, symmetrize_fc=True, is_compact_fc=True, symprec=1e-5, log_level=0): """Create Phonopy instance from parameters and/or input files. "phonopy_yaml"-like file is parsed unless crystal structure information is given by unitcell_filename, supercell_filename, unitcell (PhonopyAtoms-like), or supercell (PhonopyAtoms-like). Even when "phonopy_yaml"-like file is parse, parameters except for crystal structure can be overwritten. Phonopy default files of 'FORCE_SETS' and 'BORN' are parsed when they are found in current directory and those data are not yet provided by other means. Crystal structure ----------------- Means to provide crystal structure(s) and their priority: 1. unitcell_filename (with supercell_matrix) 2. supercell_filename 3. unitcell (with supercell_matrix) 4. supercell. 5. phonopy_yaml Force sets or force constants ----------------------------- Optional. Means to provide information to generate force constants and their priority: 1. force_constants_filename 2. force_sets_filename 3. phonopy_yaml if force constants are found in phonoy_yaml. 4. phonopy_yaml if forces are found in phonoy_yaml.dataset. 5. 'FORCE_CONSTANTS' is searched in current directory. 6. 'force_constants.hdf5' is searched in current directory. 7. 'FORCE_SETS' is searched in current directory. When both of 3 and 4 are satisfied but not others, force constants and dataset are stored in Phonopy instance, but force constants are not produced from dataset. Parameters for non-analytical term correctiion (NAC) ---------------------------------------------------- Optional. Means to provide NAC parameters and their priority: 1. born_filename 2. nac_params 3. phonopy_yaml.nac_params if existed and is_nac=True. 4. 'BORN' is searched in current directory when is_nac=True. Parameters ---------- phonopy_yaml : str, optional Filename of "phonopy.yaml"-like file. If this is given, the data in the file are parsed. Default is None. supercell_matrix : array_like, optional Supercell matrix multiplied to input cell basis vectors. shape=(3, ) or (3, 3), where the former is considered a diagonal matrix. Default is the unit matrix. dtype=int primitive_matrix : array_like or str, optional Primitive matrix multiplied to input cell basis vectors. Default is None, which is equivalent to 'auto'. For array_like, shape=(3, 3), dtype=float. When 'F', 'I', 'A', 'C', or 'R' is given instead of a 3x3 matrix, the primitive matrix for the character found at https://spglib.github.io/spglib/definition.html is used. is_nac : bool, optional If True, look for 'BORN' file. If False, NAS is turned off. Default is True. calculator : str, optional. Calculator used for computing forces. This is used to switch the set of physical units. Default is None, which is equivalent to "vasp". unitcell : PhonopyAtoms, optional Input unit cell. Default is None. supercell : PhonopyAtoms, optional Input supercell. With given, default value of primitive_matrix is set to 'auto' (can be overwitten). supercell_matrix is ignored. Default is None. nac_params : dict, optional Parameters required for non-analytical term correction. Default is None. {'born': Born effective charges (array_like, shape=(primitive cell atoms, 3, 3), dtype=float), 'dielectric': Dielectric constant matrix (array_like, shape=(3, 3), dtype=float), 'factor': unit conversion facotr (float)} unitcell_filename : str, optional Input unit cell filename. Default is None. supercell_filename : str, optional Input supercell filename. When this is specified, supercell_matrix is ignored. Default is None. born_filename : str, optional Filename corresponding to 'BORN', a file contains non-analytical term correction parameters. force_sets_filename : str, optional Filename of a file corresponding to 'FORCE_SETS', a file contains sets of forces and displacements. Default is None. force_constants_filename : str, optional Filename of a file corresponding to 'FORCE_CONSTANTS' or 'force_constants.hdf5', a file contains force constants. Default is None. fc_calculator : str, optional Force constants calculator. Currently only 'alm'. Default is None. fc_calculator_options : str, optional Optional parameters that are passed to the external fc-calculator. This is given as one text string. How to parse this depends on the fc-calculator. For alm, each parameter is splitted by comma ',', and each set of key and value pair is written in 'key = value'. factor : float, optional Phonon frequency unit conversion factor. Unless specified, default unit conversion factor for each calculator is used. frequency_scale_factor : float, optional Factor multiplied to calculated phonon frequency. Default is None, i.e., effectively 1. produce_fc : bool, optional Setting False, force constants are not calculated from displacements and forces. Default is True. is_symmetry : bool, optional Setting False, crystal symmetry except for lattice translation is not considered. Default is True. symmetrize_fc : bool, optional Setting False, force constants are not symmetrized when creating force constants from displacements and forces. Default is True. is_compact_fc : bool Force constants are produced in the array whose shape is True: (primitive, supecell, 3, 3) False: (supercell, supecell, 3, 3) where 'supercell' and 'primitive' indicate number of atoms in these cells. Default is True. symprec : float, optional Tolerance used to find crystal symmetry. Default is 1e-5. log_level : int, optional Verbosity control. Default is 0. """ if (supercell is not None or supercell_filename is not None or unitcell is not None or unitcell_filename is not None): cell, smat, pmat = load_helper.get_cell_settings( supercell_matrix=supercell_matrix, primitive_matrix=primitive_matrix, unitcell=unitcell, supercell=supercell, unitcell_filename=unitcell_filename, supercell_filename=supercell_filename, calculator=calculator, symprec=symprec, log_level=log_level) _calculator = calculator _nac_params = nac_params _dataset = None _fc = None elif phonopy_yaml is not None: phpy_yaml = PhonopyYaml() phpy_yaml.read(phonopy_yaml) cell = phpy_yaml.unitcell smat = phpy_yaml.supercell_matrix if smat is None: smat = np.eye(3, dtype='intc', order='C') if primitive_matrix is not None: pmat = get_primitive_matrix(primitive_matrix, symprec=symprec) else: pmat = phpy_yaml.primitive_matrix if nac_params is not None: _nac_params = nac_params elif is_nac: _nac_params = phpy_yaml.nac_params else: _nac_params = None _dataset = phpy_yaml.dataset _fc = phpy_yaml.force_constants if calculator is None: _calculator = phpy_yaml.calculator else: _calculator = calculator else: msg = ("Cell information could not found. " "Phonopy instance loading failed.") raise RuntimeError(msg) if log_level and _calculator is not None: print("Set \"%s\" mode." % _calculator) # units keywords: factor, nac_factor, distance_to_A units = get_default_physical_units(_calculator) if factor is None: _factor = units['factor'] else: _factor = factor phonon = Phonopy(cell, smat, primitive_matrix=pmat, factor=_factor, frequency_scale_factor=frequency_scale_factor, symprec=symprec, is_symmetry=is_symmetry, calculator=_calculator, log_level=log_level) # NAC params if born_filename is not None or _nac_params is not None or is_nac: ret_nac_params = load_helper.get_nac_params( primitive=phonon.primitive, nac_params=_nac_params, born_filename=born_filename, is_nac=is_nac, nac_factor=units['nac_factor'], log_level=log_level) if ret_nac_params is not None: phonon.nac_params = ret_nac_params # Displacements, forces, and force constants load_helper.set_dataset_and_force_constants( phonon, _dataset, _fc, force_constants_filename=force_constants_filename, force_sets_filename=force_sets_filename, fc_calculator=fc_calculator, fc_calculator_options=fc_calculator_options, produce_fc=produce_fc, symmetrize_fc=symmetrize_fc, is_compact_fc=is_compact_fc, log_level=log_level) return phonon
def load( phono3py_yaml=None, # phono3py.yaml-like must be the first argument. supercell_matrix=None, primitive_matrix=None, phonon_supercell_matrix=None, mesh=None, is_nac=True, calculator=None, unitcell=None, supercell=None, nac_params=None, unitcell_filename=None, supercell_filename=None, born_filename=None, forces_fc3_filename=None, forces_fc2_filename=None, fc3_filename=None, fc2_filename=None, fc_calculator=None, fc_calculator_options=None, factor=None, frequency_scale_factor=None, produce_fc=True, is_symmetry=True, symmetrize_fc=True, is_mesh_symmetry=True, is_compact_fc=False, symprec=1e-5, log_level=0): """Create Phono3py instance from parameters and/or input files. "phono3py_yaml"-like file is parsed unless crystal structure information is given by unitcell_filename, supercell_filename, unitcell (PhonopyAtoms-like), or supercell (PhonopyAtoms-like). Even when "phono3py_yaml"-like file is parse, parameters except for crystal structure can be overwritten. 'fc3.hdf5' is read if found in current directory. Unless 'fc3.hdf5' is found and if 'FORCES_FC3' and 'disp_fc3.yaml" are found, these are read and fc3 and fc2 are produced. if 'fc2.hdf5' is found, this is read. Unless 'fc2.hdf5' is found and if 'FORCES_FC2' and 'disp_fc2.yaml" are found, these are read and fc2 is produced. When force_sets_filename and force_constants_filename are not given, 'FORCES_FC3' and 'FORCES_FC2' are looked for in the current directory as the default behaviour. When 'FORCES_FC3' ('FORCES_FC2') is given in the type-1 format, 'disp_fc3.yaml' ('disp_fc2.yaml') is also necessary and read. Crystal structure ----------------- Means to provide crystal structure(s) and their priority: 1. unitcell_filename (with supercell_matrix) 2. supercell_filename 3. unitcell (with supercell_matrix) 4. supercell. 5. phono3py_yaml-like Force sets or force constants ----------------------------- Optional. Means to provide information to generate force constants and their priority: 1. fc3_filename (fc2_filename) 2. forces_fc3_filename (forces_fc2_filename). Do not forget that for type-1 format, disp_fc3.yaml (disp_fc2.yaml) has to be given, too. 3. 'fc3.hdf5' and 'fc2.hdf5' are searched in current directory. 4. 'FORCES_FC3' and 'FORCES_FC2' are searched in current directory. 'FORCES_FC2' is optional. For type-1 format, 'disp_fc3.yaml' and optionally 'disp_fc2.yaml' are also searched in current directory. When 'FORCES_FC2' is not found, 'FORCES_FC3' is used to create fc2. Parameters for non-analytical term correctiion (NAC) ---------------------------------------------------- Optional. Means to provide NAC parameters and their priority: 1. born_filename 2. nac_params 3. phono3py_yaml_like.nac_params if existed and is_nac=True. 4. 'BORN' is searched in current directory when is_nac=True. Parameters ---------- phono3py_yaml : str, optional Filename of "phono3py.yaml"-like file. If this is given, the data in the file are parsed. Default is None. supercell_matrix : array_like, optional Supercell matrix multiplied to input cell basis vectors. shape=(3, ) or (3, 3), where the former is considered a diagonal matrix. Default is the unit matrix. dtype=int primitive_matrix : array_like or str, optional Primitive matrix multiplied to input cell basis vectors. Default is the identity matrix. Default is None, which is equivalent to 'auto'. shape=(3, 3), dtype=float. When 'F', 'I', 'A', 'C', or 'R' is given instead of a 3x3 matrix, the primitive matrix defined at https://spglib.github.io/spglib/definition.html is used. phonon_supercell_matrix : array_like, optional Supercell matrix used for fc2. In phono3py, supercell matrix for fc3 and fc2 can be different to support longer range interaction of fc2 than that of fc3. Unless setting this, supercell_matrix is used. This is only valide when unitcell or unitcell_filename is given. Default is None. mesh : array_like, optional Grid mesh numbers in reciprocal cell. shape=(3,), dtype='intc' is_nac : bool, optional If True, look for 'BORN' file. If False, NAS is turned off. Default is True. calculator : str, optional. Calculator used for computing forces. This is used to switch the set of physical units. Default is None, which is equivalent to "vasp". unitcell : PhonopyAtoms, optional Input unit cell. Default is None. supercell : PhonopyAtoms, optional Input supercell. With given, default value of primitive_matrix is set to 'auto' (can be overwitten). supercell_matrix is ignored. Default is None. nac_params : dict, optional Parameters required for non-analytical term correction. Default is None. {'born': Born effective charges (array_like, shape=(primitive cell atoms, 3, 3), dtype=float), 'dielectric': Dielectric constant matrix (array_like, shape=(3, 3), dtype=float), 'factor': unit conversion facotr (float)} unitcell_filename : str, optional Input unit cell filename. Default is None. supercell_filename : str, optional Input supercell filename. When this is specified, supercell_matrix is ignored. Default is None. born_filename : str, optional Filename corresponding to 'BORN', a file contains non-analytical term correction parameters. forces_fc3_filename : sequence or str, optional A two-elemental sequence of filenames corresponding to ('FORCES_FC3', 'disp_fc3.yaml') in the type-1 format or a filename (str) corresponding to 'FORCES_FC3' in the type-2 format. Default is None. forces_fc2_filename : str or tuple, optional A two-elemental sequence of filenames corresponding to ('FORCES_FC2', 'disp_fc2.yaml') in the type-1 format or a filename (str) corresponding to 'FORCES_FC2' in the type-2 format. Default is None. fc3_filename : str, optional Filename of a file corresponding to 'fc3.hdf5', a file contains third-order force constants. Default is None. fc2_filename : str, optional Filename of a file corresponding to 'fc2.hdf5', a file contains second-order force constants. Default is None. fc_calculator : str, optional Force constants calculator. Currently only 'alm'. Default is None. fc_calculator_options : str, optional Optional parameters that are passed to the external fc-calculator. This is given as one text string. How to parse this depends on the fc-calculator. For alm, each parameter is splitted by comma ',', and each set of key and value pair is written in 'key = value'. factor : float, optional Phonon frequency unit conversion factor. Unless specified, default unit conversion factor for each calculator is used. frequency_scale_factor : float, optional Factor multiplied to calculated phonon frequency. Default is None, i.e., effectively 1. produce_fc : bool, optional Setting False, force constants are not calculated from displacements and forces. Default is True. is_symmetry : bool, optional Setting False, crystal symmetry except for lattice translation is not considered. Default is True. symmetrize_fc : bool, optional Setting False, force constants are not symmetrized when creating force constants from displacements and forces. Default is True. is_mesh_symmetry : bool, optional Setting False, reciprocal mesh symmetry is not considered. Default is True. is_compact_fc : bool fc3 are created in the array whose shape is True: (primitive, supercell, supecell, 3, 3, 3) False: (supercell, supercell, supecell, 3, 3, 3) and for fc2 True: (primitive, supecell, 3, 3) False: (supercell, supecell, 3, 3) where 'supercell' and 'primitive' indicate number of atoms in these cells. Default is False. symprec : float, optional Tolerance used to find crystal symmetry. Default is 1e-5. log_level : int, optional Verbosity control. Default is 0. """ if (supercell is not None or supercell_filename is not None or unitcell is not None or unitcell_filename is not None): cell, smat, pmat = load_helper.get_cell_settings( supercell_matrix=supercell_matrix, primitive_matrix=primitive_matrix, unitcell=unitcell, supercell=supercell, unitcell_filename=unitcell_filename, supercell_filename=supercell_filename, calculator=calculator, symprec=symprec) if phonon_supercell_matrix is not None: if unitcell is None and unitcell_filename is None: msg = ("phonon_supercell_matrix can be used only when " "unitcell or unitcell_filename is given.") raise RuntimeError(msg) ph_smat = phonon_supercell_matrix else: ph_smat = None _nac_params = nac_params ph3py_yaml = None elif phono3py_yaml is not None: ph3py_yaml = Phono3pyYaml() ph3py_yaml.read(phono3py_yaml) cell = ph3py_yaml.unitcell smat = ph3py_yaml.supercell_matrix ph_smat = ph3py_yaml.phonon_supercell_matrix if smat is None: smat = np.eye(3, dtype='intc', order='C') if primitive_matrix == 'auto': pmat = 'auto' else: pmat = ph3py_yaml.primitive_matrix if nac_params is not None: _nac_params = nac_params elif is_nac: _nac_params = ph3py_yaml.nac_params else: _nac_params = None # units keywords: factor, nac_factor, distance_to_A physical_units = get_default_physical_units(calculator) if factor is None: _factor = physical_units['factor'] else: _factor = factor ph3py = Phono3py(cell, smat, primitive_matrix=pmat, phonon_supercell_matrix=ph_smat, frequency_factor_to_THz=_factor, symprec=symprec, is_symmetry=is_symmetry, is_mesh_symmetry=is_mesh_symmetry, calculator=calculator, log_level=log_level) ph3py.mesh_number = mesh # NAC params if (born_filename is not None or nac_params is not None or is_nac and os.path.isfile("BORN")): ph3py.nac_params = load_helper.get_nac_params( ph3py.primitive, _nac_params, born_filename, is_nac, physical_units['nac_factor'], log_level=log_level) set_dataset_and_force_constants( ph3py, ph3py_yaml=ph3py_yaml, fc3_filename=fc3_filename, fc2_filename=fc2_filename, forces_fc3_filename=forces_fc3_filename, forces_fc2_filename=forces_fc2_filename, fc_calculator=fc_calculator, fc_calculator_options=fc_calculator_options, produce_fc=produce_fc, symmetrize_fc=symmetrize_fc, is_compact_fc=is_compact_fc, log_level=log_level) if mesh is not None: ph3py.init_phph_interaction( frequency_scale_factor=frequency_scale_factor) return ph3py
def main(**argparse_control): load_phono3py_yaml = argparse_control.get('load_phono3py_yaml', False) args, log_level = start_phono3py(**argparse_control) physical_units = get_default_physical_units(get_interface_mode(vars(args))) if load_phono3py_yaml: input_filename = None output_filename = None else: (input_filename, output_filename) = get_input_output_filenames_from_args(args) settings, confs, cell_filename = read_phono3py_settings( args, argparse_control, log_level) if args.force_sets_to_forces_fc2_mode: create_FORCES_FC2_from_FORCE_SETS_then_exit(log_level) if args.force_sets_mode: create_FORCE_SETS_from_FORCES_FCx_then_exit( settings.phonon_supercell_matrix, input_filename, log_level) if args.write_grid_points: run_mode = "write_grid_info" elif args.show_num_triplets: run_mode = "show_triplets_info" else: run_mode = None # ----------------------------------------------------------------------- # ----------------- 'args' should not be used below. -------------------- # ----------------------------------------------------------------------- #################################### # Create FORCES_FC3 and FORCES_FC2 # #################################### create_FORCES_FC3_and_FORCES_FC2_then_exit(settings, input_filename, output_filename, log_level) ########################################################### # Symmetry tolerance. Distance unit depends on interface. # ########################################################### if settings.symmetry_tolerance is None: symprec = 1e-5 else: symprec = settings.symmetry_tolerance cell_info = get_cell_info(settings, cell_filename, symprec, log_level) unitcell_filename = cell_info['optional_structure_info'][0] interface_mode = cell_info['interface_mode'] # ph3py_yaml = cell_info['phonopy_yaml'] if run_mode is None: run_mode = get_run_mode(settings) ###################################################### # Create supercells with displacements and then exit # ###################################################### if settings.create_displacements: phono3py = create_phono3py_supercells(cell_info, settings, symprec, output_filename=output_filename, interface_mode=interface_mode, log_level=log_level) finalize_phono3py(phono3py, confs, log_level, displacements_mode=True, filename="phono3py_disp.yaml") ####################### # Initialize phono3py # ####################### # updated_settings keys # ('grid_points', 'sigmas', 'temperature_points', 'temperatures', # 'frequency_factor_to_THz', 'num_frequency_points', # 'frequency_step', 'frequency_scale_factor', # 'cutoff_frequency') phono3py, updated_settings = init_phono3py(settings, cell_info, interface_mode, output_filename, symprec, log_level) ################################################# # Show phono3py settings and crystal structures # ################################################# if log_level: show_general_settings(settings, run_mode, phono3py, unitcell_filename, input_filename, output_filename) if log_level > 1: show_phono3py_cells(phono3py, settings) else: print("Spacegroup: %s" % phono3py.symmetry.get_international_table()) print("Use -v option to watch primitive cell, unit cell, " "and supercell structures.") ################## # Check settings # ################## run_modes_with_mesh = ("conductivity-RTA", "conductivity-LBTE", "imag_self_energy", "jdos", "isotope", "write_grid_info", "show_triplets_info") run_modes_with_gp = ("imag_self_energy", "jdos", "isotope") if phono3py.mesh_numbers is None and run_mode in run_modes_with_mesh: print("") print("Mesh numbers have to be specified.") print("") if log_level: print_error() sys.exit(1) if (run_mode in run_modes_with_gp and updated_settings['grid_points'] is None): print("") print("Grid point(s) has to be specified.") print("") if log_level: print_error() sys.exit(1) ######################################################### # Write ir-grid points and grid addresses and then exit # ######################################################### if run_mode == "write_grid_info": write_grid_points(phono3py.primitive, phono3py.mesh_numbers, mesh_divs=settings.mesh_divisors, band_indices=settings.band_indices, sigmas=updated_settings['sigmas'], temperatures=updated_settings['temperatures'], coarse_mesh_shifts=settings.coarse_mesh_shifts, is_kappa_star=settings.is_kappa_star, is_lbte=(settings.write_collision or settings.is_lbte), compression=settings.hdf5_compression, symprec=symprec) if log_level: print_end() sys.exit(0) ################################################################ # Show reduced number of triplets at grid points and then exit # ################################################################ if run_mode == "show_triplets_info": show_num_triplets(phono3py.primitive, phono3py.mesh_numbers, mesh_divs=settings.mesh_divisors, band_indices=settings.band_indices, grid_points=updated_settings['grid_points'], coarse_mesh_shifts=settings.coarse_mesh_shifts, is_kappa_star=settings.is_kappa_star, symprec=symprec) if log_level: print_end() sys.exit(0) ################################## # Non-analytical term correction # ################################## store_nac_params(phono3py, settings, cell_info['phonopy_yaml'], unitcell_filename, log_level, nac_factor=Hartree * Bohr, load_phonopy_yaml=load_phono3py_yaml) ################### # Force constants # ################### store_force_constants(phono3py, settings, cell_info['phonopy_yaml'], physical_units, input_filename, output_filename, load_phono3py_yaml, log_level) ############################################ # Phonon Gruneisen parameter and then exit # ############################################ if settings.is_gruneisen: run_gruneisen_then_exit(phono3py, settings, output_filename, log_level) ################# # Show settings # ################# if log_level and run_mode is not None: show_phono3py_settings(phono3py, settings, updated_settings, log_level) ########################### # Joint DOS and then exit # ########################### if run_mode == "jdos": run_jdos_then_exit(phono3py, settings, updated_settings, output_filename, log_level) ################################################ # Mass variances for phonon-isotope scattering # ################################################ if settings.is_isotope and settings.mass_variances is None: from phonopy.structure.atoms import isotope_data symbols = phono3py.phonon_primitive.symbols in_database = True for s in set(symbols): if s not in isotope_data: print("%s is not in the list of isotope databese" % s) print("(not implemented).") print("Use --mass_variances option.") in_database = False if not in_database: if log_level: print_end() sys.exit(0) ######################################### # Phonon-isotope lifetime and then exit # ######################################### if run_mode == "isotope": run_isotope_then_exit(phono3py, settings, updated_settings, log_level) ######################################## # Initialize phonon-phonon interaction # ######################################## if run_mode is not None: init_phph_interaction(phono3py, settings, updated_settings, input_filename, output_filename, log_level) ####################################################### # Run imaginary part of self energy of bubble diagram # ####################################################### if run_mode == "imag_self_energy": phono3py.run_imag_self_energy( updated_settings['grid_points'], updated_settings['temperature_points'], frequency_step=updated_settings['frequency_step'], num_frequency_points=updated_settings['num_frequency_points'], scattering_event_class=settings.scattering_event_class, write_txt=True, write_gamma_detail=settings.write_gamma_detail, output_filename=output_filename) ##################################################### # Run frequency shift calculation of bubble diagram # ##################################################### elif run_mode == "real_self_energy": phono3py.run_real_self_energy( updated_settings['grid_points'], updated_settings['temperature_points'], frequency_step=updated_settings['frequency_step'], num_frequency_points=updated_settings['num_frequency_points'], write_txt=True, output_filename=output_filename) ####################################################### # Run spectral function calculation of bubble diagram # ####################################################### elif run_mode == "spectral_function": phono3py.run_spectral_function( updated_settings['grid_points'], updated_settings['temperature_points'], frequency_step=updated_settings['frequency_step'], num_frequency_points=updated_settings['num_frequency_points'], num_points_in_batch=updated_settings['num_points_in_batch'], write_txt=True, write_hdf5=True, output_filename=output_filename) #################################### # Run lattice thermal conductivity # #################################### elif run_mode == "conductivity-RTA" or run_mode == "conductivity-LBTE": phono3py.run_thermal_conductivity( is_LBTE=settings.is_lbte, temperatures=updated_settings['temperatures'], is_isotope=settings.is_isotope, mass_variances=settings.mass_variances, grid_points=updated_settings['grid_points'], boundary_mfp=settings.boundary_mfp, solve_collective_phonon=settings.solve_collective_phonon, use_ave_pp=settings.use_ave_pp, gamma_unit_conversion=settings.gamma_conversion_factor, mesh_divisors=settings.mesh_divisors, coarse_mesh_shifts=settings.coarse_mesh_shifts, is_reducible_collision_matrix=settings. is_reducible_collision_matrix, is_kappa_star=settings.is_kappa_star, gv_delta_q=settings.group_velocity_delta_q, is_full_pp=settings.is_full_pp, pinv_cutoff=settings.pinv_cutoff, pinv_solver=settings.pinv_solver, write_gamma=settings.write_gamma, read_gamma=settings.read_gamma, write_kappa=True, is_N_U=settings.is_N_U, write_gamma_detail=settings.write_gamma_detail, write_collision=settings.write_collision, read_collision=settings.read_collision, write_pp=settings.write_pp, read_pp=settings.read_pp, write_LBTE_solution=settings.write_LBTE_solution, compression=settings.hdf5_compression, input_filename=input_filename, output_filename=output_filename) else: if log_level: print("-" * 11 + " None of ph-ph interaction calculation was performed. " + "-" * 11) finalize_phono3py(phono3py, confs, log_level)