-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample_adapter.py
More file actions
60 lines (51 loc) · 2.25 KB
/
Copy pathexample_adapter.py
File metadata and controls
60 lines (51 loc) · 2.25 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
from __future__ import annotations
from acidwatch_api.models.base import BaseAdapter, BaseParameters, Parameter, RunResult
from acidwatch_api.models.datamodel import Phase
class ExampleParameters(BaseParameters):
spontaneously_combust: int = Parameter(
# Label that will be shown to the user
label="Spontaneously combust",
# Description
description="The rate at which atoms will spontaneously disappear",
# Minimum (optional)
min=0,
# Maximum (optional)
max=100,
# Which unit to show this as
unit="%",
# Default value
default=50,
)
class ExampleAdapter(BaseAdapter):
"""This is an example on how to write model adapters"""
model_id = "example"
# Every model requires a human-readable model name. This text will be
# displayed in the frontend.
display_name = "Example"
# Every model has a set of initial concentrations of substances.
#
# This property must contain a list of valid chemical substances
# (eg. 'HNO2', but not 'ASDF') indicating it's possible for the user to
# supply it.
#
# The frontend has a set of substances that by default is shown to the user,
# any substance other than those will be possible for the user to add from a
# drop down menu. If the adapter does not specify one of the default ones,
# they will not be shown.
#
# The exception is CO2, which must not be specified as it's the solvent.
#
# Note that all concentrations provided to the adapter through
# self.concentrations will be in the unit mol PPM. Likewise, all concentrations
# provided in the results will be treated as mol PPM by the frontend. Make sure
# to adhere to this unit in the adapter interface.
valid_substances = ["H2O"]
parameters: ExampleParameters
async def run(self) -> RunResult:
# At this point the adapter can do whatever they want with the
# concentrations. The first returned object is considered the output
# concentrations and must be of the same type as self.concentrations
# (dict[str, number]), and the unit of number must be in ppm.
return [
Phase(kind="co2-rich", fraction=1.0, concentrations=self.concentrations)
]