[cig-commits] [commit] add_gibbs_energy: Updated process chemistry to accept fractions (e43ade1)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Thu Dec 11 17:13:00 PST 2014


Repository : https://github.com/geodynamics/burnman

On branch  : add_gibbs_energy
Link       : https://github.com/geodynamics/burnman/compare/0000000000000000000000000000000000000000...2148b324d3e8aa7b527f831eb397590942563008

>---------------------------------------------------------------

commit e43ade1baaeafdf9ef7c780dae19ef4aba801b28
Author: Bob Myhill <myhill.bob at gmail.com>
Date:   Tue Dec 9 10:47:52 2014 -0800

    Updated process chemistry to accept fractions


>---------------------------------------------------------------

e43ade1baaeafdf9ef7c780dae19ef4aba801b28
 burnman/processchemistry.py | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/burnman/processchemistry.py b/burnman/processchemistry.py
index eca5eba..11e8b71 100644
--- a/burnman/processchemistry.py
+++ b/burnman/processchemistry.py
@@ -31,17 +31,16 @@ def dictionarize_formula(formula):
     convert it into a dictionary
     """
     f=dict()
-    for element in re.findall('[A-Z][^A-Z]*', formula):
-        list=filter(None, re.split(r'(\d+)', element))
-        # Look up number of atoms of element
-        if len(list) == 1:
-            nel=1.
+    elements=re.findall('[A-Z][^A-Z]*',formula)
+    for element in elements:
+        element_name=re.split('[0-9][^A-Z]*',element)[0]
+        element_atoms=re.findall('[0-9][^A-Z]*',element)
+        if len(element_atoms) == 0:
+            element_atoms=Fraction(1.0)
         else:
-            nel=float(list[1])
-        if list[0] not in f:
-            f[list[0]]=nel
-        else:
-            f[list[0]]=nel+f[list[0]]
+            element_atoms=Fraction(element_atoms[0])
+        f[element_name]=f.get(element_name, 0.0) + element_atoms
+
     return f
 
 def formula_mass(formula, atomic_masses):



More information about the CIG-COMMITS mailing list