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

fix rise angle null values of calculate_lattice_structure #117

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 4 additions & 10 deletions cylindra/cylmeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,10 @@ def calc_rise(mole: Molecules, spl: CylSpline) -> pl.Series:
sign = spl.config.rise_sign
return (
calc_localvec_lat(mole, spl, fill=np.nan)
.select(
pl.arctan2("vecy", "veca")
.degrees()
.fill_nan(-float("inf"))
.alias(Mole.rise)
)
.select(pl.arctan2("vecy", "veca").degrees().alias(Mole.rise))
.to_series()
* sign
)
).fill_nan(-float("inf"))


def calc_lateral_interval(mole: Molecules, spl: CylSpline) -> pl.Series:
Expand All @@ -113,11 +108,10 @@ def calc_lateral_interval(mole: Molecules, spl: CylSpline) -> pl.Series:
.select(
(pl.col("vecy") ** 2 + pl.col("veca") ** 2)
.sqrt()
.fill_nan(-float("inf"))
.alias(Mole.lateral_interval)
)
.to_series()
)
).fill_nan(-float("inf"))


def _pad_molecules_at_seam(mole: Molecules, spl: CylSpline) -> tuple[Molecules, int]:
Expand Down Expand Up @@ -195,7 +189,7 @@ def calc_localvec_lat(
_vec_tr = _vec_tr[:-1, :]
sub0 = sub0.subset(slice(None, -1))
else:
_vec_tr[:-1, :] = fill
_vec_tr[-1, :] = fill
subsets.append(
sub0.with_features(
pl.Series("vecr", _vec_tr[:, 0], dtype=pl.Float32),
Expand Down
6 changes: 6 additions & 0 deletions tests/test_gui_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,12 @@ def test_calc_misc(ui: CylindraMainWidget):
all_props = cylmeasure.LatticeParameters.choices()
ui.calculate_lattice_structure(layer=layer, props=all_props)
assert layer.features[Mole.radius].std() < 0.1
# check null values
assert layer.molecules.features[Mole.spacing].is_finite().not_().sum() == 13
assert layer.molecules.features[Mole.twist].is_finite().not_().sum() == 13
assert layer.molecules.features[Mole.rise].is_finite().not_().sum() == 3
assert layer.molecules.features[Mole.lateral_interval].is_finite().not_().sum() == 3

ui.paint_molecules(layer, color_by=Mole.nth, limits=(0, 10))
colors = ui.mole_layers.last().face_color
ui.MoleculesMenu.View.plot_molecule_feature(layer, backend="qt")
Expand Down
Loading