class PourbaixPlotterTest(unittest.TestCase): def setUp(self): warnings.simplefilter("ignore") self.test_data = loadfn( os.path.join(PymatgenTest.TEST_FILES_DIR, "pourbaix_test_data.json")) self.pd = PourbaixDiagram(self.test_data["Zn"]) self.plotter = PourbaixPlotter(self.pd) def tearDown(self): warnings.simplefilter("default") 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]]) def test_plot_entry_stability(self): entry = self.pd.all_entries[0] self.plotter.plot_entry_stability(entry, limits=[[-2, 14], [-3, 3]]) # binary system pd_binary = PourbaixDiagram(self.test_data["Ag-Te"], comp_dict={ "Ag": 0.5, "Te": 0.5 }) binary_plotter = PourbaixPlotter(pd_binary) plt = binary_plotter.plot_entry_stability(self.test_data["Ag-Te"][53]) plt.close()
def setUp(self): warnings.simplefilter("ignore") self.test_data = loadfn( os.path.join(PymatgenTest.TEST_FILES_DIR, "pourbaix_test_data.json")) self.pd = PourbaixDiagram(self.test_data["Zn"]) self.plotter = PourbaixPlotter(self.pd)
class PourbaixPlotterTest(unittest.TestCase): def setUp(self): warnings.simplefilter("ignore") self.test_data = loadfn(os.path.join(test_dir, "pourbaix_test_data.json")) self.pd = PourbaixDiagram(self.test_data["Zn"]) self.plotter = PourbaixPlotter(self.pd) def tearDown(self): warnings.resetwarnings() 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]]) def test_plot_entry_stability(self): entry = self.pd.all_entries[0] self.plotter.plot_entry_stability(entry, limits=[[-2, 14], [-3, 3]]) # binary system pd_binary = PourbaixDiagram(self.test_data['Ag-Te'], comp_dict = {"Ag": 0.5, "Te": 0.5}) binary_plotter = PourbaixPlotter(pd_binary) test_entry = pd_binary._unprocessed_entries[0] plt = binary_plotter.plot_entry_stability(test_entry) plt.close()
def test_plot_entry_stability(self): entry = self.pd.all_entries[0] self.plotter.plot_entry_stability(entry, limits=[[-2, 14], [-3, 3]]) # binary system pd_binary = PourbaixDiagram(self.test_data["Ag-Te"], comp_dict={"Ag": 0.5, "Te": 0.5}) binary_plotter = PourbaixPlotter(pd_binary) plt = binary_plotter.plot_entry_stability(self.test_data["Ag-Te"][53]) plt.close()
def test_plot_entry_stability(self): entry = self.pd.all_entries[0] self.plotter.plot_entry_stability(entry, limits=[[-2, 14], [-3, 3]]) # binary system pd_binary = PourbaixDiagram(self.test_data['Ag-Te'], comp_dict = {"Ag": 0.5, "Te": 0.5}) binary_plotter = PourbaixPlotter(pd_binary) test_entry = pd_binary._unprocessed_entries[0] plt = binary_plotter.plot_entry_stability(test_entry) plt.close()
def getentrystability(entry, stabilitydata, ehullmax, newcomp, plotterobj=None, compdict=None, all_entries=None): if newcomp == True: if compdict == None or all_entries == None: raise Exception( 'Need to provide all_entries and compdict when using new composition!' ) pbx = PourbaixDiagram(all_entries, comp_dict=compdict) plotterobj = PourbaixPlotter(pbx) elif plotterobj == None: raise Exception( 'Need to provide plotter object if using previous composition!') stability, (pH, V) = plotterobj.get_entry_stability(entry, e_hull_max=ehullmax) stability_metrics = stabilitymetrics(stability, pH, V) return (stability_metrics, plotterobj)
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]])
def setUp(self): warnings.simplefilter("ignore") self.test_data = loadfn(os.path.join(test_dir, "pourbaix_test_data.json")) self.pd = PourbaixDiagram(self.test_data["Zn"]) self.plotter = PourbaixPlotter(self.pd)
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
mpr = MPRester("6ycZ7v9nGu4TsKlA") # Get all pourbaix entries corresponding to the Ti-Ni-O-H chemical system. entries = mpr.get_pourbaix_entries(["Ni", "Ti"]) # Construct the PourbaixDiagram object pbx = PourbaixDiagram(entries, comp_dict={"Ni": 0.5, "Ti": 0.5}, conc_dict={"Ni": 1e-8, "Ti": 1e-8}, filter_solids=False) # Get an entry stability as a function of pH and V #for e in entries: # print(e) entry = [e for e in entries if e.entry_id == 'ion-8'][0] #ion-8 is ti++, mp-10257 is Ni(s) plotter = PourbaixPlotter(pbx) bivo4_entry = [entry for entry in entries if entry.entry_id=="ion-8"][0] plt = plotter.plot_entry_stability(bivo4_entry) #print(pbx.get_decomposition_energy(entry, pH=0, V=-0.85)) plt.title("Ti2+ Stability Range", fontsize=50) plt.subplots_adjust(top=0.95) plt.tight_layout() plt.show(figsize = (20, 15)) #plt = plotter.plot_entry_stability(entry)
from pymatgen import MPRester 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 },