atomict 1.2.21__tar.gz → 1.2.22__tar.gz

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.
Files changed (100) hide show
  1. {atomict-1.2.21 → atomict-1.2.22}/PKG-INFO +1 -1
  2. atomict-1.2.22/atomict/__version__.py +1 -0
  3. {atomict-1.2.21 → atomict-1.2.22}/atomict/io/formats/tess.py +169 -173
  4. atomict-1.2.22/atomict/io/trajectory.py +263 -0
  5. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/phonon.py +10 -0
  6. {atomict-1.2.21 → atomict-1.2.22}/atomict.egg-info/PKG-INFO +1 -1
  7. {atomict-1.2.21 → atomict-1.2.22}/atomict.egg-info/SOURCES.txt +1 -0
  8. atomict-1.2.21/atomict/__version__.py +0 -1
  9. {atomict-1.2.21 → atomict-1.2.22}/LICENSE +0 -0
  10. {atomict-1.2.21 → atomict-1.2.22}/README.md +0 -0
  11. {atomict-1.2.21 → atomict-1.2.22}/atomict/__init__.py +0 -0
  12. {atomict-1.2.21 → atomict-1.2.22}/atomict/api.py +0 -0
  13. {atomict-1.2.21 → atomict-1.2.22}/atomict/ase/atatoms.py +0 -0
  14. {atomict-1.2.21 → atomict-1.2.22}/atomict/auth.py +0 -0
  15. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/__init__.py +0 -0
  16. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/adsorbate.py +0 -0
  17. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/ai_assist.py +0 -0
  18. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/catalysis.py +0 -0
  19. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/common.py +0 -0
  20. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/exploration/__init__.py +0 -0
  21. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/exploration/soec.py +0 -0
  22. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/exploration/sqs.py +0 -0
  23. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/helpers.py +0 -0
  24. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/k8s.py +0 -0
  25. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/login.py +0 -0
  26. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/organization.py +0 -0
  27. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/project.py +0 -0
  28. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/simulation/__init__.py +0 -0
  29. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/simulation/catalysis.py +0 -0
  30. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/simulation/fhiaims.py +0 -0
  31. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/simulation/kpoint.py +0 -0
  32. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/simulation/vibes.py +0 -0
  33. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/simulation.py +0 -0
  34. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/task.py +0 -0
  35. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/token.py +0 -0
  36. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/traj.py +0 -0
  37. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/upload.py +0 -0
  38. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/commands/user.py +0 -0
  39. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/core/client.py +0 -0
  40. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/core/config.py +0 -0
  41. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/core/utils.py +0 -0
  42. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/ext/custom_classes.py +0 -0
  43. {atomict-1.2.21 → atomict-1.2.22}/atomict/cli/main.py +0 -0
  44. {atomict-1.2.21 → atomict-1.2.22}/atomict/env.py +0 -0
  45. {atomict-1.2.21 → atomict-1.2.22}/atomict/exceptions.py +0 -0
  46. {atomict-1.2.21 → atomict-1.2.22}/atomict/infra/__init__.py +0 -0
  47. {atomict-1.2.21 → atomict-1.2.22}/atomict/infra/distwork/__init__.py +0 -0
  48. {atomict-1.2.21 → atomict-1.2.22}/atomict/infra/distwork/environment.py +0 -0
  49. {atomict-1.2.21 → atomict-1.2.22}/atomict/infra/distwork/task.py +0 -0
  50. {atomict-1.2.21 → atomict-1.2.22}/atomict/infra/logging.py +0 -0
  51. {atomict-1.2.21 → atomict-1.2.22}/atomict/io/__init__.py +0 -0
  52. {atomict-1.2.21 → atomict-1.2.22}/atomict/io/atoms.py +0 -0
  53. {atomict-1.2.21 → atomict-1.2.22}/atomict/io/cif.py +0 -0
  54. {atomict-1.2.21 → atomict-1.2.22}/atomict/io/fhiaims.py +0 -0
  55. {atomict-1.2.21 → atomict-1.2.22}/atomict/io/formats/__init__.py +0 -0
  56. {atomict-1.2.21 → atomict-1.2.22}/atomict/io/formats/atraj.py +0 -0
  57. {atomict-1.2.21 → atomict-1.2.22}/atomict/io/formats/traj.py +0 -0
  58. {atomict-1.2.21 → atomict-1.2.22}/atomict/io/utils.py +0 -0
  59. {atomict-1.2.21 → atomict-1.2.22}/atomict/ml/__init__.py +0 -0
  60. {atomict-1.2.21 → atomict-1.2.22}/atomict/ml/model.py +0 -0
  61. {atomict-1.2.21 → atomict-1.2.22}/atomict/project/__init__.py +0 -0
  62. {atomict-1.2.21 → atomict-1.2.22}/atomict/project/link.py +0 -0
  63. {atomict-1.2.21 → atomict-1.2.22}/atomict/project/note.py +0 -0
  64. {atomict-1.2.21 → atomict-1.2.22}/atomict/project/project.py +0 -0
  65. {atomict-1.2.21 → atomict-1.2.22}/atomict/project/tags.py +0 -0
  66. {atomict-1.2.21 → atomict-1.2.22}/atomict/project/workbench.py +0 -0
  67. {atomict-1.2.21 → atomict-1.2.22}/atomict/reality/__init__.py +0 -0
  68. {atomict-1.2.21 → atomict-1.2.22}/atomict/reality/oqmd.py +0 -0
  69. {atomict-1.2.21 → atomict-1.2.22}/atomict/reality/slabs.py +0 -0
  70. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/__init__.py +0 -0
  71. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/cantera.py +0 -0
  72. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/catalysis.py +0 -0
  73. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/counterfactual.py +0 -0
  74. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/defect.py +0 -0
  75. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/ea.py +0 -0
  76. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/fhi_aims.py +0 -0
  77. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/impact.py +0 -0
  78. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/kpoint.py +0 -0
  79. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/mattergen.py +0 -0
  80. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/md.py +0 -0
  81. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/mlrelax.py +0 -0
  82. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/models.py +0 -0
  83. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/qe.py +0 -0
  84. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/sh.py +0 -0
  85. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/sqs.py +0 -0
  86. {atomict-1.2.21 → atomict-1.2.22}/atomict/simulation/utils.py +0 -0
  87. {atomict-1.2.21 → atomict-1.2.22}/atomict/user/__init__.py +0 -0
  88. {atomict-1.2.21 → atomict-1.2.22}/atomict/user/files.py +0 -0
  89. {atomict-1.2.21 → atomict-1.2.22}/atomict/user/workspace.py +0 -0
  90. {atomict-1.2.21 → atomict-1.2.22}/atomict/utils/fhiaims/__init__.py +0 -0
  91. {atomict-1.2.21 → atomict-1.2.22}/atomict/utils/fhiaims/geometry.py +0 -0
  92. {atomict-1.2.21 → atomict-1.2.22}/atomict/utils/tenacity.py +0 -0
  93. {atomict-1.2.21 → atomict-1.2.22}/atomict/utils/traj.py +0 -0
  94. {atomict-1.2.21 → atomict-1.2.22}/atomict.egg-info/dependency_links.txt +0 -0
  95. {atomict-1.2.21 → atomict-1.2.22}/atomict.egg-info/entry_points.txt +0 -0
  96. {atomict-1.2.21 → atomict-1.2.22}/atomict.egg-info/requires.txt +0 -0
  97. {atomict-1.2.21 → atomict-1.2.22}/atomict.egg-info/top_level.txt +0 -0
  98. {atomict-1.2.21 → atomict-1.2.22}/pyproject.toml +0 -0
  99. {atomict-1.2.21 → atomict-1.2.22}/requirements.txt +0 -0
  100. {atomict-1.2.21 → atomict-1.2.22}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atomict
3
- Version: 1.2.21
3
+ Version: 1.2.22
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
@@ -0,0 +1 @@
1
+ __version__ = "1.2.22"
@@ -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
- worker_count = _max_workers(len(filtered_offsets))
363
- chunk_size = _chunk_size(worker_count)
364
-
365
- with ThreadPoolExecutor(max_workers=worker_count) as executor:
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
- compressed = mm[start:start + length]
418
- return orig_idx, lz4.block.decompress(compressed)
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, frame_bytes) in enumerate(
427
- executor.map(_decompress, offset_chunk), start=0
502
+ for result_idx, (orig_idx, atoms) in enumerate(
503
+ executor.map(_decode, offset_chunk), start=0
428
504
  ):
429
- frame_dict = msgpack.unpackb(
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
 
@@ -0,0 +1,263 @@
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
+ self._buffer.append(plain)
126
+
127
+ def close(self) -> None:
128
+ """Flush buffered frames and/or close backend."""
129
+ if self._backend_is_ase:
130
+ self._backend.close()
131
+ return
132
+
133
+ # Write buffered frames using the chosen msgpack-based format
134
+ if not self.master:
135
+ # Only master writes similar to ASE semantics
136
+ self._buffer = []
137
+ return
138
+
139
+ if not self._buffer:
140
+ # Nothing to write
141
+ return
142
+
143
+ lower = self.filename.lower()
144
+ frames = self._buffer
145
+
146
+ if lower.endswith('.atraj'):
147
+ from atomict.io.formats.atraj import write_atraj
148
+
149
+ write_atraj(frames, self.filename, metadata=self._description or None)
150
+ elif lower.endswith('.tess'):
151
+ from atomict.io.formats.tess import write_tess
152
+
153
+ write_tess(
154
+ frames,
155
+ self.filename,
156
+ metadata=self._description or None,
157
+ compression=self._tess_compression,
158
+ compression_level=self._tess_compression_level,
159
+ )
160
+ else:
161
+ # Fallback: use ASE .traj if unknown extension
162
+ from ase.io.trajectory import TrajectoryWriter as _ASEWriter
163
+
164
+ with _ASEWriter(self.filename, mode=self.mode, properties=self.properties, master=self.master, comm=self.comm) as tw:
165
+ for fr in frames:
166
+ tw.write(fr)
167
+
168
+ # Clear buffer after writing
169
+ self._buffer = []
170
+
171
+ def __len__(self) -> int:
172
+ if self._backend_is_ase:
173
+ return self.comm.sum_scalar(len(self._backend))
174
+ return len(self._buffer or [])
175
+
176
+
177
+ class TrajectoryReader:
178
+ """Unified trajectory reader supporting .traj (ASE), .atraj and .tess formats.
179
+
180
+ Provides random access (__getitem__), slicing, iteration, and length like ASE's reader.
181
+ """
182
+
183
+ def __init__(self, filename: str) -> None:
184
+ self.filename = filename
185
+ self._metadata: Dict[str, Any] = {}
186
+ lower = filename.lower()
187
+ if lower.endswith('.traj'):
188
+ from ase.io.trajectory import TrajectoryReader as _ASEReader
189
+
190
+ self._backend = _ASEReader(filename)
191
+ self._backend_is_ase = True
192
+ self._frames: Optional[List['Atoms']] = None
193
+ elif lower.endswith('.atraj'):
194
+ from atomict.io.formats.atraj import read_atraj
195
+
196
+ frames, meta = read_atraj(filename)
197
+ self._frames = frames
198
+ self._metadata = meta or {}
199
+ self._backend = None
200
+ self._backend_is_ase = False
201
+ elif lower.endswith('.tess'):
202
+ from atomict.io.formats.tess import read_tess
203
+
204
+ frames, meta = read_tess(filename)
205
+ self._frames = frames
206
+ self._metadata = meta or {}
207
+ self._backend = None
208
+ self._backend_is_ase = False
209
+ else:
210
+ # Fallback to ASE reader
211
+ from ase.io.trajectory import TrajectoryReader as _ASEReader
212
+
213
+ self._backend = _ASEReader(filename)
214
+ self._backend_is_ase = True
215
+ self._frames = None
216
+
217
+ def __enter__(self) -> "TrajectoryReader":
218
+ return self
219
+
220
+ def __exit__(self, exc_type, exc_value, tb) -> None:
221
+ self.close()
222
+
223
+ def close(self) -> None:
224
+ if self._backend_is_ase and self._backend is not None:
225
+ self._backend.close()
226
+
227
+ def __len__(self) -> int:
228
+ if self._backend_is_ase and self._backend is not None:
229
+ return len(self._backend)
230
+ return len(self._frames or [])
231
+
232
+ def __getitem__(self, i: Union[int, slice]) -> Union['Atoms', List['Atoms']]:
233
+ if isinstance(i, slice):
234
+ if self._backend_is_ase and self._backend is not None:
235
+ return list(self._backend[i])
236
+ return (self._frames or [])[i]
237
+ # int index
238
+ if self._backend_is_ase and self._backend is not None:
239
+ return self._backend[i]
240
+ return (self._frames or [])[i]
241
+
242
+ def __iter__(self) -> Iterator['Atoms']:
243
+ if self._backend_is_ase and self._backend is not None:
244
+ for i in range(len(self._backend)):
245
+ yield self._backend[i]
246
+ else:
247
+ for fr in (self._frames or []):
248
+ yield fr
249
+
250
+ @property
251
+ def metadata(self) -> Dict[str, Any]:
252
+ return dict(self._metadata)
253
+
254
+
255
+ 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):
256
+ """Factory matching ASE's ase.io.trajectory.Trajectory API.
257
+
258
+ Returns TrajectoryReader in read mode, TrajectoryWriter otherwise.
259
+ """
260
+ if mode == 'r':
261
+ return TrajectoryReader(filename)
262
+ return TrajectoryWriter(filename, mode=mode, atoms=atoms, properties=properties, master=master, comm=comm, **kwargs)
263
+
@@ -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.21
3
+ Version: 1.2.22
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
@@ -53,6 +53,7 @@ atomict/io/__init__.py
53
53
  atomict/io/atoms.py
54
54
  atomict/io/cif.py
55
55
  atomict/io/fhiaims.py
56
+ atomict/io/trajectory.py
56
57
  atomict/io/utils.py
57
58
  atomict/io/formats/__init__.py
58
59
  atomict/io/formats/atraj.py
@@ -1 +0,0 @@
1
- __version__ = "1.2.21"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes