1 Introduction

Epilepsy is a neurological disorder characterized by abnormal excitation or synchronization of brain neurons [7]. The unpredictable nature of these seizures often results in physical harm and impacts patients’ daily lives significantly [12]. Despite efforts to develop new drug therapies, approximately 30% of patients still suffer from drug-resistant epilepsy [23], in which antiepileptic drugs fail to effectively control seizures, and patients with drug treatments also suffer from certain side effects [39]. Surgical resection is a common treatment option, however, it presents challenges in cases where the epileptogenic area coincides with functional brain regions or when multiple epileptogenic zones are present [13].

In recent years, several neuromodulation techniques have been developed to control seizures, including deep brain stimulation (DBS), optogenetic stimulation, and vagus nerve stimulation [10, 11, 38]. By incorporating modeling and theoretical analysis, numerous studies have elucidated the modulation mechanisms underlying various stimulation strategies, providing a theoretical basis for the development of effective treatment strategies [15, 36, 41, 42]. During seizures, neurons may be hyperactivated due to abnormalities in the neural circuits, which constitute the core of the dynamics changes [9]. Typically, this abnormal activity is initiated within a specific epileptogenic zone, potentially extending to adjacent brain areas or even broader regions of the brain [30, 46]. Therefore, the objective of the external stimulation strategy is to inhibit these overactive neural circuits and prevent the spread of abnormal discharges, thereby effectively controlling seizures.

Transcranial electrical stimulation (tES), a non-invasive neuromodulation method, employs low-intensity electrical currents, applied via anodic and cathodic electrodes on the scalp, to generate a weak electric field that modulates cortical excitability and activity [3]. Transcranial direct current stimulation (tDCS) and transcranial alternating current stimulation (tACS) are the two most common types of tES, utilize constant and sinusoidal current waveforms, respectively. Typically, anodic stimulation enhances the excitability of the target area, whereas cathodic stimulation tends to exert an inhibitory effect [26, 28]. It is due to this polarity effect that cathodal tES has been shown to be feasible, safe and effective in the treatment of patients with epilepsy [1, 45]. The adoption of computational modeling techniques further facilitates the exploration of more potent tES stimulation strategies. Several investigations have performed tES modeling at microscopic or macroscopic scales. At the microscopic level, tES is often modeled as a current perturbation to the neuron, where the effective membrane potential deflection is determined by the direction of the electric field vector relative to the somato-dendritic axis of the neuron [24]. At the macroscopic level, the current modeling analysis for tES can be performed as a combination of two steps. The first step is to calculate the spatial distribution of the induced electric field generated by tES, which is implemented using a finite element model of the current [16, 32]. The second step is to combine the electric field distribution generated by tES with the brain node dynamics model to construct the brain dynamics model under tES regulation [22, 25, 47].

The above modeling focuses on the immediate effects of tES. However, short-term stimulation has been demonstrated to elicit cortical plastic changes, sustaining the inhibitory effect on seizures for a period post-stimulation [6, 29]. Studies have shown that the duration and strength of the stimulus aftereffect depends on the intensity and duration of the stimulus [27]. Additional mechanisms may play a role in this process, including the dynamic regulation of synaptic efficacy and the induction of neurotransmitter release [17, 37]. For example, using magnetic resonance spectroscopy, Stagg et al. found that excitatory (anodic) tES resulted in a decrease in local GABA, whereas inhibitory (cathodic) stimulation resulted in diminished glutamatergic neuronal activity. They also interpreted the decrease in glutamate after cathodic stimulation as a result of a reduced rate of glutamine synthesis from glutamine and a reduction in excitatory neuronal transmission [37]. Therefore, it is reasonable to explore the lasting effects of tES from a synaptic level perspective.

While various modulation techniques have provided effective methods for the treatment of epilepsy, the abnormal discharge patterns characteristic of epilepsy are intermittent. Therefore, closed-loop neuromodulation presents a more promising avenue for epilepsy treatment, as it has the potential to reduce the time spent on clinical stimulation parameter settings and may result in robust and effective modulation effects [8, 48]. It involves continuous monitoring through implanted electrodes located in the seizure or ictal zone, and once an abnormal pattern is detected, a stimulation signal is sent to terminate the seizure. This on-demand stimulation results in fewer stimulation instances, thereby extending battery life for some invasive devices [14, 33]. Meanwhile, the closed-loop design of non-invasive modulation techniques has also garnered attention. For example, Berényi et al. demonstrated that epilepsy-triggered feedback transcranial electrical stimulation significantly reduced seizures in a rodent model of generalized epilepsy [2]. Furthermore, Kozák et al. mentioned that on-demand tES significantly reduced seizure duration and individual seizure duration, although they observed higher seizure rates during the treatment period [20]. However, there have also been some failures in electrical stimulation attempts, possibly due to a lack of temporal selectivity or inappropriate selection of epileptic stimulation targets [20]. Moreover, patient specificity is an important factor that should not be ignored. Differences in the epileptogenic zones of patients can lead to different propagation of epileptic networks and further affect the effectiveness of the stimulation.

The aim of this study is to establish a temporal lobe epilepsy brain model under tES, incorporating a phenomenological model of tES effects on synaptic variables, to analyze the the immediate and lasting inhibitory effects of this stimulus on epileptic seizures. Furthermore, we propose an amplitude-modulated closed-loop tES strategy, utilizing simulated EEG signals as a feedback mechanism in the loop. Each detected epileptiform discharge triggers a continuous current stimulation lasting for a duration of \(\tau \) seconds. We explore potential factors that influence the immediate and lasting treatment effects of closed-loop tES. This study demonstrate the potential efficacy of closed-loop tES in controlling the propagation of seizures and discuss the impact of the stimulus duration window, feedback signal, and neurotransmitter decay rate on the effectiveness of the stimulus. Additionally, the robustness of closed-loop tES in relation to the specificity of epileptogenic and propagating zones is examined, incorporating specificity data from different patients. These findings offer theoretical support for the application of non-invasive stimulation techniques in the treatment of neurological disorders.

Fig. 1
figure 1

(Color online)Whole brain network model of epilepsy and closed-loop tES procedure diagram. (a) Whole brain network model of epileptic brain. The model consists of 74 nodes, each of which is simulated using the Jansen-Rit model and includes pyramidal neuron population (PY), excitatory interneuron population (EIN), and inhibitory interneuron population (IIN). Nodes are connected based on the weights matrix and tract lengths matrix. The epileptogenic zone (EZ) and initial propagation zone (PZ) in the brain are inscribed by adjusting the excitatory synaptic increment. (b) Distribution of tES voltage and electric field strength simulated based on ROAST open-source software. Based on the coordinates of different nodes, the corresponding stimulus strength is determined. Simulated EEG signals are obtained by calculating the brain node oscillations in the model and designing a closed-loop tES stimulation strategy based on EEG amplitudes

2 Models and methods

2.1 The whole-brain epilepsy network model

A whole brain network model consisting of 74 brain region nodes is constructed [35], and the numbers, abbreviations, and full names of the different regions are displayed in [47]. The model utilizes the Jansen-Rit model to characterize the behavior of each node, including the excitatory pyramidal population, excitatory interneuron population, and inhibitory interneuron population [18]. Each neural population is modeled by two blocks. The first block represents the postsynaptic potential (PSP) dynamics. The second block converts the average membrane potential of the neuron population into average pulse density. The connections within each node are shown in Fig. 1. The connection strength \(w_{ij}\) between nodes is categorized into four levels of strength: 0, 1, 2, and 3, representing no connection, weak connection, medium connection, and strong connection, respectively. The connectivity matrix used in the model is derived from the CoCoMac database and corresponds to the large-scale connectivity of different brain regions in the healthy primate brain [19, 34] (Fig. 1). Additionally, the model takes into account the synaptic delay between nodes, which is determined by the tract lengths matrix divided by the transmission velocity [35]. Specifically, the dynamical behavior of the node i is denoted as:

$$\begin{aligned} \dot{x}_{i,1}&=x_{i,4} \end{aligned}$$
(1)
$$\begin{aligned} \dot{x}_{i,4}&=Aa[S(x_{i,2}-x_{i,3}+U_{\textrm{tES}})]-2ax_{i,4}-a^2x_{i,1} \end{aligned}$$
(2)
$$\begin{aligned} \dot{x}_{i,2}&=x_{i,5} \end{aligned}$$
(3)
$$\begin{aligned} \dot{x}_{i,5}&=Aa[I+C_2S(C_1x_{i,1})+K\sum _{j=1}^Nw_{ij}S(x_{i,2}-x_{i,3})]\nonumber \\&\quad -2ax_{i,5}-a^2x_{i,2}+\zeta \end{aligned}$$
(4)
$$\begin{aligned} \dot{x}_{i,3}&=x_{i,6} \end{aligned}$$
(5)
$$\begin{aligned} \dot{x}_{i,6}&=Bb[C_4S(C_3x_{i,1})]-2bx_{i,6}-b^2x_{i,3}. \end{aligned}$$
(6)

The difference \(x_{i,2}-x_{i,3} \) is often used as the output of the node i to represent the net effect of excitatory and inhibitory inputs on the pyramidal cells, providing a balanced representation of neural activity [18, 44]. It is crucial for understanding various brain states, such as oscillatory behavior and its alteration in different cognitive or pathological conditions. Additionally, some studies have shown that this representation can better match macroscopic physiological, capture oscillations and phase phenomena in brain activity, making it more relevant to the actual output of neural populations [4, 5]. K is the global coupling scale factor of the brain model, and \(w_{ij}\) is the connection weight of the jth node to the ith node. \(U_{\textrm{tES}}\) is the scale factor of tES intensity, which depends on the electrode position of the tES and the region of the brain node.\(\zeta \) is the noise term. Based on the “\(\lambda \)E” model, the effect of tES-induced polarization is simulated as the perturbation voltage added to the mean membrane potential of pyramidal cells [22]. N=74 is the number of brain nodes. S(v) is the activation function that converts postsynaptic potentials to the average density of action potentials:

$$\begin{aligned} S(v)=2e_0/[1+\exp (r(v_0-v))]. \end{aligned}$$
(7)

\(A,B,a,b,C_1,C_2,C_3,C_4\) and the specific parameters of the activation function and their implications are shown in Table 1 [18]. Furthermore, we add Gaussian white noise to the excitatory loop and employ a fourth-order stochastic Runge–Kutta method to numerically solve the differential equations of the model [21].

The nodes are coupled by synapses to form a whole-brain network model. Further, to study seizures and their propagation, the model assumes the presence of epileptogenic zones (EZ) and initial propagation zones (PZ) associated with seizure initiation. To characterize different regions, previous studies have set the excitatory synaptic gain A to different values. Specifically, A is set to 3.6 in the EZ region, 3.4 in the PZ, and 3.25 in other nodes [46, 47]. By varying the EZ and PZ ranges in subsequent studies, the model is able to simulate different patient patterns of epileptic brain dynamics. This allows for a detailed analysis of how different EZ and PZ locations affect the performance of stimulation techniques.

Table 1 Parameter interpretation and values of the Jansen-rit model

2.2 Simulation of EEG signals

In this work, both the selection of electrode positions for cathode tES and the choice of closed-loop feedback indicators are referenced to the simulated EEG signal. As a non-invasive closed-loop stimulation method, the EEG signal is considered the optimal choice for the feedback indicators. Similar to our previous study, the 74 brain regions are projected onto 62 EEG electrodes through the specific propagation matrix. The propagation matrix is obtained by solving the boundary element method and is available in the TVB dataset [34, 35]. The specific names of the 62 EEG channels are given in [47].

2.3 Modeling the immediate effects of tES

ROAST open source software is used to calculate the voltage and electric field distributions in the brain area during tES stimulation [16]. The electrode shape is selected as “pad” with a size of [50 mm 30 mm 3 mm]. The default parameters in ROAST are used for the rest of the calculations. To determine the stimulus intensity for each brain region, the MNI coordinates of the brain regions are used to calculate the affine transformation matrix using the REST software package [31]. This matrix is then used to obtain the corresponding voxel coordinates (xyz) for each brain region. According to our previous definition [47], the voltage perturbation \(\gamma \) of the tES at the voxel coordinate (xyz) is defined as:

$$\begin{aligned} \gamma =E(x,y,z)\cdot \textrm{sign}(V(x,y,z)-V_{\textrm{med}}), \end{aligned}$$
(8)

where E is the magnitude of the electric field strength at (xyz) and V is the voltage. \(V_{\textrm{med}}=(V_{\textrm{max}}+V_\textrm{min})/2\) is the median voltage in voxel space. ROAST can only calculate the electric field intensity at each point but cannot distinguish the contributions from the cathode and anode. The function sign() is necessary to ensure which nodes received contributions from the cathode, which is essential for our model. We consider the voxel point (xyz) with a voltage greater than \(V_{\textrm{med}}\) as an anodic contribution (+1), and a voltage smaller than \(V_{\textrm{med}}\) as contributing cathodic polarity (−1) [47]. This approach effectively ensures the inhibitory effect of the cathodic electrode on brain regions. Finally, the specific voltage offset of each brain node is

$$\begin{aligned} U_{\textrm{tES}}={\hat{u}}_{\textrm{tES}}\cdot \gamma , \end{aligned}$$
(9)

where \({\hat{u}}_{\textrm{tES}}\) is the stimulus intensity of tES. In a subsequent study, we set the applied stimulus current to 1 mA and varied \({\hat{u}}_{\textrm{tES}}\) to indirectly reflect the effects of different stimulus intensities. Because the control for epilepsy is cathodic stimulation, we focus on exploring the inhibitory effect of different cathodic stimulation on epileptic propagation. By default, when the cathodic electrode is placed in the left hemisphere, the anodic electrode is placed in Ex8 (additional electrode position for ROAST, non-epileptic area). When the cathode electrode is placed in the right hemisphere, the anode electrode is placed in Ex7, and the exact position of these two electrodes is shown in Fig.  3d. Moreover, all simulations are performed using MATLAB and the duration of each simulation is set to 50 s for subsequent analysis.

2.4 Modeling the lasting effects of tES

In conjunction with previous studies of tES affecting glutamatergic neurotransmitter levels [37], the study explores the lasting effects of cathodal tES by modulating synaptic levels within excitatory loops in the Jansen-Rit model. According to Nitsche et al., the magnitude and duration of post-stimulation effects depend on the duration and intensity of the stimulation [27]. Specifically, the duration of effects increases with longer stimulation times and higher current intensities. Based on their experimental results, we propose a phenomenological model for changes in the level of excitatory synaptic channels:

$$\begin{aligned} & \frac{d^2Z}{dt^2}=a\cdot |u_{\textrm{tES}}(t,:)|-{a_1\frac{dZ}{dt}}-b_1\cdot Z(t) \end{aligned}$$
(10)
$$\begin{aligned} & a_1=8+\beta \cdot \left( \int |u_{\textrm{tES}}|dt\right) ^2, \end{aligned}$$
(11)

where \(a=10\) represents the effect factor of tES on synaptic decay rate Z. The term \(a_1\frac{dZ}{dt}-b_1\cdot Z(t)\) can be interpreted as the internal regulatory mechanism of the system, where \(a_1\) serves as the damping coefficient. In the absence of stimulation, \(a_1\) is set at 8. As the duration of the stimulus increases, \(a_1\) also increases gradually, thereby decelerating the rate of change in the system state. Overall, \(a_1\) is proportional to the square of the duration. \(\beta \) is called the synaptic decay coefficient and is analyzed in the subsequent focus. \(b_1\)=10 acts as the recovery factor of the system. Additionally, the effects on \( C_{1}\) and \(C_2\) are defined as:

$$\begin{aligned} & C_{1}=135\cdot (1+sig\cdot Z) \end{aligned}$$
(12)
$$\begin{aligned} & C_{2}=135\cdot (0.8+sig\cdot Z). \end{aligned}$$
(13)

Given the primary focus on the inhibitory impact of cathodal tES on epileptic seizures, anodic electrodes were positioned at Ex8 and Ex7, locations that have less effect on brain regions. Therefore, only the lasting effects induced by cathodal tES are considered. When the \(\gamma \) of a node is less than 0, sig is -1, representing the action of the cathode tES on the synapse. For remaining nodes, sig=0. As shown in Fig. 2, the cathodal tES mainly predominantly impacts the excitatory loop between PY and EIN. This influence results in a reduction in the average number of synapses within the excitatory feedback loop, thereby facilitating the realization of the lasting effect. The time series of the stimulus signal and Z(t) are given in Fig. 2c and d, respectively. It can be seen that as the stimulus time increases, Z(t) saturates and the duration of the post-stimulus influence extends (\(\beta \)=8). Similarly, an enhancement in stimulus intensity correlates with an increase in both the duration and intensity of the post-stimulus effect (Fig. 2e and f). Specifically, the magnitude of the post-stimulation effect on the node varies with the changes in stimulation intensity and stimulation duration, as shown in Fig. S1. Therefore, the model can qualitatively replicate the experimental observation that the duration of stimulation and intensity are positively correlated with the duration of the post-stimulation effects. A key parameter closely related to the post-stimulation effects is the synaptic delay coefficient \(\beta \), which can be considered an internal brain parameter and will be analyzed in subsequent sections.

Fig. 2
figure 2

(Color online) The lasting effects of tES are modeled by influencing the synaptic parameters of excitatory loops. (a) and (b) show the schematic diagrams of the stimulus and the node circuit. Red shading and blue shading represent anodic and cathodic stimuli, respectively. (c) and (d) show the trend of synaptic decay rate Z(t) for different stimulus durations. As the duration of stimulation increases, the time required for Z(t) to decay to zero also grows. (e) and (f) show the trend of synaptic decay rate Z(t) under varying stimulation intensities. It can be observed that both the duration of stimulation and the intensity of stimulation are positively correlated with the duration of the post-stimulation effect

Fig. 3
figure 3

(Color online) Time series and simulated EEG signals in a whole-brain model of epilepsy. (a) Time series of discharges in 74 brain region nodes during seizure state. The EZ regions are set to left HC (10), left PHC (25), and left AMYG (3)), and PZ regions are set to the left inferior temporal cortex (32) and temporal ventral cortex (35). (b) The typical abnormal oscillatory discharges (b1-b3), and the resting state (b4). (c) Simulated EEG signals of representative channels. (d) 62 EEG electrode distribution diagrams, along with the default anode position (Ex7 or Ex8)

3 Results

3.1 Immediate and lasting effects of tES on the suppression of seizure oscillation propagation

The amygdala (AMYG), hippocampus (HC), and parahippocampal gyrus (PHC) are closely related to epilepsy and are predicted to be the most likely sites of seizure onset [40]. Therefore, we first construct a typical epileptic brain model by setting the left HC (lHC), left PHC (lPHC), and left AMYG (lAMYG)) as the EZs, and the left inferior temporal cortex (lTCI) and temporal ventral cortex (lTCV) as the initial PZs [47]. With the passage of time, the abnormal discharges are evident in most of the left hemisphere and extend further to the right hemisphere, recruiting most of nodes to produce epileptic discharges (as shown in Fig. 3a). In general, high-amplitude oscillations usually indicate seizure dynamics, and low-amplitude irregular oscillations are considered as non-seizure states. The discharge patterns of different nodes are given in Fig. 3b which is a partially enlarged view of Fig. 3a. The dynamics of individual nodes of the brain in the background state are consistent with Fig. 3b4. In epileptic states, the nodal dynamics show limit cycles of different frequencies (Fig. 3b1–b3). Based on the method mentioned in Sect. 2.2, we further calculate the simulated EEG signals of the corresponding 62 electrode channels. The time-series of several representative channels are shown in Fig.  3c. It can be seen that the left channels, such as F3, P3, and CP5, exhibit obvious high-amplitude oscillatory behaviors.

Fig. 4
figure 4

(Color online) The inhibitory effect of tES stimulation on the propagation of epileptic oscillations. (a) Time series graphs of the left hemisphere nodes without considering the effect of stimulation on synaptic variables. tES stimulation is applied during the first 25 s. EZ:nodes 3,10,25. PZ: nodes 32 and 35. (b) Time series graphs of the left hemisphere nodes after incorporating the effects of tES on synaptic variables. (c) The spatial distribution of electric field strength under tES (cathode: CP5, anode: Ex8), and the distribution of voltage perturbation across 74 brain nodes. (d) The distribution of Z(t) in different nodes under cathodal tES stimulation. The left black horizontal lines indicate the stimulation intensity at different nodes. (e) The curves of Z(t) changes corresponding to nodes 3, 20, and 23

Fig. 5
figure 5

(Color online) Closed-loop tES stimulation with different feedback EEG signals. (a) Energy values for different channels are derived and normalized based on power spectral density analysis curves of EEG signals. Ten simulations are conducted, and the error bars indicate the standard deviation of energy value fluctuations. (b) and (c) show the immediate and lasting effects of closed-loop tES on oscillation propagation suppression under different feedback signals, respectively. (dg) are time series of left hemisphere nodes and feedback channels under closed-loop tES stimulation with different feedback signals. The blue shaded sections represent the phases of stimulation. EZ:nodes 3,10,25. PZ: nodes 32 and 35. The red line in the time series of the feedback signals represents the stimulation threshold, exceeding which turns on the stimulation.The red dashed line is t = 25 s and the closed-loop control is only on for the first 25 s

Consistent with our previous work, the energy of the different EEG signals is quantified using the integral of the power spectral density analysis curves of the EEG signals in the range of 0–50 Hz over a period of 50 s [47]. The spectral analysis is performed with the Chronux neural signal analysis software package. We divide all data points by the maximum value such that the maximum value is normalized to 1 and the other data points are proportionally mapped to the range between 0 and 1. The channel with the highest energy is considered to be the region with the strongest epileptic activity. Based on the current EZ and PZ settings, the electrode channel with the strongest epileptic activity is CP5 (as shown in Fig. 5a). Consequently, we position the cathode of the tES at CP5 and the anode at Ex8. Figure 4c shows the spatial distribution of the electric field strength in the brain model under the action of tES, as well as the perturbation distribution of 74 brain region nodes induced by tES. The parameter \(u_{\textrm{tES}}\) influences the effect of stimulation significantly. Based on previous work, we fix \(u_\textrm{tES}\)= 1.5 [47]. The total duration of the simulation is 50 s. The tES is applied during the initial 25 s, followed by an analysis period of the subsequent 25 s to evaluate the lasting effects of tES. Figure 4a presents the results of tES stimulation without considering synaptic influences. Under the suppressive effects of cathodic stimulation, abnormal oscillatory behaviors are confined to nodes 3, 10, 25, and 35, all of which are designated as the initial settings for the EZ and PZ. Upon the removal of tES, the areas exhibiting oscillatory activity gradually expand and propagate throughout the entire left hemisphere. Figure 4b shows the time series of different brain regions in the left hemisphere with tES stimulation considering synaptic influences. The impact of tES on variables \(C_1\) and \(C_2\) allows for the suppression of oscillatory activity to be maintained for a period following the cessation of stimulation. During the application of stimulation, tES induces alterations in synaptic variables. Figure 4d shows the changes of Z(t) of the left hemisphere. Due to the variation in stimulation intensity across different nodes, the trend of Z(t) shows inconsistency. As shown in Fig. 4e, node 3 is subjected to higher intensity stimulation, resulting in a longer duration of post-stimulation effects. However, since node 3 is an EZ node with an excitatory gain A = 3.6, greater changes in C1 and C2 are needed to suppress oscillations. As shown in Fig. 4d, in contrast, the Z(t) changes in node 10 are more pronounced, thus the oscillations in node 10 are suppressed within the last 25 s. In contrast, node 23 exhibits a shorter duration of post-stimulus influence. Therefore, considering the action of tES on synaptic variables could replicate its lasting effect, thereby achieving an inhibitory influence on the propagation of epileptic oscillation.

3.2 Amplitude-based closed-loop tES

Based on the above epilepsy brain dynamics model, the control effect of closed-loop tES is further explored. Figure 5a shows the normalized results of different EEG signal energies in 50 s. Ten simulations are performed so as to eliminate the effect of noise. Consistent with the study of open-loop tES [47], we select CP5 (the maximum energy channel) as the cathode electrode location and the anode is placed on Ex8 with 1 mA tES current strength applied. Since the tES is a non-invasive stimulus, it is reasonable to select the EEG signal as the feedback signal indicator. To investigate the impact of feedback signal selection on the stimulation effect, we chose 8 EEG channel signals with high energy as the feedback signals. It is assumed that significant epileptic oscillations are present when the EEG signal amplitude exceeded 5. Subsequently, tES stimulation lasting 5 s is automatically applied. In the background state, the signal amplitude of the EEG is usually around 2 (Fig. 3b). However, during the onset of a seizure, the amplitude gradually increases and may reach values in the tens range. Therefore, setting an amplitude threshold of 5 is reasonable to effectively detect the initial propagation of the oscillations.

Figure 5b and c show the number of seizure nodes during the first 25 s and the second 25 s, respectively, under closed-loop tES stimulation using different feedback signals. It can be seen that although the stimulation electrodes are consistent, different feedback signals result in variations in the stimulation effect. Notably, when CP5 and PO3 are utilized as feedback signals, closed-loop tES effectively suppresses abnormal oscillations in nodes other than EZ and PZ, and this suppression effect is sustained for the subsequent 25 s. Figure 5d presents a time series of the left hemisphere node when CP5 is used as a feedback signal. The discharge of CP5 is also given in the figure, with the red line representing the stimulation threshold. The stimulation is initiated when the amplitude exceeds 5. The dark blue color in the figure indicates the stimulation phase, with a stimulation ratio of approximately 40.13%. In contrast, when P1, P3, and AF3 are employed as feedback signals, closed-loop tES demonstrates satisfactory suppression during the first 25 s, however, the lasting suppression is not achieved. Figure 5e shows a time series of the left hemisphere node when AF3 is used as a feedback signal. The stimulus onset time is delayed, with only one stimulus occurring within the initial 25 s. This leads to minor changes in synaptic variables, which are insufficient to affect the subsequent stimulation effect. In addition, when using F3 as a feedback signal, the stimulus time is further delayed, resulting in the propagation of oscillations that are already present prior to the application of the stimulus (Fig. 5f). When O1 is utilized as a feedback signal, the substantial delay in stimulus timing allows oscillations to spread throughout the left hemisphere node long before the addition of a stimulus, making it ineffective in suppressing oscillations (Fig. 5g). Feedback signals primarily control the timing of stimulation initiation and duration. From the perspective of initiation timing, different stimulation effects are mainly due to the state of the nodes. If stimulation is introduced early in the phase, when the nodes have not yet entered or have just begun to enter the oscillatory cycle, external stimulation can effectively disrupt the system’s transition to an oscillatory state. Conversely, if stimulation is added late in the oscillatory cycle, the system may have already established a stable oscillatory pattern, with the system’s energy and state approaching a periodic equilibrium. At this point, external stimulation is often ineffective at altering the system’s state, unable to suppress an established oscillatory condition. Hence, it can be seen that the feedback signal determines the on-time of the stimulus and is crucial for the effect of stimulus inhibition.

Fig. 6
figure 6

(Color online) (a) Time series graphs of nodes 3, 10, and 17 under closed-loop tES with CP5 as the feedback signal. (b) The change curves of synaptic decay rate Z(t) under tES stimulation across different nodes. (c) The immediate and lasting suppression effects under open-loop and closed-loop tES conditions.The asterisk (*) represents the p-value of the statistical test. ** represents the p-value is less than 0.01. **** represents the p-value is less than 0.0001. (d) CP5, PO3 and P1 are selected as stimulation targets to compare the stimulation intensity received by nodes within the EZ and PZ. CP5 is found to have the highest stimulus intensity as a target. (e) The number of oscillating nodes in the initial 25 s and the subsequent 25 s under varying stimulation targets. (f) The curves depicting changes in Z(t) under different stimulation targets

Using CP5 as the feedback signal, we investigate the trend of synaptic variables at each node after applying the stimulus. As shown in Fig. 6a, epileptic oscillations in the EZ nodes (node 3 and node 10) are suppressed to different degrees after stimulation. In contrast, the oscillations at other nodes (e.g., node 17) are completely suppressed. The variation in synaptic variables at different nodes is attributable to the varying electric field strengths of the tES applied to each node. Figure 6b shows that Z(t) exhibits a significant increase and takes longer to recover to 0 after two stimuli when the node receives a higher-intensity stimulus. Conversely, nodes receiving lower-intensity stimulation alter synaptic variables for a relatively short period of time. It is evident that changes in synaptic variables at critical nodes (e.g., EZ and PZ) have a much greater impact on long-term stimulation results. To compare the effects of open-loop and closed-loop stimulations, we conduct an analysis involving ten closed-loop stimulation events, followed by administering open-loop tES with identical duration and intensity to ensure that the energy requirements for both approaches are matched. Figure 6c illustrates the immediate and lasting suppression effects under open-loop and closed-loop tES conditions. The immediate effects of seizure suppression are similar between the two stimulation, confining seizure oscillations within the EZ and PZ. However, there are marked differences in the lasting effects of stimulation. Closed-loop tES maintains a more sustained effect on suppression. Analyzing the Z(t) synaptic change curves for both stimulation types reveals that, compared to a period of continuous stimulation, a subsequent stimulation in the closed-loop causes slight variations in the Z(t) curve, thereby producing different sustained impacts.

To explore the optimal stimulation target, we compare three selected stimulation targets in the left region of the brain. When CP5 is used as the stimulus target (Fig. 6d), the nodes in the EZ and PZ regions receive the highest stimulus intensity. Therefore, different stimulation targets lead to varying biases in the stimulation voltages received by the brain nodes. As illustrated in Fig. 6f, although all intensities of stimulation had immediate beneficial effects, the different strengths influenced the rate of synaptic delay changes. We also present the curves depicting changes in Z(t) under different stimulation targets. The subsequent divergent outcomes primarily arise from the internal dynamics of the nodes. Specifically, for the EZ and PZ, the differences in node states are mainly due to the excitatory loops within the Jansen-rit model. For other nodes, such as node 7, the effects are driven by the network, as Z(t) rapidly approaches zero under different stimulation targets. Under the influence of network connectivity, other nodes are driven by epileptogenic nodes, resulting in oscillatory behavior.

Fig. 7
figure 7

(Color online) Effects of stimulus duration \(\tau \) and synaptic delay coefficient \(\beta \) on stimulus effects. (a) and (b) are the number of nodes with abnormal oscillations during the first 25 s and the last 25 s under the dual parameter influence of \(\tau \) and \(\beta \), respectively. (c) Stimulus duty cycle for different closed-loop tES parameters. (df) Trends in stimulus activation time and Z(t) changes for different parameter settings. Increasing the duration of stimulus activation slows the rate of decay of z(t), thereby enhancing the lasting effectiveness of the stimulation

In addition, we examine the impacts of the stimulus duration of each stimulus turn-on (\(\tau \)) and the synaptic decay rate (\(\beta \)) on the efficacy of stimulation. Figure 7a shows the immediate effects of closed-loop stimulation with different parameters, and it can be seen that the immediate effects are not affected by the stimulation parameters. In contrast, the lasting effect of closed-loop stimulation is significantly influenced by \(\tau \) and \(\beta \). As \(\tau \) and \(\beta \) increase, there is a gradual reduction in the number of nodes exhibiting oscillations in the subsequent 25 s, indicating an enhancement in the lasting efficacy of the stimulus. It is worth noting that as the stimulus duration \(\tau \) increases, the corresponding stimulus duty cycle also increases gradually. But even with \(\tau \) = 5, the stimulus duty cycle does not exceed 45%. Three parameter combinations are selected to illustrate the corresponding stimulus times and Z(t) changes. As shown in Figs. 7d–f, when \(\tau \) is set to 0.5 s, the stimulus is activated frequently. However, due to the short duration of each stimulus, the change of Z(t) is not obvious, which is the main reason for the insignificant lasting effect. As \(\tau \) and \(\beta \) increase, the stimulus duration gradually increases and the rate of Z(t) recovery gradually slows, thus enhancing the lasting effect of the stimulus. It is evident that while \(\tau \) and \(\beta \) do not influence the short-term effects of closed-loop tES, they significantly impact its lasting outcomes. Given that \(\beta \), as a synaptic variable, may be challenging to access in experiments, appropriately increasing the time \(\tau \) is a means of improving lasting effects.

Fig. 8
figure 8

(Color online) (a) Time series of different states of the system, S1 (0–10 s): the seizure state, S2 (10–35 s): the closed-loop stimulation state, S3 (35–60 s): the post-stimulation effective state, and S4 (60–80 s) represents the post-stimulation seizure state. (b) Phase plane of node 22 under the S1 + S2 window (black) and under the S2 window (orange). (c) Phase plane of node 22 in 35–65 s

To systematically analyze the mechanism of seizure termination under the action of tES, we simulate the discharge of the system over a period of 80 s (Fig. 8a), where S1 (0–10 s), S2 (10–35 s), S3 (35–60 s), and S4 (60–80 s) are the seizure state, the closed-loop stimulation state, the post-stimulation effective state, and the post-stimulation seizure state, respectively. It is generally accepted that seizures are described as a transition from a background state (fixed point) to a seizure state (limit cycle). And after adding the closed-loop tES, the system transitions to a new stable state (S2). At this time, most of the subsystems are in the stable fixed point state (as shown in Fig. 8b), and some EZ or PZ nodes remain in the limit cycle state. Therefore, within S2, the system undergoes a state transition from a seizure state to another stable state in response to an applied stimulus, a process similar to switching between attractors.

In contrast, when the closed-loop stimulus is switched off, the system returns to an oscillatory state after a period of time. From this perspective, we consider this transient change in state as a temporary behavior of the system under external perturbation or altered conditions. Over time, the system will eventually return to the seizure state (Fig. 8c). Therefore, S3 does not achieve a stable equilibrium state. The primary reason for this phenomenon may be due to the effect of tES on the excitatory loop of the system, which is induced by the transient dynamics of Z. Over time, the decrease in Z leads to a diminishing influence on the excitatory circuits, causing the system to revert to the oscillatory state. Consequently, the long-term effect of tES can be interpreted, to some extent, as a prolonged transient process.

3.3 Simulation of closed-loop tES effects on patient-specific epileptic networks

In the previous analysis, fixed EZs and PZs are set up. However, it is important to consider the individual variability in seizures for focal epilepsies such as temporal lobe epilepsy, as different patients may have different EZs and PZs. Therefore, it is essential to explore the effect of different EZs and PZs on the effectiveness of the stimulus. In this section, we concentrate on six patients with temporal lobe epilepsy, employing their stereo electroencephalography (SEEG) reports and clinical diagnoses to ascertain their specific EZs and PZs. Patient-specific information can be found in Table 2. We initially focus on patients 1-5, whose EZ and PZ are localized to one cerebral hemisphere. In patients 1 and 4, where the EZ and PZ are identified in the left hemisphere, CP5 is designated as the stimulation target, and the EEG signal from CP5 is utilized as the feedback signal. In contrast, for patients 2, 3, and 5, with the EZ and PZ positioned in the right hemisphere, CP6 is selected as the stimulation target, and the corresponding EEG signal is employed as the feedback indicator. In the supplementary material, we show the immediate and lasting effects of stimulation under different combinations of cathodic stimulation and feedback signals (Fig. S2 and Fig. S3). While the pattern of their immediate effects is traceable, their impact on lasting effects is not obvious. The selection of CP5 and CP6 as stimulation targets is primarily based on the fact that in these patients with temporal lobe epilepsy, most of the EZs and PZs are distributed in the HC, PHC, and AMYG regions. For all patients, CP5 and CP6 are not only higher-energy channels, but also act as stimulation targets with higher stimulation intensities for the EZ and PZ regions (Fig.  6d). The effects of different tES stimulations on seizure propagation inhibition are presented in Fig. 9. Here we focus on exploring the effects of stimulus duration and synaptic decay coefficient on the immediate and lasting effects of the stimulus. It is important to note that we consider tES suppression to be effective only if the remaining oscillatory nodes under stimulation are less than 10 (the dark area in Fig. 9).

Table 2 Clinical characteristics and epileptogenic information in six patients with temporal lobe epilepsy

Figure 9a–e the immediate impacts of closed-loop tES stimulation on the epileptic brain networks specific to patients 1–5, respectively. Similar to the results in the previous section, \(\tau \) and \(\beta \) have little effect on the immediate inhibitory effect of tES, and predominantly determine the lasting inhibitory effect of epileptic propagation (Fig. 9f–j). A notable variation in the duration of closed-loop tES stimulation necessary for the patient-specific epilepsy network model is observed. For patients 3 and 5, a smaller time window (e.g., \(\tau \) = 5) is sufficient to effectively inhibit epileptic propagation. Conversely, for Patients 1, 2, and 4, an extended \(\tau \) yielded an enhanced stimulation outcome. These results show that the selection of the time window for each trigger opening of closed-loop tES is also very important, and the selection of the appropriate stimulation window can facilitate improved stimulation results for distinct patients. On the other hand, the effect of tES remained consistent in various epilepsy network models. When both \(\tau \) and \(\beta \) satisfy specific conditions, tES effectively inhibits the propagation of abnormal oscillations in the epileptic network and sustains the suppression of such oscillations for a duration following the cessation of the stimulus.

Fig. 9
figure 9

(Color online) Effect of stimulation parameters \(\tau \) and \(\beta \) in closed-loop tES on the suppression of abnormal oscillations in different patient-specific epileptic network models. (ae). Immediate inhibitory effects of tES on specific epileptic brain networks from Patient 1 to Patient 5, respectively. (fg). Lasting effects of tES on specific epileptic brain networks from Patient 1 to Patient 5, respectively

Fig. 10
figure 10

(Color online) (a) and (b) show the effects of single-target stimulation with stimulation targets CP6 and CP5, respectively.Here, \(\tau \)=8, \(\beta \)=15. The closed-loop tES with a single target does not suppress the abnormal oscillations within the whole network well. (c) and (d) are the immediate and lasting effects of dual-target closed-loop tES with stimulus targets of CP5 and CP6 and feedback signal of CP6. Satisfactory lasting effects can be achieved with appropriate \(\tau \) and \(\beta \). (e) and (f) are the electric field strength distributions of the brain under single-cathode tES and dual-cathode tES, respectively

Finally, we consider patient 6, whose PZ distribution is notably widespread, encompassing both hemispheres. Previous studies have shown that patient 6 has highest energy in both the CP5 and CP6 channels of the EEG, but neither the tES of CP5 nor CP6 suppresses the propagation of epileptic oscillations well. Figure 10a and b correspond to closed-loop tES with stimulation and feedback signals targeting CP6 and CP5, respectively. Here, we choose \(\tau \)=8, \(\beta \)=15. Upon incorporating the impact of tES on synapses, it is observed that closed-loop tES still failed to effectively suppress the propagation of epileptic oscillations. In the previous study, we considered dual-target tES stimulation, which effectively suppressed seizure propagation while ensuring constant current intensity [47]. Similarly, here, we design a closed-loop tES with dual cathodes to probe its inhibitory effect on abnormal oscillations of patient 6-specific epileptic brain networks. Due to the strong stimulation intensity produced by CP5 and CP6 on the EZ and PZ regions, we position dual cathodes at CP5 and CP6 and placed the anode at Ex8, ensuring the stimulation current intensity remained unchanged. This adjustment implies a shift from a single electrode delivering 1 mA of stimulation to two electrodes, each delivering 0.5 mA of stimulation (Fig. 10e and f). Figure  10c and d show the immediate and lasting effects of closed-loop dual-cathode tES with CP6 as the feedback signal, indicating that the inhibitory effect is significantly enhanced with increasing stimulation parameters. It can be seen that dual-cathode tES stimulation not only broadened the range of action of the stimulation, but also achieved satisfactory lasting results without changing the current intensity. This approach may offer a potential regulatory method for patients with multiple epileptic foci in future studies.

4 Discussion and conclusion

The recurrent seizures and patient-specificity of epilepsy pose challenges to the study of neuromodulation techniques. In this paper, we initially construct a model to simulate the dynamics of epileptic brain networks under tES, incorporating the mechanism of stimulus effects on excitatory synaptic levels to examine both the immediate and lasting effects of tES on controlling epileptic oscillatory propagation. Specifically, following the principle that increased stimulus intensity and duration prolong the lasting effect of the stimulation, we find that the addition of tES to the synaptic level of the excitatory loop effectively revealed an experimentally lasting effect of tES on seizure propagation. Hence, synaptic alterations may constitute one of the potential mechanisms underpinning the delayed effects of tES.

Further, we develop an amplitude-based closed-loop tES, emphasizing the importance of selecting appropriate feedback indicators and the positioning of the cathode. The typical epilepsy model presented in Sect. 3.2 highlights the importance of choosing appropriate feedback indicators. As shown in Fig. 5, when CP5 is used as the feedback signal, initiating two stimulations within the first 25 s resulted in better immediate and long-term effects. One obvious reason for this is that the two stimulations caused significant changes in Z(t), leading to more sustained inhibitory effects. It is worth noting, however, that the stimulus effect depends not only on the number of stimulation, but also on the initial timing of the stimulus. Incorrect selection of feedback signals can result in stimulation that is activated too late, resulting in its ineffectiveness in suppressing seizures. The decreased stimulus effect with delayed onset may be attributable to the situation in which only a single stimulus activation occurs within the initial 25 s. Additionally, a short duration of stimulation impacts the lasitng effectiveness of tES. It may also appear that when the anomalous oscillations propagate throughout the network, the weaker tES is no longer valid. These findings highlight the critical role of the feedback signal in the stimulation process. Only an appropriate feedback signal can ensure that the stimulation initiation time and duration are suitable. Therefore, in the future application of closed-loop tES, incorporating seizure detection alerts to anticipate seizures and deliver tES after seizure onset may enhance the effectiveness of seizure control. As shown in Fig.  5b and c, CP5, PO3, and P1, which are EEG channels close to the EZ and PZ regions, are suitable as feedback signal indicators. Beside, the determination of cathode placement primarily relies on the level of stimulation intensity received by the EZ and PZ nodes.

Our comprehensive examination extends to the effects of closed-loop tES across six individualized epileptic brain network models, with each model manifesting unique variations in the EZ and PZ distributions that significantly influence the dynamics of seizure propagation. Our detailed analysis foucses on the roles of \(\tau \) and \(\beta \) in modulating stimulation efficacy. When the distribution of the PZ and EZ involves only one brain hemisphere, unilateral closed-loop tES can select appropriate values of \(\tau \) and \(\beta \) to obtain satisfactory immediate and long-term inhibitory effects. However, if the EZ and PZ involved two brain hemispheres, as in Patient 6, unilateral closed-loop tES could not achieve a satisfactory inhibitory effect. Further, we find that these two parameters have little effect on the immediate effect of closed-loop stimulation, but play a critical role in the lasting success of inhibiting seizure propagation. Specifically, it emerges that the duration of each stimulation session is important and insufficient duration results in inadequate suppression of seizure propagation across the network. The need for customized stimulation parameters became apparent as the brain networks responded differently in each case, but a consistent pattern was observed in most patients except Patient 6. As \(\tau \) and \(\beta \) values increase, the lasting suppression effects of closed-loop stimulation improve. However, due to the difficulty in accurately measuring \(\beta \) as an internal brain parameter, extending the duration of stimulation could potentially enhance the effectiveness of closed-loop tES. Additionally, for Patient 6, the extensive bihemispherical spread of the PZ complicates the application of unilateral closed-loop electrical stimulation, highlighting its inherent limitations in effectively managing the spread of epileptic seizures. Drawing on the success of dual-target electrical stimulation methods, we explore the adoption of a dual-target closed-loop electrical stimulation system. In patients with extensive PZ distribution, such as Patient 6, this approach has proven effective in managing complex seizure propagation while maintaining a constant total stimulation current. This strategy ensures that despite the broad and diverse impacts of different brain network characteristics on stimulation outcomes, effective seizure management can be achieved by adjusting the stimulation protocol to accommodate the specific distribution patterns of the EZ and PZ, thereby enhancing overall treatment efficacy.

Finally, there are some limitations of the model. Firstly, the model only includes 74 brain regions, and some epilepsy patients may have PZs and EZs in other regions. Constructing a more comprehensive epilepsy network model could improve patient specificity. Moreover, the phenomenological model proposed for synaptic delay changes merely replicates the basic experimental observation of the interaction between stimulation duration, intensity, and sustained effects. Notably, the lasting effects of the model have not yet been directly validated in patient data. A more comprehensive and rational model of synaptic changes that considers additional factors, such as patient-specific information, could be considered in the future. Secondly, the Jansen-Rit model is widely used in large-scale modeling studies, the propagation of epileptic seizures, and tES modulation analysis [22, 25, 46, 47]. Its advantages include a simple and comprehensible structure, flexible parameterization, biological relevance, widespread application, and high computational efficiency. However, the model also has some drawbacks, such as insufficient physiological details, lack of individual variability handling, difficulty in fully capturing the diversity of epileptic seizures, and challenges in fitting actual data. In this study, the model distinguishes between healthy and seizure states based only on resting and oscillatory states, without considering the temporal evolution of seizures. Thus, while the Jansen-Rit model offers unique advantages in understanding fundamental neural dynamics and providing a basis for pathological studies, its simplicity also limits its precision and broad applicability. Future improvements to the model should consider different phases of epileptic seizures, particularly if exploring seizure prediction. Additionally, for tES, which has various modes of action, the Jansen-Rit model may not fully capture all characteristics and effects of different types of stimulation, which should be addressed in subsequent research. In addition, our study focuses only on the sustained effect within 25 s after tES stimulation. The study suggests that tES stimulation may be sustained for a longer period of time after tES stimulation, and the dynamical mechanism behind it deserves our consideration. In addition, previous study has demonstrated that heterogeneity in nodal excitability significantly impacts the seizure propagation within the network [43]. Seizure activity propagates from focal nodes to other nodes with varying delays. Only three types of node excitability, EZ, PZ and other nodes, are considered in our model. It is important to consider the effect of complex node excitability heterogeneity on stimulation effects in subsequent studies. In conclusion, it is crucial to develop personalized stimulation strategies using non-invasive closed-loop modulation techniques for targeted seizure control interventions. This study provides a theoretical basis for the application of tES in epilepsy diagnosis and treatment.