示例#1
0
    def __init__(self,
                 force_constants_filename=None,
                 poscar=None,
                 poscar_ideal=None,
                 phonopy_conf=None,
                 is_symmetrized=True):

        if poscar_ideal is None:
            poscar_ideal = poscar

        force_constants = parse_FORCE_CONSTANTS(force_constants_filename)

        atoms = read_vasp(poscar)
        atoms_ideal = read_vasp(poscar_ideal)

        supercell_matrix = read_supercell_matrix(phonopy_conf)

        # force_constants_analyzer.generate_symmetrized_force_constants(
        #     atoms_symmetry)
        # force_constants_analyzer.write_force_constants_pair()

        super(VaspFCAnalyzer, self).__init__(force_constants=force_constants,
                                             atoms=atoms,
                                             atoms_ideal=atoms_ideal,
                                             supercell_matrix=supercell_matrix,
                                             is_symmetrized=True)

        # force_constants_analyzer.check_translational_invariance()

        self.generate_symmetrized_force_constants()
        self.write_force_constants_symmetrized()
示例#2
0
def read_crystal_structure(filename=None,
                           interface_mode=None,
                           chemical_symbols=None,
                           yaml_mode=False):
    if filename is None:
        unitcell_filename = get_default_cell_filename(interface_mode,
                                                      yaml_mode)
    else:
        unitcell_filename = filename

    if not os.path.exists(unitcell_filename):
        if filename is None:
            return None, (unitcell_filename + " (default file name)", )
        else:
            return None, (unitcell_filename, )

    if yaml_mode:
        from phonopy.interface.phonopy_yaml import PhonopyYaml
        phpy_yaml = PhonopyYaml()
        phpy_yaml.read(unitcell_filename)
        unitcell = phpy_yaml.get_unitcell()
        return unitcell, (unitcell_filename, )

    if interface_mode is None or interface_mode == 'vasp':
        from phonopy.interface.vasp import read_vasp
        if chemical_symbols is None:
            unitcell = read_vasp(unitcell_filename)
        else:
            unitcell = read_vasp(unitcell_filename, symbols=chemical_symbols)
        return unitcell, (unitcell_filename, )

    if interface_mode == 'abinit':
        from phonopy.interface.abinit import read_abinit
        unitcell = read_abinit(unitcell_filename)
        return unitcell, (unitcell_filename, )

    if interface_mode == 'pwscf':
        from phonopy.interface.pwscf import read_pwscf
        unitcell, pp_filenames = read_pwscf(unitcell_filename)
        return unitcell, (unitcell_filename, pp_filenames)

    if interface_mode == 'wien2k':
        from phonopy.interface.wien2k import parse_wien2k_struct
        unitcell, npts, r0s, rmts = parse_wien2k_struct(unitcell_filename)
        return unitcell, (unitcell_filename, npts, r0s, rmts)

    if interface_mode == 'elk':
        from phonopy.interface.elk import read_elk
        unitcell, sp_filenames = read_elk(unitcell_filename)
        return unitcell, (unitcell_filename, sp_filenames)

    if interface_mode == 'siesta':
        from phonopy.interface.siesta import read_siesta
        unitcell, atypes = read_siesta(unitcell_filename)
        return unitcell, (unitcell_filename, atypes)

    if interface_mode == 'crystal':
        from phonopy.interface.crystal import read_crystal
        unitcell, conv_numbers = read_crystal(unitcell_filename)
        return unitcell, (unitcell_filename, conv_numbers)
示例#3
0
    def __init__(self,
                 force_constants_filename=None,
                 poscar=None,
                 poscar_ideal=None,
                 phonopy_conf=None,
                 is_symmetrized=True):

        if poscar_ideal is None:
            poscar_ideal = poscar

        force_constants = parse_FORCE_CONSTANTS(force_constants_filename)

        atoms = read_vasp(poscar)
        atoms_ideal = read_vasp(poscar_ideal)

        supercell_matrix = read_supercell_matrix(phonopy_conf)

        # force_constants_analyzer.generate_symmetrized_force_constants(
        #     atoms_symmetry)
        # force_constants_analyzer.write_force_constants_pair()

        super(VaspFCAnalyzer, self).__init__(
            force_constants=force_constants,
            atoms=atoms,
            atoms_ideal=atoms_ideal,
            supercell_matrix=supercell_matrix,
            is_symmetrized=True)

        # force_constants_analyzer.check_translational_invariance()

        self.generate_symmetrized_force_constants()
        self.write_force_constants_symmetrized()
示例#4
0
def read_crystal_structure(filename=None,
                           interface_mode=None,
                           chemical_symbols=None,
                           command_name="phonopy"):
    if interface_mode == 'phonopy_yaml':
        return _read_phonopy_yaml(filename, command_name)

    if filename is None:
        cell_filename = get_default_cell_filename(interface_mode)
        if not os.path.isfile(cell_filename):
            return None, (cell_filename, "(default file name)")
    else:
        cell_filename = filename
        if not os.path.isfile(cell_filename):
            return None, (cell_filename, )

    if interface_mode is None or interface_mode == 'vasp':
        from phonopy.interface.vasp import read_vasp
        if chemical_symbols is None:
            unitcell = read_vasp(cell_filename)
        else:
            unitcell = read_vasp(cell_filename, symbols=chemical_symbols)
        return unitcell, (cell_filename, )
    elif interface_mode == 'abinit':
        from phonopy.interface.abinit import read_abinit
        unitcell = read_abinit(cell_filename)
        return unitcell, (cell_filename, )
    elif interface_mode == 'qe':
        from phonopy.interface.qe import read_pwscf
        unitcell, pp_filenames = read_pwscf(cell_filename)
        return unitcell, (cell_filename, pp_filenames)
    elif interface_mode == 'wien2k':
        from phonopy.interface.wien2k import parse_wien2k_struct
        unitcell, npts, r0s, rmts = parse_wien2k_struct(cell_filename)
        return unitcell, (cell_filename, npts, r0s, rmts)
    elif interface_mode == 'elk':
        from phonopy.interface.elk import read_elk
        unitcell, sp_filenames = read_elk(cell_filename)
        return unitcell, (cell_filename, sp_filenames)
    elif interface_mode == 'siesta':
        from phonopy.interface.siesta import read_siesta
        unitcell, atypes = read_siesta(cell_filename)
        return unitcell, (cell_filename, atypes)
    elif interface_mode == 'cp2k':
        from phonopy.interface.cp2k import read_cp2k
        unitcell = read_cp2k(cell_filename)
        return unitcell, (cell_filename, )
    elif interface_mode == 'crystal':
        from phonopy.interface.crystal import read_crystal
        unitcell, conv_numbers = read_crystal(cell_filename)
        return unitcell, (cell_filename, conv_numbers)
    elif interface_mode == 'dftbp':
        from phonopy.interface.dftbp import read_dftbp
        unitcell = read_dftbp(cell_filename)
        return unitcell, (cell_filename, )
    elif interface_mode == 'turbomole':
        from phonopy.interface.turbomole import read_turbomole
        unitcell = read_turbomole(cell_filename)
        return unitcell, (cell_filename, )
 def prepare_L1_2(self):
     unitcell = read_vasp("poscars/POSCAR_L1_2")
     primitive_matrix = [
         [0.0, 0.5, 0.5],
         [0.5, 0.0, 0.5],
         [0.5, 0.5, 0.0],
     ]
     unitcell_ideal = read_vasp("poscars/POSCAR_fcc")
     return unitcell, unitcell_ideal, primitive_matrix
 def prepare_L1_2(self):
     unitcell = read_vasp(os.path.join(POSCAR_DIR, "POSCAR_L1_2"))
     primitive_matrix = [
         [0.0, 0.5, 0.5],
         [0.5, 0.0, 0.5],
         [0.5, 0.5, 0.0],
     ]
     unitcell_ideal = read_vasp(os.path.join(POSCAR_DIR, "POSCAR_fcc"))
     return unitcell, unitcell_ideal, primitive_matrix
 def prepare_L1_2(self):
     unitcell = read_vasp("poscars/POSCAR_L1_2")
     primitive_matrix = [
         [0.0, 0.5, 0.5],
         [0.5, 0.0, 0.5],
         [0.5, 0.5, 0.0],
     ]
     unitcell_ideal = read_vasp("poscars/POSCAR_fcc")
     return unitcell, unitcell_ideal, primitive_matrix
示例#8
0
文件: __init__.py 项目: nfh/phonopy
def read_crystal_structure(filename=None, interface_mode="vasp", chemical_symbols=None, yaml_mode=False):
    if filename is None:
        unitcell_filename = get_default_cell_filename(interface_mode, yaml_mode)
    else:
        unitcell_filename = filename

    if not os.path.exists(unitcell_filename):
        if filename is None:
            return None, (unitcell_filename + " (default file name)",)
        else:
            return None, (unitcell_filename,)

    if yaml_mode:
        from phonopy.interface.phonopy_yaml import phonopyYaml

        unitcell = phonopyYaml(unitcell_filename).get_atoms()
        return unitcell, (unitcell_filename,)

    if interface_mode == "vasp":
        from phonopy.interface.vasp import read_vasp

        if chemical_symbols is None:
            unitcell = read_vasp(unitcell_filename)
        else:
            unitcell = read_vasp(unitcell_filename, symbols=chemical_symbols)
        return unitcell, (unitcell_filename,)

    if interface_mode == "abinit":
        from phonopy.interface.abinit import read_abinit

        unitcell = read_abinit(unitcell_filename)
        return unitcell, (unitcell_filename,)

    if interface_mode == "pwscf":
        from phonopy.interface.pwscf import read_pwscf

        unitcell, pp_filenames = read_pwscf(unitcell_filename)
        return unitcell, (unitcell_filename, pp_filenames)

    if interface_mode == "wien2k":
        from phonopy.interface.wien2k import parse_wien2k_struct

        unitcell, npts, r0s, rmts = parse_wien2k_struct(unitcell_filename)
        return unitcell, (unitcell_filename, npts, r0s, rmts)

    if interface_mode == "elk":
        from phonopy.interface.elk import read_elk

        unitcell, sp_filenames = read_elk(unitcell_filename)
        return unitcell, (unitcell_filename, sp_filenames)

    if interface_mode == "siesta":
        from phonopy.interface.siesta import read_siesta

        unitcell, atypes = read_siesta(unitcell_filename)
        return unitcell, (unitcell_filename, atypes)
示例#9
0
def read_crystal_structure(filename=None,
                           interface_mode=None,
                           chemical_symbols=None,
                           yaml_mode=False):
    if filename is None:
        unitcell_filename = get_default_cell_filename(interface_mode, yaml_mode)
    else:
        unitcell_filename = filename

    if not os.path.exists(unitcell_filename):
        if filename is None:
            return None, (unitcell_filename + " (default file name)",)
        else:
            return None, (unitcell_filename,)

    if yaml_mode:
        from phonopy.interface.phonopy_yaml import PhonopyYaml
        phpy_yaml = PhonopyYaml()
        phpy_yaml.read(unitcell_filename)
        unitcell = phpy_yaml.get_unitcell()
        return unitcell, (unitcell_filename,)

    if interface_mode is None or interface_mode == 'vasp':
        from phonopy.interface.vasp import read_vasp
        if chemical_symbols is None:
            unitcell = read_vasp(unitcell_filename)
        else:
            unitcell = read_vasp(unitcell_filename, symbols=chemical_symbols)
        return unitcell, (unitcell_filename,)

    if interface_mode == 'abinit':
        from phonopy.interface.abinit import read_abinit
        unitcell = read_abinit(unitcell_filename)
        return unitcell, (unitcell_filename,)

    if interface_mode == 'pwscf':
        from phonopy.interface.pwscf import read_pwscf
        unitcell, pp_filenames = read_pwscf(unitcell_filename)
        return unitcell, (unitcell_filename, pp_filenames)

    if interface_mode == 'wien2k':
        from phonopy.interface.wien2k import parse_wien2k_struct
        unitcell, npts, r0s, rmts = parse_wien2k_struct(unitcell_filename)
        return unitcell, (unitcell_filename, npts, r0s, rmts)

    if interface_mode == 'elk':
        from phonopy.interface.elk import read_elk
        unitcell, sp_filenames = read_elk(unitcell_filename)
        return unitcell, (unitcell_filename, sp_filenames)

    if interface_mode == 'siesta':
        from phonopy.interface.siesta import read_siesta
        unitcell, atypes = read_siesta(unitcell_filename)
        return unitcell, (unitcell_filename, atypes)
示例#10
0
 def _get_phonon(self):
     cell = read_vasp(os.path.join(data_dir, "..", "POSCAR_NaCl"))
     phonon = Phonopy(cell,
                      np.diag([2, 2, 2]),
                      primitive_matrix=[[0, 0.5, 0.5],
                                        [0.5, 0, 0.5],
                                        [0.5, 0.5, 0]])
     filename = os.path.join(data_dir, "FORCE_SETS_NaCl")
     force_sets = parse_FORCE_SETS(filename=filename)
     phonon.set_displacement_dataset(force_sets)
     phonon.produce_force_constants()
     born_elems = {'Na': [[1.08703, 0, 0],
                          [0, 1.08703, 0],
                          [0, 0, 1.08703]],
                   'Cl': [[-1.08672, 0, 0],
                          [0, -1.08672, 0],
                          [0, 0, -1.08672]]}
     born = [born_elems[s] for s in ['Na', 'Cl']]
     epsilon = [[2.43533967, 0, 0],
                [0, 2.43533967, 0],
                [0, 0, 2.43533967]]
     factors = 14.400
     phonon.set_nac_params({'born': born,
                            'factor': factors,
                            'dielectric': epsilon})
     return phonon
示例#11
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()
     return phonon
 def setUp(self):
     self._atoms = read_vasp('poscars/POSCAR_fcc_2x2x2')
     self._primitive_matrix = np.array([
         [0.00, 0.25, 0.25],
         [0.25, 0.00, 0.25],
         [0.25, 0.25, 0.00],
     ])
示例#13
0
 def setUp(self):
     self._atoms = read_vasp(os.path.join(POSCAR_DIR, 'POSCAR_fcc_2x2x2'))
     self._primitive_matrix = np.array([
         [0.00, 0.25, 0.25],
         [0.25, 0.00, 0.25],
         [0.25, 0.25, 0.00],
     ])
示例#14
0
    def test_a3(self):
        filename = "../poscars/POSCAR_A3"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, '6/mmm')

        p = [0.0, 0.0, 0.5]  # A (6/mmm)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '6/mmm')

        p = [1.0 / 3.0, 1.0 / 3.0, 0.0]  # K (-6m2)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '-6m2')

        p = [0.5, 0.0, 0.0]  # M (mmm)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, 'mmm')

        p = [0.5, 0.0, 0.5]  # L (mmm)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, 'mmm')

        p = [0.0, 0.0, 0.25]  # DT (6mm)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '6mm')
示例#15
0
def create_supercells_with_displacements():
    """Create supercells with displacements."""
    cell = read_vasp("POSCAR-unitcell")
    ph3 = Phono3py(cell, np.diag([2, 2, 2]), primitive_matrix="F")
    ph3.generate_displacements(distance=0.03)
    print(ph3.supercells_with_displacements)  # List of PhonopyAtoms
    print(ph3.displacements.shape)  # (supercells, atoms, xyz)
示例#16
0
    def test_cl12pd6(self):
        filename = "../poscars/POSCAR_Cl12Pd6"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)  # 148

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, '-3')
示例#17
0
    def test_thcl4(self):
        filename = "../poscars/POSCAR_ThCl4"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)  # 88

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, '4/m')
 def input_files(self, path_POSCAR, path_FORCECONSTANT):
     bulk = read_vasp(path_POSCAR)
     self.phonon = Phonopy(bulk,
                           self.super_cell,
                           primitive_matrix=self.primitive_cell)
     force_constants = file_IO.parse_FORCE_CONSTANTS(path_FORCECONSTANT)
     self.phonon.set_force_constants(force_constants)
     return self.phonon
示例#19
0
def main():
    import argparse
    from phonopy.interface.vasp import read_vasp
    parser = argparse.ArgumentParser()
    parser.add_argument('atoms', type=str, help="POSCAR")
    args = parser.parse_args()
    atoms = read_vasp(args.atoms)
    VolumeVoronoi(atoms).run()
示例#20
0
    def test_97(self):
        filename = "../poscars/POSCAR_NaGdCu2F8"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, '422')
示例#21
0
def _compare(cell):
    cell_ref = read_vasp(os.path.join(data_dir, "..", "POSCAR_NaCl"))
    assert (np.abs(cell.cell - cell_ref.cell) < 1e-5).all()
    diff_pos = cell.scaled_positions - cell_ref.scaled_positions
    diff_pos -= np.rint(diff_pos)
    assert (np.abs(diff_pos) < 1e-5).all()
    for s, s_r in zip(cell.symbols, cell_ref.symbols):
        assert s == s_r
示例#22
0
    def test_b_h(self):
        filename = "tests/poscars/POSCAR_WC"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, '-6m2')
示例#23
0
 def _compare(self, cell):
     cell_ref = read_vasp(os.path.join(data_dir, "../POSCAR_NaCl"))
     self.assertTrue((np.abs(cell.get_cell() - cell_ref.get_cell()) < 1e-5).all())
     diff_pos = cell.get_scaled_positions() - cell_ref.get_scaled_positions()
     diff_pos -= np.rint(diff_pos)
     self.assertTrue((np.abs(diff_pos) < 1e-5).all())
     for s, s_r in zip(cell.get_chemical_symbols(), cell_ref.get_chemical_symbols()):
         self.assertTrue(s == s_r)
示例#24
0
def _get_phonon(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.dataset = force_sets
    phonon.produce_force_constants()
    return phonon
示例#25
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)
     filename = os.path.join(data_dir, "FORCE_SETS_%s" % spgtype)
     force_sets = parse_FORCE_SETS(filename=filename)
     phonon.set_displacement_dataset(force_sets)
     phonon.produce_force_constants()
     print(phonon.get_symmetry().get_pointgroup())
     return phonon
示例#26
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()
     return phonon
示例#27
0
def get_frequency(poscar_filename, force_sets_filename):
    bulk = read_vasp(poscar_filename)
    volume = bulk.get_volume()
    phonon = Phonopy(bulk, [[2, 0, 0], [0, 2, 0], [0, 0, 2]],
                     is_auto_displacements=False)
    force_sets = parse_FORCE_SETS(filename=force_sets_filename)
    phonon.set_force_sets(force_sets)
    phonon.set_post_process([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]])
    return phonon.get_frequencies([0.5, 0.5, 0]), volume
示例#28
0
def get_frequency(poscar_filename, force_sets_filename):
    bulk = read_vasp(poscar_filename)
    volume = bulk.get_volume()
    phonon = Phonopy(bulk, [[2, 0, 0], [0, 2, 0], [0, 0, 2]],
                     is_auto_displacements=False)
    force_sets = parse_FORCE_SETS(filename=force_sets_filename)
    phonon.set_force_sets(force_sets)
    phonon.set_post_process([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]])
    return phonon.get_frequencies([0.5, 0.5, 0]), volume
 def test_B3(self):
     unitcell = read_vasp("poscars/POSCAR_B3_conv")
     primitive_matrix = [
         [0.0, 0.5, 0.5],
         [0.5, 0.0, 0.5],
         [0.5, 0.5, 0.0],
     ]
     primitive = get_primitive(unitcell, primitive_matrix)
     self.check(unitcell, primitive)
 def test_B3(self):
     unitcell = read_vasp("poscars/POSCAR_B3_conv")
     primitive_matrix = [
         [0.0, 0.5, 0.5],
         [0.5, 0.0, 0.5],
         [0.5, 0.5, 0.0],
     ]
     primitive = get_primitive(unitcell, primitive_matrix)
     self.check(unitcell, primitive)
 def test_B3(self):
     unitcell = read_vasp(os.path.join(POSCAR_DIR, "POSCAR_B3_conv"))
     primitive_matrix = [
         [0.0, 0.5, 0.5],
         [0.5, 0.0, 0.5],
         [0.5, 0.5, 0.0],
     ]
     primitive = get_primitive(unitcell, primitive_matrix)
     self.check(unitcell, primitive)
示例#32
0
def get_frequency(poscar_filename, force_sets_filename):
    unitcell = read_vasp(poscar_filename)
    volume = unitcell.get_volume()
    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]])
    force_sets = parse_FORCE_SETS(filename=force_sets_filename)
    phonon.set_displacement_dataset(force_sets)
    phonon.produce_force_constants()
    return phonon.get_frequencies([0.5, 0.5, 0]), volume
示例#33
0
 def create_primitive(self, filename="POSCAR", conf_file=None):
     from phonopy.structure.cells import get_primitive
     from phonopy.interface.vasp import read_vasp
     if conf_file is None:
         self._check_conf_files()
     else:
         self.set_conf_file(conf_file)
     primitive_matrix = self._read_primitive_matrix()
     atoms = read_vasp(filename)
     return get_primitive(atoms, primitive_matrix)
示例#34
0
 def create_primitive(self, filename="POSCAR", conf_file=None):
     from phonopy.structure.cells import get_primitive
     from phonopy.interface.vasp import read_vasp
     if conf_file is None:
         self._check_conf_files()
     else:
         self.set_conf_file(conf_file)
     primitive_matrix = self._read_primitive_matrix()
     atoms = read_vasp(filename)
     return get_primitive(atoms, primitive_matrix)
示例#35
0
def test_read_vasp():
    """Test read_vasp."""
    cell = read_vasp(os.path.join(data_dir, "..", "POSCAR_NaCl"))
    filename = os.path.join(data_dir, "NaCl-vasp.yaml")
    cell_ref = read_cell_yaml(filename)
    assert (np.abs(cell.cell - cell_ref.cell) < 1e-5).all()
    diff_pos = cell.scaled_positions - cell_ref.scaled_positions
    diff_pos -= np.rint(diff_pos)
    assert (np.abs(diff_pos) < 1e-5).all()
    for s, s_r in zip(cell.symbols, cell_ref.symbols):
        assert s == s_r
示例#36
0
 def _compare(self, cell):
     cell_ref = read_vasp(os.path.join(data_dir, "..", "POSCAR_NaCl"))
     self.assertTrue(
         (np.abs(cell.get_cell() - cell_ref.get_cell()) < 1e-5).all())
     diff_pos = (cell.get_scaled_positions() -
                 cell_ref.get_scaled_positions())
     diff_pos -= np.rint(diff_pos)
     self.assertTrue((np.abs(diff_pos) < 1e-5).all())
     for s, s_r in zip(cell.get_chemical_symbols(),
                       cell_ref.get_chemical_symbols()):
         self.assertTrue(s == s_r)
示例#37
0
def _poscar_failed(cell_filename):
    """Determine if fall back happens

    1) read_vasp (parsing POSCAR-style file) is failed. --> fallback

    ValueError is raised by read_vasp when the POSCAR-style format
    is broken. By this way, we assume the input crystal structure
    is not in the POSCAR-style format and is in the phonopy.yaml
    type.

    2) The file given by get_default_cell_filename('vasp') is not
       found at the current directory.  --> fallback

    This is the trigger to look for the phonopy.yaml type file.

    3) The given file with cell_filename is not found.  --> not fallback

    This case will not invoke phonopy.yaml mode and here nothing
    is done, i.e., fallback_reason = None.
    This error will be caught in the following part again be
    handled properly (read_crystal_structure).

    """

    fallback_reason = None
    try:
        if cell_filename is None:
            read_vasp(get_default_cell_filename('vasp'))
        else:
            read_vasp(cell_filename)
    except ValueError:
        # (1) see above
        fallback_reason = "read_vasp parsing failed"
    except FileNotFoundError:
        if cell_filename is None:
            # (2) see above
            fallback_reason = "default file not found"
        else:
            # (3) see above
            pass
    return fallback_reason
示例#38
0
    def test_sc(self):
        filename = "../poscars/POSCAR_Sc"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)  # 178

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, '622')

        p = [1.0 / 3.0, 1.0 / 3.0, 0.0]  # K (32)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '32')
示例#39
0
    def test_a13(self):
        filename = "../poscars/POSCAR_A13"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)  # 213

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, '432')

        p = [0.0, 0.5, 0.5]  # X (422)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '422')
示例#40
0
    def test_b3(self):
        filename = "../poscars/POSCAR_B3_conv"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)  # 216

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, '-43m')

        p = [0.0, 0.5, 0.5]  # X (-42m)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '-42m')
示例#41
0
 def test_read_vasp(self):
     cell = read_vasp(os.path.join(data_dir, "../POSCAR_NaCl"))
     filename = os.path.join(data_dir, "NaCl-vasp.yaml")
     cell_ref = get_unitcell_from_phonopy_yaml(filename)
     self.assertTrue(
         (np.abs(cell.get_cell() - cell_ref.get_cell()) < 1e-5).all())
     diff_pos = cell.get_scaled_positions() - cell_ref.get_scaled_positions()
     diff_pos -= np.rint(diff_pos)
     self.assertTrue((np.abs(diff_pos) < 1e-5).all())
     for s, s_r in zip(cell.get_chemical_symbols(),
                       cell_ref.get_chemical_symbols()):
         self.assertTrue(s == s_r)
    def create_list_element_indices(self):
        from phonopy.interface.vasp import read_vasp
        filename = self._variables["poscar"]
        atoms = read_vasp(filename)

        symbols = atoms.get_chemical_symbols()
        reduced_symbols = sorted(set(symbols), key=symbols.index)
        list_element_indices = []
        for s in reduced_symbols:
            indices = [i for i, x in enumerate(symbols) if x == s]
            list_element_indices.append((s, indices))

        self._natoms = atoms.get_number_of_atoms()
        self._list_element_indices = list_element_indices
 def _get_phonon_NaCl(self):
     cell = read_vasp(os.path.join(data_dir, "..", "POSCAR_NaCl"))
     phonon = Phonopy(cell,
                      np.diag([2, 2, 2]),
                      primitive_matrix=[[0, 0.5, 0.5],
                                        [0.5, 0, 0.5],
                                        [0.5, 0.5, 0]])
     filename = os.path.join(data_dir, "..", "FORCE_SETS_NaCl")
     force_sets = parse_FORCE_SETS(filename=filename)
     phonon.set_displacement_dataset(force_sets)
     phonon.produce_force_constants()
     filename_born = os.path.join(data_dir, "..", "BORN_NaCl")
     nac_params = parse_BORN(phonon.get_primitive(), filename=filename_born)
     phonon.set_nac_params(nac_params)
     return phonon
示例#44
0
def read_crystal_structure(filename=None,
                           interface_mode='vasp',
                           chemical_symbols=None):
    if filename is None:
        unitcell_filename = get_default_cell_filename(interface_mode)
    else:
        unitcell_filename = filename

    if not os.path.exists(unitcell_filename):
        if filename is None:
            return None, (unitcell_filename + " (default file name)",)
        else:
            return None, (unitcell_filename,)
    
    if interface_mode == 'vasp':
        from phonopy.interface.vasp import read_vasp
        if chemical_symbols is None:
            unitcell = read_vasp(unitcell_filename)
        else:
            unitcell = read_vasp(unitcell_filename, symbols=chemical_symbols)
        return unitcell, (unitcell_filename,)
        
    if interface_mode == 'abinit':
        from phonopy.interface.abinit import read_abinit
        unitcell = read_abinit(unitcell_filename)
        return unitcell, (unitcell_filename,)
        
    if interface_mode == 'pwscf':
        from phonopy.interface.pwscf import read_pwscf
        unitcell, pp_filenames = read_pwscf(unitcell_filename)
        return unitcell, (unitcell_filename, pp_filenames)
        
    if interface_mode == 'wien2k':
        from phonopy.interface.wien2k import parse_wien2k_struct
        unitcell, npts, r0s, rmts = parse_wien2k_struct(unitcell_filename)
        return unitcell, (unitcell_filename, npts, r0s, rmts)
示例#45
0
 def _get_phonon(self):
     cell = read_vasp(os.path.join(data_dir, "../POSCAR_NaCl"))
     phonon = Phonopy(cell, np.diag([2, 2, 2]), primitive_matrix=[[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]])
     filename = os.path.join(data_dir, "FORCE_SETS_NaCl")
     force_sets = parse_FORCE_SETS(filename=filename)
     phonon.set_displacement_dataset(force_sets)
     phonon.produce_force_constants()
     supercell = phonon.get_supercell()
     born_elems = {
         "Na": [[1.08703, 0, 0], [0, 1.08703, 0], [0, 0, 1.08703]],
         "Cl": [[-1.08672, 0, 0], [0, -1.08672, 0], [0, 0, -1.08672]],
     }
     born = [born_elems[s] for s in ["Na", "Cl"]]
     epsilon = [[2.43533967, 0, 0], [0, 2.43533967, 0], [0, 0, 2.43533967]]
     factors = 14.400
     phonon.set_nac_params({"born": born, "factor": factors, "dielectric": epsilon})
     return phonon
示例#46
0
    def test_fcc_conv(self):
        filename = "../poscars/POSCAR_fcc"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, 'm-3m')

        rotations = symmetry.get_group_of_wave_vector([0.00, 0.25, 0.25])[0]
        self.check_irreps(rotations, 'mm2')

        rotations = symmetry.get_group_of_wave_vector([0.25, 0.00, 0.25])[0]
        self.check_irreps(rotations, 'mm2')

        rotations = symmetry.get_group_of_wave_vector([0.25, 0.25, 0.00])[0]
        self.check_irreps(rotations, 'mm2')
示例#47
0
 def test_properties(self):
     cell = read_vasp(os.path.join(data_dir, "..", "POSCAR_NaCl"))
     phonon = Phonopy(cell,
                      np.diag([2, 2, 2]),
                      primitive_matrix=[[0, 0.5, 0.5],
                                        [0.5, 0, 0.5],
                                        [0.5, 0.5, 0]])
     filename = os.path.join(data_dir, "..", "FORCE_SETS_NaCl")
     force_sets = parse_FORCE_SETS(filename=filename)
     phonon.set_displacement_dataset(force_sets)
     phonon.produce_force_constants()
     dynmat = phonon.dynamical_matrix
     dynmat.set_dynamical_matrix([0, 0, 0])
     self.assertTrue(id(dynmat.primitive)
                     == id(dynmat.get_primitive()))
     self.assertTrue(id(dynmat.supercell)
                     == id(dynmat.get_supercell()))
     np.testing.assert_allclose(dynmat.dynamical_matrix,
                                dynmat.get_dynamical_matrix())
示例#48
0
    def test_mgnh(self):
        filename = "../poscars/POSCAR_MgNH"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)  # 216

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, '6/m')

        p = [1.0 / 3.0, 1.0 / 3.0, 0.0]  # K (-6)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '-6')

        p = [0.0, 0.0, 0.25]  # DT (6)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '6')

        p = [1.0 / 3.0, 1.0 / 3.0, 0.25]  # P (3)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '3')
 def test_reduce_vectors_to_primitive_for_multidimensional_vectors(self):
     vectors_adjuster = self._vectors_adjuster
     atoms = read_vasp("poscars/POSCAR_fcc")
     primitive_matrix = [
         [0.0, 0.5, 0.5],
         [0.5, 0.0, 0.5],
         [0.5, 0.5, 0.0],
     ]
     primitive = get_primitive(atoms, primitive_matrix)
     vectors = self.get_eigvec_0()[None, :, None]
     reduced_vectors = vectors_adjuster.reduce_vectors_to_primitive(
         vectors, primitive)
     nexpansion = 4
     exp = np.array([
         0.5,
         0.0,
         0.0,
     ])[None, :, None]
     exp *= np.sqrt(nexpansion)
     self.assertTrue(np.all(np.abs(reduced_vectors - exp) < 1e-6))
示例#50
0
    def test_fcc_prim(self):
        filename = "../poscars/POSCAR_fcc_prim"

        atoms = read_vasp(filename)
        symmetry = UnfolderSymmetry(atoms)

        rotations = symmetry.get_pointgroup_operations()
        self.check_irreps(rotations, 'm-3m')

        rotations = symmetry.get_group_of_wave_vector([0.00, 0.25, -0.25])[0]
        self.check_irreps(rotations, 'mm2')

        p = [0.50, 0.25, 0.75]  # W (-42m)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '-42m')

        rotations = symmetry.get_group_of_wave_vector([0.50, 0.25, 0.25])[0]
        self.check_irreps(rotations, 'mm2')

        rotations = symmetry.get_group_of_wave_vector([0.25, 0.50, 0.25])[0]
        self.check_irreps(rotations, 'mm2')

        rotations = symmetry.get_group_of_wave_vector([0.25, 0.25, 0.50])[0]
        self.check_irreps(rotations, 'mm2')

        p = [0.5, 0.3, 0.7]  # Q (2)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '2')

        p = [0.4, 0.4, 0.1]  # C (m)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, 'm')

        p = [0.4, 0.2, 0.1]  # GP (1)
        rotations = symmetry.get_group_of_wave_vector(p)[0]
        self.check_irreps(rotations, '1')
 def setUp(self):
     atoms = read_vasp("POSCAR_sc")
     self._symmetry = UnfolderSymmetry(atoms)
示例#52
0
from phonopy import Phonopy
from phonopy.interface.vasp import read_vasp
from phonopy.file_IO import parse_FORCE_SETS
from phonopy.file_IO import parse_FORCE_CONSTANTS, write_FORCE_CONSTANTS

cell = read_vasp("POSCAR")
phonon = Phonopy(cell, [[2, 0, 0], [0, 2, 0], [0, 0, 2]])
force_sets = parse_FORCE_SETS()
phonon.set_displacement_dataset(force_sets)
phonon.produce_force_constants()
write_FORCE_CONSTANTS(phonon.get_force_constants(), filename="FORCE_CONSTANTS")

force_constants = parse_FORCE_CONSTANTS()
phonon.set_force_constants(force_constants)
phonon.symmetrize_force_constants(iteration=1)
write_FORCE_CONSTANTS(phonon.get_force_constants(), filename="FORCE_CONSTANTS_NEW")
示例#53
0
    parser = OptionParser()
    parser.set_defaults( w2v  = False,
                         v2w = False)
    parser.add_option("-w", dest="w2v",
                      action="store_true",
                      help="Convert WIEN2k to VASP")
    parser.add_option("-v", dest="v2w",
                      action="store_true",
                      help="Convert VASP to WIEN2k")
    (options, args) = parser.parse_args()

    from phonopy.units import Bohr

    if options.v2w:
        cell = read_vasp(args[0])
        lattice = cell.get_cell() / Bohr
        cell.set_cell( lattice )
        npts, r0s, rmts = parse_core_param(open(args[1]))
        text = get_wien2k_struct(cell, npts, r0s, rmts)
        print text

    elif options.w2v:
        cell, npts, r0s, rmts = parse_wien2k_struct(args[0])
        positions = cell.get_scaled_positions()
        lattice = cell.get_cell() * Bohr
        cell.set_cell( lattice )
        cell.set_scaled_positions( positions )
        clean_scaled_positions( cell )
        write_vasp("POSCAR.wien2k", cell, direct=True)
        w = open("wien2k_core.dat", 'w')