atomict 0.1.2__py3-none-any.whl → 0.2.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- atomict/__init__.py +1 -1
- atomict/__version__.py +1 -0
- atomict/api.py +182 -0
- atomict/auth.py +47 -0
- atomict/cli/commands/adsorbate.py +183 -0
- atomict/cli/commands/ai_assist.py +111 -0
- atomict/cli/commands/catalysis.py +171 -0
- atomict/cli/commands/common.py +57 -0
- atomict/cli/commands/exploration/__init__.py +7 -0
- atomict/cli/commands/exploration/soec.py +564 -0
- atomict/cli/commands/exploration/sqs.py +440 -0
- atomict/cli/commands/helpers.py +74 -0
- atomict/cli/commands/k8s.py +211 -0
- atomict/cli/commands/login.py +34 -0
- atomict/cli/commands/organization.py +76 -0
- atomict/cli/commands/project.py +876 -0
- atomict/cli/commands/simulation/__init__.py +20 -0
- atomict/cli/commands/simulation/catalysis.py +223 -0
- atomict/cli/commands/simulation/fhiaims.py +279 -0
- atomict/cli/commands/simulation/kpoint.py +380 -0
- atomict/cli/commands/simulation/vibes.py +161 -0
- atomict/cli/commands/simulation.py +176 -0
- atomict/cli/commands/task.py +181 -0
- atomict/cli/commands/upload.py +89 -0
- atomict/cli/commands/user.py +201 -0
- atomict/cli/core/client.py +202 -0
- atomict/cli/core/config.py +43 -0
- atomict/cli/core/utils.py +32 -0
- atomict/cli/main.py +130 -0
- atomict/env.py +79 -0
- atomict/exceptions.py +12 -0
- atomict/infra/distwork/environment.py +26 -0
- atomict/infra/distwork/task.py +49 -0
- atomict/infra/logging.py +22 -0
- atomict/io/cif.py +138 -0
- atomict/io/fhiaims.py +30 -0
- atomict/io/json.py +28 -0
- atomict/io/utils.py +11 -0
- atomict/ml/__init__.py +0 -0
- atomict/ml/model.py +13 -0
- atomict/project/__init__.py +1 -0
- atomict/project/link.py +26 -0
- atomict/project/note.py +18 -0
- atomict/project/project.py +32 -0
- atomict/project/tags.py +48 -0
- atomict/project/workbench.py +6 -0
- atomict/reality/__init__.py +0 -0
- atomict/reality/oqmd.py +5 -0
- atomict/reality/slabs.py +5 -0
- atomict/simulation/__init__.py +0 -0
- atomict/simulation/cantera.py +35 -0
- atomict/simulation/catalysis.py +20 -0
- atomict/simulation/counterfactual.py +28 -0
- atomict/simulation/ea.py +64 -0
- atomict/simulation/fhi_aims.py +72 -0
- atomict/simulation/kpoint.py +74 -0
- atomict/simulation/mattergen.py +20 -0
- atomict/simulation/mlrelax.py +83 -0
- atomict/simulation/phonon.py +12 -0
- atomict/simulation/qe.py +74 -0
- atomict/simulation/sqs.py +24 -0
- atomict/simulation/utils.py +90 -0
- atomict/user/__init__.py +0 -0
- atomict/user/files.py +31 -0
- atomict/user/workspace.py +112 -0
- atomict/utils/fhiaims/__init__.py +0 -0
- atomict/utils/fhiaims/geometry.py +73 -0
- atomict/utils/tenacity.py +36 -0
- {atomict-0.1.2.dist-info → atomict-0.2.4.dist-info}/LICENSE +0 -0
- atomict-0.2.4.dist-info/METADATA +109 -0
- atomict-0.2.4.dist-info/RECORD +78 -0
- {atomict-0.1.2.dist-info → atomict-0.2.4.dist-info}/WHEEL +1 -1
- atomict-0.2.4.dist-info/entry_points.txt +2 -0
- {atomict-0.1.2.dist-info → atomict-0.2.4.dist-info}/top_level.txt +0 -1
- atomict/__main__.py +0 -3
- atomict/cli.py +0 -59
- atomict/datasets/__init__.py +0 -25
- atomict/datasets/io.py +0 -47
- atomict/datasets/public.py +0 -32
- atomict/utils/requests.py +0 -19
- atomict/version.py +0 -2
- atomict-0.1.2.dist-info/METADATA +0 -97
- atomict-0.1.2.dist-info/RECORD +0 -19
- atomict-0.1.2.dist-info/entry_points.txt +0 -2
- tests/test_sdk.py +0 -16
- /atomict/{auth → cli}/__init__.py +0 -0
- /atomict/{utils → infra}/__init__.py +0 -0
- {tests → atomict/infra/distwork}/__init__.py +0 -0
- /tests/test_cli.py → /atomict/io/__init__.py +0 -0
atomict/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
from .
|
|
1
|
+
from .__version__ import __version__
|
atomict/__version__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.4"
|
atomict/api.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
from requests.exceptions import (
|
|
7
|
+
HTTPError,
|
|
8
|
+
ConnectionError,
|
|
9
|
+
Timeout,
|
|
10
|
+
)
|
|
11
|
+
from tenacity import retry, stop_after_attempt, wait_exponential, after_log, retry_if_exception_type, retry_if_exception, before_sleep_log
|
|
12
|
+
|
|
13
|
+
from atomict.exceptions import APIValidationError, PermissionDenied
|
|
14
|
+
from atomict.utils.tenacity import before_log
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def is_http_5xx_error(exception):
|
|
21
|
+
"""These are the HTTP errors that we should attempt to retry on."""
|
|
22
|
+
return isinstance(exception, HTTPError) and 500 <= exception.response.status_code < 600
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@retry(
|
|
26
|
+
stop=stop_after_attempt(5),
|
|
27
|
+
wait=wait_exponential(multiplier=2, min=1, max=30),
|
|
28
|
+
retry=(retry_if_exception_type((ConnectionError, Timeout)) | retry_if_exception(is_http_5xx_error)),
|
|
29
|
+
before=before_log(logger, logging.INFO),
|
|
30
|
+
after=after_log(logger, logging.INFO),
|
|
31
|
+
before_sleep=before_sleep_log(logger, logging.WARNING),
|
|
32
|
+
)
|
|
33
|
+
def get(path: str):
|
|
34
|
+
api_root = os.environ.get("AT_SERVER", "https://api.atomictessellator.com")
|
|
35
|
+
headers = {"Accept": "application/json", "Content-Type": "application/json"}
|
|
36
|
+
|
|
37
|
+
if os.environ.get("AT_TOKEN"):
|
|
38
|
+
headers["Authorization"] = f"Token {os.environ.get('AT_TOKEN')}"
|
|
39
|
+
|
|
40
|
+
response = requests.get(f"{api_root}/{path}", headers=headers)
|
|
41
|
+
|
|
42
|
+
content_type = response.headers.get("Content-Type")
|
|
43
|
+
|
|
44
|
+
if response.status_code == requests.codes.ok and content_type == "application/json":
|
|
45
|
+
resp = response.json()
|
|
46
|
+
|
|
47
|
+
# This is truely hideous, an error can take many forms, not just permission denied
|
|
48
|
+
# This really needs to be cleaned up
|
|
49
|
+
# This hack about the paths is because the task object is special case where it has a legitimate
|
|
50
|
+
# field called "error" -
|
|
51
|
+
# We need to standardize a response type from the server, likely the django rest framework response
|
|
52
|
+
if "error" in resp and resp["error"] is not None and "api/tasks/" not in path:
|
|
53
|
+
raise PermissionDenied(resp["error"])
|
|
54
|
+
else:
|
|
55
|
+
return resp
|
|
56
|
+
elif (
|
|
57
|
+
response.status_code == requests.codes.ok and content_type != "application/json"
|
|
58
|
+
):
|
|
59
|
+
return response.content
|
|
60
|
+
elif response.status_code == requests.codes.bad_request:
|
|
61
|
+
raise APIValidationError(response.json())
|
|
62
|
+
elif response.status_code == requests.codes.forbidden:
|
|
63
|
+
raise PermissionDenied(response.json())
|
|
64
|
+
else:
|
|
65
|
+
response.raise_for_status()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@retry(
|
|
69
|
+
stop=stop_after_attempt(5),
|
|
70
|
+
wait=wait_exponential(multiplier=2, min=1, max=30),
|
|
71
|
+
retry=(retry_if_exception_type((ConnectionError, Timeout)) | retry_if_exception(is_http_5xx_error)),
|
|
72
|
+
before=before_log(logger, logging.INFO),
|
|
73
|
+
after=after_log(logger, logging.INFO),
|
|
74
|
+
before_sleep=before_sleep_log(logger, logging.WARNING),
|
|
75
|
+
)
|
|
76
|
+
def post(path: str, payload: dict, files=None, extra_headers={}):
|
|
77
|
+
# Jesus christ this logic needs cleaning up
|
|
78
|
+
if not files and "Content-Type" not in extra_headers:
|
|
79
|
+
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
|
80
|
+
else:
|
|
81
|
+
headers = {}
|
|
82
|
+
|
|
83
|
+
if extra_headers:
|
|
84
|
+
if "Content-Type" in extra_headers:
|
|
85
|
+
headers["Content-Type"] = extra_headers["Content-Type"]
|
|
86
|
+
payload = json.dumps(payload)
|
|
87
|
+
else:
|
|
88
|
+
headers.update(extra_headers)
|
|
89
|
+
|
|
90
|
+
if os.environ.get("AT_TOKEN"):
|
|
91
|
+
headers["Authorization"] = f"Token {os.environ.get('AT_TOKEN')}"
|
|
92
|
+
|
|
93
|
+
api_root = os.environ.get("AT_SERVER")
|
|
94
|
+
|
|
95
|
+
if files is not None:
|
|
96
|
+
response = requests.post(
|
|
97
|
+
f"{api_root}/{path}", data=payload, headers=headers, files=files
|
|
98
|
+
)
|
|
99
|
+
else:
|
|
100
|
+
response = requests.post(f"{api_root}/{path}", data=payload, headers=headers)
|
|
101
|
+
|
|
102
|
+
if response.status_code in [requests.codes.ok, requests.codes.created]:
|
|
103
|
+
resp = response.json()
|
|
104
|
+
|
|
105
|
+
if "error" in resp and "api/tasks/" not in path:
|
|
106
|
+
raise PermissionDenied(resp["error"])
|
|
107
|
+
else:
|
|
108
|
+
return resp
|
|
109
|
+
|
|
110
|
+
elif response.status_code == requests.codes.bad_request:
|
|
111
|
+
raise APIValidationError(response.json())
|
|
112
|
+
elif response.status_code == requests.codes.forbidden:
|
|
113
|
+
raise PermissionDenied(response.json())
|
|
114
|
+
else:
|
|
115
|
+
response.raise_for_status()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@retry(
|
|
119
|
+
stop=stop_after_attempt(5),
|
|
120
|
+
wait=wait_exponential(multiplier=2, min=1, max=30),
|
|
121
|
+
retry=(retry_if_exception_type((ConnectionError, Timeout)) | retry_if_exception(is_http_5xx_error)),
|
|
122
|
+
before=before_log(logger, logging.INFO),
|
|
123
|
+
after=after_log(logger, logging.INFO),
|
|
124
|
+
before_sleep=before_sleep_log(logger, logging.WARNING),
|
|
125
|
+
)
|
|
126
|
+
def patch(path: str, payload: dict):
|
|
127
|
+
payload_enc = json.dumps(payload)
|
|
128
|
+
headers = {"Content-Type": "application/json"}
|
|
129
|
+
|
|
130
|
+
if os.environ.get("AT_TOKEN"):
|
|
131
|
+
headers["Authorization"] = f"Token {os.environ.get('AT_TOKEN')}"
|
|
132
|
+
|
|
133
|
+
api_root = os.environ.get("AT_SERVER")
|
|
134
|
+
response = requests.patch(f"{api_root}/{path}", data=payload_enc, headers=headers)
|
|
135
|
+
|
|
136
|
+
if response.status_code == requests.codes.ok:
|
|
137
|
+
resp = response.json()
|
|
138
|
+
|
|
139
|
+
if resp.get("error") is not None and "api/tasks/" not in path:
|
|
140
|
+
raise Exception(resp["error"])
|
|
141
|
+
else:
|
|
142
|
+
return resp
|
|
143
|
+
|
|
144
|
+
elif response.status_code == requests.codes.bad_request:
|
|
145
|
+
raise APIValidationError(response.json())
|
|
146
|
+
elif response.status_code == requests.codes.forbidden:
|
|
147
|
+
raise PermissionDenied(response.json())
|
|
148
|
+
else:
|
|
149
|
+
response.raise_for_status()
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@retry(
|
|
153
|
+
stop=stop_after_attempt(5),
|
|
154
|
+
wait=wait_exponential(multiplier=2, min=1, max=30),
|
|
155
|
+
retry=(retry_if_exception_type((ConnectionError, Timeout)) | retry_if_exception(is_http_5xx_error)),
|
|
156
|
+
before=before_log(logger, logging.INFO),
|
|
157
|
+
after=after_log(logger, logging.INFO),
|
|
158
|
+
before_sleep=before_sleep_log(logger, logging.WARNING),
|
|
159
|
+
)
|
|
160
|
+
def delete(path: str):
|
|
161
|
+
headers = {}
|
|
162
|
+
|
|
163
|
+
if os.environ.get("AT_TOKEN"):
|
|
164
|
+
headers["Authorization"] = f"Token {os.environ.get('AT_TOKEN')}"
|
|
165
|
+
|
|
166
|
+
api_root = os.environ.get("AT_SERVER")
|
|
167
|
+
response = requests.delete(f"{api_root}/{path}", headers=headers)
|
|
168
|
+
|
|
169
|
+
if response.status_code == requests.codes.ok:
|
|
170
|
+
resp = response.json()
|
|
171
|
+
|
|
172
|
+
if resp.get("error") is not None and "api/tasks/" not in path:
|
|
173
|
+
raise Exception(resp["error"])
|
|
174
|
+
else:
|
|
175
|
+
return resp
|
|
176
|
+
|
|
177
|
+
elif response.status_code == requests.codes.bad_request:
|
|
178
|
+
raise APIValidationError(response.json())
|
|
179
|
+
elif response.status_code == requests.codes.forbidden:
|
|
180
|
+
raise PermissionDenied(response.json())
|
|
181
|
+
else:
|
|
182
|
+
response.raise_for_status()
|
atomict/auth.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from atomict.api import post
|
|
4
|
+
from atomict.env import get, store
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def authenticate(username: str, password: str) -> str:
|
|
8
|
+
"""Authenticate a user."""
|
|
9
|
+
|
|
10
|
+
response = post("api-auth/", {"username": username, "password": password})
|
|
11
|
+
|
|
12
|
+
store("token", response["token"])
|
|
13
|
+
return response["token"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def resolve_token() -> str:
|
|
17
|
+
"""
|
|
18
|
+
Resolve the token from the environment or authenticate.
|
|
19
|
+
|
|
20
|
+
Order of presedence:
|
|
21
|
+
- Environment variable
|
|
22
|
+
- Store
|
|
23
|
+
- Authenticate
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
token = os.environ.get("AT_TOKEN")
|
|
29
|
+
if token:
|
|
30
|
+
return token
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
token = get("token")
|
|
34
|
+
if token:
|
|
35
|
+
return token
|
|
36
|
+
except FileNotFoundError:
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
user = os.environ.get("AT_USER")
|
|
40
|
+
passw = os.environ.get("AT_PASS")
|
|
41
|
+
|
|
42
|
+
if None in [user, passw]:
|
|
43
|
+
raise ValueError(
|
|
44
|
+
"AT_TOKEN not set and user and password also not set AT_USER, AT_PASS"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
return authenticate(user, passw)
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# cli/commands/adsorbate.py
|
|
2
|
+
from typing import Optional, Tuple
|
|
3
|
+
|
|
4
|
+
import click
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
from rich.panel import Panel
|
|
7
|
+
|
|
8
|
+
from atomict.cli.commands.common import create_table
|
|
9
|
+
from atomict.cli.core.client import get_client
|
|
10
|
+
from atomict.cli.core.utils import get_pagination_info
|
|
11
|
+
|
|
12
|
+
console = Console()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@click.group(name="adsorbate")
|
|
16
|
+
def adsorbate():
|
|
17
|
+
"""Manage adsorbates"""
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@adsorbate.command()
|
|
22
|
+
@click.argument("id", required=False)
|
|
23
|
+
@click.option("--json-output", is_flag=True, help="Output in JSON format")
|
|
24
|
+
@click.option("--search", help="Search term")
|
|
25
|
+
@click.option("--filter", "filters", multiple=True, help="Filter in format field=value")
|
|
26
|
+
@click.option("--ordering", help="Field to order by (prefix with - for descending)")
|
|
27
|
+
@click.option(
|
|
28
|
+
"--all",
|
|
29
|
+
"fetch_all",
|
|
30
|
+
is_flag=True,
|
|
31
|
+
help="Fetch all results (otherwise returns first page)",
|
|
32
|
+
)
|
|
33
|
+
def get(
|
|
34
|
+
id: Optional[str],
|
|
35
|
+
search: Optional[str] = None,
|
|
36
|
+
filters: Optional[Tuple] = None, # Fixed syntax error and moved default value
|
|
37
|
+
ordering: Optional[str] = None,
|
|
38
|
+
fetch_all: bool = False,
|
|
39
|
+
json_output: bool = False,
|
|
40
|
+
):
|
|
41
|
+
"""List adsorbates with optional filtering and search"""
|
|
42
|
+
client = get_client()
|
|
43
|
+
|
|
44
|
+
if id:
|
|
45
|
+
result = client.get(f"/api/adsorbate/{id}/")
|
|
46
|
+
if json_output:
|
|
47
|
+
console.print_json(data=result)
|
|
48
|
+
return
|
|
49
|
+
|
|
50
|
+
console.print(Panel("[bold]Adsorbate Details[/bold]"))
|
|
51
|
+
console.print(f"ID: {result['id']}")
|
|
52
|
+
# Add other relevant fields
|
|
53
|
+
else:
|
|
54
|
+
# Build query parameters
|
|
55
|
+
params = {}
|
|
56
|
+
if search:
|
|
57
|
+
params["search"] = search
|
|
58
|
+
if ordering:
|
|
59
|
+
params["ordering"] = ordering
|
|
60
|
+
if filters:
|
|
61
|
+
for f in filters:
|
|
62
|
+
try:
|
|
63
|
+
key, value = f.split("=")
|
|
64
|
+
params[key] = value
|
|
65
|
+
except ValueError:
|
|
66
|
+
click.echo(
|
|
67
|
+
f"[red]Invalid filter format: {f}. Use field=value[/red]",
|
|
68
|
+
err=True,
|
|
69
|
+
)
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
if fetch_all:
|
|
73
|
+
# Get all results using the paginate method
|
|
74
|
+
results = client.get_all("/api/adsorbate/", params=params)
|
|
75
|
+
else:
|
|
76
|
+
# Get just the first page
|
|
77
|
+
results = client.get("/api/adsorbate/", params=params)
|
|
78
|
+
|
|
79
|
+
if json_output:
|
|
80
|
+
console.print_json(data=results)
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
# Define columns with optional formatters
|
|
84
|
+
columns = [
|
|
85
|
+
("ID", "id", None), # Using default str formatter
|
|
86
|
+
("SMILES", "smiles", None),
|
|
87
|
+
("Binding Indices", "binding_indices", None),
|
|
88
|
+
("Reaction String", "reaction_string", None),
|
|
89
|
+
]
|
|
90
|
+
items, footer_string = get_pagination_info(results)
|
|
91
|
+
# Create and display the table
|
|
92
|
+
table = create_table(
|
|
93
|
+
columns=columns, items=items, title="Adsorbates", caption=footer_string
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
console.print(table)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@adsorbate.command()
|
|
100
|
+
@click.option("--ase-atoms", required=True, help="ASE atoms string representation")
|
|
101
|
+
@click.option("--smiles", help="SMILES string representation of the molecule")
|
|
102
|
+
@click.option(
|
|
103
|
+
"--binding-indices",
|
|
104
|
+
multiple=True,
|
|
105
|
+
type=int,
|
|
106
|
+
help="Binding atom indices (can be specified multiple times)",
|
|
107
|
+
)
|
|
108
|
+
@click.option("--reaction-string", help="Reaction string representation")
|
|
109
|
+
def create(
|
|
110
|
+
ase_atoms: Optional[str] = None,
|
|
111
|
+
smiles: Optional[str] = None,
|
|
112
|
+
binding_indices: Optional[tuple[int, ...]] = None,
|
|
113
|
+
reaction_string: Optional[str] = None,
|
|
114
|
+
):
|
|
115
|
+
"""
|
|
116
|
+
Create a new adsorbate.
|
|
117
|
+
|
|
118
|
+
Examples:
|
|
119
|
+
at adsorbate create --smiles "CC(=O)O" --binding-indices 1 --binding-indices 2
|
|
120
|
+
at adsorbate create --ase-atoms "Atoms(...)" --reaction-string "A + B -> C"
|
|
121
|
+
"""
|
|
122
|
+
client = get_client()
|
|
123
|
+
|
|
124
|
+
data = {
|
|
125
|
+
"ase_atoms": ase_atoms, # this needs work on the server side
|
|
126
|
+
"smiles": smiles,
|
|
127
|
+
"binding_indices": list(binding_indices) if binding_indices else None,
|
|
128
|
+
"reaction_string": reaction_string,
|
|
129
|
+
}
|
|
130
|
+
data = {k: v for k, v in data.items() if v is not None}
|
|
131
|
+
|
|
132
|
+
result = client.post("/api/adsorbate/", data)
|
|
133
|
+
console.print(f"[green]Created adsorbate {result['id']}[/green]")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@adsorbate.command()
|
|
137
|
+
@click.argument("id")
|
|
138
|
+
@click.option("--ase-atoms", help="ASE atoms string representation")
|
|
139
|
+
@click.option("--smiles", help="SMILES string representation of the molecule")
|
|
140
|
+
@click.option(
|
|
141
|
+
"--binding-indices",
|
|
142
|
+
multiple=True,
|
|
143
|
+
type=int,
|
|
144
|
+
help="Binding atom indices (can be specified multiple times)",
|
|
145
|
+
)
|
|
146
|
+
@click.option("--reaction-string", help="Reaction string representation")
|
|
147
|
+
def update(
|
|
148
|
+
id: str,
|
|
149
|
+
ase_atoms: Optional[str] = None,
|
|
150
|
+
smiles: Optional[str] = None,
|
|
151
|
+
binding_indices: Optional[tuple[int, ...]] = None,
|
|
152
|
+
reaction_string: Optional[str] = None,
|
|
153
|
+
):
|
|
154
|
+
"""
|
|
155
|
+
Update an existing adsorbate.
|
|
156
|
+
|
|
157
|
+
Examples:
|
|
158
|
+
at adsorbate update 123 --smiles "CC(=O)O" --binding-indices 1 --binding-indices 2
|
|
159
|
+
at adsorbate update 456 --ase-atoms "Atoms(...)" --reaction-string "A + B -> C"
|
|
160
|
+
"""
|
|
161
|
+
client = get_client()
|
|
162
|
+
|
|
163
|
+
# Build update data excluding None values
|
|
164
|
+
data = {
|
|
165
|
+
"ase_atoms": ase_atoms,
|
|
166
|
+
"smiles": smiles,
|
|
167
|
+
"binding_indices": list(binding_indices) if binding_indices else None,
|
|
168
|
+
"reaction_string": reaction_string,
|
|
169
|
+
}
|
|
170
|
+
data = {k: v for k, v in data.items() if v is not None}
|
|
171
|
+
|
|
172
|
+
result = client.put(f"/api/adsorbate/{id}/", data)
|
|
173
|
+
console.print(f"[green]Updated adsorbate {result['id']}[/green]")
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@adsorbate.command()
|
|
177
|
+
@click.argument("id")
|
|
178
|
+
def delete(id: str):
|
|
179
|
+
"""Delete an adsorbate"""
|
|
180
|
+
client = get_client()
|
|
181
|
+
|
|
182
|
+
client.delete(f"/api/adsorbate/{id}/")
|
|
183
|
+
console.print(f"[green]Deleted adsorbate {id}[/green]")
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# cli/commands/ai_assist.py
|
|
2
|
+
import json
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.panel import Panel
|
|
8
|
+
from rich.table import Table
|
|
9
|
+
|
|
10
|
+
from atomict.cli.core.client import get_client
|
|
11
|
+
|
|
12
|
+
console = Console()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@click.group(name="ai-assist")
|
|
16
|
+
def ai_assist_group():
|
|
17
|
+
"""Manage AI assistance features (WIP)"""
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@ai_assist_group.command()
|
|
22
|
+
@click.argument("id", required=False)
|
|
23
|
+
@click.option("--json-output", is_flag=True, help="Output in JSON format")
|
|
24
|
+
def get_accepted(id: Optional[str] = None, json_output: bool = False):
|
|
25
|
+
"""Get accepted AI suggestions or list all"""
|
|
26
|
+
client = get_client()
|
|
27
|
+
|
|
28
|
+
if id:
|
|
29
|
+
result = client.get(f"/api/ai-assist-accepted-code/{id}/")
|
|
30
|
+
if json_output:
|
|
31
|
+
click.echo(json.dumps(result, indent=2))
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
console.print(Panel(f"[bold]Accepted AI Suggestion[/bold]"))
|
|
35
|
+
console.print(f"ID: {result['id']}")
|
|
36
|
+
console.print(f"Created: {result.get('created_at', 'N/A')}")
|
|
37
|
+
console.print(f"\nCode:\n{result.get('code', 'N/A')}")
|
|
38
|
+
else:
|
|
39
|
+
results = client.get_all("/api/ai-assist-accepted-code/")
|
|
40
|
+
if json_output:
|
|
41
|
+
click.echo(json.dumps(results, indent=2))
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
table = Table(show_header=True)
|
|
45
|
+
table.add_column("ID")
|
|
46
|
+
table.add_column("Created")
|
|
47
|
+
table.add_column("User")
|
|
48
|
+
|
|
49
|
+
for item in results:
|
|
50
|
+
table.add_row(
|
|
51
|
+
str(item["id"]), item.get("created_at", "N/A"), item.get("user", "N/A")
|
|
52
|
+
)
|
|
53
|
+
console.print(table)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@ai_assist_group.command()
|
|
57
|
+
@click.argument("id", required=False)
|
|
58
|
+
@click.option("--json-output", is_flag=True, help="Output in JSON format")
|
|
59
|
+
def get_votes(id: Optional[str] = None, json_output: bool = False):
|
|
60
|
+
"""Get AI suggestion votes or list all"""
|
|
61
|
+
client = get_client()
|
|
62
|
+
|
|
63
|
+
if id:
|
|
64
|
+
result = client.get(f"/api/ai-assist-vote/{id}/")
|
|
65
|
+
if json_output:
|
|
66
|
+
click.echo(json.dumps(result, indent=2))
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
console.print(Panel(f"[bold]AI Suggestion Vote[/bold]"))
|
|
70
|
+
console.print(f"ID: {result['id']}")
|
|
71
|
+
console.print(f"Vote: {result.get('vote', 'N/A')}")
|
|
72
|
+
console.print(f"Created: {result.get('created_at', 'N/A')}")
|
|
73
|
+
else:
|
|
74
|
+
results = client.get_all("/api/ai-assist-vote/")
|
|
75
|
+
if json_output:
|
|
76
|
+
click.echo(json.dumps(results, indent=2))
|
|
77
|
+
return
|
|
78
|
+
|
|
79
|
+
table = Table(show_header=True)
|
|
80
|
+
table.add_column("ID")
|
|
81
|
+
table.add_column("Vote")
|
|
82
|
+
table.add_column("Created")
|
|
83
|
+
table.add_column("User")
|
|
84
|
+
|
|
85
|
+
for item in results:
|
|
86
|
+
table.add_row(
|
|
87
|
+
str(item["id"]),
|
|
88
|
+
str(item.get("vote", "N/A")),
|
|
89
|
+
item.get("created_at", "N/A"),
|
|
90
|
+
item.get("user", "N/A"),
|
|
91
|
+
)
|
|
92
|
+
console.print(table)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@ai_assist_group.command()
|
|
96
|
+
@click.option(
|
|
97
|
+
"--vote", type=click.Choice(["up", "down"]), required=True, help="Vote up or down"
|
|
98
|
+
)
|
|
99
|
+
@click.option("--suggestion-id", required=True, help="ID of the AI suggestion")
|
|
100
|
+
def vote(vote: str, suggestion_id: str):
|
|
101
|
+
"""Vote on an AI suggestion"""
|
|
102
|
+
# TODO: iron out the server side of this
|
|
103
|
+
client = get_client()
|
|
104
|
+
|
|
105
|
+
data = {"vote": 1 if vote == "up" else -1, "suggestion": suggestion_id}
|
|
106
|
+
|
|
107
|
+
result = client.post("/api/ai-assist-vote/", data)
|
|
108
|
+
console.print(f"[green]Vote recorded: {result['id']}[/green]")
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
ai_assist = ai_assist_group
|