[cig-commits] [commit] add_thermodynamic_potentials: Basic formula parsing now accepts decimals and fractions (60a43fc)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Tue Nov 11 13:01:10 PST 2014
Repository : https://github.com/geodynamics/burnman
On branch : add_thermodynamic_potentials
Link : https://github.com/geodynamics/burnman/compare/f9a1e215ff875e89f69b5e717b85d9af5d44e93b...83c31a2149ddfb6f77c6a72fb5cf3eef08996a42
>---------------------------------------------------------------
commit 60a43fc48cf8f9633eec8b65910ef0451c3ea963
Author: Bob Myhill <myhill.bob at gmail.com>
Date: Tue Nov 11 22:04:45 2014 +0100
Basic formula parsing now accepts decimals and fractions
>---------------------------------------------------------------
60a43fc48cf8f9633eec8b65910ef0451c3ea963
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