Skip to content

Commit

Permalink
v 0.1.9, added lots of JS functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbois committed Apr 1, 2023
1 parent 96afe62 commit 3843604
Show file tree
Hide file tree
Showing 37 changed files with 264 additions and 59 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE.md
100644 → 100755
Empty file.
Empty file modified MANIFEST.in
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified biocircuits/.gitignore
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion biocircuits/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

__author__ = """Justin Bois"""
__email__ = "[email protected]"
__version__ = "0.1.8"
__version__ = "0.1.9"
Empty file modified biocircuits/apps/.gitignore
100644 → 100755
Empty file.
Empty file modified biocircuits/apps/__init__.py
100644 → 100755
Empty file.
Empty file modified biocircuits/apps/ffl.py
100644 → 100755
Empty file.
Empty file modified biocircuits/apps/promiscuous.py
100644 → 100755
Empty file.
Empty file modified biocircuits/dynsys.py
100644 → 100755
Empty file.
69 changes: 50 additions & 19 deletions biocircuits/gillespie.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def _gillespie_draw(propensity_func, propensities, population, t, args):
# Sum of propensities
props_sum = _sum(propensities)

# Bail if the sum of propensities is zero (no moves to make)
if props_sum == 0.0:
return -1, -1.0

# Compute time
time = _draw_time(props_sum)

Expand Down Expand Up @@ -85,12 +89,16 @@ def _copy_population(population_previous, population):
# draw the event and time step
event, dt = draw_fun(propensity_func, propensities, population, t, args)

# Update the population
_copy_population(population_previous, population)
population += update[event, :]
if event == -1:
# Skip to the end of the simulation with the same population
t = time_points[-1]
else:
# Update the population
_copy_population(population_previous, population)
population += update[event, :]

# Increment time
t += dt
# Increment time
t += dt

# Update the index (Have to be careful about types for Numba)
j = np.searchsorted((time_points > t).astype(np.int64), 1)
Expand All @@ -105,7 +113,6 @@ def _copy_population(population_previous, population):
return pop_out, None


@numba.njit
def _gillespie_trajectory_report_time_points(
propensity_func, update, population_0, time_points, draw_fun, args=()
):
Expand All @@ -129,12 +136,20 @@ def _gillespie_trajectory_report_time_points(
# draw the event and time step
event, dt = draw_fun(propensity_func, propensities, population, t, args)

if event == -1:
# Skip to the end of the simulation with the same population
t = time_points[-1]
else:
# New population
population += update[event, :]

# Increment time
t += dt

# Update the population
population += update[event, :]
pop[i, :] = population

# Increment time
t += dt
# Updated time
tp[i] = t

# Increment indexes
Expand Down Expand Up @@ -226,6 +241,10 @@ def _draw(propensities, population, t):
# Sum of propensities
props_sum = np.sum(propensities)

# Bail if the sum of propensities is zero
if props_sum == 0.0:
return -1, -1.0

# Compute time
time = np.random.exponential(1 / props_sum)

Expand Down Expand Up @@ -258,12 +277,20 @@ def _traj():
# draw the event and time step
event, dt = _draw(propensities, population, t)

if event == -1:
# Skip to the end of the simulation with the same population
t = time_points[-1]
else:
# New population
population += update[event, :]

# Increment time
t += dt

# Update the population
population += update[event, :]
pop[i, :] = population

# Increment time
t += dt
# Updated time
tp[i] = t

# Increment indexes
Expand Down Expand Up @@ -299,12 +326,16 @@ def _traj():
# draw the event and time step
event, dt = _draw(propensities, population, t)

# Update the population
_copy_population(population_previous, population)
population += update[event, :]
if event == -1:
# Skip to the end of the simulation with the same population
t = time_points[-1]
else:
# Update the population
_copy_population(population_previous, population)
population += update[event, :]

# Increment time
t += dt
# Increment time
t += dt

# Update the index (Be careful about types for Numba)
j = np.searchsorted((time_points > t).astype(np.int64), 1)
Expand All @@ -321,7 +352,7 @@ def _traj():
else:
if return_time_points:

def traj():
def _traj():
return _gillespie_trajectory_report_time_points(
propensity_func,
update,
Expand Down Expand Up @@ -371,7 +402,7 @@ def _traj():


def _gillespie_multi_fn(args):
"""Convenient function for multithreading."""
"""Convenience function for multithreading."""
return _gillespie_ssa(*args)


Expand Down
30 changes: 29 additions & 1 deletion biocircuits/jsfunctions.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,34 @@
cds.change.emit();
}
""",
"simple_binding_sensitivity": """
function sensitivity(a0, b0, Kd) {
let b = a0 - b0 - Kd;
let discrim = b * b + 4 * a0 * Kd;
let sqrtDiscrim = Math.sqrt(discrim);
return a0 * (1 - b / sqrtDiscrim) / (sqrtDiscrim - b);
}
function callback() {
let b0 = Math.pow(10, b0Slider.value);
let KdVals = [0.001, 0.01, 0.1, 1.0, 10.0];
let a0 = cds.data['a0'];
for (let i = 0; i < KdVals.length; i++) {
let ind = 's' + i.toString();
for (let j = 0; j < a0.length; j++) {
cds.data[ind][j] = sensitivity(a0[j], b0, KdVals[i]);
}
}
span.location = b0;
cds.change.emit();
}
""",
"toggle_nullclines": """
function f(x, beta, n) {return beta / (1.0 + Math.pow(x, n));}
Expand Down Expand Up @@ -1758,4 +1786,4 @@
cdsUnstable.change.emit();
}
""",
}
}
Loading

0 comments on commit 3843604

Please sign in to comment.