-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patharcs.py
More file actions
97 lines (87 loc) · 2.72 KB
/
Copy patharcs.py
File metadata and controls
97 lines (87 loc) · 2.72 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from acidwatch_api.models.datamodel import ReactionPathsResult
from acidwatch_api.models.base import (
BaseAdapter,
RunResult,
)
from acidwatch_api.models.datamodel import Phase
from acidwatch_api.settings import SETTINGS
DESCRIPTION: str = """Automated Reactions for CO2 Storage (ARCS) model.
ARCS combines first-principles calculations with Monte-Carlo sampling and models possible reactions that may occur under a given set of conditions.
This process identifies the most frequently occurring reactions and paths, final products, and expected concentrations.
Source code found at https://github.com/equinor/arcs/tree/21ded96960d28d549c0950fbc1aa09c94159f652
"""
class ArcsAdapter(BaseAdapter):
model_id = "arcs"
display_name = "ARCS"
description = DESCRIPTION
category = "ChemicalEquilibrium"
valid_substances = [
"CH2O2",
"CH3CH2OH",
"CO",
"H2",
"O2",
"CH3COOH",
"CH3OH",
"CH4",
"CH3CHO",
"H2CO",
"H2O",
"H2SO4",
"H2S",
"S8",
"SO2",
"H2SO3",
"HNO3",
"NO2",
"NH3",
"HNO2",
"NO",
"N2",
"NOHSO4",
]
base_url = SETTINGS.arcs_api_base_uri
async def run(self) -> RunResult:
response = await self.client.post(
f"{SETTINGS.arcs_api_base_uri}/run_simulation",
json={
"concs": {
key: value / 1e6 for key, value in self.concentrations.items()
},
"temperature": self.conditions.temperature + 273,
"pressure": self.conditions.pressure,
"samples": 2000, # Default to 2000 samples
},
timeout=300.0,
)
result = response.json()
paths = result["analysis"]["common_paths"]
stats = result["analysis"]["stats"]
common_paths = [
{
"Path": v.replace("<sub>", "").replace("</sub>", ""),
"k": paths["k"][k],
"Frequency": paths["frequency"][k],
}
for k, v in paths["paths"].items()
]
all_stats = [
{
"Path": v,
"k": stats["k"][k],
"Frequency": stats["frequency"][k],
}
for k, v in stats["index"].items()
]
return [
Phase(
kind="co2-rich",
fraction=1.0,
concentrations={
k: v * 1e6 for k, v in result["results"]["final_concs"].items()
},
)
], ReactionPathsResult(
common_paths=common_paths,
stats=all_stats,
)