Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdc1d #3

Merged
merged 125 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
9ba7405
implmentation of part of the state trait
angelcerveraroldan Jun 12, 2024
2e415ed
choose event at point started + comments / typos
angelcerveraroldan Jun 12, 2024
57cb9e0
base implementation of sdc1d
angelcerveraroldan Jun 13, 2024
fc403c6
get params function
angelcerveraroldan Jun 13, 2024
b1d8f3c
SDC model handling for TileSet (FromTileSet not done)
cgevans Jun 13, 2024
75a3f64
rudimentary tileset->sdc implementation
cgevans Jun 14, 2024
2eefd20
fix inadvertent doctest activation
cgevans Jun 14, 2024
bd415d3
Merge branch 'main' into sdc1d
cgevans Jun 14, 2024
f7bdf05
fix gluelinks reference after merge
cgevans Jun 14, 2024
46c64e3
allow energy_bonds viewing from python
cgevans Jun 14, 2024
ae5857b
add missing just_calc parameter
angelcerveraroldan Jun 15, 2024
fe399f6
typo, cargo fmt
angelcerveraroldan Jun 15, 2024
c4646d9
Fill friends, disable anchor tiles for now.
cgevans Jun 16, 2024
80c362a
rust Debug info in python for system and state
cgevans Jun 16, 2024
31d12b5
Actually disable anchor tiles for now
cgevans Jun 16, 2024
62c7541
SDC: change away from g_se & alpha
cgevans Jun 17, 2024
ec2d890
SDC: remove g_se and alpha from struct
cgevans Jun 17, 2024
2bfaaac
silliness
cgevans Jun 18, 2024
6701985
update_system function improved + tested | cargo fmt
angelcerveraroldan Jun 18, 2024
ee45549
add basic way to get sdc system in python
cgevans Jun 18, 2024
7c5b407
working sliding window fold - (non tested) calculation of delta G
angelcerveraroldan Jun 19, 2024
d3c59d8
filled delta g and delta s table
angelcerveraroldan Jun 20, 2024
012d33f
changed formula to use dG = dG_37 - (T - 37) dS
angelcerveraroldan Jun 20, 2024
2a34c85
added function new :: minimum params needed -> SDC
angelcerveraroldan Jun 20, 2024
dfde20c
Add G_Scaffold, and take it into account for detachment
angelcerveraroldan Jun 20, 2024
6686d87
added missing parameter to test
angelcerveraroldan Jun 20, 2024
1a3e4c6
ΔG parameter changes, use &str, tests.
cgevans Jun 20, 2024
2e02391
added function to get ΔG and ΔS for entire sequence
angelcerveraroldan Jun 20, 2024
ce800c5
fix issue for glues with ** in the name
angelcerveraroldan Jun 20, 2024
1c37e8e
Add direct state creation.
cgevans Jun 20, 2024
949d0a1
Merge branch 'sdc1d' of github.com:cgevans/rgrow into sdc1d
angelcerveraroldan Jun 20, 2024
3151d7d
colors, python, scaffold
cgevans Jun 20, 2024
800a184
Merge branch 'main' into sdc1d
cgevans Jun 21, 2024
2c08f16
remove old TODO comments
angelcerveraroldan Jun 21, 2024
9fa724c
make friends join a to a*
angelcerveraroldan Jun 21, 2024
1a9e614
remove reduntant line
angelcerveraroldan Jun 21, 2024
24887e5
Removed negatives
angelcerveraroldan Jun 21, 2024
d62c4f4
Improved error name
angelcerveraroldan Jun 21, 2024
8f72ba6
allow for None in Python Description
angelcerveraroldan Jun 21, 2024
250ac14
No need to put empty tile in the input
angelcerveraroldan Jun 21, 2024
003aaa5
sdc: fix scaffold energy to do complement
cgevans Jun 21, 2024
d95edf2
sdc: temperature get/set_param
cgevans Jun 21, 2024
313d2b3
don't fill energy array for empty tile / tile 0
cgevans Jun 21, 2024
e7fda40
enable sierpinski benchmark
cgevans Jun 21, 2024
3f08cb2
remove unnecessary ?Sized
cgevans Jun 21, 2024
d0adc73
ktam optimization
cgevans Jun 21, 2024
54ca0f0
remove debug println, add python dgds
cgevans Jun 21, 2024
3d52f03
Merge branch 'main' into sdc1d
angelcerveraroldan Jun 23, 2024
417cbed
added missing underscore
angelcerveraroldan Jun 23, 2024
50505fa
easier python interface -- no need for user to keep track of strand i…
angelcerveraroldan Jun 24, 2024
143eed1
Allow user to set glue to its DNA sequence
angelcerveraroldan Jun 24, 2024
7b35444
bit copy notebook
angelcerveraroldan Jun 24, 2024
b7a6096
implement mismatch_locations
cgevans Jun 24, 2024
7ae81b8
Fix scaffold length information.
cgevans Jun 24, 2024
7545969
divide by R*T
angelcerveraroldan Jun 25, 2024
887d131
RT unit fixes; use mod for scaffold dimension 0 if canvas is larger (…
cgevans Jun 25, 2024
bd3f297
account for penalties
angelcerveraroldan Jun 25, 2024
0c34a90
Fix Python mismatch display code.
cgevans Jun 27, 2024
a89c934
Merge branch 'main' into sdc1d
cgevans Jun 27, 2024
aa6a154
better error message (unwrap is confusing on the python side)
angelcerveraroldan Jun 27, 2024
b99ee67
Add SDCStrand, SDCParams to rgrow.sdc for Python.
cgevans Jun 27, 2024
5119aac
Fixed early panic -- This exception made implementing simulations ver…
angelcerveraroldan Jun 30, 2024
aace8c4
Merge main and sdc1d, ensure sdc1d works in new arrangement
cgevans Jul 2, 2024
7d23898
Calculate loop penalty
angelcerveraroldan Jul 8, 2024
c1f3525
Fix R
angelcerveraroldan Jul 8, 2024
1c20c77
cleanup loop cost helper function
angelcerveraroldan Jul 9, 2024
cf15399
expose function to python lib
angelcerveraroldan Jul 11, 2024
661445e
boltzman distribution
angelcerveraroldan Jul 12, 2024
b893da2
temperature as kelvin
angelcerveraroldan Jul 12, 2024
0f5a39f
Better interface
angelcerveraroldan Jul 13, 2024
021359a
change 1/beta to RT
angelcerveraroldan Jul 15, 2024
e2c5346
Give python acess to partition function
angelcerveraroldan Jul 18, 2024
a61a2bb
Hopefully put a tile_counts in State
cgevans Jul 22, 2024
2b4b4b2
mutate attachment array
angelcerveraroldan Jul 23, 2024
1a2e49b
probability of strand being already attached
angelcerveraroldan Jul 23, 2024
7feb8a1
Update attachment/detachment
angelcerveraroldan Jul 23, 2024
8e3c12c
Better error reporting
angelcerveraroldan Jul 23, 2024
2c5f53c
When no event takes place, let time pass
angelcerveraroldan Jul 23, 2024
403c5d1
scaffold concentration
angelcerveraroldan Jul 23, 2024
6cd55db
mistake when counting scaffolds
angelcerveraroldan Jul 23, 2024
d855234
add an nrows/cols_usable to canvas, use this for n_scaffolds
cgevans Jul 24, 2024
b688e75
Move tile count updates to perform_event in sdc.
cgevans Jul 24, 2024
d0c75d8
reuse rand thread
angelcerveraroldan Jul 25, 2024
acbc811
remove import
angelcerveraroldan Jul 25, 2024
bf22c40
remove polymer update from SDC (there are no polymers)
angelcerveraroldan Jul 25, 2024
cf52bdb
two match branches into one
angelcerveraroldan Jul 25, 2024
6da83aa
base anneal definition
angelcerveraroldan Jul 25, 2024
29c6f7e
change to seconds per step
angelcerveraroldan Jul 25, 2024
2dc37ad
generate arrays from anneal data
angelcerveraroldan Jul 25, 2024
7d11772
test anneal vectors
angelcerveraroldan Jul 25, 2024
238c4d2
rust anneal -- not tested
angelcerveraroldan Jul 25, 2024
9d86e9c
state for running anneal
angelcerveraroldan Jul 25, 2024
fedf2d8
test -- check no errors are thrown
angelcerveraroldan Jul 25, 2024
162c49b
remove imports
angelcerveraroldan Jul 25, 2024
9938658
add AnnealProtocol
angelcerveraroldan Jul 25, 2024
e73c512
Create anneal protocol from python
angelcerveraroldan Jul 25, 2024
9b9a71c
Add fixme (broken anneal)
angelcerveraroldan Jul 25, 2024
5864b26
boltzmann distribution uses β rather than RT, also fix vim-introduced…
cgevans Jul 27, 2024
734d33a
only nonzero rate update in anneal
cgevans Jul 29, 2024
cef881d
fix g_system units / RT problems; add some python methods.
cgevans Jul 31, 2024
90bd218
Run Many Anneals -- Get probs
angelcerveraroldan Jul 31, 2024
6e6112f
Merge remote-tracking branch 'origin/sdc1d' into sdc1d
angelcerveraroldan Jul 31, 2024
9e9ee84
mismatches
angelcerveraroldan Aug 1, 2024
65f5991
typo
angelcerveraroldan Aug 1, 2024
e4c5192
simplify function
angelcerveraroldan Aug 1, 2024
c22dced
Add function to handle both cases (one sequence and two)
angelcerveraroldan Aug 1, 2024
c09bd5c
DNA sequence delta g delta s with internal loop
angelcerveraroldan Aug 1, 2024
568bff6
docs update
angelcerveraroldan Aug 1, 2024
2e9fdc7
fast partition function, some name changes
cgevans Aug 5, 2024
6c99af3
sdc: add multi-precision float calculation to log for partition funct…
cgevans Aug 6, 2024
5552e7e
MFE -- not yet tested
angelcerveraroldan Aug 7, 2024
32c1a96
extract sdc sys for tests
angelcerveraroldan Aug 7, 2024
44e8975
Dont access matrix directly
angelcerveraroldan Aug 8, 2024
9314c6a
CachedResult type
angelcerveraroldan Aug 8, 2024
cb87255
Remove Custom Type -- Use Cell
angelcerveraroldan Aug 8, 2024
09cfdc6
Cache values
angelcerveraroldan Aug 8, 2024
15ed017
Remove GlueLinks
angelcerveraroldan Aug 8, 2024
d97101c
Merge branch 'main' into sdc1d
angelcerveraroldan Aug 8, 2024
5f3e66a
Remove line (function stopped being found)
angelcerveraroldan Aug 8, 2024
24885cb
Use astro-float instead of rug.
cgevans Aug 9, 2024
20d73ec
fix astro-float pfunc, use it for probability_of_state
cgevans Aug 9, 2024
ca34b3e
allow python subclassing of SDC
cgevans Aug 22, 2024
92288c1
Add sdc python code
cgevans Sep 2, 2024
7175fbe
import fixes
cgevans Sep 2, 2024
ae8e6f8
use Python subclass SDC, add plot_canvas to stub
cgevans Sep 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde = {version = "^1.0.185", features=["derive", "rc"]}
pyo3 = {version = "^0.21", features = ["extension-module", "multiple-pymethods"]}
rayon = { version = "1" }
numpy = "^0.21"
enum_dispatch = "0.3"
approx = "^0.5"
pyo3-polars = "^0.15"
polars = {version = "^0.41", features = ["lazy", "parquet", "product"]}

Expand All @@ -21,7 +21,5 @@ edition = "2021"
repository = "https://github.com/cgevans/rgrow"
license = "BSD-3-Clause"
categories = ["science", "simulation"]

[profile.release]
# debug = true
# lto = true
308 changes: 308 additions & 0 deletions examples/sdc/bit_copy.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion py-rgrow/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "rgrow"
dependencies = ["numpy ~= 1.26", "attrs ~= 23.2", "matplotlib ~= 3.8.2", "typing_extensions"]
dependencies = ["numpy ~= 1.26", "attrs ~= 23.2", "matplotlib ~= 3.8.2", "typing_extensions", "tqdm"]
requires-python = ">=3.9"

[project.optional-dependencies]
Expand Down
21 changes: 16 additions & 5 deletions py-rgrow/rgrow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
EvolveBounds,
FFSStateRef,
)
from .sdc import SDC
import attrs
import attr

Expand All @@ -40,7 +41,7 @@
)

System: TypeAlias = ATAM | KTAM | OldKTAM
SYSTEMS = (ATAM, KTAM, OldKTAM)
SYSTEMS = (ATAM, KTAM, OldKTAM, SDC)

if TYPE_CHECKING: # pragma: no cover
import matplotlib.pyplot as plt
Expand All @@ -67,7 +68,9 @@ def _system_name_canvas(self: "System", state: State | FFSStateRef) -> np.ndarra
return a[state.canvas_view]


def _system_color_canvas(self: System, state: State | np.ndarray | FFSStateRef) -> np.ndarray:
def _system_color_canvas(
self: System, state: State | np.ndarray | FFSStateRef
) -> np.ndarray:
"""Returns the current canvas for state, as an array of tile colors."""

if isinstance(state, (State, FFSStateRef)):
Expand Down Expand Up @@ -157,7 +160,11 @@ def _system_plot_canvas(
tile_colors / 12.92,
((tile_colors + 0.055) / 1.055) ** 2.4,
)
lum = 0.2126 * lumcolors[:, 0] + 0.7152 * lumcolors[:, 1] + 0.0722 * lumcolors[:, 2]
lum = (
0.2126 * lumcolors[:, 0]
+ 0.7152 * lumcolors[:, 1]
+ 0.0722 * lumcolors[:, 2]
)
for i in range(i_min, i_max + 1):
for j in range(j_min, j_max + 1):
if cv[i, j] == 0:
Expand Down Expand Up @@ -411,7 +418,9 @@ def ensure_state(self, n: int = 0) -> int:
def check_state(self, n: int = 0) -> int:
"""Check that the simulation has at least n states."""
if len(self.states) < n:
raise ValueError(f"Simulation has {len(self.states)} states, but {n} were required.")
raise ValueError(
f"Simulation has {len(self.states)} states, but {n} were required."
)

return n

Expand Down Expand Up @@ -609,7 +618,9 @@ def evolve_some(
require_strong_bound=require_strong_bound,
)

def plot_state(self, state_index: int = 0, ax: "plt.Axes | None" = None) -> "plt.QuadMesh":
def plot_state(
self, state_index: int = 0, ax: "plt.Axes | None" = None
) -> "plt.QuadMesh":
"""Plot a state as a pcolormesh. Returns the pcolormesh object."""
import matplotlib.pyplot as plt

Expand Down
284 changes: 278 additions & 6 deletions py-rgrow/rgrow/rgrow.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from numpy import ndarray
import numpy as np
import polars as pl
from numpy.typing import NDArray
from matplotlib.axes import Axes

class ATAM:
@property
Expand Down Expand Up @@ -249,8 +250,262 @@ class ATAM:
The name of the file to write to.
"""

def color_canvas(self, state: State | FFSStateRef | NDArray[np.uint]) -> NDArray[np.uint8]: ...
def name_canvas(self, state: State | FFSStateRef | NDArray[np.uint]) -> NDArray[np.str_]: ...
def color_canvas(
self, state: State | FFSStateRef | NDArray[np.uint]
) -> NDArray[np.uint8]: ...
def name_canvas(
self, state: State | FFSStateRef | NDArray[np.uint]
) -> NDArray[np.str_]: ...

class SDC:
@property
def tile_names(self) -> list[str]: ...
@property
def tile_colors(self) -> NDArray[np.uint]: ...
def calc_dimers(self) -> List[DimerInfo]:
"""
Calculate information about the dimers the system is able to form.

Returns
-------
List[DimerInfo]
"""

def calc_mismatch_locations(self, state: State | FFSStateRef) -> NDArray[np.uint64]:
"""
Calculate the locations of mismatches in the state.

This returns a copy of the canvas, with the values set to 0 if there is no mismatch
in the location, and > 0, in a model defined way, if there is at least one mismatch.
Most models use v = 8*N + 4*E + 2*S + W, where N, E, S, W are the four directions.
Thus, a tile with mismatches to the E and W would have v = 4+2 = 6.

Parameters
----------
state : State or FFSStateRef
The state to calculate mismatches for.

Returns
-------
ndarray
An array of the same shape as the state's canvas, with the values set as described above.
"""

def calc_mismatches(self, state: State | FFSStateRef) -> int:
"""
Calculate the number of mismatches in a state.

Parameters
----------
state : State or FFSStateRef
The state to calculate mismatches for.

Returns
-------
int
The number of mismatches.

See also
--------
calc_mismatch_locations
Calculate the location and direction of mismatches, not jus the number.
"""

@overload
def evolve(
self,
state: State,
for_events: int | None = None,
total_events: int | None = None,
for_time: float | None = None,
total_time: float | None = None,
size_min: int | None = None,
size_max: int | None = None,
for_wall_time: float | None = None,
require_strong_bound: bool = True,
show_window: bool = False,
parallel: bool = True,
) -> EvolveOutcome: ...
@overload
def evolve(
self,
state: Sequence[State],
for_events: int | None = None,
total_events: int | None = None,
for_time: float | None = None,
total_time: float | None = None,
size_min: int | None = None,
size_max: int | None = None,
for_wall_time: float | None = None,
require_strong_bound: bool = True,
show_window: bool = False,
parallel: bool = True,
) -> List[EvolveOutcome]: ...
@overload
def evolve(
self,
state: State | Sequence[State],
for_events: int | None = None,
total_events: int | None = None,
for_time: float | None = None,
total_time: float | None = None,
size_min: int | None = None,
size_max: int | None = None,
for_wall_time: float | None = None,
require_strong_bound: bool = True,
show_window: bool = False,
parallel: bool = True,
) -> EvolveOutcome | List[EvolveOutcome]:
"""
Evolve a state (or states), with some bounds on the simulation.

If evolving multiple states, the bounds are applied per-state.

Parameters
----------
state : State or Sequence[State]
The state or states to evolve.
for_events : int, optional
Stop evolving each state after this many events.
total_events : int, optional
Stop evelving each state when the state's total number of events (including
previous events) reaches this.
for_time : float, optional
Stop evolving each state after this many seconds of simulated time.
total_time : float, optional
Stop evolving each state when the state's total time (including previous steps)
reaches this.
size_min : int, optional
Stop evolving each state when the state's number of tiles is less than or equal to this.
size_max : int, optional
Stop evolving each state when the state's number of tiles is greater than or equal to this.
for_wall_time : float, optional
Stop evolving each state after this many seconds of wall time.
require_strong_bound : bool
Require that the stopping conditions are strong, i.e., they are guaranteed to be eventually
satisfied under normal conditions.
show_window : bool
Show a graphical UI window while evolving (requires ui feature, and a single state).
parallel : bool
Use multiple threads.

Returns
-------
EvolveOutcome or List[EvolveOutcome]
The outcome (stopping condition) of the evolution. If evolving a single state, returns a single outcome.
"""

def get_param(self, param_name): ...
def print_debug(self): ...
@staticmethod
def read_json(filename: str) -> None:
"""
Read a system from a JSON file.

Parameters
----------
filename : str
The name of the file to read from.
"""

def run_ffs(self, config: FFSRunConfig = ..., **kwargs: Any) -> FFSRunResult:
"""
Run FFS.

Parameters
----------
config : FFSRunConfig
The configuration for the FFS run.
**kwargs
FFSRunConfig parameters as keyword arguments.

Returns
-------
FFSRunResult
The result of the FFS run.
"""

def set_param(self, param_name: str, value: Any) -> NeededUpdate:
"""
Set a system parameter.

Parameters
----------
param_name : str
The name of the parameter to set.
value : Any
The value to set the parameter to.

Returns
-------
NeededUpdate
The type of state update needed. This can be passed to
`update_state` to update the state.
"""

def tile_color(self, tile_number: int) -> list[int]:
"""
Given a tile number, return the color of the tile.

Parameters
----------
tile_number : int
The tile number.

Returns
-------
list[int]
The color of the tile, as a list of 4 integers (RGBA).
"""

def tile_number_from_name(self, tile_name: str) -> int:
"""
Given a tile name, return the tile number.

Parameters
----------
tile_name : str
The name of the tile.

Returns
-------
int
The tile number.
"""

def update_all(self, state, needed=...): ...
def update_state(self, state: State, needed: NeededUpdate | None = ...) -> None:
"""
Recalculate a state's rates.

This is usually needed when a parameter of the system has
been changed.

Parameters
----------
state : State
The state to update.
needed : NeededUpdate, optional
The type of update needed. If not provided, all locations
will be recalculated.
"""

def write_json(self, filename: str) -> None:
"""
Write the system to a JSON file.

Parameters
----------
filename : str
The name of the file to write to.
"""

def color_canvas(
self, state: State | FFSStateRef | NDArray[np.uint]
) -> NDArray[np.uint8]: ...
def name_canvas(
self, state: State | FFSStateRef | NDArray[np.uint]
) -> NDArray[np.str_]: ...

class EvolveBounds:
def __init__(self, for_time: float | None = None): ...
Expand Down Expand Up @@ -564,16 +819,33 @@ class KTAM:
filename : str
The name of the file to write to.
"""
def color_canvas(self, state: State | FFSStateRef | NDArray[np.uint]) -> NDArray[np.uint8]: ...
def name_canvas(self, state: State | FFSStateRef | NDArray[np.uint]) -> NDArray[np.str_]: ...

def color_canvas(
self, state: State | FFSStateRef | NDArray[np.uint]
) -> NDArray[np.uint8]: ...
def name_canvas(
self, state: State | FFSStateRef | NDArray[np.uint]
) -> NDArray[np.str_]: ...
def plot_canvas(
self,
state: State | np.ndarray | FFSStateRef,
ax: "Axes" | None = None,
annotate_tiles: bool = False,
annotate_mismatches: bool = False,
crop: bool = False,
) -> "Axes": ...

class OldKTAM:
@property
def tile_names(self) -> list[str]: ...
@property
def tile_colors(self) -> NDArray[np.uint]: ...
def color_canvas(self, state: State | FFSStateRef | NDArray[np.uint]) -> NDArray[np.uint8]: ...
def name_canvas(self, state: State | FFSStateRef | NDArray[np.uint]) -> NDArray[np.str_]: ...
def color_canvas(
self, state: State | FFSStateRef | NDArray[np.uint]
) -> NDArray[np.uint8]: ...
def name_canvas(
self, state: State | FFSStateRef | NDArray[np.uint]
) -> NDArray[np.str_]: ...
def calc_dimers(self) -> List[DimerInfo]:
"""
Calculate information about the dimers the system is able to form.
Expand Down
Loading
Loading