當前位置: 首頁>>代碼示例>>Python>>正文


Python Phonopy.get_displacements方法代碼示例

本文整理匯總了Python中phonopy.Phonopy.get_displacements方法的典型用法代碼示例。如果您正苦於以下問題:Python Phonopy.get_displacements方法的具體用法?Python Phonopy.get_displacements怎麽用?Python Phonopy.get_displacements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在phonopy.Phonopy的用法示例。


在下文中一共展示了Phonopy.get_displacements方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_displaced_structures

# 需要導入模塊: from phonopy import Phonopy [as 別名]
# 或者: from phonopy.Phonopy import get_displacements [as 別名]
def get_displaced_structures(pmg_structure, atom_disp=0.01,
                             supercell_matrix=None, yaml_fname=None, **kwargs):
    """
    Generate a set of symmetrically inequivalent displaced structures for
    phonon calculations.

    Args:
        pmg_structure (Structure): A pymatgen structure object.
        atom_disp (float): Atomic displacement. Default is 0.01 $\\AA$.
        supercell_matrix (3x3 array): Scaling matrix for supercell.
        yaml_fname (string): If not None, it represents the full path to
            the outputting displacement yaml file, e.g. disp.yaml.
        **kwargs: Parameters used in Phonopy.generate_displacement method.

    Return:
        A list of symmetrically inequivalent structures with displacements, in
        which the first element is the perfect supercell structure.
    """

    is_plusminus = kwargs.get("is_plusminus", "auto")
    is_diagonal = kwargs.get("is_diagonal", True)
    is_trigonal = kwargs.get("is_trigonal", False)

    ph_structure = get_phonopy_structure(pmg_structure)

    if supercell_matrix is None:
        supercell_matrix = np.eye(3) * np.array((1, 1, 1))

    phonon = Phonopy(unitcell=ph_structure, supercell_matrix=supercell_matrix)
    phonon.generate_displacements(distance=atom_disp,
                                  is_plusminus=is_plusminus,
                                  is_diagonal=is_diagonal,
                                  is_trigonal=is_trigonal)

    if yaml_fname is not None:
        displacements = phonon.get_displacements()
        directions = phonon.get_displacement_directions()
        write_disp_yaml(displacements=displacements,
                        supercell=phonon.get_supercell(),
                        directions=directions, filename=yaml_fname)

    # Supercell structures with displacement
    disp_supercells = phonon.get_supercells_with_displacements()
    # Perfect supercell structure
    init_supercell = phonon.get_supercell()
    # Structure list to be returned
    structure_list = [get_pmg_structure(init_supercell)]

    for c in disp_supercells:
        if c is not None:
            structure_list.append(get_pmg_structure(c))

    return structure_list
開發者ID:ExpHP,項目名稱:pymatgen,代碼行數:55,代碼來源:phonopy.py

示例2: phonopy_pre_process

# 需要導入模塊: from phonopy import Phonopy [as 別名]
# 或者: from phonopy.Phonopy import get_displacements [as 別名]
def phonopy_pre_process(cell, supercell_matrix=None):

    if supercell_matrix is None:
        smat = [[2,0,0], [0,2,0], [0,0,2]],
    else:
        smat = supercell_matrix
    phonon = Phonopy(cell,
                     smat,
                     primitive_matrix=[[0, 0.5, 0.5],
                                       [0.5, 0, 0.5],
                                       [0.5, 0.5, 0]])
    phonon.generate_displacements(distance=0.03)
    print("[Phonopy] Atomic displacements:")
    disps = phonon.get_displacements()
    for d in disps:
        print("[Phonopy] %d %s" % (d[0], d[1:]))
    return phonon
開發者ID:atztogo,項目名稱:phonopy,代碼行數:19,代碼來源:8Si-phonon.py

示例3: PhononBase

# 需要導入模塊: from phonopy import Phonopy [as 別名]
# 或者: from phonopy.Phonopy import get_displacements [as 別名]

#.........這裏部分代碼省略.........
                for task in self._tasks:
                    forces.append(task.get_properties()['forces'][-1])
                self._phonon.produce_force_constants(forces)
                write_FORCE_SETS(self._phonon.get_displacement_dataset())
                self._tasks = []
            elif self._status == "terminate" and self._traverse == "restart":
                self._traverse = False
                disp_terminated = []
                for i, task in enumerate(self._tasks):
                    if task.get_status() == "terminate":
                        disp_terminated.append(i)
                tasks = self._get_displacement_tasks()
                self._tasks = []
                for i in disp_terminated:
                    self._tasks.append(tasks[i])
                    self._phonon_tasks[i + 1] = tasks[i]
                self._status = "displacements"
                return self._tasks
                
        self._write_yaml()
            
        raise StopIteration

    def _set_stage0(self):
        self._status = "equilibrium"
        task = self._get_equilibrium_task()
        self._phonon_tasks = [task]
        self._tasks = [task]
        
    def _set_stage1(self):
        self._stage = 1
        self._status = "displacements"
        self._set_phonon()
        self._tasks = self._get_displacement_tasks()
        self._phonon_tasks += self._tasks

    def _evaluate_stop_condition(self):
        if self._stop_condition:
            if "symmetry_operations" in self._stop_condition:
                num_ops = len(self._space_group['rotations'])
                if (num_ops <
                    self._stop_condition['symmetry_operations']):
                    self._status = "low_symmetry"
                    return True
                    
        return False
        
    def _set_phonon(self):
        cell = self.get_cell()
        phonopy_cell = cell2atoms(cell)
        self._phonon = Phonopy(phonopy_cell,
                               self._supercell_matrix,
                               primitive_matrix=self._primitive_matrix,
                               is_auto_displacements=False,
                               dynamical_matrix_decimals=14,
                               force_constants_decimals=14)
        self._phonon.generate_displacements(
            distance=self._distance,
            is_plusminus=self._displace_plusminus,
            is_diagonal=self._displace_diagonal)
        supercell = self._phonon.get_supercell()
        displacements = self._phonon.get_displacements()

        write_poscar(cell, "POSCAR-unitcell")
        write_disp_yaml(displacements, supercell)

    def _write_yaml(self):
        w = open("%s.yaml" % self._directory, 'w')
        w.write("supercell_matrix:\n")
        for row in self._supercell_matrix:
            w.write("- [ %3d, %3d, %3d ]\n" % tuple(row))
        w.write("primitive_matrix:\n")
        for row in self._primitive_matrix:
            w.write("- [ %6.3f, %6.3f, %6.3f ]\n" % tuple(row))
        w.write("distance: %f\n" % self._distance)
        
        if self._phonon_tasks[0]:
            if self._lattice_tolerance is not None:
                w.write("lattice_tolerance: %f\n" % self._lattice_tolerance)
            if self._stress_tolerance is not None:
                w.write("stress_tolerance: %f\n" % self._stress_tolerance)
                w.write("pressure_target: %f\n" % self._pressure_target)
            w.write("force_tolerance: %f\n" % self._force_tolerance)
            if self._max_increase is None:
                w.write("max_increase: unset\n")
            else:
                w.write("max_increase: %f\n" % self._max_increase)
            w.write("max_iteration: %d\n" % self._max_iteration)
            w.write("min_iteration: %d\n" % self._min_iteration)
            w.write("iteration: %d\n" % self._phonon_tasks[0].get_stage())
            if self._energy:
                w.write("electric_total_energy: %20.10f\n" % self._energy)
                
        w.write("status: %s\n" % self._status)
        w.write("tasks:\n")
        for task in self._phonon_tasks:
            if task and task.get_status():
                w.write("- name:   %s\n" % task.get_name())
                w.write("  status: %s\n" % task.get_status())
        w.close()
開發者ID:vanceeasleaf,項目名稱:cogue,代碼行數:104,代碼來源:phonon.py

示例4: PhononFC3Base

# 需要導入模塊: from phonopy import Phonopy [as 別名]
# 或者: from phonopy.Phonopy import get_displacements [as 別名]

#.........這裏部分代碼省略.........
        self._tasks = self._get_displacement_tasks(start=start_index)
        self._phonon_fc3_tasks += self._tasks

    def _reset_stage2(self):
        self._traverse = False
        disp_terminated = []
        for i, task in enumerate(self._tasks):
            if task.get_status() == "terminate":
                disp_terminated.append(i)

        if self._check_imaginary:
            disp_dataset = self._phonon_fc3.get_displacement_dataset()
            start_index = len(disp_dataset['first_atoms'])
        else:
            start_index = 0
        tasks = self._get_displacement_tasks(start=start_index)
        self._tasks = []
        for i in disp_terminated:
            self._tasks.append(tasks[i])
            self._phonon_fc3_tasks[i + 1 + start_index] = tasks[i]
        self._status = "fc3_displacements"

    def _set_phonon_fc3(self):
        cell = self.get_cell()
        phonopy_cell = cell2atoms(cell)
        self._phonon = Phonopy(phonopy_cell,
                               self._supercell_matrix,
                               primitive_matrix=self._primitive_matrix,
                               dynamical_matrix_decimals=14,
                               force_constants_decimals=14)
        self._phonon_fc3 = Phono3py(phonopy_cell,
                                    self._supercell_matrix,
                                    primitive_matrix=self._primitive_matrix)
        self._phonon_fc3.generate_displacements(distance=self._distance,
                                                is_diagonal=self._is_diagonal)
        supercell = self._phonon_fc3.get_supercell()
        disp_dataset = self._phonon_fc3.get_displacement_dataset()
        self._phonon.set_displacement_dataset(disp_dataset)
        write_poscar(cell, "POSCAR-unitcell")
        write_disp_yaml(self._phonon.get_displacements(),
                        supercell,
                        directions=self._phonon.get_displacement_directions())
        write_disp_fc3_yaml(disp_dataset, supercell)

    def _exist_imaginary_mode(self):
        if self._primitive_matrix is None:
            pmat = np.eye(3)
        else:
            pmat = self._primitive_matrix
        exact_point_matrix = np.dot(np.linalg.inv(self._supercell_matrix),
                                    pmat).T
        max_integer = np.rint(np.amax(np.abs(np.linalg.inv(exact_point_matrix))))
        q_points = []
        for i in np.arange(-max_integer, max_integer + 1):
            for j in np.arange(-max_integer, max_integer + 1):
                for k in np.arange(-max_integer, max_integer + 1):
                    q = np.dot(exact_point_matrix, [i, j, k])
                    if (-1 < q).all() and (q < 1).all():
                        q_points.append(q)
        self._phonon.set_qpoints_phonon(q_points)
        frequencies = self._phonon.get_qpoints_phonon()[0]
        if (frequencies < self._cutoff_frequency).any():
            self._log = "Stop at phonon calculation due to imaginary modes"
            return True
        else:
            return False

    def _write_yaml(self):
        w = open("%s.yaml" % self._directory, 'w')
        if self._lattice_tolerance is not None:
            w.write("lattice_tolerance: %f\n" % self._lattice_tolerance)
        if self._stress_tolerance is not None:
            w.write("stress_tolerance: %f\n" % self._stress_tolerance)
            w.write("pressure_target: %f\n" % self._pressure_target)
        w.write("force_tolerance: %f\n" % self._force_tolerance)
        if self._max_increase is None:
            w.write("max_increase: unset\n")
        else:
            w.write("max_increase: %f\n" % self._max_increase)
        w.write("max_iteration: %d\n" % self._max_iteration)
        w.write("min_iteration: %d\n" % self._min_iteration)
        w.write("supercell_matrix:\n")
        for row in self._supercell_matrix:
            w.write("- [ %3d, %3d, %3d ]\n" % tuple(row))
        if self._primitive_matrix is not None:
            w.write("primitive_matrix:\n")
            for row in self._primitive_matrix:
                w.write("- [ %6.3f, %6.3f, %6.3f ]\n" % tuple(row))
        w.write("distance: %f\n" % self._distance)
        if self._phonon_fc3_tasks[0] is not None:
            w.write("iteration: %d\n" % self._phonon_fc3_tasks[0].get_stage())
            if self._energy:
                w.write("electric_total_energy: %20.10f\n" % self._energy)
        w.write("status: %s\n" % self._status)
        w.write("tasks:\n")
        for task in self._phonon_fc3_tasks:
            if task and task.get_status():
                w.write("- name:   %s\n" % task.get_name())
                w.write("  status: %s\n" % task.get_status())
        w.close()
開發者ID:atztogo,項目名稱:cogue,代碼行數:104,代碼來源:phonon_fc3.py

示例5: PhononBase

# 需要導入模塊: from phonopy import Phonopy [as 別名]
# 或者: from phonopy.Phonopy import get_displacements [as 別名]

#.........這裏部分代碼省略.........
                raise StopIteration
        else: # task 1..n: displaced supercells
            if "next" in self._status:
                self._status = "done"
                forces = []
                for task in self._phonon_tasks[1:]:
                    forces.append(task.get_properties()['forces'][-1])
                self._write_FORCE_SETS(forces)
                self._phonon.set_post_process(self._primitive_matrix,
                                              forces,
                                              force_constants_decimals=14)
                self._tasks = []
                raise StopIteration
            elif "terminate" in self._status and self._traverse == "restart":
                self._traverse = False
                disp_terminated = []
                for i, task in enumerate(self._tasks):
                    if task.get_status() == "terminate":
                        disp_terminated.append(i)
                tasks = self._get_displacement_tasks()[1:]
                self._tasks = []
                for i in disp_terminated:
                    self._tasks.append(tasks[i])
                    self._phonon_tasks[i + 1] = tasks[i]
                self._status = "displacements"
                return self._tasks
            else:
                raise StopIteration

    def _set_stage0(self):
        self._status = "equilibrium"
        task = self._get_equilibrium_task()
        self._phonon_tasks = [task]
        self._tasks = [task]
        
    def _set_stage1(self):
        self._stage = 1
        self._status = "displacements"
        self._set_phonon()
        self._tasks = self._get_displacement_tasks()[1:]
        self._phonon_tasks += self._tasks

    def _set_phonon(self):
        cell = self.get_cell()
        phonopy_cell = Atoms(
            cell=cell.get_lattice().T,
            scaled_positions=cell.get_points().T,
            symbols=cell.get_symbols())
        
        self._phonon = Phonopy(phonopy_cell,
                               self._supercell_matrix,
                               is_auto_displacements=False)
        self._phonon.generate_displacements(distance=self._distance,
                                            is_diagonal=False)

        supercell = self._phonon.get_supercell()
        displacements = self._phonon.get_displacements()

        write_poscar(cell, "POSCAR-unitcell")
        write_disp_yaml(displacements, supercell)

    def _write_FORCE_SETS(self, forces):
        displacements = [[x[0], x[1:4]]
                         for x in self._phonon.get_displacements()]
        natom = self._phonon.get_supercell().get_number_of_atoms()
        write_FORCE_SETS("FORCE_SETS",
                         natom,
                         displacements,
                         forces,
                         verbose=False)

    def _write_yaml(self):
        w = open("%s.yaml" % self._directory, 'w')
        if self._phonon_tasks[0]:
            if self._lattice_tolerance is not None:
                w.write("lattice_tolerance: %f\n" % self._lattice_tolerance)
            if self._stress_tolerance is not None:
                w.write("stress_tolerance: %f\n" % self._stress_tolerance)
                w.write("pressure_target: %f\n" % self._pressure_target)
            w.write("force_tolerance: %f\n" % self._force_tolerance)
            w.write("max_increase: %f\n" % self._max_increase)
            w.write("max_iteration: %d\n" % self._max_iteration)
            w.write("min_iteration: %d\n" % self._min_iteration)
            w.write("supercell_matrix:\n")
            for row in self._supercell_matrix:
                w.write("- [ %3d, %3d, %3d ]\n" % tuple(row))
            w.write("primitive_matrix:\n")
            for row in self._primitive_matrix:
                w.write("- [ %6.3f, %6.3f, %6.3f ]\n" % tuple(row))
            w.write("distance: %f\n" % self._distance)
            w.write("iteration: %d\n" % self._phonon_tasks[0].get_stage())
            if self._energy:
                w.write("electric_total_energy: %20.10f\n" % self._energy)
        w.write("status: %s\n" % self._status)
        w.write("tasks:\n")
        for task in self._phonon_tasks:
            if task and task.get_status():
                w.write("- name:   %s\n" % task.get_name())
                w.write("  status: %s\n" % task.get_status())
        w.close()
開發者ID:mgtekns,項目名稱:cogue,代碼行數:104,代碼來源:phonon.py

示例6: GPAW

# 需要導入模塊: from phonopy import Phonopy [as 別名]
# 或者: from phonopy.Phonopy import get_displacements [as 別名]
                                      (0.75, 0.25, 0.75),
                                      (0.75, 0.75, 0.25)] )
bulk.set_cell(np.diag((a, a, a)))

calc = GPAW(mode=PW(300),
            kpts={'size': (4, 4, 4)},
            symmetry={'symmorphic': False})

phonon = Phonopy(bulk,
                 [[1,0,0],[0,1,0],[0,0,1]],
                 primitive_matrix=[[0, 0.5, 0.5],
                                   [0.5, 0, 0.5],
                                   [0.5, 0.5, 0]],
                 distance=0.01)
print "[Phonopy] Atomic displacements:"
disps = phonon.get_displacements()
for d in disps:
    print "[Phonopy]", d[0], d[1:]
supercells = phonon.get_supercells_with_displacements()

# Force calculations by calculator
set_of_forces = []
for scell in supercells:
    cell = Atoms(symbols=scell.get_chemical_symbols(),
                 scaled_positions=scell.get_scaled_positions(),
                 cell=scell.get_cell(),
                 pbc=True)
    cell.set_calculator(calc)
    forces = cell.get_forces()
    drift_force = forces.sum(axis=0)
    print "[Phonopy] Drift force:", "%11.5f"*3 % tuple(drift_force)
開發者ID:Johnson-Wang,項目名稱:phonopy,代碼行數:33,代碼來源:8Si-phonon.py

示例7: PhononBase

# 需要導入模塊: from phonopy import Phonopy [as 別名]
# 或者: from phonopy.Phonopy import get_displacements [as 別名]

#.........這裏部分代碼省略.........
        self._status = "displacements"
        self._set_phonon()
        self._tasks = self._get_displacement_tasks()
        self._all_tasks += self._tasks

    def _set_stage2(self):
        self._stage = 2
        self._status = "nac"
        if self._nac == "relax":
            nac_task = self._get_nac_task(is_cell_relaxed=False)
        else:
            nac_task = self._get_nac_task()
        self._tasks = [nac_task]
        self._all_tasks += self._tasks

    def _collect_forces(self):
        forces = []
        for task in self._tasks:
            forces.append(task.get_properties()['forces'][-1])
        if self._phonon.produce_force_constants(forces=forces):
            write_FORCE_SETS(self._phonon.get_displacement_dataset())
            return True
        else:
            # This can be due to delay of writting file to file system.
            return False

    def _set_born_and_epsilon(self):
        nac_task = self._tasks[0]
        born = nac_task.get_born_effective_charge()
        epsilon = nac_task.get_dielectric_constant()

        indep_atoms = self._phonon.get_symmetry().get_independent_atoms()
        supercell = self._phonon.get_supercell()
        s2u = supercell.get_supercell_to_unitcell_map()
        u2u = supercell.get_unitcell_to_unitcell_map()
        indep_atoms_u = [u2u[i] for i in s2u[indep_atoms]]

        if born is not None and epsilon is not None:
            self._born = born
            self._epsilon = epsilon
            header = "# epsilon and Z* of atoms "
            header += ' '.join(["%d" % (n + 1) for n in indep_atoms_u])
            lines = [header]
            lines.append(("%13.8f" * 9) % tuple(epsilon.flatten()))
            for z in born[indep_atoms_u]:
                lines.append(("%13.8f" * 9) % tuple(z.flatten()))
            with open("BORN", 'w') as w:
                w.write('\n'.join(lines))

    def _evaluate_stop_condition(self):
        if self._stop_condition:
            if "symmetry_operations" in self._stop_condition:
                num_ops = len(self._space_group['rotations'])
                if (num_ops <
                    self._stop_condition['symmetry_operations']):
                    self._status = "low_symmetry"
                    return True

        return False

    def _set_phonon(self):
        if self._supercell_matrix is None:
            cell = sort_cell_by_symbols(
                get_crystallographic_cell(self.get_cell()))
            self._supercell_matrix = estimate_supercell_matrix(
                cell,
                max_num_atoms=self._max_num_atoms)
        else:
            cell = self.get_cell()

        phonopy_cell = cell2atoms(cell)
        self._phonon = Phonopy(phonopy_cell,
                               self._supercell_matrix,
                               primitive_matrix=self._primitive_matrix,
                               dynamical_matrix_decimals=14,
                               force_constants_decimals=14,
                               symprec=self._symmetry_tolerance)
        self._phonon.generate_displacements(
            distance=self._distance,
            is_plusminus=self._displace_plusminus,
            is_diagonal=self._displace_diagonal)
        supercell = self._phonon.get_supercell()
        displacements = self._phonon.get_displacements()

        write_poscar(cell, filename="POSCAR-unitcell")
        write_poscar_yaml(cell, filename="POSCAR-unitcell.yaml")
        write_disp_yaml(displacements, supercell)

    def get_yaml_lines(self):
        lines = TaskElement.get_yaml_lines(self)
        if self._is_cell_relaxed:
            cell = self._cell
        else:
            cell = self.get_cell()
        lines += self._get_phonon_yaml_lines(cell)
        if self._all_tasks[0] is not None:
            if self._energy:
                lines.append("electric_total_energy: %20.10f" % self._energy)

        return lines
開發者ID:atztogo,項目名稱:cogue,代碼行數:104,代碼來源:phonon.py


注:本文中的phonopy.Phonopy.get_displacements方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。