atomict 1.2.20__py3-none-any.whl → 1.2.21__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 CHANGED
@@ -1 +1 @@
1
- __version__ = "1.2.20"
1
+ __version__ = "1.2.21"
@@ -1,5 +1,5 @@
1
1
  from concurrent.futures import ThreadPoolExecutor
2
- from typing import Dict, List, Optional, Tuple, Union, TYPE_CHECKING
2
+ from typing import Dict, List, Optional, Tuple, Union, TYPE_CHECKING, Any, cast
3
3
 
4
4
  if TYPE_CHECKING:
5
5
  from ase import Atoms
@@ -67,14 +67,106 @@ def write_tess(
67
67
  positions_list = [a.get_positions().astype(np.float32) for a in frames_list]
68
68
  if cell_changes:
69
69
  cells_list = [np.array(a.get_cell(), dtype=np.float32) for a in frames_list]
70
+
71
+ # Ensure constant atom count and species across frames for tess format
72
+ first_numbers = np.asarray(frames_list[0].get_atomic_numbers())
73
+ for a in frames_list[1:]:
74
+ if len(a) != len(frames_list[0]) or not np.array_equal(np.asarray(a.get_atomic_numbers()), first_numbers):
75
+ raise ValueError("tess format requires constant atom count and species across frames")
76
+
77
+ # Determine static vs per-frame ASE arrays
78
+ first_tags = np.asarray(frames_list[0].get_tags())
79
+ tags_static = all(np.array_equal(np.asarray(a.get_tags()), first_tags) for a in frames_list)
80
+
81
+ first_init_charges = np.asarray(frames_list[0].get_initial_charges())
82
+ init_charges_static = all(np.array_equal(np.asarray(a.get_initial_charges()), first_init_charges) for a in frames_list)
83
+
84
+ first_init_magmoms = np.asarray(frames_list[0].get_initial_magnetic_moments())
85
+ init_magmoms_static = all(np.array_equal(np.asarray(a.get_initial_magnetic_moments()), first_init_magmoms) for a in frames_list)
86
+
87
+ # Per-frame dynamic arrays/props presence checks
88
+ has_any_momenta = any(np.any(np.abs(a.get_momenta()) > 1e-10) for a in frames_list)
89
+ has_any_forces = any('forces' in a.arrays for a in frames_list)
90
+ has_any_stress = any(hasattr(a, 'stress') and getattr(a, 'stress') is not None for a in frames_list)
91
+
92
+ # Helper to extract calculator results per frame (aligned with atoms_to_dict)
93
+ def _calc_results_for(a):
94
+ calc_data = {}
95
+ calc_found = False
96
+ if hasattr(a, 'calc') and a.calc is not None:
97
+ calc_found = True
98
+ calc_data['name'] = a.calc.__class__.__name__
99
+ for prop in ['energy', 'free_energy', 'forces', 'stress', 'dipole', 'charges', 'magmom', 'magmoms']:
100
+ try:
101
+ if hasattr(a.calc, 'results') and prop in a.calc.results:
102
+ calc_data[prop] = a.calc.results[prop]
103
+ else:
104
+ value = a.calc.get_property(prop, a)
105
+ if value is not None:
106
+ calc_data[prop] = value
107
+ except Exception:
108
+ pass
109
+ if not calc_found and hasattr(a, 'info'):
110
+ calc_name = a.info.get('_calc_name')
111
+ if calc_name:
112
+ calc_data['name'] = calc_name
113
+ for key, value in a.info.items():
114
+ if key.startswith('_calc_') and key != '_calc_name':
115
+ calc_data[key[6:]] = value
116
+ return calc_data if len(calc_data) > 0 else None
117
+
118
+ has_any_calc = any(_calc_results_for(a) is not None for a in frames_list)
119
+
120
+ # Helper to serialize info dict values (to_dict/todict if available)
121
+ def _serialize_info(info: Dict) -> Dict:
122
+ out = {}
123
+ for k, v in (info or {}).items():
124
+ if hasattr(v, 'to_dict') and callable(v.to_dict):
125
+ out[k] = v.to_dict()
126
+ elif hasattr(v, 'todict') and callable(v.todict):
127
+ out[k] = v.todict()
128
+ else:
129
+ out[k] = v
130
+ return out
70
131
 
71
132
  # Optimized frame serialization - pack only essential per-frame data
72
133
  def _pack_frame(i: int) -> bytes:
73
134
  # Only pack data that changes between frames
135
+ a = frames_list[i]
74
136
  frame_dict = {'positions': positions_list[i]}
75
137
  if cell_changes:
76
138
  frame_dict['cell'] = cells_list[i]
77
- return msgpack.packb(frame_dict, use_bin_type=True)
139
+ # Per-frame arrays
140
+ if has_any_momenta:
141
+ frame_dict['momenta'] = a.get_momenta()
142
+ if not tags_static:
143
+ frame_dict['tags'] = a.get_tags()
144
+ if not init_charges_static:
145
+ frame_dict['initial_charges'] = a.get_initial_charges()
146
+ if not init_magmoms_static:
147
+ frame_dict['initial_magmoms'] = a.get_initial_magnetic_moments()
148
+ # Forces/stress
149
+ if has_any_forces and 'forces' in a.arrays:
150
+ frame_dict['forces'] = a.arrays['forces']
151
+ if has_any_stress and hasattr(a, 'stress') and getattr(a, 'stress') is not None:
152
+ frame_dict['stress'] = np.asarray(getattr(a, 'stress'), dtype=np.float64)
153
+ # Calculator results
154
+ if has_any_calc:
155
+ calc_data = _calc_results_for(a)
156
+ if calc_data is not None:
157
+ frame_dict['calc_results'] = calc_data
158
+ # Info dict
159
+ if hasattr(a, 'info') and a.info:
160
+ frame_dict['info'] = _serialize_info(a.info)
161
+ # Custom arrays
162
+ standard_arrays = {'numbers', 'positions', 'momenta', 'masses', 'tags', 'charges', 'forces'}
163
+ custom_arrays = {}
164
+ for key, value in a.arrays.items():
165
+ if key not in standard_arrays:
166
+ custom_arrays[key] = value
167
+ if custom_arrays:
168
+ frame_dict['custom_arrays'] = custom_arrays
169
+ return cast(bytes, msgpack.packb(frame_dict, use_bin_type=True))
78
170
 
79
171
  with open(filename, 'wb', buffering=1024*1024) as f:
80
172
  frame_offsets: List[Tuple[int, int]] = []
@@ -121,8 +213,8 @@ def write_tess(
121
213
  symbols_idx = np.array([unique_symbols_lookup[s] for s in symbols], dtype=np.uint16)
122
214
 
123
215
  # Write header
124
- header_dict: Dict[str, object] = {
125
- 'format_version': 4,
216
+ header_dict: Dict[str, Any] = {
217
+ 'format_version': 5,
126
218
  'metadata': dict(metadata or {}),
127
219
  'unique_symbols': unique_symbols,
128
220
  'num_frames': len(frames_list),
@@ -138,14 +230,20 @@ def write_tess(
138
230
  'cell_changes': cell_changes,
139
231
  }
140
232
  }
233
+ # Add static arrays when invariant across frames
234
+ if tags_static:
235
+ header_dict['static_data']['tags'] = first_tags
236
+ if init_charges_static:
237
+ header_dict['static_data']['initial_charges'] = first_init_charges
238
+ if init_magmoms_static:
239
+ header_dict['static_data']['initial_magmoms'] = first_init_magmoms
141
240
  if compression_mode != 'none':
142
- header_dict['compression'] = {
143
- 'type': compression_mode,
144
- }
241
+ comp_dict: Dict[str, Any] = {'type': compression_mode}
145
242
  if compression_mode == 'zlib':
146
- header_dict['compression']['level'] = compression_level
243
+ comp_dict['level'] = int(compression_level)
244
+ header_dict['compression'] = comp_dict
147
245
  header_dict['frame_uncompressed_lengths'] = uncompressed_lengths
148
- header_bytes = msgpack.packb(header_dict, use_bin_type=True)
246
+ header_bytes = cast(bytes, msgpack.packb(header_dict, use_bin_type=True))
149
247
  header_start = f.tell()
150
248
  f.write(header_bytes)
151
249
 
@@ -163,6 +261,8 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
163
261
  import mmap
164
262
  import zlib
165
263
  import lz4.block
264
+ import numpy as np
265
+ from ase.calculators.singlepoint import SinglePointCalculator
166
266
  except ImportError:
167
267
  raise ImportError("You need to install with `pip install atomict[utils]` to use the newer formats")
168
268
 
@@ -185,7 +285,7 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
185
285
  header = msgpack.unpackb(header_bytes, raw=False, strict_map_key=False)
186
286
 
187
287
  format_version = header.get('format_version', 1)
188
- if format_version not in {2, 3, 4}:
288
+ if format_version not in {2, 3, 4, 5}:
189
289
  raise ValueError("Invalid format version")
190
290
 
191
291
  compression_info = header.get('compression')
@@ -218,10 +318,10 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
218
318
  filtered_offsets = [(i, offset) for i, offset in enumerate(frame_offsets)]
219
319
 
220
320
  # Pre-allocate the result list based on requested frames
221
- atoms_list = [None] * len(frames_to_load)
321
+ atoms_list: List[Optional[Atoms]] = [None] * len(frames_to_load)
222
322
 
223
- # Handle format version 4 with static data
224
- if format_version == 4:
323
+ # Handle format version 4/5 with static data
324
+ if format_version in {4, 5}:
225
325
  static_data = header.get('static_data', {})
226
326
  unique_symbols = header['unique_symbols']
227
327
  symbols_idx = static_data['symbols']
@@ -231,13 +331,21 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
231
331
  pbc = static_data['pbc']
232
332
  static_cell = static_data.get('cell')
233
333
  cell_changes = static_data.get('cell_changes', True)
334
+ static_tags = static_data.get('tags')
335
+ static_init_charges = static_data.get('initial_charges')
336
+ static_init_magmoms = static_data.get('initial_magmoms')
234
337
 
235
338
  # Create a template Atoms object to clone for efficiency
236
- import numpy as np
237
339
  template_atoms = Atoms(numbers=numbers, pbc=pbc)
238
340
  template_atoms.set_masses(masses)
239
341
  if static_cell is not None:
240
342
  template_atoms.set_cell(static_cell)
343
+ if static_tags is not None:
344
+ template_atoms.set_tags(static_tags)
345
+ if static_init_charges is not None:
346
+ template_atoms.set_initial_charges(static_init_charges)
347
+ if static_init_magmoms is not None:
348
+ template_atoms.set_initial_magnetic_moments(static_init_magmoms)
241
349
  else:
242
350
  convert = dict_to_atoms
243
351
  static_data = None
@@ -263,12 +371,42 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
263
371
  frame_dict = msgpack.unpackb(
264
372
  frame_bytes, raw=False, strict_map_key=False
265
373
  )
266
- if format_version == 4:
267
- # Fast path for v4: clone template and update only changing data
374
+ if format_version in {4, 5}:
375
+ # Fast path for v4/v5: clone template and update changing data
268
376
  atoms = template_atoms.copy()
269
377
  atoms.set_positions(frame_dict['positions'])
270
378
  if cell_changes and 'cell' in frame_dict:
271
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
272
410
  atoms_list[chunk_start + result_idx] = atoms
273
411
  else:
274
412
  atoms_list[chunk_start + result_idx] = convert(frame_dict)[0]
@@ -291,11 +429,39 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
291
429
  frame_dict = msgpack.unpackb(
292
430
  frame_bytes, raw=False, strict_map_key=False
293
431
  )
294
- if format_version == 4:
432
+ if format_version in {4, 5}:
295
433
  atoms = template_atoms.copy()
296
434
  atoms.set_positions(frame_dict['positions'])
297
435
  if cell_changes and 'cell' in frame_dict:
298
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
299
465
  atoms_list[chunk_start + result_idx] = atoms
300
466
  else:
301
467
  atoms_list[chunk_start + result_idx] = convert(frame_dict)[0]
@@ -305,15 +471,43 @@ def read_tess(filename: str, frames_indices: Optional[List[int]] = None) -> Tupl
305
471
  frame_dict = msgpack.unpackb(
306
472
  frame_slice, raw=False, strict_map_key=False
307
473
  )
308
- if format_version == 4:
474
+ if format_version in {4, 5}:
309
475
  atoms = template_atoms.copy()
310
476
  atoms.set_positions(frame_dict['positions'])
311
477
  if cell_changes and 'cell' in frame_dict:
312
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
313
507
  atoms_list[result_idx] = atoms
314
508
  else:
315
509
  atoms_list[result_idx] = convert(frame_dict)[0]
316
510
  finally:
317
511
  mm.close()
318
512
 
319
- return atoms_list, metadata
513
+ return cast(List[Atoms], atoms_list), metadata
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atomict
3
- Version: 1.2.20
3
+ Version: 1.2.21
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=nQtXpLTEUbMtAPecTV_hZAJZb9EhWc8glRv6hgKyvG4,23
2
+ atomict/__version__.py,sha256=3uF8dV6igE_qWszFViblw_rtJOgCwoi-rVuWcQrSR0A,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
@@ -46,7 +46,7 @@ atomict/io/fhiaims.py,sha256=4Z5oImjZuP-k8AudrMrXqvsO0IHajDy__h5NmLr1LGY,1197
46
46
  atomict/io/utils.py,sha256=ncA8XchNN3lJT8EhJK6tLJE9TvmHmPlxizTnY5ASvEc,272
47
47
  atomict/io/formats/__init__.py,sha256=_wKNHpV0VZKh7mzO6kRfaETYPxg_DYbrJwH4kqduD9Q,300
48
48
  atomict/io/formats/atraj.py,sha256=2aqS5Gcr_SzE-d-wG9FLr_ckyKFkLHSAqhZUR9cXyR4,3355
49
- atomict/io/formats/tess.py,sha256=frQYIdNWE8NQL19F6BWV_lW6nJ9WwMX-yBrx_xmtSUA,14044
49
+ atomict/io/formats/tess.py,sha256=4cCVUFFZsSOVbU8TrvwV5nS_0hdjILNyc793V2UEURU,26006
50
50
  atomict/io/formats/traj.py,sha256=AaojyrUzTMiobt2Nhyc7UCjNX1efGnvhV6z1avPtK-4,2273
51
51
  atomict/ml/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
52
52
  atomict/ml/model.py,sha256=Ug6IyRNNQ5_SHnQabFHnCCAGTHa9jxrRAUAkBsdcjgo,279
@@ -84,9 +84,9 @@ atomict/utils/tenacity.py,sha256=phc6YPEk7idqiFFeHeK-ngiAaqVOZFYp8S7dX1k-YXc,998
84
84
  atomict/utils/traj.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
85
85
  atomict/utils/fhiaims/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
86
86
  atomict/utils/fhiaims/geometry.py,sha256=3Ap6gO7UsLFXBl9Ohv8Vmfpvwu0fohpzgdxOFGg6Tmc,2281
87
- atomict-1.2.20.dist-info/licenses/LICENSE,sha256=fzvTkxUzi2u1cea_aRtmg5_mRk6ZyLWJJRr49K28qKg,1075
88
- atomict-1.2.20.dist-info/METADATA,sha256=Sk30hOT87B04NfvZjw-rYasA_Xkf03tA_swSWn2aH3A,3359
89
- atomict-1.2.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
90
- atomict-1.2.20.dist-info/entry_points.txt,sha256=PozguIUgJUHgS65PSZBHNPUiwYGDwXa4vLZ7hde3aq8,47
91
- atomict-1.2.20.dist-info/top_level.txt,sha256=CCo525YmAj7ZbToMmQcVKQ-JiIiFKiq3GmhIYCG2gaM,8
92
- atomict-1.2.20.dist-info/RECORD,,
87
+ atomict-1.2.21.dist-info/licenses/LICENSE,sha256=fzvTkxUzi2u1cea_aRtmg5_mRk6ZyLWJJRr49K28qKg,1075
88
+ atomict-1.2.21.dist-info/METADATA,sha256=KwEJNZtwOT1QaWdw90lLmd0uUVA0W2pKc8HtP-boQ0s,3359
89
+ atomict-1.2.21.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
90
+ atomict-1.2.21.dist-info/entry_points.txt,sha256=PozguIUgJUHgS65PSZBHNPUiwYGDwXa4vLZ7hde3aq8,47
91
+ atomict-1.2.21.dist-info/top_level.txt,sha256=CCo525YmAj7ZbToMmQcVKQ-JiIiFKiq3GmhIYCG2gaM,8
92
+ atomict-1.2.21.dist-info/RECORD,,