Esempio n. 1
0
 def _get_phonon(self, spgtype, dim, pmat):
     cell = read_vasp("POSCAR_%s" % spgtype)
     phonon = Phonopy(cell, np.diag(dim), primitive_matrix=pmat)
     force_sets = parse_FORCE_SETS(filename="FORCE_SETS_%s" % spgtype)
     phonon.set_displacement_dataset(force_sets)
     phonon.produce_force_constants()
     print(phonon.get_symmetry().get_pointgroup())
     return phonon
Esempio n. 2
0
 def _get_phonon(self, spgtype, dim, pmat):
     cell = read_vasp(os.path.join(data_dir,"POSCAR_%s" % spgtype))
     phonon = Phonopy(cell,
                      np.diag(dim),
                      primitive_matrix=pmat)
     force_sets = parse_FORCE_SETS(filename=os.path.join(data_dir,"FORCE_SETS_%s" % spgtype))
     phonon.set_displacement_dataset(force_sets)
     phonon.produce_force_constants()
     print(phonon.get_symmetry().get_pointgroup())
     return phonon
Esempio n. 3
0
    def get_spacegroup_string(self, symprec=0.001):
        """
		Returns string of spacegroup information like Imma (74).

		symprec controls the symmetry tolerance for atomic positions (in Angstroms)
		"""

        unit_cell_phonopy_structure = self.convert_structure_to_phonopy_atoms()
        supercell_dimensions_matrix = np.diag([1, 1, 1])

        phonon = Phonopy(unitcell=unit_cell_phonopy_structure,
                         supercell_matrix=supercell_dimensions_matrix,
                         symprec=symprec)

        symmetry = phonon.get_symmetry()

        return str(symmetry.get_international_table())
Esempio n. 4
0
#                                           [0.5, 0, 0.5],
#                                           [0.5, 0.5, 0],
#                                           [0.5, 0.5, 0.5],
#                                           [0.5, 0, 0],
#                                           [0, 0.5, 0],
#                                           [0, 0, 0.5]])

phonon = Phonopy(unitcell,
                 [[2, 0, 0],
                  [0, 2, 0],
                  [0, 0, 2]],
                 primitive_matrix=[[0, 0.5, 0.5],
                                   [0.5, 0, 0.5],
                                   [0.5, 0.5, 0]])

symmetry = phonon.get_symmetry()
print "Space group:", symmetry.get_international_table()

force_sets = parse_FORCE_SETS()
phonon.set_displacement_dataset(force_sets)
phonon.produce_force_constants()
primitive = phonon.get_primitive()

# Born effective charges and dielectric constants are read from BORN file.
nac_params = parse_BORN(primitive, filename="BORN")
# Or it can be of course given by hand as follows:
# born = [[[1.08703, 0, 0],
#          [0, 1.08703, 0],
#          [0, 0, 1.08703]],
#         [[-1.08672, 0, 0],
#          [0, -1.08672, 0],
Esempio n. 5
0
from phonopy import Phonopy
from phonopy.interface.vasp import read_vasp
from phonopy.file_IO import parse_FORCE_SETS, parse_BORN
import numpy as np

cell = read_vasp("POSCAR")

# Initialize phonon. Supercell matrix has to have the shape of (3, 3)
phonon = Phonopy(cell, np.diag([3, 3, 2]))

symmetry = phonon.get_symmetry()
print "Space group:", symmetry.get_international_table()

# Read forces and displacements
force_sets = parse_FORCE_SETS()

# Sets of forces have to be set before phonon.set_post_process or
# at phonon.set_post_process(..., sets_of_forces=sets_of_forces, ...).
phonon.set_force_sets(force_sets)
phonon.set_post_process()

# Character table
phonon.set_irreps([1./3, 1./3, 0], 1e-4)
ct = phonon.get_irreps() 
band_indices = ct.get_band_indices()
characters = np.rint(ct.get_characters()).real
for bi, cts in zip(band_indices, characters):
    print np.array(bi) + 1, cts
# phonon.show_character_table()
Esempio n. 6
0
def calculate_phonon(atoms,
                     calc=None,
                     forces_set_file=None,
                     ndim=np.eye(3),
                     primitive_matrix=np.eye(3),
                     distance=0.01,
                     factor=VaspToTHz,
                     is_plusminus='auto',
                     is_symmetry=True,
                     symprec=1e-5,
                     func=None,
                     prepare_initial_wavecar=False,
                     skip=None,
                     restart=True,
                     parallel=True,
                     sc_mag=None,
                     **func_args):
    """
    """
    if 'magmoms' in atoms.arrays or 'initial_magmoms' in atoms.arrays:
        is_mag = True
    else:
        is_mag = False
    print("is_mag: ", is_mag)
    # 1. get displacements and supercells
    if calc is not None:
        atoms.set_calculator(calc)
    # bulk = PhonopyAtoms(atoms=atoms)
    if is_mag:
        bulk = PhonopyAtoms(
            symbols=atoms.get_chemical_symbols(),
            scaled_positions=atoms.get_scaled_positions(),
            cell=atoms.get_cell(),
            magmoms=atoms.arrays['initial_magmoms'],
        )
    else:
        bulk = PhonopyAtoms(symbols=atoms.get_chemical_symbols(),
                            scaled_positions=atoms.get_scaled_positions(),
                            cell=atoms.get_cell())

    phonon = Phonopy(bulk,
                     ndim,
                     primitive_matrix=primitive_matrix,
                     factor=factor,
                     symprec=symprec)
    phonon.generate_displacements(distance=distance, is_plusminus=is_plusminus)
    disps = phonon.get_displacements()
    for d in disps:
        print(("[phonopy] %d %s" % (d[0], d[1:])))
    supercell0 = phonon.get_supercell()
    supercells = phonon.get_supercells_with_displacements()
    #write_supercells_with_displacements(supercell0, supercells)
    write_disp_yaml(disps, supercell0)

    # 2. calculated forces.
    if forces_set_file is not None:
        symmetry = phonon.get_symmetry()
        set_of_forces = parse_FORCE_SETS(
            is_translational_invariance=False,
            filename=forces_set_file)  # ['first_atoms']
        # set_of_forces=np.array(set_of_forces)
        #set_of_forces=[np.asarray(f) for f in set_of_forces]
        phonon.set_displacement_dataset(set_of_forces)
        phonon.produce_force_constants()
    else:
        # initialize set of forces
        if restart and os.path.exists('forces_set.pickle'):
            try:
                with open("forces_set.pickle", 'rb') as myfile:
                    set_of_forces = pickle.load(myfile)
                iskip = len(set_of_forces) - 1
            except:
                set_of_forces = []
                iskip = -1
        else:
            set_of_forces = []
            iskip = -1

        if prepare_initial_wavecar and skip is None:
            scell = supercell0
            cell = Atoms(symbols=scell.get_chemical_symbols(),
                         scaled_positions=scell.get_scaled_positions(),
                         cell=scell.get_cell(),
                         pbc=True)
            if is_mag:
                cell.set_initial_magnetic_moments(sc_mag)
            write('Supercell.cif', cell)
            mcalc = copy.deepcopy(calc)
            mcalc.set(lwave=True, lcharg=True)
            cell.set_calculator(mcalc)
            dir_name = "SUPERCELL0"
            cur_dir = os.getcwd()
            if not os.path.exists(dir_name):
                os.mkdir(dir_name)
            os.chdir(dir_name)
            mcalc.scf_calculation(cell)
            os.chdir(cur_dir)

        def calc_force(iscell):
            scell = supercells[iscell]
            cell = Atoms(symbols=scell.get_chemical_symbols(),
                         scaled_positions=scell.get_scaled_positions(),
                         cell=scell.get_cell(),
                         pbc=True)
            if is_mag:
                cell.set_initial_magnetic_moments(sc_mag)
            cell.set_calculator(copy.deepcopy(calc))
            dir_name = "PHON_CELL%s" % iscell
            cur_dir = os.getcwd()
            if not os.path.exists(dir_name):
                os.mkdir(dir_name)
            if prepare_initial_wavecar:
                os.system('ln -s %s %s' %
                          (os.path.abspath("SUPERCELL0/WAVECAR"),
                           os.path.join(dir_name, 'WAVECAR')))

            os.chdir(dir_name)
            forces = cell.get_forces()
            print("[Phonopy] Forces: %s" % forces)
            # Do something other than calculating the forces with func.
            # func: func(atoms, calc, func_args)
            if func is not None:
                func(cell, calc, **func_args)
            os.chdir(cur_dir)
            drift_force = forces.sum(axis=0)
            print("[Phonopy] Drift force:", "%11.5f" * 3 % tuple(drift_force))
            # Simple translational invariance
            for force in forces:
                force -= drift_force / forces.shape[0]
            return forces

        if parallel:
            p = Pool()
            set_of_forces = p.map(calc_force,
                                  list(range(iskip, len(supercells))))
        else:
            for iscell, scell in enumerate(supercells):
                if iscell > iskip:
                    fs = calc_force(iscell)
                    set_of_forces.append(fs)
                    with open("forces_set.pickle", 'wb') as myfile:
                        pickle.dump(set_of_forces, myfile)

        phonon.produce_force_constants(forces=np.array(set_of_forces))
    force_constants = phonon.get_force_constants()
    write_FORCE_CONSTANTS(force_constants, filename='FORCE_CONSTANTS')
    #print("[Phonopy] Phonon frequencies at Gamma:")
    # for i, freq in enumerate(phonon.get_frequencies((0, 0, 0))):
    #    print(("[Phonopy] %3d: %10.5f THz" % (i + 1, freq)))  # THz
    #    print(("[Phonopy] %3d: %10.5f cm-1" % (i + 1, freq * 33.35)))  #cm-1
    with open('phonon.pickle', 'wb') as myfile:
        pickle.dump(phonon, myfile)
    phonon.save(settings={'force_constants': True})
    return phonon
Esempio n. 7
0
# initial settings
#
cell = read_vasp_from_strings(poscar_str)
phonon = Phonopy(cell, np.diag([2, 2, 2]))
force_sets = parse_FORCE_SETS_from_strings(force_sets_str,
                                           cell.get_number_of_atoms() * 8)
phonon.set_force_sets(force_sets)
phonon.set_post_process(primitive_matrix=[[0, 0.5, 0.5],
                                          [0.5, 0, 0.5],
                                          [0.5, 0.5, 0]],
                        is_nac=True)
born_params = parse_BORN_from_strings(born_str,
                                      phonon.get_primitive())
phonon.set_nac_params(born_params)                                      

print phonon.get_symmetry().get_international_table()
primitive = phonon.get_primitive()
reclat = np.linalg.inv(primitive.get_cell())
print reclat

ndiv = 100
band = get_band([0.0, 0.0, 0.0], [0.5, 0.5, 0.0], ndiv)
bands = [band]
phonon.set_band_structure(bands)

#
# Run1
#
band_index = 2
vg = GroupVelocity(phonon.get_dynamical_matrix(), phonon.get_primitive(), q_length=1e-5)
q_points = band