pyafv 0.3.1__cp313-cp313-musllinux_1_2_i686.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.
@@ -0,0 +1,117 @@
1
+ import numpy as np
2
+ from scipy.optimize import minimize
3
+ from dataclasses import dataclass, replace
4
+
5
+
6
+ def sigmoid(x):
7
+ # stable sigmoid that handles large |x|
8
+ if x >= 0:
9
+ z = np.exp(-x)
10
+ return 1 / (1 + z)
11
+ else:
12
+ z = np.exp(x)
13
+ return z / (1 + z)
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class PhysicalParams:
18
+ # Radius (maximal) of the Voronoi cells
19
+ r: float = 1.0
20
+ A0: float = np.pi # Preferred area of the Voronoi cells
21
+ P0: float = 4.8 # Preferred perimeter of the Voronoi cells
22
+ KA: float = 1.0 # Area elasticity
23
+ KP: float = 1.0 # Perimeter elasticity
24
+ lambda_tension: float = 0.2 # Tension difference
25
+ delta: float = 0. # Small offset to avoid singularities
26
+
27
+ def get_steady_state(self):
28
+ # compute steady-state (l,d) given physical params
29
+ params = [self.KA, self.KP, self.A0, self.P0, self.lambda_tension]
30
+ result = self._minimize_energy(params, restarts=10)
31
+ l, d = result[0]
32
+ return l, d
33
+
34
+ def with_optimal_radius(self):
35
+ """Returns a new instance with the radius updated to steady state."""
36
+ l, d = self.get_steady_state()
37
+ new_params = replace(self, r=l)
38
+ return new_params
39
+
40
+ def with_delta(self, delta_new: float):
41
+ """Returns a new instance with the specified delta."""
42
+ return replace(self, delta=delta_new)
43
+
44
+ def _energy_unconstrained(self, z, params):
45
+ v, u = float(z[0]), float(z[1])
46
+ l = np.exp(v) # l > 0
47
+ phi = 0.5*np.pi * sigmoid(u) # phi in (0, pi/2)
48
+ s, c = np.sin(phi), np.cos(phi)
49
+ theta = np.pi + 2.0*phi
50
+ A = 0.5*l*l*(theta + np.sin(2.0*phi))
51
+ P = 2.0*l*c + l*theta
52
+ ln = l*theta
53
+
54
+ KA, KP, A0, P0, Lambda = params
55
+ return KA * (A - A0)**2 + KP * (P - P0)**2 + Lambda * ln
56
+
57
+ def _minimize_energy(self, params, restarts=10, seed=None):
58
+ rng = np.random.default_rng(seed)
59
+ best = None
60
+ for _ in range(restarts):
61
+ z0 = rng.normal(size=2)
62
+
63
+ res = minimize(lambda z: self._energy_unconstrained(z, params), z0, method="BFGS",
64
+ options={"gtol": 1e-8, "maxiter": 1e4})
65
+ val = res.fun
66
+ z = res.x
67
+
68
+ if (best is None) or (val < best[0]):
69
+ best = (val, z)
70
+
71
+ # map back to (l,d)
72
+ val, z = best
73
+ v, u = float(z[0]), float(z[1])
74
+ l = np.exp(v)
75
+ phi = 0.5*np.pi * sigmoid(u)
76
+ d = l*np.sin(phi)
77
+
78
+ return [l, d], val
79
+
80
+
81
+ def target_delta(params: PhysicalParams, target_force: float) -> float:
82
+ """
83
+ Given physical parameters and a target detachment force, compute the corresponding delta.
84
+ """
85
+ KP, A0, P0, Lambda = params.KP, params.A0, params.P0, params.lambda_tension
86
+ l = params.r
87
+
88
+ distances = np.linspace(1e-6, 2*l-(1e-6), 10_000)
89
+ detachment_forces = []
90
+ for distance in distances:
91
+ epsilon = l - (distance/2.)
92
+
93
+ theta = 2 * np.pi - 2 * np.arctan2(np.sqrt(l**2 - (l - epsilon)**2), l - epsilon)
94
+ A = (l - epsilon) * np.sqrt(l**2 -
95
+ (l - epsilon)**2) + 0.5 * (l**2 * theta)
96
+ P = 2 * np.sqrt(l**2 - (l - epsilon)**2) + l * theta
97
+
98
+ f = 4. * np.sqrt((2-epsilon) * epsilon) * (A - A0 + KP * ((P - P0)/(2 - epsilon))
99
+ + (Lambda/2) * (1./((2-epsilon)*epsilon)))
100
+ detachment_forces.append(f)
101
+
102
+ # print(detachment_forces)
103
+
104
+ detachment_forces = np.array(detachment_forces)
105
+
106
+ idx = np.abs(detachment_forces[None, :] - target_force).argmin()
107
+ target_distances = distances[idx]
108
+
109
+ delta = np.sqrt(4*(l**2) - target_distances**2)
110
+
111
+ return delta
112
+
113
+
114
+ __all__ = [
115
+ "PhysicalParams",
116
+ "target_delta",
117
+ ]
pyafv/simulator.py ADDED
@@ -0,0 +1,37 @@
1
+ # API-facing wrapper
2
+
3
+ from .backend import backend_simulator, _BACKEND_NAME
4
+
5
+
6
+ class FiniteVoronoiSimulator(backend_simulator):
7
+ """Finite Voronoi Simulator.
8
+
9
+ This class provides an interface to simulate finite Voronoi models.
10
+ It wraps around the backend simulator implementation, which may be
11
+ either a Cython-accelerated version or a pure Python fallback.
12
+
13
+ Attributes:
14
+ See `backend_simulator` for details.
15
+ """
16
+ # Define as a class attribute
17
+ _BACKEND = _BACKEND_NAME
18
+
19
+ def __init__(self, *args, **kwargs):
20
+ # Ensure you call the parent constructor
21
+ super().__init__(*args, **kwargs)
22
+
23
+ if self._BACKEND not in {"cython", "numba"}: # pragma: no cover
24
+ # raise warning to inform user about fallback
25
+ import warnings
26
+ warnings.warn(
27
+ "Could not import the Cython-accelerated module. "
28
+ "Falling back to the pure Python implementation, which may be slower. "
29
+ "To enable the accelerated version, ensure that all dependencies are installed.",
30
+ RuntimeWarning,
31
+ stacklevel=2,
32
+ )
33
+
34
+
35
+ __all__ = [
36
+ "FiniteVoronoiSimulator",
37
+ ]
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyafv
3
+ Version: 0.3.1
4
+ Summary: Python implementation of the active-finite-Voronoi (AFV) model
5
+ Author-email: "Wei Wang (汪巍)" <ww000721@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Wei Wang
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Download, https://test.pypi.org/project/pyafv/#files
29
+ Project-URL: Source Code, https://github.com/wwang721/pyafv
30
+ Requires-Python: >=3.11.11
31
+ Description-Content-Type: text/markdown
32
+ License-File: LICENSE
33
+ Requires-Dist: numpy>=2.1.3
34
+ Requires-Dist: scipy>=1.15.3
35
+ Requires-Dist: matplotlib>=3.10.7
36
+ Provides-Extra: examples
37
+ Requires-Dist: ipywidgets>=8.1.5; extra == "examples"
38
+ Requires-Dist: jupyter>=1.1.0; extra == "examples"
39
+ Requires-Dist: tqdm>=4.67.1; extra == "examples"
40
+ Dynamic: license-file
41
+
42
+ <!--[![Tests](https://github.com/wwang721/pyafv/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/wwang721/pyafv/actions/workflows/tests.yml?query=branch:main)-->
43
+ [![pytest](https://github.com/wwang721/pyafv/actions/workflows/tests.yml/badge.svg)](https://github.com/wwang721/pyafv/actions/workflows/tests.yml)
44
+ [![codecov](https://codecov.io/github/wwang721/pyafv/branch/main/graph/badge.svg?token=VSXSOX8HVS)](https://codecov.io/github/wwang721/pyafv/tree/main)
45
+ [![DOI](https://zenodo.org/badge/1124385738.svg)](https://doi.org/10.5281/zenodo.18091659)
46
+
47
+ Python code that implements the **active-finite-Voronoi (AFV) model**.
48
+ The AFV framework was introduced and developed in, for example, Refs. [[1](#huang2023bridging)&ndash;[3](#wang2026divergence)].
49
+
50
+
51
+ ## More information
52
+
53
+ GitHub: [https://github.com/wwang721/pyafv](https://github.com/wwang721/pyafv)
54
+
55
+ See important [**issues**](https://github.com/wwang721/pyafv/issues?q=is%3Aissue%20state%3Aclosed) for additional context, such as:
56
+ * [QhullError when 3+ points are collinear #1](https://github.com/wwang721/pyafv/issues/1) [Closed - see [comments](https://github.com/wwang721/pyafv/issues/1#issuecomment-3701355742)]
57
+ * [Add customized plotting to examples illustrating access to vertices and edges #5](https://github.com/wwang721/pyafv/issues/5) [Completed in PR [#7](https://github.com/wwang721/pyafv/pull/7)]
58
+ * [Time step dependence of intercellular adhesion in simulations #8](https://github.com/wwang721/pyafv/issues/8) [Closed in PR [#9](https://github.com/wwang721/pyafv/pull/9)]
59
+
60
+
61
+ ## References
62
+
63
+ <table>
64
+ <tr>
65
+ <td id="huang2023bridging" valign="top">[1]</td>
66
+ <td>
67
+ J. Huang, H. Levine, and D. Bi, <em>Bridging the gap between collective motility and epithelial-mesenchymal transitions through the active finite Voronoi model</em>, <a href="https://doi.org/10.1039/D3SM00327B">Soft Matter <strong>19</strong>, 9389 (2023)</a>.
68
+ </td>
69
+ </tr>
70
+ <tr>
71
+ <td id="teomy2018confluent" valign="top">[2]</td>
72
+ <td>
73
+ E. Teomy, D. A. Kessler, and H. Levine, <em>Confluent and nonconfluent phases in a model of cell tissue</em>, <a href="https://doi.org/10.1103/PhysRevE.98.042418">Phys. Rev. E <strong>98</strong>, 042418 (2018)</a>.
74
+ </td>
75
+ </tr>
76
+ <tr>
77
+ <td id="wang2026divergence" valign="top">[3]</td>
78
+ <td>
79
+ W. Wang (汪巍) and B. A. Camley, <em>Divergence of detachment forces in the finite-Voronoi model</em>, manuscript in preparation (2026).
80
+ </td>
81
+ </tr>
82
+ </table>
83
+
@@ -0,0 +1,13 @@
1
+ pyafv/cell_geom.pyx,sha256=Yemf_8GcgwynR-4dRwbNJPnEH9P1qGejgxKJCIzJC08,18299
2
+ pyafv/backend.py,sha256=p0gXsoZdNxytiBhg-txa9nD1HLzSZUwKPFE8BdWAHAY,395
3
+ pyafv/simulator.py,sha256=NzL4Fu6w-3fdS8zmagfekKrUH3uR5kMSyz13rs0Xv7E,1214
4
+ pyafv/finite_voronoi_fallback.py,sha256=NiguvSeLUbDQ2wOH3bnx0rxzQWBEbuP5-sjkWruQigg,42827
5
+ pyafv/finite_voronoi_fast.py,sha256=tjzzPpCCNlQ_5cnglTsdBV2IV6Zw-GKpGiS_x81dBNY,36095
6
+ pyafv/physical_params.py,sha256=QPM1CCLx_dlof1WsykHwMLfRMctr5ALlMLVmrpiSp_c,3901
7
+ pyafv/__init__.py,sha256=yCP6T5JFYghx6zMKR-_Aci08vSmOj_w7rh3xoOkB518,215
8
+ pyafv/cell_geom.cpython-313-i386-linux-musl.so,sha256=-mF8gkabbpSvC05RpRi9K8zEwIDDBA9vTztoekWiFgg,1555124
9
+ pyafv-0.3.1.dist-info/WHEEL,sha256=I3qXEeYII2DAKChe42mwue5TBWcnIOptn9ocRU9pF-E,110
10
+ pyafv-0.3.1.dist-info/top_level.txt,sha256=mrKQNqc4GQxuZ7hd5UrKxbA_AJsuSqiJyMxL7Nu7va0,6
11
+ pyafv-0.3.1.dist-info/METADATA,sha256=py5if-a6eBS_QCLRkjSZCNAXo9IBe18YH1BxISashfg,4425
12
+ pyafv-0.3.1.dist-info/RECORD,,
13
+ pyafv-0.3.1.dist-info/licenses/LICENSE,sha256=TNjxBxdiOzyewn2FP7g1FjW3CJoxiGCY6ShPVFv02G8,1065
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-musllinux_1_2_i686
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Wei Wang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ pyafv