Skip to content

Commit

Permalink
Adding pourbaix dir again - RF
Browse files Browse the repository at this point in the history
  • Loading branch information
raulf2012 committed Mar 18, 2018
1 parent 1b5cd09 commit d2060b0
Show file tree
Hide file tree
Showing 20 changed files with 2,299 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pourbaix_pymatgen/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Raul Flores

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions pourbaix_pymatgen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pourbaix_pymatgen
Pourbaix construction and analysis using Materials Project database
122 changes: 122 additions & 0 deletions pourbaix_pymatgen/data_exp_form_e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
"""TEMP TEMP - 180317"""

def formation_e_data_dict():
"""
Dictionary of formation energies for transition metal species.
All energies are in [eV]
"""
#start_fold - formation_e_data_dict
import ast
direct_0 = '/home/flores12/01_ORR-MatStabScreen/01_virenv-pymatgen/01_data/03_formation_e/'
List = open(direct_0+'data.py').read().splitlines()
# Returns python list of entries_lst from read data file
entries_lst = []
line_cnt = 1
for i in List:
# print str(line_cnt)+' :'+str(i)
if not i=="":
if i[0]=='#':
line_cnt=line_cnt+1
continue
else:
try:
entries_lst.append(ast.literal_eval(i))
except:
print 'data_exp_form_e.formation_e_data_dict - error with line: '+str(line_cnt)
line_cnt=line_cnt+1
## Turns entry lists into dictionaries
cf_k = "chem_formula" # Chemical formula list key
fe_k = "form_e" # Formation energy key
r_k = "reference" # Literature reference key
c_k = "comments" # Comments key

entries = []
for i in entries_lst:
entry_dict = {}
entry_dict[cf_k] = i[0]
entry_dict[fe_k] = i[1]
entry_dict[r_k] = i[2]
entry_dict[c_k] = i[3]
entries.append(entry_dict)

chem_form_lst = []
for entry in entries:
# chem_form = entry[0]
chem_form_lst.append(frozenset(entry[cf_k]))
unique_entries_lst = list(list(i) for i in list(set(chem_form_lst)))

dict = {}
for i in unique_entries_lst:
dict[frozenset(i)]=[]
for j in entries:
if set(j[cf_k])==set(i):
dict[frozenset(i)].append(j)
return dict

#end_fold

def get_entry(chemical_formula_list, data_dict):
"""
Args:
chemical_formula_list:
data_dict:
"""
#start_fold - get_entry
# print chemical_formula_list
key = frozenset(chemical_formula_list)

try:
entry = data_dict[key]
except KeyError:
entry = None
# print 'data_exp_form_e.get_entry - no experimental data available'

return entry

#end_fold

# form_e_data = formation_e_data_dict()
# temp = get_entry(['Pt1','O2'],form_e_data)

def oxygen_stoich(exp_entry):
"""
Args:
exp_entry
"""
#start_fold - oxygen_stoich
formula = exp_entry['chem_formula']
for i in formula:
if i[0]=='O' and i[1].isdigit()==True:
num_of_digits = len(i)-1
if num_of_digits==1:
oxy_num = int(i[1])
elif num_of_digits>1:
oxy_num = int(i[1:])
break
return oxy_num

#end_fold


#start_fold - Possible code to take "Pt2O3 and extract out the elements and stoicheometric numbers"
# import re
#
# chem_form_lst = []
# for entry in entries_lst:
#
# chem_form = entry[0]
# form_e = entry[1]
# ref = entry[2]
# comments = entry[3]
#
# chem_form_lst.append(set(chem_form))
#
# ## Separating the element name from the stoicheometric factor
# for element in chem_form:
# elem_stoich = re.match(r"([a-z]+)([0-9]+)", element, re.I).groups()
# elem = elem_stoich[0]
# stoich = elem_stoich[1]
#end_fold
Expand Down
125 changes: 125 additions & 0 deletions pourbaix_pymatgen/element_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
from pymatgen.core.periodic_table import Element # Call elements by atomic #
class ElementList(object):
"""
Class for creating element lists and ranges
By default the first list created is in order of atomic number
Args:
N/A
"""
#start_fold - ElementList
def __init__(self, atom_num_lst=[[]]):
self.atom_num_lst = atom_num_lst
if not atom_num_lst==[[]]:
self.list = self.mk_lst_atnum()
self.trans_met = self.mk_lst_trans_met()

def mk_lst_atnum(self):
"""
Makes list of elements from the atom_num_lst input
"""
elem_rnge=[]
for i in self.atom_num_lst:
el_strt=i[0]
el_end=i[1]
rnge_sect=range(el_strt,el_end+1)
elem_rnge.extend(rnge_sect)
elements=[]
for i in elem_rnge:
element=Element.from_Z(i) # Indice -> pymatgen element object
elements.append(element)
return elements
print elements

def mk_lst_trans_met(self):
"""
Produces list of transition metals in order of atomic number
"""
elem_rnge_I = [[21,30],[39,44],[46,48],[74,76],[78,80]]
elem_rnge=[]
for i in elem_rnge_I:
el_strt=i[0]
el_end=i[1]
rnge_sect=range(el_strt,el_end+1)
elem_rnge.extend(rnge_sect)
elements=[]
for i in elem_rnge:
element=Element.from_Z(i) # Indice -> pymatgen element object
elements.append(element)
return elements

#end_fold

class ElemList_mod(object):
"""
"""
#start_fold - ElemList_mod
def __init__(self,elem_lst):
self.elem_lst = elem_lst
@property
def sort(self,srt_type='group_num'):
"""
Sorts element entries
Args:
srt_type
DEFAULT: group_num, sorts by group number with lowest group number first, and
lowest period first
"""
if srt_type == 'group_num':
elem_lst = self.elem_lst
elem_lst_sorted = elem_lst[:] # Maintains the original unaffected
elem_lst_sorted.sort(key=lambda x: x.group)
return elem_lst_sorted

#start_fold - d-band filling
if srt_type == 'd-band': #COMBAK
tmp = 7




#end_fold

def remove(self,element):
"""
Removes element from element list
Args:
List of element objects
If only 1 element just 1 element number or chemical symbol
name "or" atomic number of the element to be removed
"""
elem_lst_0 = self.elem_lst
if type(element)==type([]):
for elem in element:
if type(elem)==type('string'):
# Find the occurance of input 'elem' in the list and returns it
elem_0 = next((x for x in elem_lst_0 if x.name == elem), None)
elem_lst_0 = [x for x in elem_lst_0 if not x.name == elem]
elif type(elem)==type(2):
elem_0 = next((x for x in elem_lst_0 if x.number == elem), None)
elem_lst_0 = [x for x in elem_lst_0 if not x.number == elem]
return elem_lst_0
if type(element)==type('string'):
# Find the occurance of input 'elem' in the list and returns it
elem_0 = next((x for x in self.elem_lst if x.name == element), None)
elem_lst_new = [x for x in self.elem_lst if not x.name == element]
return elem_lst_new

elif type(element)==type(2):
elem_0 = next((x for x in self.elem_lst if x.number == element), None)
elem_lst_new = [x for x in self.elem_lst if not x.number == element]
return elem_lst_new
#end_fold

def elem_str_mke(elem_lst):
"""
Args:
elem_lst:
"""
#start_fold - elem_str_mke
elem_str=[]
for i in elem_lst:
elem_str.append(i.symbol)
return elem_str

#end_fold
Expand Down
Loading

0 comments on commit d2060b0

Please sign in to comment.