示例#1
0
def create_fle_entry_ion(el_0,el_1):
	"""
	Creates a directory and creates 3 files:
		ion_data_1: contains ion_data for el_0 relevent to Pourbaix Diagrams
		ion_data_2: contains ion_data for el_1 relevent to Pourbaix Diagrams
		mp_entries.txt: entry data from Materials Project
	Args:
		el_0: Elemental symbol (type: string) of first element
		el_1: Elemental symbol (type: string) of second element
	"""

	fle_nme = el_0+'_'+el_1
	os.makedirs(fle_nme)
	os.chdir(fle_nme)

	mpr = MPRester('TA7RCwHn3PGaN2m1')
	if el_0==el_1:
		entries = mpr.get_entries_in_chemsys([el_0, 'O', 'H'])
	else:
		entries = mpr.get_entries_in_chemsys([el_0, el_1, 'O', 'H'])

	ion_dict_1 = mpr._make_request('/pourbaix_diagram/reference_data/'+el_0)
	ion_dict_2 = mpr._make_request('/pourbaix_diagram/reference_data/'+el_1)

	## Writing the Material Project entries to file ##
	tmp = json.dumps(entries, cls=MontyEncoder)
	f = open('mp_entries.txt','w')
	f.write(tmp)
	f.close()

	## Writing ion data to file ##
	f = open('ion_data_1.txt','w')
	json.dump(ion_dict_1, f)
	f.close()

	f = open('ion_data_2.txt','w')
	json.dump(ion_dict_2, f)
	f.close()

	os.chdir('..')
示例#2
0
def entry_data(mtnme_1, mtnme_2, direct_0, mprester_key):
    """
    Obtaining entry and ion data from local source. If the data cannot be
    found, it will do an HTTP request to the Materials Project database.

    Args:
        mtnme_1: Material 1
        mtnme_2: Material 2
        direct_0: Directory of entry database for binary systems
    """
    #| -  entry_data
    from pymatgen.matproj.rest import MPRester # Access species in MP
    import warnings; import json; from monty.json import MontyDecoder
    warnings.filterwarnings('ignore')    # Ignore errors related to HTTP request
    mpr = MPRester(mprester_key)    # REST api adaptor, INPUT

    try:
        direct_0 = direct_0        #INPUT#
        direct = direct_0+mtnme_1+'_'+mtnme_2+'/'
        entries = json.loads(open(direct+'mp_entries.txt','r').read(), cls=MontyDecoder)
        ion_dict_1 = json.loads(open(direct+'ion_data_1.txt','r').read())

        if not mtnme_1==mtnme_2:
            ion_dict_2 = json.loads(open(direct+'ion_data_2.txt','r').read())
    except:
        pass

################################################################################
    ## Obtains all entries in MP corresponding to input element, O and H
    if mtnme_1==mtnme_2:
        try:
            entries = entries
        except:
            print 'pd_make.entry_data - made http request line 64'
            entries = mpr.get_entries_in_chemsys([mtnme_1, 'O', 'H'])

        ## Dictionary of reference state:experimental formation energy
        try:
            ion_dict_1 = ion_dict_1
        except:
            print 'pd_make.entry_data - made http request line 69'
            ion_dict_1 = mpr._make_request('/pourbaix_diagram/reference_data/'+mtnme_1)
        out_dict = {"entries" : entries, "ion_dict_1" : ion_dict_1}
        return out_dict

    if not mtnme_1==mtnme_2:
        try:
            entries = entries
        except:
            print 'pd_make.entry_data - made http request - line 146'
            ## Obtains all entries in MP corresponding to input element, O and H
            entries = mpr.get_entries_in_chemsys([mtnme_1, mtnme_2, 'O', 'H'])
            ## Dictionary of reference state:experimental formation energy
        try:
            ion_dict_1 == ion_dict_1
            ion_dict_2 == ion_dict_2
        except:
            print 'pd_make.entry_data - made http request - line 154'
            ion_dict_1 = mpr._make_request('/pourbaix_diagram/reference_data/'+mtnme_1)
            ion_dict_2 = mpr._make_request('/pourbaix_diagram/reference_data/'+mtnme_2)
        out_dict = {"entries" : entries, "ion_dict_1" : ion_dict_1, "ion_dict_2" : ion_dict_2}
        return out_dict