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.
- atomict/__version__.py +1 -1
- atomict/api.py +30 -26
- atomict/cli/commands/exploration/soec.py +97 -61
- atomict/cli/commands/exploration/sqs.py +37 -23
- atomict/cli/commands/k8s.py +3 -3
- atomict/cli/commands/project.py +21 -17
- atomict/cli/commands/simulation/fhiaims.py +1 -19
- atomict/cli/commands/simulation/kpoint.py +24 -21
- atomict/cli/commands/simulation/qe.py +407 -0
- atomict/cli/commands/task.py +8 -3
- atomict/cli/main.py +2 -1
- atomict/infra/distwork/task.py +15 -8
- atomict/infra/logging.py +19 -9
- atomict/simulation/ea.py +35 -13
- atomict/simulation/fhi_aims.py +18 -7
- atomict/simulation/kpoint.py +39 -15
- atomict/simulation/mlrelax.py +19 -10
- atomict/simulation/qe.py +1 -1
- atomict/simulation/utils.py +42 -34
- atomict/user/files.py +11 -5
- atomict/user/workspace.py +30 -7
- {atomict-1.2.25.dist-info → atomict-1.2.27.dist-info}/METADATA +1 -1
- {atomict-1.2.25.dist-info → atomict-1.2.27.dist-info}/RECORD +27 -27
- {atomict-1.2.25.dist-info → atomict-1.2.27.dist-info}/WHEEL +1 -1
- atomict/simulation/mattergen.py +0 -20
- {atomict-1.2.25.dist-info → atomict-1.2.27.dist-info}/entry_points.txt +0 -0
- {atomict-1.2.25.dist-info → atomict-1.2.27.dist-info}/licenses/LICENSE +0 -0
- {atomict-1.2.25.dist-info → atomict-1.2.27.dist-info}/top_level.txt +0 -0
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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"%(
|
|
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/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(
|
|
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
|
)
|
atomict/simulation/fhi_aims.py
CHANGED
|
@@ -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,
|
|
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
|
atomict/simulation/kpoint.py
CHANGED
|
@@ -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,
|
|
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
|
atomict/simulation/mlrelax.py
CHANGED
|
@@ -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(
|
|
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/?
|
|
73
|
+
result = get(f"api/qe-simulation-file/?simulation_uuid={simulation_id}")
|
|
74
74
|
return result
|
atomict/simulation/utils.py
CHANGED
|
@@ -16,29 +16,43 @@ from atomict.user.files import download_file
|
|
|
16
16
|
from atomict.user.workspace import download_workspace
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
def
|
|
20
|
-
if
|
|
19
|
+
def _read_geometry_file(filepath: str, extension: str) -> Atoms:
|
|
20
|
+
if extension == "atraj":
|
|
21
|
+
atoms, _ = read_atraj(filepath)
|
|
22
|
+
elif extension == "tess":
|
|
23
|
+
atoms, _ = read_tess(filepath)
|
|
24
|
+
else:
|
|
25
|
+
atoms = read(filepath)
|
|
26
|
+
|
|
27
|
+
if isinstance(atoms, list):
|
|
28
|
+
return atoms[-1]
|
|
29
|
+
return atoms
|
|
21
30
|
|
|
31
|
+
|
|
32
|
+
def fetch_source_geometry(sim: dict, workbench_dir: str, *, api_root: str = None, token: str = None) -> Atoms:
|
|
33
|
+
if sim.get("source_geometry"):
|
|
22
34
|
extension = sim["source_geometry"]["orig_name"].split(".")[-1]
|
|
35
|
+
filepath = workbench_dir + f"/geometry.{extension}"
|
|
36
|
+
download_file(sim["source_geometry"]["id"], filepath, api_root=api_root, token=token)
|
|
37
|
+
return _read_geometry_file(filepath, extension)
|
|
38
|
+
else:
|
|
39
|
+
raise ValueError("No associated input geometry found (simulation.source_geometry)")
|
|
23
40
|
|
|
24
|
-
download_file(sim["source_geometry"]["id"], workbench_dir + f"/geometry.{extension}")
|
|
25
|
-
|
|
26
|
-
if extension == "atraj":
|
|
27
|
-
atoms, _ = read_atraj(workbench_dir + f"/geometry.{extension}")
|
|
28
|
-
elif extension == "tess":
|
|
29
|
-
atoms, _ = read_tess(workbench_dir + f"/geometry.{extension}")
|
|
30
|
-
else:
|
|
31
|
-
atoms = read(workbench_dir + f"/geometry.{extension}")
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
def get_source_geometry(sim: dict, workbench_dir: str, *, api_root: str = None, token: str = None) -> Atoms:
|
|
43
|
+
"""Return the source geometry, reading from disk if already present."""
|
|
44
|
+
if sim.get("source_geometry"):
|
|
45
|
+
extension = sim["source_geometry"]["orig_name"].split(".")[-1]
|
|
46
|
+
filepath = workbench_dir + f"/geometry.{extension}"
|
|
47
|
+
if os.path.exists(filepath):
|
|
48
|
+
logging.info(f"Source geometry already on disk, skipping download: {filepath}")
|
|
49
|
+
return _read_geometry_file(filepath, extension)
|
|
50
|
+
return fetch_source_geometry(sim, workbench_dir, api_root=api_root, token=token)
|
|
37
51
|
else:
|
|
38
|
-
raise ValueError("No input geometry found")
|
|
52
|
+
raise ValueError("No associated input geometry found (simulation.source_geometry)")
|
|
39
53
|
|
|
40
54
|
|
|
41
|
-
def fetch_relaxed_geometry(sim: dict, workbench_dir: str) -> Atoms:
|
|
55
|
+
def fetch_relaxed_geometry(sim: dict, workbench_dir: str, *, api_root: str = None, token: str = None) -> Atoms:
|
|
42
56
|
|
|
43
57
|
"""
|
|
44
58
|
Fetch the relaxed geometry from the simulation
|
|
@@ -48,9 +62,9 @@ def fetch_relaxed_geometry(sim: dict, workbench_dir: str) -> Atoms:
|
|
|
48
62
|
"""
|
|
49
63
|
|
|
50
64
|
if sim.get("starting_structure"):
|
|
51
|
-
previous_simulation = fhi_get_simulation(sim["starting_structure"]["id"], include_ht=True)
|
|
65
|
+
previous_simulation = fhi_get_simulation(sim["starting_structure"]["id"], include_ht=True, api_root=api_root, token=token)
|
|
52
66
|
logging.info(f"Previous simulation: {previous_simulation['id']}")
|
|
53
|
-
files = fhi_get_simulation_files(previous_simulation["id"])
|
|
67
|
+
files = fhi_get_simulation_files(previous_simulation["id"], api_root=api_root, token=token)
|
|
54
68
|
|
|
55
69
|
total_size = 0
|
|
56
70
|
for file in files["results"]:
|
|
@@ -62,7 +76,7 @@ def fetch_relaxed_geometry(sim: dict, workbench_dir: str) -> Atoms:
|
|
|
62
76
|
|
|
63
77
|
prev_sim_dir = os.path.join(workbench_dir, "previous_simulation")
|
|
64
78
|
os.makedirs(prev_sim_dir, exist_ok=True)
|
|
65
|
-
download_workspace(files["results"], prev_sim_dir)
|
|
79
|
+
download_workspace(files["results"], prev_sim_dir, api_root=api_root, token=token)
|
|
66
80
|
atoms = read_aims_output(
|
|
67
81
|
os.path.join(prev_sim_dir, f"{previous_simulation['id']}.out")
|
|
68
82
|
)
|
|
@@ -71,9 +85,9 @@ def fetch_relaxed_geometry(sim: dict, workbench_dir: str) -> Atoms:
|
|
|
71
85
|
|
|
72
86
|
elif sim.get("starting_structure_mlrelax"):
|
|
73
87
|
|
|
74
|
-
previous_mlrelax = get_mlrelax(sim["starting_structure_mlrelax"]["id"], include_ht=True)
|
|
88
|
+
previous_mlrelax = get_mlrelax(sim["starting_structure_mlrelax"]["id"], include_ht=True, api_root=api_root, token=token)
|
|
75
89
|
logging.info(f"Previous MLRelaxation: {previous_mlrelax['id']}")
|
|
76
|
-
files = get_mlrelax_files(previous_mlrelax["id"])
|
|
90
|
+
files = get_mlrelax_files(previous_mlrelax["id"], api_root=api_root, token=token)
|
|
77
91
|
|
|
78
92
|
total_size = 0
|
|
79
93
|
for file in files["results"]:
|
|
@@ -85,27 +99,21 @@ def fetch_relaxed_geometry(sim: dict, workbench_dir: str) -> Atoms:
|
|
|
85
99
|
|
|
86
100
|
mlrelax_dir = os.path.join(workbench_dir, "previous_mlrelax")
|
|
87
101
|
os.makedirs(mlrelax_dir, exist_ok=True)
|
|
88
|
-
download_workspace(files["results"], mlrelax_dir)
|
|
102
|
+
download_workspace(files["results"], mlrelax_dir, api_root=api_root, token=token)
|
|
89
103
|
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
for ext in ("atraj", "tess", "traj"):
|
|
105
|
+
candidate = os.path.join(mlrelax_dir, f"relax.{ext}")
|
|
106
|
+
if os.path.exists(candidate):
|
|
107
|
+
return _read_geometry_file(candidate, ext)
|
|
92
108
|
|
|
93
|
-
|
|
94
|
-
atoms, _ = read_atraj(atraj_file)
|
|
95
|
-
else:
|
|
96
|
-
atoms = read(traj_file)
|
|
97
|
-
|
|
98
|
-
if isinstance(atoms, list):
|
|
99
|
-
return atoms[-1]
|
|
100
|
-
else:
|
|
101
|
-
return atoms
|
|
109
|
+
raise FileNotFoundError(f"No relaxation output found in {mlrelax_dir}")
|
|
102
110
|
|
|
103
111
|
elif sim.get("starting_structure_userupload"):
|
|
104
112
|
logging.info(f"Previous UserUpload: {sim['starting_structure_userupload']['id']}")
|
|
105
113
|
|
|
106
114
|
extension = sim["starting_structure_userupload"]["orig_name"].split(".")[-1]
|
|
107
115
|
|
|
108
|
-
download_file(sim["starting_structure_userupload"]["id"], workbench_dir + f"/geometry.{extension}")
|
|
116
|
+
download_file(sim["starting_structure_userupload"]["id"], workbench_dir + f"/geometry.{extension}", api_root=api_root, token=token)
|
|
109
117
|
|
|
110
118
|
if extension == "atraj":
|
|
111
119
|
atoms, _ = read_atraj(workbench_dir + f"/geometry.{extension}")
|
atomict/user/files.py
CHANGED
|
@@ -3,8 +3,14 @@ import os
|
|
|
3
3
|
from atomict.api import get, post
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
def upload_single_file(
|
|
7
|
-
|
|
6
|
+
def upload_single_file(
|
|
7
|
+
full_path: str,
|
|
8
|
+
file_name: str = None,
|
|
9
|
+
project_id: str = None,
|
|
10
|
+
*,
|
|
11
|
+
api_root: str = None,
|
|
12
|
+
token: str = None,
|
|
13
|
+
):
|
|
8
14
|
payload = {}
|
|
9
15
|
|
|
10
16
|
if file_name:
|
|
@@ -16,12 +22,12 @@ def upload_single_file(full_path: str, file_name: str = None, project_id: str =
|
|
|
16
22
|
payload['project_id'] = project_id
|
|
17
23
|
|
|
18
24
|
with open(full_path, "rb") as f:
|
|
19
|
-
result = post("user/file_upload/", files={file_name: f}, payload=payload)
|
|
25
|
+
result = post("user/file_upload/", files={file_name: f}, payload=payload, api_root=api_root, token=token)
|
|
20
26
|
return result
|
|
21
27
|
|
|
22
28
|
|
|
23
|
-
def download_file(user_upload_id: str, destination_path: str):
|
|
24
|
-
content = get(f"user/file_upload_get/{user_upload_id}/")
|
|
29
|
+
def download_file(user_upload_id: str, destination_path: str, *, api_root: str = None, token: str = None):
|
|
30
|
+
content = get(f"user/file_upload_get/{user_upload_id}/", api_root=api_root, token=token)
|
|
25
31
|
|
|
26
32
|
# Write the content to the destination path
|
|
27
33
|
# if there's a directory path in the destination path, create the directory
|