From 6456f6211710601c580dc6cdace877eb7aaf1bc4 Mon Sep 17 00:00:00 2001 From: Vincent Ebert <85253529+vincentebert@users.noreply.github.com> Date: Wed, 19 Aug 2026 09:29:37 +0200 Subject: [PATCH 1/2] user-specified transitions user-specified energy transfer transitions accepts 5 nm as distance and does no longer require 5.0 nm --- src/fluopy/emissions.py | 2 +- src/fluopy/transitions.py | 37 ++++++++++++++++++++----------------- tests/test_transitions.py | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/fluopy/emissions.py b/src/fluopy/emissions.py index 9582704..74fc10d 100644 --- a/src/fluopy/emissions.py +++ b/src/fluopy/emissions.py @@ -68,7 +68,7 @@ def __init__( https://pandas.pydata.org/docs/user_guide/timeseries.html -> Offset aliases. bandpass The lowest and highest emission wavelength to be passed by the bandpass - filter. + filter. Requires emission spectrum data when specified. seed A seed to initialize the BitGenerator. """ diff --git a/src/fluopy/transitions.py b/src/fluopy/transitions.py index 3adec72..5c6ce2e 100644 --- a/src/fluopy/transitions.py +++ b/src/fluopy/transitions.py @@ -314,7 +314,9 @@ class TransitionSet: ---------- transitions : dict[str, list[Transition]] Contains lists of transitions of type Transition with non-zero rate as values - and fluorophores or fluorophore-combinations as keys. + and fluorophores or fluorophore-combinations as keys. Fluorophore-combination + keys require the format 'D: {name of donor}, A: {name of acceptor}, dist: + {distance between them in nm}'. fluorophore_system : fluopy.fluorophores.FluorophoreSystem Container for attributes of multiple, interrelated fluorophores. combined_state_transitions_df : pd.DataFrame @@ -346,7 +348,9 @@ def __init__( ---------- transitions Contains lists of transitions of type Transition as values and fluorophores - or fluorophore-combinations as keys. + or fluorophore-combinations as keys. Fluorophore-combination keys require + the format 'D: {name of donor}, A: {name of acceptor}, dist: {distance + between them in nm}'. fluorophore_system Container for attributes of multiple, interrelated fluorophores. keep_zero_rates @@ -361,18 +365,18 @@ def __init__( keep_transitions = [] df_constructor = [] for transition in f_transitions: - if "dist" not in fluorophore_comb and isinstance( - transition.initial_state, PairedState - ): - raise ValueError( - "energy transfers have to be defined in transitions with the " - "key 'D: {name of donor}, A: {name of acceptor}, dist: " - "{distance between them}'." + if isinstance(transition.initial_state, PairedState): + pattern = ( + r"D:\s*([^,]+),\s*A:\s*([^,]+),\s*dist:\s*(\d+(?:\.\d+)?)\s*" ) - if "dist" in fluorophore_comb: - pattern = r"D:\s*([^,]+),\s*A:\s*([^,]+),\s*dist:\s*([\d.]+)" - match = re.match(pattern=pattern, string=fluorophore_comb) - d, a, dist = match.group(1), match.group(2), match.group(3) + match = re.fullmatch(pattern=pattern, string=fluorophore_comb) + if match is None: + raise ValueError( + "energy transfers have to be defined in transitions with the " + "key 'D: {name of donor}, A: {name of acceptor}, dist: " + "{distance between them in nm}'." + ) + d, a, dist = match.groups() for d_t, a_t in transition.fluorophore_ids: if self.fluorophore_system.fluorophores[d_t].name != d: raise ValueError( @@ -386,11 +390,10 @@ def __init__( f"{self.fluorophore_system.fluorophores[a_t].name} " "found." ) - if str(self.fluorophore_system.distances[(d_t, a_t)]) != dist: + actual_dist = self.fluorophore_system.distances[(d_t, a_t)] + if float(dist) != actual_dist: raise ValueError( - f"{dist} nm indicated, " - f"{self.fluorophore_system.distances[(d_t, a_t)]} nm " - "found." + f"{dist} nm indicated, {actual_dist} nm found." ) else: for j in transition.fluorophore_ids: diff --git a/tests/test_transitions.py b/tests/test_transitions.py index 8a950c8..23e93a9 100644 --- a/tests/test_transitions.py +++ b/tests/test_transitions.py @@ -208,7 +208,7 @@ def test_transition_set_errors( ValueError, match="energy transfers have to be defined in transitions with the " "key 'D: {name of donor}, A: {name of acceptor}, dist: " - "{distance between them}'", + "{distance between them in nm}'", ): tr.TransitionSet( transitions=transitions, fluorophore_system=fluorophore_system From e94f9857652871e2bfa49ea87183b391f473e12b Mon Sep 17 00:00:00 2001 From: Vincent Ebert <85253529+vincentebert@users.noreply.github.com> Date: Wed, 19 Aug 2026 09:32:58 +0200 Subject: [PATCH 2/2] fixed line length --- src/fluopy/transitions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fluopy/transitions.py b/src/fluopy/transitions.py index 5c6ce2e..d28a46d 100644 --- a/src/fluopy/transitions.py +++ b/src/fluopy/transitions.py @@ -372,8 +372,8 @@ def __init__( match = re.fullmatch(pattern=pattern, string=fluorophore_comb) if match is None: raise ValueError( - "energy transfers have to be defined in transitions with the " - "key 'D: {name of donor}, A: {name of acceptor}, dist: " + "energy transfers have to be defined in transitions with " + "the key 'D: {name of donor}, A: {name of acceptor}, dist: " "{distance between them in nm}'." ) d, a, dist = match.groups() @@ -523,8 +523,8 @@ def adjust_rates( def remove_zero_rates(self) -> TransitionSet: """ - Returns another TransitionSet with all transitions removed that have a rate constant - of zero. + Returns another TransitionSet with all transitions removed that have a rate + constant of zero. Returns -------