atomict 1.2.16__py3-none-any.whl → 1.2.19__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/ase/atatoms.py +1 -1
- atomict/cli/commands/simulation/kpoint.py +1 -1
- atomict/cli/core/client.py +1 -1
- atomict/cli/ext/custom_classes.py +1 -1
- atomict/cli/main.py +30 -29
- atomict/infra/__init__.py +3 -0
- atomict/infra/distwork/task.py +14 -9
- atomict/io/{msgpack.py → atoms.py} +87 -237
- atomict/io/formats/atraj.py +99 -0
- atomict/io/formats/tess.py +319 -0
- atomict/io/formats/traj.py +62 -0
- atomict/project/project.py +1 -2
- atomict/simulation/fhi_aims.py +5 -4
- atomict/simulation/mlrelax.py +35 -16
- atomict/simulation/models.py +2 -1
- atomict/simulation/qe.py +1 -1
- atomict/simulation/utils.py +3 -3
- atomict/user/files.py +11 -8
- atomict/user/workspace.py +1 -1
- {atomict-1.2.16.dist-info → atomict-1.2.19.dist-info}/METADATA +2 -1
- {atomict-1.2.16.dist-info → atomict-1.2.19.dist-info}/RECORD +26 -24
- atomict/io/trajectory.py +0 -437
- {atomict-1.2.16.dist-info → atomict-1.2.19.dist-info}/WHEEL +0 -0
- {atomict-1.2.16.dist-info → atomict-1.2.19.dist-info}/entry_points.txt +0 -0
- {atomict-1.2.16.dist-info → atomict-1.2.19.dist-info}/licenses/LICENSE +0 -0
- {atomict-1.2.16.dist-info → atomict-1.2.19.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from typing import Union, List, Dict, TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
import ase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def write_atraj(atoms: Union['ase.Atoms', List['ase.Atoms']], filename: str, metadata: Dict = None):
|
|
9
|
+
"""Save atoms to a mpv1 file."""
|
|
10
|
+
|
|
11
|
+
from atomict.io.msgpack import atoms_to_dict
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
import msgpack
|
|
15
|
+
import msgpack_numpy as m
|
|
16
|
+
from ase import Atoms
|
|
17
|
+
except ImportError:
|
|
18
|
+
raise ImportError("You need to install with `pip install atomict[utils]` to use msgpack I/O")
|
|
19
|
+
|
|
20
|
+
# Enable numpy array serialization
|
|
21
|
+
m.patch()
|
|
22
|
+
|
|
23
|
+
# Single atoms case - convert to list
|
|
24
|
+
if isinstance(atoms, Atoms):
|
|
25
|
+
atoms_list = [atoms]
|
|
26
|
+
else:
|
|
27
|
+
atoms_list = atoms
|
|
28
|
+
|
|
29
|
+
# Create container for the trajectory data
|
|
30
|
+
traj_data = {
|
|
31
|
+
'format_version': 1, # Version for future compatibility
|
|
32
|
+
'metadata': metadata or {},
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# Extract properties to dictionary - no selective mode for trajectories
|
|
36
|
+
atoms_data = atoms_to_dict(atoms_list, selective=False)
|
|
37
|
+
|
|
38
|
+
# Add atoms data to the trajectory container
|
|
39
|
+
traj_data['atoms_data'] = atoms_data
|
|
40
|
+
|
|
41
|
+
# Pack and save
|
|
42
|
+
with open(filename, 'wb') as f:
|
|
43
|
+
msgpack.pack(traj_data, f, use_bin_type=True)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def read_atraj(filename: str) -> Union['ase.Atoms', List['ase.Atoms']]:
|
|
47
|
+
|
|
48
|
+
"""Load atoms from a mpv1 file."""
|
|
49
|
+
from atomict.io.msgpack import dict_to_atoms
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
import msgpack
|
|
53
|
+
import msgpack_numpy as m
|
|
54
|
+
except ImportError:
|
|
55
|
+
raise ImportError("You need to install with `pip install atomict[utils]` to use msgpack I/O")
|
|
56
|
+
|
|
57
|
+
# Enable numpy array deserialization
|
|
58
|
+
m.patch()
|
|
59
|
+
|
|
60
|
+
# Load data
|
|
61
|
+
with open(filename, 'rb') as f:
|
|
62
|
+
traj_data = msgpack.unpack(f, raw=False, strict_map_key=True)
|
|
63
|
+
|
|
64
|
+
# Check if this is a new-style trajectory with format_version
|
|
65
|
+
if isinstance(traj_data, dict) and 'format_version' in traj_data:
|
|
66
|
+
metadata = traj_data.get('metadata', {})
|
|
67
|
+
atoms_data = traj_data.get('atoms_data', {})
|
|
68
|
+
else:
|
|
69
|
+
# Legacy format - just raw atoms data
|
|
70
|
+
metadata = {}
|
|
71
|
+
atoms_data = traj_data
|
|
72
|
+
|
|
73
|
+
# Ensure that calculated properties are transferred to the calculator in dict_to_atoms
|
|
74
|
+
if 'calc_results' not in atoms_data and hasattr(atoms_data, 'get') and atoms_data.get('forces') is not None:
|
|
75
|
+
# If we have forces in the data but no calc_results, create calc_results entries
|
|
76
|
+
calc_data_list = []
|
|
77
|
+
n_frames = atoms_data.get('n_frames', 0)
|
|
78
|
+
|
|
79
|
+
for i in range(n_frames):
|
|
80
|
+
calc_data = {'name': 'SinglePointCalculator'}
|
|
81
|
+
if 'forces' in atoms_data and i < len(atoms_data['forces']):
|
|
82
|
+
calc_data['forces'] = atoms_data['forces'][i]
|
|
83
|
+
if 'stress' in atoms_data and i < len(atoms_data['stress']):
|
|
84
|
+
calc_data['stress'] = atoms_data['stress'][i]
|
|
85
|
+
if 'energy' in atoms_data and i < len(atoms_data['energy']):
|
|
86
|
+
calc_data['energy'] = atoms_data['energy'][i]
|
|
87
|
+
calc_data_list.append(calc_data)
|
|
88
|
+
|
|
89
|
+
atoms_data['calc_results'] = calc_data_list
|
|
90
|
+
|
|
91
|
+
# Convert to atoms objects
|
|
92
|
+
atoms_list = dict_to_atoms(atoms_data)
|
|
93
|
+
|
|
94
|
+
# Make sure atoms_list is always a list
|
|
95
|
+
if not isinstance(atoms_list, list):
|
|
96
|
+
atoms_list = [atoms_list]
|
|
97
|
+
|
|
98
|
+
return atoms_list, metadata
|
|
99
|
+
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
2
|
+
from typing import Dict, List, Optional, Tuple, Union, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from ase import Atoms
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _max_workers(task_count: int) -> int:
|
|
9
|
+
if task_count <= 1:
|
|
10
|
+
return 1
|
|
11
|
+
return max(1, min(task_count, 24))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _chunk_size(max_workers: int) -> int:
|
|
15
|
+
return max(1, max_workers * 4)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def write_tess(
|
|
19
|
+
atoms: Union['Atoms', List['Atoms']],
|
|
20
|
+
filename: str,
|
|
21
|
+
metadata: Optional[Dict] = None,
|
|
22
|
+
compression: Optional[str] = 'none',
|
|
23
|
+
compression_level: int = 0,
|
|
24
|
+
) -> None:
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
import msgpack
|
|
28
|
+
import msgpack_numpy as m
|
|
29
|
+
from ase import Atoms
|
|
30
|
+
import zlib
|
|
31
|
+
import lz4.block
|
|
32
|
+
import numpy as np
|
|
33
|
+
except ImportError:
|
|
34
|
+
raise ImportError("You need to install with `pip install atomict[utils]` to use msgpack I/O")
|
|
35
|
+
|
|
36
|
+
# Enable numpy array serialization
|
|
37
|
+
m.patch()
|
|
38
|
+
|
|
39
|
+
if isinstance(atoms, Atoms):
|
|
40
|
+
frames_list = [atoms]
|
|
41
|
+
else:
|
|
42
|
+
frames_list = list(atoms)
|
|
43
|
+
|
|
44
|
+
compression_mode = (compression or 'none').lower()
|
|
45
|
+
if compression_mode not in {'none', 'zlib', 'lz4'}:
|
|
46
|
+
raise ValueError(
|
|
47
|
+
f"Unsupported compression mode '{compression_mode}' for tess format"
|
|
48
|
+
)
|
|
49
|
+
if compression_mode == 'zlib' and not (0 <= compression_level <= 9):
|
|
50
|
+
raise ValueError("compression_level must be between 0 and 9 for zlib compression")
|
|
51
|
+
|
|
52
|
+
# Collect global unique_symbols
|
|
53
|
+
unique_symbols_set = set()
|
|
54
|
+
for a in frames_list:
|
|
55
|
+
unique_symbols_set.update(a.get_chemical_symbols())
|
|
56
|
+
unique_symbols = sorted(list(unique_symbols_set))
|
|
57
|
+
unique_symbols_lookup = {s: i for i, s in enumerate(unique_symbols)}
|
|
58
|
+
|
|
59
|
+
# Check if cell changes across frames
|
|
60
|
+
first_cell = np.array(frames_list[0].get_cell(), dtype=np.float32)
|
|
61
|
+
cell_changes = any(
|
|
62
|
+
not np.allclose(np.array(a.get_cell(), dtype=np.float32), first_cell, rtol=1e-6)
|
|
63
|
+
for a in frames_list[1:20] # Sample first 20 frames
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# Pre-extract positions as float32 arrays for all frames
|
|
67
|
+
positions_list = [a.get_positions().astype(np.float32) for a in frames_list]
|
|
68
|
+
if cell_changes:
|
|
69
|
+
cells_list = [np.array(a.get_cell(), dtype=np.float32) for a in frames_list]
|
|
70
|
+
|
|
71
|
+
# Optimized frame serialization - pack only essential per-frame data
|
|
72
|
+
def _pack_frame(i: int) -> bytes:
|
|
73
|
+
# Only pack data that changes between frames
|
|
74
|
+
frame_dict = {'positions': positions_list[i]}
|
|
75
|
+
if cell_changes:
|
|
76
|
+
frame_dict['cell'] = cells_list[i]
|
|
77
|
+
return msgpack.packb(frame_dict, use_bin_type=True)
|
|
78
|
+
|
|
79
|
+
with open(filename, 'wb', buffering=1024*1024) as f:
|
|
80
|
+
frame_offsets: List[Tuple[int, int]] = []
|
|
81
|
+
uncompressed_lengths: List[int] = []
|
|
82
|
+
if compression_mode == 'zlib' or compression_mode == 'lz4':
|
|
83
|
+
# Pre-pack all frames (fast operation)
|
|
84
|
+
packed_frames = [_pack_frame(i) for i in range(len(frames_list))]
|
|
85
|
+
|
|
86
|
+
worker_count = _max_workers(len(packed_frames))
|
|
87
|
+
|
|
88
|
+
def _compress_frame(packed: bytes) -> bytes:
|
|
89
|
+
if compression_mode == 'zlib':
|
|
90
|
+
return zlib.compress(packed, compression_level)
|
|
91
|
+
else: # lz4
|
|
92
|
+
return lz4.block.compress(packed, store_size=True)
|
|
93
|
+
|
|
94
|
+
initial = f.tell()
|
|
95
|
+
current = initial
|
|
96
|
+
|
|
97
|
+
with ThreadPoolExecutor(max_workers=worker_count) as executor:
|
|
98
|
+
compressed_frames = list(executor.map(_compress_frame, packed_frames))
|
|
99
|
+
|
|
100
|
+
# Write all compressed frames
|
|
101
|
+
for packed, compressed in zip(packed_frames, compressed_frames):
|
|
102
|
+
f.write(compressed)
|
|
103
|
+
frame_offsets.append((current, len(compressed)))
|
|
104
|
+
uncompressed_lengths.append(len(packed))
|
|
105
|
+
current += len(compressed)
|
|
106
|
+
|
|
107
|
+
else:
|
|
108
|
+
# Write frames directly without intermediate buffer
|
|
109
|
+
initial = f.tell()
|
|
110
|
+
current = initial
|
|
111
|
+
for i in range(len(frames_list)):
|
|
112
|
+
packed = _pack_frame(i)
|
|
113
|
+
l = len(packed)
|
|
114
|
+
f.write(packed)
|
|
115
|
+
frame_offsets.append((current, l))
|
|
116
|
+
current += l
|
|
117
|
+
|
|
118
|
+
# Store static data in header (data that's the same for all frames)
|
|
119
|
+
first_frame = frames_list[0]
|
|
120
|
+
symbols = first_frame.get_chemical_symbols()
|
|
121
|
+
symbols_idx = np.array([unique_symbols_lookup[s] for s in symbols], dtype=np.uint16)
|
|
122
|
+
|
|
123
|
+
# Write header
|
|
124
|
+
header_dict: Dict[str, object] = {
|
|
125
|
+
'format_version': 4,
|
|
126
|
+
'metadata': dict(metadata or {}),
|
|
127
|
+
'unique_symbols': unique_symbols,
|
|
128
|
+
'num_frames': len(frames_list),
|
|
129
|
+
'frame_offsets': frame_offsets,
|
|
130
|
+
# Static frame data stored once in header
|
|
131
|
+
'static_data': {
|
|
132
|
+
'n_atoms': len(first_frame),
|
|
133
|
+
'symbols': symbols_idx,
|
|
134
|
+
'numbers': first_frame.get_atomic_numbers(),
|
|
135
|
+
'masses': first_frame.get_masses(),
|
|
136
|
+
'pbc': first_frame.get_pbc(),
|
|
137
|
+
'cell': first_cell,
|
|
138
|
+
'cell_changes': cell_changes,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if compression_mode != 'none':
|
|
142
|
+
header_dict['compression'] = {
|
|
143
|
+
'type': compression_mode,
|
|
144
|
+
}
|
|
145
|
+
if compression_mode == 'zlib':
|
|
146
|
+
header_dict['compression']['level'] = compression_level
|
|
147
|
+
header_dict['frame_uncompressed_lengths'] = uncompressed_lengths
|
|
148
|
+
header_bytes = msgpack.packb(header_dict, use_bin_type=True)
|
|
149
|
+
header_start = f.tell()
|
|
150
|
+
f.write(header_bytes)
|
|
151
|
+
|
|
152
|
+
# Write header offset
|
|
153
|
+
f.write(header_start.to_bytes(8, 'little'))
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tuple[List['Atoms'], Dict]:
|
|
157
|
+
|
|
158
|
+
try:
|
|
159
|
+
import msgpack
|
|
160
|
+
import msgpack_numpy as m
|
|
161
|
+
from atomict.io.atoms import dict_to_atoms
|
|
162
|
+
from ase import Atoms
|
|
163
|
+
import mmap
|
|
164
|
+
import zlib
|
|
165
|
+
import lz4.block
|
|
166
|
+
except ImportError:
|
|
167
|
+
raise ImportError("You need to install with `pip install atomict[utils]` to use msgpack I/O")
|
|
168
|
+
|
|
169
|
+
# Enable numpy array deserialization
|
|
170
|
+
m.patch()
|
|
171
|
+
|
|
172
|
+
with open(filename, 'rb') as f:
|
|
173
|
+
# Use mmap with larger read-ahead hint
|
|
174
|
+
mm = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
|
|
175
|
+
try:
|
|
176
|
+
# Advise the kernel we'll read sequentially
|
|
177
|
+
if hasattr(mm, 'madvise'):
|
|
178
|
+
import mmap as mmap_module
|
|
179
|
+
if hasattr(mmap_module, 'MADV_SEQUENTIAL'):
|
|
180
|
+
mm.madvise(mmap_module.MADV_SEQUENTIAL)
|
|
181
|
+
|
|
182
|
+
file_size = mm.size()
|
|
183
|
+
header_start = int.from_bytes(mm[file_size - 8:file_size], 'little')
|
|
184
|
+
header_bytes = mm[header_start:file_size - 8]
|
|
185
|
+
header = msgpack.unpackb(header_bytes, raw=False, strict_map_key=False)
|
|
186
|
+
|
|
187
|
+
format_version = header.get('format_version', 1)
|
|
188
|
+
if format_version not in {2, 3, 4}:
|
|
189
|
+
raise ValueError("Invalid format version")
|
|
190
|
+
|
|
191
|
+
compression_info = header.get('compression')
|
|
192
|
+
if isinstance(compression_info, dict):
|
|
193
|
+
compression_type = compression_info.get('type', 'none')
|
|
194
|
+
elif isinstance(compression_info, str):
|
|
195
|
+
compression_type = compression_info
|
|
196
|
+
else:
|
|
197
|
+
compression_type = 'none'
|
|
198
|
+
compression_type = (compression_type or 'none').lower()
|
|
199
|
+
if compression_type not in {'none', 'zlib', 'lz4'}:
|
|
200
|
+
raise ValueError(f"Unsupported compression type '{compression_type}' in tess file")
|
|
201
|
+
|
|
202
|
+
metadata = header.get('metadata', {})
|
|
203
|
+
frame_offsets = [tuple(offset) for offset in header['frame_offsets']]
|
|
204
|
+
num_frames = len(frame_offsets)
|
|
205
|
+
|
|
206
|
+
# Determine which frames to load
|
|
207
|
+
if frames_indices is not None:
|
|
208
|
+
# Validate and normalize indices
|
|
209
|
+
frames_to_load = []
|
|
210
|
+
for idx in frames_indices:
|
|
211
|
+
if idx < 0 or idx >= num_frames:
|
|
212
|
+
raise IndexError(f"Frame index {idx} out of range [0, {num_frames})")
|
|
213
|
+
frames_to_load.append(idx)
|
|
214
|
+
# Filter offsets to only requested frames
|
|
215
|
+
filtered_offsets = [(i, frame_offsets[i]) for i in frames_to_load]
|
|
216
|
+
else:
|
|
217
|
+
frames_to_load = list(range(num_frames))
|
|
218
|
+
filtered_offsets = [(i, offset) for i, offset in enumerate(frame_offsets)]
|
|
219
|
+
|
|
220
|
+
# Pre-allocate the result list based on requested frames
|
|
221
|
+
atoms_list = [None] * len(frames_to_load)
|
|
222
|
+
|
|
223
|
+
# Handle format version 4 with static data
|
|
224
|
+
if format_version == 4:
|
|
225
|
+
static_data = header.get('static_data', {})
|
|
226
|
+
unique_symbols = header['unique_symbols']
|
|
227
|
+
symbols_idx = static_data['symbols']
|
|
228
|
+
symbols = [unique_symbols[i] for i in symbols_idx]
|
|
229
|
+
numbers = static_data['numbers']
|
|
230
|
+
masses = static_data['masses']
|
|
231
|
+
pbc = static_data['pbc']
|
|
232
|
+
static_cell = static_data.get('cell')
|
|
233
|
+
cell_changes = static_data.get('cell_changes', True)
|
|
234
|
+
|
|
235
|
+
# Create a template Atoms object to clone for efficiency
|
|
236
|
+
import numpy as np
|
|
237
|
+
template_atoms = Atoms(numbers=numbers, pbc=pbc)
|
|
238
|
+
template_atoms.set_masses(masses)
|
|
239
|
+
if static_cell is not None:
|
|
240
|
+
template_atoms.set_cell(static_cell)
|
|
241
|
+
else:
|
|
242
|
+
convert = dict_to_atoms
|
|
243
|
+
static_data = None
|
|
244
|
+
cell_changes = True
|
|
245
|
+
|
|
246
|
+
# Process frames with minimal overhead
|
|
247
|
+
if compression_type == 'zlib' and len(filtered_offsets) > 0:
|
|
248
|
+
|
|
249
|
+
def _decompress(idx_offset: Tuple[int, Tuple[int, int]]) -> Tuple[int, bytes]:
|
|
250
|
+
orig_idx, (start, length) = idx_offset
|
|
251
|
+
compressed = mm[start:start + length]
|
|
252
|
+
return orig_idx, zlib.decompress(compressed)
|
|
253
|
+
|
|
254
|
+
worker_count = _max_workers(len(filtered_offsets))
|
|
255
|
+
chunk_size = _chunk_size(worker_count)
|
|
256
|
+
|
|
257
|
+
with ThreadPoolExecutor(max_workers=worker_count) as executor:
|
|
258
|
+
for chunk_start in range(0, len(filtered_offsets), chunk_size):
|
|
259
|
+
offset_chunk = filtered_offsets[chunk_start:chunk_start + chunk_size]
|
|
260
|
+
for result_idx, (orig_idx, frame_bytes) in enumerate(
|
|
261
|
+
executor.map(_decompress, offset_chunk), start=0
|
|
262
|
+
):
|
|
263
|
+
frame_dict = msgpack.unpackb(
|
|
264
|
+
frame_bytes, raw=False, strict_map_key=False
|
|
265
|
+
)
|
|
266
|
+
if format_version == 4:
|
|
267
|
+
# Fast path for v4: clone template and update only changing data
|
|
268
|
+
atoms = template_atoms.copy()
|
|
269
|
+
atoms.set_positions(frame_dict['positions'])
|
|
270
|
+
if cell_changes and 'cell' in frame_dict:
|
|
271
|
+
atoms.set_cell(frame_dict['cell'])
|
|
272
|
+
atoms_list[chunk_start + result_idx] = atoms
|
|
273
|
+
else:
|
|
274
|
+
atoms_list[chunk_start + result_idx] = convert(frame_dict)[0]
|
|
275
|
+
elif compression_type == 'lz4' and len(filtered_offsets) > 0:
|
|
276
|
+
|
|
277
|
+
def _decompress(idx_offset: Tuple[int, Tuple[int, int]]) -> Tuple[int, bytes]:
|
|
278
|
+
orig_idx, (start, length) = idx_offset
|
|
279
|
+
compressed = mm[start:start + length]
|
|
280
|
+
return orig_idx, lz4.block.decompress(compressed)
|
|
281
|
+
|
|
282
|
+
worker_count = _max_workers(len(filtered_offsets))
|
|
283
|
+
chunk_size = _chunk_size(worker_count)
|
|
284
|
+
|
|
285
|
+
with ThreadPoolExecutor(max_workers=worker_count) as executor:
|
|
286
|
+
for chunk_start in range(0, len(filtered_offsets), chunk_size):
|
|
287
|
+
offset_chunk = filtered_offsets[chunk_start:chunk_start + chunk_size]
|
|
288
|
+
for result_idx, (orig_idx, frame_bytes) in enumerate(
|
|
289
|
+
executor.map(_decompress, offset_chunk), start=0
|
|
290
|
+
):
|
|
291
|
+
frame_dict = msgpack.unpackb(
|
|
292
|
+
frame_bytes, raw=False, strict_map_key=False
|
|
293
|
+
)
|
|
294
|
+
if format_version == 4:
|
|
295
|
+
atoms = template_atoms.copy()
|
|
296
|
+
atoms.set_positions(frame_dict['positions'])
|
|
297
|
+
if cell_changes and 'cell' in frame_dict:
|
|
298
|
+
atoms.set_cell(frame_dict['cell'])
|
|
299
|
+
atoms_list[chunk_start + result_idx] = atoms
|
|
300
|
+
else:
|
|
301
|
+
atoms_list[chunk_start + result_idx] = convert(frame_dict)[0]
|
|
302
|
+
else:
|
|
303
|
+
for result_idx, (orig_idx, (start, length)) in enumerate(filtered_offsets):
|
|
304
|
+
frame_slice = mm[start:start + length]
|
|
305
|
+
frame_dict = msgpack.unpackb(
|
|
306
|
+
frame_slice, raw=False, strict_map_key=False
|
|
307
|
+
)
|
|
308
|
+
if format_version == 4:
|
|
309
|
+
atoms = template_atoms.copy()
|
|
310
|
+
atoms.set_positions(frame_dict['positions'])
|
|
311
|
+
if cell_changes and 'cell' in frame_dict:
|
|
312
|
+
atoms.set_cell(frame_dict['cell'])
|
|
313
|
+
atoms_list[result_idx] = atoms
|
|
314
|
+
else:
|
|
315
|
+
atoms_list[result_idx] = convert(frame_dict)[0]
|
|
316
|
+
finally:
|
|
317
|
+
mm.close()
|
|
318
|
+
|
|
319
|
+
return atoms_list, metadata
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from typing import Union, List, Dict, TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
if TYPE_CHECKING:
|
|
4
|
+
import ase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def write_traj(atoms: Union['ase.Atoms', List['ase.Atoms']], filename: str, metadata: Dict = None, properties: List[str] = None):
|
|
8
|
+
"""Save atoms to an ASE trajectory file.
|
|
9
|
+
|
|
10
|
+
Parameters:
|
|
11
|
+
atoms: Single Atoms object or list of Atoms objects to write
|
|
12
|
+
filename: Output trajectory filename
|
|
13
|
+
metadata: Optional metadata to add to frames
|
|
14
|
+
properties: List of calculator properties to save (e.g., ['energy', 'forces', 'stress'])
|
|
15
|
+
If None, all available properties are saved
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
from ase.io.trajectory import TrajectoryWriter
|
|
20
|
+
from ase import Atoms
|
|
21
|
+
except ImportError:
|
|
22
|
+
raise ImportError("You need to install ASE to use trajectory I/O")
|
|
23
|
+
|
|
24
|
+
# Single atoms case - convert to list
|
|
25
|
+
if isinstance(atoms, Atoms):
|
|
26
|
+
atoms_list = [atoms]
|
|
27
|
+
else:
|
|
28
|
+
atoms_list = atoms
|
|
29
|
+
|
|
30
|
+
# Use TrajectoryWriter for better control over properties
|
|
31
|
+
with TrajectoryWriter(filename, mode='w', properties=properties) as traj:
|
|
32
|
+
for atoms_frame in atoms_list:
|
|
33
|
+
if metadata:
|
|
34
|
+
# Only copy if we need to add metadata to avoid modifying original
|
|
35
|
+
frame_copy = atoms_frame.copy()
|
|
36
|
+
frame_copy.info.update(metadata)
|
|
37
|
+
traj.write(frame_copy)
|
|
38
|
+
else:
|
|
39
|
+
# Write directly without copying if no metadata
|
|
40
|
+
traj.write(atoms_frame)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def read_traj(filename: str) -> tuple[List['ase.Atoms'], Dict]:
|
|
44
|
+
"""Load atoms from an ASE trajectory file."""
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
from ase.io.trajectory import TrajectoryReader
|
|
48
|
+
except ImportError:
|
|
49
|
+
raise ImportError("You need to install ASE to use trajectory I/O")
|
|
50
|
+
|
|
51
|
+
atoms_list = []
|
|
52
|
+
metadata = {}
|
|
53
|
+
|
|
54
|
+
# Read trajectory using TrajectoryReader for better control
|
|
55
|
+
with TrajectoryReader(filename) as traj:
|
|
56
|
+
for atoms_frame in traj:
|
|
57
|
+
atoms_list.append(atoms_frame)
|
|
58
|
+
# Extract metadata from the first frame's info
|
|
59
|
+
if not metadata and atoms_frame.info:
|
|
60
|
+
metadata = dict(atoms_frame.info)
|
|
61
|
+
|
|
62
|
+
return atoms_list, metadata
|
atomict/project/project.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
from atomict.api import delete, get, post
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def create_project(name: str, description: str = None
|
|
4
|
+
def create_project(name: str, description: str = None) -> dict:
|
|
5
5
|
|
|
6
6
|
payload = {
|
|
7
7
|
"name": name,
|
|
8
8
|
"description_html": description,
|
|
9
|
-
"thumbnail_smiles": thumbnail_smiles,
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
response = post(
|
atomict/simulation/fhi_aims.py
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
from atomict.api import delete, get, post
|
|
2
|
+
from atomict.infra.distwork.task import SimulationAction
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
def create_simulation(
|
|
5
6
|
project_id: str,
|
|
6
7
|
control_file: str,
|
|
7
8
|
geometry_file: str,
|
|
8
|
-
action:
|
|
9
|
+
action: SimulationAction,
|
|
9
10
|
name: str = None,
|
|
10
11
|
description: str = None,
|
|
11
12
|
extra_simulation_kwargs: dict = None,
|
|
12
13
|
) -> dict:
|
|
13
14
|
|
|
14
|
-
if action not in [
|
|
15
|
-
raise ValueError("Action must be '
|
|
15
|
+
if action not in [SimulationAction.SAVE_DRAFT, SimulationAction.LAUNCH]:
|
|
16
|
+
raise ValueError("Action must be 'SimulationAction.SAVE_DRAFT' or 'SimulationAction.LAUNCH'")
|
|
16
17
|
|
|
17
18
|
payload = {
|
|
18
19
|
"project_id": project_id,
|
|
19
20
|
"control_file": control_file,
|
|
20
21
|
"geometry_file": geometry_file,
|
|
21
|
-
"action": action,
|
|
22
|
+
"action": action.value,
|
|
22
23
|
"name": name,
|
|
23
24
|
"description": description,
|
|
24
25
|
}
|
atomict/simulation/mlrelax.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
1
3
|
from atomict.api import get, post
|
|
2
|
-
from atomict.
|
|
4
|
+
from atomict.infra.distwork.task import SimulationAction
|
|
5
|
+
from atomict.simulation.models import MODEL_ORB_V3_CONSERVATIVE, MODEL_ESEN_30M_OAM, MODEL_UMA
|
|
3
6
|
|
|
4
7
|
COMPUTATION_TYPE_RELAXATION = 0
|
|
5
8
|
COMPUTATION_TYPE_SINGLE_POINT = 1
|
|
@@ -38,38 +41,49 @@ def associate_user_upload_with_mlrelaxation(user_upload_id: str, mlrelax_id: str
|
|
|
38
41
|
def create_mlrelaxation(
|
|
39
42
|
project_id: str,
|
|
40
43
|
source_geometry_id: str,
|
|
41
|
-
action:
|
|
44
|
+
action: SimulationAction,
|
|
42
45
|
name: str = None,
|
|
43
46
|
description: str = None,
|
|
44
47
|
computation_type: int = COMPUTATION_TYPE_RELAXATION,
|
|
45
48
|
f_max: float = None,
|
|
46
|
-
model: int =
|
|
49
|
+
model: int = MODEL_ESEN_30M_OAM,
|
|
50
|
+
calculator: Union[int, None] = None,
|
|
47
51
|
extra_simulation_kwargs: dict = None,
|
|
48
52
|
):
|
|
49
53
|
"""
|
|
50
54
|
Create a MLRelaxation
|
|
51
55
|
"""
|
|
52
56
|
|
|
53
|
-
if action not in [
|
|
54
|
-
raise ValueError("Action must be '
|
|
57
|
+
if action not in [SimulationAction.SAVE_DRAFT, SimulationAction.LAUNCH]:
|
|
58
|
+
raise ValueError("Action must be 'SimulationAction.SAVE_DRAFT' or 'SimulationAction.LAUNCH'")
|
|
55
59
|
|
|
56
60
|
if computation_type not in [
|
|
57
61
|
COMPUTATION_TYPE_RELAXATION,
|
|
58
62
|
COMPUTATION_TYPE_SINGLE_POINT,
|
|
59
63
|
]:
|
|
60
64
|
raise ValueError(
|
|
61
|
-
"Invalid computation type. Please use COMPUTATION_TYPE_RELAXATION
|
|
65
|
+
"Invalid computation type. Please use atomict.simulation.mlrelax.COMPUTATION_TYPE_RELAXATION or atomict.simulation.mlrelax.COMPUTATION_TYPE_SINGLE_POINT."
|
|
62
66
|
)
|
|
63
67
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
# backwards compat
|
|
69
|
+
if calculator:
|
|
70
|
+
if calculator not in [
|
|
71
|
+
MODEL_ORB_V3_CONSERVATIVE,
|
|
72
|
+
MODEL_ESEN_30M_OAM,
|
|
73
|
+
MODEL_UMA
|
|
74
|
+
]:
|
|
75
|
+
raise ValueError(
|
|
76
|
+
"Invalid model. Please use atomict.simulation.models.MODEL_ORB_V3_CONSERVATIVE, or atomict.simulation.models.MODEL_ESEN_30M_OAM, or atomict.simulation.models.MODEL_UMA."
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
else:
|
|
80
|
+
if model not in [
|
|
81
|
+
MODEL_ORB_V3_CONSERVATIVE,
|
|
82
|
+
MODEL_ESEN_30M_OAM,
|
|
83
|
+
]:
|
|
84
|
+
raise ValueError(
|
|
85
|
+
"Invalid model. Please use atomict.simulation.models.MODEL_ORB_V3_CONSERVATIVE, or atomict.simulation.models.MODEL_ESEN_30M_OAM, or atomict.simulation.models.MODEL_UMA."
|
|
86
|
+
)
|
|
73
87
|
|
|
74
88
|
payload = {
|
|
75
89
|
"project": project_id,
|
|
@@ -79,9 +93,14 @@ def create_mlrelaxation(
|
|
|
79
93
|
"description": description,
|
|
80
94
|
"computation_type": computation_type,
|
|
81
95
|
"f_max": f_max,
|
|
82
|
-
"model": model,
|
|
83
96
|
}
|
|
84
97
|
|
|
98
|
+
# backwards compat
|
|
99
|
+
if calculator:
|
|
100
|
+
payload["calculator"] = calculator
|
|
101
|
+
else:
|
|
102
|
+
payload["model"] = model
|
|
103
|
+
|
|
85
104
|
if extra_simulation_kwargs:
|
|
86
105
|
payload.update(extra_simulation_kwargs)
|
|
87
106
|
|
atomict/simulation/models.py
CHANGED
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_id={simulation_id}")
|
|
74
74
|
return result
|
atomict/simulation/utils.py
CHANGED
|
@@ -25,7 +25,7 @@ def fetch_source_geometry(sim: dict, workbench_dir: str) -> Atoms:
|
|
|
25
25
|
|
|
26
26
|
extension = sim["source_geometry"]["orig_name"].split(".")[-1]
|
|
27
27
|
|
|
28
|
-
download_file(sim["source_geometry"]["
|
|
28
|
+
download_file(sim["source_geometry"]["id"], workbench_dir + f"/geometry.{extension}")
|
|
29
29
|
|
|
30
30
|
if extension == "atraj":
|
|
31
31
|
atoms, _ = load_msgpack_trajectory(workbench_dir + f"/geometry.{extension}")
|
|
@@ -103,11 +103,11 @@ def fetch_relaxed_geometry(sim: dict, workbench_dir: str) -> Atoms:
|
|
|
103
103
|
return atoms
|
|
104
104
|
|
|
105
105
|
elif sim.get("starting_structure_userupload"):
|
|
106
|
-
logging.info(f"Previous UserUpload: {sim['starting_structure_userupload']['
|
|
106
|
+
logging.info(f"Previous UserUpload: {sim['starting_structure_userupload']['id']}")
|
|
107
107
|
|
|
108
108
|
extension = sim["starting_structure_userupload"]["orig_name"].split(".")[-1]
|
|
109
109
|
|
|
110
|
-
download_file(sim["starting_structure_userupload"]["
|
|
110
|
+
download_file(sim["starting_structure_userupload"]["id"], workbench_dir + f"/geometry.{extension}")
|
|
111
111
|
|
|
112
112
|
if extension == "atraj":
|
|
113
113
|
atoms, _ = load_msgpack_trajectory(workbench_dir + f"/geometry.{extension}")
|