Skip to content

Instantly share code, notes, and snippets.

@rnelsonchem
Last active March 28, 2023 19:10
Show Gist options
  • Save rnelsonchem/709d64446b042127191bc03892d142c0 to your computer and use it in GitHub Desktop.
Save rnelsonchem/709d64446b042127191bc03892d142c0 to your computer and use it in GitHub Desktop.
AcidGas Class Test
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c7eee77c-6b34-49a4-bb74-1de077a2fbff",
"metadata": {},
"outputs": [],
"source": [
"from pHcalc import AcidGas, System, Inert"
]
},
{
"cell_type": "markdown",
"id": "c6533ada-06f8-4cd7-beb2-dad4e390f62e",
"metadata": {},
"source": [
"# AcidGas Object Class\n",
"\n",
"Initial CO2 conc is set using Hs and Pgas. Use the Pgas value from the examples provided in @mhvwerts test file."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f8ea421d-6f5c-49a7-b124-06f2a0d7108d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.3401934316721468e-05"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"co2 = AcidGas(pKa=[6.35, 10.33], charge=0,\n",
" Hs=0.03429, Pgas=10**-3.408)\n",
"co2.conc"
]
},
{
"cell_type": "markdown",
"id": "c7921f14-cc37-476a-a63c-82689b63ad62",
"metadata": {},
"source": [
"# Pure water"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e8a65a71-330e-4036-8f04-910a0a07b106",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7.0"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system = System()\n",
"system.pHsolve()\n",
"system.pH"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "42c9473b-a006-4cbc-8550-0b84f22f2390",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5.611044311523436"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system = System(co2)\n",
"system.pHsolve()\n",
"system.pH"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1a5ae1cf-3689-42aa-b460-c6b2bc6fdb84",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1.34019597e-02, 2.44462709e-03, 4.66935541e-08])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"co2.conc*co2.alpha(system.pH)*1000"
]
},
{
"cell_type": "markdown",
"id": "b61e58fe-6a77-406f-aca5-e1e46c89b7a3",
"metadata": {},
"source": [
"# with NaOH"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "2ed46649-b1ea-4249-aac6-2a7f5a514989",
"metadata": {},
"outputs": [],
"source": [
"na = Inert(charge=1, conc=0.001)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "6fbda62f-b17c-49a9-837b-2e275e3d30b8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11.000000762939456"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system = System(na)\n",
"system.pHsolve()\n",
"system.pH"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "5ea63f39-a4a6-4f30-b90b-aba1c174a8dc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8.215499114990234"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system = System(co2, na)\n",
"system.pHsolve()\n",
"system.pH"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "50489c6f-e20a-4ac3-b034-faad9229f2d8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.01340193, 0.98325599, 0.0075538 ])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"co2.conc*co2.alpha(system.pH)*1000"
]
},
{
"cell_type": "markdown",
"id": "c4fb80de-c901-4c58-8ac5-7407df40b880",
"metadata": {},
"source": [
"# with HCl"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "46cd27e3-2537-4f2a-9428-9b17402bebb8",
"metadata": {},
"outputs": [],
"source": [
"cl = Inert(charge=-1, conc=0.001)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "683b8a7a-e532-4ab8-aa62-404766f9b262",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.999999237060545"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system = System(cl)\n",
"system.pHsolve()\n",
"system.pH"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "bebb23e3-e60c-4935-8a29-ab34d30051be",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.999999237060545"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system = System(co2, cl)\n",
"system.pHsolve()\n",
"system.pH"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "853932bc-92b9-4b43-841a-11c95b55063b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1.34019343e-02, 5.98641365e-06, 2.80005111e-13])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"co2.conc*co2.alpha(system.pH)*1000"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "e90bf8c9-635e-45eb-9ed8-7b73ab24fece",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9549925860214359"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# From https://www.aqion.onl/\n",
"(10**-3.02)*1000"
]
},
{
"cell_type": "markdown",
"id": "b7b07f5b-a4bb-42c4-abad-4e46eb29c018",
"metadata": {},
"source": [
"Something is funny from the aqion website. The pH is listed as 3.02, but the \\[H+\\] is 1.00. However, from the calculation above it looks like it should be 0.95.... The co2 concentrations above are roughly inline with the aqion calculations..."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a67f079f-b944-418e-8b0c-92b24af475b7",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment