libvcell 0.0.1__tar.gz

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.
libvcell-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Jim Schaff
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,68 @@
1
+ Metadata-Version: 2.3
2
+ Name: libvcell
3
+ Version: 0.0.1
4
+ Summary: This is a python package which wraps a subset of VCell Java code as a native python package.
5
+ Author: Jim Schaff
6
+ Author-email: schaff@uchc.edu
7
+ Requires-Python: >=3.9,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Dist: pydantic (>=2.10.6,<3.0.0)
15
+ Project-URL: Documentation, https://virtualcell.github.io/libvcell/
16
+ Project-URL: Repository, https://github.com/virtualcell/libvcell
17
+ Description-Content-Type: text/markdown
18
+
19
+ # libvcell
20
+
21
+ [![Release](https://img.shields.io/github/v/release/virtualcell/libvcell)](https://img.shields.io/github/v/release/virtualcell/libvcell)
22
+ [![Build status](https://img.shields.io/github/actions/workflow/status/virtualcell/libvcell/main.yml?branch=main)](https://github.com/virtualcell/libvcell/actions/workflows/main.yml?query=branch%3Amain)
23
+ [![codecov](https://codecov.io/gh/virtualcell/libvcell/branch/main/graph/badge.svg)](https://codecov.io/gh/virtualcell/libvcell)
24
+ [![Commit activity](https://img.shields.io/github/commit-activity/m/virtualcell/libvcell)](https://img.shields.io/github/commit-activity/m/virtualcell/libvcell)
25
+ [![License](https://img.shields.io/github/license/virtualcell/libvcell)](https://img.shields.io/github/license/virtualcell/libvcell)
26
+
27
+ libvcell is a subset of VCell algorithms intended to support the [pyvcell](https://pypi.org/project/pyvcell/) python package. libvcell is available as a native executable and a python package.
28
+
29
+ - **Github repository**: <https://github.com/virtualcell/libvcell/>
30
+ - **Documentation** <https://virtualcell.github.io/libvcell/>
31
+
32
+ ## Getting started with your project
33
+
34
+ First, create a repository on GitHub with the same name as this project, and then run the following commands:
35
+
36
+ ```bash
37
+ git init -b main
38
+ git add .
39
+ git commit -m "init commit"
40
+ git remote add origin git@github.com:virtualcell/libvcell.git
41
+ git push -u origin main
42
+ ```
43
+
44
+ Finally, install the environment and the pre-commit hooks with
45
+
46
+ ```bash
47
+ make install
48
+ ```
49
+
50
+ You are now ready to start development on your project!
51
+ The CI/CD pipeline will be triggered when you open a pull request, merge to main, or when you create a new release.
52
+
53
+ To finalize the set-up for publishing to PyPI or Artifactory, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/publishing/#set-up-for-pypi).
54
+ For activating the automatic documentation with MkDocs, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/mkdocs/#enabling-the-documentation-on-github).
55
+ To enable the code coverage reports, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/codecov/).
56
+
57
+ ## Releasing a new version
58
+
59
+ - Create an API Token on [PyPI](https://pypi.org/).
60
+ - Add the API Token to your projects secrets with the name `PYPI_TOKEN` by visiting [this page](https://github.com/virtualcell/libvcell/settings/secrets/actions/new).
61
+ - Create a [new release](https://github.com/virtualcell/libvcell/releases/new) on Github.
62
+ - Create a new tag in the form `*.*.*`.
63
+ - For more details, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/cicd/#how-to-trigger-a-release).
64
+
65
+ ---
66
+
67
+ Repository initiated with [fpgmaas/cookiecutter-poetry](https://github.com/fpgmaas/cookiecutter-poetry).
68
+
@@ -0,0 +1,49 @@
1
+ # libvcell
2
+
3
+ [![Release](https://img.shields.io/github/v/release/virtualcell/libvcell)](https://img.shields.io/github/v/release/virtualcell/libvcell)
4
+ [![Build status](https://img.shields.io/github/actions/workflow/status/virtualcell/libvcell/main.yml?branch=main)](https://github.com/virtualcell/libvcell/actions/workflows/main.yml?query=branch%3Amain)
5
+ [![codecov](https://codecov.io/gh/virtualcell/libvcell/branch/main/graph/badge.svg)](https://codecov.io/gh/virtualcell/libvcell)
6
+ [![Commit activity](https://img.shields.io/github/commit-activity/m/virtualcell/libvcell)](https://img.shields.io/github/commit-activity/m/virtualcell/libvcell)
7
+ [![License](https://img.shields.io/github/license/virtualcell/libvcell)](https://img.shields.io/github/license/virtualcell/libvcell)
8
+
9
+ libvcell is a subset of VCell algorithms intended to support the [pyvcell](https://pypi.org/project/pyvcell/) python package. libvcell is available as a native executable and a python package.
10
+
11
+ - **Github repository**: <https://github.com/virtualcell/libvcell/>
12
+ - **Documentation** <https://virtualcell.github.io/libvcell/>
13
+
14
+ ## Getting started with your project
15
+
16
+ First, create a repository on GitHub with the same name as this project, and then run the following commands:
17
+
18
+ ```bash
19
+ git init -b main
20
+ git add .
21
+ git commit -m "init commit"
22
+ git remote add origin git@github.com:virtualcell/libvcell.git
23
+ git push -u origin main
24
+ ```
25
+
26
+ Finally, install the environment and the pre-commit hooks with
27
+
28
+ ```bash
29
+ make install
30
+ ```
31
+
32
+ You are now ready to start development on your project!
33
+ The CI/CD pipeline will be triggered when you open a pull request, merge to main, or when you create a new release.
34
+
35
+ To finalize the set-up for publishing to PyPI or Artifactory, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/publishing/#set-up-for-pypi).
36
+ For activating the automatic documentation with MkDocs, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/mkdocs/#enabling-the-documentation-on-github).
37
+ To enable the code coverage reports, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/codecov/).
38
+
39
+ ## Releasing a new version
40
+
41
+ - Create an API Token on [PyPI](https://pypi.org/).
42
+ - Add the API Token to your projects secrets with the name `PYPI_TOKEN` by visiting [this page](https://github.com/virtualcell/libvcell/settings/secrets/actions/new).
43
+ - Create a [new release](https://github.com/virtualcell/libvcell/releases/new) on Github.
44
+ - Create a new tag in the form `*.*.*`.
45
+ - For more details, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/cicd/#how-to-trigger-a-release).
46
+
47
+ ---
48
+
49
+ Repository initiated with [fpgmaas/cookiecutter-poetry](https://github.com/fpgmaas/cookiecutter-poetry).
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ # Ignore everything in this directory
2
+ *
3
+ # Except this file
4
+ !.gitignore
@@ -0,0 +1,60 @@
1
+ import ctypes
2
+ import logging
3
+ from pathlib import Path
4
+
5
+ from pydantic import BaseModel
6
+
7
+ from libvcell._internal.native_utils import IsolateManager, VCellNativeLibraryLoader
8
+
9
+
10
+ class ReturnValue(BaseModel):
11
+ success: bool
12
+ message: str
13
+
14
+
15
+ class VCellNativeCalls:
16
+ def __init__(self) -> None:
17
+ self.loader = VCellNativeLibraryLoader()
18
+ self.lib = self.loader.lib
19
+
20
+ def vcml_to_finite_volume_input(
21
+ self, vcml_content: str, simulation_name: str, output_dir_path: Path
22
+ ) -> ReturnValue:
23
+ try:
24
+ with IsolateManager(self.lib) as isolate_thread:
25
+ json_ptr: ctypes.c_char_p = self.lib.vcmlToFiniteVolumeInput(
26
+ isolate_thread,
27
+ ctypes.c_char_p(vcml_content.encode("utf-8")),
28
+ ctypes.c_char_p(simulation_name.encode("utf-8")),
29
+ ctypes.c_char_p(str(output_dir_path).encode("utf-8")),
30
+ )
31
+
32
+ value: bytes | None = ctypes.cast(json_ptr, ctypes.c_char_p).value
33
+ if value is None:
34
+ logging.error("Failed to convert vcml to finite volume input")
35
+ return ReturnValue(success=False, message="Failed to convert vcml to finite volume input")
36
+ json_str: str = value.decode("utf-8")
37
+ # self.lib.freeString(json_ptr)
38
+ return ReturnValue.model_validate_json(json_data=json_str)
39
+ except Exception as e:
40
+ logging.exception("Error in vcml_to_finite_volume_input()", exc_info=e)
41
+ raise
42
+
43
+ def sbml_to_finite_volume_input(self, sbml_content: str, output_dir_path: Path) -> ReturnValue:
44
+ try:
45
+ with IsolateManager(self.lib) as isolate_thread:
46
+ json_ptr: ctypes.c_char_p = self.lib.sbmlToFiniteVolumeInput(
47
+ isolate_thread,
48
+ ctypes.c_char_p(sbml_content.encode("utf-8")),
49
+ ctypes.c_char_p(str(output_dir_path).encode("utf-8")),
50
+ )
51
+ value: bytes | None = ctypes.cast(json_ptr, ctypes.c_char_p).value
52
+ if value is None:
53
+ logging.error("Failed to convert sbml to finite volume input")
54
+ return ReturnValue(success=False, message="Failed to convert sbml to finite volume input")
55
+ json_str: str = value.decode("utf-8")
56
+ # self.lib.freeString(json_ptr)
57
+ return ReturnValue.model_validate_json(json_data=json_str)
58
+ except Exception as e:
59
+ logging.exception("Error in sbml_to_finite_volume_input()", exc_info=e)
60
+ raise
@@ -0,0 +1,60 @@
1
+ import ctypes
2
+ import platform
3
+ from _ctypes import byref
4
+ from importlib.resources import files
5
+
6
+ import libvcell
7
+
8
+
9
+ class VCellNativeLibraryLoader:
10
+ lib: ctypes.CDLL
11
+
12
+ def __init__(self) -> None:
13
+ self.lib = self._load_library()
14
+ self._define_entry_points()
15
+
16
+ def _load_library(self) -> ctypes.CDLL:
17
+ system = platform.system()
18
+ lib_ext = {"Linux": ".so", "Darwin": ".dylib", "Windows": ".dll"}.get(system)
19
+
20
+ if lib_ext is None:
21
+ raise OSError(f"Unsupported operating system: {system}")
22
+
23
+ libs_dir = files(libvcell).joinpath("_internal/libs")
24
+ if not libs_dir.is_dir():
25
+ raise OSError(f"Could not find the shared library directory {libs_dir}")
26
+
27
+ for file in libs_dir.iterdir():
28
+ if file.name.endswith(lib_ext):
29
+ print(f"Found shared library: {file}")
30
+ return ctypes.CDLL(name=str(file))
31
+
32
+ raise OSError("Could not find the shared library")
33
+
34
+ def _define_entry_points(self) -> None:
35
+ self.lib.vcmlToFiniteVolumeInput.restype = ctypes.c_char_p
36
+ self.lib.vcmlToFiniteVolumeInput.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
37
+
38
+ self.lib.sbmlToFiniteVolumeInput.restype = ctypes.c_char_p
39
+ self.lib.sbmlToFiniteVolumeInput.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p]
40
+
41
+ self.lib.freeString.restype = None
42
+ self.lib.freeString.argtypes = [ctypes.c_char_p]
43
+
44
+
45
+ class IsolateManager:
46
+ lib: ctypes.CDLL
47
+ isolate: ctypes.c_void_p
48
+ isolate_thread: ctypes.c_void_p
49
+
50
+ def __init__(self, lib: ctypes.CDLL) -> None:
51
+ self.lib = lib
52
+ self.isolate = ctypes.c_void_p()
53
+ self.isolate_thread = ctypes.c_void_p()
54
+
55
+ def __enter__(self) -> ctypes.c_void_p:
56
+ self.lib.graal_create_isolate(None, byref(self.isolate), byref(self.isolate_thread))
57
+ return self.isolate_thread
58
+
59
+ def __exit__(self, exc_type: type | None, exc_val: Exception, exc_tb: object | None) -> None:
60
+ self.lib.graal_tear_down_isolate(self.isolate_thread)
@@ -0,0 +1,19 @@
1
+ from pathlib import Path
2
+
3
+ from libvcell._internal.native_calls import ReturnValue, VCellNativeCalls
4
+
5
+
6
+ class libvcell:
7
+ @staticmethod
8
+ def vcml_to_finite_volume_input(vcml_content: str, simulation_name: str, output_dir_path: Path) -> None:
9
+ native = VCellNativeCalls()
10
+ return_value: ReturnValue = native.vcml_to_finite_volume_input(vcml_content, simulation_name, output_dir_path)
11
+ if not return_value.success:
12
+ raise RuntimeError(f"Error in vcml_to_finite_volume_input: {return_value.message}")
13
+
14
+ @staticmethod
15
+ def sbml_to_finite_volume_input(sbml_content: str, output_dir_path: Path) -> None:
16
+ native = VCellNativeCalls()
17
+ return_value: ReturnValue = native.sbml_to_finite_volume_input(sbml_content, output_dir_path)
18
+ if not return_value.success:
19
+ raise RuntimeError(f"Error in sbml_to_finite_volume_input: {return_value.message}")
@@ -0,0 +1,102 @@
1
+ [tool.poetry]
2
+ name = "libvcell"
3
+ version = "0.0.1"
4
+ description = "This is a python package which wraps a subset of VCell Java code as a native python package."
5
+ authors = ["Jim Schaff <schaff@uchc.edu>"]
6
+ repository = "https://github.com/virtualcell/libvcell"
7
+ documentation = "https://virtualcell.github.io/libvcell/"
8
+ readme = "README.md"
9
+ packages = [
10
+ {include = "libvcell"}
11
+ ]
12
+ include = [
13
+ {path="libvcell/_internal/libs/*", format="wheel"}
14
+ ]
15
+
16
+ [tool.poetry.dependencies]
17
+ python = ">=3.9,<4.0"
18
+ pydantic = "^2.10.6"
19
+
20
+ [tool.poetry.group.dev.dependencies]
21
+ pytest = "^7.2.0"
22
+ pytest-cov = "^4.0.0"
23
+ deptry = "^0.16.2"
24
+ mypy = "^1.5.1"
25
+ pre-commit = "^3.8.0"
26
+ tox = "^4.11.1"
27
+
28
+ [tool.poetry.group.docs.dependencies]
29
+ mkdocs = "^1.6.1"
30
+ mkdocs-material = "^9.5.50"
31
+ mkdocstrings = {extras = ["python"], version = "^0.27.0"}
32
+
33
+ [build-system]
34
+ requires = ["poetry-core>=1.0.0"]
35
+ build-backend = "poetry.core.masonry.api"
36
+
37
+ [tool.mypy]
38
+ files = ["libvcell", "tests"]
39
+ exclude = [ "vcell_submodule"]
40
+ strict = true
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
44
+
45
+ [tool.ruff]
46
+ target-version = "py39"
47
+ line-length = 120
48
+ fix = true
49
+ lint.select = [
50
+ # flake8-2020
51
+ "YTT",
52
+ # flake8-bandit
53
+ "S",
54
+ # flake8-bugbear
55
+ "B",
56
+ # flake8-builtins
57
+ "A",
58
+ # flake8-comprehensions
59
+ "C4",
60
+ # flake8-debugger
61
+ "T10",
62
+ # flake8-simplify
63
+ "SIM",
64
+ # isort
65
+ "I",
66
+ # mccabe
67
+ "C90",
68
+ # pycodestyle
69
+ "E", "W",
70
+ # pyflakes
71
+ "F",
72
+ # pygrep-hooks
73
+ "PGH",
74
+ # pyupgrade
75
+ "UP",
76
+ # ruff
77
+ "RUF",
78
+ # tryceratops
79
+ "TRY",
80
+ ]
81
+ lint.ignore = [
82
+ # LineTooLong
83
+ "E501",
84
+ # DoNotAssignLambda
85
+ "E731",
86
+ # avoid specifiying long messages outside the exception class
87
+ "TRY003",
88
+ ]
89
+
90
+ [tool.ruff.format]
91
+ preview = true
92
+
93
+ [tool.coverage.report]
94
+ skip_empty = true
95
+
96
+ [tool.coverage.run]
97
+ branch = true
98
+ source = ["libvcell"]
99
+
100
+
101
+ [tool.ruff.per-file-ignores]
102
+ "tests/*" = ["S101"]