bmtool 0.6.5.1__py3-none-any.whl → 0.6.6.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bmtool/synapses.py CHANGED
@@ -405,6 +405,10 @@ class SynapseTuner:
405
405
  ------
406
406
  - This function is based on experiments from the Allen Database.
407
407
  """
408
+ # lets also set the train drive and delay here
409
+ self.train_freq = freq
410
+ self.train_delay = delay
411
+
408
412
  n_init_pulse = 8
409
413
  n_ending_pulse = 4
410
414
  self.nstim.start = self.general_settings['tstart']
@@ -500,7 +504,7 @@ class SynapseTuner:
500
504
 
501
505
  if print_math:
502
506
  print("\n" + "="*40)
503
- print("Short Term Plasticity Results")
507
+ print(f"Short Term Plasticity Results for {self.train_freq}Hz with {self.train_delay} Delay")
504
508
  print("="*40)
505
509
  print("PPR: Above 1 is facilitating, below 1 is depressing.")
506
510
  print("Induction: Above 0 is facilitating, below 0 is depressing.")
@@ -682,6 +686,100 @@ class SynapseTuner:
682
686
 
683
687
  display(ui)
684
688
  update_ui()
689
+
690
+ def stp_frequency_response(self, freqs=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 35, 50, 100, 200],
691
+ delay=250, plot=True,log_plot=True):
692
+ """
693
+ Analyze synaptic response across different stimulation frequencies.
694
+
695
+ Parameters:
696
+ -----------
697
+ freqs : list, optional
698
+ List of frequencies to analyze (in Hz)
699
+ delay : float, optional
700
+ Delay between pulse trains in ms
701
+ plot : bool, optional
702
+ Whether to plot the results
703
+
704
+ Returns:
705
+ --------
706
+ dict
707
+ Dictionary containing frequency-dependent metrics
708
+ """
709
+ results = {
710
+ 'frequencies': freqs,
711
+ 'ppr': [],
712
+ 'induction': [],
713
+ 'recovery': []
714
+ }
715
+
716
+ # Store original state
717
+ original_ispk = self.ispk
718
+
719
+ for freq in tqdm(freqs, desc="Analyzing frequencies"):
720
+ self._simulate_model(freq, delay)
721
+ amp = self._response_amplitude()
722
+ ppr, induction, recovery = self._calc_ppr_induction_recovery(amp, print_math=False)
723
+
724
+ results['ppr'].append(float(ppr))
725
+ results['induction'].append(float(induction))
726
+ results['recovery'].append(float(recovery))
727
+
728
+ # Restore original state
729
+ self.ispk = original_ispk
730
+
731
+ if plot:
732
+ self._plot_frequency_analysis(results,log_plot=log_plot)
733
+
734
+ return results
735
+
736
+ def _plot_frequency_analysis(self, results,log_plot):
737
+ """
738
+ Plot the frequency-dependent synaptic properties.
739
+
740
+ Parameters:
741
+ -----------
742
+ results : dict
743
+ Dictionary containing frequency analysis results
744
+ """
745
+ fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(15, 5))
746
+
747
+
748
+ # Plot PPR
749
+ if log_plot:
750
+ ax1.semilogx(results['frequencies'], results['ppr'], 'o-')
751
+ else:
752
+ ax1.plot(results['frequencies'], results['ppr'], 'o-')
753
+ ax1.axhline(y=1, color='gray', linestyle='--', alpha=0.5)
754
+ ax1.set_xlabel('Frequency (Hz)')
755
+ ax1.set_ylabel('Paired Pulse Ratio')
756
+ ax1.set_title('PPR vs Frequency')
757
+ ax1.grid(True)
758
+
759
+ # Plot Induction
760
+ if log_plot:
761
+ ax2.semilogx(results['frequencies'], results['induction'], 'o-')
762
+ else:
763
+ ax2.plot(results['frequencies'], results['induction'], 'o-')
764
+ ax2.axhline(y=0, color='gray', linestyle='--', alpha=0.5)
765
+ ax2.set_xlabel('Frequency (Hz)')
766
+ ax2.set_ylabel('Induction')
767
+ ax2.set_title('Induction vs Frequency')
768
+ ax2.grid(True)
769
+
770
+ # Plot Recovery
771
+ if log_plot:
772
+ ax3.semilogx(results['frequencies'], results['recovery'], 'o-')
773
+ else:
774
+ ax3.plot(results['frequencies'], results['recovery'], 'o-')
775
+ ax3.axhline(y=0, color='gray', linestyle='--', alpha=0.5)
776
+ ax3.set_xlabel('Frequency (Hz)')
777
+ ax3.set_ylabel('Recovery')
778
+ ax3.set_title('Recovery vs Frequency')
779
+ ax3.grid(True)
780
+
781
+ plt.tight_layout()
782
+ plt.show()
685
783
 
686
784
  class GapJunctionTuner:
687
785
  def __init__(self, mechanisms_dir: str, templates_dir: str, general_settings: dict, conn_type_settings: dict):
@@ -829,13 +927,13 @@ class SynapseOptimizer:
829
927
  return np.array([normalized_params[i] * self.param_scales[name] for i, name in enumerate(param_names)])
830
928
 
831
929
  def _calculate_metrics(self) -> Dict[str, float]:
832
- """Calculate standard metrics from the current simulation"""
833
- self.tuner._simulate_model(50, 250) # 50 Hz with 250ms Delay
930
+ """Calculate standard metrics from the current simulation using specified frequency"""
931
+ self.tuner._simulate_model(self.train_frequency, self.train_delay)
834
932
  amp = self.tuner._response_amplitude()
835
933
  ppr, induction, recovery = self.tuner._calc_ppr_induction_recovery(amp, print_math=False)
836
934
  amp = self.tuner._find_max_amp(amp)
837
935
  return {
838
- 'induction': float(induction), # Ensure these are scalar values
936
+ 'induction': float(induction),
839
937
  'ppr': float(ppr),
840
938
  'recovery': float(recovery),
841
939
  'max_amplitude': float(amp)
@@ -874,15 +972,40 @@ class SynapseOptimizer:
874
972
 
875
973
  return error
876
974
 
877
- def optimize_parameters(self,
878
- target_metrics: Dict[str, float],
879
- param_bounds: Dict[str, Tuple[float, float]],
880
- cost_function: Optional[Callable] = None,
881
- method: str = 'SLSQP',init_guess='random') -> SynapseOptimizationResult:
975
+ def optimize_parameters(self, target_metrics: Dict[str, float],
976
+ param_bounds: Dict[str, Tuple[float, float]],
977
+ train_frequency: float = 50,train_delay: float = 250,
978
+ cost_function: Optional[Callable] = None,
979
+ method: str = 'SLSQP',init_guess='random') -> SynapseOptimizationResult:
882
980
  """
883
981
  Optimize synaptic parameters using custom cost function
884
- """
982
+
983
+ Parameters:
984
+ -----------
985
+ target_metrics : Dict[str, float]
986
+ Target values for synaptic metrics
987
+ param_bounds : Dict[str, Tuple[float, float]]
988
+ Bounds for each parameter to optimize
989
+ train_frequency : float, optional
990
+ Frequency of the stimulus train in Hz (default: 50)
991
+ train_delay : float, optional
992
+ Delay between pulse trains in ms (default: 250)
993
+ cost_function : Optional[Callable]
994
+ Custom cost function for optimization
995
+ method : str, optional
996
+ Optimization method to use (default: 'SLSQP')
997
+ init_guess : str, optional
998
+ Method for initial parameter guess ('random' or 'middle_guess')
999
+
1000
+ Returns:
1001
+ --------
1002
+ SynapseOptimizationResult
1003
+ Results of the optimization
1004
+ """
885
1005
  self.optimization_history = []
1006
+ self.train_frequency = train_frequency
1007
+ self.train_delay = train_delay
1008
+
886
1009
  param_names = list(param_bounds.keys())
887
1010
  bounds = [param_bounds[name] for name in param_names]
888
1011
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: bmtool
3
- Version: 0.6.5.1
3
+ Version: 0.6.6.2
4
4
  Summary: BMTool
5
5
  Home-page: https://github.com/cyneuro/bmtool
6
6
  Download-URL:
@@ -7,7 +7,7 @@ bmtool/graphs.py,sha256=K8BiughRUeXFVvAgo8UzrwpSClIVg7UfmIcvtEsEsk0,6020
7
7
  bmtool/manage.py,sha256=_lCU0qBQZ4jSxjzAJUd09JEetb--cud7KZgxQFbLGSY,657
8
8
  bmtool/plot_commands.py,sha256=Tqujyf0c0u8olhiHOMwgUSJXIIE1hgjv6otb25G9cA0,12298
9
9
  bmtool/singlecell.py,sha256=MQiLucsI6OBIjtcJra3Z9PTFQOE-Zn5ST-R9SmFvrbQ,27049
10
- bmtool/synapses.py,sha256=jQFOpi9hzzBEijDQ7dsWfcxW-DtxN9v0UWxCqDSlcTs,48466
10
+ bmtool/synapses.py,sha256=KyvDtoL7_mbXLr7TXaaeFTjqUM_ZXoVzSABQ69eTAHI,52876
11
11
  bmtool/debug/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  bmtool/debug/commands.py,sha256=AwtcR7BUUheM0NxvU1Nu234zCdpobhJv5noX8x5K2vY,583
13
13
  bmtool/debug/debug.py,sha256=xqnkzLiH3s-tS26Y5lZZL62qR2evJdi46Gud-HzxEN4,207
@@ -16,9 +16,9 @@ bmtool/util/commands.py,sha256=zJF-fiLk0b8LyzHDfvewUyS7iumOxVnj33IkJDzux4M,64396
16
16
  bmtool/util/util.py,sha256=00vOAwTVIifCqouBoFoT0lBashl4fCalrk8fhg_Uq4c,56654
17
17
  bmtool/util/neuron/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  bmtool/util/neuron/celltuner.py,sha256=xSRpRN6DhPFz4q5buq_W8UmsD7BbUrkzYBEbKVloYss,87194
19
- bmtool-0.6.5.1.dist-info/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
20
- bmtool-0.6.5.1.dist-info/METADATA,sha256=mCHLJ27JL7d17fe5atQTwQGkVfzVQ6MhqHlhgbm8yh4,20226
21
- bmtool-0.6.5.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
22
- bmtool-0.6.5.1.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
23
- bmtool-0.6.5.1.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
24
- bmtool-0.6.5.1.dist-info/RECORD,,
19
+ bmtool-0.6.6.2.dist-info/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
20
+ bmtool-0.6.6.2.dist-info/METADATA,sha256=ufAGAV4laD-Jo5B7L77lHrfMgb4_V7iv_6u1Lf3O1Qc,20226
21
+ bmtool-0.6.6.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
22
+ bmtool-0.6.6.2.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
23
+ bmtool-0.6.6.2.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
24
+ bmtool-0.6.6.2.dist-info/RECORD,,