-
Notifications
You must be signed in to change notification settings - Fork 23
Add the to_phreeqc() method
#288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2699,3 +2699,33 @@ def add_solvent(self, formula: str, amount: str): # pragma: no cover | |
| mw = self.get_property(formula, "molecular_weight") | ||
| target_mol = quantity.to("moles", "chem", mw=mw, volume=self.volume, solvent_mass=self.solvent_mass) | ||
| self.components[formula] = target_mol.to("moles").magnitude | ||
|
|
||
| def to_phreeqc(self, units: str = "mol/L", charge_balance: bool = "False") -> str: | ||
| """Generate a PHREEQC input string representing the Solution. | ||
|
|
||
| Returns: | ||
| A string that can be used as part of a PHREEQC input file to define | ||
| the solution. | ||
| """ | ||
| lines = ["SOLUTION 0"] | ||
| lines.append(f" temp {self.temperature.to('degC').magnitude:.2f}") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if charge_balance == "True": | ||
| lines.append(f" pH {self.pH:.2f} charge") | ||
| else: | ||
| lines.append(f" pH {self.pH:.2f}") | ||
| lines.append(f" pe {self.pE:.2f}") | ||
| lines.append(f" units {units}") | ||
| for solute, amount in self.components.items(): | ||
| amount = self.get_amount(solute, units).magnitude | ||
| if solute in ["H2O(aq)", "H[+1]", "OH[-1]"]: | ||
| continue | ||
| k = standardize_formula(solute) | ||
| spl = k.split("[") | ||
| el = spl[0] | ||
| chg = spl[1].split("]")[0] | ||
| if chg[-1] == "1": | ||
| chg = chg[0] | ||
| k = el + chg | ||
|
Comment on lines
+2718
to
+2728
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, I think you will need to specify the total element concentrations via Also, any formula that is coming out of |
||
| lines.append(f" {k} {amount:.6e}") | ||
| lines.append("END") | ||
| return "\n".join(lines) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
charge_balanceshould not be a kwarg here, but rather be read from theSolution.balance_chargeattribute which is set on__init__. See here for the documentation.This will require some careful handling depending on the different cases - the pH case is easy and will work very much like you've coded below.
If 'balance_charge' is another species, you'll have to determine the associated element (e.g.,
Na+->Na) and then append thechargeto that line (I think).