atomict 1.2.25__py3-none-any.whl → 1.2.27__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.
@@ -44,7 +44,7 @@ def get(
44
44
  # Format single simulation output
45
45
  console.print(f"ID: {simulation['id']}")
46
46
  console.print(f"Name: {simulation.get('name', 'N/A')}")
47
- console.print(f"Finite diff displacement: {simulation.get('finite_diff_displacement', 'N/A')}")
47
+ console.print(f"Description: {simulation.get('description', 'N/A')}")
48
48
  console.print(f"Created: {format_datetime(simulation['created_at'])}")
49
49
  if simulation.get("task"):
50
50
  status = get_status_string(simulation["task"].get("status"))
@@ -77,12 +77,9 @@ def get(
77
77
  console.print_json(data=results)
78
78
  return
79
79
 
80
- # Define columns based on what's already in the table_0 setup
81
80
  columns = [
82
81
  ("ID", "id", None),
83
82
  ("Name", "name", None),
84
- ("Finite diff displacement", "finite_diff_displacement", None),
85
- ("Task status", "task", lambda x: get_status_string(x.get("status"))),
86
83
  ("Created", "created_at", format_datetime),
87
84
  (
88
85
  "Status",
@@ -116,37 +113,22 @@ def get(
116
113
  @click.option("--description", help="Simulation description")
117
114
  @click.option("--control-file", required=True, help="Control file content")
118
115
  @click.option("--geometry-file", required=True, help="Geometry file content")
119
- @click.option(
120
- "--generate-finite-diff",
121
- is_flag=True,
122
- help="Generate finite difference displacements",
123
- )
124
- @click.option(
125
- "--finite-diff-displacement",
126
- type=float,
127
- help="Finite difference displacement value",
128
- )
129
116
  def create(
130
117
  name: Optional[str],
131
118
  description: Optional[str],
132
119
  control_file: str,
133
120
  geometry_file: str,
134
- generate_finite_diff: bool = False,
135
- finite_diff_displacement: Optional[float] = None,
136
121
  ):
137
122
  """Create a new FHI-aims simulation"""
138
123
  client = get_client()
139
124
  data = {
140
125
  "control_file": control_file,
141
126
  "geometry_file": geometry_file,
142
- "generate_finite_diff_displacements": generate_finite_diff,
143
127
  }
144
128
  if name:
145
129
  data["name"] = name
146
130
  if description:
147
131
  data["description"] = description
148
- if finite_diff_displacement is not None:
149
- data["finite_diff_displacement"] = finite_diff_displacement
150
132
 
151
133
  simulation = client.post("/api/fhiaims-simulation/", data=data)
152
134
  console.print(f"[green]Created simulation with ID: {simulation['id']}[/green]")
@@ -118,16 +118,22 @@ def get(
118
118
 
119
119
  @kpoint_group.command()
120
120
  @click.option("--exploration", required=True, help="Exploration ID")
121
+ @click.option("--simulation", required=True, help="FHI-aims simulation ID")
121
122
  @click.option(
122
- "--k-points", required=True, multiple=True, type=float, help="K-point values"
123
+ "--k-points", multiple=True, type=float, help="K-point values"
123
124
  )
124
- def create(exploration: str, k_points: List[float]):
125
+ def create(exploration: str, simulation: str, k_points: List[float]):
125
126
  """Create a new K-point simulation"""
126
127
  client = get_client()
127
- data = {"exploration": exploration, "k_points": list(k_points)}
128
+ data = {
129
+ "exploration_id": exploration,
130
+ "simulation_id": simulation,
131
+ }
132
+ if k_points:
133
+ data["k_points"] = list(k_points)
128
134
 
129
- simulation = client.post("/api/kpoint-simulation/", data=data)
130
- console.print(f"[green]Created simulation with ID: {simulation['id']}[/green]")
135
+ result = client.post("/api/kpoint-simulation/", data=data)
136
+ console.print(f"[green]Created simulation with ID: {result['id']}[/green]")
131
137
 
132
138
 
133
139
  @kpoint_group.command()
@@ -234,14 +240,14 @@ def get_exploration(
234
240
 
235
241
 
236
242
  @kpoint_group.command()
237
- @click.option("--name", required=True, help="Exploration name")
243
+ @click.option("--name", help="Exploration name")
238
244
  @click.option("--description", help="Exploration description")
239
- def create_exploration(name: str, description: Optional[str] = None):
245
+ def create_exploration(name: Optional[str] = None, description: Optional[str] = None):
240
246
  """Create a new K-point exploration"""
241
247
  client = get_client()
242
- data = {
243
- "name": name,
244
- }
248
+ data = {}
249
+ if name:
250
+ data["name"] = name
245
251
  if description:
246
252
  data["description"] = description
247
253
 
@@ -355,20 +361,17 @@ def get_analysis(
355
361
 
356
362
 
357
363
  @kpoint_group.command()
358
- @click.argument("analysis")
364
+ @click.argument("analysis", required=False)
359
365
  @click.option("--exploration", required=True, help="Exploration ID")
360
- def create_analysis(exploration: str, analysis: str):
361
- """Create a new K-point analysis. Takes JSON analysis data as main argument."""
366
+ def create_analysis(exploration: str, analysis: Optional[str] = None):
367
+ """Create a new K-point analysis. Optionally takes JSON analysis data as the argument."""
362
368
  client = get_client()
363
- # TODO: what data would a user provide?
364
- data = {
365
- "analysis": analysis,
366
- }
367
- if exploration:
368
- data["exploration"] = exploration
369
+ data = {"exploration_id": exploration}
370
+ if analysis is not None:
371
+ data["analysis"] = analysis
369
372
 
370
- analysis = client.post("/api/kpoint-analysis/", data=data)
371
- console.print(f"[green]Created analysis with ID: {analysis['id']}[/green]")
373
+ result = client.post("/api/kpoint-analysis/", data=data)
374
+ console.print(f"[green]Created analysis with ID: {result['id']}[/green]")
372
375
 
373
376
 
374
377
  @kpoint_group.command()
@@ -0,0 +1,407 @@
1
+ from pathlib import Path
2
+ from typing import Optional
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.commands.helpers import format_datetime, get_status_string
10
+ from atomict.cli.core.client import get_client
11
+ from atomict.cli.core.utils import get_pagination_info
12
+
13
+ console = Console()
14
+
15
+
16
+ PSEUDO_LIBRARY_CHOICES = ["efficiency", "precision", "sg15_oncv"]
17
+ EXECUTABLE_CHOICES = ["pw.x", "dos.x", "projwfc.x", "bands.x"]
18
+
19
+
20
+ def _read_input_file(input_file: Optional[str], input_path: Optional[str]) -> str:
21
+ """Resolve the QE input file content from either an inline string or a path."""
22
+ if input_file and input_path:
23
+ raise click.UsageError(
24
+ "Provide either --input-file or --input-path, not both"
25
+ )
26
+ if input_path:
27
+ path = Path(input_path)
28
+ if not path.is_file():
29
+ raise click.UsageError(f"Input file not found: {input_path}")
30
+ return path.read_text()
31
+ if input_file:
32
+ return input_file
33
+ raise click.UsageError("One of --input-file or --input-path is required")
34
+
35
+
36
+ @click.group(name="qe")
37
+ def qe_group():
38
+ """Manage Quantum ESPRESSO simulations"""
39
+ pass
40
+
41
+
42
+ @qe_group.command()
43
+ @click.argument("id", required=False)
44
+ @click.option("--search", help="Search term")
45
+ @click.option("--ordering", help="Field to order results by")
46
+ @click.option(
47
+ "--filter", "filters", multiple=True, help="Filter in format field=value"
48
+ )
49
+ @click.option("--project", help="Filter by project ID")
50
+ @click.option(
51
+ "--include-results",
52
+ is_flag=True,
53
+ help="Include parsed results (atoms, pwscf, dos, ...) when fetching a single sim",
54
+ )
55
+ @click.option("--json-output", is_flag=True, help="Output in JSON format")
56
+ @click.option("--all", "fetch_all", is_flag=True, help="Fetch all results")
57
+ def get(
58
+ id: Optional[str] = None,
59
+ search: Optional[str] = None,
60
+ ordering: Optional[str] = None,
61
+ filters: tuple = (),
62
+ project: Optional[str] = None,
63
+ include_results: bool = False,
64
+ json_output: bool = False,
65
+ fetch_all: bool = False,
66
+ ):
67
+ """Get QE simulation details or list all simulations"""
68
+ client = get_client()
69
+
70
+ if id:
71
+ params = {}
72
+ if include_results:
73
+ params["include_results"] = "true"
74
+ simulation = client.get(f"/api/qe-simulation/{id}/", params=params)
75
+ if json_output:
76
+ console.print_json(data=simulation)
77
+ return
78
+
79
+ console.print(Panel("[bold]Quantum ESPRESSO Simulation[/bold]"))
80
+ console.print(f"ID: {simulation['id']}")
81
+ console.print(f"Name: {simulation.get('name', 'N/A')}")
82
+ console.print(f"Description: {simulation.get('description', 'N/A')}")
83
+ console.print(f"Executable: {simulation.get('executable', 'N/A')}")
84
+ console.print(
85
+ f"Pseudo library: {simulation.get('pseudopotential_library', 'N/A')}"
86
+ )
87
+ console.print(f"Calc type: {simulation.get('calc_type', 'N/A')}")
88
+ console.print(
89
+ f"Convergence achieved: {simulation.get('convergence_achieved', 'N/A')}"
90
+ )
91
+ console.print(f"Created: {format_datetime(simulation.get('created_at'))}")
92
+ if simulation.get("task"):
93
+ status = get_status_string(simulation["task"].get("status"))
94
+ console.print(f"Status: {status}")
95
+ return
96
+
97
+ params = {}
98
+ if search:
99
+ params["search"] = search
100
+ if ordering:
101
+ params["ordering"] = ordering
102
+ if project:
103
+ params["task__project"] = project
104
+
105
+ for f in filters:
106
+ try:
107
+ field, value = f.split("=", 1)
108
+ params[field] = value
109
+ except ValueError:
110
+ click.echo(f"Invalid filter format: {f}. Use field=value", err=True)
111
+ return
112
+
113
+ if fetch_all:
114
+ results = client.get_all("/api/qe-simulation/", params=params)
115
+ else:
116
+ results = client.get("/api/qe-simulation/", params=params)
117
+
118
+ if json_output:
119
+ console.print_json(data=results)
120
+ return
121
+
122
+ columns = [
123
+ ("ID", "id", None),
124
+ ("Name", "name", None),
125
+ ("Executable", "executable", None),
126
+ ("Created", "created_at", format_datetime),
127
+ (
128
+ "Status",
129
+ "task",
130
+ lambda x: get_status_string(
131
+ x.get("status") if isinstance(x, dict) else None
132
+ ),
133
+ ),
134
+ ]
135
+
136
+ items, footer_string = get_pagination_info(results)
137
+
138
+ if not items:
139
+ console.print(
140
+ f"[white]No simulations found with the given criteria:[/white]\n[green]{params}"
141
+ )
142
+ return
143
+
144
+ table = create_table(
145
+ columns=columns,
146
+ items=items,
147
+ title="Quantum ESPRESSO Simulations",
148
+ caption=footer_string,
149
+ )
150
+ console.print(table)
151
+
152
+
153
+ @qe_group.command()
154
+ @click.option("--project", required=True, help="Project ID to create the simulation in")
155
+ @click.option("--name", help="Simulation name")
156
+ @click.option("--description", help="Simulation description")
157
+ @click.option(
158
+ "--input-file",
159
+ help="Inline QE input file content (use --input-path for a file on disk)",
160
+ )
161
+ @click.option(
162
+ "--input-path",
163
+ type=click.Path(exists=True, dir_okay=False, readable=True),
164
+ help="Path to a QE input file (.in / .pwi) to read",
165
+ )
166
+ @click.option(
167
+ "--executable",
168
+ type=click.Choice(EXECUTABLE_CHOICES),
169
+ help="Override the QE executable (auto-derived from input if omitted)",
170
+ )
171
+ @click.option(
172
+ "--pseudo-library",
173
+ type=click.Choice(PSEUDO_LIBRARY_CHOICES),
174
+ help=(
175
+ "Public pseudopotential library to auto-fetch (efficiency, precision, "
176
+ "sg15_oncv). Omit to attach UPFs yourself via qe-simulation-file."
177
+ ),
178
+ )
179
+ @click.option(
180
+ "--parent-simulation",
181
+ help="Parent QE simulation ID (e.g. SCF parent for an NSCF/bands run)",
182
+ )
183
+ @click.option(
184
+ "--cluster",
185
+ "k8s_cluster",
186
+ help="K8s cluster ID to deploy to (required for --launch unless --batch-config is set)",
187
+ )
188
+ @click.option(
189
+ "--batch-config",
190
+ help="GCP batch config ID to deploy to (required for --launch unless --cluster is set)",
191
+ )
192
+ @click.option(
193
+ "--launch",
194
+ is_flag=True,
195
+ help="Immediately launch the simulation after creating it (default: DRAFT)",
196
+ )
197
+ @click.option("--json-output", is_flag=True, help="Output created simulation as JSON")
198
+ def create(
199
+ project: str,
200
+ name: Optional[str],
201
+ description: Optional[str],
202
+ input_file: Optional[str],
203
+ input_path: Optional[str],
204
+ executable: Optional[str],
205
+ pseudo_library: Optional[str],
206
+ parent_simulation: Optional[str],
207
+ k8s_cluster: Optional[str],
208
+ batch_config: Optional[str],
209
+ launch: bool,
210
+ json_output: bool,
211
+ ):
212
+ """Create (and optionally launch) a Quantum ESPRESSO simulation"""
213
+ content = _read_input_file(input_file, input_path)
214
+
215
+ if launch and not (k8s_cluster or batch_config):
216
+ raise click.UsageError(
217
+ "--launch requires --cluster (k8s) or --batch-config (GCP)"
218
+ )
219
+
220
+ data = {
221
+ "project": project,
222
+ "input_file": content,
223
+ "action": "LAUNCH" if launch else "DRAFT",
224
+ }
225
+ if name:
226
+ data["name"] = name
227
+ if description:
228
+ data["description"] = description
229
+ if executable:
230
+ data["executable"] = executable
231
+ if pseudo_library:
232
+ data["pseudopotential_library"] = pseudo_library
233
+ if parent_simulation:
234
+ data["parent_simulation"] = parent_simulation
235
+ if k8s_cluster:
236
+ data["task__k8s_cluster"] = k8s_cluster
237
+ if batch_config:
238
+ data["task__batch_config"] = batch_config
239
+
240
+ client = get_client()
241
+ simulation = client.post("/api/qe-simulation/", data=data)
242
+
243
+ if json_output:
244
+ console.print_json(data=simulation)
245
+ return
246
+
247
+ verb = "Launched" if launch else "Created"
248
+ console.print(
249
+ f"[green]{verb} QE simulation with ID: {simulation['id']}[/green]"
250
+ )
251
+
252
+
253
+ @qe_group.command()
254
+ @click.argument("id")
255
+ @click.option(
256
+ "--cluster",
257
+ "k8s_cluster",
258
+ help="K8s cluster ID to deploy to (required unless --batch-config is set or the sim already has one)",
259
+ )
260
+ @click.option(
261
+ "--batch-config",
262
+ help="GCP batch config ID to deploy to (required unless --cluster is set or the sim already has one)",
263
+ )
264
+ @click.option("--json-output", is_flag=True, help="Output updated simulation as JSON")
265
+ def launch(
266
+ id: str,
267
+ k8s_cluster: Optional[str],
268
+ batch_config: Optional[str],
269
+ json_output: bool,
270
+ ):
271
+ """Launch an existing draft QE simulation"""
272
+ data = {"action": "LAUNCH"}
273
+ if k8s_cluster:
274
+ data["task__k8s_cluster"] = k8s_cluster
275
+ if batch_config:
276
+ data["task__batch_config"] = batch_config
277
+
278
+ client = get_client()
279
+ simulation = client.patch(f"/api/qe-simulation/{id}/", data=data)
280
+
281
+ if json_output:
282
+ console.print_json(data=simulation)
283
+ return
284
+
285
+ console.print(f"[green]Launched QE simulation {id}[/green]")
286
+
287
+
288
+ @qe_group.command()
289
+ @click.argument("id")
290
+ def delete(id: str):
291
+ """Delete a QE simulation"""
292
+ client = get_client()
293
+ client.delete(f"/api/qe-simulation/{id}/")
294
+ console.print(f"[green]Deleted QE simulation {id}[/green]")
295
+
296
+
297
+ @qe_group.command(name="get-files")
298
+ @click.argument("id", required=False)
299
+ @click.option("--simulation", help="Filter files by parent simulation ID")
300
+ @click.option("--search", help="Search term")
301
+ @click.option("--ordering", help="Field to order results by")
302
+ @click.option(
303
+ "--filter", "filters", multiple=True, help="Filter in format field=value"
304
+ )
305
+ @click.option("--json-output", is_flag=True, help="Output in JSON format")
306
+ @click.option("--all", "fetch_all", is_flag=True, help="Fetch all results")
307
+ def get_files(
308
+ id: Optional[str] = None,
309
+ simulation: Optional[str] = None,
310
+ search: Optional[str] = None,
311
+ ordering: Optional[str] = None,
312
+ filters: tuple = (),
313
+ json_output: bool = False,
314
+ fetch_all: bool = False,
315
+ ):
316
+ """Get QE simulation file details or list all simulation files"""
317
+ client = get_client()
318
+
319
+ if id:
320
+ file = client.get(f"/api/qe-simulation-file/{id}/")
321
+ if json_output:
322
+ console.print_json(data=file)
323
+ return
324
+
325
+ console.print(f"ID: {file['id']}")
326
+ sim = file.get("simulation") or {}
327
+ console.print(f"Simulation ID: {sim.get('id', 'N/A')}")
328
+ if file.get("user_upload"):
329
+ uu = file["user_upload"]
330
+ console.print(f"File Name: {uu.get('users_name', 'N/A')}")
331
+ console.print(f"Original Name: {uu.get('orig_name', 'N/A')}")
332
+ console.print(f"Size: {uu.get('size', 'N/A')} bytes")
333
+ console.print(f"Uploaded: {format_datetime(uu.get('uploaded'))}")
334
+ if uu.get("users_description"):
335
+ console.print(f"Description: {uu['users_description']}")
336
+ return
337
+
338
+ params = {}
339
+ if simulation:
340
+ params["simulation_uuid"] = simulation
341
+ if search:
342
+ params["search"] = search
343
+ if ordering:
344
+ params["ordering"] = ordering
345
+
346
+ for f in filters:
347
+ try:
348
+ field, value = f.split("=", 1)
349
+ params[field] = value
350
+ except ValueError:
351
+ click.echo(f"Invalid filter format: {f}. Use field=value", err=True)
352
+ return
353
+
354
+ if fetch_all:
355
+ results = client.get_all("/api/qe-simulation-file/", params=params)
356
+ else:
357
+ results = client.get("/api/qe-simulation-file/", params=params)
358
+
359
+ if json_output:
360
+ console.print_json(data=results)
361
+ return
362
+
363
+ columns = [
364
+ ("ID", "id", None),
365
+ (
366
+ "Simulation",
367
+ "simulation",
368
+ lambda x: x.get("id") if isinstance(x, dict) else None,
369
+ ),
370
+ (
371
+ "Original Name",
372
+ "user_upload",
373
+ lambda x: x.get("orig_name") if isinstance(x, dict) else None,
374
+ ),
375
+ (
376
+ "Size (bytes)",
377
+ "user_upload",
378
+ lambda x: (
379
+ str(x.get("size"))
380
+ if isinstance(x, dict) and x.get("size") is not None
381
+ else None
382
+ ),
383
+ ),
384
+ (
385
+ "Uploaded",
386
+ "user_upload",
387
+ lambda x: (
388
+ format_datetime(x.get("uploaded")) if isinstance(x, dict) else None
389
+ ),
390
+ ),
391
+ ]
392
+
393
+ items, footer_string = get_pagination_info(results)
394
+
395
+ if not items:
396
+ console.print(
397
+ f"[white]No simulation files found with the given criteria:[/white]\n[green]{params}"
398
+ )
399
+ return
400
+
401
+ table = create_table(
402
+ columns=columns,
403
+ items=items,
404
+ title="Quantum ESPRESSO Simulation Files",
405
+ caption=footer_string,
406
+ )
407
+ console.print(table)
@@ -111,10 +111,15 @@ def get(
111
111
 
112
112
  columns = [
113
113
  ("ID", "id", None),
114
- ("Project name", "project", lambda x: x.get("name", "N/A")),
114
+ (
115
+ "Project",
116
+ "project",
117
+ lambda x: (
118
+ x.get("name", "N/A") if isinstance(x, dict) else (x or "N/A")
119
+ ),
120
+ ),
115
121
  ("Progress", "progress", None),
116
122
  ("Status", "status", get_status_string),
117
- ("Error", "error", None),
118
123
  ("Created", "created_at", format_datetime),
119
124
  ]
120
125
 
@@ -139,7 +144,7 @@ def get(
139
144
  def get_status_history(task_id: str, json_output: bool = False):
140
145
  """Get status history for a task"""
141
146
  client = get_client()
142
- results = client.get("/api/task-status-history/", params={"id": task_id})
147
+ results = client.get("/api/task-status-history/", params={"task": task_id})
143
148
 
144
149
  if json_output:
145
150
  console.print_json(data=results)
atomict/cli/main.py CHANGED
@@ -10,7 +10,7 @@ from atomict.__version__ import __version__
10
10
  from atomict.cli.commands import login, token, user, workspace
11
11
  from .commands import k8s, project, task, traj, upload, convert
12
12
  from .commands.exploration import soec, sqs
13
- from .commands.simulation import fhiaims, kpoint
13
+ from .commands.simulation import fhiaims, kpoint, qe
14
14
 
15
15
 
16
16
  console = Console()
@@ -97,6 +97,7 @@ cli.add_command(project.project_group)
97
97
  cli.add_command(k8s.k8s_group)
98
98
  cli.add_command(fhiaims.fhiaims_group)
99
99
  cli.add_command(kpoint.kpoint_group)
100
+ cli.add_command(qe.qe_group)
100
101
  cli.add_command(sqs.sqs_group)
101
102
  cli.add_command(soec.soecexploration_group)
102
103
  cli.add_command(traj.traj)
@@ -19,22 +19,29 @@ class TaskStatus(Enum):
19
19
  USER_ABORTED = 6
20
20
 
21
21
 
22
- def get_task(task_id: str):
23
- return get(f"api/tasks/{task_id}/")
22
+ def get_task(task_id: str, *, api_root: str = None, token: str = None):
23
+ return get(f"api/tasks/{task_id}/", api_root=api_root, token=token)
24
24
 
25
25
 
26
- def task_should_abort(task_id: str) -> bool:
27
- task = get_task(task_id)
26
+ def task_should_abort(task_id: str, *, api_root: str = None, token: str = None) -> bool:
27
+ task = get_task(task_id, api_root=api_root, token=token)
28
28
  return task["user_aborted_flag"]
29
29
 
30
30
 
31
- def except_on_user_abort(task_id: str):
32
- if task_should_abort(task_id):
31
+ def except_on_user_abort(task_id: str, *, api_root: str = None, token: str = None):
32
+ if task_should_abort(task_id, api_root=api_root, token=token):
33
33
  raise UserTaskAbortException(f"User aborted task {task_id}")
34
34
 
35
35
 
36
36
  def update_task_status(
37
- task_id: str, status: TaskStatus = None, error_msg: str = None, percent: int = None, progress_indeterminate: bool = None
37
+ task_id: str,
38
+ status: TaskStatus = None,
39
+ error_msg: str = None,
40
+ percent: int = None,
41
+ progress_indeterminate: bool = None,
42
+ *,
43
+ api_root: str = None,
44
+ token: str = None,
38
45
  ):
39
46
  payload = {}
40
47
 
@@ -50,5 +57,5 @@ def update_task_status(
50
57
  if progress_indeterminate is not None:
51
58
  payload["progress_indeterminate"] = progress_indeterminate
52
59
 
53
- res = patch(f"api/tasks/{task_id}/", payload=payload)
60
+ res = patch(f"api/tasks/{task_id}/", payload=payload, api_root=api_root, token=token)
54
61
  return res