pyafv 0.3.6__cp313-cp313-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.

Potentially problematic release.


This version of pyafv might be problematic. Click here for more details.

@@ -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,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyafv
3
+ Version: 0.3.6
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
+ Project-URL: Documentation, https://pyafv.readthedocs.io/
10
+ Project-URL: Changelog, https://github.com/wwang721/pyafv/releases/latest
11
+ Keywords: voronoi-model,cellular-patterns,biological-modeling
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Operating System :: OS Independent
22
+ Classifier: Topic :: Scientific/Engineering
23
+ Requires-Python: <3.15,>=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: numpy>=1.26.4
27
+ Requires-Dist: scipy>=1.13.1
28
+ Requires-Dist: matplotlib>=3.8.4
29
+ Provides-Extra: examples
30
+ Requires-Dist: ipywidgets>=8.1.5; extra == "examples"
31
+ Requires-Dist: jupyter>=1.1.0; extra == "examples"
32
+ Requires-Dist: tqdm>=4.67.1; extra == "examples"
33
+ Dynamic: license-file
34
+
35
+ [![PyPi](https://img.shields.io/pypi/v/pyafv)](https://pypi.org/project/pyafv/)
36
+ [![Downloads](https://img.shields.io/pypi/dm/pyafv.svg)](https://pypi.org/project/pyafv/)
37
+ [![Zenodo](https://zenodo.org/badge/1124385738.svg)](https://doi.org/10.5281/zenodo.18091659)
38
+ <!--[![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)-->
39
+ [![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)
40
+ [![pytest](https://github.com/wwang721/pyafv/actions/workflows/tests.yml/badge.svg)](https://github.com/wwang721/pyafv/actions/workflows/tests.yml)
41
+ [![codecov](https://codecov.io/github/wwang721/pyafv/branch/main/graph/badge.svg?token=VSXSOX8HVS)](https://codecov.io/github/wwang721/pyafv/tree/main)
42
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
43
+
44
+
45
+ # PyAFV
46
+
47
+ Python code that implements the **active-finite-Voronoi (AFV) model** in 2D.
48
+ The AFV framework was introduced and developed in, for example, Refs. [[1](#huang2023bridging)&ndash;[3](#wang2026divergence)].
49
+
50
+
51
+ ## Installation
52
+
53
+ To install **PyAFV** with `pip`, run:
54
+ ```bash
55
+ pip install pyafv
56
+ ```
57
+ The package supports Python ≥ 3.10 and < 3.15.
58
+ To verify that the installation was successful and that the correct version is installed, run the following in Python:
59
+ ```python
60
+ import pyafv
61
+ print(pyafv.__version__)
62
+ ```
63
+
64
+
65
+ ## Usage
66
+
67
+ <!--Using `uv run python`, you should be able to import `pyafv` from anywhere within the repository directory.-->
68
+ The following example demonstrates how to construct a finite-Voronoi diagram:
69
+ ```python
70
+ import numpy as np
71
+ import pyafv as afv
72
+
73
+ N = 100 # number of cells
74
+ pts = np.random.rand(N, 2) * 10 # initial positions
75
+ params = afv.PhysicalParams() # use default parameter values
76
+ sim = afv.FiniteVoronoiSimulator(pts, params) # initialize the simulator
77
+ sim.plot_2d(show=True) # visualize the Voronoi diagram
78
+ ```
79
+ To compute the conservative forces and extract detailed geometric information (e.g., cell areas, vertices, and edges), call:
80
+ ```python
81
+ diag = sim.build()
82
+ ```
83
+ The returned object `diag` is a Python `dict` containing these quantities.
84
+
85
+
86
+ ## More information
87
+
88
+ GitHub: [https://github.com/wwang721/pyafv](https://github.com/wwang721/pyafv)
89
+
90
+ See important [**issues**](https://github.com/wwang721/pyafv/issues?q=is%3Aissue%20state%3Aclosed) for additional context, such as:
91
+ * [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)]
92
+ * [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)]
93
+ * [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)]
94
+
95
+ Full documentation on [readthedocs](https://pyafv.readthedocs.io/en/latest/)!
96
+
97
+ ## References
98
+
99
+ <table>
100
+ <tr>
101
+ <td id="huang2023bridging" valign="top">[1]</td>
102
+ <td>
103
+ 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>.
104
+ </td>
105
+ </tr>
106
+ <tr>
107
+ <td id="teomy2018confluent" valign="top">[2]</td>
108
+ <td>
109
+ 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>.
110
+ </td>
111
+ </tr>
112
+ <tr>
113
+ <td id="wang2026divergence" valign="top">[3]</td>
114
+ <td>
115
+ W. Wang (汪巍) and B. A. Camley, <em>Divergence of detachment forces in the finite-Voronoi model</em>, manuscript in preparation (2026).
116
+ </td>
117
+ </tr>
118
+ </table>
@@ -0,0 +1,12 @@
1
+ pyafv/__init__.py,sha256=i6DtniJfMN8_wiOWpNGhPCU7OdQhOANfJfF56oGguVM,426
2
+ pyafv/_version.py,sha256=td0yl-KXLJoMk9Xqi4IHgKZoN7BKWLkRiGBDmc3qB0g,42
3
+ pyafv/backend.py,sha256=O15-rtzPQvTl_fIyZu4L0LU8UG4uRnAuq4bi5HBlKy8,418
4
+ pyafv/cell_geom.cpython-313-aarch64-linux-musl.so,sha256=op9sqackhYan5QM9btImiSe2WCfTA_hh2xE71RbZeXY,1768608
5
+ pyafv/cell_geom_fallback.py,sha256=XeafJJFV-ykAaKT-UoDnX7FIbmNXChzJn1AwVgQIM-8,9142
6
+ pyafv/finite_voronoi.py,sha256=tQg1lJbXnH4JDnmABJzh-wJ57W4-EcMFLD70H93ALK8,44464
7
+ pyafv/physical_params.py,sha256=qyZFGsH9Hpk8pA4_RE95cLRSZOw1P9K5tPOK0hX8M4o,5187
8
+ pyafv-0.3.6.dist-info/METADATA,sha256=l-cKhjFiEp8K5Ku6Y2PuFVjOMx4iLdK6W0A4nT5o7YE,5664
9
+ pyafv-0.3.6.dist-info/WHEEL,sha256=3IjWZRuuq2q-vKtU0x2XxSbfx92VUEmTDWR0AUEtZxI,113
10
+ pyafv-0.3.6.dist-info/top_level.txt,sha256=mrKQNqc4GQxuZ7hd5UrKxbA_AJsuSqiJyMxL7Nu7va0,6
11
+ pyafv-0.3.6.dist-info/RECORD,,
12
+ pyafv-0.3.6.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_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.
@@ -0,0 +1 @@
1
+ pyafv