def _get_cell_settings(unitcell_filename, supercell_filename, unitcell, supercell, calculator, pmat, smat, symprec): if unitcell_filename is not None: cell, filename = read_crystal_structure(filename=unitcell_filename, interface_mode=calculator) _smat = _get_supercell_matrix(smat) _pmat = pmat elif supercell_filename is not None: cell, filename = read_crystal_structure(filename=supercell_filename, interface_mode=calculator) _smat = np.eye(3, dtype='intc', order='C') if pmat is None: _pmat = 'auto' elif unitcell is not None: cell = unitcell elif supercell is not None: cell = supercell _smat = np.eye(3, dtype='intc', order='C') if pmat is None: _pmat = 'auto' else: raise RuntimeError("Cell has to be specified.") if cell is None: msg = "'%s' could not be found." % filename raise FileNotFoundError(msg) _pmat = _get_primitive_matrix(_pmat, cell, symprec) return cell, _smat, _pmat
def get_data(args, interface_mode=None): args = parse_args() cell, _ = read_crystal_structure(args.filenames[0], interface_mode=interface_mode) f = h5py.File(args.filenames[1]) primitive_matrix = np.reshape( [fracval(x) for x in args.primitive_matrix.split()], (3, 3)) primitive = get_primitive(cell, primitive_matrix) symmetry = Symmetry(primitive) data = {} data['cell'] = primitive data['symmetry'] = symmetry data['mesh'] = np.array(f['mesh'][:], dtype='intc') # (3) data['weight'] = f['weight'][:] # (gp) data['group_velocity'] = f['group_velocity'][:] # (gp, band, 3) data['qpoint'] = f['qpoint'][:] # (gp, 3) data['frequency'] = f['frequency'][:] # (gp, band) if 'gamma_N' in f: data['gamma_N'] = f['gamma_N'][:] # (temps, gp, band) data['gamma_U'] = f['gamma_U'][:] # (temps, gp, band) if 'gamma_isotope' in f: data['gamma_isotope'] = f['gamma_isotope'][:] # (gp, band) data['heat_capacity'] = f['heat_capacity'][:] # (temps, gp, band) data['temperature'] = np.array(f['temperature'][:], dtype='double') # (temps) ir_grid_points, grid_address, _ = get_grid_symmetry(data) data['ir_grid_points'] = ir_grid_points data['grid_address'] = grid_address return data
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_cell_settings(phonopy_yaml=None, supercell_matrix=None, primitive_matrix=None, unitcell=None, supercell=None, unitcell_filename=None, supercell_filename=None, calculator=None, symprec=1e-5): if unitcell_filename is not None: cell, filename = read_crystal_structure( filename=unitcell_filename, interface_mode=calculator) smat = _get_supercell_matrix(supercell_matrix) pmat = primitive_matrix elif supercell_filename is not None: cell, filename = read_crystal_structure( filename=supercell_filename, interface_mode=calculator) smat = np.eye(3, dtype='intc', order='C') if primitive_matrix is None or primitive_matrix == "auto": pmat = 'auto' elif unitcell is not None: cell = PhonopyAtoms(atoms=unitcell) smat = _get_supercell_matrix(supercell_matrix) pmat = primitive_matrix elif supercell is not None: cell = PhonopyAtoms(atoms=supercell) smat = np.eye(3, dtype='intc', order='C') if primitive_matrix is None or primitive_matrix == "auto": pmat = 'auto' else: raise RuntimeError("Cell has to be specified.") if cell is None: msg = "'%s' could not be found." % filename raise FileNotFoundError(msg) pmat = _get_primitive_matrix(pmat, cell, symprec) return cell, smat, pmat
def collect_cell_info(supercell_matrix=None, primitive_matrix=None, interface_mode=None, cell_filename=None, chemical_symbols=None, enforce_primitive_matrix_auto=False, command_name="phonopy", symprec=1e-5): if supercell_matrix is None: _interface_mode = "phonopy_yaml" elif interface_mode is None: try: read_vasp(cell_filename) _interface_mode = None except (ValueError, TypeError): # TypeError occurs when cell_filename is None. # ValueError occurs in parsing POSCAR like file. _interface_mode = "phonopy_yaml" else: _interface_mode = interface_mode unitcell, optional_structure_info = read_crystal_structure( filename=cell_filename, interface_mode=_interface_mode, chemical_symbols=chemical_symbols, command_name=command_name) unitcell_filename = optional_structure_info[0] if _interface_mode == 'phonopy_yaml' and unitcell is not None: if optional_structure_info[1] is None: interface_mode_out = interface_mode else: interface_mode_out = optional_structure_info[1] if optional_structure_info[2] is None: _supercell_matrix = supercell_matrix else: _supercell_matrix = optional_structure_info[2] if primitive_matrix is not None: _primitive_matrix = primitive_matrix elif optional_structure_info[3] is not None: _primitive_matrix = optional_structure_info[3] else: _primitive_matrix = 'auto' has_read_phonopy_yaml = True else: interface_mode_out = _interface_mode _supercell_matrix = supercell_matrix _primitive_matrix = primitive_matrix has_read_phonopy_yaml = False if enforce_primitive_matrix_auto: _primitive_matrix = 'auto' if _supercell_matrix is None and _primitive_matrix == 'auto': supercell_matrix_out = np.eye(3, dtype='intc') else: supercell_matrix_out = _supercell_matrix primitive_matrix_out = _primitive_matrix if unitcell is None: fname_list = optional_structure_info if len(fname_list) == 1: msg = "Crystal structure file of \"%s\"" % fname_list[0] msg_list = [ "%s was not found." % msg, ] elif len(fname_list) == 2: msg = "Crystal structure file of \"%s\" %s" % fname_list msg_list = [ "%s was not found." % msg, ] elif len(fname_list) == 4: msg_list = [] if cell_filename is None: msg = ( "\"%s\" or \"%s\" should exist in the current directory" % fname_list[:2]) msg_list.append(msg) msg = "to run without setting supercell matrix (DIM or --dim)." msg_list.append(msg) else: msg_list.append("Supercell matrix (DIM or --dim) may be " "forgotten to be specified.") return "\n".join(msg_list) if supercell_matrix_out is None: return "Supercell matrix (DIM or --dim) is not specified." # Check unit cell if np.linalg.det(unitcell.get_cell()) < 0.0: return "Lattice vectors have to follow the right-hand rule." return (unitcell, supercell_matrix_out, primitive_matrix_out, unitcell_filename, optional_structure_info, interface_mode_out, has_read_phonopy_yaml)
option_list=option_list) settings = phonopy_conf.get_settings() else: phonopy_conf = PhonopyConfParser(options=options, option_list=option_list) settings = phonopy_conf.get_settings() if options.is_graph_save: import matplotlib matplotlib.use('Agg') ################## # Initialization # ################## unitcell, optional_structure_file_information = read_crystal_structure( filename=settings.get_cell_filename(), interface_mode=interface_mode, chemical_symbols=settings.get_chemical_symbols(), yaml_mode=settings.get_yaml_mode()) unitcell_filename = optional_structure_file_information[0] if unitcell is None: print_error_message("Crystal structure file of %s could not be found." % unitcell_filename) if log_level > 0: print_error() sys.exit(1) # Check unit cell if np.linalg.det(unitcell.get_cell()) < 0.0: print_error_message("Determinant of the lattice vector matrix " "has to be positive.")
def collect_cell_info(supercell_matrix=None, primitive_matrix=None, interface_mode=None, cell_filename=None, chemical_symbols=None, enforce_primitive_matrix_auto=False, command_name="phonopy", symprec=1e-5): if supercell_matrix is None: _interface_mode = "phonopy_yaml" elif interface_mode is None: try: if cell_filename is None: read_vasp(get_default_cell_filename('vasp')) else: read_vasp(cell_filename) _interface_mode = None except (ValueError, TypeError): # TypeError occurs when cell_filename is None. # ValueError occurs in parsing POSCAR like file. _interface_mode = "phonopy_yaml" else: _interface_mode = interface_mode unitcell, optional_structure_info = read_crystal_structure( filename=cell_filename, interface_mode=_interface_mode, chemical_symbols=chemical_symbols, command_name=command_name) unitcell_filename = optional_structure_info[0] if _interface_mode == 'phonopy_yaml' and unitcell is not None: if optional_structure_info[1] is None: interface_mode_out = interface_mode else: interface_mode_out = optional_structure_info[1] if optional_structure_info[2] is None: _supercell_matrix = supercell_matrix else: _supercell_matrix = optional_structure_info[2] if primitive_matrix is not None: _primitive_matrix = primitive_matrix elif optional_structure_info[3] is not None: _primitive_matrix = optional_structure_info[3] else: _primitive_matrix = 'auto' has_read_phonopy_yaml = True else: interface_mode_out = _interface_mode _supercell_matrix = supercell_matrix _primitive_matrix = primitive_matrix has_read_phonopy_yaml = False if enforce_primitive_matrix_auto: _primitive_matrix = 'auto' if _supercell_matrix is None and _primitive_matrix == 'auto': supercell_matrix_out = np.eye(3, dtype='intc') else: supercell_matrix_out = _supercell_matrix primitive_matrix_out = _primitive_matrix if unitcell is None: fname_list = optional_structure_info if len(fname_list) == 1: msg = "Crystal structure file of \"%s\"" % fname_list[0] msg_list = ["%s was not found." % msg, ] elif len(fname_list) == 2: msg = "Crystal structure file of \"%s\" %s" % fname_list msg_list = ["%s was not found." % msg, ] elif len(fname_list) == 4: msg_list = [] if supercell_matrix is None: if cell_filename is None: msg = ["Supercell matrix (DIM or --dim) is not specified. " "To run phonopy without", "explicitly setting supercell matrix, \"%s\" or \"%s\" " % fname_list[:2], "must exist in the current directory."] msg_list += msg else: msg_list.append("Supercell matrix (DIM or --dim) may be " "forgotten to be specified.") elif cell_filename is None: msg_list = ["Any crystal structure file was not found.", ""] return "\n".join(msg_list) if supercell_matrix_out is None: return "Supercell matrix (DIM or --dim) is not specified." # Check unit cell if np.linalg.det(unitcell.get_cell()) < 0.0: return "Lattice vectors have to follow the right-hand rule." return (unitcell, supercell_matrix_out, primitive_matrix_out, unitcell_filename, optional_structure_info, interface_mode_out, has_read_phonopy_yaml)