17
17
from iapws import IAPWS95
18
18
from maggma .stores import JSONStore , Store
19
19
from monty .dev import deprecated
20
- from monty .json import MSONable
20
+ from monty .json import MontyDecoder , MSONable
21
21
from pint import DimensionalityError , Quantity
22
22
from pymatgen .core import Element
23
23
from pymatgen .core .ion import Ion
@@ -69,13 +69,13 @@ def __init__(
69
69
70
70
Defaults to empty (pure solvent) if omitted
71
71
volume : str, optional
72
- Volume of the solvent, including the ureg . Defaults to '1 L' if omitted.
72
+ Volume of the solvent, including the unit . Defaults to '1 L' if omitted.
73
73
Note that the total solution volume will be computed using partial molar
74
74
volumes of the respective solutes as they are added to the solution.
75
75
temperature : str, optional
76
76
The solution temperature, including the ureg. Defaults to '25 degC' if omitted.
77
77
pressure : Quantity, optional
78
- The ambient pressure of the solution, including the ureg .
78
+ The ambient pressure of the solution, including the unit .
79
79
Defaults to '1 atm' if omitted.
80
80
pH : number, optional
81
81
Negative log of H+ activity. If omitted, the solution will be
@@ -97,12 +97,13 @@ def __init__(
97
97
contains serialized SoluteDocs. `None` (default) will use the built-in pyEQL database.
98
98
99
99
Examples:
100
- >>> s1 = pyEQL.Solution([[ 'Na+', '1 mol/L'],[ 'Cl-', '1 mol/L']] ,temperature='20 degC',volume='500 mL')
100
+ >>> s1 = pyEQL.Solution({ 'Na+': '1 mol/L', 'Cl-': '1 mol/L'} ,temperature='20 degC',volume='500 mL')
101
101
>>> print(s1)
102
102
Components:
103
- ['H2O', 'Cl-', 'H+', 'OH-', 'Na+']
104
- Volume: 0.5 l
105
- Density: 1.0383030844030992 kg/l
103
+ Volume: 0.500 l
104
+ Pressure: 1.000 atm
105
+ Temperature: 293.150 K
106
+ Components: ['H2O(aq)', 'H[+1]', 'OH[-1]', 'Na[+1]', 'Cl[-1]']
106
107
"""
107
108
# create a logger attached to this class
108
109
# self.logger = logging.getLogger(type(self).__name__)
@@ -2350,11 +2351,6 @@ def _get_solute_volume(self):
2350
2351
"""Return the volume of only the solutes."""
2351
2352
return self .engine .get_solute_volume (self )
2352
2353
2353
- # copying and serialization
2354
- def copy (self ) -> Solution :
2355
- """Return a copy of the solution."""
2356
- return Solution .from_dict (self .as_dict ())
2357
-
2358
2354
def as_dict (self ) -> dict :
2359
2355
"""
2360
2356
Convert the Solution into a dict representation that can be serialized to .json or other format.
@@ -2364,7 +2360,7 @@ def as_dict(self) -> dict:
2364
2360
self ._update_volume ()
2365
2361
d = super ().as_dict ()
2366
2362
# replace solutes with the current composition
2367
- d ["solutes" ] = {k : v * ureg . Quantity ( "1 mol") for k , v in self .components .items ()}
2363
+ d ["solutes" ] = {k : f" { v } mol" for k , v in self .components .items ()}
2368
2364
# replace the engine with the associated str
2369
2365
d ["engine" ] = self ._engine
2370
2366
return d
@@ -2379,7 +2375,8 @@ def from_dict(cls, d: dict) -> Solution:
2379
2375
# first we store the volume of the serialized solution
2380
2376
orig_volume = ureg .Quantity (d ["volume" ])
2381
2377
# then instantiate a new one
2382
- new_sol = super ().from_dict (d )
2378
+ decoded = {k : MontyDecoder ().process_decoded (v ) for k , v in d .items () if not k .startswith ("@" )}
2379
+ new_sol = cls (** decoded )
2383
2380
# now determine how different the new solution volume is from the original
2384
2381
scale_factor = (orig_volume / new_sol .volume ).magnitude
2385
2382
# reset the new solution volume to that of the original. In the process of
0 commit comments