Skip to content

Protocols

Stimulus builders for current- and voltage-clamp simulations. The dispatchers (build_current_protocol, build_voltage_protocol) select a generator by name; the generators can also be called directly for single-sweep stimuli.

Dispatchers

neuroclamp.build_current_protocol

build_current_protocol(protocol_type, sampling_frequency, pre_stimulus_duration=10.0, stimulus_duration=30.0, post_stimulus_duration=10.0, min_stimulus=10.0, max_stimulus=10.0, stimulus_step=0.0, start_current=0.0, end_current=15.0, pulse_amplitude=10.0, pulse_width=2.0, pulse_interval=10.0, dc_offset=8.0, amplitude=4.0, frequency=50.0, start_frequency=1.0, end_frequency=100.0, mean_current=8.0, std_current=2.0)

Build current clamp protocol arrays from explicit parameters.

Parameters:

Name Type Description Default
protocol_type str

One of "Step", "Ramp", "Pulse Train", "Sinusoidal", "Chirp", or "Noise".

required
sampling_frequency float

Sampling frequency in Hz.

required
pre_stimulus_duration float

Duration before the stimulus in ms.

10.0
stimulus_duration float

Duration of the stimulus in ms.

30.0
post_stimulus_duration float

Duration after the stimulus in ms.

10.0
min_stimulus float

Step current amplitude in µA/cm² for a single-step, or minimum current when running a multi-sweep range.

10.0
max_stimulus float

Maximum current for multi-sweep range in µA/cm². Must be >= min_stimulus.

10.0
stimulus_step float

Step size for multi-sweep range in µA/cm². Use 0.0 (or set min_stimulus == max_stimulus) for a single-step protocol.

0.0
start_current float

Ramp start current in µA/cm².

0.0
end_current float

Ramp end current in µA/cm².

15.0
pulse_amplitude float

Pulse amplitude in µA/cm².

10.0
pulse_width float

Pulse width in ms.

2.0
pulse_interval float

Interval between pulse starts in ms.

10.0
dc_offset float

DC offset for sinusoidal/chirp in µA/cm².

8.0
amplitude float

AC amplitude for sinusoidal/chirp in µA/cm².

4.0
frequency float

Sinusoidal frequency in Hz.

50.0
start_frequency float

Chirp start frequency in Hz.

1.0
end_frequency float

Chirp end frequency in Hz.

100.0
mean_current float

Noise mean current in µA/cm².

8.0
std_current float

Noise standard deviation in µA/cm².

2.0

Returns:

Type Description
ndarray

2-D array of shape (n_sweeps, n_samples). Single-step protocols

ndarray

return shape (1, n_samples). Multi-sweep Step protocols return one

ndarray

row per current level.

Raises:

Type Description
ValueError

If protocol_type is unrecognized or parameters are invalid.

Source code in neuroclamp/protocols/builders.py
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def build_current_protocol(
    protocol_type: str,
    sampling_frequency: float,
    pre_stimulus_duration: float = 10.0,
    stimulus_duration: float = 30.0,
    post_stimulus_duration: float = 10.0,
    min_stimulus: float = 10.0,
    max_stimulus: float = 10.0,
    stimulus_step: float = 0.0,
    start_current: float = 0.0,
    end_current: float = 15.0,
    pulse_amplitude: float = 10.0,
    pulse_width: float = 2.0,
    pulse_interval: float = 10.0,
    dc_offset: float = 8.0,
    amplitude: float = 4.0,
    frequency: float = 50.0,
    start_frequency: float = 1.0,
    end_frequency: float = 100.0,
    mean_current: float = 8.0,
    std_current: float = 2.0,
) -> np.ndarray:
    """Build current clamp protocol arrays from explicit parameters.

    Args:
        protocol_type: One of "Step", "Ramp", "Pulse Train", "Sinusoidal",
            "Chirp", or "Noise".
        sampling_frequency: Sampling frequency in Hz.
        pre_stimulus_duration: Duration before the stimulus in ms.
        stimulus_duration: Duration of the stimulus in ms.
        post_stimulus_duration: Duration after the stimulus in ms.
        min_stimulus: Step current amplitude in µA/cm² for a single-step, or
            minimum current when running a multi-sweep range.
        max_stimulus: Maximum current for multi-sweep range in µA/cm².  Must
            be >= min_stimulus.
        stimulus_step: Step size for multi-sweep range in µA/cm².  Use 0.0
            (or set min_stimulus == max_stimulus) for a single-step protocol.
        start_current: Ramp start current in µA/cm².
        end_current: Ramp end current in µA/cm².
        pulse_amplitude: Pulse amplitude in µA/cm².
        pulse_width: Pulse width in ms.
        pulse_interval: Interval between pulse starts in ms.
        dc_offset: DC offset for sinusoidal/chirp in µA/cm².
        amplitude: AC amplitude for sinusoidal/chirp in µA/cm².
        frequency: Sinusoidal frequency in Hz.
        start_frequency: Chirp start frequency in Hz.
        end_frequency: Chirp end frequency in Hz.
        mean_current: Noise mean current in µA/cm².
        std_current: Noise standard deviation in µA/cm².

    Returns:
        2-D array of shape ``(n_sweeps, n_samples)``.  Single-step protocols
        return shape ``(1, n_samples)``.  Multi-sweep Step protocols return one
        row per current level.

    Raises:
        ValueError: If protocol_type is unrecognized or parameters are invalid.
    """
    total_duration = pre_stimulus_duration + stimulus_duration + post_stimulus_duration
    sweeps: list[np.ndarray]
    if protocol_type == "Step":
        if stimulus_step < 0.0:
            raise ValueError("stimulus_step must be >= 0.0")
        if min_stimulus > max_stimulus:
            raise ValueError(
                f"min_stimulus ({min_stimulus}) must be"
                f" <= max_stimulus ({max_stimulus})"
            )
        if min_stimulus != max_stimulus and stimulus_step == 0.0:
            raise ValueError(
                "stimulus_step must be > 0.0 when min_stimulus != max_stimulus"
            )
        if min_stimulus == max_stimulus:
            sweeps = [
                step_current(
                    duration=total_duration,
                    current_amplitude=min_stimulus,
                    step_start=pre_stimulus_duration,
                    step_duration=stimulus_duration,
                    sampling_frequency=sampling_frequency,
                )
            ]
        else:
            n_steps = round((max_stimulus - min_stimulus) / stimulus_step) + 1
            currents = np.linspace(min_stimulus, max_stimulus, n_steps)
            sweeps = [
                step_current(
                    duration=total_duration,
                    current_amplitude=float(current),
                    step_start=pre_stimulus_duration,
                    step_duration=stimulus_duration,
                    sampling_frequency=sampling_frequency,
                )
                for current in currents
            ]
    elif protocol_type == "Ramp":
        sweeps = [
            ramp_current(
                duration=total_duration,
                start_current=start_current,
                end_current=end_current,
                ramp_start=pre_stimulus_duration,
                ramp_duration=stimulus_duration,
                sampling_frequency=sampling_frequency,
            )
        ]
    elif protocol_type == "Pulse Train":
        sweeps = [
            pulse_train(
                duration=total_duration,
                pulse_amplitude=pulse_amplitude,
                pulse_width=pulse_width,
                pulse_interval=pulse_interval,
                train_start=pre_stimulus_duration,
                sampling_frequency=sampling_frequency,
            )
        ]
    elif protocol_type == "Sinusoidal":
        sweeps = [
            sinusoidal_current(
                duration=total_duration,
                dc_offset=dc_offset,
                amplitude=amplitude,
                frequency=frequency,
                stimulus_start=pre_stimulus_duration,
                stimulus_duration=stimulus_duration,
                sampling_frequency=sampling_frequency,
            )
        ]
    elif protocol_type == "Chirp":
        sweeps = [
            chirp_current(
                duration=total_duration,
                dc_offset=dc_offset,
                amplitude=amplitude,
                start_frequency=start_frequency,
                end_frequency=end_frequency,
                stimulus_start=pre_stimulus_duration,
                stimulus_duration=stimulus_duration,
                sampling_frequency=sampling_frequency,
            )
        ]
    elif protocol_type == "Noise":
        sweeps = [
            noise_current(
                duration=total_duration,
                mean_current=mean_current,
                std_current=std_current,
                stimulus_start=pre_stimulus_duration,
                stimulus_duration=stimulus_duration,
                sampling_frequency=sampling_frequency,
            )
        ]
    else:
        raise ValueError(f"Unknown current protocol type: {protocol_type!r}")
    logger.debug(
        "build_current_protocol: type=%r total_duration=%.1f ms sweeps=%d",
        protocol_type,
        total_duration,
        len(sweeps),
    )
    return np.array(sweeps)

neuroclamp.build_voltage_protocol

build_voltage_protocol(protocol_type, sampling_frequency, pre_stimulus_duration=10.0, stimulus_duration=30.0, post_stimulus_duration=10.0, holding_voltage=-70.0, start_voltage=-70.0, end_voltage=40.0, pulse_amplitude=20.0, pulse_width=2.0, pulse_interval=10.0, test_pulse_voltage=0.0, min_stimulus=0.0, max_stimulus=0.0, stimulus_step=0.0)

Build voltage clamp protocol arrays from explicit parameters.

Parameters:

Name Type Description Default
protocol_type str

One of "Step", "Ramp", "Pulse Train", or "Inactivation".

required
sampling_frequency float

Sampling frequency in Hz.

required
pre_stimulus_duration float

Duration before the stimulus in ms. For the "Inactivation" protocol this is the conditioning prepulse duration.

10.0
stimulus_duration float

Duration of the stimulus in ms. For the "Inactivation" protocol this is the fixed test-pulse duration.

30.0
post_stimulus_duration float

Duration after the stimulus in ms.

10.0
holding_voltage float

Holding voltage in mV. Ignored by the "Inactivation" protocol, which uses each sweep's conditioning prepulse as the holding level.

-70.0
start_voltage float

Ramp start voltage in mV.

-70.0
end_voltage float

Ramp end voltage in mV.

40.0
pulse_amplitude float

Pulse amplitude in mV.

20.0
pulse_width float

Pulse width in ms.

2.0
pulse_interval float

Interval between pulse starts in ms.

10.0
test_pulse_voltage float

Fixed test-pulse voltage in mV for the "Inactivation" two-pulse protocol. The swept min_stimulus / max_stimulus / stimulus_step range then specifies the conditioning prepulse voltage applied as each sweep's holding level.

0.0
min_stimulus float

Step voltage amplitude in mV for a single-step, or minimum voltage when running a multi-sweep range. For the "Inactivation" protocol this is the most-hyperpolarized prepulse.

0.0
max_stimulus float

Maximum voltage for multi-sweep range in mV. Must be >= min_stimulus. For the "Inactivation" protocol this is the most-depolarized prepulse.

0.0
stimulus_step float

Step size for multi-sweep range in mV. Use 0.0 (or set min_stimulus == max_stimulus) for a single-step protocol. Must be > 0.0 for the "Inactivation" protocol, which is inherently multi-sweep.

0.0

Returns:

Type Description
ndarray

2-D array of shape (n_sweeps, n_samples). Single-step protocols

ndarray

return shape (1, n_samples). Multi-sweep Step protocols return one

ndarray

row per voltage level; the "Inactivation" protocol returns one row per

ndarray

conditioning prepulse voltage.

Raises:

Type Description
ValueError

If protocol_type is unrecognized or parameters are invalid.

Source code in neuroclamp/protocols/builders.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
def build_voltage_protocol(
    protocol_type: str,
    sampling_frequency: float,
    pre_stimulus_duration: float = 10.0,
    stimulus_duration: float = 30.0,
    post_stimulus_duration: float = 10.0,
    holding_voltage: float = -70.0,
    start_voltage: float = -70.0,
    end_voltage: float = 40.0,
    pulse_amplitude: float = 20.0,
    pulse_width: float = 2.0,
    pulse_interval: float = 10.0,
    test_pulse_voltage: float = 0.0,
    min_stimulus: float = 0.0,
    max_stimulus: float = 0.0,
    stimulus_step: float = 0.0,
) -> np.ndarray:
    """Build voltage clamp protocol arrays from explicit parameters.

    Args:
        protocol_type: One of "Step", "Ramp", "Pulse Train", or "Inactivation".
        sampling_frequency: Sampling frequency in Hz.
        pre_stimulus_duration: Duration before the stimulus in ms.  For the
            "Inactivation" protocol this is the conditioning prepulse duration.
        stimulus_duration: Duration of the stimulus in ms.  For the
            "Inactivation" protocol this is the fixed test-pulse duration.
        post_stimulus_duration: Duration after the stimulus in ms.
        holding_voltage: Holding voltage in mV.  Ignored by the "Inactivation"
            protocol, which uses each sweep's conditioning prepulse as the
            holding level.
        start_voltage: Ramp start voltage in mV.
        end_voltage: Ramp end voltage in mV.
        pulse_amplitude: Pulse amplitude in mV.
        pulse_width: Pulse width in ms.
        pulse_interval: Interval between pulse starts in ms.
        test_pulse_voltage: Fixed test-pulse voltage in mV for the
            "Inactivation" two-pulse protocol.  The swept ``min_stimulus`` /
            ``max_stimulus`` / ``stimulus_step`` range then specifies the
            conditioning prepulse voltage applied as each sweep's holding level.
        min_stimulus: Step voltage amplitude in mV for a single-step, or
            minimum voltage when running a multi-sweep range.  For the
            "Inactivation" protocol this is the most-hyperpolarized prepulse.
        max_stimulus: Maximum voltage for multi-sweep range in mV.  Must
            be >= min_stimulus.  For the "Inactivation" protocol this is the
            most-depolarized prepulse.
        stimulus_step: Step size for multi-sweep range in mV.  Use 0.0
            (or set min_stimulus == max_stimulus) for a single-step protocol.
            Must be > 0.0 for the "Inactivation" protocol, which is inherently
            multi-sweep.

    Returns:
        2-D array of shape ``(n_sweeps, n_samples)``.  Single-step protocols
        return shape ``(1, n_samples)``.  Multi-sweep Step protocols return one
        row per voltage level; the "Inactivation" protocol returns one row per
        conditioning prepulse voltage.

    Raises:
        ValueError: If protocol_type is unrecognized or parameters are invalid.
    """
    total_duration = pre_stimulus_duration + stimulus_duration + post_stimulus_duration
    sweeps: list[np.ndarray]
    if protocol_type == "Step":
        if stimulus_step < 0.0:
            raise ValueError("stimulus_step must be >= 0.0")
        if min_stimulus > max_stimulus:
            raise ValueError(
                f"min_stimulus ({min_stimulus}) must be"
                f" <= max_stimulus ({max_stimulus})"
            )
        if min_stimulus != max_stimulus and stimulus_step == 0.0:
            raise ValueError(
                "stimulus_step must be > 0.0 when min_stimulus != max_stimulus"
            )
        if min_stimulus == max_stimulus:
            sweeps = [
                step_voltage(
                    duration=total_duration,
                    voltage_amplitude=min_stimulus,
                    step_start=pre_stimulus_duration,
                    step_duration=stimulus_duration,
                    holding_voltage=holding_voltage,
                    sampling_frequency=sampling_frequency,
                )
            ]
        else:
            n_steps = round((max_stimulus - min_stimulus) / stimulus_step) + 1
            voltages = np.linspace(min_stimulus, max_stimulus, n_steps)
            sweeps = [
                step_voltage(
                    duration=total_duration,
                    voltage_amplitude=float(voltage),
                    step_start=pre_stimulus_duration,
                    step_duration=stimulus_duration,
                    holding_voltage=holding_voltage,
                    sampling_frequency=sampling_frequency,
                )
                for voltage in voltages
            ]
    elif protocol_type == "Ramp":
        sweeps = [
            ramp_voltage(
                duration=total_duration,
                start_voltage=start_voltage,
                end_voltage=end_voltage,
                ramp_start=pre_stimulus_duration,
                ramp_duration=stimulus_duration,
                holding_voltage=holding_voltage,
                sampling_frequency=sampling_frequency,
            )
        ]
    elif protocol_type == "Pulse Train":
        sweeps = [
            pulse_train_voltage(
                duration=total_duration,
                pulse_amplitude=pulse_amplitude,
                pulse_width=pulse_width,
                pulse_interval=pulse_interval,
                train_start=pre_stimulus_duration,
                holding_voltage=holding_voltage,
                sampling_frequency=sampling_frequency,
            )
        ]
    elif protocol_type == "Inactivation":
        # Two-pulse steady-state-inactivation protocol: each sweep holds at a
        # different conditioning prepulse voltage (the swept min/max/step range)
        # for the pre-stimulus duration, then steps to the fixed
        # test_pulse_voltage for the stimulus duration, then returns to the
        # prepulse level.  Built from ordinary step_voltage arrays so the
        # standard I-V analysis can extract the test-pulse peak current per
        # sweep over the [pre, pre + stimulus] window.  Unlike "Step", a
        # single sweep is rejected — there is no inactivation curve to measure.
        if stimulus_step < 0.0:
            raise ValueError("stimulus_step must be >= 0.0")
        if min_stimulus > max_stimulus:
            raise ValueError(
                f"min_stimulus ({min_stimulus}) must be"
                f" <= max_stimulus ({max_stimulus})"
            )
        if min_stimulus == max_stimulus:
            raise ValueError(
                "Inactivation protocol requires a conditioning prepulse range "
                "(min_stimulus must differ from max_stimulus)"
            )
        if stimulus_step == 0.0:
            raise ValueError(
                "stimulus_step must be > 0.0 for the Inactivation protocol"
            )
        n_steps = round((max_stimulus - min_stimulus) / stimulus_step) + 1
        prepulse_voltages = np.linspace(min_stimulus, max_stimulus, n_steps)
        sweeps = [
            step_voltage(
                duration=total_duration,
                voltage_amplitude=test_pulse_voltage,
                step_start=pre_stimulus_duration,
                step_duration=stimulus_duration,
                holding_voltage=float(prepulse),
                sampling_frequency=sampling_frequency,
            )
            for prepulse in prepulse_voltages
        ]
    else:
        raise ValueError(f"Unknown voltage protocol type: {protocol_type!r}")
    logger.debug(
        "build_voltage_protocol: type=%r total_duration=%.1f ms sweeps=%d",
        protocol_type,
        total_duration,
        len(sweeps),
    )
    return np.array(sweeps)

Current-clamp generators

neuroclamp.step_current

step_current(duration, current_amplitude, step_start=0.0, step_duration=None, sampling_frequency=SIM_SAMPLING_FREQ)

Generate a step current protocol.

Creates a current protocol with a rectangular step of specified amplitude and duration, useful for studying action potential threshold and firing patterns.

Parameters:

Name Type Description Default
duration float

Total duration of the protocol in milliseconds.

required
current_amplitude float

Amplitude of the current step in uA/cm^2.

required
step_start float

Time when the step begins in milliseconds. Default is 0.0.

0.0
step_duration float | None

Duration of the current step in milliseconds. If None, the step lasts for the entire duration.

None
sampling_frequency float

Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

SIM_SAMPLING_FREQ

Returns:

Type Description
ndarray

Array of current values in uA/cm^2.

Source code in neuroclamp/protocols/current.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def step_current(
    duration: float,
    current_amplitude: float,
    step_start: float = 0.0,
    step_duration: float | None = None,
    sampling_frequency: float = SIM_SAMPLING_FREQ,
) -> np.ndarray:
    """Generate a step current protocol.

    Creates a current protocol with a rectangular step of specified amplitude
    and duration, useful for studying action potential threshold and firing patterns.

    Args:
        duration: Total duration of the protocol in milliseconds.
        current_amplitude: Amplitude of the current step in uA/cm^2.
        step_start: Time when the step begins in milliseconds. Default is 0.0.
        step_duration: Duration of the current step in milliseconds.
            If None, the step lasts for the entire duration.
        sampling_frequency: Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

    Returns:
        Array of current values in uA/cm^2.
    """
    return _generate_step_protocol(
        duration,
        current_amplitude,
        baseline=0.0,
        step_start=step_start,
        step_duration=step_duration,
        sampling_frequency=sampling_frequency,
    )

neuroclamp.ramp_current

ramp_current(duration, start_current, end_current, ramp_start=0.0, ramp_duration=None, sampling_frequency=SIM_SAMPLING_FREQ)

Generate a ramp current protocol.

Creates a current protocol with a linear ramp from start to end current, useful for studying firing frequency adaptation and rheobase determination.

Parameters:

Name Type Description Default
duration float

Total duration of the protocol in milliseconds.

required
start_current float

Starting current amplitude in uA/cm^2.

required
end_current float

Ending current amplitude in uA/cm^2.

required
ramp_start float

Time when the ramp begins in milliseconds. Default is 0.0.

0.0
ramp_duration float | None

Duration of the ramp in milliseconds. If None, the ramp lasts for the entire duration.

None
sampling_frequency float

Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

SIM_SAMPLING_FREQ

Returns:

Type Description
ndarray

Array of current values in uA/cm^2.

Source code in neuroclamp/protocols/current.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def ramp_current(
    duration: float,
    start_current: float,
    end_current: float,
    ramp_start: float = 0.0,
    ramp_duration: float | None = None,
    sampling_frequency: float = SIM_SAMPLING_FREQ,
) -> np.ndarray:
    """Generate a ramp current protocol.

    Creates a current protocol with a linear ramp from start to end current,
    useful for studying firing frequency adaptation and rheobase determination.

    Args:
        duration: Total duration of the protocol in milliseconds.
        start_current: Starting current amplitude in uA/cm^2.
        end_current: Ending current amplitude in uA/cm^2.
        ramp_start: Time when the ramp begins in milliseconds. Default is 0.0.
        ramp_duration: Duration of the ramp in milliseconds.
            If None, the ramp lasts for the entire duration.
        sampling_frequency: Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

    Returns:
        Array of current values in uA/cm^2.
    """
    return _generate_ramp_protocol(
        duration,
        start_current,
        end_current,
        baseline=start_current,
        ramp_start=ramp_start,
        ramp_duration=ramp_duration,
        sampling_frequency=sampling_frequency,
    )

neuroclamp.pulse_train

pulse_train(duration, pulse_amplitude, pulse_width, pulse_interval, train_start=0.0, num_pulses=None, sampling_frequency=SIM_SAMPLING_FREQ)

Generate a pulse train current protocol.

Creates a series of rectangular current pulses with specified amplitude, width, and interval, useful for studying synaptic integration and temporal summation.

Parameters:

Name Type Description Default
duration float

Total duration of the protocol in milliseconds.

required
pulse_amplitude float

Amplitude of each pulse in uA/cm^2.

required
pulse_width float

Width of each pulse in milliseconds.

required
pulse_interval float

Time between pulse onsets in milliseconds.

required
train_start float

Time when the pulse train begins in milliseconds. Default is 0.0.

0.0
num_pulses int | None

Number of pulses in the train. If None, pulses continue until the end of the duration.

None
sampling_frequency float

Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

SIM_SAMPLING_FREQ

Returns:

Type Description
ndarray

Array of current values in uA/cm^2.

Source code in neuroclamp/protocols/current.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def pulse_train(
    duration: float,
    pulse_amplitude: float,
    pulse_width: float,
    pulse_interval: float,
    train_start: float = 0.0,
    num_pulses: int | None = None,
    sampling_frequency: float = SIM_SAMPLING_FREQ,
) -> np.ndarray:
    """Generate a pulse train current protocol.

    Creates a series of rectangular current pulses with specified amplitude,
    width, and interval, useful for studying synaptic integration and
    temporal summation.

    Args:
        duration: Total duration of the protocol in milliseconds.
        pulse_amplitude: Amplitude of each pulse in uA/cm^2.
        pulse_width: Width of each pulse in milliseconds.
        pulse_interval: Time between pulse onsets in milliseconds.
        train_start: Time when the pulse train begins in milliseconds.
            Default is 0.0.
        num_pulses: Number of pulses in the train. If None, pulses
            continue until the end of the duration.
        sampling_frequency: Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

    Returns:
        Array of current values in uA/cm^2.
    """
    return _generate_pulse_train_protocol(
        duration,
        pulse_amplitude,
        pulse_width,
        pulse_interval,
        baseline=0.0,
        train_start=train_start,
        num_pulses=num_pulses,
        sampling_frequency=sampling_frequency,
    )

neuroclamp.sinusoidal_current

sinusoidal_current(duration, dc_offset, amplitude, frequency, phase=0.0, stimulus_start=0.0, stimulus_duration=0.0, sampling_frequency=SIM_SAMPLING_FREQ)

Generate a sinusoidal current protocol.

Creates a sinusoidal current waveform with specified DC offset, amplitude, and frequency, useful for studying frequency response and impedance.

The waveform starts at stimulus_start and lasts for stimulus_duration. The pre- and post-stimulus periods are filled with 0 current. When both stimulus_start and stimulus_duration are 0.0, the waveform fills the entire duration.

Parameters:

Name Type Description Default
duration float

Total duration of the protocol in milliseconds.

required
dc_offset float

DC offset current in uA/cm^2.

required
amplitude float

Amplitude of the sinusoidal component in uA/cm^2.

required
frequency float

Frequency of the sinusoid in Hz.

required
phase float

Phase offset in radians. Default is 0.0.

0.0
stimulus_start float

Time when the waveform begins in milliseconds. Default is 0.0.

0.0
stimulus_duration float

Duration of the sinusoidal stimulus in milliseconds. Default is 0.0, which fills the recording from stimulus_start to the end of duration.

0.0
sampling_frequency float

Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

SIM_SAMPLING_FREQ

Returns:

Type Description
ndarray

Array of current values in uA/cm^2.

Source code in neuroclamp/protocols/current.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def sinusoidal_current(
    duration: float,
    dc_offset: float,
    amplitude: float,
    frequency: float,
    phase: float = 0.0,
    stimulus_start: float = 0.0,
    stimulus_duration: float = 0.0,
    sampling_frequency: float = SIM_SAMPLING_FREQ,
) -> np.ndarray:
    """Generate a sinusoidal current protocol.

    Creates a sinusoidal current waveform with specified DC offset, amplitude,
    and frequency, useful for studying frequency response and impedance.

    The waveform starts at `stimulus_start` and lasts for `stimulus_duration`.
    The pre- and post-stimulus periods are filled with 0 current. When both
    `stimulus_start` and `stimulus_duration` are 0.0, the waveform fills the
    entire `duration`.

    Args:
        duration: Total duration of the protocol in milliseconds.
        dc_offset: DC offset current in uA/cm^2.
        amplitude: Amplitude of the sinusoidal component in uA/cm^2.
        frequency: Frequency of the sinusoid in Hz.
        phase: Phase offset in radians. Default is 0.0.
        stimulus_start: Time when the waveform begins in milliseconds.
            Default is 0.0.
        stimulus_duration: Duration of the sinusoidal stimulus in milliseconds.
            Default is 0.0, which fills the recording from stimulus_start to
            the end of duration.
        sampling_frequency: Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

    Returns:
        Array of current values in uA/cm^2.
    """
    if stimulus_duration == 0.0:
        stimulus_duration = duration - stimulus_start

    num_points, time_array = _calculate_time_parameters(duration, sampling_frequency)
    current_array = np.zeros(num_points)

    stim_mask = _apply_time_window(time_array, stimulus_start, stimulus_duration)
    stim_times_seconds = (time_array[stim_mask] - stimulus_start) / 1000.0
    current_array[stim_mask] = dc_offset + amplitude * np.sin(
        2 * np.pi * frequency * stim_times_seconds + phase
    )

    return current_array

neuroclamp.chirp_current

chirp_current(duration, dc_offset, amplitude, start_frequency, end_frequency, stimulus_start=0.0, stimulus_duration=0.0, sampling_frequency=SIM_SAMPLING_FREQ)

Generate a chirp (frequency sweep) current protocol.

Creates a sinusoidal current with linearly increasing frequency, useful for measuring frequency response characteristics.

The waveform starts at stimulus_start and lasts for stimulus_duration. The pre- and post-stimulus periods are filled with 0 current. The frequency sweep spans start_frequency to end_frequency over stimulus_duration. When both stimulus_start and stimulus_duration are 0.0, the waveform fills the entire duration.

Parameters:

Name Type Description Default
duration float

Total duration of the protocol in milliseconds.

required
dc_offset float

DC offset current in uA/cm^2.

required
amplitude float

Amplitude of the chirp in uA/cm^2.

required
start_frequency float

Starting frequency in Hz.

required
end_frequency float

Ending frequency in Hz.

required
stimulus_start float

Time when the waveform begins in milliseconds. Default is 0.0.

0.0
stimulus_duration float

Duration of the chirp stimulus in milliseconds. Default is 0.0, which fills the recording from stimulus_start to the end of duration.

0.0
sampling_frequency float

Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

SIM_SAMPLING_FREQ

Returns:

Type Description
ndarray

Array of current values in uA/cm^2.

Source code in neuroclamp/protocols/current.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def chirp_current(
    duration: float,
    dc_offset: float,
    amplitude: float,
    start_frequency: float,
    end_frequency: float,
    stimulus_start: float = 0.0,
    stimulus_duration: float = 0.0,
    sampling_frequency: float = SIM_SAMPLING_FREQ,
) -> np.ndarray:
    """Generate a chirp (frequency sweep) current protocol.

    Creates a sinusoidal current with linearly increasing frequency,
    useful for measuring frequency response characteristics.

    The waveform starts at `stimulus_start` and lasts for `stimulus_duration`.
    The pre- and post-stimulus periods are filled with 0 current. The frequency
    sweep spans `start_frequency` to `end_frequency` over `stimulus_duration`.
    When both `stimulus_start` and `stimulus_duration` are 0.0, the waveform
    fills the entire `duration`.

    Args:
        duration: Total duration of the protocol in milliseconds.
        dc_offset: DC offset current in uA/cm^2.
        amplitude: Amplitude of the chirp in uA/cm^2.
        start_frequency: Starting frequency in Hz.
        end_frequency: Ending frequency in Hz.
        stimulus_start: Time when the waveform begins in milliseconds.
            Default is 0.0.
        stimulus_duration: Duration of the chirp stimulus in milliseconds.
            Default is 0.0, which fills the recording from stimulus_start to
            the end of duration.
        sampling_frequency: Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

    Returns:
        Array of current values in uA/cm^2.
    """
    if stimulus_duration == 0.0:
        stimulus_duration = duration - stimulus_start

    num_points, time_array = _calculate_time_parameters(duration, sampling_frequency)
    current_array = np.zeros(num_points)

    stim_mask = _apply_time_window(time_array, stimulus_start, stimulus_duration)
    stim_times_seconds = (time_array[stim_mask] - stimulus_start) / 1000.0
    stim_duration_seconds = stimulus_duration / 1000.0

    # phi=-90 converts scipy's cosine chirp to a sine chirp (sin = cos(x - 90°))
    current_array[stim_mask] = dc_offset + amplitude * chirp(
        stim_times_seconds,
        f0=start_frequency,
        t1=stim_duration_seconds,
        f1=end_frequency,
        method="linear",
        phi=-90,
    )

    return current_array

neuroclamp.noise_current

noise_current(duration, mean_current, std_current, stimulus_start=0.0, stimulus_duration=0.0, sampling_frequency=SIM_SAMPLING_FREQ, seed=None)

Generate a Gaussian white noise current protocol.

Creates a current protocol with Gaussian-distributed random values, useful for studying stochastic resonance and noise effects.

The noise starts at stimulus_start and lasts for stimulus_duration. The pre- and post-stimulus periods are filled with 0 current. When both stimulus_start and stimulus_duration are 0.0, the noise fills the entire duration.

Parameters:

Name Type Description Default
duration float

Total duration of the protocol in milliseconds.

required
mean_current float

Mean current value in uA/cm^2.

required
std_current float

Standard deviation of current in uA/cm^2.

required
stimulus_start float

Time when the noise begins in milliseconds. Default is 0.0.

0.0
stimulus_duration float

Duration of the noise stimulus in milliseconds. Default is 0.0, which fills the recording from stimulus_start to the end of duration.

0.0
sampling_frequency float

Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

SIM_SAMPLING_FREQ
seed int | None

Random seed for reproducibility. If None, uses random seed.

None

Returns:

Type Description
ndarray

Array of current values in uA/cm^2.

Source code in neuroclamp/protocols/current.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
def noise_current(
    duration: float,
    mean_current: float,
    std_current: float,
    stimulus_start: float = 0.0,
    stimulus_duration: float = 0.0,
    sampling_frequency: float = SIM_SAMPLING_FREQ,
    seed: int | None = None,
) -> np.ndarray:
    """Generate a Gaussian white noise current protocol.

    Creates a current protocol with Gaussian-distributed random values,
    useful for studying stochastic resonance and noise effects.

    The noise starts at `stimulus_start` and lasts for `stimulus_duration`.
    The pre- and post-stimulus periods are filled with 0 current. When both
    `stimulus_start` and `stimulus_duration` are 0.0, the noise fills the
    entire `duration`.

    Args:
        duration: Total duration of the protocol in milliseconds.
        mean_current: Mean current value in uA/cm^2.
        std_current: Standard deviation of current in uA/cm^2.
        stimulus_start: Time when the noise begins in milliseconds.
            Default is 0.0.
        stimulus_duration: Duration of the noise stimulus in milliseconds.
            Default is 0.0, which fills the recording from stimulus_start to
            the end of duration.
        sampling_frequency: Sampling frequency in Hz; default SIM_SAMPLING_FREQ.
        seed: Random seed for reproducibility. If None, uses random seed.

    Returns:
        Array of current values in uA/cm^2.
    """
    if stimulus_duration == 0.0:
        stimulus_duration = duration - stimulus_start

    # Create a local RNG instance to avoid mutating global state
    rng = np.random.default_rng(seed)

    num_points, time_array = _calculate_time_parameters(duration, sampling_frequency)
    current_array = np.zeros(num_points)

    stim_mask = _apply_time_window(time_array, stimulus_start, stimulus_duration)
    n_stim_points = int(np.sum(stim_mask))
    current_array[stim_mask] = rng.normal(mean_current, std_current, n_stim_points)

    return current_array

Voltage-clamp generators

neuroclamp.step_voltage

step_voltage(duration, voltage_amplitude, step_start=0.0, step_duration=None, holding_voltage=-70.0, sampling_frequency=SIM_SAMPLING_FREQ)

Generate a step voltage protocol for voltage clamp experiments.

Creates a voltage protocol with a rectangular step of specified amplitude and duration, useful for studying ionic currents and gating kinetics.

Parameters:

Name Type Description Default
duration float

Total duration of the protocol in milliseconds.

required
voltage_amplitude float

Amplitude of the voltage step in mV.

required
step_start float

Time when the step begins in milliseconds. Default is 0.0.

0.0
step_duration float | None

Duration of the voltage step in milliseconds. If None, the step lasts for the entire duration.

None
holding_voltage float

Holding voltage in mV. Default is -70.0 mV.

-70.0
sampling_frequency float

Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

SIM_SAMPLING_FREQ

Returns:

Type Description
ndarray

Array of voltage values in mV.

Source code in neuroclamp/protocols/voltage.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def step_voltage(
    duration: float,
    voltage_amplitude: float,
    step_start: float = 0.0,
    step_duration: float | None = None,
    holding_voltage: float = -70.0,
    sampling_frequency: float = SIM_SAMPLING_FREQ,
) -> np.ndarray:
    """Generate a step voltage protocol for voltage clamp experiments.

    Creates a voltage protocol with a rectangular step of specified amplitude
    and duration, useful for studying ionic currents and gating kinetics.

    Args:
        duration: Total duration of the protocol in milliseconds.
        voltage_amplitude: Amplitude of the voltage step in mV.
        step_start: Time when the step begins in milliseconds. Default is 0.0.
        step_duration: Duration of the voltage step in milliseconds.
            If None, the step lasts for the entire duration.
        holding_voltage: Holding voltage in mV. Default is -70.0 mV.
        sampling_frequency: Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

    Returns:
        Array of voltage values in mV.
    """
    return _generate_step_protocol(
        duration,
        voltage_amplitude,
        baseline=holding_voltage,
        step_start=step_start,
        step_duration=step_duration,
        sampling_frequency=sampling_frequency,
    )

neuroclamp.ramp_voltage

ramp_voltage(duration, start_voltage, end_voltage, ramp_start=0.0, ramp_duration=None, holding_voltage=-70.0, sampling_frequency=SIM_SAMPLING_FREQ)

Generate a ramp voltage protocol for voltage clamp experiments.

Creates a voltage protocol with a linear ramp from start to end voltage, useful for studying voltage-dependent activation and I-V relationships.

Parameters:

Name Type Description Default
duration float

Total duration of the protocol in milliseconds.

required
start_voltage float

Starting voltage in mV.

required
end_voltage float

Ending voltage in mV.

required
ramp_start float

Time when the ramp begins in milliseconds. Default is 0.0.

0.0
ramp_duration float | None

Duration of the ramp in milliseconds. If None, the ramp lasts for the entire duration.

None
holding_voltage float

Holding voltage in mV. Default is -70.0 mV.

-70.0
sampling_frequency float

Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

SIM_SAMPLING_FREQ

Returns:

Type Description
ndarray

Array of voltage values in mV.

Source code in neuroclamp/protocols/voltage.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def ramp_voltage(
    duration: float,
    start_voltage: float,
    end_voltage: float,
    ramp_start: float = 0.0,
    ramp_duration: float | None = None,
    holding_voltage: float = -70.0,
    sampling_frequency: float = SIM_SAMPLING_FREQ,
) -> np.ndarray:
    """Generate a ramp voltage protocol for voltage clamp experiments.

    Creates a voltage protocol with a linear ramp from start to end voltage,
    useful for studying voltage-dependent activation and I-V relationships.

    Args:
        duration: Total duration of the protocol in milliseconds.
        start_voltage: Starting voltage in mV.
        end_voltage: Ending voltage in mV.
        ramp_start: Time when the ramp begins in milliseconds. Default is 0.0.
        ramp_duration: Duration of the ramp in milliseconds.
            If None, the ramp lasts for the entire duration.
        holding_voltage: Holding voltage in mV. Default is -70.0 mV.
        sampling_frequency: Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

    Returns:
        Array of voltage values in mV.
    """
    return _generate_ramp_protocol(
        duration,
        start_voltage,
        end_voltage,
        baseline=holding_voltage,
        ramp_start=ramp_start,
        ramp_duration=ramp_duration,
        sampling_frequency=sampling_frequency,
    )

neuroclamp.pulse_train_voltage

pulse_train_voltage(duration, pulse_amplitude, pulse_width, pulse_interval, train_start=0.0, num_pulses=None, holding_voltage=-70.0, sampling_frequency=SIM_SAMPLING_FREQ)

Generate a pulse train voltage protocol for voltage clamp experiments.

Creates a series of rectangular voltage pulses with specified amplitude, width, and interval, useful for studying synaptic currents and channel inactivation.

Parameters:

Name Type Description Default
duration float

Total duration of the protocol in milliseconds.

required
pulse_amplitude float

Amplitude of each pulse in mV.

required
pulse_width float

Width of each pulse in milliseconds.

required
pulse_interval float

Time between pulse onsets in milliseconds.

required
train_start float

Time when the pulse train begins in milliseconds. Default is 0.0.

0.0
num_pulses int | None

Number of pulses in the train. If None, pulses continue until the end of the duration.

None
holding_voltage float

Holding voltage in mV. Default is -70.0 mV.

-70.0
sampling_frequency float

Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

SIM_SAMPLING_FREQ

Returns:

Type Description
ndarray

Array of voltage values in mV.

Source code in neuroclamp/protocols/voltage.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def pulse_train_voltage(
    duration: float,
    pulse_amplitude: float,
    pulse_width: float,
    pulse_interval: float,
    train_start: float = 0.0,
    num_pulses: int | None = None,
    holding_voltage: float = -70.0,
    sampling_frequency: float = SIM_SAMPLING_FREQ,
) -> np.ndarray:
    """Generate a pulse train voltage protocol for voltage clamp experiments.

    Creates a series of rectangular voltage pulses with specified amplitude,
    width, and interval, useful for studying synaptic currents and
    channel inactivation.

    Args:
        duration: Total duration of the protocol in milliseconds.
        pulse_amplitude: Amplitude of each pulse in mV.
        pulse_width: Width of each pulse in milliseconds.
        pulse_interval: Time between pulse onsets in milliseconds.
        train_start: Time when the pulse train begins in milliseconds.
            Default is 0.0.
        num_pulses: Number of pulses in the train. If None, pulses
            continue until the end of the duration.
        holding_voltage: Holding voltage in mV. Default is -70.0 mV.
        sampling_frequency: Sampling frequency in Hz; default SIM_SAMPLING_FREQ.

    Returns:
        Array of voltage values in mV.
    """
    return _generate_pulse_train_protocol(
        duration,
        pulse_amplitude,
        pulse_width,
        pulse_interval,
        baseline=holding_voltage,
        train_start=train_start,
        num_pulses=num_pulses,
        sampling_frequency=sampling_frequency,
    )