pyafv 0.3.9__cp312-cp312-musllinux_1_2_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 value of the small cutoff :math:`\delta`.
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,163 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyafv
3
+ Version: 0.3.9
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?cacheSeconds=43200)](https://pypi.org/project/pyafv/)
38
+ [![Documentation](https://img.shields.io/badge/documentation-pyafv.readthedocs.io-yellow.svg?logo=readthedocs)](https://pyafv.readthedocs.io)
39
+ <!--[![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)-->
40
+ [![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)
41
+ [![pytest](https://github.com/wwang721/pyafv/actions/workflows/tests.yml/badge.svg)](https://github.com/wwang721/pyafv/actions/workflows/tests.yml)
42
+ [![Codecov](https://codecov.io/github/wwang721/pyafv/branch/main/graph/badge.svg?token=VSXSOX8HVS)](https://codecov.io/github/wwang721/pyafv/tree/main)
43
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
44
+
45
+ <!--
46
+ [![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)
47
+ [![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)
48
+ [![Soft Matter](https://img.shields.io/badge/Soft%20Matter-XXXXX-63a7c2.svg?colorA=63a7c2&colorB=grey)](https://doi.org/10.1103/PhysRevE.109.054408)
49
+ -->
50
+
51
+
52
+ # PyAFV
53
+
54
+ Python code that implements the **active-finite-Voronoi (AFV) model** in 2D.
55
+ The AFV framework was introduced and developed in, for example, Refs. [[1](#huang2023bridging)&ndash;[3](#wang2026divergence)].
56
+
57
+
58
+ ## Installation
59
+
60
+ **PyAFV** is available on **PyPI** and can be installed using *pip* directly:
61
+ ```bash
62
+ pip install pyafv
63
+ ```
64
+ The package supports Python ≥ 3.10 and < 3.15, including Python 3.14t (the free-threaded, no-GIL build).
65
+ To verify that the installation was successful and that the correct version is installed, run the following in Python:
66
+ ```python
67
+ import pyafv
68
+ print(pyafv.__version__)
69
+ ```
70
+
71
+ > On HPC clusters, global Python path can contaminate the runtime environment. You may need to clear it explicitly using `unset PYTHONPATH` or prefixing the *pip* command with `PYTHONPATH=""`.
72
+
73
+ ### Install from source
74
+
75
+ Installing from source can be necessary if *pip* installation does not work. First, download and unzip the source code, then navigate to the root directory of the package and run:
76
+ ```bash
77
+ pip install .
78
+ ```
79
+
80
+ > **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.
81
+
82
+
83
+ #### Windows MinGW GCC
84
+
85
+ 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 `pip install .` with the following content:
86
+ ```ini
87
+ # setup.cfg
88
+ [build_ext]
89
+ compiler=mingw32
90
+ ```
91
+
92
+
93
+ ## Usage
94
+
95
+ Here is a simple example to get you started, demonstrating how to construct a finite-Voronoi diagram:
96
+ ```python
97
+ import numpy as np
98
+ import pyafv as afv
99
+
100
+ N = 100 # number of cells
101
+ pts = np.random.rand(N, 2) * 10 # initial positions
102
+ params = afv.PhysicalParams() # use default parameter values
103
+ sim = afv.FiniteVoronoiSimulator(pts, params) # initialize the simulator
104
+ sim.plot_2d(show=True) # visualize the Voronoi diagram
105
+ ```
106
+ To compute the conservative forces and extract detailed geometric information (e.g., cell areas, vertices, and edges), call:
107
+ ```python
108
+ diag = sim.build()
109
+ ```
110
+ The returned object `diag` is a Python `dict` containing these quantities.
111
+
112
+
113
+ ## Simulation previews
114
+
115
+ Below are representative simulation snapshots generated using the code:
116
+
117
+ | Model illustration | Periodic boundary conditions |
118
+ |-----------------|-----------------|
119
+ | <img src="https://media.githubusercontent.com/media/wwang721/pyafv/main/assets/model_illustration.png" width="540"> | <img src="https://media.githubusercontent.com/media/wwang721/pyafv/main/assets/pbc.png" width="385">|
120
+
121
+ | Initial configuration | After relaxation | Active dynamics enabled |
122
+ |-----------------------|-----------------------|-----------------------|
123
+ | <img src="https://media.githubusercontent.com/media/wwang721/pyafv/main/assets/initial_configuration.png" width="300"> | <img src="https://media.githubusercontent.com/media/wwang721/pyafv/main/assets/relaxed_configuration.png" width="300"> | <img src="https://media.githubusercontent.com/media/wwang721/pyafv/main/assets/active_FV.png" width="300"> |
124
+
125
+
126
+ ## More information
127
+
128
+ - **Full documentation** on [readthedocs](https://pyafv.readthedocs.io) or as [a single PDF file](https://pyafv.readthedocs.io/_/downloads/en/latest/pdf/).
129
+
130
+ - See [CONTRIBUTING.md](https://github.com/wwang721/pyafv/blob/main/CONTRIBUTING.md) or the [documentation](https://pyafv.readthedocs.io/latest/contributing.html) for **local development instructions**.
131
+
132
+ - See some important [**issues**](https://github.com/wwang721/pyafv/issues?q=is%3Aissue%20state%3Aclosed) for additional context, such as:
133
+ * [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)]
134
+ * [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)]
135
+ * [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)]
136
+
137
+ - Some releases of this repository are cross-listed on [Zenodo](https://doi.org/10.5281/zenodo.18091659):
138
+
139
+ [![Zenodo](https://zenodo.org/badge/1124385738.svg)](https://doi.org/10.5281/zenodo.18091659)
140
+
141
+
142
+ ## References
143
+
144
+ <table>
145
+ <tr>
146
+ <td id="huang2023bridging" valign="top">[1]</td>
147
+ <td>
148
+ 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>.
149
+ </td>
150
+ </tr>
151
+ <tr>
152
+ <td id="teomy2018confluent" valign="top">[2]</td>
153
+ <td>
154
+ 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>.
155
+ </td>
156
+ </tr>
157
+ <tr>
158
+ <td id="wang2026divergence" valign="top">[3]</td>
159
+ <td>
160
+ W. Wang (汪巍) and B. A. Camley, <em>Divergence of detachment forces in the finite-Voronoi model</em>, manuscript in preparation (2026).
161
+ </td>
162
+ </tr>
163
+ </table>
@@ -0,0 +1,13 @@
1
+ pyafv/__init__.py,sha256=i6DtniJfMN8_wiOWpNGhPCU7OdQhOANfJfF56oGguVM,426
2
+ pyafv/_version.py,sha256=MtcRvCNzt93nWiO-J1vZqECrdCt8hCDfnoD9cjIQb5o,42
3
+ pyafv/backend.py,sha256=O15-rtzPQvTl_fIyZu4L0LU8UG4uRnAuq4bi5HBlKy8,418
4
+ pyafv/cell_geom.cpython-310-aarch64-linux-gnu.so,sha256=YW8lhLxaqM-nyt00j75uupPPToDnodekBZEMDvbU8gI,1440976
5
+ pyafv/cell_geom.cpython-311-aarch64-linux-musl.so,sha256=0xRO0lftXNp3tCkwX12Tt65pKAIQvKBGVhk02klBrrg,1514616
6
+ pyafv/cell_geom.cpython-312-aarch64-linux-musl.so,sha256=BPZ6Hb53-HroUa7PguJ94tkqQPsDSPwxNATgDtQDppQ,1594448
7
+ pyafv/cell_geom_fallback.py,sha256=XeafJJFV-ykAaKT-UoDnX7FIbmNXChzJn1AwVgQIM-8,9142
8
+ pyafv/finite_voronoi.py,sha256=SZS4VY4bGTUBUBHc8Zqtw0CpTalFZoc3ExDMVo7jbfc,44873
9
+ pyafv/physical_params.py,sha256=XL3f4jYb8ltOfdFowXBcc2aauyyNHW5avOBRagg4jzI,5192
10
+ pyafv-0.3.9.dist-info/METADATA,sha256=WknbQMcrco00NHz9261rM0lk-uhGkeSJITy9RM9J41E,8461
11
+ pyafv-0.3.9.dist-info/WHEEL,sha256=dhN-x1_awsBUMQblQjs8plMLHwphdjrL5H1eYKLTr8o,110
12
+ pyafv-0.3.9.dist-info/RECORD,,
13
+ pyafv-0.3.9.dist-info/licenses/LICENSE,sha256=TNjxBxdiOzyewn2FP7g1FjW3CJoxiGCY6ShPVFv02G8,1065
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: false
4
+ Tag: cp312-cp312-musllinux_1_2_aarch64
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.