atomict 0.1.2__tar.gz → 0.1.4__tar.gz

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.
Files changed (101) hide show
  1. {atomict-0.1.2 → atomict-0.1.4}/LICENSE +0 -0
  2. atomict-0.1.4/PKG-INFO +105 -0
  3. atomict-0.1.4/README.md +72 -0
  4. atomict-0.1.4/atomict/__init__.py +1 -0
  5. atomict-0.1.4/atomict/__version__.py +1 -0
  6. atomict-0.1.4/atomict/api.py +182 -0
  7. atomict-0.1.4/atomict/auth.py +47 -0
  8. atomict-0.1.4/atomict/cli/commands/adsorbate.py +183 -0
  9. atomict-0.1.4/atomict/cli/commands/ai_assist.py +111 -0
  10. atomict-0.1.4/atomict/cli/commands/catalysis.py +171 -0
  11. atomict-0.1.4/atomict/cli/commands/common.py +57 -0
  12. atomict-0.1.4/atomict/cli/commands/exploration/__init__.py +7 -0
  13. atomict-0.1.4/atomict/cli/commands/exploration/soec.py +564 -0
  14. atomict-0.1.4/atomict/cli/commands/exploration/sqs.py +440 -0
  15. atomict-0.1.4/atomict/cli/commands/helpers.py +74 -0
  16. atomict-0.1.4/atomict/cli/commands/k8s.py +211 -0
  17. atomict-0.1.4/atomict/cli/commands/login.py +34 -0
  18. atomict-0.1.4/atomict/cli/commands/organization.py +76 -0
  19. atomict-0.1.4/atomict/cli/commands/project.py +876 -0
  20. atomict-0.1.4/atomict/cli/commands/simulation/__init__.py +20 -0
  21. atomict-0.1.4/atomict/cli/commands/simulation/catalysis.py +223 -0
  22. atomict-0.1.4/atomict/cli/commands/simulation/fhiaims.py +279 -0
  23. atomict-0.1.4/atomict/cli/commands/simulation/kpoint.py +380 -0
  24. atomict-0.1.4/atomict/cli/commands/simulation/vibes.py +161 -0
  25. atomict-0.1.4/atomict/cli/commands/simulation.py +176 -0
  26. atomict-0.1.4/atomict/cli/commands/task.py +181 -0
  27. atomict-0.1.4/atomict/cli/commands/upload.py +84 -0
  28. atomict-0.1.4/atomict/cli/commands/user.py +201 -0
  29. atomict-0.1.4/atomict/cli/core/client.py +202 -0
  30. atomict-0.1.4/atomict/cli/core/config.py +43 -0
  31. atomict-0.1.4/atomict/cli/core/utils.py +32 -0
  32. atomict-0.1.4/atomict/cli/main.py +124 -0
  33. atomict-0.1.4/atomict/env.py +79 -0
  34. atomict-0.1.4/atomict/exceptions.py +12 -0
  35. atomict-0.1.4/atomict/infra/distwork/environment.py +26 -0
  36. atomict-0.1.4/atomict/infra/distwork/task.py +49 -0
  37. atomict-0.1.4/atomict/infra/logging.py +22 -0
  38. atomict-0.1.4/atomict/io/cif.py +131 -0
  39. atomict-0.1.4/atomict/io/fhiaims.py +24 -0
  40. atomict-0.1.4/atomict/io/json.py +22 -0
  41. atomict-0.1.4/atomict/io/utils.py +11 -0
  42. atomict-0.1.4/atomict/ml/__init__.py +0 -0
  43. atomict-0.1.4/atomict/ml/model.py +13 -0
  44. atomict-0.1.4/atomict/project/__init__.py +1 -0
  45. atomict-0.1.4/atomict/project/link.py +26 -0
  46. atomict-0.1.4/atomict/project/note.py +18 -0
  47. atomict-0.1.4/atomict/project/project.py +32 -0
  48. atomict-0.1.4/atomict/project/tags.py +48 -0
  49. atomict-0.1.4/atomict/project/workbench.py +6 -0
  50. atomict-0.1.4/atomict/reality/__init__.py +0 -0
  51. atomict-0.1.4/atomict/reality/oqmd.py +5 -0
  52. atomict-0.1.4/atomict/reality/slabs.py +5 -0
  53. atomict-0.1.4/atomict/simulation/__init__.py +0 -0
  54. atomict-0.1.4/atomict/simulation/cantera.py +35 -0
  55. atomict-0.1.4/atomict/simulation/catalysis.py +20 -0
  56. atomict-0.1.4/atomict/simulation/counterfactual.py +28 -0
  57. atomict-0.1.4/atomict/simulation/ea.py +64 -0
  58. atomict-0.1.4/atomict/simulation/fhi_aims.py +72 -0
  59. atomict-0.1.4/atomict/simulation/kpoint.py +74 -0
  60. atomict-0.1.4/atomict/simulation/mlrelax.py +83 -0
  61. atomict-0.1.4/atomict/simulation/phonon.py +12 -0
  62. atomict-0.1.4/atomict/simulation/qe.py +74 -0
  63. atomict-0.1.4/atomict/simulation/sqs.py +24 -0
  64. atomict-0.1.4/atomict/simulation/utils.py +83 -0
  65. atomict-0.1.4/atomict/user/__init__.py +0 -0
  66. atomict-0.1.4/atomict/user/files.py +31 -0
  67. atomict-0.1.4/atomict/user/workspace.py +112 -0
  68. atomict-0.1.4/atomict/utils/fhiaims/__init__.py +0 -0
  69. atomict-0.1.4/atomict/utils/fhiaims/geometry.py +65 -0
  70. atomict-0.1.4/atomict/utils/tenacity.py +36 -0
  71. atomict-0.1.4/atomict.egg-info/PKG-INFO +105 -0
  72. atomict-0.1.4/atomict.egg-info/SOURCES.txt +81 -0
  73. atomict-0.1.4/atomict.egg-info/entry_points.txt +2 -0
  74. atomict-0.1.4/atomict.egg-info/requires.txt +14 -0
  75. {atomict-0.1.2 → atomict-0.1.4}/atomict.egg-info/top_level.txt +0 -1
  76. atomict-0.1.4/pyproject.toml +81 -0
  77. atomict-0.1.4/requirements.txt +10 -0
  78. atomict-0.1.2/MANIFEST.in +0 -1
  79. atomict-0.1.2/PKG-INFO +0 -55
  80. atomict-0.1.2/README.md +0 -33
  81. atomict-0.1.2/atomict/__init__.py +0 -1
  82. atomict-0.1.2/atomict/__main__.py +0 -3
  83. atomict-0.1.2/atomict/cli.py +0 -59
  84. atomict-0.1.2/atomict/datasets/__init__.py +0 -25
  85. atomict-0.1.2/atomict/datasets/io.py +0 -47
  86. atomict-0.1.2/atomict/datasets/public.py +0 -32
  87. atomict-0.1.2/atomict/utils/requests.py +0 -19
  88. atomict-0.1.2/atomict/version.py +0 -2
  89. atomict-0.1.2/atomict.egg-info/PKG-INFO +0 -55
  90. atomict-0.1.2/atomict.egg-info/SOURCES.txt +0 -24
  91. atomict-0.1.2/atomict.egg-info/entry_points.txt +0 -2
  92. atomict-0.1.2/atomict.egg-info/requires.txt +0 -42
  93. atomict-0.1.2/requirements.txt +0 -42
  94. atomict-0.1.2/setup.py +0 -41
  95. atomict-0.1.2/tests/test_sdk.py +0 -16
  96. {atomict-0.1.2/atomict/auth → atomict-0.1.4/atomict/cli}/__init__.py +0 -0
  97. {atomict-0.1.2/atomict/utils → atomict-0.1.4/atomict/infra}/__init__.py +0 -0
  98. {atomict-0.1.2/tests → atomict-0.1.4/atomict/infra/distwork}/__init__.py +0 -0
  99. /atomict-0.1.2/tests/test_cli.py → /atomict-0.1.4/atomict/io/__init__.py +0 -0
  100. {atomict-0.1.2 → atomict-0.1.4}/atomict.egg-info/dependency_links.txt +0 -0
  101. {atomict-0.1.2 → atomict-0.1.4}/setup.cfg +0 -0
File without changes
atomict-0.1.4/PKG-INFO ADDED
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.2
2
+ Name: atomict
3
+ Version: 0.1.4
4
+ Summary: The client application for the https://atomictessellator.com/
5
+ Author-email: Steven Anderson <steven@atomictessellator.com>, Alain Richardt <alain@atomictessellator.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/AtomicTessellator/atomic_cli
8
+ Keywords: atomic,tessellator,cli,client,fhi-aims,kpoint,sqs,adsorbate
9
+ Classifier: Topic :: Scientific/Engineering :: Physics
10
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
11
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: requests
21
+ Requires-Dist: ase>=3.23.0
22
+ Requires-Dist: tenacity~=9.0
23
+ Requires-Dist: spglib==2.5.0
24
+ Requires-Dist: httpx
25
+ Requires-Dist: click~=8.0
26
+ Requires-Dist: rich~=13.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest~=8.0; extra == "dev"
29
+ Requires-Dist: black; extra == "dev"
30
+ Requires-Dist: isort; extra == "dev"
31
+ Requires-Dist: mypy; extra == "dev"
32
+ Requires-Dist: flake8; extra == "dev"
33
+
34
+ # Atomic Tessellator - CLI package
35
+
36
+ ## Installation
37
+ ```
38
+ pip install atomict
39
+ ```
40
+
41
+ ## Installation for devs
42
+ ```
43
+ pip install -e ".[dev]"
44
+ ```
45
+
46
+ Enable verbose logging for debugging:
47
+
48
+ ```
49
+ export AT_DEBUG=enabled
50
+ ```
51
+
52
+ # CLI Usage
53
+
54
+ ## Get a list of available commands
55
+
56
+ ```$ at```
57
+
58
+ ![Alt text](img/at.png?raw=true "at")
59
+
60
+ You can get help for each command with `at <command> --help`. This will print the command-specific help and options.
61
+ ## Log in and store authentication token
62
+
63
+ ```$ at login```
64
+
65
+ This will prompt you for your username and password.
66
+
67
+
68
+ ## Get a list of available projects
69
+
70
+ ```$ at project get```
71
+
72
+ ![Alt text](img/at_project_get.png?raw=true "at project get")
73
+
74
+
75
+ ## Get a list of adsorbates
76
+
77
+ ```$ at adsorbate get```
78
+
79
+ ![Alt text](img/at_adsorbate_get.png?raw=true "at adsorbate get")
80
+
81
+ ## Search objects for substrings
82
+
83
+ ```$ at adsorbate get --search NH3```
84
+
85
+ ![Alt text](img/at_adsorbate_get_search.png?raw=true "at adsorbate get --search")
86
+
87
+ ## Get a list of tasks
88
+
89
+ ```$ at task get```
90
+
91
+ ![Alt text](img/at_task_get.png?raw=true "at task get")
92
+
93
+ ## Get tasks with a specific status
94
+
95
+ ```$ at task get --status completed```
96
+
97
+ ![Alt text](img/at_task_get_completed.png?raw=true "at task get --status completed")
98
+
99
+ ## Configuration
100
+
101
+ Tab completion is available. Run the hidden command:
102
+
103
+ ```at completion```
104
+
105
+ This will print out the instructions for enabling tab completion for your shell.
@@ -0,0 +1,72 @@
1
+ # Atomic Tessellator - CLI package
2
+
3
+ ## Installation
4
+ ```
5
+ pip install atomict
6
+ ```
7
+
8
+ ## Installation for devs
9
+ ```
10
+ pip install -e ".[dev]"
11
+ ```
12
+
13
+ Enable verbose logging for debugging:
14
+
15
+ ```
16
+ export AT_DEBUG=enabled
17
+ ```
18
+
19
+ # CLI Usage
20
+
21
+ ## Get a list of available commands
22
+
23
+ ```$ at```
24
+
25
+ ![Alt text](img/at.png?raw=true "at")
26
+
27
+ You can get help for each command with `at <command> --help`. This will print the command-specific help and options.
28
+ ## Log in and store authentication token
29
+
30
+ ```$ at login```
31
+
32
+ This will prompt you for your username and password.
33
+
34
+
35
+ ## Get a list of available projects
36
+
37
+ ```$ at project get```
38
+
39
+ ![Alt text](img/at_project_get.png?raw=true "at project get")
40
+
41
+
42
+ ## Get a list of adsorbates
43
+
44
+ ```$ at adsorbate get```
45
+
46
+ ![Alt text](img/at_adsorbate_get.png?raw=true "at adsorbate get")
47
+
48
+ ## Search objects for substrings
49
+
50
+ ```$ at adsorbate get --search NH3```
51
+
52
+ ![Alt text](img/at_adsorbate_get_search.png?raw=true "at adsorbate get --search")
53
+
54
+ ## Get a list of tasks
55
+
56
+ ```$ at task get```
57
+
58
+ ![Alt text](img/at_task_get.png?raw=true "at task get")
59
+
60
+ ## Get tasks with a specific status
61
+
62
+ ```$ at task get --status completed```
63
+
64
+ ![Alt text](img/at_task_get_completed.png?raw=true "at task get --status completed")
65
+
66
+ ## Configuration
67
+
68
+ Tab completion is available. Run the hidden command:
69
+
70
+ ```at completion```
71
+
72
+ This will print out the instructions for enabling tab completion for your shell.
@@ -0,0 +1 @@
1
+ from .__version__ import __version__
@@ -0,0 +1 @@
1
+ __version__ = "0.1.4"
@@ -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()
@@ -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]")