pack-mm 0.0.22__py3-none-any.whl → 0.0.24__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.
pack_mm/core/core.py CHANGED
@@ -186,7 +186,7 @@ def set_defaults(
186
186
 
187
187
 
188
188
  def pack_molecules(
189
- system: str = None,
189
+ system: str | Atoms = None,
190
190
  molecule: str = "H2O",
191
191
  nmols: int = -1,
192
192
  arch: str = "cpu",
@@ -214,13 +214,13 @@ def pack_molecules(
214
214
  md_steps: int = 10,
215
215
  md_timestep: float = 1.0,
216
216
  md_temperature: float = 100.0,
217
- ) -> float:
217
+ ) -> tuple(float, Atoms):
218
218
  """
219
219
  Pack molecules into a system based on the specified parameters.
220
220
 
221
221
  Parameters
222
222
  ----------
223
- system (str): Path to the system file or name of the system.
223
+ system (str|Atoms): Path to the system file or name of the system.
224
224
  molecule (str): Path to the molecule file or name of the molecule.
225
225
  nmols (int): Number of molecules to insert.
226
226
  arch (str): Architecture for the calculator.
@@ -246,6 +246,11 @@ def pack_molecules(
246
246
  insert_strategy (str): Insert strategy, "random" or "md"
247
247
  relax_strategy (str): Relax strategy, "geometry_optimisation" or "md"
248
248
 
249
+ Returns
250
+ -------
251
+ tuple: A tuple energy and Atoms object containing
252
+ original system and added molecules..
253
+
249
254
  """
250
255
  kbt = temperature * kB
251
256
  validate_value("temperature", temperature)
@@ -270,6 +275,9 @@ def pack_molecules(
270
275
  if system is None:
271
276
  sys = Atoms(cell=[cell_a, cell_b, cell_c], pbc=[True, True, True])
272
277
  sysname = ""
278
+ elif isinstance(system, Atoms):
279
+ sys = system.copy()
280
+ sysname = sys.get_chemical_formula()
273
281
  else:
274
282
  sys = read(system)
275
283
  sysname = Path(system).stem + "+"
@@ -306,6 +314,20 @@ def pack_molecules(
306
314
  tsys, md_temperature, md_steps, md_timestep, arch, model, device
307
315
  )
308
316
 
317
+ if every > 0 and _itry / every == 0:
318
+ tsys = save_the_day(
319
+ struct_path=tsys,
320
+ device=device,
321
+ arch=arch,
322
+ model=model,
323
+ fmax=fmax,
324
+ out_path=out_path,
325
+ md_temperature=md_temperature,
326
+ md_steps=md_steps,
327
+ md_timestep=md_timestep,
328
+ relax_strategy=relax_strategy,
329
+ )
330
+
309
331
  tsys.calc = calc
310
332
  en = tsys.get_potential_energy()
311
333
  de = en - e
@@ -317,20 +339,6 @@ def pack_molecules(
317
339
  if u <= acc:
318
340
  accept = True
319
341
  break
320
- if every > 0 and _itry / every == 0:
321
- csys = save_the_day(
322
- Path(out_path) / f"{sysname}{i}{Path(molecule).stem}.cif",
323
- device,
324
- arch,
325
- model,
326
- fmax,
327
- out_path,
328
- md_temperature,
329
- md_steps,
330
- md_timestep,
331
- relax_strategy,
332
- )
333
-
334
342
  if accept:
335
343
  csys = tsys.copy()
336
344
  e = en
@@ -342,7 +350,7 @@ def pack_molecules(
342
350
  # once you hit here is bad, this can keep looping
343
351
  print(f"Failed to insert particle {i + 1} after {ntries} tries")
344
352
  csys = save_the_day(
345
- Path(out_path) / f"{sysname}{i}{Path(molecule).stem}.cif",
353
+ csys,
346
354
  device,
347
355
  arch,
348
356
  model,
@@ -358,7 +366,7 @@ def pack_molecules(
358
366
 
359
367
  # Perform final geometry optimization if requested
360
368
  if geometry:
361
- energy_final = optimize_geometry(
369
+ energy_final, csys = optimize_geometry(
362
370
  Path(out_path) / f"{sysname}{nmols}{Path(molecule).stem}.cif",
363
371
  device,
364
372
  arch,
@@ -367,7 +375,7 @@ def pack_molecules(
367
375
  out_path,
368
376
  True,
369
377
  )
370
- return energy_final
378
+ return (energy_final, csys)
371
379
 
372
380
 
373
381
  def load_molecule(molecule: str):
@@ -410,7 +418,7 @@ def rotate_molecule(mol):
410
418
 
411
419
 
412
420
  def save_the_day(
413
- struct_path: str = "",
421
+ struct_path: str | Atoms,
414
422
  device: str = "",
415
423
  arch: str = "",
416
424
  model: str = "",
@@ -423,7 +431,7 @@ def save_the_day(
423
431
  ) -> Atoms:
424
432
  """Geometry optimisation or MD to get a better structure."""
425
433
  if relax_strategy == "geometry_optimisation":
426
- _ = optimize_geometry(
434
+ _, a = optimize_geometry(
427
435
  struct_path,
428
436
  device,
429
437
  arch,
@@ -431,7 +439,7 @@ def save_the_day(
431
439
  fmax,
432
440
  out_path,
433
441
  )
434
- return read(Path(out_path) / f"{Path(struct_path).stem}-opt.cif")
442
+ return a
435
443
  if relax_strategy == "md":
436
444
  return run_md_nve(
437
445
  struct_path, md_temperature, md_steps, md_timestep, arch, model, device
@@ -476,23 +484,34 @@ def run_md_nve(
476
484
 
477
485
 
478
486
  def optimize_geometry(
479
- struct_path: str,
487
+ struct_path: str | Atoms,
480
488
  device: str,
481
489
  arch: str,
482
490
  model: str,
483
491
  fmax: float,
484
492
  out_path: str = ".",
485
493
  opt_cell: bool = False,
486
- ) -> float:
494
+ ) -> tuple(float, Atoms):
487
495
  """Optimize the geometry of a structure."""
488
- geo = GeomOpt(
489
- struct_path=struct_path,
490
- device=device,
491
- arch=arch,
492
- fmax=fmax,
493
- calc_kwargs={"model_paths": model},
494
- filter_kwargs={"hydrostatic_strain": opt_cell},
495
- )
496
- geo.run()
497
- write(Path(out_path) / f"{Path(struct_path).stem}-opt.cif", geo.struct)
498
- return geo.struct.get_potential_energy()
496
+ if isinstance(struct_path, Atoms):
497
+ geo = GeomOpt(
498
+ struct=struct_path,
499
+ device=device,
500
+ arch=arch,
501
+ fmax=fmax,
502
+ calc_kwargs={"model_paths": model},
503
+ filter_kwargs={"hydrostatic_strain": opt_cell},
504
+ )
505
+ geo.run()
506
+ else:
507
+ geo = GeomOpt(
508
+ struct_path=struct_path,
509
+ device=device,
510
+ arch=arch,
511
+ fmax=fmax,
512
+ calc_kwargs={"model_paths": model},
513
+ filter_kwargs={"hydrostatic_strain": opt_cell},
514
+ )
515
+ geo.run()
516
+ write(Path(out_path) / f"{Path(struct_path).stem}-opt.cif", geo.struct)
517
+ return (geo.struct.get_potential_energy(), geo.struct)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pack-mm
3
- Version: 0.0.22
3
+ Version: 0.0.24
4
4
  Summary: packing materials and molecules in boxes using for machine learnt interatomic potentials
5
5
  Author: Alin M. Elena
6
6
  Classifier: Programming Language :: Python
@@ -50,6 +50,11 @@ or install the latest
50
50
 
51
51
  ```
52
52
 
53
+ ## Jupyter notebook examples
54
+
55
+
56
+ - [Basics](docs/source/tutorials/basics.ipynb) [![badge](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ddmms/pack-mm/blob/main/docs/source/tutorials/basic.ipynb)
57
+
53
58
  ## CLI examples
54
59
 
55
60
 
@@ -0,0 +1,8 @@
1
+ pack_mm-0.0.24.dist-info/METADATA,sha256=Qdbk-eAfirZQY0G6cOibTNAuy6rZtZbCoSktOTAyYKo,13757
2
+ pack_mm-0.0.24.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ pack_mm-0.0.24.dist-info/entry_points.txt,sha256=ajKA2oehIa_LCVCP2XTRxV0VNgjGl9c2wYkwk0BasrQ,66
4
+ pack_mm-0.0.24.dist-info/licenses/LICENSE,sha256=ZOYkPdn_vQ8wYJqZnjesow79F_grMbVlHcJ9V91G1pE,1100
5
+ pack_mm/__init__.py,sha256=ct7qfCmTDwhLYip6JKYWRLasmmaGYt0ColbK0CpvYZk,150
6
+ pack_mm/cli/packmm.py,sha256=E63MmBrxvn9g5GQMK5vlyq6CmHL8hgQ8CICeX2N9z1E,6398
7
+ pack_mm/core/core.py,sha256=vLTdnWaqnIOtkhtLBG9911RxhJMn-DWAWe5GzyFWSdc,15883
8
+ pack_mm-0.0.24.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- pack_mm-0.0.22.dist-info/METADATA,sha256=5XjBJexb_jY1kVAZdZSXFcXfdWvfHJFpnsYJ25tTQlc,13509
2
- pack_mm-0.0.22.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- pack_mm-0.0.22.dist-info/entry_points.txt,sha256=ajKA2oehIa_LCVCP2XTRxV0VNgjGl9c2wYkwk0BasrQ,66
4
- pack_mm-0.0.22.dist-info/licenses/LICENSE,sha256=ZOYkPdn_vQ8wYJqZnjesow79F_grMbVlHcJ9V91G1pE,1100
5
- pack_mm/__init__.py,sha256=ct7qfCmTDwhLYip6JKYWRLasmmaGYt0ColbK0CpvYZk,150
6
- pack_mm/cli/packmm.py,sha256=E63MmBrxvn9g5GQMK5vlyq6CmHL8hgQ8CICeX2N9z1E,6398
7
- pack_mm/core/core.py,sha256=R0d-FTmuTj-5BSwG5S4Fa6f3BFdYrvBUsV2cSwcHi2c,15269
8
- pack_mm-0.0.22.dist-info/RECORD,,