help='number of trees in annoy index')
opt = parser.parse_args()
print(opt)

# Annoy index stores the electronic band structure with each vector corresponding to a sliding window.
annoyindex = AnnoyIndex(int(2 * opt.dimensions), metric='angular')

# A lookuptable is necessary to link annoy vectors to their correct material and k-space position.
lookuptable = []

for mpid in ["mp-2090"]:

    mpr = MPRester('4JzM8sNnMkyVJceK')

    bs = mpr.get_bandstructure_by_material_id(mpid)
    dos = mpr.get_dos_by_material_id(mpid)

    kpoints = pymatgen.Kpoints(bs)
    doscar = pymatgen.Doscar(dos)
    if doscar.converged == False:
        continue  # skip calculations that did not converge
    fermi_energy = doscar.fermi_energy

    eigenval = pymatgen.Eigenval(bs, fermi_energy)

    bands = eigenval.spin_up

    # lower_fermi_band_index indicates the band just below Fermi level
    lower_fermi_band_index = np.argmax(np.nanmax(bands, axis=1) > 0) - 1

    # Find continuous segments in KPOINTS
示例#2
0
def plot_band_structure(mpid, band_index, width, k_highlight, pattern):
    """
    - Plots two bands (which one is indicated by band_index)
    - Highlights a window of width `width` at k `k_highlight`
    """
    mpr = MPRester('4JzM8sNnMkyVJceK')
    bs = mpr.get_bandstructure_by_material_id(mpid)
    dos = mpr.get_dos_by_material_id(mpid)

    kpoints = pymatgen.Kpoints(bs)
    doscar = pymatgen.Doscar(dos)
    fermi_energy = doscar.fermi_energy
    eigenval = pymatgen.Eigenval(bs, fermi_energy)

    bands = eigenval.spin_up
    lower_fermi_band_index = np.argmax(np.nanmax(bands, axis=1) > 0) - 1
    """
    segment_sizes = kpoints.segment_sizes
    segmented_lower_band = np.split(bands[lower_fermi_band_index+band_index], np.cumsum(segment_sizes))[:-1]
    segmented_upper_band = np.split(bands[lower_fermi_band_index+band_index+1], np.cumsum(segment_sizes))[:-1]
    segmented_kpoints = np.split(eigenval.k_points, np.cumsum(segment_sizes))[:-1]

    last_k = 0
    """

    k = eigenval.k_points
    band_l = bands[lower_fermi_band_index + band_index]
    band_u = bands[lower_fermi_band_index + band_index + 1]
    #for k, band_l, band_u in zip(segmented_kpoints, segmented_lower_band, segmented_upper_band):
    #k_1D = np.array(path_1D(k)) + last_k
    k_1D = np.array(path_1D(k))
    plt.plot(k_1D, band_l, 'k')
    plt.plot(k_1D, band_u, 'k')
    #last_k = np.max(k_1D)
    plt.axvspan(float(k_highlight),
                float(k_highlight) + width,
                color='red',
                alpha=0.5)
    # Collect axis ticks (high symmetry points) from KPOINTS.gz
    last_k = 0
    label_k = []
    label_names = []

    #NOTE: Labels for none are question marks
    for left_k, right_k in pymatgen.chunks(kpoints.k_points, 2):
        if len(label_names) == 0:
            label_k.append(last_k)
            #label_names.append(left_k[0])
        #elif label_names[-1] != left_k[0]:
        #label_names[-1] += (';' + left_k[0])
        last_k += np.linalg.norm(right_k[1] - left_k[1])
        label_k.append(last_k)
        #label_names.append(right_k[0])

    #plt.xticks(label_k, label_names)
    #plt.xticks(label_k)

    plt.ylabel('Energy')
    plt.xlabel('k')
    plt.grid(True)
    plt.title('material ' + mpid)
    plt.savefig('misc/' + pattern + '_search_result.png')
    plt.show()
示例#3
0
from pymatgen import MPRester
from pymatgen.electronic_structure.plotter import DosPlotter
mpr = MPRester('DhmFQPuibZo8JtXn')
dsp = DosPlotter()
cdos = mpr.get_dos_by_material_id('mp-352')
dsp.add_dos_dict(cdos.get_element_dos())
dsp.show()