pyafv 0.3.8__cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.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,157 @@
1
+ from __future__ import annotations
2
+ import numpy as np
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
+ """Physical parameters for the active-finite-Voronoi (AFV) model.
19
+
20
+ Caveat:
21
+ Frozen dataclass is used for :py:class:`PhysicalParams` to ensure immutability of instances.
22
+
23
+ Args:
24
+ r: Radius (maximal) of the Voronoi cells.
25
+ A0: Preferred area of the Voronoi cells.
26
+ P0: Preferred perimeter of the Voronoi cells.
27
+ KA: Area elasticity constant.
28
+ KP: Perimeter elasticity constant.
29
+ lambda_tension: Tension difference between non-contacting edges and contacting edges.
30
+ delta: Small offset to avoid singularities in computations.
31
+ """
32
+
33
+ r: float = 1.0 #: Radius (maximal) of the Voronoi cells.
34
+ A0: float = np.pi #: Preferred area of the Voronoi cells.
35
+ P0: float = 4.8 #: Preferred perimeter of the Voronoi cells.
36
+ KA: float = 1.0 #: Area elasticity constant.
37
+ KP: float = 1.0 #: Perimeter elasticity constant.
38
+ lambda_tension: float = 0.2 #: Tension difference between non-contacting edges and contacting edges.
39
+ delta: float = 0.0 #: Small offset to avoid singularities in computations.
40
+
41
+
42
+ def get_steady_state(self) -> tuple[float, float]:
43
+ r"""Compute steady-state (l,d) for the given physical parameters.
44
+
45
+ Returns:
46
+ Steady-state :math:`(\ell,d)` values.
47
+ """
48
+ params = [self.KA, self.KP, self.A0, self.P0, self.lambda_tension]
49
+ result = self._minimize_energy(params, restarts=10)
50
+ l, d = result[0]
51
+ return l, d
52
+
53
+ def with_optimal_radius(self) -> PhysicalParams:
54
+ """Returns a new instance with the radius updated to steady state.
55
+
56
+ Returns:
57
+ New instance with optimal radius.
58
+ """
59
+ l, d = self.get_steady_state()
60
+ new_params = replace(self, r=l)
61
+ return new_params
62
+
63
+ def with_delta(self, delta_new: float) -> PhysicalParams:
64
+ """Returns a new instance with the specified delta.
65
+
66
+ Args:
67
+ delta_new: New delta value.
68
+
69
+ Returns:
70
+ New instance with updated delta.
71
+ """
72
+ return replace(self, delta=delta_new)
73
+
74
+ def _energy_unconstrained(self, z, params):
75
+ v, u = float(z[0]), float(z[1])
76
+ l = np.exp(v) # l > 0
77
+ phi = 0.5*np.pi * sigmoid(u) # phi in (0, pi/2)
78
+ s, c = np.sin(phi), np.cos(phi)
79
+ theta = np.pi + 2.0*phi
80
+ A = 0.5*l*l*(theta + np.sin(2.0*phi))
81
+ P = 2.0*l*c + l*theta
82
+ ln = l*theta
83
+
84
+ KA, KP, A0, P0, Lambda = params
85
+ return KA * (A - A0)**2 + KP * (P - P0)**2 + Lambda * ln
86
+
87
+ def _minimize_energy(self, params, restarts=10, seed=None):
88
+
89
+ from scipy.optimize import minimize
90
+
91
+ rng = np.random.default_rng(seed)
92
+ best = None
93
+ for _ in range(restarts):
94
+ z0 = rng.normal(size=2)
95
+
96
+ res = minimize(lambda z: self._energy_unconstrained(z, params), z0, method="BFGS",
97
+ options={"gtol": 1e-8, "maxiter": 1e4})
98
+ val = res.fun
99
+ z = res.x
100
+
101
+ if (best is None) or (val < best[0]):
102
+ best = (val, z)
103
+
104
+ # map back to (l,d)
105
+ val, z = best
106
+ v, u = float(z[0]), float(z[1])
107
+ l = np.exp(v)
108
+ phi = 0.5*np.pi * sigmoid(u)
109
+ d = l*np.sin(phi)
110
+
111
+ return [l, d], val
112
+
113
+
114
+ def target_delta(params: PhysicalParams, target_force: float) -> float:
115
+ r"""
116
+ Given the physical parameters and a target detachment force, compute the corresponding delta.
117
+
118
+ Args:
119
+ params: Physical parameters of the AFV model.
120
+ target_force: Target detachment force.
121
+
122
+ Returns:
123
+ Corresponding small cutoff :math:`\delta`'s value.
124
+ """
125
+ KP, A0, P0, Lambda = params.KP, params.A0, params.P0, params.lambda_tension
126
+ l = params.r
127
+
128
+ distances = np.linspace(1e-6, 2*l-(1e-6), 10_000)
129
+ detachment_forces = []
130
+ for distance in distances:
131
+ epsilon = l - (distance/2.)
132
+
133
+ theta = 2 * np.pi - 2 * np.arctan2(np.sqrt(l**2 - (l - epsilon)**2), l - epsilon)
134
+ A = (l - epsilon) * np.sqrt(l**2 -
135
+ (l - epsilon)**2) + 0.5 * (l**2 * theta)
136
+ P = 2 * np.sqrt(l**2 - (l - epsilon)**2) + l * theta
137
+
138
+ f = 4. * np.sqrt((2-epsilon) * epsilon) * (A - A0 + KP * ((P - P0)/(2 - epsilon))
139
+ + (Lambda/2) * (1./((2-epsilon)*epsilon)))
140
+ detachment_forces.append(f)
141
+
142
+ # print(detachment_forces)
143
+
144
+ detachment_forces = np.array(detachment_forces)
145
+
146
+ idx = np.abs(detachment_forces[None, :] - target_force).argmin()
147
+ target_distances = distances[idx]
148
+
149
+ delta = np.sqrt(4*(l**2) - target_distances**2)
150
+
151
+ return delta
152
+
153
+
154
+ __all__ = [
155
+ "PhysicalParams",
156
+ "target_delta",
157
+ ]
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyafv
3
+ Version: 0.3.8
4
+ Summary: Python implementation of the active-finite-Voronoi (AFV) model
5
+ Project-URL: Homepage, https://github.com/wwang721/pyafv
6
+ Project-URL: Download, https://pypi.org/project/pyafv/#files
7
+ Project-URL: Source Code, https://github.com/wwang721/pyafv
8
+ Project-URL: Documentation, https://pyafv.readthedocs.io/
9
+ Project-URL: Changelog, https://github.com/wwang721/pyafv/releases/latest
10
+ Author: Wei Wang
11
+ Author-email: ww000721@gmail.com
12
+ License-Expression: MIT
13
+ License-File: LICENSE
14
+ Keywords: biological-modeling,cellular-patterns,voronoi-model
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: Science/Research
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Topic :: Scientific/Engineering
26
+ Requires-Python: <3.15,>=3.10
27
+ Requires-Dist: matplotlib>=3.8.4
28
+ Requires-Dist: numpy>=1.26.4
29
+ Requires-Dist: scipy>=1.13.1
30
+ Provides-Extra: examples
31
+ Requires-Dist: ipywidgets>=8.1.5; extra == 'examples'
32
+ Requires-Dist: jupyter>=1.1.0; extra == 'examples'
33
+ Requires-Dist: tqdm>=4.67.1; extra == 'examples'
34
+ Description-Content-Type: text/markdown
35
+
36
+ [![PyPi](https://img.shields.io/pypi/v/pyafv?cacheSeconds=300)](https://pypi.org/project/pyafv/)
37
+ [![Downloads](https://img.shields.io/pypi/dm/pyafv.svg)](https://pypi.org/project/pyafv/)
38
+ [![doc](https://img.shields.io/badge/documentation-pyafv.readthedocs.io-yellow.svg?logo=readthedocs)](https://pyafv.readthedocs.io)
39
+ [![Zenodo](https://zenodo.org/badge/1124385738.svg)](https://doi.org/10.5281/zenodo.18091659)
40
+ <!--[![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)-->
41
+ [![Tests on all platforms](https://github.com/wwang721/pyafv/actions/workflows/tests_all_platform.yml/badge.svg)](https://github.com/wwang721/pyafv/actions/workflows/tests_all_platform.yml)
42
+ [![pytest](https://github.com/wwang721/pyafv/actions/workflows/tests.yml/badge.svg)](https://github.com/wwang721/pyafv/actions/workflows/tests.yml)
43
+ [![codecov](https://codecov.io/github/wwang721/pyafv/branch/main/graph/badge.svg?token=VSXSOX8HVS)](https://codecov.io/github/wwang721/pyafv/tree/main)
44
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
45
+
46
+ <!--
47
+ [![arXiv:2503.03126](https://img.shields.io/badge/arXiv-2503.03126-grey.svg?colorA=a42c25&colorB=grey&logo=arxiv)](https://doi.org/10.48550/arXiv.2503.03126)
48
+ [![PhysRevE.109.054408](https://img.shields.io/badge/Phys.%20Rev.%20E-109.054408-grey.svg?colorA=8c6040)](https://doi.org/10.1103/PhysRevE.109.054408)
49
+ [![Soft Matter](https://img.shields.io/badge/Soft%20Matter-XXXXX-63a7c2.svg?colorA=63a7c2&colorB=grey)](https://doi.org/10.1103/PhysRevE.109.054408)
50
+ -->
51
+
52
+
53
+ # PyAFV
54
+
55
+ Python code that implements the **active-finite-Voronoi (AFV) model** in 2D.
56
+ The AFV framework was introduced and developed in, for example, Refs. [[1](#huang2023bridging)&ndash;[3](#wang2026divergence)].
57
+
58
+
59
+ ## Installation
60
+
61
+ ### Install using pip
62
+
63
+ Install **PyAFV** using `pip`:
64
+ ```bash
65
+ pip install pyafv
66
+ ```
67
+ The package supports Python ≥ 3.10 and < 3.15, including Python 3.14t (the free-threaded, no-GIL build).
68
+ To verify that the installation was successful and that the correct version is installed, run the following in Python:
69
+ ```python
70
+ import pyafv
71
+ print(pyafv.__version__)
72
+ ```
73
+
74
+
75
+ ### Install from source
76
+
77
+ Installing from source can be necessary if pip installation does not work. First, download and unzip the source code, then navigate to the project directory and run:
78
+ ```bash
79
+ pip install .
80
+ ```
81
+
82
+ > **Note:** A C/C++ compiler is required if you are building from source, since some components of **PyAFV** are implemented in Cython for performance optimization.
83
+
84
+
85
+ #### Windows MinGW GCC
86
+
87
+ If you are using **MinGW GCC** (rather than **MSVC**) on *Windows*, to build from the source code, add a `setup.cfg` at the repository root before running the installation command above, with the following content:
88
+ ```ini
89
+ # setup.cfg
90
+ [build_ext]
91
+ compiler=mingw32
92
+ ```
93
+
94
+
95
+ ## Usage
96
+
97
+ Here is a simple example to get you started, demonstrating how to construct a finite-Voronoi diagram:
98
+ ```python
99
+ import numpy as np
100
+ import pyafv as afv
101
+
102
+ N = 100 # number of cells
103
+ pts = np.random.rand(N, 2) * 10 # initial positions
104
+ params = afv.PhysicalParams() # use default parameter values
105
+ sim = afv.FiniteVoronoiSimulator(pts, params) # initialize the simulator
106
+ sim.plot_2d(show=True) # visualize the Voronoi diagram
107
+ ```
108
+ To compute the conservative forces and extract detailed geometric information (e.g., cell areas, vertices, and edges), call:
109
+ ```python
110
+ diag = sim.build()
111
+ ```
112
+ The returned object `diag` is a Python `dict` containing these quantities.
113
+
114
+ > Full documentation on [readthedocs](https://pyafv.readthedocs.io)!
115
+
116
+
117
+ ## Simulation previews
118
+
119
+ Below are representative simulation snapshots generated using the code:
120
+
121
+ | Model illustration | Periodic boundary conditions |
122
+ |-----------------|-----------------|
123
+ | <img src="https://media.githubusercontent.com/media/wwang721/pyafv/main/assets/model_illustration.png" height="373"> | <img src="https://media.githubusercontent.com/media/wwang721/pyafv/main/assets/pbc.png" height="385">|
124
+
125
+ | Initial configuration | After relaxation | Active dynamics enabled |
126
+ |-----------------------|-----------------------|-----------------------|
127
+ | <img src="https://media.githubusercontent.com/media/wwang721/pyafv/main/assets/initial_configuration.png" height="300"> | <img src="https://media.githubusercontent.com/media/wwang721/pyafv/main/assets/relaxed_configuration.png" height="300"> | <img src="https://media.githubusercontent.com/media/wwang721/pyafv/main/assets/active_FV.png" height="300"> |
128
+
129
+
130
+ ## Development
131
+
132
+ See [CONTRIBUTING.md](https://github.com/wwang721/pyafv/blob/main/CONTRIBUTING.md) or [Documentation](https://pyafv.readthedocs.io/stable/contributing.html) for local development instructions.
133
+
134
+
135
+ ## More information
136
+
137
+ See important [**issues**](https://github.com/wwang721/pyafv/issues?q=is%3Aissue%20state%3Aclosed) for additional context, such as:
138
+ * [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)]
139
+ * [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)]
140
+ * [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)]
141
+
142
+
143
+ ## Zenodo
144
+
145
+ The releases of this repository are cross-listed on [Zenodo](https://doi.org/10.5281/zenodo.18091659).
146
+
147
+
148
+ ## License
149
+
150
+ This project is licensed under the [MIT License](https://github.com/wwang721/pyafv/blob/main/LICENSE), which permits free use, modification, and distribution of the code for nearly any purpose.
151
+
152
+
153
+ ## References
154
+
155
+ <table>
156
+ <tr>
157
+ <td id="huang2023bridging" valign="top">[1]</td>
158
+ <td>
159
+ 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>.
160
+ </td>
161
+ </tr>
162
+ <tr>
163
+ <td id="teomy2018confluent" valign="top">[2]</td>
164
+ <td>
165
+ 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>.
166
+ </td>
167
+ </tr>
168
+ <tr>
169
+ <td id="wang2026divergence" valign="top">[3]</td>
170
+ <td>
171
+ W. Wang (汪巍) and B. A. Camley, <em>Divergence of detachment forces in the finite-Voronoi model</em>, manuscript in preparation (2026).
172
+ </td>
173
+ </tr>
174
+ </table>
@@ -0,0 +1,14 @@
1
+ pyafv/__init__.py,sha256=i6DtniJfMN8_wiOWpNGhPCU7OdQhOANfJfF56oGguVM,426
2
+ pyafv/_version.py,sha256=xjcZx30gcW3a5cAfnx8XLkRqbaqUama6cq_a6FkkcCE,42
3
+ pyafv/backend.py,sha256=O15-rtzPQvTl_fIyZu4L0LU8UG4uRnAuq4bi5HBlKy8,418
4
+ pyafv/cell_geom.cpython-310-aarch64-linux-gnu.so,sha256=ipK0AVXeSMUlOpbwMpYaFCauf67c_eCL6ng50vmiYqc,2065976
5
+ pyafv/cell_geom.cpython-311-aarch64-linux-gnu.so,sha256=OtMp6aYkKFH2MX30akdFWX0KGgf9h58-UeFG6Ntx97k,2179472
6
+ pyafv/cell_geom.cpython-312-aarch64-linux-gnu.so,sha256=QiLWAM4UkVFLdSgVPXkxhks3d-wx7y6DcX23TReZY_4,2286816
7
+ pyafv/cell_geom.cpython-313-aarch64-linux-gnu.so,sha256=7WhYPVt4sjTuZIK89QaHHx67Hi5LHvsJjPwb5i0yo-s,2272680
8
+ pyafv/cell_geom_fallback.py,sha256=XeafJJFV-ykAaKT-UoDnX7FIbmNXChzJn1AwVgQIM-8,9142
9
+ pyafv/finite_voronoi.py,sha256=tQg1lJbXnH4JDnmABJzh-wJ57W4-EcMFLD70H93ALK8,44464
10
+ pyafv/physical_params.py,sha256=qyZFGsH9Hpk8pA4_RE95cLRSZOw1P9K5tPOK0hX8M4o,5187
11
+ pyafv-0.3.8.dist-info/METADATA,sha256=iH10lOSF3oossK_5e9G44FPjuRcxzzS3pkWWLS-aaHE,8337
12
+ pyafv-0.3.8.dist-info/WHEEL,sha256=GmDHRSo9nqMEJNiAxl34wFIK2xPIFfD4ypET8P0dITk,190
13
+ pyafv-0.3.8.dist-info/RECORD,,
14
+ pyafv-0.3.8.dist-info/licenses/LICENSE,sha256=TNjxBxdiOzyewn2FP7g1FjW3CJoxiGCY6ShPVFv02G8,1065
@@ -0,0 +1,7 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-manylinux_2_17_aarch64
5
+ Tag: cp313-cp313-manylinux2014_aarch64
6
+ Tag: cp313-cp313-manylinux_2_28_aarch64
7
+
@@ -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.