pyafv 0.3.4__cp311-cp311-win_arm64.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,160 @@
1
+ from __future__ import annotations
2
+ import numpy as np
3
+ from scipy.optimize import minimize
4
+ from dataclasses import dataclass, replace
5
+
6
+
7
+ def sigmoid(x):
8
+ # stable sigmoid that handles large |x|
9
+ if x >= 0:
10
+ z = np.exp(-x)
11
+ return 1 / (1 + z)
12
+ else:
13
+ z = np.exp(x)
14
+ return z / (1 + z)
15
+
16
+
17
+ @dataclass(frozen=True)
18
+ class PhysicalParams:
19
+ """Physical parameters for the active-finite-Voronoi (AFV) model.
20
+
21
+ Caveat:
22
+ Frozen dataclass is used to ensure immutability of instances.
23
+ """
24
+
25
+ r: float = 1.0
26
+ """Radius (maximal) of the Voronoi cells."""
27
+
28
+ A0: float = np.pi
29
+ """Preferred area of the Voronoi cells."""
30
+
31
+ P0: float = 4.8
32
+ """Preferred perimeter of the Voronoi cells."""
33
+
34
+ KA: float = 1.0
35
+ """Area elasticity constant."""
36
+
37
+ KP: float = 1.0
38
+ """Perimeter elasticity constant."""
39
+
40
+ lambda_tension: float = 0.2
41
+ """Tension difference between non-contacting edges and contacting edges."""
42
+
43
+ delta: float = 0.0
44
+ """Small offset to avoid singularities in computations."""
45
+
46
+ def get_steady_state(self) -> tuple[float, float]:
47
+ """Compute steady-state (l,d) given physical params.
48
+
49
+ :return: Tuple of (l, d) at steady state.
50
+ :rtype: tuple[float, float]
51
+ """
52
+ params = [self.KA, self.KP, self.A0, self.P0, self.lambda_tension]
53
+ result = self._minimize_energy(params, restarts=10)
54
+ l, d = result[0]
55
+ return l, d
56
+
57
+ def with_optimal_radius(self) -> PhysicalParams:
58
+ """Returns a new instance with the radius updated to steady state.
59
+
60
+ :return: New instance with optimal radius.
61
+ :rtype: PhysicalParams
62
+ """
63
+ l, d = self.get_steady_state()
64
+ new_params = replace(self, r=l)
65
+ return new_params
66
+
67
+ def with_delta(self, delta_new: float) -> PhysicalParams:
68
+ """Returns a new instance with the specified delta.
69
+
70
+ :param delta_new: New delta value.
71
+ :type delta_new: float
72
+
73
+ :return: New instance with updated delta.
74
+ :rtype: PhysicalParams
75
+ """
76
+ return replace(self, delta=delta_new)
77
+
78
+ def _energy_unconstrained(self, z, params):
79
+ v, u = float(z[0]), float(z[1])
80
+ l = np.exp(v) # l > 0
81
+ phi = 0.5*np.pi * sigmoid(u) # phi in (0, pi/2)
82
+ s, c = np.sin(phi), np.cos(phi)
83
+ theta = np.pi + 2.0*phi
84
+ A = 0.5*l*l*(theta + np.sin(2.0*phi))
85
+ P = 2.0*l*c + l*theta
86
+ ln = l*theta
87
+
88
+ KA, KP, A0, P0, Lambda = params
89
+ return KA * (A - A0)**2 + KP * (P - P0)**2 + Lambda * ln
90
+
91
+ def _minimize_energy(self, params, restarts=10, seed=None):
92
+ rng = np.random.default_rng(seed)
93
+ best = None
94
+ for _ in range(restarts):
95
+ z0 = rng.normal(size=2)
96
+
97
+ res = minimize(lambda z: self._energy_unconstrained(z, params), z0, method="BFGS",
98
+ options={"gtol": 1e-8, "maxiter": 1e4})
99
+ val = res.fun
100
+ z = res.x
101
+
102
+ if (best is None) or (val < best[0]):
103
+ best = (val, z)
104
+
105
+ # map back to (l,d)
106
+ val, z = best
107
+ v, u = float(z[0]), float(z[1])
108
+ l = np.exp(v)
109
+ phi = 0.5*np.pi * sigmoid(u)
110
+ d = l*np.sin(phi)
111
+
112
+ return [l, d], val
113
+
114
+
115
+ def target_delta(params: PhysicalParams, target_force: float) -> float:
116
+ """
117
+ Given physical parameters and a target detachment force, compute the corresponding delta.
118
+
119
+ :param params: Physical parameters of the AFV model.
120
+ :type params: PhysicalParams
121
+
122
+ :param target_force: Target detachment force.
123
+ :type target_force: float
124
+
125
+ :return: Corresponding delta value.
126
+ :rtype: float
127
+ """
128
+ KP, A0, P0, Lambda = params.KP, params.A0, params.P0, params.lambda_tension
129
+ l = params.r
130
+
131
+ distances = np.linspace(1e-6, 2*l-(1e-6), 10_000)
132
+ detachment_forces = []
133
+ for distance in distances:
134
+ epsilon = l - (distance/2.)
135
+
136
+ theta = 2 * np.pi - 2 * np.arctan2(np.sqrt(l**2 - (l - epsilon)**2), l - epsilon)
137
+ A = (l - epsilon) * np.sqrt(l**2 -
138
+ (l - epsilon)**2) + 0.5 * (l**2 * theta)
139
+ P = 2 * np.sqrt(l**2 - (l - epsilon)**2) + l * theta
140
+
141
+ f = 4. * np.sqrt((2-epsilon) * epsilon) * (A - A0 + KP * ((P - P0)/(2 - epsilon))
142
+ + (Lambda/2) * (1./((2-epsilon)*epsilon)))
143
+ detachment_forces.append(f)
144
+
145
+ # print(detachment_forces)
146
+
147
+ detachment_forces = np.array(detachment_forces)
148
+
149
+ idx = np.abs(detachment_forces[None, :] - target_force).argmin()
150
+ target_distances = distances[idx]
151
+
152
+ delta = np.sqrt(4*(l**2) - target_distances**2)
153
+
154
+ return delta
155
+
156
+
157
+ __all__ = [
158
+ "PhysicalParams",
159
+ "target_delta",
160
+ ]
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyafv
3
+ Version: 0.3.4
4
+ Summary: Python implementation of the active-finite-Voronoi (AFV) model
5
+ Author-email: "Wei Wang (汪巍)" <ww000721@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Download, https://pypi.org/project/pyafv/#files
8
+ Project-URL: Source Code, https://github.com/wwang721/pyafv
9
+ Keywords: voronoi-model,cellular-patterns,biological-modeling
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Topic :: Scientific/Engineering
22
+ Requires-Python: <3.15,>=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: numpy>=1.26.4
26
+ Requires-Dist: scipy>=1.13.1
27
+ Requires-Dist: matplotlib>=3.8.4
28
+ Provides-Extra: examples
29
+ Requires-Dist: ipywidgets>=8.1.5; extra == "examples"
30
+ Requires-Dist: jupyter>=1.1.0; extra == "examples"
31
+ Requires-Dist: tqdm>=4.67.1; extra == "examples"
32
+ Dynamic: license-file
33
+
34
+ [![PyPi](https://img.shields.io/pypi/v/pyafv)](https://pypi.org/project/pyafv/)
35
+ [![Downloads](https://img.shields.io/pypi/dm/pyafv.svg)](https://pypi.org/project/pyafv/)
36
+ [![Zenodo](https://zenodo.org/badge/1124385738.svg)](https://doi.org/10.5281/zenodo.18091659)
37
+ <!--[![pytest](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)-->
38
+ [![pytest](https://github.com/wwang721/pyafv/actions/workflows/tests.yml/badge.svg)](https://github.com/wwang721/pyafv/actions/workflows/tests.yml)
39
+ [![codecov](https://codecov.io/github/wwang721/pyafv/branch/main/graph/badge.svg?token=VSXSOX8HVS)](https://codecov.io/github/wwang721/pyafv/tree/main)
40
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
41
+
42
+
43
+ # PyAFV
44
+
45
+ Python code that implements the **active-finite-Voronoi (AFV) model** in 2D.
46
+ The AFV framework was introduced and developed in, for example, Refs. [[1](#huang2023bridging)&ndash;[3](#wang2026divergence)].
47
+
48
+
49
+ ## Installation
50
+
51
+ To install **PyAFV** with `pip`, run:
52
+ ```bash
53
+ pip install pyafv
54
+ ```
55
+ The package supports Python ≥ 3.9 and < 3.15.
56
+ To verify that the installation was successful and that the correct version is installed, run the following in Python:
57
+ ```python
58
+ import pyafv
59
+ print(pyafv.__version__)
60
+ ```
61
+
62
+
63
+ ## Usage
64
+
65
+ <!--Using `uv run python`, you should be able to import `pyafv` from anywhere within the repository directory.-->
66
+ The following example demonstrates how to construct a finite-Voronoi diagram:
67
+ ```python
68
+ import numpy as np
69
+ import pyafv as afv
70
+
71
+ N = 100 # number of cells
72
+ pts = np.random.rand(N, 2) * 10 # initial positions
73
+ params = afv.PhysicalParams() # use default parameter values
74
+ sim = afv.FiniteVoronoiSimulator(pts, params) # initialize the simulator
75
+ sim.plot_2d(show=True) # visualize the Voronoi diagram
76
+ ```
77
+ To compute the conservative forces and extract detailed geometric information (e.g., cell areas, vertices, and edges), call:
78
+ ```python
79
+ diag = sim.build()
80
+ ```
81
+ The returned object `diag` is a Python `dict` containing these quantities.
82
+
83
+
84
+ ## More information
85
+
86
+ GitHub: [https://github.com/wwang721/pyafv](https://github.com/wwang721/pyafv)
87
+
88
+ See important [**issues**](https://github.com/wwang721/pyafv/issues?q=is%3Aissue%20state%3Aclosed) for additional context, such as:
89
+ * [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)]
90
+ * [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)]
91
+ * [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)]
92
+
93
+ Full documentation on [readthedocs](https://pyafv.readthedocs.io/en/latest/)!
94
+
95
+ ## References
96
+
97
+ <table>
98
+ <tr>
99
+ <td id="huang2023bridging" valign="top">[1]</td>
100
+ <td>
101
+ 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>.
102
+ </td>
103
+ </tr>
104
+ <tr>
105
+ <td id="teomy2018confluent" valign="top">[2]</td>
106
+ <td>
107
+ 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>.
108
+ </td>
109
+ </tr>
110
+ <tr>
111
+ <td id="wang2026divergence" valign="top">[3]</td>
112
+ <td>
113
+ W. Wang (汪巍) and B. A. Camley, <em>Divergence of detachment forces in the finite-Voronoi model</em>, manuscript in preparation (2026).
114
+ </td>
115
+ </tr>
116
+ </table>
@@ -0,0 +1,12 @@
1
+ pyafv/__init__.py,sha256=xq3i-S8DIbYIJ1VgHV-CYY44OV3RU926fLvdfDpJsEI,573
2
+ pyafv/_version.py,sha256=4dFMgMxXy6i7Osz479bSd0-ZlU_IvZsjVSlxs1zHUGM,44
3
+ pyafv/backend.py,sha256=MlQThqIlTGXt__dj44rSutZLexKJTl9NaOEZ5s1otns,438
4
+ pyafv/cell_geom.cp311-win_arm64.pyd,sha256=JfVEnjraiSesJfWx_7pnVRS2oYa2tpWDkoHXoG6j2Xs,192512
5
+ pyafv/cell_geom_fallback.py,sha256=mLUvz225eqQYYZQ5SOv81NfLtFem9ArxCgo_qVWtuDw,9376
6
+ pyafv/finite_voronoi.py,sha256=vwm1TICgex3h1ay5_C4mx26BaNoePsmxN-pVap3gFZY,40017
7
+ pyafv/physical_params.py,sha256=lEM9bpBjfTqhdLbkDTYjA5RRlFFTSZ0WptpxBegt40I,4983
8
+ pyafv-0.3.4.dist-info/licenses/LICENSE,sha256=UHfiLQ93gkQMOoN559ZBeG9kywkNcvDgxA9MRniWOpY,1086
9
+ pyafv-0.3.4.dist-info/METADATA,sha256=SrbS9lsTk1T2T9b2JGQpe39Uez9ZLEpf84FbvaXw37w,5506
10
+ pyafv-0.3.4.dist-info/WHEEL,sha256=_6dVEvfjMkp6KZZXihi2C2UP-ewiZXAMezDMkPqYmGo,101
11
+ pyafv-0.3.4.dist-info/top_level.txt,sha256=mrKQNqc4GQxuZ7hd5UrKxbA_AJsuSqiJyMxL7Nu7va0,6
12
+ pyafv-0.3.4.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp311-cp311-win_arm64
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