Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed Dec 20, 2023
1 parent acf12c8 commit f430211
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
35 changes: 35 additions & 0 deletions docs/molecules/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,38 @@

In `cylindra`, molecules are processed largely depending on the [**expression** system
of `polars`](https://pola-rs.github.io/polars/user-guide/concepts/expressions/).

```python
df = pl.DataFrame(
{
"nth": [0, 1, 2, 3],
"score": [0.8, 0.9, 0.4, 0.8]
},
)
df
```

|nth|score|
|--:|----:|
| 0| 0.8|
| 1| 0.9|
| 2| 0.4|
| 3| 0.8|

```python
pl.col("score") # the column named "score"
df_filt = df.filter(pl.col("score") > 0.7) # filter rows by the values of "score"
df_filt
```

|nth|score|
|--:|----:|
| 0| 0.8|
| 1| 0.9|
| 3| 0.8|

Here's some examples.

- `pl.col("pf-id") % 2 == 1`
- `pl.col("nth") + pl.col("y") < 1`
- `pl.col("orientation") == "PlusToMinus"`
39 changes: 38 additions & 1 deletion tests/test_gui_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ def test_simulator(ui: CylindraMainWidget):
radius=6,
offsets=(0.0, 0.18),
)
ui.simulator._get_components()
ui.simulator.expand(layer, by=0.1, yrange=(11, 15), arange=(0, 14), allev=True)
ui.simulator.twist(layer, by=0.3, yrange=(11, 15), arange=(0, 14), allev=True)
ui.simulator.dilate(layer, by=-0.5, yrange=(11, 15), arange=(0, 14), allev=True)
Expand Down Expand Up @@ -1069,6 +1070,30 @@ def test_calc_misc(ui: CylindraMainWidget):
assert_allclose(ui.mole_layers.last().face_color, colors)


def test_lattice_structure_of_curved_microtubule(ui: CylindraMainWidget):
ui.simulator.create_empty_image(size=(60.0, 200.0, 90.0), scale=1.0)
ui.register_path(coords=[[35.0, 27.8, 22.0], [35.0, 106, 25.3], [35.0, 179, 55.5]])

def _get_mean(p: str):
s = ui.mole_layers.last().molecules.features[p]
s0 = s.filter(s.is_finite())
return s0.mean()

ui.simulator.generate_molecules(
spline=0,
spacing=4.1,
twist=-0.25,
start=3,
npf=14,
radius=11.0,
)
ui.calculate_lattice_structure(
layer="Mole(Sim)-0", props=["spacing", "twist", "skew_angle", "rise_angle"]
)
assert _get_mean("spacing") == pytest.approx(4.1, abs=3e-3)
assert _get_mean("twist") == pytest.approx(-0.25, abs=1e-4)


def test_spline_fitter(ui: CylindraMainWidget):
ui.open_image(
TEST_DIR / f"14pf_MT.tif",
Expand Down Expand Up @@ -1386,7 +1411,7 @@ def test_image_processor(ui: CylindraMainWidget):

def test_workflows_custom(ui: CylindraMainWidget):
name = "Test"
code = "import numpy as np\n" "def main(ui):\n" " print(ui.default_config)\n"
code = "import numpy as np\ndef main(ui):\n print(ui.default_config)\n"
with tempfile.TemporaryDirectory() as dirpath, _config.patch_workflow_path(dirpath):
ui.OthersMenu.Workflows.define_workflow(name, code)
ui.OthersMenu.Workflows.edit_workflow(name, code)
Expand All @@ -1399,6 +1424,18 @@ def test_workflows_custom(ui: CylindraMainWidget):
ui.OthersMenu.Workflows.delete_workflow([name])
ui.OthersMenu.Workflows.copy_workflow_directory()

# test invalid code
with pytest.raises(Exception):
# attribute error
ui.OthersMenu.Workflows.define_workflow(
"Test-2", "def main(ui):\n ui.bad_method_name()\n"
)
with pytest.raises(Exception):
# not enough arguments
ui.OthersMenu.Workflows.define_workflow(
"Test-2", "def main(ui):\n ui.open_image()\n"
)


def test_stash(ui: CylindraMainWidget):
ui.load_project(PROJECT_DIR_13PF, filter=None)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ def test_sequence_methods():
assert mole.count() > 500
for (i, s), mole in seq.iter_molecules():
pass


def test_molecules_items():
seq = collect_projects([PROJECT_DIR_13PF, PROJECT_DIR_14PF])
for item in seq.iter_molecules_with_splines(name_filter=lambda name: True):
assert item.molecules.count() > 0
assert item.spline is not None
item.lattice_structure(("spacing",))
item.local_vectors_longitudinal()
item.local_vectors_lateral()

0 comments on commit f430211

Please sign in to comment.