SurfPlan
Compute solvent-accessible surface area using various algorithms.
Constructor
from warp_md import SurfPlan
plan = SurfPlan(
selection,
algorithm="bbox",
probe_radius=1.4,
n_sphere_points=64
)
Atoms to compute surface area for
Algorithm to use:
"bbox": Fast bounding box approximation
"sasa": Accurate SASA using sphere point sampling
Solvent probe radius in Å (1.4 for water)
Number of points for sphere sampling (only for algorithm="sasa")
run() Method
Returns: 1D array of surface area values in Ų (one per frame)
Example
import warp_md as wmd
import matplotlib.pyplot as plt
system = wmd.System("protein.pdb")
traj = wmd.open_trajectory("md.xtc", system)
# Calculate protein SASA
protein = system.select("protein")
# Fast approximation
plan_fast = wmd.SurfPlan(protein, algorithm="bbox")
sasa_fast = plan_fast.run(traj, system)
# Accurate SASA
plan_accurate = wmd.SurfPlan(
protein,
algorithm="sasa",
probe_radius=1.4,
n_sphere_points=128
)
sasa_accurate = plan_accurate.run(traj, system)
# Compare methods
plt.figure(figsize=(10, 4))
plt.subplot(1, 2, 1)
plt.plot(sasa_fast, label="BBox")
plt.plot(sasa_accurate, label="SASA", alpha=0.7)
plt.xlabel("Frame")
plt.ylabel("Surface Area (Ų)")
plt.legend()
plt.title("Total Protein SASA")
plt.subplot(1, 2, 2)
plt.scatter(sasa_fast, sasa_accurate, alpha=0.5)
plt.xlabel("BBox (Ų)")
plt.ylabel("Accurate SASA (Ų)")
plt.title("Method Comparison")
plt.tight_layout()
plt.show()
print(f"Mean SASA: {sasa_accurate.mean():.1f} Ų")
print(f"SASA range: {sasa_accurate.min():.1f} - {sasa_accurate.max():.1f} Ų")
Use algorithm="bbox" for quick screening. Use algorithm="sasa" with higher n_sphere_points for publication-quality results.
MolSurfPlan
Compute molecular surface (Richards surface) instead of SASA.
Constructor
plan = MolSurfPlan(
selection,
probe_radius=1.4,
n_sphere_points=128
)
Atoms to compute molecular surface for
Difference: SASA vs Molecular Surface
- SASA (SurfPlan): Traces the center of the probe sphere as it rolls over the molecule
- Molecular Surface (MolSurfPlan): Actual contact surface + reentrant surface
Example
# Compare SASA and molecular surface
protein = system.select("protein")
sasa_plan = wmd.SurfPlan(protein, algorithm="sasa", probe_radius=1.4)
sasa = sasa_plan.run(traj, system)
molsurf_plan = wmd.MolSurfPlan(protein, probe_radius=1.4)
molsurf = molsurf_plan.run(traj, system)
print(f"SASA: {sasa.mean():.1f} Ų")
print(f"Molecular surface: {molsurf.mean():.1f} Ų")
print(f"Ratio: {sasa.mean() / molsurf.mean():.2f}")
Per-Residue SASA Example
import numpy as np
import pandas as pd
# Calculate SASA for each residue
atom_table = system.atom_table()
resids = np.unique(atom_table["resid"])
residue_sasa = []
for resid in resids:
residue_sel = system.select(f"resid {resid}")
plan = wmd.SurfPlan(residue_sel, algorithm="sasa")
sasa_values = plan.run(traj, system)
residue_sasa.append({
"resid": resid,
"mean_sasa": sasa_values.mean(),
"std_sasa": sasa_values.std()
})
df = pd.DataFrame(residue_sasa)
print(df.head(10))
# Plot residue SASA
import matplotlib.pyplot as plt
plt.bar(df["resid"], df["mean_sasa"], yerr=df["std_sasa"])
plt.xlabel("Residue ID")
plt.ylabel("SASA (Ų)")
plt.title("Per-Residue Solvent Accessibility")
plt.show()
Python Helper Functions
from warp_md.analysis import surf, molsurf
# High-level SASA calculation
sasa_values = surf(
traj,
system,
mask="protein",
probe_radius=1.4,
n_sphere_points=128
)
# Molecular surface
molsurf_values = molsurf(
traj,
system,
mask="protein",
probe_radius=1.4
)
SASA is widely used in protein folding and binding studies. Buried surface area upon binding can be calculated by:buried_area = sasa_protein + sasa_ligand - sasa_complex