示例#1
0
 def test_plot_pourbaix(self):
     plotter = PourbaixPlotter(self.pd)
     # Default limits
     plotter.get_pourbaix_plot()
     # Non-standard limits
     plotter.get_pourbaix_plot(limits=[[-5, 4], [-2, 2]])
示例#2
0
文件: pourbaix.py 项目: kimsooil/temp
def pourbaix(comp, target=None, range_ph=[0, 16], range_voltage=[-2, 2]):
    entries = []
    try:
        elements = [str(e) for e in np.unique(comp.split('-')).tolist()]
        if 'O' in elements: elements.remove('O')
        if 'H' in elements: elements.remove('H')
        if len(elements) == 5:
            print(
                '2.5 milions etries will be considered. It will take more than 2 hours.'
            )
        '''
        elif len(elements) > 6: 
            print('Too many etries needed to be considered. Please contact APOLEX admin ([email protected]) to perform this calculation.')
            return time.strftime("%c"), -2, [0,20], [-3,3]
        '''
    except ValueError as e:
        #print('Wrong input for the chemical space. Please put it with format "A-B-C-D"')
        #return time.strftime("%c"), -1, [0,20], [-3,3]
        return time.strftime(str(e)), -1, [0, 20], [-3, 3]
    elements.sort()
    elem = ''
    for i in range(len(elements)):
        elem = elem + "{}".format(elements[i])
        if i + 1 == len(elements): elem = elem + ''
        else: elem = elem + '-'
    print(elem)

    # Need to modify the directory
    printtimestamp('1')
    #fname = "/home/kimsooil/venv3/pourbaix/data/data_cache2/{}".format(elem)
    fname = "data/data_cache2/{}".format(elem)
    if os.path.isfile(fname) == True:
        with open(fname, 'rb') as fr:
            entries = pickle.load(fr)
        print('Found it-1')
    else:
        try:
            mpr = MPRester("8kEI0dFbzgfxX5cT")
            #entries = mpr.get_pourbaix_entries(elements)
            entries = getPourbaixEntryfromMongo(elements)
            #print(entries)
            with open(fname, 'wb') as fw:
                pickle.dump(entries, fw, protocol=pickle.HIGHEST_PROTOCOL)
        except ValueError as e:
            if len(elements) > 4:
                #return time.strftime("%c"), -2,  [0,20], [-3,3]
                return time.strftime(str(e)), -2, [0, 20], [-3, 3]
            else:
                #return time.strftime("%c"), -1,  [0,20], [-3,3]
                return time.strftime(str(e)), -1, [0, 20], [-3, 3]

    # Need to modify the directory
    #pbxname = "/home/kimsooil/venv3/pourbaix/data/data_cache2/{}-pbx".format(elem)
    pbxname = "data/data_cache2/{}-pbx".format(elem)

    printtimestamp('2')

    if os.path.isfile(pbxname) == True:
        with open(pbxname, 'rb') as pbxr:
            pbx = pickle.load(pbxr)
        print('Found it-2')
    else:
        printtimestamp('2.5')
        pbx = PourbaixDiagram(entries, filter_solids=True)
        with open(pbxname, 'wb') as pbxw:
            pickle.dump(pbx, pbxw, protocol=pickle.HIGHEST_PROTOCOL)

    printtimestamp('3')

    plotter = PourbaixPlotter(pbx)
    plt1 = plotter.get_pourbaix_plot(limits=[range_ph, range_voltage])

    printtimestamp('4')

    plt1.ylabel("E (V) vs SHE")
    #plt1.title("Pourbaix diagram of {} system".format(elem+'-O-H'),  fontsize=35, y=1.08)
    #plt1.tight_layout()
    #time_stamp = time.strftime("%c")
    time_stamp = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S.%f")
    plt1.savefig('static/pourbaix1_' + time_stamp + '.png')
    #print(entries)
    if target != None:
        try:
            #entry = [entry for entry in entries if Composition(entry.composition).reduced_formula == Composition(target).reduced_formula][0]#942733-LLZO Li7La3Zr2O12
            entry = [entry for entry in entries if entry.name == target][0]
            print(entry)
            plt2 = plotter.plot_entry_stability(
                entry,
                pH_range=range_ph,
                pH_resolution=100,
                V_range=range_voltage,
                V_resolution=300,
                e_hull_max=1,
                limits=[range_ph, range_voltage])
            ##plt2.tight_layout()
            #plt2.title("Stability of {} in Pourbaix diagram of {} system".format(target, elem),  fontsize=30, y=1.08)
            plt2.ylabel("E (V) vs SHE")
            plt2.savefig('static/pourbaix2_' + time_stamp + '.png')
            images = 2
        except:
            images = 1
    else:
        images = 1
    return time_stamp, images, range_ph, range_voltage
示例#3
0
 def test_plot_pourbaix(self):
     plotter = PourbaixPlotter(self.pd)
     # Default limits
     plotter.get_pourbaix_plot()
     # Non-standard limits
     plotter.get_pourbaix_plot(limits=[[-5, 4], [-2, 2]])
示例#4
0
from pymatgen.analysis.pourbaix_diagram import PourbaixDiagram, PourbaixPlotter
# %matplotlib inline
# Initialize the MP Rester
mpr = MPRester("hvSDrzMafUtXE0JQ")  ##将API 秘钥输入适配器中,并且初始化适配器,需要自己申请。
# Get all pourbaix entries corresponding to the Cu-O-H chemical system.
entries = mpr.get_pourbaix_entries(["Cu"])
# Construct the PourbaixDiagram object
pbx = PourbaixDiagram(entries)
# Get an entry stability as a function of pH and V
entry = [e for e in entries if e.entry_id == 'mp-1692'][0]
print(
    "CuO's potential energy per atom relative to the most",
    "stable decomposition product is {:0.2f} eV/atom".format(
        pbx.get_decomposition_energy(entry, pH=7, V=-0.2)))
plotter = PourbaixPlotter(pbx)
plotter.get_pourbaix_plot().show()
plt = plotter.plot_entry_stability(entry)
plt.show()
# Get all pourbaix entries corresponding to the Fe-O-H chemical system.
entries = mpr.get_pourbaix_entries(["Bi", "V"])
# Construct the PourbaixDiagram object
pbx = PourbaixDiagram(entries,
                      comp_dict={
                          "Bi": 0.5,
                          "V": 0.5
                      },
                      conc_dict={
                          "Bi": 1e-8,
                          "V": 1e-8
                      },
                      filter_solids=True)