atomict 1.2.24__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.
atomict/cli/main.py CHANGED
@@ -7,10 +7,10 @@ import click
7
7
  from rich.console import Console
8
8
 
9
9
  from atomict.__version__ import __version__
10
- from atomict.cli.commands import login, token, user
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,10 +97,12 @@ 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)
103
104
  cli.add_command(user.user_group)
105
+ cli.add_command(workspace.workspace_group)
104
106
  cli.add_command(login._login)
105
107
  cli.add_command(token._token)
106
108
 
@@ -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
atomict/infra/logging.py CHANGED
@@ -79,7 +79,8 @@ class LokiHandler(logging.Handler):
79
79
 
80
80
  try:
81
81
  item = self.queue.get(timeout=timeout)
82
- batch.append(item)
82
+ if item is not None: # Skip sentinel values
83
+ batch.append(item)
83
84
  except:
84
85
  pass # Queue.get timed out
85
86
 
@@ -94,9 +95,7 @@ class LokiHandler(logging.Handler):
94
95
  if batch:
95
96
  self._send_batch(batch)
96
97
  batch = []
97
- else:
98
- pass
99
- last_flush = time.time() # Update last_flush even if batch was empty
98
+ last_flush = time.time()
100
99
 
101
100
  except Exception as e:
102
101
  # Log to stderr to avoid recursion
@@ -105,6 +104,10 @@ class LokiHandler(logging.Handler):
105
104
  import traceback
106
105
  traceback.print_exc()
107
106
 
107
+ # Flush final batch before exiting
108
+ if batch:
109
+ self._send_batch(batch)
110
+
108
111
  except Exception as e:
109
112
  import sys
110
113
  print(f"[LokiHandler._worker] FATAL ERROR in worker thread: {e}", file=sys.stderr)
@@ -154,18 +157,25 @@ class LokiHandler(logging.Handler):
154
157
  """Flush remaining logs and stop the worker thread"""
155
158
 
156
159
  self.stop_event.set()
157
- # Flush any remaining logs
160
+
161
+ # Put a sentinel value to wake up the worker if it's blocked in queue.get()
162
+ self.queue.put(None)
163
+
164
+ # Wait for worker to finish - it should now wake up and exit
165
+ self.worker_thread.join(timeout=2)
166
+
167
+ # Flush any remaining logs from queue (in case worker exited before processing them)
158
168
  remaining = []
159
169
  while not self.queue.empty():
160
170
  try:
161
- remaining.append(self.queue.get_nowait())
171
+ item = self.queue.get_nowait()
172
+ if item is not None: # Skip sentinel values
173
+ remaining.append(item)
162
174
  except:
163
175
  break
164
176
  if remaining:
165
177
  self._send_batch(remaining)
166
178
 
167
- # Wait for worker to finish
168
- self.worker_thread.join(timeout=1)
169
179
  super().close()
170
180
 
171
181
 
@@ -216,7 +226,7 @@ def config_loggers(
216
226
  batch_size=batch_size,
217
227
  flush_interval=flush_interval,
218
228
  )
219
- loki_handler.setFormatter(logging.Formatter(f"%(levelname)s %(asctime)s {prefix} %(message)s"))
229
+ loki_handler.setFormatter(logging.Formatter(f"%(asctime)s %(levelname)s {prefix} %(message)s"))
220
230
 
221
231
  # Add to root logger
222
232
  logging.getLogger().addHandler(loki_handler)
atomict/io/trajectory.py CHANGED
@@ -123,7 +123,25 @@ class TrajectoryWriter:
123
123
  raise TypeError('Unsupported atoms-like object; expected ASE Atoms or compatible wrapper')
124
124
  plain = Atoms(numbers=numbers, positions=positions, cell=cell, pbc=pbc)
125
125
  # Make a copy to avoid all frames pointing to the same object after in-place modifications
126
- self._buffer.append(plain.copy())
126
+ copied = plain.copy()
127
+
128
+ # Preserve calculator results using SinglePointCalculator
129
+ # (ASE's Atoms.copy() intentionally does not copy the calculator)
130
+ if plain.calc is not None:
131
+ from ase.calculators.singlepoint import SinglePointCalculator
132
+
133
+ results = {}
134
+ for prop in ['energy', 'forces', 'stress', 'dipole', 'charges', 'magmom', 'magmoms']:
135
+ try:
136
+ val = plain.calc.get_property(prop, plain, allow_calculation=False)
137
+ if val is not None:
138
+ results[prop] = val
139
+ except Exception:
140
+ pass
141
+ if results:
142
+ copied.calc = SinglePointCalculator(copied, **results)
143
+
144
+ self._buffer.append(copied)
127
145
 
128
146
  def close(self) -> None:
129
147
  """Flush buffered frames and/or close backend."""
atomict/simulation/ea.py CHANGED
@@ -1,83 +1,100 @@
1
1
  from atomict.api import get, post
2
2
 
3
3
 
4
- def get_ea_exploration(exploration_id: str, **params):
4
+ def get_ea_exploration(exploration_id: str, *, api_root: str = None, token: str = None, **params):
5
5
  """
6
6
  Get EA exploration
7
7
 
8
8
  Args:
9
9
  exploration_id: str - The ID of the exploration
10
+ api_root: str - Optional API root URL (defaults to AT_SERVER env var)
11
+ token: str - Optional API token (defaults to AT_TOKEN env var)
10
12
  **params: Additional GET parameters to pass to the API
11
13
  """
12
14
  query_string = '&'.join(f"{k}={v}" for k, v in params.items())
13
15
  base_url = f"api/ea-exploration/{exploration_id}/"
14
16
  url = f"{base_url}?{query_string}" if query_string else base_url
15
- return get(url)
17
+ return get(url, api_root=api_root, token=token)
16
18
 
17
19
 
18
- def get_ea_exploration_sample(sample_id: str, **params):
20
+ def get_ea_exploration_sample(sample_id: str, *, api_root: str = None, token: str = None, **params):
19
21
  """
20
22
  Get EA exploration sample
21
23
 
22
24
  Args:
23
25
  sample_id: str - The ID of the sample
26
+ api_root: str - Optional API root URL (defaults to AT_SERVER env var)
27
+ token: str - Optional API token (defaults to AT_TOKEN env var)
24
28
  **params: Additional GET parameters to pass to the API
25
29
  """
26
30
  query_string = '&'.join(f"{k}={v}" for k, v in params.items())
27
31
  base_url = f"api/ea-exploration-sample/{sample_id}/"
28
32
  url = f"{base_url}?{query_string}" if query_string else base_url
29
- return get(url)
33
+ return get(url, api_root=api_root, token=token)
30
34
 
31
35
 
32
- def get_ea_exploration_samples(exploration_id: str, **params):
36
+ def get_ea_exploration_samples(exploration_id: str, *, api_root: str = None, token: str = None, **params):
33
37
  """
34
38
  Get EA exploration samples
35
39
 
36
40
  Args:
37
41
  exploration_id: str - The ID of the exploration
42
+ api_root: str - Optional API root URL (defaults to AT_SERVER env var)
43
+ token: str - Optional API token (defaults to AT_TOKEN env var)
38
44
  **params: Additional GET parameters to pass to the API
39
45
  """
40
- # Start with the required exploration parameter
41
46
  query_params = params.copy()
42
47
  query_params['exploration'] = exploration_id
43
-
48
+
44
49
  query_string = '&'.join(f"{k}={v}" for k, v in query_params.items())
45
50
  url = f"api/ea-exploration-sample/?{query_string}"
46
- return get(url)
51
+ return get(url, api_root=api_root, token=token)
47
52
 
48
53
 
49
- def get_ea_exploration_analysis(analysis_id: str, **params):
54
+ def get_ea_exploration_analysis(analysis_id: str, *, api_root: str = None, token: str = None, **params):
50
55
  """
51
56
  Get EA exploration analysis
52
57
 
53
58
  Args:
54
59
  analysis_id: str - The ID of the analysis
60
+ api_root: str - Optional API root URL (defaults to AT_SERVER env var)
61
+ token: str - Optional API token (defaults to AT_TOKEN env var)
55
62
  **params: Additional GET parameters to pass to the API
56
63
  """
57
64
  query_string = '&'.join(f"{k}={v}" for k, v in params.items())
58
65
  base_url = f"api/ea-exploration-analysis/{analysis_id}/"
59
66
  url = f"{base_url}?{query_string}" if query_string else base_url
60
- return get(url)
67
+ return get(url, api_root=api_root, token=token)
61
68
 
62
69
 
63
- def get_ea_exploration_analysis_file(analysis_file_id: str, **params):
70
+ def get_ea_exploration_analysis_file(analysis_file_id: str, *, api_root: str = None, token: str = None, **params):
64
71
  """
65
72
  Get EA exploration analysis file
66
73
 
67
74
  Args:
68
75
  analysis_file_id: str - The ID of the analysis file
76
+ api_root: str - Optional API root URL (defaults to AT_SERVER env var)
77
+ token: str - Optional API token (defaults to AT_TOKEN env var)
69
78
  **params: Additional GET parameters to pass to the API
70
79
  """
71
80
  query_string = '&'.join(f"{k}={v}" for k, v in params.items())
72
81
  base_url = f"api/ea-exploration-analysis-file/{analysis_file_id}/"
73
82
  url = f"{base_url}?{query_string}" if query_string else base_url
74
- return get(url)
83
+ return get(url, api_root=api_root, token=token)
75
84
 
76
85
 
77
- def associate_user_upload_with_ea_exploration(user_upload_id: str, analysis_id: str):
86
+ def associate_user_upload_with_ea_exploration(
87
+ user_upload_id: str,
88
+ analysis_id: str,
89
+ *,
90
+ api_root: str = None,
91
+ token: str = None,
92
+ ):
78
93
  return post(
79
94
  "api/ea-exploration-analysis-file/",
80
95
  payload={"user_upload_id": user_upload_id, "analysis_id": analysis_id},
96
+ api_root=api_root,
97
+ token=token,
81
98
  )
82
99
 
83
100
 
@@ -87,6 +104,9 @@ def create_exploration_sample(
87
104
  mlrelax_id: str = None,
88
105
  strain: float = None,
89
106
  matrix: int = None,
107
+ *,
108
+ api_root: str = None,
109
+ token: str = None,
90
110
  ):
91
111
  """
92
112
  Create an exploration sample
@@ -114,4 +134,6 @@ def create_exploration_sample(
114
134
  return post(
115
135
  "api/ea-exploration-sample/",
116
136
  payload=payload,
137
+ api_root=api_root,
138
+ token=token,
117
139
  )
@@ -10,6 +10,9 @@ def create_simulation(
10
10
  name: str = None,
11
11
  description: str = None,
12
12
  extra_simulation_kwargs: dict = None,
13
+ *,
14
+ api_root: str = None,
15
+ token: str = None,
13
16
  ) -> dict:
14
17
 
15
18
  if action not in [SimulationAction.SAVE_DRAFT, SimulationAction.LAUNCH]:
@@ -31,32 +34,38 @@ def create_simulation(
31
34
  "api/fhiaims-simulation/",
32
35
  payload,
33
36
  extra_headers={"Content-Type": "application/json"},
37
+ api_root=api_root,
38
+ token=token,
34
39
  )
35
40
 
36
41
  return result
37
42
 
38
43
 
39
- def get_simulation(simulation_id: str, **params):
44
+ def get_simulation(simulation_id: str, *, api_root: str = None, token: str = None, **params):
40
45
  """
41
46
  Get a FHI aims simulation
42
47
  """
43
48
  query_string = '&'.join(f"{k}={v}" for k, v in params.items())
44
49
  base_url = f"api/fhiaims-simulation/{simulation_id}/"
45
50
  url = f"{base_url}?{query_string}" if query_string else base_url
46
- result = get(url)
51
+ result = get(url, api_root=api_root, token=token)
47
52
  return result
48
53
 
49
54
 
50
- def delete_simulation(simulation_id):
55
+ def delete_simulation(simulation_id, *, api_root: str = None, token: str = None):
51
56
  """
52
57
  Delete a FHI aims simulation
53
58
  """
54
- result = delete(f"api/fhiaims-simulation/{simulation_id}/")
59
+ result = delete(f"api/fhiaims-simulation/{simulation_id}/", api_root=api_root, token=token)
55
60
  return result
56
61
 
57
62
 
58
63
  def associate_user_upload_with_fhiaims_simulation(
59
- user_upload_id: str, fhi_simulation_id: str
64
+ user_upload_id: str,
65
+ fhi_simulation_id: str,
66
+ *,
67
+ api_root: str = None,
68
+ token: str = None,
60
69
  ):
61
70
  """
62
71
  Associate a user upload with a FHI-aims simulation
@@ -64,13 +73,15 @@ def associate_user_upload_with_fhiaims_simulation(
64
73
  result = post(
65
74
  "api/fhiaims-simulation-file/",
66
75
  payload={"user_upload_id": user_upload_id, "simulation_id": fhi_simulation_id},
76
+ api_root=api_root,
77
+ token=token,
67
78
  )
68
79
  return result
69
80
 
70
81
 
71
- def get_simulation_files(simulation_id: str):
82
+ def get_simulation_files(simulation_id: str, *, api_root: str = None, token: str = None):
72
83
  """
73
84
  Get the files associated with a FHI-aims simulation
74
85
  """
75
- result = get(f"api/fhiaims-simulation-file/?simulation__id={simulation_id}")
86
+ result = get(f"api/fhiaims-simulation-file/?simulation__id={simulation_id}", api_root=api_root, token=token)
76
87
  return result
@@ -1,40 +1,45 @@
1
1
  from atomict.api import get, post, patch
2
2
 
3
3
 
4
- def get_kpoint_exploration(simulation_id: str):
4
+ def get_kpoint_exploration(simulation_id: str, *, api_root: str = None, token: str = None):
5
5
  """
6
6
  Get kpoints for a simulation
7
7
  """
8
- result = get(f"api/kpoint-exploration/{simulation_id}/")
8
+ result = get(f"api/kpoint-exploration/{simulation_id}/", api_root=api_root, token=token)
9
9
  return result
10
10
 
11
11
 
12
- def update_kpoint_exploration(exploration_id: str, fields: dict):
12
+ def update_kpoint_exploration(exploration_id: str, fields: dict, *, api_root: str = None, token: str = None):
13
13
  """
14
14
  Update KPoint exploration
15
15
  """
16
- result = patch(f"api/kpoint-exploration/{exploration_id}/", payload=fields)
16
+ result = patch(f"api/kpoint-exploration/{exploration_id}/", payload=fields, api_root=api_root, token=token)
17
17
  return result
18
18
 
19
19
 
20
- def get_kpoint_simulation_list(exploration_id: str):
20
+ def get_kpoint_simulation_list(exploration_id: str, *, api_root: str = None, token: str = None):
21
21
  """
22
22
  Get kpoints for a simulation
23
23
  """
24
- result = get(f"api/kpoint-simulation/?exploration__id={exploration_id}")
24
+ result = get(f"api/kpoint-simulation/?exploration__id={exploration_id}", api_root=api_root, token=token)
25
25
  return result
26
26
 
27
27
 
28
- def get_kpoint_simulation(simulation_id: str):
28
+ def get_kpoint_simulation(simulation_id: str, *, api_root: str = None, token: str = None):
29
29
  """
30
30
  Get KPoint simulation
31
31
  """
32
- result = get(f"api/kpoint-simulation/{simulation_id}/")
32
+ result = get(f"api/kpoint-simulation/{simulation_id}/", api_root=api_root, token=token)
33
33
  return result
34
34
 
35
35
 
36
36
  def create_kpoint_simulation(
37
- exploration_id: str, simulation_id: str, k_points: list[float]
37
+ exploration_id: str,
38
+ simulation_id: str,
39
+ k_points: list[float],
40
+ *,
41
+ api_root: str = None,
42
+ token: str = None,
38
43
  ):
39
44
  """
40
45
  Create KPoint simulation
@@ -46,29 +51,48 @@ def create_kpoint_simulation(
46
51
  "simulation_id": simulation_id,
47
52
  "k_points": k_points,
48
53
  },
54
+ api_root=api_root,
55
+ token=token,
49
56
  )
50
57
  return result
51
58
 
52
59
 
53
- def update_kpoint_simulation(simulation_id: str, fields: dict):
60
+ def update_kpoint_simulation(simulation_id: str, fields: dict, *, api_root: str = None, token: str = None):
54
61
  """
55
62
  Update KPoint simulation
56
63
  """
57
- result = patch(f"api/kpoint-simulation/{simulation_id}/", payload=fields)
64
+ result = patch(f"api/kpoint-simulation/{simulation_id}/", payload=fields, api_root=api_root, token=token)
58
65
  return result
59
66
 
60
67
 
61
- def get_kpoint_analysis(analysis_id: str):
68
+ def get_kpoint_analysis(analysis_id: str, *, api_root: str = None, token: str = None):
62
69
  """
63
70
  Get KPoint analysis
64
71
  """
65
- result = get(f"api/kpoint-analysis/{analysis_id}/")
72
+ result = get(f"api/kpoint-analysis/{analysis_id}/", api_root=api_root, token=token)
66
73
  return result
67
74
 
68
75
 
69
- def update_kpoint_analysis(analysis_id: str, fields: dict):
76
+ def update_kpoint_analysis(analysis_id: str, fields: dict, *, api_root: str = None, token: str = None):
70
77
  """
71
78
  Update KPoint analysis
72
79
  """
73
- result = patch(f"api/kpoint-analysis/{analysis_id}/", payload=fields)
80
+ result = patch(f"api/kpoint-analysis/{analysis_id}/", payload=fields, api_root=api_root, token=token)
81
+ return result
82
+
83
+
84
+ def delete_kpoint_simulations(exploration_id: str, *, api_root: str = None, token: str = None):
85
+ """Delete all FHIAims simulations linked to the exploration via KPointSimulation.
86
+
87
+ Calls the server-side reset_simulations endpoint which cascade-deletes
88
+ KPointSimulation records by deleting their FHIAimsSimulation parents.
89
+ Safe to call when no simulations exist (returns {"deleted": 0}).
90
+ Used as a saga compensation and as a clean-slate step before retrying Stage 1.
91
+ """
92
+ result = post(
93
+ f"api/kpoint-exploration/{exploration_id}/reset_simulations/",
94
+ payload={},
95
+ api_root=api_root,
96
+ token=token,
97
+ )
74
98
  return result
@@ -8,32 +8,38 @@ COMPUTATION_TYPE_RELAXATION = 0
8
8
  COMPUTATION_TYPE_SINGLE_POINT = 1
9
9
 
10
10
 
11
- def get_mlrelax(id: str, **params):
11
+ def get_mlrelax(id: str, *, api_root: str = None, token: str = None, **params):
12
12
  """
13
13
  Get MLRelaxation
14
14
 
15
15
  Args:
16
16
  id: str - The ID of the MLRelaxation
17
+ api_root: str - Optional API root URL (defaults to AT_SERVER env var)
18
+ token: str - Optional API token (defaults to AT_TOKEN env var)
17
19
  **params: Additional GET parameters to pass to the API
18
20
  """
19
- # Build query string from parameters
20
21
  query_string = '&'.join(f"{k}={v}" for k, v in params.items())
21
22
  base_url = f"api/mlrelax/{id}/"
22
-
23
- # Add query string if we have parameters
24
23
  url = f"{base_url}?{query_string}" if query_string else base_url
25
-
26
- result = get(url)
24
+ result = get(url, api_root=api_root, token=token)
27
25
  return result
28
26
 
29
27
 
30
- def associate_user_upload_with_mlrelaxation(user_upload_id: str, mlrelax_id: str):
28
+ def associate_user_upload_with_mlrelaxation(
29
+ user_upload_id: str,
30
+ mlrelax_id: str,
31
+ *,
32
+ api_root: str = None,
33
+ token: str = None,
34
+ ):
31
35
  """
32
36
  Associate a user upload with a MLRelaxation
33
37
  """
34
38
  result = post(
35
39
  "api/mlrelax-file/",
36
40
  payload={"user_upload_id": user_upload_id, "mlrelax_id": mlrelax_id},
41
+ api_root=api_root,
42
+ token=token,
37
43
  )
38
44
  return result
39
45
 
@@ -49,6 +55,9 @@ def create_mlrelaxation(
49
55
  model: int = MODEL_ESEN_30M_OAM,
50
56
  calculator: Union[int, None] = None,
51
57
  extra_simulation_kwargs: dict = None,
58
+ *,
59
+ api_root: str = None,
60
+ token: str = None,
52
61
  ):
53
62
  """
54
63
  Create a MLRelaxation
@@ -85,13 +94,13 @@ def create_mlrelaxation(
85
94
  if extra_simulation_kwargs:
86
95
  payload.update(extra_simulation_kwargs)
87
96
 
88
- result = post("api/mlrelax/", payload)
97
+ result = post("api/mlrelax/", payload, api_root=api_root, token=token)
89
98
  return result
90
99
 
91
100
 
92
- def get_mlrelax_files(mlrelax_id: str):
101
+ def get_mlrelax_files(mlrelax_id: str, *, api_root: str = None, token: str = None):
93
102
  """
94
103
  Get the files associated with a MLRelaxation
95
104
  """
96
- result = get(f"api/mlrelax-file/?mlrelax__id={mlrelax_id}")
105
+ result = get(f"api/mlrelax-file/?mlrelax__id={mlrelax_id}", api_root=api_root, token=token)
97
106
  return result
atomict/simulation/qe.py CHANGED
@@ -70,5 +70,5 @@ def get_simulation_files(simulation_id: str):
70
70
  """
71
71
  Get the files associated with a Quantum Espresso simulation
72
72
  """
73
- result = get(f"api/qe-simulation-file/?simulation_id={simulation_id}")
73
+ result = get(f"api/qe-simulation-file/?simulation_uuid={simulation_id}")
74
74
  return result