GO-Diff 1.0.1__tar.gz → 1.1.0__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 (44) hide show
  1. {go_diff-1.0.1 → go_diff-1.1.0}/PKG-INFO +1 -1
  2. go_diff-1.1.0/VERSION +1 -0
  3. {go_diff-1.0.1 → go_diff-1.1.0}/docs/source/conf.py +9 -1
  4. go_diff-1.1.0/go_diff/__init__.py +3 -0
  5. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/filter.py +32 -0
  6. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/go_diff.py +82 -49
  7. {go_diff-1.0.1 → go_diff-1.1.0}/scripts/heptamer.py +1 -1
  8. {go_diff-1.0.1 → go_diff-1.1.0}/scripts/stepped_pt.py +1 -1
  9. {go_diff-1.0.1 → go_diff-1.1.0}/tests/test_godiff.py +17 -24
  10. go_diff-1.0.1/VERSION +0 -1
  11. go_diff-1.0.1/go_diff/__init__.py +0 -3
  12. {go_diff-1.0.1 → go_diff-1.1.0}/.github/workflows/auto-tag.yml +0 -0
  13. {go_diff-1.0.1 → go_diff-1.1.0}/.github/workflows/publish.yml +0 -0
  14. {go_diff-1.0.1 → go_diff-1.1.0}/.github/workflows/tests.yml +0 -0
  15. {go_diff-1.0.1 → go_diff-1.1.0}/.gitignore +0 -0
  16. {go_diff-1.0.1 → go_diff-1.1.0}/.readthedocs.yaml +0 -0
  17. {go_diff-1.0.1 → go_diff-1.1.0}/LICENSE +0 -0
  18. {go_diff-1.0.1 → go_diff-1.1.0}/README.md +0 -0
  19. {go_diff-1.0.1 → go_diff-1.1.0}/docs/Makefile +0 -0
  20. {go_diff-1.0.1 → go_diff-1.1.0}/docs/make.bat +0 -0
  21. {go_diff-1.0.1 → go_diff-1.1.0}/docs/requirements.txt +0 -0
  22. {go_diff-1.0.1 → go_diff-1.1.0}/docs/source/concepts.rst +0 -0
  23. {go_diff-1.0.1 → go_diff-1.1.0}/docs/source/index.rst +0 -0
  24. {go_diff-1.0.1 → go_diff-1.1.0}/docs/source/installation.rst +0 -0
  25. {go_diff-1.0.1 → go_diff-1.1.0}/docs/source/overview.rst +0 -0
  26. {go_diff-1.0.1 → go_diff-1.1.0}/docs/source/references.rst +0 -0
  27. {go_diff-1.0.1 → go_diff-1.1.0}/docs/source/troubleshooting.rst +0 -0
  28. {go_diff-1.0.1 → go_diff-1.1.0}/docs/source/tutorial/quickstart.rst +0 -0
  29. {go_diff-1.0.1 → go_diff-1.1.0}/docs/source/tutorial/tutorial.rst +0 -0
  30. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/controllers/__init__.py +0 -0
  31. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/controllers/buffer.py +0 -0
  32. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/controllers/sample.py +0 -0
  33. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/controllers/temperature.py +0 -0
  34. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/controllers/training.py +0 -0
  35. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/logger.py +0 -0
  36. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/noisers/__init__.py +0 -0
  37. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/noisers/weighted_pos.py +0 -0
  38. {go_diff-1.0.1 → go_diff-1.1.0}/go_diff/utils.py +0 -0
  39. {go_diff-1.0.1 → go_diff-1.1.0}/pyproject.toml +0 -0
  40. {go_diff-1.0.1 → go_diff-1.1.0}/tests/__init__.py +0 -0
  41. {go_diff-1.0.1 → go_diff-1.1.0}/tests/conftest.py +0 -0
  42. {go_diff-1.0.1 → go_diff-1.1.0}/tests/test_sample_controller.py +0 -0
  43. {go_diff-1.0.1 → go_diff-1.1.0}/tests/test_temperature.py +0 -0
  44. {go_diff-1.0.1 → go_diff-1.1.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GO-Diff
3
- Version: 1.0.1
3
+ Version: 1.1.0
4
4
  Summary: GO-Diff
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
go_diff-1.1.0/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.0
@@ -6,10 +6,18 @@
6
6
  # -- Project information -----------------------------------------------------
7
7
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8
8
 
9
+ import os
10
+
9
11
  project = 'GO-Diff'
10
12
  copyright = '2025, Nikolaj Rønne'
11
13
  author = 'Nikolaj Rønne'
12
- release = '1.0.0'
14
+
15
+ _version_file = os.path.join(os.path.dirname(__file__), '..', '..', 'VERSION')
16
+ try:
17
+ with open(_version_file) as _f:
18
+ release = _f.read().strip()
19
+ except OSError as e:
20
+ raise RuntimeError(f"Could not read VERSION file at {_version_file}: {e}") from e
13
21
 
14
22
  # -- General configuration ---------------------------------------------------
15
23
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -0,0 +1,3 @@
1
+ from .go_diff import GODiff
2
+ from .logger import GODiffLogger
3
+ from .filter import Filter, MinEnergyFilter, MaxEnergyFilter, MinDistFilter
@@ -68,3 +68,35 @@ class MaxEnergyFilter:
68
68
  return atoms.get_potential_energy() < self.threshold
69
69
 
70
70
 
71
+ class MinDistFilter:
72
+ """Keep only structures where all pairwise interatomic distances are at
73
+ least *min_dist*.
74
+
75
+ Parameters
76
+ ----------
77
+ min_dist : float
78
+ Minimum allowed distance (Å) between any pair of atoms. Structures
79
+ with any pair closer than this threshold are discarded.
80
+ Default: 1.0.
81
+
82
+ Examples
83
+ --------
84
+ Supply as a :attr:`~go_diff.GODiff.valid_structure_filters` entry to
85
+ replace the former hard-coded ``check_min_dist`` call::
86
+
87
+ from go_diff.filter import MinDistFilter
88
+ valid_structure_filters = [MinDistFilter(1.0)]
89
+ """
90
+
91
+ def __init__(self, min_dist: float = 1.0) -> None:
92
+ self.min_dist = min_dist
93
+
94
+ def __call__(self, atoms: Atoms) -> bool:
95
+ positions = atoms.get_positions()
96
+ dists = np.linalg.norm(
97
+ positions[:, np.newaxis] - positions, axis=-1
98
+ )
99
+ np.fill_diagonal(dists, np.inf)
100
+ return float(np.min(dists)) >= self.min_dist
101
+
102
+
@@ -23,6 +23,7 @@ from .filter import (
23
23
  Filter,
24
24
  MinEnergyFilter,
25
25
  MaxEnergyFilter,
26
+ MinDistFilter,
26
27
  )
27
28
  from go_diff.controllers import (
28
29
  TemperatureSchedule,
@@ -105,7 +106,18 @@ class GODiff:
105
106
  iteration. Default: 32.
106
107
  max_steps_per_loop : int
107
108
  Maximum number of training steps per GO-Diff iteration. Default: 500.
108
- valid_structure_filters : list of Filter or None, optional
109
+ seed_structures : list of ase.Atoms or None, optional
110
+ Structures to seed the initial buffer and dataset. If provided, these are evaluated
111
+ with the calculator and added to ``all_data`` and no sampling is performed on the
112
+ first iteration. Defaults to ``None`` (empty initial dataset).
113
+ after_sample_filters : list of Filter, optional
114
+ Sequence of callables ``(atoms: Atoms) -> bool`` applied right after
115
+ sampling and **before** energy/force evaluation. Only structures
116
+ passing every filter are forwarded to the calculator. Defaults to
117
+ ``[MinDistFilter(1.0)]``, which replicates the former hard-coded
118
+ ``check_min_dist`` call. Pass ``[]`` to disable pre-evaluation
119
+ filtering.
120
+ after_potential_filters : list of Filter or None, optional
109
121
  Sequence of callables ``(atoms: Atoms) -> bool`` applied right after
110
122
  energy/force evaluation to discard physically unreasonable structures.
111
123
  Discarded structures are never added to ``all_data`` or the buffer.
@@ -138,6 +150,9 @@ class GODiff:
138
150
  batch_size: int = 32,
139
151
  sample_batch_size: int = 16,
140
152
  max_steps_per_loop: int = 500,
153
+ seed_structures: list | None = None,
154
+ after_sample_filters: list[Filter] | None = None,
155
+ after_potential_filters: list[Filter] | None = None,
141
156
  valid_structure_filters: list[Filter] | None = None,
142
157
  buffer_filters: list[Filter] | None = None,
143
158
  device: str = "cuda",
@@ -156,7 +171,23 @@ class GODiff:
156
171
  self.batch_size: int = batch_size
157
172
  self.sample_batch_size: int = sample_batch_size
158
173
  self.max_steps_per_loop: int = max_steps_per_loop
159
- self.valid_structure_filters: list[Filter] | None = valid_structure_filters
174
+ self.seed_structures: list[Atoms] | None = seed_structures
175
+ self.after_sample_filters: list[Filter] = (
176
+ after_sample_filters if after_sample_filters is not None else [MinDistFilter(1.0)]
177
+ )
178
+
179
+ self.after_potential_filters: list[Filter] | None = after_potential_filters
180
+ if valid_structure_filters is not None:
181
+ import warnings
182
+ warnings.warn(
183
+ "Passing valid_structure_filters to the GODiff constructor is deprecated and will be removed in a future release. "
184
+ "Please apply these filters manually in the sample_stage method instead.",
185
+ DeprecationWarning,
186
+ )
187
+ self.after_potential_filters = valid_structure_filters
188
+
189
+
190
+
160
191
  self.buffer_filters: list[Filter] = (
161
192
  buffer_filters if buffer_filters is not None else [MaxEnergyFilter(0.0)]
162
193
  )
@@ -271,37 +302,6 @@ class GODiff:
271
302
 
272
303
  return atoms_list
273
304
 
274
- def check_min_dist(
275
- self,
276
- atoms_list: list[Atoms],
277
- min_dist: float = 1.0,
278
- ) -> list[Atoms]:
279
- """Filter structures with interatomic distances below *min_dist*.
280
-
281
- Parameters
282
- ----------
283
- atoms_list : list of ase.Atoms
284
- Structures to filter.
285
- min_dist : float
286
- Minimum allowed distance (Å) between any pair of atoms.
287
- Default: 1.0.
288
-
289
- Returns
290
- -------
291
- list of ase.Atoms
292
- Structures in which all pairwise distances are ≥ *min_dist*.
293
- """
294
- filtered: list[Atoms] = []
295
- for atoms in atoms_list:
296
- positions = atoms.get_positions()
297
- dists = np.linalg.norm(
298
- positions[:, np.newaxis] - positions, axis=-1
299
- )
300
- np.fill_diagonal(dists, np.inf)
301
- if float(np.min(dists)) >= min_dist:
302
- filtered.append(atoms)
303
- return filtered
304
-
305
305
  # ------------------------------------------------------------------
306
306
  # Boltzmann weighting helpers
307
307
  # ------------------------------------------------------------------
@@ -417,10 +417,34 @@ class GODiff:
417
417
  # Buffer management
418
418
  # ------------------------------------------------------------------
419
419
 
420
- def _apply_valid_structure_filters(self, data: list[Atoms]) -> list[Atoms]:
421
- """Apply :attr:`valid_structure_filters` to *data* and return survivors.
420
+ def _apply_after_sample_filters(self, data: list[Atoms]) -> list[Atoms]:
421
+ """Apply :attr:`after_sample_filters` to *data* and return survivors.
422
422
 
423
- When :attr:`valid_structure_filters` is ``None`` (the default), all
423
+ Called right after sampling and before energy/force evaluation.
424
+ When :attr:`after_sample_filters` is empty, all structures are returned
425
+ unchanged. Otherwise a structure is kept only when **every** filter
426
+ returns ``True``.
427
+
428
+ Parameters
429
+ ----------
430
+ data : list of ase.Atoms
431
+
432
+ Returns
433
+ -------
434
+ list of ase.Atoms
435
+ """
436
+ if not self.after_sample_filters:
437
+ return data
438
+ return [
439
+ atoms for atoms in data
440
+ if all(f(atoms) for f in self.after_sample_filters)
441
+ ]
442
+
443
+ def _apply_after_potential_filters(self, data: list[Atoms]) -> list[Atoms]:
444
+ """Apply :attr:`after_potential_filters` to *data* and return survivors.
445
+
446
+ Called right after energy/force evaluation.
447
+ When :attr:`after_potential_filters` is ``None`` (the default), all
424
448
  structures are returned unchanged. Otherwise a structure is kept only
425
449
  when **every** filter returns ``True``.
426
450
 
@@ -432,11 +456,11 @@ class GODiff:
432
456
  -------
433
457
  list of ase.Atoms
434
458
  """
435
- if not self.valid_structure_filters:
459
+ if not self.after_potential_filters:
436
460
  return data
437
461
  return [
438
462
  atoms for atoms in data
439
- if all(f(atoms) for f in self.valid_structure_filters)
463
+ if all(f(atoms) for f in self.after_potential_filters)
440
464
  ]
441
465
 
442
466
  def update_buffer(self) -> None:
@@ -522,22 +546,31 @@ class GODiff:
522
546
  evaluation_wall_s = 0.0
523
547
  iteration_data: list[Atoms] = []
524
548
 
525
- while self.sample_controller.continue_sampling(
526
- [a.get_potential_energy() for a in iteration_data],
527
- current_temperature,
528
- ):
549
+ if iteration == 0 and self.seed_structures is not None:
529
550
  t0 = time.perf_counter()
530
- new_samples = self.sample(exclude_keys=exclude_sample_keys)
531
- new_samples = self.check_min_dist(new_samples, min_dist=1.0)
532
- sampling_wall_s += time.perf_counter() - t0
533
-
534
- t0 = time.perf_counter()
535
- new_samples = self.evaluate(new_samples, iteration=iteration)
551
+ new_samples = self.evaluate(self.seed_structures, iteration=iteration)
536
552
  evaluation_wall_s += time.perf_counter() - t0
537
553
 
538
- new_samples = self._apply_valid_structure_filters(new_samples)
554
+ new_samples = self._apply_after_potential_filters(new_samples)
539
555
  iteration_data.extend(new_samples)
540
556
 
557
+ else:
558
+ while self.sample_controller.continue_sampling(
559
+ [a.get_potential_energy() for a in iteration_data],
560
+ current_temperature,
561
+ ):
562
+ t0 = time.perf_counter()
563
+ new_samples = self.sample(exclude_keys=exclude_sample_keys)
564
+ sampling_wall_s += time.perf_counter() - t0
565
+ new_samples = self._apply_after_sample_filters(new_samples)
566
+
567
+ t0 = time.perf_counter()
568
+ new_samples = self.evaluate(new_samples, iteration=iteration)
569
+ evaluation_wall_s += time.perf_counter() - t0
570
+
571
+ new_samples = self._apply_after_potential_filters(new_samples)
572
+ iteration_data.extend(new_samples)
573
+
541
574
  # Save this iteration's structures
542
575
  name = f"{current_temperature:.3f}" if current_temperature is not None else "initial"
543
576
  self.save_trajectory(
@@ -65,7 +65,7 @@ godiff = GODiff(
65
65
  trainer_config={
66
66
  "name": name
67
67
  },
68
- valid_structure_filters=[MinEnergyFilter(min_E)],
68
+ after_potential_filter=[MinEnergyFilter(min_E)],
69
69
  )
70
70
 
71
71
  # Train the model
@@ -67,7 +67,7 @@ godiff = GODiff(
67
67
  "name": name
68
68
  },
69
69
  min_E=min_E,
70
- valid_structure_filters=[MinEnergyFilter(min_E)],
70
+ after_potential_filter=[MinEnergyFilter(min_E)],
71
71
  )
72
72
 
73
73
  # Train the model
@@ -14,7 +14,7 @@ import pytest
14
14
 
15
15
  from go_diff.controllers.temperature import TemperatureSchedule
16
16
  from go_diff.controllers.sample import SampleController
17
- from go_diff.filter import Filter, MinEnergyFilter, MaxEnergyFilter
17
+ from go_diff.filter import Filter, MinEnergyFilter, MaxEnergyFilter, MinDistFilter
18
18
  from go_diff.go_diff import GODiff
19
19
 
20
20
 
@@ -48,47 +48,40 @@ def _make_godiff(**kwargs) -> GODiff:
48
48
 
49
49
 
50
50
  # ---------------------------------------------------------------------------
51
- # check_min_dist
51
+ # MinDistFilter
52
52
  # ---------------------------------------------------------------------------
53
53
 
54
- class TestCheckMinDist:
54
+ class TestMinDistFilter:
55
55
  def test_accepts_well_separated(self):
56
56
  from ase import Atoms
57
57
  from ase.calculators.singlepoint import SinglePointCalculator as SPC
58
- gd = _make_godiff()
59
- # 3 atoms spaced 2 Å apart
60
58
  atoms = Atoms("HHH", positions=[[0, 0, 0], [2, 0, 0], [4, 0, 0]])
61
59
  atoms.calc = SPC(atoms, energy=-1.0, forces=np.zeros((3, 3)))
62
- result = gd.check_min_dist([atoms], min_dist=1.0)
63
- assert len(result) == 1
60
+ assert MinDistFilter(1.0)(atoms) is True
64
61
 
65
62
  def test_rejects_close_atoms(self):
66
63
  from ase import Atoms
67
64
  from ase.calculators.singlepoint import SinglePointCalculator as SPC
68
- gd = _make_godiff()
69
65
  atoms = Atoms("HH", positions=[[0, 0, 0], [0.1, 0, 0]])
70
66
  atoms.calc = SPC(atoms, energy=-1.0, forces=np.zeros((2, 3)))
71
- result = gd.check_min_dist([atoms], min_dist=1.0)
72
- assert len(result) == 0
67
+ assert MinDistFilter(1.0)(atoms) is False
73
68
 
74
69
  def test_single_atom_always_passes(self):
75
70
  from ase import Atoms
76
71
  from ase.calculators.singlepoint import SinglePointCalculator as SPC
77
- gd = _make_godiff()
78
72
  atoms = Atoms("H", positions=[[0, 0, 0]])
79
73
  atoms.calc = SPC(atoms, energy=-1.0, forces=np.zeros((1, 3)))
80
- result = gd.check_min_dist([atoms], min_dist=1.0)
81
- assert len(result) == 1
74
+ assert MinDistFilter(1.0)(atoms) is True
82
75
 
83
- def test_mixed_list(self):
76
+ def test_filters_mixed_structures(self):
84
77
  from ase import Atoms
85
78
  from ase.calculators.singlepoint import SinglePointCalculator as SPC
86
- gd = _make_godiff()
87
79
  good = Atoms("HH", positions=[[0, 0, 0], [3, 0, 0]])
88
80
  good.calc = SPC(good, energy=-1.0, forces=np.zeros((2, 3)))
89
81
  bad = Atoms("HH", positions=[[0, 0, 0], [0.1, 0, 0]])
90
82
  bad.calc = SPC(bad, energy=-2.0, forces=np.zeros((2, 3)))
91
- result = gd.check_min_dist([good, bad], min_dist=1.0)
83
+ gd = _make_godiff(after_potential_filters=[MinDistFilter(1.0)])
84
+ result = gd._apply_after_potential_filters([good, bad])
92
85
  assert len(result) == 1
93
86
  assert result[0] is good
94
87
 
@@ -269,33 +262,33 @@ class TestFilterProtocol:
269
262
 
270
263
  class TestApplyValidStructureFilters:
271
264
  def test_single_filter(self):
272
- gd = _make_godiff(valid_structure_filters=[MinEnergyFilter(-5.0)])
265
+ gd = _make_godiff(after_potential_filters=[MinEnergyFilter(-5.0)])
273
266
  data = [_make_atoms(-3.0), _make_atoms(-10.0), _make_atoms(-1.0)]
274
- result = gd._apply_valid_structure_filters(data)
267
+ result = gd._apply_after_potential_filters(data)
275
268
  assert len(result) == 2
276
269
  assert all(a.get_potential_energy() > -5.0 for a in result)
277
270
 
278
271
  def test_multiple_filters_stacked(self):
279
272
  # Keep only structures with -4.0 < e < -0.5
280
- gd = _make_godiff(valid_structure_filters=[
273
+ gd = _make_godiff(after_potential_filters=[
281
274
  MinEnergyFilter(-4.0),
282
275
  MaxEnergyFilter(-0.5),
283
276
  ])
284
277
  data = [_make_atoms(-1.0), _make_atoms(-2.0), _make_atoms(-5.0), _make_atoms(-0.1)]
285
- result = gd._apply_valid_structure_filters(data)
278
+ result = gd._apply_after_potential_filters(data)
286
279
  assert len(result) == 2
287
280
  assert all(-4.0 < a.get_potential_energy() < -0.5 for a in result)
288
281
 
289
282
  def test_none_filters_keeps_all(self):
290
- gd = _make_godiff(valid_structure_filters=None)
283
+ gd = _make_godiff(after_potential_filters=None)
291
284
  data = [_make_atoms(-1.0), _make_atoms(-600.0)]
292
- result = gd._apply_valid_structure_filters(data)
285
+ result = gd._apply_after_potential_filters(data)
293
286
  assert len(result) == 2
294
287
 
295
288
  def test_empty_filters_keeps_all(self):
296
- gd = _make_godiff(valid_structure_filters=[])
289
+ gd = _make_godiff(after_potential_filters=[])
297
290
  data = [_make_atoms(-1.0), _make_atoms(-600.0)]
298
- result = gd._apply_valid_structure_filters(data)
291
+ result = gd._apply_after_potential_filters(data)
299
292
  assert len(result) == 2
300
293
 
301
294
 
go_diff-1.0.1/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.1
@@ -1,3 +0,0 @@
1
- from .go_diff import GODiff
2
- from .logger import GODiffLogger
3
- from .filter import Filter, MinEnergyFilter, MaxEnergyFilter
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