AdsorPy 1.1.1__tar.gz → 1.1.2__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.
- {adsorpy-1.1.1 → adsorpy-1.1.2}/CHANGELOG.md +8 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/PKG-INFO +1 -1
- {adsorpy-1.1.1 → adsorpy-1.1.2}/pyproject.toml +1 -1
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/adsorpy/randomsequentialadsorption.py +32 -29
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/adsorpy/rsa_calculator.py +15 -11
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/adsorpy/run_simulation.py +45 -22
- {adsorpy-1.1.1 → adsorpy-1.1.2}/tests/rsa_test.py +1 -1
- {adsorpy-1.1.1 → adsorpy-1.1.2}/tests/run_simulation_test.py +6 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/.github/workflows/docs-ci.yml +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/.github/workflows/publish_to_PyPI.yml +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/.github/workflows/tests-ci.yml +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/LICENSE.md +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/README.md +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/Makefile +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/make.bat +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/source/adsorpy.molecule_lib.rst +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/source/adsorpy.randomsequentialadsorption.rst +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/source/adsorpy.rsa_calculator.rst +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/source/adsorpy.rsa_config.rst +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/source/adsorpy.rst +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/source/adsorpy.run_simulation.rst +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/source/conf.py +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/source/index.rst +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/docs/source/modules.rst +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/images/AdsorPy_Covered_Surface.png +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/py.typed +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/requirements.txt +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/requirements_dev.txt +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/__init__.py +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/__main__.py +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/adsorpy/VdW_Radii.csv +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/adsorpy/__init__.py +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/adsorpy/config.json +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/adsorpy/molecule_colour.json +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/adsorpy/molecule_lib.py +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/src/adsorpy/rsa_config.py +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/tests/__init__.py +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/tests/test_data/config_test_hard.json +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/tests/test_data/config_test_periodic.json +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/tests/test_data/config_test_soft.json +0 -0
- {adsorpy-1.1.1 → adsorpy-1.1.2}/tox.ini +0 -0
|
@@ -9,6 +9,14 @@ This format is based on [Keep a Changelog](http://keepachangelog.com/) and this
|
|
|
9
9
|
### Fixed
|
|
10
10
|
### Removed
|
|
11
11
|
|
|
12
|
+
## 1.1.2 - 2026-04-27
|
|
13
|
+
### Added
|
|
14
|
+
### Changed
|
|
15
|
+
### Fixed
|
|
16
|
+
- Turn relative imports into absolute imports to make the package pip-installable.
|
|
17
|
+
- Fix the type hints that broke as a result of this.
|
|
18
|
+
### Removed
|
|
19
|
+
|
|
12
20
|
## 1.1.1 - 2026-04-27
|
|
13
21
|
### Added
|
|
14
22
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AdsorPy
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.2
|
|
4
4
|
Summary: Random sequential adsorption (RSA) simulation, 2D lattice-based.
|
|
5
5
|
Project-URL: Repository, https://github.com/JoostFWMaas/AdsorPy
|
|
6
6
|
Project-URL: Documentation, https://joostfwmaas.github.io/AdsorPy
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "AdsorPy"
|
|
7
|
-
version = "1.1.
|
|
7
|
+
version = "1.1.2"
|
|
8
8
|
description = "Random sequential adsorption (RSA) simulation, 2D lattice-based."
|
|
9
9
|
authors = [{ name = "J.F.W. Maas", email = "j.f.w.maas@tue.nl" }]
|
|
10
10
|
readme = "README.md"
|
|
@@ -12,21 +12,23 @@ from pathlib import Path
|
|
|
12
12
|
from typing import TYPE_CHECKING, Final, Literal, ParamSpec, cast
|
|
13
13
|
|
|
14
14
|
import numpy as np # For vectorised computations (performed in C).
|
|
15
|
-
import rsa_calculator as calc # Library for calculation functions. Used to be static methods.
|
|
16
15
|
import shapely.affinity as aff
|
|
17
16
|
from matplotlib import pyplot as plt # Plotting.
|
|
18
17
|
from matplotlib.collections import PatchCollection, PolyCollection # To make pointers.
|
|
19
18
|
from matplotlib.patches import CirclePolygon, Rectangle
|
|
20
19
|
from numpy.typing import NDArray
|
|
21
|
-
from rsa_config import RsaConfig # noqa: TC002 # Config of the simulation.
|
|
22
20
|
from rtree.index import Index, Property # RTree, helps lookups!
|
|
23
21
|
from shapely import MultiPoint, Point, Polygon, STRtree, box, contains_xy, prepare
|
|
24
22
|
from shapely.prepared import PreparedGeometry # For vectorised inclusion checks.
|
|
25
23
|
|
|
24
|
+
import src.adsorpy.rsa_calculator as calc # Library for calculation functions. Used to be static methods.
|
|
25
|
+
|
|
26
26
|
if TYPE_CHECKING:
|
|
27
27
|
from matplotlib.axes import Axes
|
|
28
28
|
from matplotlib.figure import Figure
|
|
29
29
|
|
|
30
|
+
from src.adsorpy.rsa_config import RsaConfig # Config of the simulation.
|
|
31
|
+
|
|
30
32
|
plt.rcParams.update(
|
|
31
33
|
{
|
|
32
34
|
"font.size": 20,
|
|
@@ -170,7 +172,7 @@ class BoundaryParameters:
|
|
|
170
172
|
"A counter for the molecules + mirror molecules."
|
|
171
173
|
self.mirrors: IdxArray = np.empty(0, dtype=np.int_)
|
|
172
174
|
"Mirror indices."
|
|
173
|
-
self.biggest_radius:
|
|
175
|
+
self.biggest_radius: float = dbl_max_radius
|
|
174
176
|
"The biggest radius between the two largest molecules in the simulation."
|
|
175
177
|
self.tree: STRtree = STRtree([Point()]) # TODO: Figure out whether faster.
|
|
176
178
|
"STRtree, currently unused."
|
|
@@ -332,14 +334,14 @@ class MoleculeGroup:
|
|
|
332
334
|
|
|
333
335
|
self.config: Final[Config] = Config(
|
|
334
336
|
rsa_config=rsa_config,
|
|
335
|
-
sites=rsa_config.get_value("sites", required=False),
|
|
336
|
-
xsize=rsa_config.get_value("xsize", required=False),
|
|
337
|
-
ysize=rsa_config.get_value("ysize", required=False),
|
|
338
|
-
zsize=rsa_config.get_value("zsize", required=False),
|
|
339
|
-
max_molecule_count=rsa_config.get_value("max_molecule_count"),
|
|
340
|
-
lattice_a=rsa_config.get_value("lattice_a"),
|
|
341
|
-
boundary_type=rsa_config.get_value("boundary_type"),
|
|
342
|
-
sticking_probability=rsa_config.get_value("sticking_probability"),
|
|
337
|
+
sites=rsa_config.get_value("sites", required=False), # type: ignore[arg-type]
|
|
338
|
+
xsize=rsa_config.get_value("xsize", required=False), # type: ignore[arg-type]
|
|
339
|
+
ysize=rsa_config.get_value("ysize", required=False), # type: ignore[arg-type]
|
|
340
|
+
zsize=rsa_config.get_value("zsize", required=False), # type: ignore[arg-type]
|
|
341
|
+
max_molecule_count=rsa_config.get_value("max_molecule_count"), # type: ignore[arg-type]
|
|
342
|
+
lattice_a=rsa_config.get_value("lattice_a"), # type: ignore[arg-type]
|
|
343
|
+
boundary_type=rsa_config.get_value("boundary_type"), # type: ignore[arg-type]
|
|
344
|
+
sticking_probability=rsa_config.get_value("sticking_probability"), # type: ignore[arg-type]
|
|
343
345
|
)
|
|
344
346
|
"Config values."
|
|
345
347
|
|
|
@@ -558,14 +560,14 @@ class Simulator:
|
|
|
558
560
|
"""
|
|
559
561
|
self.config: Final[Config] = Config(
|
|
560
562
|
rsa_config=rsa_config,
|
|
561
|
-
sites=rsa_config.get_value("sites", required=False),
|
|
562
|
-
xsize=rsa_config.get_value("xsize", required=False),
|
|
563
|
-
ysize=rsa_config.get_value("ysize", required=False),
|
|
564
|
-
zsize=rsa_config.get_value("zsize", required=False),
|
|
565
|
-
max_molecule_count=rsa_config.get_value("max_molecule_count"),
|
|
566
|
-
lattice_a=rsa_config.get_value("lattice_a"),
|
|
567
|
-
boundary_type=rsa_config.get_value("boundary_type") if boundary_type is None else boundary_type,
|
|
568
|
-
sticking_probability=rsa_config.get_value("sticking_probability"),
|
|
563
|
+
sites=rsa_config.get_value("sites", required=False), # type: ignore[arg-type]
|
|
564
|
+
xsize=rsa_config.get_value("xsize", required=False), # type: ignore[arg-type]
|
|
565
|
+
ysize=rsa_config.get_value("ysize", required=False), # type: ignore[arg-type]
|
|
566
|
+
zsize=rsa_config.get_value("zsize", required=False), # type: ignore[arg-type]
|
|
567
|
+
max_molecule_count=rsa_config.get_value("max_molecule_count"), # type: ignore[arg-type]
|
|
568
|
+
lattice_a=rsa_config.get_value("lattice_a"), # type: ignore[arg-type]
|
|
569
|
+
boundary_type=rsa_config.get_value("boundary_type") if boundary_type is None else boundary_type, # type: ignore[arg-type]
|
|
570
|
+
sticking_probability=rsa_config.get_value("sticking_probability"), # type: ignore[arg-type]
|
|
569
571
|
)
|
|
570
572
|
"Config values."
|
|
571
573
|
|
|
@@ -1025,7 +1027,7 @@ class Simulator:
|
|
|
1025
1027
|
self,
|
|
1026
1028
|
surf: Surface,
|
|
1027
1029
|
*molgrs: MoleculeGroup,
|
|
1028
|
-
weights: FloatArray | None = None,
|
|
1030
|
+
weights: FloatArray | list[float] | None = None,
|
|
1029
1031
|
) -> tuple[bool, int, int, int, int, list[int]]:
|
|
1030
1032
|
"""Pick from a list of molecule groups and places a random one.
|
|
1031
1033
|
|
|
@@ -1035,6 +1037,7 @@ class Simulator:
|
|
|
1035
1037
|
|
|
1036
1038
|
:return: The output of Simulator.attempt_place_molecule().
|
|
1037
1039
|
"""
|
|
1040
|
+
weights = np.array(weights) if weights is not None else None
|
|
1038
1041
|
distribution = None if weights is None or len(weights) != len(molgrs) else weights / np.sum(weights)
|
|
1039
1042
|
return self.attempt_place_molecule(
|
|
1040
1043
|
surf,
|
|
@@ -1078,7 +1081,7 @@ class Simulator:
|
|
|
1078
1081
|
|
|
1079
1082
|
# Removes all gaps of 0. distance (in a molecule). Basically removes all inaccessible/occupied sites.
|
|
1080
1083
|
if not keepzero:
|
|
1081
|
-
distance_to_grid =
|
|
1084
|
+
distance_to_grid = distance_to_grid[np.nonzero(distance_to_grid)]
|
|
1082
1085
|
|
|
1083
1086
|
return distance_to_grid
|
|
1084
1087
|
|
|
@@ -1127,14 +1130,14 @@ class Surface:
|
|
|
1127
1130
|
"""
|
|
1128
1131
|
self.config: Final[Config] = Config(
|
|
1129
1132
|
rsa_config=rsa_config,
|
|
1130
|
-
sites=rsa_config.get_value("sites", required=False),
|
|
1131
|
-
xsize=rsa_config.get_value("xsize", required=False),
|
|
1132
|
-
ysize=rsa_config.get_value("ysize", required=False),
|
|
1133
|
-
zsize=rsa_config.get_value("zsize", required=False),
|
|
1134
|
-
max_molecule_count=rsa_config.get_value("max_molecule_count"),
|
|
1135
|
-
lattice_a=rsa_config.get_value("lattice_a"),
|
|
1136
|
-
boundary_type=rsa_config.get_value("boundary_type") if boundary_type is None else boundary_type,
|
|
1137
|
-
sticking_probability=rsa_config.get_value("sticking_probability"),
|
|
1133
|
+
sites=rsa_config.get_value("sites", required=False), # type: ignore[arg-type]
|
|
1134
|
+
xsize=rsa_config.get_value("xsize", required=False), # type: ignore[arg-type]
|
|
1135
|
+
ysize=rsa_config.get_value("ysize", required=False), # type: ignore[arg-type]
|
|
1136
|
+
zsize=rsa_config.get_value("zsize", required=False), # type: ignore[arg-type]
|
|
1137
|
+
max_molecule_count=rsa_config.get_value("max_molecule_count"), # type: ignore[arg-type]
|
|
1138
|
+
lattice_a=rsa_config.get_value("lattice_a"), # type: ignore[arg-type]
|
|
1139
|
+
boundary_type=rsa_config.get_value("boundary_type") if boundary_type is None else boundary_type, # type: ignore[arg-type]
|
|
1140
|
+
sticking_probability=rsa_config.get_value("sticking_probability"), # type: ignore[arg-type]
|
|
1138
1141
|
)
|
|
1139
1142
|
"Config values."
|
|
1140
1143
|
|
|
@@ -4,7 +4,7 @@ There is no real reason for the user to need to use any of this, but the functio
|
|
|
4
4
|
"""
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
-
from typing import TYPE_CHECKING, Literal, ParamSpec, cast
|
|
7
|
+
from typing import TYPE_CHECKING, Literal, ParamSpec, TypeVar, cast
|
|
8
8
|
|
|
9
9
|
import numpy as np # For vectorised computations (performed in C).
|
|
10
10
|
import shapely.affinity as aff # Install shapely via https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely
|
|
@@ -27,12 +27,14 @@ IdxArray = np.ndarray[tuple[int], np.dtype[np.int_]] # Flat index aray of integ
|
|
|
27
27
|
BoolArray = np.ndarray[tuple[int], np.dtype[np.bool_]] # Flat Boolean array.
|
|
28
28
|
CoordPair = np.ndarray[tuple[Literal[2], Literal[1]], np.dtype[np.float64]] # 2x1 array of coordinates
|
|
29
29
|
CoordsArray = np.ndarray[tuple[Literal[2], int], np.dtype[np.float64]] # 2xN array of coords.
|
|
30
|
-
|
|
30
|
+
CoordsArray3D = np.ndarray[tuple[Literal[3], int], np.dtype[np.float64]] # 2 or 3 x N array of coords.
|
|
31
31
|
Bools2D = np.ndarray[tuple[int, int], np.dtype[np.bool_]]
|
|
32
32
|
GeoArray = np.ndarray[tuple[int], np.dtype[Polygon]]
|
|
33
33
|
FloatArray = NDArray[np.float64]
|
|
34
34
|
DistArray = np.ndarray[tuple[int], np.dtype[np.float64]]
|
|
35
35
|
|
|
36
|
+
T = TypeVar("T", CoordsArray, CoordsArray3D)
|
|
37
|
+
|
|
36
38
|
|
|
37
39
|
@njit("float64[:, :](float64[:, :], float64[:, :])", parallel=True, cache=True) # type: ignore[untyped-decorator]
|
|
38
40
|
def squared_cdist(coords1: CoordsArray, coords2: CoordsArray) -> np.ndarray[tuple[int, int], np.dtype[np.float64]]:
|
|
@@ -182,7 +184,7 @@ def check_shape_overlap(
|
|
|
182
184
|
neighbour_index: IdxArray,
|
|
183
185
|
simul: Simulator,
|
|
184
186
|
pmg: MoleculeGroup,
|
|
185
|
-
try_angle_first: int | None = None,
|
|
187
|
+
try_angle_first: int | np.int_ | None = None,
|
|
186
188
|
) -> tuple[bool, CandidateMolecule]:
|
|
187
189
|
"""Check whether there the new molecule overlaps with existing molecules.
|
|
188
190
|
|
|
@@ -302,11 +304,11 @@ def make_rectangular_filter(
|
|
|
302
304
|
|
|
303
305
|
|
|
304
306
|
def create_periodic_images(
|
|
305
|
-
coordinates:
|
|
307
|
+
coordinates: T,
|
|
306
308
|
x_max: float,
|
|
307
309
|
y_max: float,
|
|
308
310
|
z_max: float | None = None,
|
|
309
|
-
) ->
|
|
311
|
+
) -> T:
|
|
310
312
|
"""Create a padding of coordinates.
|
|
311
313
|
|
|
312
314
|
Repeats the images above, below, and on the diagonals (9 tiles).
|
|
@@ -318,10 +320,12 @@ def create_periodic_images(
|
|
|
318
320
|
|
|
319
321
|
:returns: 2 by 9*N coordinate array if 2D, otherwise 3 by 27*N array.
|
|
320
322
|
"""
|
|
321
|
-
extended_coordinates:
|
|
323
|
+
extended_coordinates: T = coordinates.copy()
|
|
322
324
|
# This creates an array of the form [[x_max, 0], [0, y_max]].
|
|
323
|
-
temp_offset: np.ndarray[tuple[Literal[2
|
|
324
|
-
|
|
325
|
+
temp_offset: np.ndarray[tuple[Literal[2], Literal[2]], np.dtype[np.float64]] | np.ndarray[
|
|
326
|
+
tuple[Literal[3], Literal[3]], np.dtype[np.float64]] = cast(
|
|
327
|
+
"""np.ndarray[tuple[Literal[2], Literal[2]], np.dtype[np.float64]] |
|
|
328
|
+
np.ndarray[tuple[Literal[3], Literal[3]], np.dtype[np.float64]]""",
|
|
325
329
|
np.diag([x_max, y_max]).reshape((2, 2)) if z_max is None else np.diag([x_max, y_max, z_max]),
|
|
326
330
|
)
|
|
327
331
|
offset: np.ndarray[tuple[Literal[2, 3], Literal[2, 3], Literal[1]], np.dtype[np.float64]] = temp_offset[
|
|
@@ -330,10 +334,10 @@ def create_periodic_images(
|
|
|
330
334
|
ii: NDArray[np.float64]
|
|
331
335
|
for ii in offset: # The first pass creates padding in x dir, the second pads in y.
|
|
332
336
|
sliced_offset = ii
|
|
333
|
-
extended_coordinates1:
|
|
334
|
-
extended_coordinates2:
|
|
337
|
+
extended_coordinates1: T = extended_coordinates + sliced_offset
|
|
338
|
+
extended_coordinates2: T = extended_coordinates - sliced_offset
|
|
335
339
|
extended_coordinates = cast(
|
|
336
|
-
"
|
|
340
|
+
"T",
|
|
337
341
|
np.hstack((extended_coordinates, extended_coordinates1, extended_coordinates2), dtype=np.float64),
|
|
338
342
|
)
|
|
339
343
|
|
|
@@ -17,17 +17,18 @@ else:
|
|
|
17
17
|
import time # For timing of the script.
|
|
18
18
|
from itertools import count # A simple counter, iterates with next(...).
|
|
19
19
|
from pathlib import Path # For path handling in Python.
|
|
20
|
-
from typing import Literal, ParamSpec, TypeVar, cast # For type hinting.
|
|
20
|
+
from typing import TYPE_CHECKING, Literal, ParamSpec, TypeVar, cast # For type hinting.
|
|
21
21
|
|
|
22
|
-
import molecule_lib as mol # Homebrew lib of molecules and molecule footprint generation.
|
|
23
22
|
import numpy as np # For vectorised computations (performed in C).
|
|
24
23
|
from numpy.random import PCG64DXSM, Generator # New random generator.
|
|
25
24
|
from numpy.typing import NDArray
|
|
26
|
-
from randomsequentialadsorption import MoleculeGroup, Simulator, Surface
|
|
27
|
-
from rsa_config import RsaConfig # Config of the simulation.
|
|
28
25
|
from shapely import Polygon # Shapely creates and manipulates polygons.
|
|
29
26
|
from shapely.prepared import PreparedGeometry
|
|
30
27
|
|
|
28
|
+
import src.adsorpy.molecule_lib as mol # Homebrew lib of molecules and molecule footprint generation.
|
|
29
|
+
from src.adsorpy.randomsequentialadsorption import MoleculeGroup, Simulator, Surface
|
|
30
|
+
from src.adsorpy.rsa_config import RsaConfig # Config of the simulation.
|
|
31
|
+
|
|
31
32
|
P = ParamSpec("P") # Helps with static type checkers.
|
|
32
33
|
T1 = TypeVar("T1")
|
|
33
34
|
T2 = TypeVar("T2", bound=np.generic | Polygon) # type: ignore[explicit-any]
|
|
@@ -59,7 +60,7 @@ def run_simulation( # noqa: PLR0913
|
|
|
59
60
|
lattice_a: float | None = None,
|
|
60
61
|
boundary_condition: str | None = None,
|
|
61
62
|
simulation_type: str = "sequential",
|
|
62
|
-
dosing_distribution: list[float] | None = None,
|
|
63
|
+
dosing_distribution: list[float] | DistArray | None = None,
|
|
63
64
|
include_rejected_flux: bool = False,
|
|
64
65
|
calculate_gap_size: bool = False,
|
|
65
66
|
print_output_flag: bool = False,
|
|
@@ -70,7 +71,7 @@ def run_simulation( # noqa: PLR0913
|
|
|
70
71
|
site_y_coords: DistArray | None = None,
|
|
71
72
|
bounding_x_coord: float | None = None,
|
|
72
73
|
bounding_y_coord: float | None = None,
|
|
73
|
-
sticking_probability: float | list[float] = 1.,
|
|
74
|
+
sticking_probability: float | list[float] | DistArray = 1.,
|
|
74
75
|
) -> tuple[list[int], DistArray, int, IdxArray, IdxArray, Simulator]:
|
|
75
76
|
"""Run the RSA simulation.
|
|
76
77
|
|
|
@@ -111,7 +112,12 @@ def run_simulation( # noqa: PLR0913
|
|
|
111
112
|
"""
|
|
112
113
|
rsa_config = RsaConfig(str(Path(__file__).parent / "config.json")) if rsa_config is None else rsa_config
|
|
113
114
|
|
|
114
|
-
|
|
115
|
+
mol_lst: GeoArray
|
|
116
|
+
rot_syms: IdxArray
|
|
117
|
+
refl_syms: BoolArray
|
|
118
|
+
rot_cnts: IdxArray
|
|
119
|
+
|
|
120
|
+
mol_lst, rot_syms, refl_syms, rot_cnts = _initialise_run_parameters(
|
|
115
121
|
molecules_list,
|
|
116
122
|
rotation_symmetries,
|
|
117
123
|
reflection_symmetries,
|
|
@@ -119,11 +125,19 @@ def run_simulation( # noqa: PLR0913
|
|
|
119
125
|
simulation_type,
|
|
120
126
|
)
|
|
121
127
|
|
|
128
|
+
# molecules_list, rotation_symmetries, reflection_symmetries, rotation_counts = _initialise_run_parameters(
|
|
129
|
+
# molecules_list,
|
|
130
|
+
# rotation_symmetries,
|
|
131
|
+
# reflection_symmetries,
|
|
132
|
+
# rotation_counts,
|
|
133
|
+
# simulation_type,
|
|
134
|
+
# )
|
|
135
|
+
|
|
122
136
|
custom_grid_flg: bool = _error_checker(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
137
|
+
mol_lst,
|
|
138
|
+
rot_syms,
|
|
139
|
+
refl_syms,
|
|
140
|
+
rot_cnts,
|
|
127
141
|
simulation_type,
|
|
128
142
|
dosing_distribution,
|
|
129
143
|
boundary_condition,
|
|
@@ -133,6 +147,8 @@ def run_simulation( # noqa: PLR0913
|
|
|
133
147
|
bounding_y_coord,
|
|
134
148
|
)
|
|
135
149
|
|
|
150
|
+
|
|
151
|
+
|
|
136
152
|
# The seed is defined as the datetime in microseconds. The seed is stored so simulations can be verified.
|
|
137
153
|
how_late = datetime.now(UTC) if version_info >= (3, 11) else datetime.utcnow()
|
|
138
154
|
seed = int(how_late.strftime("%Y%m%d%H%M%S%f")) if seed is None else seed
|
|
@@ -155,29 +171,35 @@ def run_simulation( # noqa: PLR0913
|
|
|
155
171
|
|
|
156
172
|
surf = Surface(rsa_config, lattice_type=lattice_type, lattice_a=lattice_a, site_count=site_count)
|
|
157
173
|
if custom_grid_flg:
|
|
174
|
+
if TYPE_CHECKING:
|
|
175
|
+
if site_x_coords is None or site_y_coords is None or bounding_x_coord is None or bounding_y_coord is None:
|
|
176
|
+
errmsg = "Site_x_coords, site_y_coords, bounding_x_coord, bounding_y_coord must be provided."
|
|
177
|
+
raise TypeError(errmsg)
|
|
178
|
+
|
|
158
179
|
surf.generate_custom_surface(site_x_coords, site_y_coords, bounding_x_coord, bounding_y_coord)
|
|
159
180
|
else:
|
|
160
181
|
surf.generate_grid(rng)
|
|
161
182
|
|
|
162
183
|
molecules = [] # Initially, there are none.
|
|
163
|
-
rot_syms = rotation_symmetries # Rotation symmetry
|
|
164
|
-
mirror_syms = reflection_symmetries # Mirror symmetry
|
|
165
|
-
rot_cnts = rotation_counts
|
|
166
184
|
mgc: count[int] = count()
|
|
185
|
+
stick_prob: DistArray = np.array([1.])
|
|
167
186
|
if isinstance(sticking_probability, float):
|
|
168
|
-
|
|
169
|
-
elif
|
|
187
|
+
stick_prob = np.array([sticking_probability] * len(mol_lst))
|
|
188
|
+
elif isinstance(sticking_probability, list):
|
|
189
|
+
stick_prob = np.array(sticking_probability)
|
|
190
|
+
elif not isinstance(sticking_probability, np.ndarray) and sticking_probability is not None:
|
|
170
191
|
errmsg = "sticking_probability must be a float, list, or np.ndarray"
|
|
171
192
|
raise TypeError(errmsg)
|
|
172
193
|
|
|
194
|
+
|
|
173
195
|
pp: Polygon
|
|
174
|
-
for idx, (pp, stick) in enumerate(zip(
|
|
196
|
+
for idx, (pp, stick) in enumerate(zip(mol_lst, stick_prob, strict=True)):
|
|
175
197
|
molecules.append(
|
|
176
198
|
MoleculeGroup(
|
|
177
199
|
rsa_config,
|
|
178
200
|
pp,
|
|
179
201
|
rot_syms[idx],
|
|
180
|
-
|
|
202
|
+
refl_syms[idx],
|
|
181
203
|
surf.all_site_count,
|
|
182
204
|
mgc,
|
|
183
205
|
rot_cnts[idx],
|
|
@@ -244,7 +266,7 @@ def _run_codosing(
|
|
|
244
266
|
molecules: list[MoleculeGroup],
|
|
245
267
|
time_count: count[int],
|
|
246
268
|
timestep_limit: int,
|
|
247
|
-
dosing_distribution: list[float] | None = None,
|
|
269
|
+
dosing_distribution: list[float] | DistArray | None = None,
|
|
248
270
|
) -> None:
|
|
249
271
|
for moldx, molgr in enumerate(sim.molgroups):
|
|
250
272
|
while molgr.vacancy_count and next(time_count) < timestep_limit:
|
|
@@ -312,11 +334,12 @@ def _run_flux_fixedrotation(
|
|
|
312
334
|
"""
|
|
313
335
|
mol_flux: list[int] = []
|
|
314
336
|
all_phis: list[int] = []
|
|
337
|
+
mol_array: GeoArray = np.array(molecules)
|
|
315
338
|
for step in range(timestep_limit):
|
|
316
339
|
if not np.any([molgroup.vacancy_count for molgroup in molecules]):
|
|
317
340
|
break # If nothing is available, terminate.
|
|
318
341
|
|
|
319
|
-
randmol: MoleculeGroup = sim.rng.choice(
|
|
342
|
+
randmol: MoleculeGroup = sim.rng.choice(mol_array, p=distribution) # mypy complains without np.array.
|
|
320
343
|
if not randmol.vacancy_count:
|
|
321
344
|
continue
|
|
322
345
|
flag, *_, phi = sim.attempt_place_molecule(surf, randmol)
|
|
@@ -391,7 +414,7 @@ def _error_checker(
|
|
|
391
414
|
reflection_symmetries: BoolArray,
|
|
392
415
|
rotation_counts: IdxArray,
|
|
393
416
|
simulation_type: str,
|
|
394
|
-
dosing_distribution: list[float] | None = None,
|
|
417
|
+
dosing_distribution: list[float] | DistArray | None = None,
|
|
395
418
|
boundary_condition: str | None = None,
|
|
396
419
|
site_x_coords: DistArray | None = None,
|
|
397
420
|
site_y_coords: DistArray | None = None,
|
|
@@ -497,7 +520,7 @@ def _select_and_run(
|
|
|
497
520
|
include_rejected_flux: bool,
|
|
498
521
|
time_count: count[int],
|
|
499
522
|
timestep_limit: int,
|
|
500
|
-
dosing_distribution: list[float] | None = None,
|
|
523
|
+
dosing_distribution: list[float] | DistArray | None = None,
|
|
501
524
|
) -> tuple[IdxArray, IdxArray]:
|
|
502
525
|
"""Select and run. A collection of the simulations. Putting them in one function helps streamline adjusting them.
|
|
503
526
|
|
|
@@ -250,7 +250,7 @@ def test_surfacetype_invalid_input():
|
|
|
250
250
|
"""Is an error raised when the lattice type is incorrect?"""
|
|
251
251
|
with pytest.raises(ValueError):
|
|
252
252
|
rsarun.Surface(
|
|
253
|
-
|
|
253
|
+
RsaConfig(
|
|
254
254
|
join(dirname(__file__), "test_data", "config_test_soft.json")
|
|
255
255
|
),
|
|
256
256
|
"Dogbonium",
|
|
@@ -153,6 +153,12 @@ def test_run_simulation_boundary_conditions(rsa_config, default_polygon):
|
|
|
153
153
|
results = run_simulation(rsa_config, seed=SEED, molecules_list=[default_polygon], boundary_condition=boundary)
|
|
154
154
|
assert len(results[0]) == 1
|
|
155
155
|
|
|
156
|
+
def test_run_simulation_sticking_probability(rsa_config, default_polygon, subtests):
|
|
157
|
+
"""Test different sticking probability types."""
|
|
158
|
+
for stck in (0.5, [0.5], np.array([0.5])):
|
|
159
|
+
with subtests.test(f"Sticking type {type(stck)}"):
|
|
160
|
+
results = run_simulation(rsa_config, seed=SEED, molecules_list=[default_polygon], sticking_probability=stck)
|
|
161
|
+
assert len(results[0]) == 1
|
|
156
162
|
|
|
157
163
|
def test_run_simulation_randomness(rsa_config, default_polygon, monkeypatch, subtests):
|
|
158
164
|
"""Test the randomness based on datetime seed."""
|
|
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
|
|
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
|