@@ -429,6 +429,25 @@ def dielectric_constant(self) -> Quantity:
429
429
430
430
return ureg .Quantity (di_water / denominator , "dimensionless" )
431
431
432
+ @property
433
+ def chemical_system (self ) -> str :
434
+ """
435
+ Return the chemical system of the Solution as a "-" separated list of elements, sorted alphabetically. For
436
+ example, a solution containing CaCO3 would have a chemical system of "C-Ca-H-O".
437
+ """
438
+ return "-" .join (self .elements )
439
+
440
+ @property
441
+ def elements (self ) -> list :
442
+ """
443
+ Return a list of elements that are present in the solution. For example,
444
+ a solution containing CaCO3 would return ["C", "Ca", "H", "O"]
445
+ """
446
+ els = []
447
+ for s in self .components :
448
+ els .extend (self .get_property (s , "elements" ))
449
+ return sorted (set (els ))
450
+
432
451
# TODO - need tests for viscosity
433
452
@property
434
453
def viscosity_dynamic (self ) -> Quantity :
@@ -1020,6 +1039,31 @@ def get_amount(self, solute: str, units: str = "mol/L") -> Quantity:
1020
1039
1021
1040
raise ValueError (f"Unsupported unit { units } specified for get_amount" )
1022
1041
1042
+ def get_el_amt_dict (self ):
1043
+ """
1044
+ Return a dict of Element: amount in mol
1045
+
1046
+ Elements (keys) are suffixed with their oxidation state in parentheses,
1047
+ e.g. "Fe(2)", "Cl(-1)".
1048
+ """
1049
+ d = {}
1050
+ for s , mol in self .components .items ():
1051
+ elements = self .get_property (s , "elements" )
1052
+ pmg_ion_dict = self .get_property (s , "pmg_ion" )
1053
+ oxi_states = self .get_property (s , "oxi_state_guesses" )[0 ]
1054
+
1055
+ for el in elements :
1056
+ # stoichiometric coefficient, mol element per mol solute
1057
+ stoich = pmg_ion_dict .get (el )
1058
+ oxi_state = oxi_states .get (el )
1059
+ key = f"{ el } ({ oxi_state } )"
1060
+ if d .get (key ):
1061
+ d [key ] += stoich * mol
1062
+ else :
1063
+ d [key ] = stoich * mol
1064
+
1065
+ return d
1066
+
1023
1067
def get_total_amount (self , element : str , units ) -> Quantity :
1024
1068
"""
1025
1069
Return the total amount of 'element' (across all solutes) in the solution.
@@ -1825,8 +1869,15 @@ def _get_property(self, solute: str, name: str) -> Any | None:
1825
1869
return doc ["model_parameters" ]["molar_volume_pitzer" ]
1826
1870
return None
1827
1871
1872
+ if name == "molecular_weight" :
1873
+ return ureg .Quantity (doc .get (name ))
1874
+
1828
1875
# for parameters not named above, just return the base value
1829
- val = doc .get (name ) if not isinstance (doc .get (name ), dict ) else doc [name ].get ("value" )
1876
+ if name == "pmg_ion" or not isinstance (doc .get (name ), dict ):
1877
+ # if the queried value is not a dict, it is a root level key and should be returned as is
1878
+ return doc .get (name )
1879
+
1880
+ val = doc [name ].get ("value" )
1830
1881
# logger.warning("%s has not been corrected for solution conditions" % name)
1831
1882
if val is not None :
1832
1883
return ureg .Quantity (val )
0 commit comments