-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtocomo.py
More file actions
66 lines (54 loc) · 2.11 KB
/
Copy pathtocomo.py
File metadata and controls
66 lines (54 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from __future__ import annotations
from acidwatch_api.models.base import BaseAdapter, RunResult
from acidwatch_api.models.datamodel import Phase, TableResult
from fastapi import APIRouter
from acidwatch_api.settings import SETTINGS
router = APIRouter()
DESCRIPTION: str = """The Total Consumption Model (ToCoMo) estimates final concentrations of chemicals based on initial input concentrations using a series of chemical reactions.
The model applies the following reactions in a specific order:
3. H₂S + 3 NO₂ → SO₂ + H₂O + 3 NO
2. 2 NO + O₂ → 2 NO₂
1. NO₂ + SO₂ + H₂O → NO + H₂SO₄
4. 3 NO₂ + H₂O → 2 HNO₃ + NO
5. 2 NO₂ + H₂O → HNO₃ + HNO₂
6. 8 H₂S + 4 O₂ → 8 H₂O + S₈
The model operates as follows:
We go through the list in the order given and try to apply the reaction.
If it is not possible with the current reaction, we proceed to the next one.
If a reaction can occur, it will be applied, and then we start from the top again.
This iterative approach allows ToCoMo to simulate the chemical interactions and provide estimates of final concentrations based on the initial conditions.
"""
class TocomoAdapter(BaseAdapter):
model_id = "tocomo"
display_name = "ToCoMo"
description = DESCRIPTION
category = "ChemicalEquilibrium"
valid_substances = [
"O2",
"H2O",
"H2S",
"SO2",
"NO2",
]
authentication = False
base_url = SETTINGS.tocomo_api_base_uri
async def run(self) -> RunResult:
res = await self.client.post(
"/api/run_reaction",
json={key.lower(): value for key, value in self.concentrations.items()},
timeout=60.0,
)
res.raise_for_status()
result = res.json()
return (
[
Phase(
kind="co2-rich",
fraction=1.0,
concentrations={
key.upper(): value for key, value in result["final"].items()
},
)
],
TableResult(data=result["steps"], label="Reaction Steps"),
)