예제 #1
0
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()
예제 #2
0
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()
예제 #3
0
    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()
예제 #4
0
    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()
예제 #5
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
예제 #6
0
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)

예제 #7
0
with open('results/pbx_analysis.log', 'w') as f:

    for idx in range(num_ini, num_fin):

        formula = df_entries['formula'][idx]
        mpid = df_entries['mp_id'][idx]

        print('%03d_%s' % (idx + 1.0, formula))
        f.writelines('%03d_%s\n' % (idx + 1.0, formula))

        try:
            struc = mpr.get_structure_by_material_id(mpid)
            elements = [str(atom) for atom in struc.species[:2]]

            entries = mpr.get_pourbaix_entries(elements)
            entry_ids = [e for e in entries if e.entry_id == mpid]
            if len(entry_ids) == 1:
                pbx = PourbaixDiagram(entries)
                plotter = PourbaixPlotter(pbx)
                entry = entry_ids[0]
                plt = plotter.plot_entry_stability(entry)
                plt.savefig('results/plots/pourbaix/%03d_%s.png' %
                            (idx + 1.0, formula),
                            dpi=300)
            elif len(entry_ids) > 1:
                f.writelines('%03d_%s: number of entry > 1 \n' %
                             (idx + 1.0, formula))
        except:
            f.writelines('%03d_%s - Error: loading pourbaix entry from MP!\n' %
                         (idx + 1.0, formula))