Algorithm
Overview
MembraneCurvature calculates mean and Gaussian curvature of surfaces derived from atoms of reference in five steps:
A summary of the algorithm used in MembraneCurvature is shown in the following diagram:
1. Select atoms of reference
The first step in the algorithm is defining the reference atoms with the select
parameter. MembraneCurvature builds on the MDAnalysis
selection to create an AtomGroup of reference, which is
then used to derive surfaces.
For biological membranes, lipid headgroups are commonly used as reference atoms.
2. Choose surface method
To derive surfaces from the reference atoms, MembraneCurvature
has three methods available, selected via the surface_method argument:
2.1 Fourier method (
surface_method='fourier') - DefaultA truncated 2D Fourier series is fitted to atom heights by linear least squares at each frame. Partial derivatives are evaluated analytically from the fitted series on the same grid as the binning method, avoiding finite-difference discretization error. See
fourier_surfacefor details.2.2. Binning method (
surface_method='binning')Atoms are assigned to bins on a regular grid and the height at each bin centre is set to the mean \(z\)-coordinate of the atoms in that bin. Partial derivatives are estimated numerically from the discrete height field using
numpy.gradient()with the physical bin spacing. Seebinning_surfacefor details.2.3. Binning nearest method (
surface_method='binning_nearest')Grid corners are placed on a regular grid and the height at each grid corner is set to the \(z\)-coordinate of the nearest lipid in the \(xy\) plane. Partial derivatives are estimated numerically from the discrete height field using
numpy.gradient()with the physical bin spacing. Seebinning_nearest_surfacefor details.
2.1 Fourier method
surface_method='fourier' is the default method used in Membrane Curvature.
The Fourier method fits a truncated periodic 2D Fourier series to atom heights
by linear least squares at each frame.
The truncation is controlled by fourier_m and fourier_n.
The basis is periodic on the fitted domain with periods \(L_x\) and
\(L_y\) from x_range and y_range, by default matching the simulation box.
Hence, the fitted surface is consistent with periodic boundary conditions in
\(x\) and \(y\).
Note that wrap, padding, and fft_filter are not used with the Fourier method.
wrap defaults to False. Setting wrap=True, padding=True, or an
fft_filter dictionary raises ValueError. Periodicity is handled by
the Fourier basis itself.
The Fourier expansion used as a basis is given by:
where the retained mode set \(\mathcal{M}\) is the non-redundant list built by
fourier_mode_list():
where \(M_{\max}\) and \(N_{\max}\) are set by fourier_m and
fourier_n. The mean term \(A_{00}\) corresponds to
\((m,n)=(0,0)\) and is kept outside the sum.
Here, \(k_x\) and \(k_y\) are the fundamental wavevector components:
so the phase for mode (m,n) is
The Fourier method in MembraneCurvature is conceptually related to Fourier surface modeling [CAG2009] and molecular Fourier shape descriptors [JMG1988], but it is not a direct implementation of either paper. The least-squares height-field fit used in MembraneCurvature is tailored to the AtomGroup of reference given their coordinates.
Shen et al., Fourier method for large-scale surface modeling and registration, Computers & Graphics (2009), doi: 10.1016/j.cag.2009.03.002.
Leicester et al., Description of molecular surface shape using Fourier descriptors, Journal of Molecular Graphics (1988), doi: 10.1016/0263-7855(88)85008-2.
The full Fourier surface workflow comprises six steps. The first four build and
solve a linear model that reconstructs the height field from plane-wave basis
functions. The final two evaluate the fitted surface and its derivatives
analytically on a grid of bin centres. In the following sections, we describe the
overall workflow implemented in MembraneCurvature. For details on each step and
the associated functions, see the API documentation in
fourier_surface.
2.1.1 Choose Fourier modes
The first step is to choose a non-redundant set of Fourier modes with
fourier_mode_list() and determine the
total parameter count with n_fourier_parameters().
This removes conjugate redundancy for real-valued surfaces and isolates the
mean term.
MembraneCurvature builds the mode list and parameter count from fourier_m
and fourier_n, then validates that the
AtomGroup of reference contains at least that
many atoms and raises a ValueError if the selection is too small.
Warning
The explanation above is for the users to understand how MembraneCurvature builds the mode list and parameter count internally.
Do not pass the mode list fourier_mode_list()
or parameter count n_fourier_parameters()
directly. MembraneCurvature builds them internally.
Users choose the Fourier truncation via the constructor arguments fourier_m and fourier_n.
By passing the maximum mode indices, MembraneCurvature builds the actual mode list and computes the total
parameter count.
Important
Because the derivatives are analytic, the Fourier method is not subject
to finite difference discretization error from the bin grid. Curvature
still depends on the Fourier series truncation: use
fourier_m = fourier_n = 2 unless shorter wavelengths are required, and
increase these values only while curvature improves systematically rather than
becoming dominated by noise.
2.1.2 Compute wavevectors
For each retained mode, _compute_wavevector()
computes the wavevector components that set the phase
\(\phi_{mn} = k_x m x + k_y n y\) in the cosine and sine basis functions.
2.1.3 Build design matrix
_build_fourier_matrix() builds the
design matrix \(\mathbf{\Phi}\) with shape \((N,P)\). Here,
\(N\) is the number of atoms in the
AtomGroup of reference, and
\(P = 1 + 2\,n_{\text{modes}}\) is the number of Fourier parameters.
The design matrix \(\mathbf{\Phi}\) is a matrix of shape \((N, P)\) where
\(N\) is the number of atoms in the AtomGroup
of reference, and \(P\) is the number of parameters. \(P\) is defined
as \(P = 1 + 2\,n_{\text{modes}}\) where \(n_{\text{modes}}\) is the number of
the \(k\) retained Fourier modes.
We can conceptualize \(\mathbf{\Phi}\) as a matrix with rows corresponding to atom positions and columns corresponding to the basis functions (cosine and sine of the wavevector \(k\)) evaluated at each atom position, so that the fitted heights satisfy the linear system of equations \(\mathbf{z} \approx \mathbf{\Phi}\,\boldsymbol{\theta}\), from which we can solve for the Fourier coefficients by solving a least-squares system.
A single row \(i\) of \(\mathbf{\Phi}\) for an atom at \(\mathbf{r}_i=(x_i,y_i)\) has the form:
With this formulation, we can solve for the Fourier coefficients by solving a least-squares system:
where \(\boldsymbol{\theta}\) is the vector of Fourier coefficients. These coefficients are the ones we use to reconstruct the height field and calculate the derivatives.
Note that the column ordering follows the mode list returned by
fourier_mode_list(). For each retained
mode (m,n) the design matrix contains a cosine column then a sine column,
so columns appear as 1, cos_{(m1,n1)}, sin_{(m1,n1)}, cos_{(m2,n2)}, sin_{(m2,n2)}, ....
Important
In summary:
The design matrix \(\mathbf{\Phi}\) has shape \((N, P)\) where rows (\(N\)) are atoms
and columns (\(P\)) are the basis functions. \(N\) is the number of atoms in the
AtomGroup of reference. \(P\) is the total number of parameters:
which is the sum of one constant column (the mean term \(A_{00}\)) plus two columns for each retained Fourier mode (one for cosine and one for sine).
2.1.4 Solve least-squares system
MembraneCurvature solves for the Fourier coefficients with
_fourier_fit_from_atoms(), which
calls _solve_design_least_squares_svd().
The latter function solves the linear least-squares system via truncated SVD.
This function solves the least-squares system for the Fourier coefficients and splits the solution
vector into the mean term \(A_{00}\) and the per-mode amplitudes \(A_{mn}\) and \(B_{mn}\)
with _unpack_coefficients().
The returned coefficients are then used to evaluate the fitted height and its
analytic derivatives on the bin-centre mesh via _eval_fourier_surface().
The Fourier coefficients are obtained by linear least squares. The coefficients are obtained by minimizing the residual sum of squares between the observed heights and the fitted heights:
via truncated SVD with _solve_design_least_squares_svd().
Because the model is linear in
\(\boldsymbol{\theta}\), no nonlinear optimisation is required.
If the effective rank of \(\mathbf{\Phi}\) is smaller than \(P\),
a UserWarning is emitted. The truncated-SVD solver still returns a well-defined
minimum-norm least-squares solution, but the coefficients are not uniquely
determined by the data.
Overall, truncated SVD lets us fit the best surface even when the data can’t uniquely determine every Fourier coefficient, and it reduces noise amplification in modes that are not well-determined by the data.
2.1.5 Evaluate fitted surface
With the fitted coefficients, MembraneCurvature evaluates the height field on a
grid of bin centres with
_eval_fourier_surface(). The output
surface has shape (n_x_bins, n_y_bins), matching the binning method grid.
2.1.6 Evaluate analytic derivatives
The same evaluation also returns the analytic first and second partial derivatives of the fitted series, \(\partial_x\), \(\partial_y\), \(\partial_{xx}\), \(\partial_{yy}\), and \(\partial_{xy}\), used for Monge-gauge curvature. These derivatives are exact for the fitted truncated series; they are not subject to finite-difference discretization error. Curvature accuracy still depends on how well that truncated series represents the atom heights.
2.2. Binning method
The binning method derives a surface by partitioning the simulation box into
a regular n_x_bins x n_y_bins grid along the \(x\) and
\(y\) directions. For each bin we compute the average \(z\) coordinate
of the atoms that fall inside the bin to form the discrete height field.
The resulting discrete height field is then differentiated numerically
using numpy.gradient() to obtain the partial derivatives required for
curvature calculation. Set surface_method='binning' explicitly to use
this method. It requires no additional parameters beyond the grid dimensions.
Internally, get_z_surface()
constructs the surface array from the coordinates of the
AtomGroup of reference.
In the next subsections, we describe the details of the binning method.
2.2.1. Set grid
The dimensions of the grid are determined by the size of the simulation box
contained in the Universe.
The grid covers a rectangular domain in the membrane plane. By default that
domain matches the x and y edges of the simulation box from MDAnalysis’
Universe. The grid comprises n_x_bins x n_y_bins
bins along the x and y directions. Note that the user can define the number of
bins via the n_x_bins and n_y_bins arguments.
For every atom in the AtomGroup of reference,
MembraneCurvature assigns it to a grid cell based on its x and y coordinates.
In practice, each coordinate pair (x, y) is mapped to a grid location
[l, m] corresponding to a bin in the discretized membrane surface.
Here, \(L_x\) and \(L_y\) denote the size of the simulation box in the
x and y directions, respectively, while the size of the region covered by
the grid is represented by x_range and y_range, along the x and y
directions, respectively. The spacing between grid points in each direction is
then determined by dividing these lengths by the number of bins.
Note
Unless the user provides a different input, MembraneCurvature will determine
the dimensions of the grid based on the size of the box on the first frame via
dimensions.
grid_dimension_x = (0, universe.dimensions[0])
grid_dimension_y = (0, universe.dimensions[1])
2.2.2. Populate grid
Once the grid has been set, get_z_surface()
assigns the reference atoms to grid cells and collects their \(z\) coordinates
to construct the array of the height field.
Coordinates are converted to integer bin indices via scale factors
Reference atoms are assigned to the 2D grid by mapping their \(x\) and \(y\) coordinates to integer bin indices. The scale factor converts coordinates from length units into bin units so that flooring gives an integer index:
and similarly for \(y\). The function accumulates the \(z\) coordinates
and atom counts for each valid cell with numpy.add.at().
Atoms that map outside the valid bin range
(negative indices or indices ≥ n_x_bins/n_y_bins) are skipped. A
warning is issued reporting how many atoms fall outside the grid boundaries.
To populate the grid, MembraneCurvature wraps
\(x\) and \(y\) of the reference AtomGroup
into the unit cell when wrap=True, the default value for
surface_method='binning', while leaving \(z\) unchanged. Internally this
calls wrap() and then restores the
original \(z\) coordinates.
Finally, normalized_grid() divides
the accumulated \(z\) coordinates by the number of atoms in each bin.
Empty bins have zero counts, which are replaced with numpy.nan.
Trajectory averages use numpy.nanmean() and ignore empty bins.
Warning
The binning routine itself does not wrap \(x\) and \(y\) coordinates!
MembraneCurvature wraps only when wrap=True is set.
Set
wrap=Trueto wrap atoms back into the grid in \(x\) and \(y\) if you are calculating curvature on a raw trajectory. Heights in \(z\) are preserved.Set
wrap=Falseto leave atoms outside the primary cell in \(x\) and \(y\) out of the bins when you are calculating curvature on:a trajectory (membrane only or membrane-protein with position restraints) that already pre-processed periodic boundary conditions.
a membrane-protein system that already pre-processes rotational and translational fit for the protein.
Note that with padding=True, periodic images in \(x\) and \(y\) are tiled into the
buffer even if wrap=False, so the usual wrap == False warning is not triggered.
2.3. Binning nearest method
The binning nearest method derives a surface by assigning the \(z\) coordinate
of the nearest lipid in the \(xy\) plane. In contrast to the binning method, the
\(z\) coordinate is assigned to each grid corner rather than the bin centre.
However, partial derivatives are estimated identically to the binning method, by
numerically differentiating the discrete height field using numpy.gradient()
with the physical bin spacing.
2.3.1. Set grid
With the binning nearest method, the grid is set from the simulation box in a
similar way to the binning method (2.2.1. Set grid). By default,
get_z_surface_nearest()
builds an n_x_bins x n_y_bins grid that spans the \(x\) and
\(y\) dimensions of the MDAnalysis Universe.
The difference is where the height field is sampled. Sample points sit at bin corners along each axis, rather than at bin centres.
As a result, for the same bin counts and box extent, the binning nearest method grid is
offset by half a bin relative to the binning and fourier methods.
Unlike the binning method, grid_origin can also determine the grid extent.
With grid_origin='box' by default, the domain matches the simulation box.
With grid_origin='lipid_bbox', the domain is the axis-aligned bounding box
of the lipid reference points. Users can provide x_range and y_range to
override the grid extent.
2.3.2. Populate grid
Once the corner grid has been set,
get_z_surface_nearest()
assigns every sample point the \(z\) coordinate of its nearest lipid in the
\(xy\) plane to form the height field.
The lipid reference points are built from the selected
AtomGroup with
lipid_center_positions().
For every bin corner, MembraneCurvature finds the nearest lipid reference point
in the \(xy\) plane among all lipids in the selection, using
distance_array() with the simulation box. The corner
then receives the \(z\) of that lipid. Unlike the binning method, there is no
averaging over lipids within a cell: only the nearest lipid is considered, and membership
in a bin does not decide which lipids contribute.
Important
Unlike the binning method, every sample point on the grid is assigned a value.
As a result, the height field contains no empty bins and therefore no
NaN values.
Note
wrap=True is not valid with surface_method='binning_nearest'.
MembraneCurvature sets wrap to False for this method. Periodic boundary
conditions are handled when calculating distances between grid corners and lipid
reference points, rather than by wrapping atoms into the primary cell.
3. Derive surfaces per frame
For every frame of the trajectory, the surface derived from the
AtomGroup and according to the surface method selected ('fourier', 'binning',
or 'binning_nearest') is calculated and stored in the attribute
z_surface.
Common to all methods is that the surface is derived from atom positions using the selected method
and stored in z_surface for each frame.
However, the details of the surface derivation are different for each one of the three methods.
These per-frame surface arrays are fundamental to the calculation of mean and Gaussian curvature since they are the input for the two available paths to calculate curvature: by averaging the per-frame curvature maps over the trajectory, or by calculating curvature once from the trajectory-averaged surface.
In the following sections, we describe the details of surface derivation according to the selected method.
4. Calculate curvature
MembraneCurvature stores the surface, mean curvature, and Gaussian
curvature calculated for every frame of the trajectory. The parameter
curvature_on determines how the average mean and
Gaussian curvature maps are calculated:
4.A. Per frame (curvature_on='per_frame') - Default
The mean and Gaussian curvature maps are averaged over all frames.
\(H = \langle H \rangle\), and \(K = \langle K \rangle\).
Note
For backward compatibility, passing
curvature_on=Noneis equivalent tocurvature_on='per_frame'.4.B Average surface (curvature_on='average_surface')
Mean and Gaussian curvature are calculated from the average surface array.
\(H = H (\langle S \rangle)\), and \(K = K(\langle S \rangle)\).
The curvature calculated for every frame is stored in MembraneCurvature.results.mean and
MembraneCurvature.results.gaussian.
The final average curvature maps are stored in MembraneCurvature.results.average_mean and
MembraneCurvature.results.average_gaussian.
Important
Both paths require the same partial derivatives to calculate mean and Gaussian curvature.
With
curvature_on='per_frame', derivatives are calculated from the surface array at every frame.With
curvature_on='average_surface', derivatives are calculated from the average surface array \(\langle S \rangle\).
How \(\langle S \rangle\) is built, and how its derivatives are obtained,
depends on the
surface_method parameter:
With
binningandbinning_nearest, \(\langle S \rangle\) is the time average of the per-frame height fields. Partial derivatives use finite differences on that averaged array.With
fourier, MembraneCurvature averages the per-frame Fourier coefficients \(\boldsymbol{\theta}\) and rebuilds \(\langle S \rangle = S(\langle\boldsymbol{\theta}\rangle)\). Partial derivatives are evaluated analytically from that averaged series.
For more details on the calculation of partial derivatives, see section 4.1 Calculate derivatives.
In the following sections, we describe the details of the two paths to calculate curvature.
4.A. Per frame (curvature_on='per_frame')
With curvature_on='per_frame', the per-frame mean and Gaussian curvature arrays are averaged over
the trajectory. The resulting average maps are \(\langle H \rangle\) and \(\langle K \rangle\).
For every frame, mean and Gaussian curvature are derived from the surface arrays obtained in
3. Derive surfaces per frame and stored in the attributes
MembraneCurvature.results.mean and MembraneCurvature.results.gaussian, respectively.
Both arrays have shape (n_frames, n_x_bins, n_y_bins).
4.B Average surface (curvature_on='average_surface')
With curvature_on='average_surface', MembraneCurvature calculates
mean and Gaussian curvature once from the average surface, \(\langle S \rangle\).
How \(\langle S \rangle\) is obtained depends on surface_method:
With
binningorbinning_nearest, \(\langle S \rangle\) is the time average of the per-frame height fields stored inMembraneCurvature.results.z_surface. Partial derivatives are estimated withnumpy.gradient()on that averaged array.With
fourier, MembraneCurvature accumulates the per-frame Fourier coefficient vectors \(\boldsymbol{\theta}\), averages the frames that produce finite coefficients to \(\langle\boldsymbol{\theta}\rangle\), and rebuilds the height field and its analytic derivatives from those averaged coefficients. Because the Fourier height is linear in \(\boldsymbol{\theta}\),\[\langle S \rangle = S(\langle\boldsymbol{\theta}\rangle).\]The average surface and curvature therefore come from the same averaged coefficients, so derivatives remain analytic.
The resulting maps, \(H = H(\langle S \rangle)\) and \(K = K(\langle S \rangle)\), are stored in
MembraneCurvature.results.average_mean and MembraneCurvature.results.average_gaussian,
respectively. Both arrays have shape (n_x_bins, n_y_bins).
4.1 Calculate derivatives
To calculate mean and Gaussian curvature, MembraneCurvature first obtains the partial derivatives of the surface array.
Regardless of curvature_on, mean and Gaussian curvature are then
calculated using the Monge gauge equations.
These equations require the first derivatives \(\partial_x\) and \(\partial_y\), the second derivatives \(\partial_{xx}\) and \(\partial_{yy}\), and the mixed derivative \(\partial_{xy}\).
Important
The binning methods and the Fourier method calculate derivatives differently.
With the binning methods (
'binning'and'binning_nearest'), the derivatives are estimated numerically from the discrete height field usingnumpy.gradient()with the physical spacings \(\Delta x\) and \(\Delta y\). Curvature values are therefore expressed in physical units.With the Fourier method, the derivatives are evaluated analytically from the fitted Fourier series, so they are not subject to finite-difference discretization error. Curvature accuracy instead depends on how well the truncated Fourier series fits the atom heights.
Therefore, curvature accuracy is limited differently by each derivative path: the binning methods are sensitive to finite-difference error on the height grid, while the Fourier method is sensitive to the Fourier truncation and fit to the atom data.
4.1.1 Binning + finite differences (surface_method='binning' or surface_method='binning_nearest')
With surface_method='binning' or surface_method='binning_nearest', partial derivatives are estimated
numerically from the discrete height field using numpy.gradient() with the physical spacings
\(\Delta x\) and \(\Delta y\).
Curvature values are therefore expressed in physical units.
Note
MembraneCurvature passes the physical grid spacing (dx, dy) to numpy.gradient().
Therefore, changes in height are measured per unit distance in the simulation box rather than per
grid index, and curvature is calculated in physical units. However, very coarse grids may still
introduce finite-difference discretization error.
Warning
When calculating derivatives, finite differences can introduce artifacts at the edges of the simulation, where neighboring grid cells are unavailable. To reduce these artifacts, MembraneCurvature provides optional periodic edge padding (see Edge padding (padding)).
For details on the binning methods, see API documentation in
binning_surface and binning_nearest_surface
that describe the implementation of each method.
4.1.2. Fourier fit + analytic derivatives (surface_method='fourier')
With surface_method='fourier', the partial derivatives are evaluated analytically from the
fitted Fourier series.
Therefore, with the Fourier method, the partial derivatives are not subject to finite-difference
discretization error. Curvature accuracy instead depends on how well the truncated Fourier series
represents the atom heights.
Note
Because no finite-difference step is involved, the analytic derivatives are exact for the fitted truncated series, regardless of grid resolution. Curvature accuracy still depends on the truncation and the fit to the atom heights.
For details on the Fourier method, see API documentation in
fourier_surface.
Mean curvature
Mean curvature \(H\) is calculated from the five partial derivative arrays using the Monge-gauge formula:
Mean curvature is expressed in units of Å-1.
Gaussian curvature
Gaussian curvature \(K\) is calculated from the same derivative arrays using:
via gaussian_curvature_monge().
Gaussian curvature is expressed in units of Å-2.
5. Generate output arrays
In this last step, MembraneCurvature generates the
output arrays, which take the shape (n_x_bins, n_y_bins) and are stored in:
MembraneCurvature.results.average_z_surface- for the average surface.MembraneCurvature.results.average_mean- for the average mean curvature.MembraneCurvature.results.average_gaussian- for the average Gaussian curvature.
How the average curvature maps are obtained depends on curvature_on:
With
curvature_on='per_frame', the average curvature maps are the time averages of the per-frame curvature arrays:\[\mathrm{average\_mean} = \langle H \rangle, \qquad \mathrm{average\_gaussian} = \langle K \rangle.\]With
curvature_on='average_surface', mean and Gaussian curvature are calculated from the average surface:\[\mathrm{average\_mean} = H(\langle S \rangle), \qquad \mathrm{average\_gaussian} = K(\langle S \rangle).\]Note
For
surface_method='fourier', the average surface is \(S(\langle\boldsymbol{\theta}\rangle)\) as described in 4.B Average surface (curvature_on='average_surface').
Important
curvature_on='per_frame'preserves the mean contribution of instantaneous thermal fluctuations.curvature_on='average_surface'reduces the contribution of transient thermal fluctuations and emphasizes persistent surface features.
For both paths, MembraneCurvature.results.average_z_surface stores
\(\langle S \rangle\): the time average of per-frame height fields for
the binning methods, or \(S(\langle\boldsymbol{\theta}\rangle)\) for
fourier.
Optional Parameters
Edge padding (padding)
Padding is an optional step that mitigates finite-difference artifacts at the grid edges.
These artifacts are particularly pronounced for Gaussian curvature, where second-order
derivatives amplify edge effects. Because padding is intended to reduce finite-difference
artifacts, it is only available for surface_method='binning' and
surface_method='binning_nearest'.
Warning
The padding option is only available for orthorhombic boxes only. Tilted or triclinic boxes need lattice-vector replicas and are not supported. Running padding with other than orthorhombic boxes will raise an error.
When padding=True, the primary grid is expanded by a periodic buffer on each side.
The buffer width is set by the parameter edge_pad_bins.
The width of the periodic buffer is set to:
By default edge_pad_bins=2, making the buffer region two bins beyond each edge.
Hence, the expanded grid has shape
\((n_{x\_bins} + 2\,\mathrm{edge\_pad\_bins}) \times (n_{y\_bins} + 2\,\mathrm{edge\_pad\_bins})\).
Mean and Gaussian curvature are evaluated on that padded height field, and the
buffer is clipped back to the primary grid with
clip_padded_grid(). The returned arrays have
shape (n_x_bins, n_y_bins), matching the primary grid size.
Note
How the padded domain box + Δ is filled depends on the
surface_method:
With
surface_method='binning', periodic atom images are tiled into the buffer withtile_xy_buffer(), then binned withget_z_surface_padded(). Curvature is evaluated withcurvature_with_edge_pad().With
surface_method='binning_nearest', the primary surface is built first withget_z_surface_nearest(). That height field is wrap-padded and used to evaluate curvature withcurvature_from_primary_with_edge_pad().
The padding approach supplies edge and corner cells with periodic neighbors for
numpy.gradient(), which reduces finite difference artifacts that are
particularly visible in second derivatives for Gaussian curvature.
First derivatives use neighbouring bins, and second derivatives apply
numpy.gradient() again, so each sample depends on values up to two bins
away. Padding by two bins (edge_pad_bins=2) is therefore sufficient to
evaluate derivatives at the boundaries of the primary grid. Values of
edge_pad_bins above 4 are unlikely to change curvature and mainly
increase computational cost.
Since padding alone is usually enough to reduce edge artifacts, fft_filter is not
needed for that purpose. Using both optional parameters is possible. In that case,
MembraneCurvature first filters the time-averaged surface, then calculates
average curvature from the filtered surface. At that stage the buffer is added
around the filtered surface itself, not by adding periodic copies of the atoms.
See Brick-wall FFT filtering (fft_filter) for details.
Brick-wall FFT filtering (fft_filter)
Brick-wall FFT filtering is an optional step that can reduce high-frequency noise in the averaged
surface. It is available for surface_method='binning' and surface_method='binning_nearest',
and it is controlled with the fft_filter argument.
By default, fft_filter=None and no filter is applied. Set fft_filter='auto' to use the
default low-pass band (0, 0.5 * q_Nyq), derived from dx and dy. To set the pass band
manually, pass a dictionary such as {'q': (q_low, q_high)} in rad/Å.
The filter is applied to the time-averaged surface after all frames have been processed.
Important
The FFT filter is not applied to per-frame surfaces. Filtering is performed on the time-averaged height field, where thermal fluctuations have already been suppressed by averaging.
For both the 'auto' and manual modes, the pass-band limits are resolved at construction time via
resolve_fft_filter() and applied at the end of the run with
apply_fft_filter(). See
fft_filtering for more details.
When filtering is enabled, MembraneCurvature
averages the height field in
z_surface over the
trajectory. It then smooths that average in reciprocal space by zeroing Fourier
modes outside the pass band
\(q_{\mathrm{low}} \leq |q| \leq q_{\mathrm{high}}\) with
apply_fft_filter(), and transforms back
to real space. The filtered surface is stored in
average_z_surface.
With fft_filter='auto', the pass band is
\((0,\ 0.5\,q_{\mathrm{Nyq}})\). This conservative low-pass keeps the
large-scale membrane shape while suppressing short-wavelength noise.
If curvature_on is not provided, enabling fft_filter selects
curvature_on='average_surface'. In that path, mean and Gaussian curvature
are calculated from the filtered average surface. If padding=True as well,
a periodic buffer is added around that filtered average surface before mean
and Gaussian curvature are calculated, then clipped back to the primary grid.
With an explicit curvature_on='per_frame', the filtered surface is still
stored in average_z_surface, but the average curvature maps remain the
time averages of the per-frame curvature arrays.
Warning
For surface_method='binning', empty bins are temporarily filled with the
mean height of occupied bins before the FFT, then restored to NaN after
the inverse FFT. Large empty regions can introduce broadband spectral
contamination and distort the filtered surface near gaps. Prefer denser
binning or smaller empty regions when filtering is enabled.
surface_method='binning_nearest' does not leave empty-bin NaN values
in the height field, so this fill step does not arise there.
Note
The pass-band mask is isotropic in \(|q|\). For non-square bins
(\(\Delta x \neq \Delta y\)), modes that are resolvable along the finer
axis but exceed
\(q_{\mathrm{Nyq}} = \min(\pi/\Delta x,\, \pi/\Delta y)\) are removed.
Because numpy.fft.fft2() treats the grid as periodic, prefer
wrap=True with surface_method='binning' on raw trajectories with
periodic boundaries. wrap=True is not valid with
surface_method='binning_nearest'.














