atropy-core 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.
- atropy_core-0.0.1/.clang-format +8 -0
- atropy_core-0.0.1/.git +1 -0
- atropy_core-0.0.1/CMakeLists.txt +187 -0
- atropy_core-0.0.1/PKG-INFO +6 -0
- atropy_core-0.0.1/atropy_core/__init__.py +0 -0
- atropy_core-0.0.1/atropy_core/boolean_helper.py +133 -0
- atropy_core-0.0.1/atropy_core/examples/__init__.py +0 -0
- atropy_core-0.0.1/atropy_core/examples/boolean/__init__.py +0 -0
- atropy_core-0.0.1/atropy_core/examples/boolean/set_apoptosis.py +158 -0
- atropy_core-0.0.1/atropy_core/examples/boolean/set_pancreatic_cancer.py +158 -0
- atropy_core-0.0.1/atropy_core/examples/kinetic/__init__.py +0 -0
- atropy_core-0.0.1/atropy_core/examples/kinetic/set_bax.py +123 -0
- atropy_core-0.0.1/atropy_core/examples/kinetic/set_cascade.py +112 -0
- atropy_core-0.0.1/atropy_core/examples/kinetic/set_lambda_phage.py +175 -0
- atropy_core-0.0.1/atropy_core/examples/kinetic/set_toggle_switch.py +84 -0
- atropy_core-0.0.1/atropy_core/examples/models/__init__.py +0 -0
- atropy_core-0.0.1/atropy_core/examples/models/boolean/apoptosis.hpp +489 -0
- atropy_core-0.0.1/atropy_core/examples/models/boolean/pancreatic_cancer.hpp +195 -0
- atropy_core-0.0.1/atropy_core/examples/models/kinetic/__init__.py +0 -0
- atropy_core-0.0.1/atropy_core/examples/models/kinetic/bax.py +114 -0
- atropy_core-0.0.1/atropy_core/examples/models/kinetic/cascade.py +31 -0
- atropy_core-0.0.1/atropy_core/examples/models/kinetic/lambda_phage.py +59 -0
- atropy_core-0.0.1/atropy_core/examples/models/kinetic/toggle_switch.py +16 -0
- atropy_core-0.0.1/atropy_core/grid.py +86 -0
- atropy_core-0.0.1/atropy_core/id.py +46 -0
- atropy_core-0.0.1/atropy_core/index_functions.py +61 -0
- atropy_core-0.0.1/atropy_core/initial_condition.py +65 -0
- atropy_core-0.0.1/atropy_core/output_helper.py +220 -0
- atropy_core-0.0.1/atropy_core/reaction.py +28 -0
- atropy_core-0.0.1/atropy_core/tests/test_grid_class.py +53 -0
- atropy_core-0.0.1/atropy_core/tests/test_tree_class.py +231 -0
- atropy_core-0.0.1/atropy_core/tree.py +615 -0
- atropy_core-0.0.1/cmake-modules/FindNetCDF.cmake +119 -0
- atropy_core-0.0.1/include/bug_integrator.hpp +28 -0
- atropy_core-0.0.1/include/coeff_class.hpp +27 -0
- atropy_core-0.0.1/include/grid_class.hpp +42 -0
- atropy_core-0.0.1/include/index_functions.hpp +42 -0
- atropy_core-0.0.1/include/integration_methods.hpp +154 -0
- atropy_core-0.0.1/include/integrators.hpp +23 -0
- atropy_core-0.0.1/include/matrix.hpp +63 -0
- atropy_core-0.0.1/include/matrix_free.hpp +90 -0
- atropy_core-0.0.1/include/print_functions.hpp +49 -0
- atropy_core-0.0.1/include/ps_integrator.hpp +22 -0
- atropy_core-0.0.1/include/tree_class.hpp +172 -0
- atropy_core-0.0.1/pyproject.toml +15 -0
- atropy_core-0.0.1/src/bug_integrator.cpp +146 -0
- atropy_core-0.0.1/src/grid_class.cpp +28 -0
- atropy_core-0.0.1/src/main.cpp +177 -0
- atropy_core-0.0.1/src/matrix.cpp +13 -0
- atropy_core-0.0.1/src/print_functions.cpp +74 -0
- atropy_core-0.0.1/src/ps_integrator.cpp +143 -0
- atropy_core-0.0.1/src/tree_class.cpp +766 -0
- atropy_core-0.0.1/tests/CMakeLists.txt +96 -0
- atropy_core-0.0.1/tests/test_index_functions.cpp +53 -0
- atropy_core-0.0.1/tests/test_matrix_functions.cpp +108 -0
- atropy_core-0.0.1/tests/test_orthogonalization.cpp +260 -0
- atropy_core-0.0.1/tests/test_tree_h1.cpp +395 -0
- atropy_core-0.0.1/tests/test_tree_h2.cpp +692 -0
atropy_core-0.0.1/.git
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
gitdir: ../../.git/modules/atropy/core
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)
|
|
2
|
+
project(atropy_core
|
|
3
|
+
VERSION 0.0.1
|
|
4
|
+
DESCRIPTION "Dynamical low-rank solver for the kinetic CME"
|
|
5
|
+
HOMEPAGE_URL https://git.uibk.ac.at/c7021158/kinetic-cme
|
|
6
|
+
LANGUAGES CXX)
|
|
7
|
+
enable_testing()
|
|
8
|
+
|
|
9
|
+
include(FetchContent)
|
|
10
|
+
|
|
11
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
12
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
13
|
+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake-modules")
|
|
14
|
+
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Profile" CACHE STRING "" FORCE)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
################################################################################
|
|
18
|
+
# General options
|
|
19
|
+
################################################################################
|
|
20
|
+
|
|
21
|
+
option("MKL_ENABLED" "Enable MKL for Ensign" OFF)
|
|
22
|
+
option("OPENMP" "Enable OpenMP" OFF)
|
|
23
|
+
option("PYBIND11_ENABLED" "Enable PYBIND" OFF)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
################################################################################
|
|
27
|
+
# Compiler options
|
|
28
|
+
################################################################################
|
|
29
|
+
|
|
30
|
+
if(CMAKE_CXX_COMPILER_ID MATCHES Intel)
|
|
31
|
+
set(CMAKE_CXX_FLAGS
|
|
32
|
+
"${CMAKE_CXX_FLAGS} -Warn all -fpic"
|
|
33
|
+
)
|
|
34
|
+
set(CMAKE_CXX_FLAGS_DEBUG
|
|
35
|
+
"-g -check all -traceback"
|
|
36
|
+
)
|
|
37
|
+
set(CMAKE_CXX_FLAGS_RELEASE
|
|
38
|
+
"-O3 -ip -xHOST"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
else(CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
|
42
|
+
set(CMAKE_CXX_FLAGS
|
|
43
|
+
"${CMAKE_CXX_FLAGS} -Wall -fPIC"
|
|
44
|
+
)
|
|
45
|
+
set(CMAKE_CXX_FLAGS_DEBUG
|
|
46
|
+
"-O0 -g3 -ggdb3 -Wall -D_GLIBCXX_DEBUG -fno-omit-frame-pointer -ftrapv"
|
|
47
|
+
)
|
|
48
|
+
set(CMAKE_CXX_FLAGS_RELEASE
|
|
49
|
+
"-O3 -DNDEBUG -march=native -mtune=native"
|
|
50
|
+
)
|
|
51
|
+
endif()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
################################################################################
|
|
55
|
+
# External libraries
|
|
56
|
+
################################################################################
|
|
57
|
+
|
|
58
|
+
################################################################################
|
|
59
|
+
# Eigen
|
|
60
|
+
|
|
61
|
+
find_package(Eigen3 3.4 REQUIRED NO_MODULE)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
################################################################################
|
|
65
|
+
# NetCDF
|
|
66
|
+
|
|
67
|
+
find_package(NetCDF REQUIRED)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
################################################################################
|
|
71
|
+
# cxxopts
|
|
72
|
+
|
|
73
|
+
FetchContent_Declare(cxxopts
|
|
74
|
+
GIT_REPOSITORY "https://github.com/jarro2783/cxxopts.git"
|
|
75
|
+
GIT_TAG "v3.2.1"
|
|
76
|
+
GIT_SHALLOW ON
|
|
77
|
+
GIT_PROGRESS ON
|
|
78
|
+
FIND_PACKAGE_ARGS
|
|
79
|
+
)
|
|
80
|
+
FetchContent_MakeAvailable(cxxopts)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
################################################################################
|
|
84
|
+
# Ensign
|
|
85
|
+
|
|
86
|
+
FetchContent_Declare(Ensign
|
|
87
|
+
GIT_REPOSITORY https://github.com/leinkemmer/Ensign.git
|
|
88
|
+
GIT_TAG "development"
|
|
89
|
+
GIT_SHALLOW ON
|
|
90
|
+
GIT_PROGRESS ON
|
|
91
|
+
FIND_PACKAGE_ARGS
|
|
92
|
+
)
|
|
93
|
+
FetchContent_MakeAvailable(Ensign)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
################################################################################
|
|
97
|
+
# pybind 11
|
|
98
|
+
|
|
99
|
+
if (PYBIND11_ENABLED)
|
|
100
|
+
set(PYBIND11_NEWPYTHON ON)
|
|
101
|
+
find_package(pybind11 REQUIRED)
|
|
102
|
+
endif()
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
################################################################################
|
|
106
|
+
# Create short-hands
|
|
107
|
+
################################################################################
|
|
108
|
+
|
|
109
|
+
# Create `input` and `output` directories
|
|
110
|
+
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/input)
|
|
111
|
+
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/output)
|
|
112
|
+
|
|
113
|
+
# Define short-hands for the src directory and the files
|
|
114
|
+
set(SRC ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
|
115
|
+
set(SRC_FILES ${SRC}/bug_integrator.cpp
|
|
116
|
+
${SRC}/grid_class.cpp
|
|
117
|
+
${SRC}/matrix.cpp
|
|
118
|
+
${SRC}/print_functions.cpp
|
|
119
|
+
${SRC}/ps_integrator.cpp
|
|
120
|
+
${SRC}/tree_class.cpp)
|
|
121
|
+
set(HDR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
################################################################################
|
|
125
|
+
# Set up the program
|
|
126
|
+
################################################################################
|
|
127
|
+
|
|
128
|
+
if(PYBIND11_ENABLED)
|
|
129
|
+
|
|
130
|
+
################################################################################
|
|
131
|
+
# pybind11
|
|
132
|
+
|
|
133
|
+
pybind11_add_module(atropy_core_pybind11
|
|
134
|
+
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
|
|
135
|
+
${SRC_FILES}
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# Add SOURCE_ROOT as a preprocessor directive
|
|
139
|
+
target_compile_definitions(atropy_core_pybind11
|
|
140
|
+
PRIVATE "SOURCE_ROOT=${CMAKE_CURRENT_SOURCE_DIR}"
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
target_compile_definitions(atropy_core_pybind11 PRIVATE "__PYBIND11__")
|
|
144
|
+
|
|
145
|
+
target_include_directories(atropy_core_pybind11 PRIVATE ${HDR_DIR})
|
|
146
|
+
target_link_libraries(atropy_core_pybind11 PRIVATE Ensign::Ensign)
|
|
147
|
+
target_link_libraries(atropy_core_pybind11 PUBLIC Eigen3::Eigen)
|
|
148
|
+
target_include_directories(atropy_core_pybind11 PRIVATE ${NETCDF_INCLUDE_DIR})
|
|
149
|
+
|
|
150
|
+
if(cxxopts_FOUND)
|
|
151
|
+
target_link_libraries(atropy_core_pybind11 PRIVATE cxxopts::cxxopts)
|
|
152
|
+
else()
|
|
153
|
+
target_link_libraries(atropy_core_pybind11 PRIVATE cxxopts)
|
|
154
|
+
endif()
|
|
155
|
+
|
|
156
|
+
install(TARGETS atropy_core_pybind11 LIBRARY DESTINATION .)
|
|
157
|
+
|
|
158
|
+
else()
|
|
159
|
+
|
|
160
|
+
################################################################################
|
|
161
|
+
# atropy_core
|
|
162
|
+
|
|
163
|
+
add_executable(${PROJECT_NAME}
|
|
164
|
+
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
|
|
165
|
+
${SRC_FILES}
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
# Add SOURCE_ROOT as a preprocessor directive
|
|
169
|
+
target_compile_definitions(${PROJECT_NAME}
|
|
170
|
+
PRIVATE "SOURCE_ROOT=${CMAKE_CURRENT_SOURCE_DIR}"
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
target_include_directories(${PROJECT_NAME} PRIVATE ${HDR_DIR})
|
|
174
|
+
target_link_libraries(${PROJECT_NAME} PRIVATE Ensign::Ensign)
|
|
175
|
+
target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen)
|
|
176
|
+
target_include_directories(${PROJECT_NAME} PRIVATE ${NETCDF_INCLUDE_DIR})
|
|
177
|
+
|
|
178
|
+
if(cxxopts_FOUND)
|
|
179
|
+
target_link_libraries(${PROJECT_NAME} PRIVATE cxxopts::cxxopts)
|
|
180
|
+
else()
|
|
181
|
+
target_link_libraries(${PROJECT_NAME} PRIVATE cxxopts)
|
|
182
|
+
endif()
|
|
183
|
+
|
|
184
|
+
if(BUILD_TESTING)
|
|
185
|
+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
|
186
|
+
endif()
|
|
187
|
+
endif()
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: atropy_core
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Scripts for generating input files and plotting output files
|
|
5
|
+
Author-email: Julian Mangott <julian.mangott@uibk.ac.at>, Lukas Einkemmer <lukas.einkemmer@uibk.ac.at>, Martina Prugger <martina.prugger@ipp.mpg.de>, Stefan Brunner <stefan.brunner@student.uibk.ac.at>
|
|
6
|
+
Requires-Python: >=3.10
|
|
File without changes
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Helper module for Boolean reaction models."""
|
|
2
|
+
|
|
3
|
+
import ctypes
|
|
4
|
+
import inspect
|
|
5
|
+
import subprocess
|
|
6
|
+
import tempfile
|
|
7
|
+
import textwrap
|
|
8
|
+
|
|
9
|
+
import bitarray
|
|
10
|
+
import bitarray.util
|
|
11
|
+
import numpy as np
|
|
12
|
+
import regex as re
|
|
13
|
+
|
|
14
|
+
import atropy_core.reaction
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def convertRulesToReactions(filename: str):
|
|
18
|
+
"""
|
|
19
|
+
Converts a rule file of the Boolean CME integrator of
|
|
20
|
+
https://bitbucket.org/mprugger/low_rank_cme to a `ReactionSystem` instance.
|
|
21
|
+
NOTE: This method is only capable of converting systems
|
|
22
|
+
with a maximum of 64 species.
|
|
23
|
+
"""
|
|
24
|
+
with open(filename) as f:
|
|
25
|
+
line0 = f.readline()
|
|
26
|
+
f_string = f.read()
|
|
27
|
+
|
|
28
|
+
match = re.match(r"RULE_SET\((.*)\)", line0)
|
|
29
|
+
model_info = [x.split()[0] for x in match.group(1).split(",")]
|
|
30
|
+
|
|
31
|
+
model_name = model_info[0]
|
|
32
|
+
d = int(model_info[1])
|
|
33
|
+
species_names = [name[1:-1] for name in model_info[2:]]
|
|
34
|
+
|
|
35
|
+
rules = {}
|
|
36
|
+
dependencies = {}
|
|
37
|
+
|
|
38
|
+
rule_pattern = (
|
|
39
|
+
f"template<> bool {model_name}::rule<(\d+)>\(bitset<{d}> x\) " "\{([\S\s]*?)\}"
|
|
40
|
+
)
|
|
41
|
+
dependency_pattern = (
|
|
42
|
+
f"template<> vector<ind> {model_name}::depends_on<(\d+)>\(\) "
|
|
43
|
+
"\{[\s]*?return \{(.*?)\};\s*\}"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
rule_matches = re.finditer(rule_pattern, f_string, re.MULTILINE)
|
|
47
|
+
for _, match in enumerate(rule_matches, start=1):
|
|
48
|
+
i = int(match.group(1))
|
|
49
|
+
rules[i] = match.group(2)
|
|
50
|
+
|
|
51
|
+
dependency_matches = re.finditer(dependency_pattern, f_string, re.MULTILINE)
|
|
52
|
+
for _, match in enumerate(dependency_matches, start=1):
|
|
53
|
+
i = int(match.group(1))
|
|
54
|
+
dependency = [int(d) for d in match.group(2).split(",")]
|
|
55
|
+
if i not in dependency:
|
|
56
|
+
dependency.append(i)
|
|
57
|
+
dependencies[i] = sorted(dependency)
|
|
58
|
+
|
|
59
|
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
60
|
+
with open(tmpdirname + "/rule_set_temp.cpp", mode="w") as f:
|
|
61
|
+
str_begin = '#include <bitset>\nextern "C"\n{'
|
|
62
|
+
f.write(str_begin)
|
|
63
|
+
for k, v in rules.items():
|
|
64
|
+
str_rule = "\n\tbool rule_{}(std::bitset<{}> x)\n\t{{{}\t}}\n"
|
|
65
|
+
f.write(str_rule.format(k, d, textwrap.indent(v, "\t")))
|
|
66
|
+
str_end = "}"
|
|
67
|
+
f.write(str_end)
|
|
68
|
+
|
|
69
|
+
subprocess.run(
|
|
70
|
+
[
|
|
71
|
+
"g++",
|
|
72
|
+
"-fPIC",
|
|
73
|
+
"-shared",
|
|
74
|
+
"-o",
|
|
75
|
+
tmpdirname + "/rule_set_temp.so",
|
|
76
|
+
tmpdirname + "/rule_set_temp.cpp",
|
|
77
|
+
]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
handle = ctypes.CDLL(tmpdirname + "/rule_set_temp.so")
|
|
81
|
+
|
|
82
|
+
def fun_x0(x):
|
|
83
|
+
return 1 - x
|
|
84
|
+
|
|
85
|
+
def fun_x1(x):
|
|
86
|
+
return x
|
|
87
|
+
|
|
88
|
+
reactions = []
|
|
89
|
+
|
|
90
|
+
for i in range(d):
|
|
91
|
+
d_dep = len(dependencies[i])
|
|
92
|
+
dx_dep = 2**d_dep
|
|
93
|
+
for j in range(dx_dep):
|
|
94
|
+
x = bitarray.bitarray(d, endian="little")
|
|
95
|
+
x.setall(0)
|
|
96
|
+
x_dep = bitarray.util.int2ba(j, length=d_dep, endian="little")
|
|
97
|
+
for k, k_dep in enumerate(dependencies[i]):
|
|
98
|
+
x[k_dep] = x_dep[k]
|
|
99
|
+
curr_rule = handle[f"rule_{i}"]
|
|
100
|
+
curr_rule.argtypes = [
|
|
101
|
+
ctypes.c_ulonglong
|
|
102
|
+
] # avoid overflow for large systems
|
|
103
|
+
x_i_prime = curr_rule(bitarray.util.ba2int(x))
|
|
104
|
+
if (
|
|
105
|
+
x[i] != x_i_prime
|
|
106
|
+
): # create a reaction only when output is different from input
|
|
107
|
+
nu = np.zeros(d)
|
|
108
|
+
nu[i] = 1 if x[i] == 0 else -1
|
|
109
|
+
propensity = {}
|
|
110
|
+
for k_dep in dependencies[i]:
|
|
111
|
+
propensity[k_dep] = fun_x0 if x[k_dep] == 0 else fun_x1
|
|
112
|
+
reactions.append(atropy_core.reaction.Reaction(propensity, nu))
|
|
113
|
+
|
|
114
|
+
reaction_system = atropy_core.reaction.ReactionSystem(reactions, species_names)
|
|
115
|
+
|
|
116
|
+
return reaction_system
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if __name__ == "__main__":
|
|
120
|
+
import numpy as np
|
|
121
|
+
|
|
122
|
+
reaction_system = convertRulesToReactions(
|
|
123
|
+
"atropy_core/examples/models/boolean/pancreatic_cancer.hpp"
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
func_pattern = re.compile(r"return (.+)\\n")
|
|
127
|
+
for mu, reaction in enumerate(reaction_system.reactions):
|
|
128
|
+
print(f"reaction {mu}, product {int(np.nonzero(reaction.nu)[0])}")
|
|
129
|
+
for k, v in reaction.propensity.items():
|
|
130
|
+
func_string = str(inspect.getsourcelines(v)[0])
|
|
131
|
+
func = re.findall(func_pattern, func_string)
|
|
132
|
+
print(k, func)
|
|
133
|
+
print(reaction.nu, "\n")
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Script for setting the initial conditions for the Boolean apoptosis model."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
import atropy_core.boolean_helper
|
|
9
|
+
from atropy_core.grid import GridParms
|
|
10
|
+
from atropy_core.index_functions import incrVecIndex
|
|
11
|
+
from atropy_core.initial_condition import InitialCondition
|
|
12
|
+
from atropy_core.tree import Tree
|
|
13
|
+
|
|
14
|
+
reaction_system = atropy_core.boolean_helper.convertRulesToReactions(
|
|
15
|
+
"atropy_core/examples/models/boolean/apoptosis.hpp"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
p_best = (
|
|
19
|
+
"((0 2 3 4 5 6 7 8 9 12 20)(21 25 26 27 28 29 30 31 39 40))"
|
|
20
|
+
"((1 10 11 14 15 22 23 32 33 38)(13 16 17 18 19 24 34 35 36 37))"
|
|
21
|
+
)
|
|
22
|
+
p_worst = (
|
|
23
|
+
"((0 1 4 7 11 12 14 16 23 33 34)(2 3 5 8 13 19 20 24 32 35))"
|
|
24
|
+
"((6 9 15 17 21 22 25 26 31 37)(10 18 27 28 29 30 36 38 39 40))"
|
|
25
|
+
)
|
|
26
|
+
p_reasonable = (
|
|
27
|
+
"((0 2 3 4 5 6 7 8 12 20)(1 9 10 11 14 15 16 17 22 23))"
|
|
28
|
+
"((13 18 19 24 32 33 34 35 36 37 38)(21 25 26 27 28 29 30 31 39 40))"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
parser = argparse.ArgumentParser(
|
|
32
|
+
prog="set_apoptosis",
|
|
33
|
+
usage="python3 atropy_core/examples/boolean/set_apoptosis.py --partition_best --rank 5",
|
|
34
|
+
description="This script sets initial conditions for the apoptosis model.",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"-pb",
|
|
39
|
+
"--partition_best",
|
|
40
|
+
action="store_const",
|
|
41
|
+
const=p_best,
|
|
42
|
+
required=False,
|
|
43
|
+
help="Set the partition string to the best partition in terms of entropy",
|
|
44
|
+
dest="partition",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"-pw",
|
|
49
|
+
"--partition_worst",
|
|
50
|
+
action="store_const",
|
|
51
|
+
const=p_worst,
|
|
52
|
+
required=False,
|
|
53
|
+
help="Set the partition string to the worst partition w.r.t. entropy",
|
|
54
|
+
dest="partition",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
parser.add_argument(
|
|
58
|
+
"-pr",
|
|
59
|
+
"--partition_reasonable",
|
|
60
|
+
action="store_const",
|
|
61
|
+
const=p_reasonable,
|
|
62
|
+
required=False,
|
|
63
|
+
help="Set the partition string to the best partition w.r.t. Kerninghan-Lin counts",
|
|
64
|
+
dest="partition",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
parser.add_argument(
|
|
68
|
+
"-p",
|
|
69
|
+
"--partition",
|
|
70
|
+
type=str,
|
|
71
|
+
required=False,
|
|
72
|
+
help="Specify a general partition string",
|
|
73
|
+
dest="partition",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
parser.add_argument(
|
|
77
|
+
"-r",
|
|
78
|
+
"--rank",
|
|
79
|
+
type=int,
|
|
80
|
+
required=True,
|
|
81
|
+
help="Specify the ranks of the internal nodes",
|
|
82
|
+
)
|
|
83
|
+
args = parser.parse_args()
|
|
84
|
+
|
|
85
|
+
if args.partition is None:
|
|
86
|
+
print("usage:", parser.usage)
|
|
87
|
+
print(
|
|
88
|
+
parser.prog + ":",
|
|
89
|
+
"""
|
|
90
|
+
error: one of the following arguments is required:
|
|
91
|
+
-p/--partition`,
|
|
92
|
+
-pb/--partition_best,
|
|
93
|
+
-pw/--partition_worst,
|
|
94
|
+
-pr/--partition_reasonable,
|
|
95
|
+
""",
|
|
96
|
+
)
|
|
97
|
+
sys.exit(1)
|
|
98
|
+
|
|
99
|
+
partition_str = args.partition
|
|
100
|
+
|
|
101
|
+
# Grid parameters
|
|
102
|
+
d = 41
|
|
103
|
+
n = 2 * np.ones(d, dtype=int)
|
|
104
|
+
binsize = np.ones(d, dtype=int)
|
|
105
|
+
liml = np.zeros(d)
|
|
106
|
+
grid = GridParms(n, binsize, liml)
|
|
107
|
+
|
|
108
|
+
# Set up the partition tree
|
|
109
|
+
tree = Tree(partition_str, grid)
|
|
110
|
+
|
|
111
|
+
r_out = np.ones(tree.n_internal_nodes, dtype="int") * args.rank
|
|
112
|
+
n_basisfunctions = np.ones(r_out.size, dtype="int")
|
|
113
|
+
tree.initialize(reaction_system, r_out)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def eval_x(x: np.ndarray, grid: GridParms):
|
|
117
|
+
result = 1.0 / grid.dx()
|
|
118
|
+
pos0 = np.argwhere(grid.species == 0) # TNF
|
|
119
|
+
pos1 = np.argwhere(grid.species == 1) # GF
|
|
120
|
+
pos40 = np.argwhere(grid.species == 40) # DNAdam
|
|
121
|
+
if pos0.size > 0:
|
|
122
|
+
result *= 1.0 if x[pos0] == 1 else 0.0
|
|
123
|
+
if pos1.size > 0:
|
|
124
|
+
result *= 1.0 if x[pos1] == 1 else 0.0
|
|
125
|
+
if pos40.size > 0:
|
|
126
|
+
result *= 1.0 if x[pos40] == 0 else 0.0
|
|
127
|
+
return result
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# Low-rank initial conditions
|
|
131
|
+
initial_conditions = InitialCondition(tree, n_basisfunctions)
|
|
132
|
+
|
|
133
|
+
for Q in initial_conditions.Q:
|
|
134
|
+
Q[0, 0, 0] = 1.0
|
|
135
|
+
|
|
136
|
+
for n_node in range(tree.n_external_nodes):
|
|
137
|
+
vec_index = np.zeros(initial_conditions.external_nodes[n_node].grid.d())
|
|
138
|
+
for i in range(initial_conditions.external_nodes[n_node].grid.dx()):
|
|
139
|
+
initial_conditions.X[n_node][i, :] = eval_x(
|
|
140
|
+
vec_index, initial_conditions.external_nodes[n_node].grid
|
|
141
|
+
)
|
|
142
|
+
incrVecIndex(
|
|
143
|
+
vec_index,
|
|
144
|
+
initial_conditions.external_nodes[n_node].grid.n,
|
|
145
|
+
initial_conditions.external_nodes[n_node].grid.d(),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
# Calculate norm
|
|
149
|
+
_, marginal_distribution = tree.calculateObservables(
|
|
150
|
+
np.zeros(tree.root.grid.d(), dtype="int")
|
|
151
|
+
)
|
|
152
|
+
norm = np.sum(marginal_distribution[tree.species_names[0]])
|
|
153
|
+
print("norm:", norm)
|
|
154
|
+
tree.root.Q[0, 0, 0] /= norm
|
|
155
|
+
|
|
156
|
+
# Print tree and write it to a netCDF file
|
|
157
|
+
print(tree)
|
|
158
|
+
tree.write()
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Script for setting the initial conditions for the Boolean pancreatic cancer model."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
import atropy_core.boolean_helper
|
|
9
|
+
from atropy_core.grid import GridParms
|
|
10
|
+
from atropy_core.index_functions import incrVecIndex
|
|
11
|
+
from atropy_core.initial_condition import InitialCondition
|
|
12
|
+
from atropy_core.tree import Tree
|
|
13
|
+
|
|
14
|
+
reaction_system = atropy_core.boolean_helper.convertRulesToReactions(
|
|
15
|
+
"atropy_core/examples/models/boolean/pancreatic_cancer.hpp"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
p_best = (
|
|
19
|
+
"((0 1 2 3 4 5 6 9 12)(7 8 10 11 17 21 23 26))"
|
|
20
|
+
"((13 14 19 20 22 27 28 31 33)(15 16 18 24 25 29 30 32))"
|
|
21
|
+
)
|
|
22
|
+
p_worst = (
|
|
23
|
+
"((0 1 2 4 8 11 17 26)(3 5 6 7 9 10 12 21 23))"
|
|
24
|
+
"((13 18 19 20 22 25 31 33)(14 15 16 24 27 28 29 30 32))"
|
|
25
|
+
)
|
|
26
|
+
p_reasonable = (
|
|
27
|
+
"((0 1 2 3 4 5 7 9)(13 14 19 20 25 27 29 30 32))"
|
|
28
|
+
"((6 10 12 16 18 21 24 26 31)(8 11 15 17 22 23 28 33))"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
parser = argparse.ArgumentParser(
|
|
32
|
+
prog="set_pancreatic",
|
|
33
|
+
usage="python3 atropy_core/examples/boolean/set_pancreatic_cancer.py --partition_best --rank 5",
|
|
34
|
+
description="This script sets initial conditions for the pancreatic cancer model.",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"-pb",
|
|
39
|
+
"--partition_best",
|
|
40
|
+
action="store_const",
|
|
41
|
+
const=p_best,
|
|
42
|
+
required=False,
|
|
43
|
+
help="Set the partition string to the best partition in terms of entropy",
|
|
44
|
+
dest="partition",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"-pw",
|
|
49
|
+
"--partition_worst",
|
|
50
|
+
action="store_const",
|
|
51
|
+
const=p_worst,
|
|
52
|
+
required=False,
|
|
53
|
+
help="Set the partition string to the worst partition w.r.t. entropy",
|
|
54
|
+
dest="partition",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
parser.add_argument(
|
|
58
|
+
"-pr",
|
|
59
|
+
"--partition_reasonable",
|
|
60
|
+
action="store_const",
|
|
61
|
+
const=p_reasonable,
|
|
62
|
+
required=False,
|
|
63
|
+
help="Set the partition string to the best partition w.r.t. Kerninghan-Lin counts",
|
|
64
|
+
dest="partition",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
parser.add_argument(
|
|
68
|
+
"-p",
|
|
69
|
+
"--partition",
|
|
70
|
+
type=str,
|
|
71
|
+
required=False,
|
|
72
|
+
help="Specify a general partition string",
|
|
73
|
+
dest="partition",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
parser.add_argument(
|
|
77
|
+
"-r",
|
|
78
|
+
"--rank",
|
|
79
|
+
type=int,
|
|
80
|
+
required=True,
|
|
81
|
+
help="Specify the ranks of the internal nodes",
|
|
82
|
+
)
|
|
83
|
+
args = parser.parse_args()
|
|
84
|
+
|
|
85
|
+
if args.partition is None:
|
|
86
|
+
print("usage:", parser.usage)
|
|
87
|
+
print(
|
|
88
|
+
parser.prog + ":",
|
|
89
|
+
"""
|
|
90
|
+
error: one of the following arguments is required:
|
|
91
|
+
-p/--partition`,
|
|
92
|
+
-pb/--partition_best,
|
|
93
|
+
-pw/--partition_worst,
|
|
94
|
+
-pr/--partition_reasonable,
|
|
95
|
+
""",
|
|
96
|
+
)
|
|
97
|
+
sys.exit(1)
|
|
98
|
+
|
|
99
|
+
partition_str = args.partition
|
|
100
|
+
|
|
101
|
+
# Grid parameters
|
|
102
|
+
d = 34
|
|
103
|
+
n = 2 * np.ones(d, dtype=int)
|
|
104
|
+
binsize = np.ones(d, dtype=int)
|
|
105
|
+
liml = np.zeros(d)
|
|
106
|
+
grid = GridParms(n, binsize, liml)
|
|
107
|
+
|
|
108
|
+
# Set up the partition tree
|
|
109
|
+
tree = Tree(partition_str, grid)
|
|
110
|
+
|
|
111
|
+
r_out = np.ones(tree.n_internal_nodes, dtype="int") * args.rank
|
|
112
|
+
n_basisfunctions = np.ones(r_out.size, dtype="int")
|
|
113
|
+
tree.initialize(reaction_system, r_out)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def eval_x(x: np.ndarray, grid: GridParms):
|
|
117
|
+
result = 1.0 / grid.dx()
|
|
118
|
+
# pos0 = np.argwhere(grid.species==0) # HMGB
|
|
119
|
+
# pos4 = np.argwhere(grid.species==4) # RAS
|
|
120
|
+
# pos25 = np.argwhere(grid.species==25) # P54
|
|
121
|
+
# if pos0.size > 0:
|
|
122
|
+
# result *= (1.0 if x[pos0] == 1 else 0.0)
|
|
123
|
+
# if pos4.size > 0:
|
|
124
|
+
# result *= (1.0 if x[pos4] == 1 else 0.0)
|
|
125
|
+
# if pos25.size > 0:
|
|
126
|
+
# result *= (1.0 if x[pos25] == 0 else 0.0)
|
|
127
|
+
return result
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# Low-rank initial conditions
|
|
131
|
+
initial_conditions = InitialCondition(tree, n_basisfunctions)
|
|
132
|
+
|
|
133
|
+
for Q in initial_conditions.Q:
|
|
134
|
+
Q[0, 0, 0] = 1.0
|
|
135
|
+
|
|
136
|
+
for n_node in range(tree.n_external_nodes):
|
|
137
|
+
vec_index = np.zeros(initial_conditions.external_nodes[n_node].grid.d())
|
|
138
|
+
for i in range(initial_conditions.external_nodes[n_node].grid.dx()):
|
|
139
|
+
initial_conditions.X[n_node][i, :] = eval_x(
|
|
140
|
+
vec_index, initial_conditions.external_nodes[n_node].grid
|
|
141
|
+
)
|
|
142
|
+
incrVecIndex(
|
|
143
|
+
vec_index,
|
|
144
|
+
initial_conditions.external_nodes[n_node].grid.n,
|
|
145
|
+
initial_conditions.external_nodes[n_node].grid.d(),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
# Calculate norm
|
|
149
|
+
_, marginal_distribution = tree.calculateObservables(
|
|
150
|
+
np.zeros(tree.root.grid.d(), dtype="int")
|
|
151
|
+
)
|
|
152
|
+
norm = np.sum(marginal_distribution[tree.species_names[0]])
|
|
153
|
+
print("norm:", norm)
|
|
154
|
+
tree.root.Q[0, 0, 0] /= norm
|
|
155
|
+
|
|
156
|
+
# Print tree and write it to a netCDF file
|
|
157
|
+
print(tree)
|
|
158
|
+
tree.write()
|
|
File without changes
|