Exemplo n.º 1
0
def phonon_unfold():
    atoms = FaceCenteredCubic(size=(1, 1, 1), symbol="Cu", pbc=True)
    symbols = atoms.get_chemical_symbols()
    #symbols[-1] = 'Ag'
    atoms.set_chemical_symbols(symbols)
    calc = EMT()
    atoms.set_calculator(calc)
    phonon = calculate_phonon(atoms,
                              calc,
                              ndim=np.eye(3) * 2,
                              primitive_matrix=np.eye(3) / 1.0)

    kpts, x, X, names = kpath()
    kpts = [
        np.dot(
            k,
            np.linalg.inv((np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]]) / 2.0)))
        for k in kpts
    ]
    phonon.set_qpoints_phonon(kpts, is_eigenvectors=True)
    freqs, eigvecs = phonon.get_qpoints_phonon()

    sc = atoms
    sc_mat = np.linalg.inv((np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]]) / 2.0))
    spos = sc.get_scaled_positions()

    uf = phonon_unfolder(atoms, sc_mat, eigvecs, kpts)
    weights = uf.get_weights()

    ax = None
    ax = plot_band_weight([list(x)] * freqs.shape[1],
                          freqs.T * 33.356,
                          weights[:, :].T * 0.98 + 0.01,
                          xticks=[names, X],
                          axis=ax)

    # print freqs
    # for i in range(freqs.shape[1]):
    #    plt.plot(x, freqs[:, i], color='blue', alpha=0.2, linewidth=2.5)

    plt.xticks(X, names)
    plt.ylabel('Frequency (cm$^{-1}$)')
    plt.ylim([0, 350])
    plt.title('with defect (1/4) (method: reciprocal)')

    get_phonon_prim(ax)
    plt.savefig('defrec4.png')

    plt.show()
Exemplo n.º 2
0
def get_structure():
    DDB = abilab.abiopen('out_DDB')
    struct = DDB.structure
    atoms = DDB.structure.to_ase_atoms()
    scaled_positions = struct.frac_coords

    cell = struct.lattice_vectors()
    numbers = struct.atomic_numbers
    masses = [atomic_masses[i] for i in numbers]

    print numbers
    print cell
    print scaled_positions

    points = kpath()[-1]

    sc_mat = np.linalg.inv((np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]]) / 2.0))

    kpath_bounds = [np.dot(k, sc_mat) for k in points]
    print kpath_bounds

    phbst, phdos = DDB.anaget_phbst_and_phdos_files(
        nqsmall=5,
        asr=1,
        chneut=1,
        dipdip=0,
        verbose=1,
        lo_to_splitting=False,
        qptbounds=kpath_bounds,
    )
    #phbst.plot_phbands()
    qpoints = phbst.qpoints.frac_coords
    print qpoints
    nqpts = len(qpoints)
    nbranch = 3 * len(numbers)
    evals = np.zeros([nqpts, nbranch])
    evecs = np.zeros([nqpts, nbranch, nbranch], dtype='complex128')

    m = np.sqrt(np.kron(masses, [1, 1, 1]))
    #positions=np.kron(scaled_positions,[1,1,1])

    for iqpt, qpt in enumerate(qpoints):
        for ibranch in range(nbranch):
            phmode = phbst.get_phmode(qpt, ibranch)
            evals[iqpt, ibranch] = phmode.freq
            evec = phmode.displ_cart * m
            phase = [
                np.exp(-2j * np.pi * np.dot(pos, qpt))
                for pos in scaled_positions
            ]
            phase = np.kron(phase, [1, 1, 1])
            evec *= phase
            evec /= np.linalg.norm(evec)
            evecs[iqpt, :, ibranch] = evec

    uf = phonon_unfolder(atoms, sc_mat, evecs, qpoints, phase=False)
    weights = uf.get_weights()
    print weights.min(), weights.max()
    x = np.arange(nqpts)
    freqs = evals
    names = ['$\Gamma$', 'X', 'W', '$\Gamma$', 'L']
    #ax=plot_band_weight([list(x)]*freqs.shape[1],freqs.T*33.356,weights[:,:].T*0.98+0.01,xticks=[names,X],axis=ax)
    ax = plot_band_weight([list(x)] * freqs.shape[1],
                          freqs.T * 27 * 33.356,
                          weights[:, :].T * 0.98 + 0.01,
                          xticks=[names, [1, 2, 3, 4, 5]],
                          style='alpha')

    plt.show()
Exemplo n.º 3
0
def nc_unfolder(fname, sc_mat, kx=None, knames=None, ghost_atoms=None):
    ncfile = abilab.abiopen(fname)
    struct = ncfile.structure
    atoms = ncfile.structure.to_ase_atoms()
    scaled_positions = struct.frac_coords

    cell = struct.lattice_vectors()
    numbers = struct.atomic_numbers
    masses = [atomic_masses[i] for i in numbers]

    #print numbers
    #print cell
    #print scaled_positions

    #print kpath_bounds

    phbst = ncfile.phbands
    #phbst.plot_phbands()
    qpoints = phbst.qpoints.frac_coords
    nqpts = len(qpoints)
    nbranch = 3 * len(numbers)
    evals = np.zeros([nqpts, nbranch])
    evecs = np.zeros([nqpts, nbranch, nbranch], dtype='complex128')

    m = np.sqrt(np.kron(masses, [1, 1, 1]))
    #positions=np.kron(scaled_positions,[1,1,1])
    freqs = phbst.phfreqs
    displ_carts = phbst.phdispl_cart

    for iqpt, qpt in enumerate(qpoints):
        print(iqpt, qpt)
        for ibranch in range(nbranch):
            #phmode = ncfile.get_phmode(qpt, ibranch)
            #print(2)
            evals[iqpt, ibranch] = freqs[iqpt, ibranch]
            #evec=phmode.displ_cart *m
            #phase = [np.exp(-2j*np.pi*np.dot(pos,qpt)) for pos in scaled_positions]
            #phase = np.kron(phase,[1,1,1])
            #evec*=phase
            #evec /= np.linalg.norm(evec)
            evec = displacement_cart_to_evec(displ_carts[iqpt, ibranch, :],
                                             masses,
                                             scaled_positions,
                                             qpoint=qpt,
                                             add_phase=True)
            evecs[iqpt, :, ibranch] = evec

    uf = phonon_unfolder(atoms,
                         sc_mat,
                         evecs,
                         qpoints,
                         phase=False,
                         ghost_atoms=ghost_atoms)
    weights = uf.get_weights()
    x = np.arange(nqpts)
    freqs = evals
    #names = ['$\Gamma$', 'X', 'W', '$\Gamma$', 'L']
    #ax=plot_band_weight([list(x)]*freqs.shape[1],freqs.T*33.356,weights[:,:].T*0.98+0.01,xticks=[names,X],axis=ax)
    ax = plot_band_weight([list(x)] * freqs.shape[1],
                          freqs.T * 8065.6,
                          weights[:, :].T * 0.98 + 0.01,
                          xticks=[knames, kx],
                          style='alpha')
    #plt.show()
    return ax
Exemplo n.º 4
0
def DDB_unfolder(DDB_fname,
                 kpath_bounds,
                 sc_mat,
                 knames=None,
                 kx=None,
                 dipdip=1):
    DDB = abilab.abiopen(DDB_fname)
    struct = DDB.structure
    atoms = DDB.structure.to_ase_atoms()
    scaled_positions = struct.frac_coords

    cell = struct.lattice_vectors()
    numbers = struct.atomic_numbers
    masses = [atomic_masses[i] for i in numbers]

    #print numbers
    #print cell
    #print scaled_positions

    #print kpath_bounds

    phbst, phdos = DDB.anaget_phbst_and_phdos_files(
        nqsmall=2,
        asr=1,
        chneut=1,
        dipdip=dipdip,
        verbose=1,
        ndivsm=40,
        lo_to_splitting=True,
        qptbounds=kpath_bounds,
    )
    #phbst.plot_phbands()
    qpoints = phbst.qpoints.frac_coords
    nqpts = len(qpoints)
    nbranch = 3 * len(numbers)
    evals = np.zeros([nqpts, nbranch])
    evecs = np.zeros([nqpts, nbranch, nbranch], dtype='complex128')

    m = np.sqrt(np.kron(masses, [1, 1, 1]))
    #positions=np.kron(scaled_positions,[1,1,1])

    for iqpt, qpt in enumerate(qpoints):
        for ibranch in range(nbranch):
            phmode = phbst.get_phmode(qpt, ibranch)
            evals[iqpt, ibranch] = phmode.freq
            #evec=phmode.displ_cart *m
            #phase = [np.exp(-2j*np.pi*np.dot(pos,qpt)) for pos in scaled_positions]
            #phase = np.kron(phase,[1,1,1])
            #evec*=phase
            #evec /= np.linalg.norm(evec)
            evec = displacement_cart_to_evec(phmode.displ_cart,
                                             masses,
                                             scaled_positions,
                                             qpoint=qpt,
                                             add_phase=True)
            evecs[iqpt, :, ibranch] = evec

    uf = phonon_unfolder(atoms, sc_mat, evecs, qpoints, phase=False)
    weights = uf.get_weights()
    x = np.arange(nqpts)
    freqs = evals
    xpts = []
    for ix, xx in enumerate(x):
        for q in kpath_bounds:
            if np.sum((np.array(qpoints[ix]) - np.array(q))**
                      2) < 0.00001 and ix not in xpts:
                xpts.append(ix)
    if knames is None:
        knames = [str(k) for k in kpath_bounds]

    #names = ['$\Gamma$', 'X', 'W', '$\Gamma$', 'L']
    #ax=plot_band_weight([list(x)]*freqs.shape[1],freqs.T*33.356,weights[:,:].T*0.98+0.01,xticks=[names,X],axis=ax)
    ax = plot_band_weight([list(x)] * freqs.shape[1],
                          freqs.T * 8065.6,
                          weights[:, :].T * 0.98 + 0.01,
                          xticks=[knames, xpts],
                          style='alpha')
    #ax=plot_band_weight([list(x)]*freqs.shape[1],freqs.T*8065.6,weights[:,:].T*0.98+0.000001,xticks=[knames, kx],style='alpha' )

    #plt.show()
    return ax