<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="https://www.kopec-lab.com/feed.xml" rel="self" type="application/atom+xml"/><link href="https://www.kopec-lab.com/" rel="alternate" type="text/html" hreflang="en"/><updated>2026-04-06T16:19:00+00:00</updated><id>https://www.kopec-lab.com/feed.xml</id><title type="html">Computational Biophysics of Ion Channels</title><subtitle>Dr. Wojciech Kopec lab</subtitle><entry><title type="html">Calculating membrane potential from GROMACS trajectories</title><link href="https://www.kopec-lab.com/blog/2026/membrane-potential-gmx/" rel="alternate" type="text/html" title="Calculating membrane potential from GROMACS trajectories"/><published>2026-04-05T12:00:00+00:00</published><updated>2026-04-05T12:00:00+00:00</updated><id>https://www.kopec-lab.com/blog/2026/membrane-potential-gmx</id><content type="html" xml:base="https://www.kopec-lab.com/blog/2026/membrane-potential-gmx/"><![CDATA[<h3 id="intro">Intro</h3> <p>If you have ever run an MD simulation of a lipid membrane, one of the analyses likely included calculating the membrane potential. In GROMACS, this is conveniently done using ‘gmx potential’. However, what you likely observed was an asymmetric potential profile, varying wildly depending on the number of slices used for integration and the simulation length. You may then have tried the -correct flag in the same tool, which appears to fix these issues — although it is still debated whether, and under what circumstances, it should be used. Below, I present some thoughts on this, together with a new method for calculating the membrane potential.</p> <h3 id="the-problem">The problem</h3> <p>When computing the electrostatic potential from an MD simulation, the standard recipe is:</p> <ol> <li>Divide the simulation box into thin slices along one axis (typically Z)</li> <li>Compute the charge density rho(z) in each slice</li> <li>Integrate rho(z) twice to obtain the potential psi(z) via the Poisson equation</li> </ol> <p>In the classical form (Eq. 2 in Gurtovenko 2009), the boundary conditions are psi(0) = 0 and E(0) = 0, and the integration proceeds from z = 0 to z = L (the box length):</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>E(z)   = (1/epsilon_0) * integral_0^z rho(z') dz'
psi(z) = -integral_0^z E(z') dz'
</code></pre></div></div> <p>For a symmetric POPC bilayer (centered so the membrane is in the middle of the box and water is at the edges), this approach produces potential profiles that are <strong>strongly dependent on the number of slices</strong>, with large asymmetries that vary erratically. For example, in my hands, applying gmx potential without the -correct flag to a trajectory of a symmetric POPC bilayer produced:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Slices   Peak (V)   Asymmetry psi(L)-psi(0) (V)
  50      0.55       -0.08
 100      0.81       +0.47
 200      0.69       +0.17
 300      0.75       +0.25
 500      0.69       +0.13
 800      0.61       -0.00
1000      0.65       +0.06
</code></pre></div></div> <p>For a system that is perfectly symmetric, psi(L) should equal psi(0). Instead, the potential drop across the box fluctuates between -0.08 and +0.47 V depending on how many slices are used. The peak potential varies between 0.55 and 0.81 V. This behavior is identical in <code class="language-plaintext highlighter-rouge">gmx potential</code>.</p> <h3 id="root-cause-molecule-splitting-at-the-periodic-boundary">Root cause: molecule splitting at the periodic boundary</h3> <p>The artifact originates from how atoms are assigned to slices when the system is periodic.</p> <p>After centering (shifting so the bilayer center of mass is at z = L/2), each atom’s z-coordinate is wrapped into [0, L) using modular arithmetic (<code class="language-plaintext highlighter-rouge">z % L</code>). This ensures all atoms fall within the box. However, <strong>molecules that straddle the wrapping boundary at z = 0 / z = L get torn apart</strong>: some atoms of the molecule end up near z = 0 and others near z = L.</p> <p>For a typical POPC/water system, approximately 400 water molecules are split this way in each frame. Consider a TIP3P water molecule at the boundary:</p> <ul> <li>Before wrapping: O at z = -0.3 A, H1 at z = 0.5 A, H2 at z = 0.7 A (molecule is intact)</li> <li>After wrapping: O at z = L - 0.3, H1 at z = 0.5, H2 at z = 0.7 (molecule is torn apart)</li> </ul> <p>The oxygen (charge -0.834e) is now at the right edge of the box, while the hydrogens (+0.417e each) remain at the left edge. Each split molecule creates an <strong>artificial dipole spanning nearly the entire box</strong>. While the total charge of each molecule is zero, its charges are now distributed across opposite ends of the integration path.</p> <p>When the Poisson equation is integrated from z = 0 to z = L, this artificial dipole contributes a linear drift to the potential. The magnitude of this drift depends on:</p> <ol> <li><strong>The number of split molecules</strong> – varies between frames as molecules diffuse</li> <li><strong>The exact positions of split atoms within their slices</strong> – changes with slice width, hence with the number of slices</li> </ol> <p>This is why the artifact varies erratically with the slice count: different slice widths cause the split charges to land in different bins, changing the effective artificial dipole moment and thus the potential drift.</p> <h3 id="what-doesnt-fix-it">What doesn’t fix it</h3> <p>Several intuitive approaches were tested and found to be ineffective:</p> <p><strong>Making molecules whole before wrapping.</strong> Even when using a preprocessed trajectory where molecules are intact (e.g., via <code class="language-plaintext highlighter-rouge">gmx trjconv -pbc whole</code>), the centering step followed by <code class="language-plaintext highlighter-rouge">z % L</code> wrapping re-splits molecules at the new boundary. The artifact is identical to using a raw trajectory.</p> <p><strong>Wrapping by molecule center of mass.</strong> Instead of wrapping individual atoms, one can shift entire molecules based on their center of mass. This keeps molecules intact but atoms of molecules near the boundary extend beyond [0, L). These out-of-range atoms must be handled somehow:</p> <ul> <li><strong>Clipping</strong> (placing them in the edge slice): Concentrates charge at the boundary, making the artifact much worse. At 1000 slices, the potential reached 47 V.</li> <li><strong>Modulo index wrapping</strong> (<code class="language-plaintext highlighter-rouge">index % n_slices</code>): Effectively re-splits the molecule – the out-of-range atoms land on the opposite side. Results are identical to simple atom wrapping.</li> </ul> <p><strong>Scaling coordinates to a fixed box size.</strong> Gurtovenko &amp; Vattulainen recommend scaling all coordinates to the initial box size to avoid effects from box size fluctuations under NPT pressure coupling. Testing showed this has negligible effect – the artifact is dominated by molecule splitting, not box fluctuations. The asymmetry pattern was essentially unchanged with or without scaling.</p> <p><strong>Placing the wrapping boundary through the membrane.</strong> Moving the boundary from the water phase (where many molecules cross it) to the membrane center (where fewer cross). This made the artifact much worse, because lipid headgroups carry much larger partial charges than water, and splitting a lipid headgroup creates a correspondingly larger artificial dipole.</p> <h3 id="fix-1-sachs-et-al-correction">Fix 1: Sachs et al. correction</h3> <p>Sachs et al. (J. Chem. Phys. 121, 10847, 2004) proposed an alternative form of the Poisson equation where the potential is constrained to be equal on both sides of the box: psi(0) = psi(L). This amounts to subtracting a linear correction term:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>psi_Sachs(z) = psi_classical(z) - (z/L) * psi_classical(L)
</code></pre></div></div> <p>Gurtovenko &amp; Vattulainen (Eq. 4-11) showed that the difference between the two forms is proportional to the total dipole moment of the system. For electroneutral systems, the correction is:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Delta(z) = z / (epsilon_0 * V) * P_total
</code></pre></div></div> <p>where P_total is the system dipole moment and V is the box volume.</p> <p>The Sachs correction eliminates the linear drift and produces stable results:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Slices   Peak (V)   Asymmetry (V)
  50      0.56       -0.001
 100      0.58       +0.005
 200      0.61       +0.001
 300      0.63       +0.001
 500      0.62       +0.000
 800      0.61       -0.000
1000      0.62       +0.000
</code></pre></div></div> <p>However, it has a fundamental limitation: <strong>it removes ALL linear drift, including any real transmembrane potential difference</strong>. For asymmetric bilayers (e.g., POPC/POPE), the transmembrane potential is a real physical quantity that should not be subtracted. The Sachs form is therefore only appropriate for symmetric systems.</p> <h3 id="fix-2-dipole-correction-subtracting-the-artifact-only">Fix 2: Dipole correction (subtracting the artifact only)</h3> <p>An alternative approach is to compute the artificial dipole moment caused by molecule splitting and subtract only that contribution:</p> <ol> <li>For each frame, compute the dipole moment of the system with intact (unwrapped) molecules: P_whole = sum(q_i * z_i_whole)</li> <li>Compute the dipole moment after wrapping: P_wrapped = sum(q_i * z_i_wrapped)</li> <li>The artifact dipole is: P_artifact = P_wrapped - P_whole</li> <li>Subtract the corresponding linear potential: Delta(z) = z / (epsilon_0 * V) * P_artifact</li> </ol> <p>In principle, this should remove only the wrapping artifact while preserving the real transmembrane potential. In practice, testing showed this <strong>overcorrects</strong> – the “whole” and “wrapped” dipole moments are not cleanly separable because the centering operation itself changes the dipole moment relative to the box origin. The corrected asymmetry was worse than uncorrected for many slice counts.</p> <h3 id="fix-3-fourier-space-integration---our-new-tool-httpsgithubcomkopec-labmembrane-potential-tool">Fix 3: Fourier-space integration - our new tool, https://github.com/Kopec-Lab/membrane-potential-tool</h3> <p>One solution is to solve the Poisson equation in Fourier (reciprocal) space, where periodicity is built in by construction.</p> <p>The 1D Poisson equation in real space:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>d^2 psi(z) / dz^2 = -rho(z) / epsilon_0
</code></pre></div></div> <p>becomes, after Fourier transform:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>-k^2 * psi_hat(k) = -rho_hat(k) / epsilon_0
</code></pre></div></div> <p>which gives:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>psi_hat(k) = rho_hat(k) / (k^2 * epsilon_0)    for k != 0
</code></pre></div></div> <p>The k = 0 component corresponds to an arbitrary overall offset of the potential and is set to zero. The electric field is obtained similarly:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>E_hat(k) = -i*k * psi_hat(k)
</code></pre></div></div> <p>The inverse Fourier transform gives the real-space potential and field.</p> <p>This approach has several key advantages:</p> <ol> <li> <p><strong>Inherently periodic.</strong> The Fourier transform assumes the input signal is periodic. The potential automatically satisfies psi(0) = psi(L), with no need for corrections or special boundary conditions. There is no “starting point” for integration that could accumulate errors.</p> </li> <li> <p><strong>Immune to the boundary artifact.</strong> Split molecules create charge density features at both edges of the box. In the classical method, the double integration treats these as separated by the full box length, amplifying their effect. In Fourier space, periodicity means the edges are the same point – the charge distribution from a split molecule is treated as if the molecule were whole, because the Fourier basis functions wrap around naturally.</p> </li> <li> <p><strong>Insensitive to the number of slices.</strong> Because there is no error accumulation from sequential integration, the result converges rapidly and varies minimally with slice count:</p> </li> </ol> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Slices   Peak (V)   Asymmetry (V)
  50      0.65       +0.003
 100      0.63       +0.003
 200      0.64       +0.001
 300      0.64       +0.001
 500      0.63       +0.000
 800      0.63       +0.000
1000      0.63       +0.000
</code></pre></div></div> <p>The peak potential is consistent at ~0.63 V regardless of slice count, and the asymmetry is essentially zero (&lt; 0.003 V). Compare this with the classical method’s range of 0.55-0.81 V for the peak and up to 0.47 V of asymmetry.</p> <h3 id="summary-of-methods">Summary of methods</h3> <table> <thead> <tr> <th>Method</th> <th>Asymmetry</th> <th>Peak stability</th> <th>Works for asymmetric bilayers?</th> </tr> </thead> <tbody> <tr> <td>Classical (gmx potential)</td> <td>up to 0.47 V</td> <td>varies 0.55-0.81 V</td> <td>yes, but with artifacts</td> </tr> <tr> <td>Classical + Sachs</td> <td>&lt; 0.005 V</td> <td>0.56-0.63 V</td> <td>no (removes real potential drop)</td> </tr> <tr> <td>Classical + correct</td> <td>&lt; 0.004 V</td> <td>0.61-0.63 V</td> <td>unclear (see discussion below)</td> </tr> <tr> <td>Classical + dipole correction</td> <td>overcorrects</td> <td>overcorrects</td> <td>no (unreliable)</td> </tr> <tr> <td><strong>Fourier (default)</strong></td> <td><strong>&lt; 0.003 V</strong></td> <td><strong>0.63-0.65 V</strong></td> <td><strong>yes</strong></td> </tr> </tbody> </table> <p>The Fourier method is the default because it is the most robust, produces consistent results regardless of slice count, and works correctly for both symmetric and asymmetric systems.</p> <hr/> <h3 id="how-it-works">How it works</h3> <h3 id="step-1-charge-density">Step 1: Charge density</h3> <p>The box is divided into <code class="language-plaintext highlighter-rouge">N</code> slices along the chosen axis. For each trajectory frame, every atom is assigned to a slice based on its coordinate. The partial charge (from the <code class="language-plaintext highlighter-rouge">.tpr</code> file) is added to that slice. The charge density is the total charge in each slice divided by the slice volume, averaged over all frames.</p> <h3 id="step-2-solve-the-poisson-equation">Step 2: Solve the Poisson equation</h3> <p><strong>Fourier method (default):</strong> The charge density is Fourier-transformed, divided by <code class="language-plaintext highlighter-rouge">k^2 * epsilon_0</code> in reciprocal space (skipping k=0), and inverse-transformed to obtain the potential. The electric field is computed analogously using <code class="language-plaintext highlighter-rouge">-i*k * psi_hat(k)</code>.</p> <p><strong>Classical method (<code class="language-plaintext highlighter-rouge">-classical</code>):</strong> The charge density is numerically integrated twice using the cumulative trapezoidal rule, with boundary conditions psi(0) = 0 and E(0) = 0. With <code class="language-plaintext highlighter-rouge">-sachs</code>, a linear correction term is subtracted to enforce psi(0) = psi(L).</p> <p>Both methods use the <code class="language-plaintext highlighter-rouge">gmx potential</code> sign convention, where the dipole potential inside the membrane is positive relative to water.</p> <h3 id="known-issues-and-considerations">Known issues and considerations</h3> <ul> <li><strong>Centering matters</strong>: Without <code class="language-plaintext highlighter-rouge">-center</code>, bilayer center-of-mass fluctuations smear the charge density and produce asymmetric profiles. Always use <code class="language-plaintext highlighter-rouge">-center</code> for membrane systems.</li> <li><strong>Convergence</strong>: Potential profiles require long trajectories (100+ ns for bilayers) to converge, particularly in the water region near lipid headgroups.</li> <li><strong>Dielectric constant</strong>: The calculation uses vacuum permittivity (epsilon_r = 1). The output represents the bare electrostatic potential from the explicit charge distribution, not a dielectrically screened quantity.</li> <li><strong>Undulations</strong>: For large membranes with significant undulations, the 1D slab decomposition may not accurately capture the local potential. Using small, planar bilayer patches avoids this issue.</li> <li><strong>Preprocessing</strong>: It is recommended (but not strictly necessary) to preprocess the trajectory with <code class="language-plaintext highlighter-rouge">gmx trjconv -pbc whole</code> to make molecules whole. While the Fourier method handles split molecules much better than the classical method, intact molecules produce marginally cleaner charge density profiles.</li> </ul> <h3 id="what-gmx-potential--correct-actually-does">What gmx potential <code class="language-plaintext highlighter-rouge">-correct</code> actually does</h3> <p>Inspection of the GROMACS source code reveals that <code class="language-plaintext highlighter-rouge">-correct</code> performs <strong>two mean subtractions</strong> during the classical double integration:</p> <ol> <li> <p><strong>Before the first integration</strong>: subtract the mean charge density from all slices that have nonzero charge density. This makes the effective total charge exactly zero, removing a constant drift term from the electric field.</p> </li> <li> <p><strong>After the first integration</strong>: subtract the mean electric field (again, only from slices with nonzero charge density). This removes a constant offset from E(z), which would otherwise produce a linear drift in the potential.</p> </li> </ol> <p>This is <em>not</em> the same as “zeroing net charge per slab” as sometimes described. It is a global correction applied to the entire charge density profile and then the entire electric field profile.</p> <h3 id="why-it-works">Why it works</h3> <p>The key insight is that Step 2 (mean E subtraction) is doing essentially the same thing as the Sachs correction and the Fourier method’s k=0 exclusion, but from a different angle.</p> <p>In a periodic system, the electric field must also be periodic: E(0) = E(L). The classical integration starts with E(0) = 0, so it requires E(L) = 0 as well. If the total integrated charge density is not exactly zero (due to molecule splitting at the boundary, finite precision, or slight charge imbalance from the slicing), E(L) != 0, and this mismatch propagates as a linear drift in the potential.</p> <p>Subtracting the mean electric field shifts E(z) so that its average is zero. For a periodic function, this is equivalent to enforcing that the integral of E over the full box vanishes — which is exactly the condition for the potential to be periodic (psi(0) = psi(L)).</p> <p>Step 1 (mean rho subtraction) has a negligible effect in practice because the total system charge is already very close to zero. Its main effect is to eliminate tiny numerical imbalances from the binning.</p> <h3 id="test-results">Test results</h3> <p>Testing on a symmetric POPC bilayer with the <code class="language-plaintext highlighter-rouge">-correct</code> flag produces results nearly identical to the Fourier method:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Classical + correct:
Slices   Peak (V)   Asymmetry (V)
  50      0.56       +0.002
 100      0.61       -0.003
 200      0.63       +0.001
 300      0.63       +0.001
 500      0.63       +0.000
 800      0.62       +0.000
1000      0.63       +0.000
</code></pre></div></div> <p>Compare with Fourier (peak ~0.63 V, asymmetry &lt; 0.003 V) and uncorrected classical (peak 0.55-0.81 V, asymmetry up to 0.47 V). The <code class="language-plaintext highlighter-rouge">-correct</code> flag effectively eliminates the slice-count sensitivity.</p> <h3 id="is-it-valid">Is it valid?</h3> <p>The <code class="language-plaintext highlighter-rouge">-correct</code> procedure is mathematically equivalent to enforcing periodic boundary conditions on the electric field, which is physically correct for a periodic system. In this sense, it is a valid fix.</p> <p>However, there is an important subtlety for <strong>asymmetric systems</strong>:</p> <ul> <li><strong>Sachs correction</strong> explicitly removes the linear potential drop across the box, destroying any real transmembrane potential difference.</li> <li><strong><code class="language-plaintext highlighter-rouge">-correct</code></strong> subtracts the mean E field. For an asymmetric system with a real transmembrane potential, the mean E field is nonzero (it equals the potential drop divided by the box length). Subtracting it would remove the real transmembrane potential along with the artifact.</li> </ul> <p>In practice, <strong><code class="language-plaintext highlighter-rouge">-correct</code> behaves identically to the Sachs correction for the linear component</strong>: both remove the entire psi(L) - psi(0) drop. The difference is only in higher-order effects from the mean rho subtraction in Step 1 of <code class="language-plaintext highlighter-rouge">-correct</code>, which are negligible.</p> <p><strong>Bottom line</strong>: <code class="language-plaintext highlighter-rouge">-correct</code> is valid for symmetric systems and produces results equivalent to the Fourier method. For asymmetric bilayers with an intrinsic transmembrane potential arising from lipid asymmetry, <code class="language-plaintext highlighter-rouge">-correct</code> may partially remove that potential (like Sachs), since both subtract a global mean. However, for systems with an applied external electric field (see <a href="#simulations-with-applied-electric-field">below</a>), <code class="language-plaintext highlighter-rouge">-correct</code> preserves the voltage-carrying slope in the reaction potential — the global mean E field that gets subtracted is dominated by the integration drift artifact, not the physical field structure. The Fourier method remains the recommended default because it handles all cases correctly and does not require any post-hoc corrections.</p> <hr/> <h3 id="simulations-with-applied-electric-field">Simulations with applied electric field</h3> <p>A common approach to simulate a transmembrane voltage in MD is to apply a constant external electric field E perpendicular to the membrane (GROMACS <code class="language-plaintext highlighter-rouge">electric-field-z</code> mdp parameter). The resulting voltage is V = E * L_z, where L_z is the box length in the field direction. This section explains what the tool computes in this scenario, how to interpret the results, and what the <code class="language-plaintext highlighter-rouge">-efield</code> flag does.</p> <h3 id="background-the-constant-electric-field-method">Background: the constant electric field method</h3> <p>In GROMACS, a constant electric field E_z applies a force F = q_i * E_z to every charged particle. The applied voltage across the simulation box is:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>V = E_z * L_z
</code></pre></div></div> <p>This is equivalent to the influence of two infinite baths connected by an electromotive force (EMF), as shown by Roux (Biophys. J. 95, 4205, 2008). The constant field method has been validated extensively (Gumbart et al., BBA 1818, 294, 2012; Jensen et al., J. Gen. Physiol. 141, 619, 2013) and is widely used for studying ion channels, electroporation, and voltage-gated conformational changes.</p> <h3 id="decomposition-of-the-total-potential">Decomposition of the total potential</h3> <p>The total electrostatic potential in a simulation with an applied field has two components (Jensen et al. Eq. 2):</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Phi_total(z) = Phi_reaction(z) - E_applied * z
</code></pre></div></div> <p>where:</p> <ul> <li> <p><strong>Phi_reaction(z)</strong> is the reaction potential arising from the explicit charges in the system (ions, water dipoles, lipid headgroups, protein residues). This is computed by the particle-mesh Ewald (PME) method during the simulation and is what our tool calculates from the charge density by solving the Poisson equation. <strong>This potential is periodic</strong>: Phi_reaction(0) = Phi_reaction(L).</p> </li> <li> <p><strong>-E_applied * z</strong> is the linear ramp from the applied external field. This component has no source charges — it is imposed externally. <strong>This breaks periodicity</strong>: the total potential differs by V = E * L_z between the two ends of the box.</p> </li> </ul> <p>The charge density rho(z) that the tool computes from atom positions reflects the system’s <em>response</em> to the applied field — the rearrangement of ions, water dipoles, and other charges. It does not contain the external field itself. Therefore, the Poisson equation solved by the tool yields only the reaction potential, which is periodic. The Fourier method remains the correct solver for this component.</p> <h3 id="what-happens-in-the-bulk-water">What happens in the bulk water</h3> <p>Bulk aqueous electrolyte behaves approximately as a conductor: it self-organizes to screen the applied field. In the water region:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>E_total = E_reaction + E_applied ≈ 0
</code></pre></div></div> <p>Therefore the reaction electric field in water is approximately:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>E_reaction ≈ -E_applied
</code></pre></div></div> <p>and the reaction potential develops a slope in the water region:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dPhi_reaction/dz ≈ E_applied    (in water)
</code></pre></div></div> <p>The total potential, being the sum of the sloped reaction potential and the opposite-sloped applied ramp, is approximately flat in bulk water — as expected for a conductor. The entire voltage drop concentrates across the low-dielectric membrane region, which is the biologically meaningful quantity.</p> <h3 id="recovering-the-voltage-from-the-charge-density">Recovering the voltage from the charge density</h3> <p>A key question is whether the applied voltage V can be recovered purely from the charge density profile, without knowing E_applied a priori.</p> <p><strong>From the electric field profile</strong>: The average reaction electric field in the bulk water region should be approximately -E_applied. Reading this value and multiplying by L_z gives an estimate of V.</p> <p><strong>From the potential slope</strong>: The reaction potential has a slope ≈ E_applied in the water region. Fitting a line to the potential in the water phase and multiplying the slope by L_z gives V.</p> <p>However, these are <strong>approximate</strong> estimates. Testing on a gramicidin A channel system (E_applied = 0.032 V/nm, expected V = 293 mV) showed:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Reaction potential slope in water (per region):
  Region 1 (left water):  slope = 0.0411 V/nm
  Region 2 (right water): slope = 0.0137 V/nm
  Average slope:           0.0274 V/nm
  -&gt; V estimate:           251 mV (85.7% of expected 293 mV)

Average reaction E field in water: -0.0278 V/nm
Expected (-E_applied):             -0.0320 V/nm
Average total E field in water:     0.0042 V/nm (ideal: 0)
</code></pre></div></div> <p>The ~85% recovery is consistent and reproducible. The underestimate reflects the fact that water is not a perfect conductor:</p> <ol> <li><strong>Finite water phase</strong>: The bulk water regions (~2 nm on each side) may not be thick enough for complete screening.</li> <li><strong>Ionic current</strong>: In a conducting channel (like gramicidin), steady-state ionic current requires a residual driving field in the water, so the screening is inherently incomplete.</li> <li><strong>Finite system size</strong>: Gumbart et al. (2012) emphasize that V = E * L_z is exact by construction, but extracting V from the potential profile introduces finite-size errors.</li> </ol> <p><strong>The exact voltage is always V = E * L_z.</strong> The slope-based estimate is useful as a consistency check but should not be used as the primary voltage determination.</p> <h3 id="what-the--efield-flag-does">What the <code class="language-plaintext highlighter-rouge">-efield</code> flag does</h3> <p>When <code class="language-plaintext highlighter-rouge">-efield VALUE</code> is specified (where VALUE is E_z in V/nm, matching the GROMACS <code class="language-plaintext highlighter-rouge">electric-field-z</code> mdp parameter):</p> <ol> <li> <p><strong>Reports the exact voltage</strong>: V = E_z * L_z, using the average box length from the trajectory.</p> </li> <li> <p><strong>Writes the total potential</strong>: Phi_total(z) = Phi_reaction(z) - E * z is written to the file specified by <code class="language-plaintext highlighter-rouge">-ot</code> (default: <code class="language-plaintext highlighter-rouge">potential_total.xvg</code>). This non-periodic profile shows the voltage drop across the membrane.</p> </li> <li> <p><strong>Detects bulk water regions</strong>: Water molecules are automatically identified (by residue name: SOL, TIP3, HOH, WAT, SPC) and their positions are binned during trajectory processing. Contiguous regions with high water density are identified as bulk water.</p> </li> <li> <p><strong>Measures the reaction potential slope</strong>: A linear fit is performed in each bulk water region independently (since different regions are at different absolute potential levels in the periodic reaction potential), and the average slope is reported.</p> </li> <li> <p><strong>Reports voltage estimates</strong>: Both the exact V = E * L_z and the slope-based estimate are printed, along with the recovery percentage. The average reaction electric field in water is also reported and compared to the expected -E_applied.</p> </li> </ol> <h3 id="classical-integration-with--correct-also-works">Classical integration with <code class="language-plaintext highlighter-rouge">-correct</code> also works</h3> <p>Perhaps surprisingly, <code class="language-plaintext highlighter-rouge">-classical -correct</code> produces the same water slope and voltage estimate as the Fourier method. Testing on the gramicidin system shows identical slopes (0.0270 V/nm) for both methods.</p> <p>The reason: <code class="language-plaintext highlighter-rouge">-correct</code> subtracts the global mean E field across all slices. This mean (-0.051 V/nm in the test system) reflects contributions from both the water regions (where E_reaction ≈ -0.029 V/nm) and the membrane region (where E_reaction ≈ +0.017 V/nm, reflecting the large headgroup dipole fields). Because these contributions partially cancel, the global mean is dominated by the integration drift artifact, not by the physical field from the applied voltage. Subtracting it removes only the artifact, preserving the spatial structure — exactly as the Fourier method does by setting k=0 to zero.</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>                           Uncorrected    After -correct    Fourier
Mean E, all slices:        -0.0512         0.0000           0.0000  V/nm
Mean E, left water:        -0.0826        -0.0314          -0.0314  V/nm
Mean E, right water:       -0.0775        -0.0263          -0.0263  V/nm
Mean E, membrane:          -0.0338        +0.0174          +0.0174  V/nm
</code></pre></div></div> <p>Both corrected methods give identical E field profiles. The <code class="language-plaintext highlighter-rouge">-sachs</code> correction, by contrast, enforces psi(0) = psi(L) by subtracting a linear term, which would remove the physical slope and should not be used with applied fields.</p> <h3 id="practical-considerations">Practical considerations</h3> <ul> <li> <p><strong>Always use <code class="language-plaintext highlighter-rouge">-center</code></strong> when analyzing systems with applied fields. Without centering, membrane drift smears the charge density and corrupts the slope measurement.</p> </li> <li> <p><strong>The total potential (<code class="language-plaintext highlighter-rouge">-ot</code> output) is not periodic.</strong> It shows a linear ramp across the box with the voltage drop concentrated at the membrane. This is the physically meaningful potential profile.</p> </li> <li> <p><strong>The reaction potential (<code class="language-plaintext highlighter-rouge">-o</code> output) is periodic.</strong> It shows the intrinsic membrane dipole potential plus the system’s response to the applied field. The slope in the water region reflects the screening of the applied field.</p> </li> <li> <p><strong>Both Fourier and <code class="language-plaintext highlighter-rouge">-classical -correct</code> work correctly</strong> with applied fields. Both methods remove only the unphysical DC offset (k=0 mode) from the electric field while preserving all spatial structure, including the slope in water that carries the voltage information. The <code class="language-plaintext highlighter-rouge">-correct</code> procedure subtracts the global mean E field across all slices — this mean (-0.051 V/nm in the gramicidin test) is NOT the same as the E field in water (-0.029 V/nm), because the membrane region has a very different E field that pulls the average away. Therefore, the physical slope is preserved. The <code class="language-plaintext highlighter-rouge">-sachs</code> correction should still be avoided with applied fields, as it explicitly enforces psi(0) = psi(L), which would remove the linear component of the reaction potential that encodes the voltage.</p> </li> </ul> <h3 id="why-the-tool-computes-the-reaction-potential-not-the-total-potential">Why the tool computes the reaction potential, not the total potential</h3> <p>A potentially confusing aspect of electrostatic potential calculations from MD simulations — both in <code class="language-plaintext highlighter-rouge">gmx potential</code> and in this tool — is that what gets computed is <strong>the reaction potential</strong>, not the total electrostatic potential. This distinction is invisible in simulations without an applied field, which is why it has historically caused confusion.</p> <p><strong>What the tool does:</strong> It bins atomic charges into slices, constructs the charge density rho(z), and solves the Poisson equation:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>d²Phi/dz² = -rho(z) / epsilon_0
</code></pre></div></div> <p>The charge density rho(z) contains only the explicit charges in the system: ions, water partial charges, lipid headgroup charges, protein residues, etc. The resulting potential Phi(z) is the <strong>reaction potential</strong> — the electrostatic potential generated by the system’s own charges in response to whatever conditions are imposed.</p> <p><strong>Why not the total potential?</strong> When an external electric field is applied in GROMACS (<code class="language-plaintext highlighter-rouge">electric-field-z</code>), the field acts as a force F = q * E_z on every particle, but it has <strong>no source charges</strong>. It is an external boundary condition, not a charge distribution. Since the applied field contributes no charges to rho(z), it does not appear in the Poisson equation, and the tool cannot “see” it. The total potential is:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Phi_total(z) = Phi_reaction(z) - E_applied * z
</code></pre></div></div> <p>The linear ramp from the applied field must be added manually (which is what the <code class="language-plaintext highlighter-rouge">-efield</code> flag does).</p> <p><strong>Why this hasn’t caused problems historically:</strong> In the vast majority of membrane simulations — symmetric bilayers, asymmetric bilayers, systems with ion gradients — there is no applied external field. In these cases, Phi_reaction(z) <em>is</em> the total potential. The distinction between reaction and total potential simply doesn’t arise, and the output of <code class="language-plaintext highlighter-rouge">gmx potential</code> is the complete answer.</p> <p><strong>Where confusion can arise:</strong> When researchers apply an external field (e.g., to study voltage-gated channels or electroporation) and then run <code class="language-plaintext highlighter-rouge">gmx potential</code> on the trajectory, they get the reaction potential — which is periodic and shows no net voltage drop across the box. This can be mistaken for a calculation error or a sign that the applied voltage had no effect. In fact, the tool is working correctly; the voltage drop is carried entirely by the applied field ramp, which is not part of the charge density. The reaction potential shows the system’s <em>response</em> to the applied voltage: screening in the water phase (visible as a slope) and the intrinsic membrane dipole potential.</p> <p><strong>To obtain the total potential</strong> in simulations with an applied field, use <code class="language-plaintext highlighter-rouge">-efield VALUE</code> where VALUE matches the <code class="language-plaintext highlighter-rouge">electric-field-z</code> parameter from the GROMACS mdp file. The tool will then write the total potential (reaction + applied ramp) to <code class="language-plaintext highlighter-rouge">potential_total.xvg</code>, which shows the non-periodic voltage profile with the full voltage drop across the membrane.</p> <h3 id="why-is-the-reaction-potential-periodic">Why is the reaction potential periodic?</h3> <p>At first glance, it seems paradoxical that the reaction potential Phi_reaction(z) is periodic even when a directional electric field is applied. One might expect charges to accumulate on one side of the membrane — as in a real capacitor — breaking the symmetry and making the charge density (and hence the potential) non-periodic. But this does not happen, for a fundamental reason: <strong>periodic boundary conditions prevent true charge accumulation</strong>.</p> <p><strong>There is only one water phase.</strong> In a membrane simulation with PBC, the water region above the membrane and the water region below it are not separate compartments — they are the same continuous water phase, connected through the periodic boundary. A water molecule (or ion) that exits the box at z = L_z immediately re-enters at z = 0. There are no edges, walls, or capacitor plates where charge can build up.</p> <p><strong>Charge density inherits the periodicity of the box.</strong> Because every atom’s position is defined modulo L_z, the ensemble-averaged charge density satisfies rho(z + L_z) = rho(z) by construction. No matter how strong the applied field, the charge density profile repeats with period L_z. The system responds to the field through <em>local</em> polarization — water dipoles align preferentially, ions redistribute slightly within the periodic cell — but these rearrangements are periodic.</p> <p><strong>Poisson’s equation preserves periodicity.</strong> The reaction potential is obtained by solving the Poisson equation with the periodic charge density as input. If rho(z) is periodic, Phi_reaction(z) is also periodic (the Fourier method enforces this explicitly; the classical method with <code class="language-plaintext highlighter-rouge">-correct</code> achieves it by removing the DC drift). The reaction potential develops a slope in the water regions (reflecting the screening of the applied field) but this slope is compensated by the opposite response in the membrane region, so that the potential returns to its starting value over one full period.</p> <p><strong>How does the system sustain a voltage without charge accumulation?</strong> This is the key insight from Roux (2008). In PBC, the applied voltage cannot be represented by accumulated surface charge (there are no surfaces). Instead, it enters as an external parameter — the EMF in Roux’s formulation — that adds a force F = q * E_z to every charged particle. The system’s response is captured by the <em>displacement charge</em> Q_d = sum(q_i * z_i) / L_z, which measures how much charge has been displaced along z relative to the periodic cell, without ever breaking periodicity. The displacement charge is analogous to the charge on a capacitor plate, but it arises from the collective shift of all charges within the periodic cell, not from accumulation at a boundary.</p> <p><strong>In summary:</strong> PBC means the simulation box has no boundaries — only a periodic unit cell. Charges cannot accumulate at edges that don’t exist. The charge density and reaction potential are therefore necessarily periodic. The entire voltage drop is encoded in the external field ramp (-E * z), which must be added manually to obtain the non-periodic total potential.</p> <h3 id="special-case-pure-water-under-applied-electric-field">Special case: pure water under applied electric field</h3> <p>Testing the tool on a pure water box with and without an applied electric field reveals a counterintuitive but physically correct result: <strong>the reaction potential is identical in both cases</strong>, and the total potential under the applied field is a perfectly linear ramp.</p> <p><strong>Why the charge density doesn’t change:</strong> The applied field does orient water dipoles — each molecule tilts slightly so its dipole aligns with E_z. However, this polarization is <em>spatially uniform</em>: every slice of the water box has the same degree of alignment. Uniform polarization produces no charge density variation:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>rho_bound = -dP/dz = 0    (when P is constant)
</code></pre></div></div> <p>Microscopically: if all hydrogens shift slightly “up”, each slice gains H charge from molecules below but loses the same amount to the slice above. For a uniform density of molecular centers, these contributions cancel exactly in every slice. The net dipole moment is real, but it is invisible in rho(z).</p> <p><strong>Why there is no screening:</strong> In a finite dielectric slab (or at a membrane interface), the edges of the polarized region carry bound surface charges (sigma_b = P dot n) that create a depolarization field screening E_applied by a factor of 1/epsilon_r. In PBC, there are no surfaces — the “+sigma” at z = L_z wraps around and cancels the “-sigma” at z = 0. Without bound surface charges, there is no screening:</p> <table> <thead> <tr> <th>System</th> <th>E_reaction in water</th> <th>E_total in water</th> <th>Screening?</th> </tr> </thead> <tbody> <tr> <td>Pure water (PBC)</td> <td>0</td> <td>E_applied</td> <td>No</td> </tr> <tr> <td>Water + membrane</td> <td>~ -E_applied</td> <td>~ 0</td> <td>Yes</td> </tr> </tbody> </table> <p>This means that in pure water with PBC, the total electric field equals the full applied field everywhere. The dielectric constant of water is irrelevant — epsilon_r only matters when interfaces are present for bound charges to accumulate on. The voltage V = E * L_z is exact regardless of epsilon_r, which is a fundamental property of the constant-field method in PBC (Roux, 2008).</p> <p><strong>What this means in practice:</strong> The perfectly linear total potential ramp in pure water is NOT because water is “a good conductor that screens the field” (leaving only the ramp). It is the opposite — water <em>cannot</em> screen the field at all in homogeneous PBC, so the reaction potential is flat and the total potential is the bare applied ramp. Screening requires interfaces (like a membrane) where the polarization changes spatially, creating bound charges that generate the reaction field.</p> <p><strong>Connection to uncompensated dipole artifacts:</strong> This physics also explains the PBC-induced water ordering artifact described by Kopec &amp; Gapsys (2026): when a membrane has an uncompensated electric dipole (from asymmetric charged lipids or an embedded protein), PBC constrains the voltage across the box to zero. The system compensates by creating a counter-field — water dipoles order and ions redistribute. This ordering is an artifact of the periodic boundary, not a physical response. Adding salt (mobile ions) alleviates it by providing charge carriers that can redistribute to screen the membrane dipole without forcing bulk water to order.</p> <h3 id="references">References</h3> <ul> <li>B. Roux, “The membrane potential and its representation by a constant electric field in computer simulations,” <em>Biophys. J.</em> <strong>95</strong>, 4205-4216 (2008).</li> <li>J. Gumbart, F. Khalili-Araghi, M. Sotomayor, B. Roux, “Constant electric field simulations of the membrane potential illustrated with simple systems,” <em>BBA - Biomembranes</em> <strong>1818</strong>, 294-302 (2012).</li> <li>M.O. Jensen, V. Jogini, M.P. Eastwood, D.E. Shaw, “Atomic-level simulation of current-voltage relationships in single-file ion channels,” <em>J. Gen. Physiol.</em> <strong>141</strong>, 619-632 (2013).</li> <li>W. Kopec, V. Gapsys, “Periodic boundaries in molecular dynamics simulations: why do we need salt?,” (2026).</li> </ul>]]></content><author><name></name></author><category term="methods"/><category term="membrane potential"/><category term="GROMACS"/><category term="electrostatics"/><category term="molecular dynamics"/><category term="computational electrophysiology"/><summary type="html"><![CDATA[How the -correct flag works, its mathematical basis, and what the tool actually computes in simulations with an applied electric field.]]></summary></entry></feed>