atomict 1.2.21__py3-none-any.whl → 1.2.23__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/io/formats/tess.py +169 -173
- atomict/io/trajectory.py +264 -0
- atomict/simulation/phonon.py +10 -0
- {atomict-1.2.21.dist-info → atomict-1.2.23.dist-info}/METADATA +1 -1
- {atomict-1.2.21.dist-info → atomict-1.2.23.dist-info}/RECORD +10 -9
- {atomict-1.2.21.dist-info → atomict-1.2.23.dist-info}/WHEEL +0 -0
- {atomict-1.2.21.dist-info → atomict-1.2.23.dist-info}/entry_points.txt +0 -0
- {atomict-1.2.21.dist-info → atomict-1.2.23.dist-info}/licenses/LICENSE +0 -0
- {atomict-1.2.21.dist-info → atomict-1.2.23.dist-info}/top_level.txt +0 -0
atomict/__version__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.2.
|
|
1
|
+
__version__ = "1.2.23"
|
atomict/io/formats/tess.py
CHANGED
|
@@ -15,6 +15,145 @@ def _chunk_size(max_workers: int) -> int:
|
|
|
15
15
|
return max(1, max_workers * 4)
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
def _read_tess_header(filename: str) -> Dict[str, Any]:
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
import msgpack
|
|
22
|
+
import msgpack_numpy as m
|
|
23
|
+
import mmap
|
|
24
|
+
except ImportError:
|
|
25
|
+
raise ImportError("You need to install with `pip install atomict[utils]` to use the newer formats")
|
|
26
|
+
|
|
27
|
+
# Enable numpy array deserialization for header contents that may include numpy arrays
|
|
28
|
+
m.patch()
|
|
29
|
+
|
|
30
|
+
with open(filename, 'rb') as f:
|
|
31
|
+
mm = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
|
|
32
|
+
try:
|
|
33
|
+
# Advise the kernel we'll read sequentially if available
|
|
34
|
+
if hasattr(mm, 'madvise'):
|
|
35
|
+
import mmap as mmap_module
|
|
36
|
+
if hasattr(mmap_module, 'MADV_SEQUENTIAL'):
|
|
37
|
+
mm.madvise(mmap_module.MADV_SEQUENTIAL)
|
|
38
|
+
|
|
39
|
+
file_size = mm.size()
|
|
40
|
+
header_start = int.from_bytes(mm[file_size - 8:file_size], 'little')
|
|
41
|
+
header_bytes = mm[header_start:file_size - 8]
|
|
42
|
+
header = msgpack.unpackb(header_bytes, raw=False, strict_map_key=False)
|
|
43
|
+
|
|
44
|
+
format_version = header.get('format_version', 1)
|
|
45
|
+
if format_version not in {2, 3, 4, 5}:
|
|
46
|
+
raise ValueError("Invalid format version")
|
|
47
|
+
|
|
48
|
+
# Normalize frame_offsets to a list of tuples for convenience
|
|
49
|
+
if 'frame_offsets' in header and isinstance(header['frame_offsets'], list):
|
|
50
|
+
header['frame_offsets'] = [tuple(offset) for offset in header['frame_offsets']]
|
|
51
|
+
|
|
52
|
+
return header
|
|
53
|
+
finally:
|
|
54
|
+
mm.close()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _decode_frame(frame_bytes: bytes, header: Dict[str, Any], template_atoms: Optional['Atoms'] = None) -> 'Atoms':
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
import msgpack
|
|
61
|
+
import msgpack_numpy as m
|
|
62
|
+
from atomict.io.atoms import dict_to_atoms
|
|
63
|
+
from ase import Atoms
|
|
64
|
+
from ase.calculators.singlepoint import SinglePointCalculator
|
|
65
|
+
import zlib
|
|
66
|
+
import lz4.block
|
|
67
|
+
except ImportError:
|
|
68
|
+
raise ImportError("You need to install with `pip install atomict[utils]` to use the newer formats")
|
|
69
|
+
|
|
70
|
+
# Enable numpy array deserialization for any numpy contents
|
|
71
|
+
m.patch()
|
|
72
|
+
|
|
73
|
+
compression_info = header.get('compression')
|
|
74
|
+
if isinstance(compression_info, dict):
|
|
75
|
+
compression_type = compression_info.get('type', 'none')
|
|
76
|
+
elif isinstance(compression_info, str):
|
|
77
|
+
compression_type = compression_info
|
|
78
|
+
else:
|
|
79
|
+
compression_type = 'none'
|
|
80
|
+
compression_type = (compression_type or 'none').lower()
|
|
81
|
+
|
|
82
|
+
# Decompress if needed
|
|
83
|
+
if compression_type == 'zlib':
|
|
84
|
+
frame_bytes = zlib.decompress(frame_bytes)
|
|
85
|
+
elif compression_type == 'lz4':
|
|
86
|
+
frame_bytes = lz4.block.decompress(frame_bytes)
|
|
87
|
+
|
|
88
|
+
# Unpack frame
|
|
89
|
+
frame_dict = msgpack.unpackb(frame_bytes, raw=False, strict_map_key=False)
|
|
90
|
+
|
|
91
|
+
format_version = header.get('format_version', 1)
|
|
92
|
+
|
|
93
|
+
# Fast path for v4/v5 using static header data
|
|
94
|
+
if format_version in {4, 5}:
|
|
95
|
+
static_data = header.get('static_data', {})
|
|
96
|
+
|
|
97
|
+
# Either copy provided template or construct one from static data
|
|
98
|
+
if template_atoms is not None:
|
|
99
|
+
atoms = template_atoms.copy()
|
|
100
|
+
else:
|
|
101
|
+
numbers = static_data['numbers']
|
|
102
|
+
masses = static_data['masses']
|
|
103
|
+
pbc = static_data['pbc']
|
|
104
|
+
atoms = Atoms(numbers=numbers, pbc=pbc)
|
|
105
|
+
atoms.set_masses(masses)
|
|
106
|
+
if 'cell' in static_data and static_data['cell'] is not None:
|
|
107
|
+
atoms.set_cell(static_data['cell'])
|
|
108
|
+
if 'tags' in static_data and static_data['tags'] is not None:
|
|
109
|
+
atoms.set_tags(static_data['tags'])
|
|
110
|
+
if 'initial_charges' in static_data and static_data['initial_charges'] is not None:
|
|
111
|
+
atoms.set_initial_charges(static_data['initial_charges'])
|
|
112
|
+
if 'initial_magmoms' in static_data and static_data['initial_magmoms'] is not None:
|
|
113
|
+
atoms.set_initial_magnetic_moments(static_data['initial_magmoms'])
|
|
114
|
+
|
|
115
|
+
# Per-frame updates
|
|
116
|
+
atoms.set_positions(frame_dict['positions'])
|
|
117
|
+
if static_data.get('cell_changes', True) and 'cell' in frame_dict:
|
|
118
|
+
atoms.set_cell(frame_dict['cell'])
|
|
119
|
+
|
|
120
|
+
if format_version == 5:
|
|
121
|
+
if 'tags' in frame_dict:
|
|
122
|
+
atoms.set_tags(frame_dict['tags'])
|
|
123
|
+
if 'initial_charges' in frame_dict:
|
|
124
|
+
atoms.set_initial_charges(frame_dict['initial_charges'])
|
|
125
|
+
if 'initial_magmoms' in frame_dict:
|
|
126
|
+
atoms.set_initial_magnetic_moments(frame_dict['initial_magmoms'])
|
|
127
|
+
if 'momenta' in frame_dict:
|
|
128
|
+
atoms.set_momenta(frame_dict['momenta'])
|
|
129
|
+
if 'forces' in frame_dict:
|
|
130
|
+
atoms.arrays['forces'] = frame_dict['forces']
|
|
131
|
+
if 'info' in frame_dict and isinstance(frame_dict['info'], dict):
|
|
132
|
+
atoms.info.update(frame_dict['info'])
|
|
133
|
+
if 'custom_arrays' in frame_dict and isinstance(frame_dict['custom_arrays'], dict):
|
|
134
|
+
for k, v in frame_dict['custom_arrays'].items():
|
|
135
|
+
atoms.arrays[k] = v
|
|
136
|
+
|
|
137
|
+
# Calculator results (merge stress if present)
|
|
138
|
+
calc_data = {}
|
|
139
|
+
if 'calc_results' in frame_dict and isinstance(frame_dict['calc_results'], dict):
|
|
140
|
+
calc_data = dict(frame_dict['calc_results'])
|
|
141
|
+
if 'stress' in frame_dict:
|
|
142
|
+
calc_data['stress'] = frame_dict['stress']
|
|
143
|
+
if len(calc_data) > 0:
|
|
144
|
+
calc = SinglePointCalculator(atoms)
|
|
145
|
+
for key, value in calc_data.items():
|
|
146
|
+
if key != 'name':
|
|
147
|
+
calc.results[key] = value
|
|
148
|
+
if calc.results:
|
|
149
|
+
atoms.calc = calc
|
|
150
|
+
|
|
151
|
+
return atoms
|
|
152
|
+
|
|
153
|
+
# Legacy path: v1-v3 store full atoms dict per frame
|
|
154
|
+
atoms_list, _ = dict_to_atoms(frame_dict)
|
|
155
|
+
return atoms_list[0]
|
|
156
|
+
|
|
18
157
|
def write_tess(
|
|
19
158
|
atoms: Union['Atoms', List['Atoms']],
|
|
20
159
|
filename: str,
|
|
@@ -269,6 +408,25 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
|
|
|
269
408
|
# Enable numpy array deserialization
|
|
270
409
|
m.patch()
|
|
271
410
|
|
|
411
|
+
# Read header once using helper
|
|
412
|
+
header = _read_tess_header(filename)
|
|
413
|
+
|
|
414
|
+
format_version = header.get('format_version', 1)
|
|
415
|
+
compression_info = header.get('compression')
|
|
416
|
+
if isinstance(compression_info, dict):
|
|
417
|
+
compression_type = compression_info.get('type', 'none')
|
|
418
|
+
elif isinstance(compression_info, str):
|
|
419
|
+
compression_type = compression_info
|
|
420
|
+
else:
|
|
421
|
+
compression_type = 'none'
|
|
422
|
+
compression_type = (compression_type or 'none').lower()
|
|
423
|
+
if compression_type not in {'none', 'zlib', 'lz4'}:
|
|
424
|
+
raise ValueError(f"Unsupported compression type '{compression_type}' in tess file")
|
|
425
|
+
|
|
426
|
+
metadata = header.get('metadata', {})
|
|
427
|
+
frame_offsets = [tuple(offset) for offset in header['frame_offsets']]
|
|
428
|
+
num_frames = len(frame_offsets)
|
|
429
|
+
|
|
272
430
|
with open(filename, 'rb') as f:
|
|
273
431
|
# Use mmap with larger read-ahead hint
|
|
274
432
|
mm = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
|
|
@@ -278,30 +436,6 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
|
|
|
278
436
|
import mmap as mmap_module
|
|
279
437
|
if hasattr(mmap_module, 'MADV_SEQUENTIAL'):
|
|
280
438
|
mm.madvise(mmap_module.MADV_SEQUENTIAL)
|
|
281
|
-
|
|
282
|
-
file_size = mm.size()
|
|
283
|
-
header_start = int.from_bytes(mm[file_size - 8:file_size], 'little')
|
|
284
|
-
header_bytes = mm[header_start:file_size - 8]
|
|
285
|
-
header = msgpack.unpackb(header_bytes, raw=False, strict_map_key=False)
|
|
286
|
-
|
|
287
|
-
format_version = header.get('format_version', 1)
|
|
288
|
-
if format_version not in {2, 3, 4, 5}:
|
|
289
|
-
raise ValueError("Invalid format version")
|
|
290
|
-
|
|
291
|
-
compression_info = header.get('compression')
|
|
292
|
-
if isinstance(compression_info, dict):
|
|
293
|
-
compression_type = compression_info.get('type', 'none')
|
|
294
|
-
elif isinstance(compression_info, str):
|
|
295
|
-
compression_type = compression_info
|
|
296
|
-
else:
|
|
297
|
-
compression_type = 'none'
|
|
298
|
-
compression_type = (compression_type or 'none').lower()
|
|
299
|
-
if compression_type not in {'none', 'zlib', 'lz4'}:
|
|
300
|
-
raise ValueError(f"Unsupported compression type '{compression_type}' in tess file")
|
|
301
|
-
|
|
302
|
-
metadata = header.get('metadata', {})
|
|
303
|
-
frame_offsets = [tuple(offset) for offset in header['frame_offsets']]
|
|
304
|
-
num_frames = len(frame_offsets)
|
|
305
439
|
|
|
306
440
|
# Determine which frames to load
|
|
307
441
|
if frames_indices is not None:
|
|
@@ -319,7 +453,7 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
|
|
|
319
453
|
|
|
320
454
|
# Pre-allocate the result list based on requested frames
|
|
321
455
|
atoms_list: List[Optional[Atoms]] = [None] * len(frames_to_load)
|
|
322
|
-
|
|
456
|
+
|
|
323
457
|
# Handle format version 4/5 with static data
|
|
324
458
|
if format_version in {4, 5}:
|
|
325
459
|
static_data = header.get('static_data', {})
|
|
@@ -334,7 +468,7 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
|
|
|
334
468
|
static_tags = static_data.get('tags')
|
|
335
469
|
static_init_charges = static_data.get('initial_charges')
|
|
336
470
|
static_init_magmoms = static_data.get('initial_magmoms')
|
|
337
|
-
|
|
471
|
+
|
|
338
472
|
# Create a template Atoms object to clone for efficiency
|
|
339
473
|
template_atoms = Atoms(numbers=numbers, pbc=pbc)
|
|
340
474
|
template_atoms.set_masses(masses)
|
|
@@ -350,72 +484,14 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
|
|
|
350
484
|
convert = dict_to_atoms
|
|
351
485
|
static_data = None
|
|
352
486
|
cell_changes = True
|
|
353
|
-
|
|
354
|
-
# Process frames with minimal overhead
|
|
355
|
-
if compression_type == 'zlib' and len(filtered_offsets) > 0:
|
|
356
|
-
|
|
357
|
-
def _decompress(idx_offset: Tuple[int, Tuple[int, int]]) -> Tuple[int, bytes]:
|
|
358
|
-
orig_idx, (start, length) = idx_offset
|
|
359
|
-
compressed = mm[start:start + length]
|
|
360
|
-
return orig_idx, zlib.decompress(compressed)
|
|
361
487
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
for chunk_start in range(0, len(filtered_offsets), chunk_size):
|
|
367
|
-
offset_chunk = filtered_offsets[chunk_start:chunk_start + chunk_size]
|
|
368
|
-
for result_idx, (orig_idx, frame_bytes) in enumerate(
|
|
369
|
-
executor.map(_decompress, offset_chunk), start=0
|
|
370
|
-
):
|
|
371
|
-
frame_dict = msgpack.unpackb(
|
|
372
|
-
frame_bytes, raw=False, strict_map_key=False
|
|
373
|
-
)
|
|
374
|
-
if format_version in {4, 5}:
|
|
375
|
-
# Fast path for v4/v5: clone template and update changing data
|
|
376
|
-
atoms = template_atoms.copy()
|
|
377
|
-
atoms.set_positions(frame_dict['positions'])
|
|
378
|
-
if cell_changes and 'cell' in frame_dict:
|
|
379
|
-
atoms.set_cell(frame_dict['cell'])
|
|
380
|
-
# v5: restore additional properties if present
|
|
381
|
-
if format_version == 5:
|
|
382
|
-
if 'tags' in frame_dict:
|
|
383
|
-
atoms.set_tags(frame_dict['tags'])
|
|
384
|
-
if 'initial_charges' in frame_dict:
|
|
385
|
-
atoms.set_initial_charges(frame_dict['initial_charges'])
|
|
386
|
-
if 'initial_magmoms' in frame_dict:
|
|
387
|
-
atoms.set_initial_magnetic_moments(frame_dict['initial_magmoms'])
|
|
388
|
-
if 'momenta' in frame_dict:
|
|
389
|
-
atoms.set_momenta(frame_dict['momenta'])
|
|
390
|
-
if 'forces' in frame_dict:
|
|
391
|
-
atoms.arrays['forces'] = frame_dict['forces']
|
|
392
|
-
if 'info' in frame_dict and isinstance(frame_dict['info'], dict):
|
|
393
|
-
atoms.info.update(frame_dict['info'])
|
|
394
|
-
if 'custom_arrays' in frame_dict and isinstance(frame_dict['custom_arrays'], dict):
|
|
395
|
-
for k, v in frame_dict['custom_arrays'].items():
|
|
396
|
-
atoms.arrays[k] = v
|
|
397
|
-
# Calculator results (merge stress if present)
|
|
398
|
-
calc_data = {}
|
|
399
|
-
if 'calc_results' in frame_dict and isinstance(frame_dict['calc_results'], dict):
|
|
400
|
-
calc_data = dict(frame_dict['calc_results'])
|
|
401
|
-
if 'stress' in frame_dict:
|
|
402
|
-
calc_data['stress'] = frame_dict['stress']
|
|
403
|
-
if len(calc_data) > 0:
|
|
404
|
-
calc = SinglePointCalculator(atoms)
|
|
405
|
-
for key, value in calc_data.items():
|
|
406
|
-
if key != 'name':
|
|
407
|
-
calc.results[key] = value
|
|
408
|
-
if calc.results:
|
|
409
|
-
atoms.calc = calc
|
|
410
|
-
atoms_list[chunk_start + result_idx] = atoms
|
|
411
|
-
else:
|
|
412
|
-
atoms_list[chunk_start + result_idx] = convert(frame_dict)[0]
|
|
413
|
-
elif compression_type == 'lz4' and len(filtered_offsets) > 0:
|
|
414
|
-
|
|
415
|
-
def _decompress(idx_offset: Tuple[int, Tuple[int, int]]) -> Tuple[int, bytes]:
|
|
488
|
+
# Process frames with minimal overhead
|
|
489
|
+
if len(filtered_offsets) > 0:
|
|
490
|
+
# Unified decode path using helper; still parallelized
|
|
491
|
+
def _decode(idx_offset: Tuple[int, Tuple[int, int]]) -> Tuple[int, 'Atoms']:
|
|
416
492
|
orig_idx, (start, length) = idx_offset
|
|
417
|
-
|
|
418
|
-
return orig_idx,
|
|
493
|
+
raw_slice = mm[start:start + length]
|
|
494
|
+
return orig_idx, _decode_frame(raw_slice, header, template_atoms if format_version in {4, 5} else None)
|
|
419
495
|
|
|
420
496
|
worker_count = _max_workers(len(filtered_offsets))
|
|
421
497
|
chunk_size = _chunk_size(worker_count)
|
|
@@ -423,90 +499,10 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
|
|
|
423
499
|
with ThreadPoolExecutor(max_workers=worker_count) as executor:
|
|
424
500
|
for chunk_start in range(0, len(filtered_offsets), chunk_size):
|
|
425
501
|
offset_chunk = filtered_offsets[chunk_start:chunk_start + chunk_size]
|
|
426
|
-
for result_idx, (orig_idx,
|
|
427
|
-
executor.map(
|
|
502
|
+
for result_idx, (orig_idx, atoms) in enumerate(
|
|
503
|
+
executor.map(_decode, offset_chunk), start=0
|
|
428
504
|
):
|
|
429
|
-
|
|
430
|
-
frame_bytes, raw=False, strict_map_key=False
|
|
431
|
-
)
|
|
432
|
-
if format_version in {4, 5}:
|
|
433
|
-
atoms = template_atoms.copy()
|
|
434
|
-
atoms.set_positions(frame_dict['positions'])
|
|
435
|
-
if cell_changes and 'cell' in frame_dict:
|
|
436
|
-
atoms.set_cell(frame_dict['cell'])
|
|
437
|
-
if format_version == 5:
|
|
438
|
-
if 'tags' in frame_dict:
|
|
439
|
-
atoms.set_tags(frame_dict['tags'])
|
|
440
|
-
if 'initial_charges' in frame_dict:
|
|
441
|
-
atoms.set_initial_charges(frame_dict['initial_charges'])
|
|
442
|
-
if 'initial_magmoms' in frame_dict:
|
|
443
|
-
atoms.set_initial_magnetic_moments(frame_dict['initial_magmoms'])
|
|
444
|
-
if 'momenta' in frame_dict:
|
|
445
|
-
atoms.set_momenta(frame_dict['momenta'])
|
|
446
|
-
if 'forces' in frame_dict:
|
|
447
|
-
atoms.arrays['forces'] = frame_dict['forces']
|
|
448
|
-
if 'info' in frame_dict and isinstance(frame_dict['info'], dict):
|
|
449
|
-
atoms.info.update(frame_dict['info'])
|
|
450
|
-
if 'custom_arrays' in frame_dict and isinstance(frame_dict['custom_arrays'], dict):
|
|
451
|
-
for k, v in frame_dict['custom_arrays'].items():
|
|
452
|
-
atoms.arrays[k] = v
|
|
453
|
-
calc_data = {}
|
|
454
|
-
if 'calc_results' in frame_dict and isinstance(frame_dict['calc_results'], dict):
|
|
455
|
-
calc_data = dict(frame_dict['calc_results'])
|
|
456
|
-
if 'stress' in frame_dict:
|
|
457
|
-
calc_data['stress'] = frame_dict['stress']
|
|
458
|
-
if len(calc_data) > 0:
|
|
459
|
-
calc = SinglePointCalculator(atoms)
|
|
460
|
-
for key, value in calc_data.items():
|
|
461
|
-
if key != 'name':
|
|
462
|
-
calc.results[key] = value
|
|
463
|
-
if calc.results:
|
|
464
|
-
atoms.calc = calc
|
|
465
|
-
atoms_list[chunk_start + result_idx] = atoms
|
|
466
|
-
else:
|
|
467
|
-
atoms_list[chunk_start + result_idx] = convert(frame_dict)[0]
|
|
468
|
-
else:
|
|
469
|
-
for result_idx, (orig_idx, (start, length)) in enumerate(filtered_offsets):
|
|
470
|
-
frame_slice = mm[start:start + length]
|
|
471
|
-
frame_dict = msgpack.unpackb(
|
|
472
|
-
frame_slice, raw=False, strict_map_key=False
|
|
473
|
-
)
|
|
474
|
-
if format_version in {4, 5}:
|
|
475
|
-
atoms = template_atoms.copy()
|
|
476
|
-
atoms.set_positions(frame_dict['positions'])
|
|
477
|
-
if cell_changes and 'cell' in frame_dict:
|
|
478
|
-
atoms.set_cell(frame_dict['cell'])
|
|
479
|
-
if format_version == 5:
|
|
480
|
-
if 'tags' in frame_dict:
|
|
481
|
-
atoms.set_tags(frame_dict['tags'])
|
|
482
|
-
if 'initial_charges' in frame_dict:
|
|
483
|
-
atoms.set_initial_charges(frame_dict['initial_charges'])
|
|
484
|
-
if 'initial_magmoms' in frame_dict:
|
|
485
|
-
atoms.set_initial_magnetic_moments(frame_dict['initial_magmoms'])
|
|
486
|
-
if 'momenta' in frame_dict:
|
|
487
|
-
atoms.set_momenta(frame_dict['momenta'])
|
|
488
|
-
if 'forces' in frame_dict:
|
|
489
|
-
atoms.arrays['forces'] = frame_dict['forces']
|
|
490
|
-
if 'info' in frame_dict and isinstance(frame_dict['info'], dict):
|
|
491
|
-
atoms.info.update(frame_dict['info'])
|
|
492
|
-
if 'custom_arrays' in frame_dict and isinstance(frame_dict['custom_arrays'], dict):
|
|
493
|
-
for k, v in frame_dict['custom_arrays'].items():
|
|
494
|
-
atoms.arrays[k] = v
|
|
495
|
-
calc_data = {}
|
|
496
|
-
if 'calc_results' in frame_dict and isinstance(frame_dict['calc_results'], dict):
|
|
497
|
-
calc_data = dict(frame_dict['calc_results'])
|
|
498
|
-
if 'stress' in frame_dict:
|
|
499
|
-
calc_data['stress'] = frame_dict['stress']
|
|
500
|
-
if len(calc_data) > 0:
|
|
501
|
-
calc = SinglePointCalculator(atoms)
|
|
502
|
-
for key, value in calc_data.items():
|
|
503
|
-
if key != 'name':
|
|
504
|
-
calc.results[key] = value
|
|
505
|
-
if calc.results:
|
|
506
|
-
atoms.calc = calc
|
|
507
|
-
atoms_list[result_idx] = atoms
|
|
508
|
-
else:
|
|
509
|
-
atoms_list[result_idx] = convert(frame_dict)[0]
|
|
505
|
+
atoms_list[chunk_start + result_idx] = atoms
|
|
510
506
|
finally:
|
|
511
507
|
mm.close()
|
|
512
508
|
|
atomict/io/trajectory.py
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
from typing import Any, Dict, Iterator, List, Optional, Union, TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
if TYPE_CHECKING:
|
|
4
|
+
from ase import Atoms
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from ase.parallel import world
|
|
8
|
+
except Exception:
|
|
9
|
+
# Fallback if ASE parallel is unavailable
|
|
10
|
+
class _DummyWorld:
|
|
11
|
+
rank = 0
|
|
12
|
+
|
|
13
|
+
def sum_scalar(self, x):
|
|
14
|
+
return x
|
|
15
|
+
|
|
16
|
+
world = _DummyWorld() # type: ignore[assignment]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TrajectoryWriter:
|
|
20
|
+
"""Unified trajectory writer supporting .traj (ASE), .atraj and .tess formats.
|
|
21
|
+
|
|
22
|
+
Mirrors the ASE TrajectoryWriter API for use in optimizers (e.g., BFGS(trajectory=...)).
|
|
23
|
+
Frames are written incrementally for .traj and buffered for .atraj/.tess (flushed on close).
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
filename: str,
|
|
29
|
+
mode: str = "w",
|
|
30
|
+
atoms: Optional['Atoms'] = None,
|
|
31
|
+
properties: Optional[List[str]] = None,
|
|
32
|
+
master: Optional[bool] = None,
|
|
33
|
+
comm: Any = world,
|
|
34
|
+
metadata: Optional[Dict] = None,
|
|
35
|
+
tess_compression: Optional[str] = "zlib",
|
|
36
|
+
tess_compression_level: int = 1,
|
|
37
|
+
) -> None:
|
|
38
|
+
"""Create a trajectory writer.
|
|
39
|
+
|
|
40
|
+
Parameters mirror ASE's writer; extra kwargs configure tess compression and metadata.
|
|
41
|
+
"""
|
|
42
|
+
# Deferred imports to avoid hard dependency during import time
|
|
43
|
+
from ase import Atoms # type: ignore
|
|
44
|
+
|
|
45
|
+
if mode not in {"w", "a"}:
|
|
46
|
+
raise ValueError('mode must be "w" or "a".')
|
|
47
|
+
|
|
48
|
+
self.filename = filename
|
|
49
|
+
self.mode = mode
|
|
50
|
+
self.atoms_default: Optional[Atoms] = atoms
|
|
51
|
+
self.properties = properties
|
|
52
|
+
self.comm = comm
|
|
53
|
+
self.master = (comm.rank == 0) if master is None else bool(master)
|
|
54
|
+
self._description: Dict[str, Any] = dict(metadata or {})
|
|
55
|
+
|
|
56
|
+
# Backend selection by extension
|
|
57
|
+
lower = filename.lower()
|
|
58
|
+
if lower.endswith(".traj"):
|
|
59
|
+
# Stream via ASE backend
|
|
60
|
+
from ase.io.trajectory import TrajectoryWriter as _ASEWriter
|
|
61
|
+
|
|
62
|
+
self._backend = _ASEWriter(filename, mode=mode, atoms=atoms, properties=properties, master=self.master, comm=comm)
|
|
63
|
+
self._backend_is_ase = True
|
|
64
|
+
self._buffer: Optional[List[Atoms]] = None
|
|
65
|
+
else:
|
|
66
|
+
# Buffer frames and flush on close for msgpack-based formats
|
|
67
|
+
self._backend = None
|
|
68
|
+
self._backend_is_ase = False
|
|
69
|
+
self._buffer = []
|
|
70
|
+
# Tess config
|
|
71
|
+
self._tess_compression = tess_compression
|
|
72
|
+
self._tess_compression_level = int(tess_compression_level)
|
|
73
|
+
|
|
74
|
+
def __enter__(self) -> "TrajectoryWriter":
|
|
75
|
+
return self
|
|
76
|
+
|
|
77
|
+
def __exit__(self, exc_type, exc_value, tb) -> None:
|
|
78
|
+
self.close()
|
|
79
|
+
|
|
80
|
+
def set_description(self, description: Dict[str, Any]) -> None:
|
|
81
|
+
# match ASE method name for compatibility
|
|
82
|
+
self._description.update(description or {})
|
|
83
|
+
|
|
84
|
+
def write(self, atoms: Optional['Atoms'] = None, **kwargs: Any) -> None:
|
|
85
|
+
"""Write a single frame. If atoms is None, uses atoms passed to __init__.
|
|
86
|
+
|
|
87
|
+
For .traj, delegates to ASE. For .atraj/.tess, buffers frames and writes on close.
|
|
88
|
+
"""
|
|
89
|
+
from ase import Atoms # type: ignore
|
|
90
|
+
|
|
91
|
+
image: Optional[Atoms] = atoms if atoms is not None else self.atoms_default
|
|
92
|
+
if image is None:
|
|
93
|
+
raise ValueError("No Atoms provided to write() and no default atoms set.")
|
|
94
|
+
|
|
95
|
+
if self._backend_is_ase:
|
|
96
|
+
# Pass through calculator properties if provided in kwargs, ASE handles it
|
|
97
|
+
self._backend.write(image, **kwargs)
|
|
98
|
+
else:
|
|
99
|
+
# Buffer plain ASE Atoms; handle OptimizableAtoms or wrappers
|
|
100
|
+
from ase import Atoms # type: ignore
|
|
101
|
+
|
|
102
|
+
plain: Optional[Atoms] = None
|
|
103
|
+
if isinstance(image, Atoms):
|
|
104
|
+
plain = image
|
|
105
|
+
else:
|
|
106
|
+
# Try common wrapper escape hatches
|
|
107
|
+
get_atoms = getattr(image, 'get_atoms', None)
|
|
108
|
+
if callable(get_atoms):
|
|
109
|
+
maybe_atoms = get_atoms()
|
|
110
|
+
if isinstance(maybe_atoms, Atoms):
|
|
111
|
+
plain = maybe_atoms
|
|
112
|
+
if plain is None:
|
|
113
|
+
inner = getattr(image, 'atoms', None)
|
|
114
|
+
if isinstance(inner, Atoms):
|
|
115
|
+
plain = inner
|
|
116
|
+
if plain is None:
|
|
117
|
+
# Best-effort reconstruction
|
|
118
|
+
numbers = getattr(image, 'get_atomic_numbers', lambda: None)()
|
|
119
|
+
positions = getattr(image, 'get_positions', lambda: None)()
|
|
120
|
+
cell = getattr(image, 'get_cell', lambda: None)()
|
|
121
|
+
pbc = getattr(image, 'get_pbc', lambda: None)()
|
|
122
|
+
if numbers is None or positions is None:
|
|
123
|
+
raise TypeError('Unsupported atoms-like object; expected ASE Atoms or compatible wrapper')
|
|
124
|
+
plain = Atoms(numbers=numbers, positions=positions, cell=cell, pbc=pbc)
|
|
125
|
+
# Make a copy to avoid all frames pointing to the same object after in-place modifications
|
|
126
|
+
self._buffer.append(plain.copy())
|
|
127
|
+
|
|
128
|
+
def close(self) -> None:
|
|
129
|
+
"""Flush buffered frames and/or close backend."""
|
|
130
|
+
if self._backend_is_ase:
|
|
131
|
+
self._backend.close()
|
|
132
|
+
return
|
|
133
|
+
|
|
134
|
+
# Write buffered frames using the chosen msgpack-based format
|
|
135
|
+
if not self.master:
|
|
136
|
+
# Only master writes similar to ASE semantics
|
|
137
|
+
self._buffer = []
|
|
138
|
+
return
|
|
139
|
+
|
|
140
|
+
if not self._buffer:
|
|
141
|
+
# Nothing to write
|
|
142
|
+
return
|
|
143
|
+
|
|
144
|
+
lower = self.filename.lower()
|
|
145
|
+
frames = self._buffer
|
|
146
|
+
|
|
147
|
+
if lower.endswith('.atraj'):
|
|
148
|
+
from atomict.io.formats.atraj import write_atraj
|
|
149
|
+
|
|
150
|
+
write_atraj(frames, self.filename, metadata=self._description or None)
|
|
151
|
+
elif lower.endswith('.tess'):
|
|
152
|
+
from atomict.io.formats.tess import write_tess
|
|
153
|
+
|
|
154
|
+
write_tess(
|
|
155
|
+
frames,
|
|
156
|
+
self.filename,
|
|
157
|
+
metadata=self._description or None,
|
|
158
|
+
compression=self._tess_compression,
|
|
159
|
+
compression_level=self._tess_compression_level,
|
|
160
|
+
)
|
|
161
|
+
else:
|
|
162
|
+
# Fallback: use ASE .traj if unknown extension
|
|
163
|
+
from ase.io.trajectory import TrajectoryWriter as _ASEWriter
|
|
164
|
+
|
|
165
|
+
with _ASEWriter(self.filename, mode=self.mode, properties=self.properties, master=self.master, comm=self.comm) as tw:
|
|
166
|
+
for fr in frames:
|
|
167
|
+
tw.write(fr)
|
|
168
|
+
|
|
169
|
+
# Clear buffer after writing
|
|
170
|
+
self._buffer = []
|
|
171
|
+
|
|
172
|
+
def __len__(self) -> int:
|
|
173
|
+
if self._backend_is_ase:
|
|
174
|
+
return self.comm.sum_scalar(len(self._backend))
|
|
175
|
+
return len(self._buffer or [])
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
class TrajectoryReader:
|
|
179
|
+
"""Unified trajectory reader supporting .traj (ASE), .atraj and .tess formats.
|
|
180
|
+
|
|
181
|
+
Provides random access (__getitem__), slicing, iteration, and length like ASE's reader.
|
|
182
|
+
"""
|
|
183
|
+
|
|
184
|
+
def __init__(self, filename: str) -> None:
|
|
185
|
+
self.filename = filename
|
|
186
|
+
self._metadata: Dict[str, Any] = {}
|
|
187
|
+
lower = filename.lower()
|
|
188
|
+
if lower.endswith('.traj'):
|
|
189
|
+
from ase.io.trajectory import TrajectoryReader as _ASEReader
|
|
190
|
+
|
|
191
|
+
self._backend = _ASEReader(filename)
|
|
192
|
+
self._backend_is_ase = True
|
|
193
|
+
self._frames: Optional[List['Atoms']] = None
|
|
194
|
+
elif lower.endswith('.atraj'):
|
|
195
|
+
from atomict.io.formats.atraj import read_atraj
|
|
196
|
+
|
|
197
|
+
frames, meta = read_atraj(filename)
|
|
198
|
+
self._frames = frames
|
|
199
|
+
self._metadata = meta or {}
|
|
200
|
+
self._backend = None
|
|
201
|
+
self._backend_is_ase = False
|
|
202
|
+
elif lower.endswith('.tess'):
|
|
203
|
+
from atomict.io.formats.tess import read_tess
|
|
204
|
+
|
|
205
|
+
frames, meta = read_tess(filename)
|
|
206
|
+
self._frames = frames
|
|
207
|
+
self._metadata = meta or {}
|
|
208
|
+
self._backend = None
|
|
209
|
+
self._backend_is_ase = False
|
|
210
|
+
else:
|
|
211
|
+
# Fallback to ASE reader
|
|
212
|
+
from ase.io.trajectory import TrajectoryReader as _ASEReader
|
|
213
|
+
|
|
214
|
+
self._backend = _ASEReader(filename)
|
|
215
|
+
self._backend_is_ase = True
|
|
216
|
+
self._frames = None
|
|
217
|
+
|
|
218
|
+
def __enter__(self) -> "TrajectoryReader":
|
|
219
|
+
return self
|
|
220
|
+
|
|
221
|
+
def __exit__(self, exc_type, exc_value, tb) -> None:
|
|
222
|
+
self.close()
|
|
223
|
+
|
|
224
|
+
def close(self) -> None:
|
|
225
|
+
if self._backend_is_ase and self._backend is not None:
|
|
226
|
+
self._backend.close()
|
|
227
|
+
|
|
228
|
+
def __len__(self) -> int:
|
|
229
|
+
if self._backend_is_ase and self._backend is not None:
|
|
230
|
+
return len(self._backend)
|
|
231
|
+
return len(self._frames or [])
|
|
232
|
+
|
|
233
|
+
def __getitem__(self, i: Union[int, slice]) -> Union['Atoms', List['Atoms']]:
|
|
234
|
+
if isinstance(i, slice):
|
|
235
|
+
if self._backend_is_ase and self._backend is not None:
|
|
236
|
+
return list(self._backend[i])
|
|
237
|
+
return (self._frames or [])[i]
|
|
238
|
+
# int index
|
|
239
|
+
if self._backend_is_ase and self._backend is not None:
|
|
240
|
+
return self._backend[i]
|
|
241
|
+
return (self._frames or [])[i]
|
|
242
|
+
|
|
243
|
+
def __iter__(self) -> Iterator['Atoms']:
|
|
244
|
+
if self._backend_is_ase and self._backend is not None:
|
|
245
|
+
for i in range(len(self._backend)):
|
|
246
|
+
yield self._backend[i]
|
|
247
|
+
else:
|
|
248
|
+
for fr in (self._frames or []):
|
|
249
|
+
yield fr
|
|
250
|
+
|
|
251
|
+
@property
|
|
252
|
+
def metadata(self) -> Dict[str, Any]:
|
|
253
|
+
return dict(self._metadata)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def Trajectory(filename: str, mode: str = 'r', atoms: Optional['Atoms'] = None, properties: Optional[List[str]] = None, master: Optional[bool] = None, comm: Any = world, **kwargs: Any):
|
|
257
|
+
"""Factory matching ASE's ase.io.trajectory.Trajectory API.
|
|
258
|
+
|
|
259
|
+
Returns TrajectoryReader in read mode, TrajectoryWriter otherwise.
|
|
260
|
+
"""
|
|
261
|
+
if mode == 'r':
|
|
262
|
+
return TrajectoryReader(filename)
|
|
263
|
+
return TrajectoryWriter(filename, mode=mode, atoms=atoms, properties=properties, master=master, comm=comm, **kwargs)
|
|
264
|
+
|
atomict/simulation/phonon.py
CHANGED
|
@@ -67,6 +67,16 @@ def create_phonon_run(project_id: str, source_geometry_id: str, action: str, nam
|
|
|
67
67
|
if action not in ["LAUNCH", "DRAFT"]:
|
|
68
68
|
raise ValueError(f"Invalid action: {action} (must be 'LAUNCH' or 'DRAFT')")
|
|
69
69
|
|
|
70
|
+
# Validate model is one of the supported constants
|
|
71
|
+
valid_models = [
|
|
72
|
+
MODEL_ORB_D3_V2,
|
|
73
|
+
MODEL_MATTERSIM_1_0_0_5M,
|
|
74
|
+
MODEL_ORB_V3_CONSERVATIVE,
|
|
75
|
+
MODEL_ESEN_30M_OAM,
|
|
76
|
+
]
|
|
77
|
+
if model not in valid_models:
|
|
78
|
+
raise ValueError(f"Invalid model: {model}")
|
|
79
|
+
|
|
70
80
|
payload = {
|
|
71
81
|
"project_id": project_id,
|
|
72
82
|
"source_geometry_id": source_geometry_id,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: atomict
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.23
|
|
4
4
|
Summary: The client application for the https://atomictessellator.com/
|
|
5
5
|
Author-email: Steven Anderson <steven@atomictessellator.com>, Alain Richardt <alain@atomictessellator.com>
|
|
6
6
|
License: MIT
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
atomict/__init__.py,sha256=nMXg9GFsk8gCcyBnh1MAeUPvo4Zcuv3sdwGHZrxfpPE,36
|
|
2
|
-
atomict/__version__.py,sha256=
|
|
2
|
+
atomict/__version__.py,sha256=y_Ev8AcJxzZe4ZJWlW3Wsver97OJUqU1nFSDqHzKBDw,23
|
|
3
3
|
atomict/api.py,sha256=1aI2qPMm6V9VY4PLR8LBMm2WwVCBB9pAL7sEowvjhtc,6706
|
|
4
4
|
atomict/auth.py,sha256=yMEaxaSg44tSDxr4x-bjwjjn9zIsqw_bVoKd01Zd9LU,987
|
|
5
5
|
atomict/env.py,sha256=RqK5SUfCDJ6aMGtCPhNmSrwsNZSjlGaDQYYk41oeBDc,2115
|
|
@@ -43,10 +43,11 @@ atomict/io/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
43
43
|
atomict/io/atoms.py,sha256=kdMnto7eyiY2zmoOvLlzbuTGUCIp4ViQGwLmf2m9fGU,13144
|
|
44
44
|
atomict/io/cif.py,sha256=o7oe6alug5ais2QnJhv88X7sAbZSbTkEWhHa-4Dkw1E,6040
|
|
45
45
|
atomict/io/fhiaims.py,sha256=4Z5oImjZuP-k8AudrMrXqvsO0IHajDy__h5NmLr1LGY,1197
|
|
46
|
+
atomict/io/trajectory.py,sha256=8ggVQ0zPbdicQ_sPqY7KN-TWjaN8nCfTYs5s8qQoMeo,9895
|
|
46
47
|
atomict/io/utils.py,sha256=ncA8XchNN3lJT8EhJK6tLJE9TvmHmPlxizTnY5ASvEc,272
|
|
47
48
|
atomict/io/formats/__init__.py,sha256=_wKNHpV0VZKh7mzO6kRfaETYPxg_DYbrJwH4kqduD9Q,300
|
|
48
49
|
atomict/io/formats/atraj.py,sha256=2aqS5Gcr_SzE-d-wG9FLr_ckyKFkLHSAqhZUR9cXyR4,3355
|
|
49
|
-
atomict/io/formats/tess.py,sha256=
|
|
50
|
+
atomict/io/formats/tess.py,sha256=tUyMucFgfEQDBWVM1-2yGzpkvNym0v0_RfSxE5H6sW0,21952
|
|
50
51
|
atomict/io/formats/traj.py,sha256=AaojyrUzTMiobt2Nhyc7UCjNX1efGnvhV6z1avPtK-4,2273
|
|
51
52
|
atomict/ml/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
52
53
|
atomict/ml/model.py,sha256=Ug6IyRNNQ5_SHnQabFHnCCAGTHa9jxrRAUAkBsdcjgo,279
|
|
@@ -72,7 +73,7 @@ atomict/simulation/mattergen.py,sha256=ybzJy0nwIAZhG8IIuhlmi-_J6lLyci3aVo35h2ni_
|
|
|
72
73
|
atomict/simulation/md.py,sha256=C32Sh2sv9PQ1lyGaWYFmG5evKk3Jqw0wel2ml4uPnJw,770
|
|
73
74
|
atomict/simulation/mlrelax.py,sha256=ZS9WoO9efHeSNXM-MxuqQMSWN54qDKLscBgxL4monfI,2841
|
|
74
75
|
atomict/simulation/models.py,sha256=RSVLldNurx7F-ijlrLuVyljMS06bsZCBFMXNcdzdOuU,115
|
|
75
|
-
atomict/simulation/phonon.py,sha256=
|
|
76
|
+
atomict/simulation/phonon.py,sha256=UG6v-mpfF-STw0DK-620v26Rpc2EzAx4K-8KykzHtm8,3080
|
|
76
77
|
atomict/simulation/qe.py,sha256=3PpqpA0Pn3FCGEgjaMnCidguhopGxFUDMaxwfIQF2FE,1700
|
|
77
78
|
atomict/simulation/sh.py,sha256=YymnH9q8aD_THiielicTKgPGcRunsAcoV5bZKu__L0w,609
|
|
78
79
|
atomict/simulation/sqs.py,sha256=1neQRVUy21R_UVusML6ocz6RVwxGUVh81CMr2TljGbw,1132
|
|
@@ -84,9 +85,9 @@ atomict/utils/tenacity.py,sha256=phc6YPEk7idqiFFeHeK-ngiAaqVOZFYp8S7dX1k-YXc,998
|
|
|
84
85
|
atomict/utils/traj.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
85
86
|
atomict/utils/fhiaims/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
86
87
|
atomict/utils/fhiaims/geometry.py,sha256=3Ap6gO7UsLFXBl9Ohv8Vmfpvwu0fohpzgdxOFGg6Tmc,2281
|
|
87
|
-
atomict-1.2.
|
|
88
|
-
atomict-1.2.
|
|
89
|
-
atomict-1.2.
|
|
90
|
-
atomict-1.2.
|
|
91
|
-
atomict-1.2.
|
|
92
|
-
atomict-1.2.
|
|
88
|
+
atomict-1.2.23.dist-info/licenses/LICENSE,sha256=fzvTkxUzi2u1cea_aRtmg5_mRk6ZyLWJJRr49K28qKg,1075
|
|
89
|
+
atomict-1.2.23.dist-info/METADATA,sha256=IAXk_IZpC7wP9n9A5HqB_4QxjcIM6YuTG5J-0U4WybQ,3359
|
|
90
|
+
atomict-1.2.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
91
|
+
atomict-1.2.23.dist-info/entry_points.txt,sha256=PozguIUgJUHgS65PSZBHNPUiwYGDwXa4vLZ7hde3aq8,47
|
|
92
|
+
atomict-1.2.23.dist-info/top_level.txt,sha256=CCo525YmAj7ZbToMmQcVKQ-JiIiFKiq3GmhIYCG2gaM,8
|
|
93
|
+
atomict-1.2.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|