This script, implemented as a PyMOL command, quantifies and characterizes the interface between polypeptide chains in a macromolecular structure. Solvent-accessible surface area (SASA) is computed from van der Waals radii with a 1.4 Å probe sphere, using the dot-based algorithm implemented in PyMOL (10.1016/0022-2836(73)90011-9; 10.1016/0022-2836(71)90324-x).
SASA is evaluated per atom for each chain in isolation and for each chain pair in the complex, after removing solvent, heteroatoms, hydrogens and alternative conformations. The buried surface area (BSA) is defined as SASA_A + SASA_B − SASA_AB, and the interface area as BSA/2, i.e. the mean area buried per partner.
Per-atom differences in SASA (ΔSASA) are then partitioned into polar (N, O) and apolar contributions, and residues with ΔSASA > 0.1 Ų are assigned to the interface and classified as core, support or rim from their relative accessibility in the monomer and in the complex (Levy, 2010; reference maximum accessibilities from Tien et al., 2013).
Polar contacts (N/O pairs ≤ 3.5 Å) and salt bridges (≤ 4.0 Å) are counted as distance-based descriptors. For PDB entry 6P8E, the A–B interface buries ≈ 1,994 Ų in total (≈ 997 Ų per partner; ≈ 7.2% of each chain's accessible surface) and involves 59 residues. This size is within the range reported for stable biological protein–protein complexes (10.1006/jmbi.1998.2439). Its composition is predominantly apolar (≈ 65%, compared with ≈ 53% for the isolated chains' surfaces), with few polar contacts (13 N/O pairs and one salt bridge), which is consistent with an interface stabilized mainly by hydrophobic burial.
These values derive from a static structure and depend on the radii, probe size and sampling density used; they should therefore be compared only with results obtained under identical settings, and not directly with those of other programs such as PISA.

"""
calc_interface_area.py
============================
Protein-protein interface analysis in PyMOL.
USAGE (in the PyMOL console):
run calc_interface_area_v3_en.py
calc_interface_area obj01
calc_interface_area obj01, chains=A+B, csv_path=interface.csv
calc_interface_area obj01, polar=N+O+S, remove_h=0
calc_interface_area obj01, area_basis=totals
FORMULAS
--------
BSA (buried surface area) = SASA(A) + SASA(B) - SASA(AB)
Interface area = BSA / 2
dSASA of an atom/residue = SASA in isolation - SASA in the complex
Polar/apolar = sum of per-atom dSASA (exact partition:
polar + apolar == BSA, no sampling noise)
CONSISTENCY CHECK (new in v3)
-----------------------------
PyMOL offers two ways of obtaining an area: the total returned by get_area and
the sum of the per-atom values it stores in the B-factor column (load_b=1).
In principle they agree. The script computes the BSA both ways, checks that
every atom of the isolated chains has a counterpart in the complex and that no
two atoms share the same key (chain, segi, resi, name), and prints the
difference. If it exceeds "check_tol" (A^2) a WARNING is shown.
With area_basis=atoms (default) ALL figures (BSA, polar/apolar, percentages,
residues) come from the per-atom sum, so they are mutually consistent. With
area_basis=totals, the BSA and percentages use the get_area totals instead.
ASSUMPTIONS AND LIMITATIONS
---------------------------
* Static structure: no water, no flexibility, no conformational change.
* Hydrogens: removed by default before the calculation (remove_h=1), so that
the result does not depend on whether the model has them (e.g. after h_add).
* Alternative conformations (altlocs): only the blank and 'A' ones are kept.
* Only the protein polymer is analysed by default (protein_only=1): ligands,
ions, glycans, water and nucleotides are excluded.
* SASA is computed with PyMOL's van der Waals radii and a 1.4 A probe
(parameter 'probe'). Values are NOT directly comparable with PISA, NACCESS
or FreeSASA; do not mix numbers from different programs.
* Polar = N and O atoms (default). S (Cys/Met) counts as apolar. Use
polar=N+O+S to reproduce the criterion of the earlier version.
* Interface residue: dSASA > 'threshold' (0.1 A^2 by default; permissive).
* Core/rim/support classification (Levy, 2010) with rASA = SASA / theoretical
maximum SASA per residue (Tien et al., 2013), 25 % cut-off. It is
approximate because PyMOL's SASA uses different radii than the original work:
support : rASA in the isolated chain < 25 % (already buried in the monomer)
core : isolated rASA >= 25 % and rASA in the complex < 25 %
rim : rASA in the complex >= 25 % (still exposed)
* Contacts: H-bonds = N/O pairs from different chains at <= 3.5 A (no angular
criterion, so this is an upper bound). Salt bridges = Lys NZ / Arg NE,NH1,NH2
with Asp OD1,OD2 / Glu OE1,OE2 at <= 4.0 A.
* Check that A-B is the biological interface and not a crystal contact: the
script only sees what is in the loaded object (asymmetric unit or assembly).
"""
import csv
import itertools
import re
from pymol import cmd
# Theoretical maximum SASA per residue, in A^2 (Tien et al., 2013)
MAX_ASA = {
"ALA": 129.0, "ARG": 274.0, "ASN": 195.0, "ASP": 193.0, "CYS": 167.0,
"GLN": 225.0, "GLU": 223.0, "GLY": 104.0, "HIS": 224.0, "ILE": 197.0,
"LEU": 201.0, "LYS": 236.0, "MET": 224.0, "PHE": 240.0, "PRO": 159.0,
"SER": 155.0, "THR": 172.0, "TRP": 285.0, "TYR": 263.0, "VAL": 174.0,
}
_POS = {("LYS", "NZ"), ("ARG", "NE"), ("ARG", "NH1"), ("ARG", "NH2")}
_NEG = {("ASP", "OD1"), ("ASP", "OD2"), ("GLU", "OE1"), ("GLU", "OE2")}
CLASS_COLORS = {"core": "red", "support": "orange", "rim": "yellow"}
# ----------------------------------------------------------------------------
# Utilities
# ----------------------------------------------------------------------------
def _flag(x):
"""Convert PyMOL console arguments (strings) to boolean."""
return str(x).strip().lower() in ("1", "true", "yes", "y", "on")
def _resi_number(resi):
m = re.search(r"-?\d+", str(resi))
return int(m.group()) if m else 0
def _residue_selection(pairs):
"""Build a PyMOL selection from [(chain, resi), ...]."""
return " or ".join(f"(chain {c} and resi {r})" for c, r in pairs)
def _measure(obj):
"""
Total SASA of the object and per-atom SASA (stored in the B-factor column
with load_b=1). Returns (total, {atom_key: (sasa, symbol, resn)}, check),
where check = {"sum_b": sum of B over all atoms,
"duplicates": number of atoms with a repeated key}.
"""
total = cmd.get_area(obj, load_b=1)
atoms = {}
sum_b = 0.0
n_atoms = 0
for at in cmd.get_model(obj).atom:
n_atoms += 1
sum_b += at.b
atoms[(at.chain, at.segi, at.resi, at.name)] = (at.b, at.symbol.upper(), at.resn)
return total, atoms, {"sum_b": sum_b, "duplicates": n_atoms - len(atoms)}
def _classify(resn, free, cplx):
"""Levy classification (support / core / rim) with rASA at 25 %."""
maximum = MAX_ASA.get(resn)
if maximum is None:
return "n/a"
r_free = free / maximum * 100.0
r_cplx = cplx / maximum * 100.0
if r_free < 25.0:
return "support"
return "core" if r_cplx < 25.0 else "rim"
def _contacts(model, iface_keys, c1):
"""Count polar N/O contacts <= 3.5 A and salt bridges <= 4.0 A."""
a1, a2 = [], []
for at in model.atom:
if at.symbol.upper() not in ("N", "O"):
continue
if (at.chain, at.resi) not in iface_keys:
continue
(a1 if at.chain == c1 else a2).append(at)
n_hb = 0
salt_bridges = set()
for x in a1:
for y in a2:
d2 = sum((p - q) ** 2 for p, q in zip(x.coord, y.coord))
if d2 <= 3.5 ** 2:
n_hb += 1
if d2 <= 4.0 ** 2:
px, py = (x.resn, x.name), (y.resn, y.name)
if (px in _POS and py in _NEG) or (px in _NEG and py in _POS):
salt_bridges.add(((x.chain, x.resi), (y.chain, y.resi)))
return n_hb, len(salt_bridges)
# ----------------------------------------------------------------------------
# Main function
# ----------------------------------------------------------------------------
def calc_interface_area(obj_name="obj01", chains="", protein_only=1,
remove_h=1, polar="N+O", dot_density=4,
probe=1.4, threshold=0.1, create_object=1,
csv_path="", area_basis="atoms", check_tol=1.0):
"""
Compute interface areas between all chain pairs of an object.
obj_name PyMOL object to analyse
chains chains to consider, e.g. "A+B" (empty = all)
protein_only 1 = polymer.protein only; 0 = everything except solvent
remove_h 1 = remove hydrogens before the calculation
polar elements counted as polar, e.g. "N+O" or "N+O+S"
dot_density SASA dot density (4 = good precision)
probe probe radius in A
threshold minimum dSASA (A^2) for a residue to count as interface
create_object 1 = create an object with the interface residues of each pair
csv_path if given, save a per-residue dSASA table
area_basis "atoms" = figures from the per-atom sum of B (default;
consistent with polar/apolar and residues);
"totals" = BSA from the get_area totals
check_tol maximum difference (A^2) between both BSA values before warning
"""
protein_only = _flag(protein_only)
remove_h = _flag(remove_h)
create_object = _flag(create_object)
dot_density = int(float(dot_density))
probe = float(probe)
threshold = float(threshold)
polar_elems = {e.strip().upper() for e in str(polar).split("+") if e.strip()}
use_atoms = str(area_basis).strip().lower() != "totals"
check_tol = float(check_tol)
# --- locate the object ---------------------------------------------------
names = cmd.get_names("all")
clean = obj_name.strip("()")
if clean in names:
target = clean
elif f"({clean})" in names:
target = f"({clean})"
else:
print(f"Error: '{obj_name}' not found. Available: {names}")
return
# --- preliminary diagnostics ---------------------------------------------
n_h = cmd.count_atoms(f"({target}) and hydro")
n_het = cmd.count_atoms(f"({target}) and hetatm and not solvent")
n_alt = cmd.count_atoms(f"({target}) and not alt ''")
print("\n==================================================================")
print(f" INTERFACE ANALYSIS IN '{target}'")
print("==================================================================")
print(f"Diagnostics: {n_h} H | {n_het} HETATM atoms (non-solvent) | "
f"{n_alt} atoms with altloc")
print(f"Hydrogens: {'removed before the calculation' if remove_h else 'INCLUDED in the calculation'}")
print(f"Atoms considered: {'protein only' if protein_only else 'everything except solvent'}")
print(f"Polar = {'+'.join(sorted(polar_elems))} | probe = {probe} A | "
f"dot_density = {dot_density} | threshold = {threshold} A^2")
if n_het and protein_only:
print(f"Warning: {n_het} HETATM atoms are excluded (ligands, ions, glycans...). "
f"If any lies at the interface, use protein_only=0.")
# --- base selection ------------------------------------------------------
sel_filter = "polymer.protein" if protein_only else "not solvent"
if remove_h:
sel_filter += " and not hydro"
sel_base = f"({target}) and ({sel_filter}) and (alt ''+A)"
all_chains = [c for c in cmd.get_chains(target) if c.strip()]
if str(chains).strip():
requested = [c for c in str(chains).replace(",", "+").split("+") if c.strip()]
chain_list = [c for c in all_chains if c in requested]
else:
chain_list = all_chains
if len(chain_list) < 2:
print(f"'{target}' has fewer than 2 usable chains ({chain_list}).")
return
print(f"Chains analysed: {', '.join(chain_list)}\n")
# --- save settings and compute -------------------------------------------
orig = {k: cmd.get(k) for k in ("dot_solvent", "dot_density", "solvent_radius")}
try:
cmd.set("dot_solvent", 1)
cmd.set("dot_density", dot_density)
cmd.set("solvent_radius", probe)
# 1) isolated chains
free = {}
for c in chain_list:
tmp = f"_tmp_chain_{c}"
cmd.create(tmp, f"{sel_base} and chain {c}")
n_at = cmd.count_atoms(tmp)
if n_at == 0:
print(f" * Chain {c}: no atoms left after filtering; ignored.")
cmd.delete(tmp)
continue
total_get, atoms, chk = _measure(tmp)
total = chk["sum_b"] if use_atoms else total_get
pol = sum(v[0] for v in atoms.values() if v[1] in polar_elems)
free[c] = {"total": total, "total_get": total_get,
"total_b": chk["sum_b"], "dups": chk["duplicates"],
"polar": pol, "apolar": total - pol,
"atoms": atoms, "n": n_at}
print(f" * Chain {c} isolated ({n_at} atoms) -> Total SASA: {total:.2f} A^2 "
f"(Polar: {pol:.2f} A^2 | Apolar: {total - pol:.2f} A^2)")
print(f" check: get_area = {total_get:.2f} | sum of B = "
f"{chk['sum_b']:.2f} | diff = {total_get - chk['sum_b']:+.2f} A^2")
cmd.delete(tmp)
# 2) each chain pair
csv_rows = []
for c1, c2 in itertools.combinations([c for c in chain_list if c in free], 2):
tmp = f"_tmp_pair_{c1}_{c2}"
cmd.create(tmp, f"{sel_base} and (chain {c1} or chain {c2})")
cplx_get, atoms_cplx, chk_cplx = _measure(tmp)
pair_model = cmd.get_model(tmp)
cmd.delete(tmp)
bsa_get = free[c1]["total_get"] + free[c2]["total_get"] - cplx_get
bsa_b = free[c1]["total_b"] + free[c2]["total_b"] - chk_cplx["sum_b"]
bsa = bsa_b if use_atoms else bsa_get
area_tot = bsa / 2.0
if area_tot <= 1.0:
print(f"\n-> Chain {c1} <-> Chain {c2}: no significant contact "
f"({area_tot:.2f} A^2)")
continue
# per-atom dSASA -> polar/apolar and per residue
bsa_pol = bsa_apol = 0.0
unmatched = 0
bsa_chain = {c1: 0.0, c2: 0.0}
residues = {} # (chain, resi) -> dict
for c in (c1, c2):
for key, (b_free, symbol, resn) in free[c]["atoms"].items():
if key not in atoms_cplx:
unmatched += 1
b_cplx = atoms_cplx.get(key, (b_free,))[0]
delta = b_free - b_cplx
bsa_chain[c] += delta
if symbol in polar_elems:
bsa_pol += delta
else:
bsa_apol += delta
rk = (key[0], key[2])
r = residues.setdefault(rk, {"resn": resn, "free": 0.0, "cplx": 0.0})
r["free"] += b_free
r["cplx"] += b_cplx
area_pol = bsa_pol / 2.0
area_apol = bsa_apol / 2.0
total_pa = area_pol + area_apol
pct_pol = area_pol / total_pa * 100.0 if total_pa > 0 else 0.0
pct_apol = area_apol / total_pa * 100.0 if total_pa > 0 else 0.0
pct1 = bsa_chain[c1] / free[c1]["total"] * 100.0
pct2 = bsa_chain[c2] / free[c2]["total"] * 100.0
pct_mean = bsa / (free[c1]["total"] + free[c2]["total"]) * 100.0
# consistency check
sum_deltas = bsa_chain[c1] + bsa_chain[c2]
diff = bsa_get - bsa_b
diff_pct = abs(diff) / abs(bsa_get) * 100.0 if bsa_get else 0.0
dups = free[c1]["dups"] + free[c2]["dups"] + chk_cplx["duplicates"]
print("\n------------------------------------------------------------------")
print(f" CONSISTENCY CHECK: Chain {c1} <-> Chain {c2}")
print("------------------------------------------------------------------")
print(f" * BSA from get_area totals : {bsa_get:.2f} A^2")
print(f" * BSA from per-atom sum of B : {bsa_b:.2f} A^2")
print(f" * Difference (totals - atoms) : {diff:+.2f} A^2 ({diff_pct:.2f} % of BSA)")
print(f" * Sum of per-atom dSASA (A+B) : {sum_deltas:.2f} A^2 "
f"(polar + apolar = {bsa_pol + bsa_apol:.2f} A^2)")
print(f" * Atoms without counterpart in complex: {unmatched} | "
f"atoms with duplicated key: {dups}")
print(f" * Main figures computed from : "
f"{'per-atom sum of B' if use_atoms else 'get_area totals'}")
if abs(diff) > check_tol or unmatched or dups:
print(f" ! WARNING: difference > {check_tol} A^2, unmatched atoms or "
f"duplicated keys. Check the cause before quoting figures.")
else:
print(" -> OK: both calculation routes agree.")
# interface residues and classification
iface = {c1: [], c2: []}
for (c, resi), r in residues.items():
delta = r["free"] - r["cplx"]
if delta > threshold:
r["delta"] = delta
r["cls"] = _classify(r["resn"], r["free"], r["cplx"])
r["resi"] = resi
r["chain"] = c
iface[c].append(r)
csv_rows.append((f"{c1}-{c2}", c, r["resn"], resi,
r["free"], r["cplx"], delta, r["cls"]))
for c in iface:
iface[c].sort(key=lambda r: _resi_number(r["resi"]))
n1, n2 = len(iface[c1]), len(iface[c2])
all_res = iface[c1] + iface[c2]
n_cls = {k: sum(1 for r in all_res if r["cls"] == k)
for k in ("core", "support", "rim", "n/a")}
n_gt1 = sum(1 for r in all_res if r["delta"] > 1.0)
iface_keys = {(r["chain"], r["resi"]) for r in all_res}
n_hb, n_salt = _contacts(pair_model, iface_keys, c1)
print("\n------------------------------------------------------------------")
print(f" INTERFACE: Chain {c1} <-> Chain {c2}")
print("------------------------------------------------------------------")
print(f" * Interface area (BSA/2) : {area_tot:.2f} A^2")
print(f" * Total buried surface area (BSA): {bsa:.2f} A^2 "
f"({c1}: {bsa_chain[c1]:.2f} | {c2}: {bsa_chain[c2]:.2f})")
print(f" * % Surface buried : {pct_mean:.2f} % "
f"(Chain {c1}: {pct1:.2f} % | Chain {c2}: {pct2:.2f} %)")
print("\n Chemical nature (sum of per-atom dSASA):")
print(f" * Polar area ({'+'.join(sorted(polar_elems))})".ljust(36)
+ f": {area_pol:.2f} A^2 ({pct_pol:.2f} %)")
print(f" * Apolar area".ljust(36) + f": {area_apol:.2f} A^2 ({pct_apol:.2f} %)")
print(f"\n Contact extent (residues with dSASA > {threshold} A^2):")
print(f" * Total interface residues : {n1 + n2} "
f"({n_gt1} with dSASA > 1 A^2)")
print(f" * Chain {c1} ({n1} res): "
f"{', '.join(r['resn'] + r['resi'] for r in iface[c1])}")
print(f" * Chain {c2} ({n2} res): "
f"{', '.join(r['resn'] + r['resi'] for r in iface[c2])}")
print("\n Classification (Levy, approximate):")
print(f" * Core: {n_cls['core']} | Support: {n_cls['support']} | "
f"Rim: {n_cls['rim']}"
+ (f" | n/a: {n_cls['n/a']}" if n_cls["n/a"] else ""))
print("\n Specific contacts (heuristic):")
print(f" * Polar N/O pairs <= 3.5 A : {n_hb}")
print(f" * Salt bridges <= 4.0 A : {n_salt}")
# 3) object and selections for visualisation
if create_object:
obj_iface = f"interface_{c1}_{c2}"
cmd.delete(obj_iface)
pairs = [(r["chain"], r["resi"]) for r in all_res]
cmd.create(obj_iface, f"{sel_base} and ({_residue_selection(pairs)})")
delta_map = {(r["chain"], r["resi"]): r["delta"] for r in all_res}
# per-residue dSASA in the B-factor column (useful with: spectrum b)
cmd.alter(obj_iface, "b=d.get((chain,resi),0.0)", space={"d": delta_map})
cmd.hide("everything", obj_iface)
cmd.show("sticks", obj_iface)
for cls, color in CLASS_COLORS.items():
p = [(r["chain"], r["resi"]) for r in all_res if r["cls"] == cls]
if p:
sel_name = f"{obj_iface}_{cls}"
cmd.select(sel_name, f"{obj_iface} and ({_residue_selection(p)})")
cmd.color(color, f"{sel_name} and elem C")
cmd.deselect()
print(f"\n -> Object created: '{obj_iface}' ({cmd.count_atoms(obj_iface)} atoms). "
f"Colors: core=red, support=orange, rim=yellow. "
f"B = residue dSASA.")
# 4) optional CSV
if str(csv_path).strip() and csv_rows:
with open(str(csv_path).strip(), "w", newline="", encoding="utf-8") as f:
w = csv.writer(f)
w.writerow(["interface", "chain", "resn", "resi", "SASA_isolated",
"SASA_complex", "dSASA", "class"])
for row in csv_rows:
w.writerow([row[0], row[1], row[2], row[3]]
+ [f"{v:.2f}" for v in row[4:7]] + [row[7]])
print(f"\nPer-residue table saved to: {csv_path}")
finally:
cmd.delete("_tmp_chain_*")
cmd.delete("_tmp_pair_*")
for k, v in orig.items():
cmd.set(k, v)
print("==================================================================\n")
cmd.extend("calc_interface_area", calc_interface_area)
# Runs automatically on 'run' (comment out the line to only define the command):
calc_interface_area("obj01")
PyMOL>run calc_interface_area.py ================================================================== INTERFACE ANALYSIS IN 'obj01' ================================================================== Diagnostics: 0 H | 0 HETATM atoms (non-solvent) | 0 atoms with altloc Hydrogens: removed before the calculation Atoms considered: protein only Polar = N+O | probe = 1.4 A | dot_density = 4 | threshold = 0.1 A^2 Chains analysed: A, B * Chain A isolated (1965 atoms) -> Total SASA: 13694.37 A^2 (Polar: 6444.45 A^2 | Apolar: 7249.92 A^2) check: get_area = 13692.67 | sum of B = 13694.37 | diff = -1.70 A^2 * Chain B isolated (2057 atoms) -> Total SASA: 14103.23 A^2 (Polar: 6581.19 A^2 | Apolar: 7522.04 A^2) check: get_area = 14101.70 | sum of B = 14103.23 | diff = -1.53 A^2 ------------------------------------------------------------------ CONSISTENCY CHECK: Chain A <-> Chain B ------------------------------------------------------------------ * BSA from get_area totals : 1987.93 A^2 * BSA from per-atom sum of B : 1993.98 A^2 * Difference (totals - atoms) : -6.05 A^2 (0.30 % of BSA) * Sum of per-atom dSASA (A+B) : 1993.98 A^2 (polar + apolar = 1993.98 A^2) * Atoms without counterpart in complex: 0 | atoms with duplicated key: 0 * Main figures computed from : per-atom sum of B ! WARNING: difference > 1.0 A^2, unmatched atoms or duplicated keys. Check the cause before quoting figures. ------------------------------------------------------------------ INTERFACE: Chain A <-> Chain B ------------------------------------------------------------------ * Interface area (BSA/2) : 996.99 A^2 * Total buried surface area (BSA): 1993.98 A^2 (A: 994.75 | B: 999.24) * % Surface buried : 7.17 % (Chain A: 7.26 % | Chain B: 7.09 %) Chemical nature (sum of per-atom dSASA): * Polar area (N+O) : 344.09 A^2 (34.51 %) * Apolar area : 652.90 A^2 (65.49 %) Contact extent (residues with dSASA > 0.1 A^2): * Total interface residues : 59 (58 with dSASA > 1 A^2) * Chain A (33 res): ASP19, LEU22, LEU23, ARG26, VAL27, ALA30, LYS33, ALA34, THR37, PHE108, VAL109, LYS112, MET113, LYS114, GLU115, THR116, PRO118, LEU119, THR120, ALA121, GLU122, LEU138, GLN139, GLU141, LEU142, VAL145, ASN146, LYS149, TRP150, ASN151, LEU152, ALA153, MET155 * Chain B (26 res): ASN41, GLY42, GLU43, GLU44, GLY45, LEU46, ILE48, THR50, VAL51, ARG52, VAL54, ALA55, LEU56, ARG58, ARG59, ALA62, PHE63, ASP73, VAL74, ALA76, SER78, ILE84, VAL86, ASP126, ALA130, PHE284 Classification (Levy, approximate): * Core: 19 | Support: 15 | Rim: 25 Specific contacts (heuristic): * Polar N/O pairs <= 3.5 A : 13 * Salt bridges <= 4.0 A : 1 -> Object created: 'interface_A_B' (463 atoms). Colors: core=red, support=orange, rim=yellow. B = residue dSASA. ==================================================================