@@ -62,20 +62,44 @@ async def run(self) -> RunResult:
6262 return phases , TextResult (data = data ["raw" ], label = "pHPitz Solubility Output" )
6363
6464 def _extract_phases (self , data : dict [str , Any ]) -> list [Phase ]:
65- aqueous = data .get ("aqueous_phase" ) or {}
66-
67- wt_pct_to_ppm = 1e4
68- component_by_field = {
69- "h2so4_wt_pct" : "H2SO4" ,
70- "hno3_wt_pct" : "HNO3" ,
71- "nh3_wt_pct" : "NH3" ,
72- "co2_wt_pct" : "CO2" ,
73- }
74-
75- concentrations : dict [str , float | int ] = {
76- component : aqueous [field ] * wt_pct_to_ppm
77- for field , component in component_by_field .items ()
78- if field in aqueous
79- }
80-
81- return [Phase (kind = "aqueous" , fraction = 0.0 , concentrations = concentrations )]
65+ solubility = data .get ("solubility" ) or {}
66+
67+ total_gas = sum (e .get ("gas_mol" , 0.0 ) for e in solubility .values ())
68+ total_water = sum (e .get ("water_mol" , 0.0 ) for e in solubility .values ())
69+ total_mol = total_gas + total_water
70+
71+ aqueous_fraction = total_water / total_mol if total_mol > 0 else 0.0
72+
73+ co2_rich_concs : dict [str , float | int ] = {}
74+ aqueous_concs : dict [str , float | int ] = {}
75+
76+ for component , entry in solubility .items ():
77+ if component == "CO2" :
78+ continue
79+ if total_gas > 0 :
80+ co2_rich_concs [component ] = (
81+ entry .get ("gas_mol" , 0.0 ) / total_gas
82+ ) * 1e6
83+ if total_water > 0 :
84+ aqueous_concs [component ] = (
85+ entry .get ("water_mol" , 0.0 ) / total_water
86+ ) * 1e6
87+
88+ phases : list [Phase ] = [
89+ Phase (
90+ kind = "co2-rich" ,
91+ fraction = 1.0 - aqueous_fraction ,
92+ concentrations = co2_rich_concs ,
93+ )
94+ ]
95+
96+ if aqueous_fraction > 0 :
97+ phases .append (
98+ Phase (
99+ kind = "aqueous" ,
100+ fraction = aqueous_fraction ,
101+ concentrations = aqueous_concs ,
102+ )
103+ )
104+
105+ return phases
0 commit comments