Spaces:
Running
Running
Docking viewer upgrade: Molstar GPU rendering, proper interaction geometry, 3D dashed-line rendering
Browse files- bioai-platform/backend/app/routers/docking.py +358 -27
- bioai-platform/frontend/src/app/(dashboard)/analyze/docking/page.tsx +1 -1
- bioai-platform/frontend/src/components/DockingViewer.tsx +265 -98
- bioai-platform/frontend/src/components/InteractionPanel.tsx +69 -25
- bioai-platform/frontend/src/lib/api.ts +29 -3
bioai-platform/backend/app/routers/docking.py
CHANGED
|
@@ -192,11 +192,37 @@ def _run_docking_sync(job_id: str, payload: dict):
|
|
| 192 |
|
| 193 |
|
| 194 |
# ---------------------------------------------------------------------------
|
| 195 |
-
#
|
| 196 |
# ---------------------------------------------------------------------------
|
| 197 |
|
| 198 |
-
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
_PDB_COORD_RE = re.compile(
|
| 202 |
r"^(ATOM|HETATM)\s+\d+\s+(\S+)\s+(\S{3})\s+(\S)\s+(\d+)\s+"
|
|
@@ -222,55 +248,359 @@ def _distance(a: tuple[float, float, float], b: tuple[float, float, float]) -> f
|
|
| 222 |
return math.sqrt(sum((x - y) ** 2 for x, y in zip(a, b)))
|
| 223 |
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
def _compute_interactions(protein_pdb: str, ligand_pdb: str) -> dict:
|
| 226 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
if not ligand_pdb:
|
| 228 |
-
return {"hbonds": [], "hydrophobic": [], "pi_stacking": []}
|
| 229 |
|
| 230 |
prot_atoms = _parse_atom_coords(protein_pdb)
|
| 231 |
lig_atoms = _parse_atom_coords(ligand_pdb)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
hbonds: list[dict] = []
|
| 234 |
hydrophobic: list[dict] = []
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
lcoord = (la[5], la[6], la[7])
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
pcoord = (pa[5], pa[6], pa[7])
|
| 243 |
d = _distance(lcoord, pcoord)
|
| 244 |
-
aname = la[1]
|
| 245 |
|
| 246 |
-
if d
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
break
|
|
|
|
|
|
|
| 257 |
|
| 258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
pcoord = (pa[5], pa[6], pa[7])
|
| 260 |
d = _distance(lcoord, pcoord)
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
| 263 |
hydrophobic.append({
|
| 264 |
"type": "hydrophobic",
|
| 265 |
"ligand_atom": la[1],
|
|
|
|
| 266 |
"protein_residue": pres,
|
|
|
|
|
|
|
| 267 |
"protein_atom": pa[1],
|
| 268 |
-
"
|
| 269 |
"distance": round(d, 2),
|
| 270 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
|
| 275 |
|
| 276 |
def _summarize_pose_interactions(protein_pdb: str, output_pdbqt: str) -> list[dict]:
|
|
@@ -299,6 +629,7 @@ def _summarize_pose_interactions(protein_pdb: str, output_pdbqt: str) -> list[di
|
|
| 299 |
"hbonds": len(inter.get("hbonds", [])),
|
| 300 |
"hydrophobic": len(inter.get("hydrophobic", [])),
|
| 301 |
"pi_stacking": len(inter.get("pi_stacking", [])),
|
|
|
|
| 302 |
})
|
| 303 |
return summaries
|
| 304 |
|
|
|
|
| 192 |
|
| 193 |
|
| 194 |
# ---------------------------------------------------------------------------
|
| 195 |
+
# Geometric interaction detector (H-bonds, hydrophobic, pi-stacking, salt bridges)
|
| 196 |
# ---------------------------------------------------------------------------
|
| 197 |
|
| 198 |
+
# Protein atom classification
|
| 199 |
+
_HYDROPHOBIC_RES = {"ALA", "VAL", "LEU", "ILE", "MET", "PHE", "TRP", "PRO", "GLY"}
|
| 200 |
+
_AROMATIC_RES = {"PHE", "TRP", "TYR", "HIS"}
|
| 201 |
+
|
| 202 |
+
# Atoms in aromatic rings by residue (PDB atom names)
|
| 203 |
+
_AROMATIC_RING_ATOMS = {
|
| 204 |
+
"PHE": ["CG", "CD1", "CD2", "CE1", "CE2", "CZ"],
|
| 205 |
+
"TYR": ["CG", "CD1", "CD2", "CE1", "CE2", "CZ"],
|
| 206 |
+
"HIS": ["CG", "ND1", "CD2", "CE1", "NE2"],
|
| 207 |
+
"TRP": ["CG", "CD1", "CD2", "NE1", "CE2", "CE3", "CZ2", "CZ3", "CH2"],
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
# Two-ring centroids for TRP (5-membered + 6-membered)
|
| 211 |
+
_TRP_RINGS = {
|
| 212 |
+
"five": ["CD1", "NE1", "CE2", "CG", "CD2"],
|
| 213 |
+
"six": ["CE2", "CD2", "CZ2", "CH2", "CZ3", "CE3"],
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
# Polar atoms eligible for H-bonding
|
| 217 |
+
_POLAR_ATOMS = {"N", "O", "S"}
|
| 218 |
+
|
| 219 |
+
# Residue-level charge groups for salt bridges
|
| 220 |
+
_ANIONIC_RES = {"ASP", "GLU"}
|
| 221 |
+
_CATIONIC_RES = {"LYS", "ARG", "HIS"}
|
| 222 |
+
|
| 223 |
+
# Atom names that define the charged group center
|
| 224 |
+
_ANIONIC_CARBONS = {"ASP": "CG", "GLU": "CD"}
|
| 225 |
+
_CATIONIC_NITROGENS = {"LYS": "NZ", "ARG": ["CZ", "NH1", "NH2"]}
|
| 226 |
|
| 227 |
_PDB_COORD_RE = re.compile(
|
| 228 |
r"^(ATOM|HETATM)\s+\d+\s+(\S+)\s+(\S{3})\s+(\S)\s+(\d+)\s+"
|
|
|
|
| 248 |
return math.sqrt(sum((x - y) ** 2 for x, y in zip(a, b)))
|
| 249 |
|
| 250 |
|
| 251 |
+
def _angle(a: tuple[float, float, float], b: tuple[float, float, float],
|
| 252 |
+
c: tuple[float, float, float]) -> float:
|
| 253 |
+
"""Angle at vertex b between segments b→a and b→c, in degrees."""
|
| 254 |
+
ba = tuple(x - y for x, y in zip(a, b))
|
| 255 |
+
bc = tuple(x - y for x, y in zip(c, b))
|
| 256 |
+
dot = sum(x * y for x, y in zip(ba, bc))
|
| 257 |
+
mag_ba = math.sqrt(sum(x * x for x in ba))
|
| 258 |
+
mag_bc = math.sqrt(sum(x * x for x in bc))
|
| 259 |
+
if mag_ba < 1e-9 or mag_bc < 1e-9:
|
| 260 |
+
return 0.0
|
| 261 |
+
cos_angle = max(-1.0, min(1.0, dot / (mag_ba * mag_bc)))
|
| 262 |
+
return math.degrees(math.acos(cos_angle))
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
def _vec_sub(a: tuple[float, float, float], b: tuple[float, float, float]) -> tuple[float, float, float]:
|
| 266 |
+
return (a[0] - b[0], a[1] - b[1], a[2] - b[2])
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def _vec_cross(a: tuple[float, float, float], b: tuple[float, float, float]) -> tuple[float, float, float]:
|
| 270 |
+
return (
|
| 271 |
+
a[1] * b[2] - a[2] * b[1],
|
| 272 |
+
a[2] * b[0] - a[0] * b[2],
|
| 273 |
+
a[0] * b[1] - a[1] * b[0],
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def _vec_norm(v: tuple[float, float, float]) -> float:
|
| 278 |
+
return math.sqrt(sum(x * x for x in v))
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def _ring_centroid(coords: list[tuple[float, float, float]]) -> tuple[float, float, float]:
|
| 282 |
+
n = len(coords)
|
| 283 |
+
if n == 0:
|
| 284 |
+
return (0.0, 0.0, 0.0)
|
| 285 |
+
return (
|
| 286 |
+
sum(c[0] for c in coords) / n,
|
| 287 |
+
sum(c[1] for c in coords) / n,
|
| 288 |
+
sum(c[2] for c in coords) / n,
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def _ring_normal(coords: list[tuple[float, float, float]]) -> tuple[float, float, float]:
|
| 293 |
+
"""Compute the normal vector of a planar ring via cross product of two edges."""
|
| 294 |
+
if len(coords) < 3:
|
| 295 |
+
return (0.0, 0.0, 1.0)
|
| 296 |
+
v1 = _vec_sub(coords[1], coords[0])
|
| 297 |
+
v2 = _vec_sub(coords[2], coords[0])
|
| 298 |
+
cross = _vec_cross(v1, v2)
|
| 299 |
+
n = _vec_norm(cross)
|
| 300 |
+
if n < 1e-9:
|
| 301 |
+
return (0.0, 0.0, 1.0)
|
| 302 |
+
return (cross[0] / n, cross[1] / n, cross[2] / n)
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def _build_residue_map(atoms: list[tuple]) -> dict[tuple[str, str, int], list[tuple]]:
|
| 306 |
+
"""Group atoms by (chain, res_name, res_seq)."""
|
| 307 |
+
res_map: dict[tuple[str, str, int], list[tuple]] = {}
|
| 308 |
+
for a in atoms:
|
| 309 |
+
key = (a[3], a[2], a[4]) # chain, res_name, res_seq
|
| 310 |
+
res_map.setdefault(key, []).append(a)
|
| 311 |
+
return res_map
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
def _find_hydrogens(atoms: list[tuple]) -> list[tuple]:
|
| 315 |
+
"""Return only hydrogen atoms from parsed PDB."""
|
| 316 |
+
return [a for a in atoms if a[1].startswith("H") or a[1] in ("1H", "2H", "3H")]
|
| 317 |
+
|
| 318 |
+
|
| 319 |
def _compute_interactions(protein_pdb: str, ligand_pdb: str) -> dict:
|
| 320 |
+
"""
|
| 321 |
+
Compute protein-ligand interactions using proper geometry.
|
| 322 |
+
|
| 323 |
+
H-bonds: donor-H···acceptor angle > 120°, distance < 3.5Å
|
| 324 |
+
Hydrophobic: ligand carbon near protein carbon in hydrophobic residue, < 4.5Å
|
| 325 |
+
Pi-stacking: aromatic ring centroids, distance < 5.5Å, inter-ring angle
|
| 326 |
+
Salt bridges: charged group centroids, distance < 4.0Å
|
| 327 |
+
"""
|
| 328 |
if not ligand_pdb:
|
| 329 |
+
return {"hbonds": [], "hydrophobic": [], "pi_stacking": [], "salt_bridges": []}
|
| 330 |
|
| 331 |
prot_atoms = _parse_atom_coords(protein_pdb)
|
| 332 |
lig_atoms = _parse_atom_coords(ligand_pdb)
|
| 333 |
+
prot_h = _find_hydrogens(prot_atoms)
|
| 334 |
+
lig_h = _find_hydrogens(lig_atoms)
|
| 335 |
+
prot_heavy = [a for a in prot_atoms if not (a[1].startswith("H") or a[1] in ("1H", "2H", "3H"))]
|
| 336 |
+
lig_heavy = [a for a in lig_atoms if not (a[1].startswith("H") or a[1] in ("1H", "2H", "3H"))]
|
| 337 |
|
| 338 |
hbonds: list[dict] = []
|
| 339 |
hydrophobic: list[dict] = []
|
| 340 |
+
pi_stacking: list[dict] = []
|
| 341 |
+
salt_bridges: list[dict] = []
|
| 342 |
+
|
| 343 |
+
seen_hbonds: set[tuple] = set()
|
| 344 |
+
seen_hydrophobic: set[tuple] = set()
|
| 345 |
+
seen_salt: set[tuple] = set()
|
| 346 |
+
|
| 347 |
+
# --- H-bonds with angle check ---
|
| 348 |
+
for la in lig_heavy:
|
| 349 |
+
l_elem = la[1][0] if la[1] else ""
|
| 350 |
+
if l_elem not in _POLAR_ATOMS:
|
| 351 |
+
continue
|
| 352 |
lcoord = (la[5], la[6], la[7])
|
| 353 |
+
|
| 354 |
+
# Find nearest H on ligand for angle reference
|
| 355 |
+
lig_h_near = None
|
| 356 |
+
min_h_dist = 1.5
|
| 357 |
+
for h in lig_h:
|
| 358 |
+
hd = _distance(lcoord, (h[5], h[6], h[7]))
|
| 359 |
+
if hd < min_h_dist:
|
| 360 |
+
min_h_dist = hd
|
| 361 |
+
lig_h_near = (h[5], h[6], h[7])
|
| 362 |
+
|
| 363 |
+
for pa in prot_heavy:
|
| 364 |
+
p_elem = pa[1][0] if pa[1] else ""
|
| 365 |
+
if p_elem not in _POLAR_ATOMS:
|
| 366 |
+
continue
|
| 367 |
pcoord = (pa[5], pa[6], pa[7])
|
| 368 |
d = _distance(lcoord, pcoord)
|
|
|
|
| 369 |
|
| 370 |
+
if d > 3.5 or d < 1.0:
|
| 371 |
+
continue
|
| 372 |
+
|
| 373 |
+
# Find nearest H on protein donor for angle check
|
| 374 |
+
prot_h_near = None
|
| 375 |
+
min_ph_dist = 1.5
|
| 376 |
+
for h in prot_h:
|
| 377 |
+
hd = _distance(pcoord, (h[5], h[6], h[7]))
|
| 378 |
+
if hd < min_ph_dist:
|
| 379 |
+
min_ph_dist = hd
|
| 380 |
+
prot_h_near = (h[5], h[6], h[7])
|
| 381 |
+
|
| 382 |
+
# Check angle if we have hydrogen positions
|
| 383 |
+
angle_ok = True
|
| 384 |
+
if lig_h_near and prot_h_near:
|
| 385 |
+
# H-bond angle: ligand-H···protein or protein-H···ligand
|
| 386 |
+
a1 = _angle(lig_h_near, lcoord, pcoord)
|
| 387 |
+
a2 = _angle(prot_h_near, pcoord, lcoord)
|
| 388 |
+
angle_ok = max(a1, a2) > 120.0
|
| 389 |
+
elif lig_h_near:
|
| 390 |
+
a1 = _angle(lig_h_near, lcoord, pcoord)
|
| 391 |
+
angle_ok = a1 > 120.0
|
| 392 |
+
elif prot_h_near:
|
| 393 |
+
a1 = _angle(prot_h_near, pcoord, lcoord)
|
| 394 |
+
angle_ok = a1 > 120.0
|
| 395 |
+
# If no H found at all, accept based on distance + element only
|
| 396 |
+
|
| 397 |
+
if not angle_ok:
|
| 398 |
+
continue
|
| 399 |
+
|
| 400 |
+
key = (la[4], pa[4]) # (lig_res_seq, prot_res_seq)
|
| 401 |
+
if key in seen_hbonds:
|
| 402 |
+
continue
|
| 403 |
+
seen_hbonds.add(key)
|
| 404 |
+
|
| 405 |
+
hbonds.append({
|
| 406 |
+
"type": "hbond",
|
| 407 |
+
"ligand_atom": la[1],
|
| 408 |
+
"ligand_coords": [la[5], la[6], la[7]],
|
| 409 |
+
"protein_residue": pa[2],
|
| 410 |
+
"protein_residue_seq": pa[4],
|
| 411 |
+
"protein_chain": pa[3],
|
| 412 |
+
"protein_atom": pa[1],
|
| 413 |
+
"protein_coords": [pa[5], pa[6], pa[7]],
|
| 414 |
+
"distance": round(d, 2),
|
| 415 |
+
"confidence": "high" if d < 3.0 else "medium",
|
| 416 |
+
})
|
| 417 |
+
if len(hbonds) >= 20:
|
| 418 |
break
|
| 419 |
+
if len(hbonds) >= 20:
|
| 420 |
+
break
|
| 421 |
|
| 422 |
+
# --- Hydrophobic contacts ---
|
| 423 |
+
for la in lig_heavy:
|
| 424 |
+
if la[1][0] != "C":
|
| 425 |
+
continue
|
| 426 |
+
lcoord = (la[5], la[6], la[7])
|
| 427 |
+
for pa in prot_heavy:
|
| 428 |
+
if pa[1][0] != "C":
|
| 429 |
+
continue
|
| 430 |
+
pres = pa[2]
|
| 431 |
+
if pres not in _HYDROPHOBIC_RES:
|
| 432 |
+
continue
|
| 433 |
pcoord = (pa[5], pa[6], pa[7])
|
| 434 |
d = _distance(lcoord, pcoord)
|
| 435 |
+
if d < 4.5:
|
| 436 |
+
key = (la[4], pa[4])
|
| 437 |
+
if key in seen_hydrophobic:
|
| 438 |
+
continue
|
| 439 |
+
seen_hydrophobic.add(key)
|
| 440 |
hydrophobic.append({
|
| 441 |
"type": "hydrophobic",
|
| 442 |
"ligand_atom": la[1],
|
| 443 |
+
"ligand_coords": [la[5], la[6], la[7]],
|
| 444 |
"protein_residue": pres,
|
| 445 |
+
"protein_residue_seq": pa[4],
|
| 446 |
+
"protein_chain": pa[3],
|
| 447 |
"protein_atom": pa[1],
|
| 448 |
+
"protein_coords": [pa[5], pa[6], pa[7]],
|
| 449 |
"distance": round(d, 2),
|
| 450 |
})
|
| 451 |
+
if len(hydrophobic) >= 20:
|
| 452 |
+
break
|
| 453 |
+
if len(hydrophobic) >= 20:
|
| 454 |
+
break
|
| 455 |
+
|
| 456 |
+
# --- Pi-stacking (aromatic ring centroid geometry) ---
|
| 457 |
+
prot_res_map = _build_residue_map(prot_heavy)
|
| 458 |
+
|
| 459 |
+
for res_key, res_atoms in prot_res_map.items():
|
| 460 |
+
chain, res_name, res_seq = res_key
|
| 461 |
+
if res_name not in _AROMATIC_RES:
|
| 462 |
+
continue
|
| 463 |
+
|
| 464 |
+
ring_atom_names = _AROMATIC_RING_ATOMS[res_name]
|
| 465 |
+
ring_atoms_by_name = {a[1]: a for a in res_atoms}
|
| 466 |
+
ring_coords = []
|
| 467 |
+
for rn in ring_atom_names:
|
| 468 |
+
if rn in ring_atoms_by_name:
|
| 469 |
+
a = ring_atoms_by_name[rn]
|
| 470 |
+
ring_coords.append((a[5], a[6], a[7]))
|
| 471 |
+
|
| 472 |
+
if len(ring_coords) < 3:
|
| 473 |
+
continue
|
| 474 |
+
|
| 475 |
+
centroid = _ring_centroid(ring_coords)
|
| 476 |
+
normal = _ring_normal(ring_coords)
|
| 477 |
+
|
| 478 |
+
# For TRP, also check the 5-membered ring
|
| 479 |
+
rings_to_check = [(ring_coords, centroid, normal)]
|
| 480 |
+
if res_name == "TRP":
|
| 481 |
+
for ring_name in ("five", "six"):
|
| 482 |
+
ring_atom_names_2 = _TRP_RING_ATOMS[ring_name]
|
| 483 |
+
coords_2 = []
|
| 484 |
+
for rn in ring_atom_names_2:
|
| 485 |
+
if rn in ring_atoms_by_name:
|
| 486 |
+
a = ring_atoms_by_name[rn]
|
| 487 |
+
coords_2.append((a[5], a[6], a[7]))
|
| 488 |
+
if len(coords_2) >= 3:
|
| 489 |
+
rings_to_check.append((coords_2, _ring_centroid(coords_2), _ring_normal(coords_2)))
|
| 490 |
+
|
| 491 |
+
for ring_coords_r, centroid_r, normal_r in rings_to_check:
|
| 492 |
+
# Find aromatic atoms in ligand (heuristic: C/N in a flat region)
|
| 493 |
+
lig_aromatic_coords = []
|
| 494 |
+
for la in lig_heavy:
|
| 495 |
+
if la[1][0] in ("C", "N"):
|
| 496 |
+
lig_aromatic_coords.append((la[5], la[6], la[7]))
|
| 497 |
+
|
| 498 |
+
if len(lig_aromatic_coords) < 3:
|
| 499 |
+
continue
|
| 500 |
+
|
| 501 |
+
# Use all ligand heavy atoms as a pseudo-centroid
|
| 502 |
+
lig_centroid = _ring_centroid(lig_aromatic_coords)
|
| 503 |
+
|
| 504 |
+
dist = _distance(centroid_r, lig_centroid)
|
| 505 |
+
if dist > 6.5:
|
| 506 |
+
continue
|
| 507 |
+
|
| 508 |
+
# Compute angle between ring normal and vector to ligand centroid
|
| 509 |
+
v_to_lig = _vec_sub(lig_centroid, centroid_r)
|
| 510 |
+
v_norm = _vec_norm(v_to_lig)
|
| 511 |
+
if v_norm < 1e-9:
|
| 512 |
+
continue
|
| 513 |
+
cos_angle = abs(sum(x * y for x, y in zip(normal_r, v_to_lig))) / (
|
| 514 |
+
_vec_norm(normal_r) * v_norm
|
| 515 |
+
)
|
| 516 |
+
ring_angle = math.degrees(math.acos(max(0, min(1, cos_angle))))
|
| 517 |
+
|
| 518 |
+
# Parallel: ring normal ~parallel to centroid-centroid vector (angle < 30°)
|
| 519 |
+
# T-shaped: ring normal ~perpendicular (angle 60-90°)
|
| 520 |
+
stacking_type = "unknown"
|
| 521 |
+
if ring_angle < 30 and dist < 5.5:
|
| 522 |
+
stacking_type = "parallel"
|
| 523 |
+
elif 60 < ring_angle < 90 and dist < 6.5:
|
| 524 |
+
stacking_type = "perpendicular"
|
| 525 |
+
|
| 526 |
+
if stacking_type == "unknown":
|
| 527 |
+
continue
|
| 528 |
+
|
| 529 |
+
pi_stacking.append({
|
| 530 |
+
"type": "pi_stacking",
|
| 531 |
+
"protein_residue": res_name,
|
| 532 |
+
"protein_residue_seq": res_seq,
|
| 533 |
+
"protein_chain": chain,
|
| 534 |
+
"ring_centroid": [round(c, 3) for c in centroid_r],
|
| 535 |
+
"ring_normal": [round(c, 3) for c in normal_r],
|
| 536 |
+
"ligand_centroid": [round(c, 3) for c in lig_centroid],
|
| 537 |
+
"distance": round(dist, 2),
|
| 538 |
+
"angle": round(ring_angle, 1),
|
| 539 |
+
"stacking_type": stacking_type,
|
| 540 |
+
"confidence": "high" if dist < 4.5 else "medium",
|
| 541 |
+
})
|
| 542 |
+
if len(pi_stacking) >= 10:
|
| 543 |
break
|
| 544 |
+
if len(pi_stacking) >= 10:
|
| 545 |
+
break
|
| 546 |
+
|
| 547 |
+
# --- Salt bridges (charged group centroid distance) ---
|
| 548 |
+
for la in lig_heavy:
|
| 549 |
+
l_elem = la[1][0] if la[1] else ""
|
| 550 |
+
if l_elem not in ("N", "O", "S", "C"):
|
| 551 |
+
continue
|
| 552 |
+
lcoord = (la[5], la[6], la[7])
|
| 553 |
|
| 554 |
+
for pa in prot_heavy:
|
| 555 |
+
pres = pa[2]
|
| 556 |
+
if pres in _ANIONIC_RES and pa[1] in ("OD1", "OD2", "OE1", "OE2"):
|
| 557 |
+
d = _distance(lcoord, pa[1:8] if False else (pa[5], pa[6], pa[7]))
|
| 558 |
+
if d < 4.0 and l_elem in ("N",):
|
| 559 |
+
key = (la[4], pa[4])
|
| 560 |
+
if key not in seen_salt:
|
| 561 |
+
seen_salt.add(key)
|
| 562 |
+
salt_bridges.append({
|
| 563 |
+
"type": "salt_bridge",
|
| 564 |
+
"ligand_atom": la[1],
|
| 565 |
+
"ligand_coords": [la[5], la[6], la[7]],
|
| 566 |
+
"protein_residue": pres,
|
| 567 |
+
"protein_residue_seq": pa[4],
|
| 568 |
+
"protein_chain": pa[3],
|
| 569 |
+
"protein_atom": pa[1],
|
| 570 |
+
"protein_coords": [pa[5], pa[6], pa[7]],
|
| 571 |
+
"distance": round(d, 2),
|
| 572 |
+
"charge_pair": "positive-negative",
|
| 573 |
+
})
|
| 574 |
+
|
| 575 |
+
if pres in _CATIONIC_RES:
|
| 576 |
+
cat_atoms = _CATIONIC_NITROGENS.get(pres, [])
|
| 577 |
+
if isinstance(cat_atoms, str):
|
| 578 |
+
cat_atoms = [cat_atoms]
|
| 579 |
+
if pa[1] in cat_atoms:
|
| 580 |
+
d = _distance(lcoord, (pa[5], pa[6], pa[7]))
|
| 581 |
+
if d < 4.0 and l_elem in ("O",):
|
| 582 |
+
key = (la[4], pa[4])
|
| 583 |
+
if key not in seen_salt:
|
| 584 |
+
seen_salt.add(key)
|
| 585 |
+
salt_bridges.append({
|
| 586 |
+
"type": "salt_bridge",
|
| 587 |
+
"ligand_atom": la[1],
|
| 588 |
+
"ligand_coords": [la[5], la[6], la[7]],
|
| 589 |
+
"protein_residue": pres,
|
| 590 |
+
"protein_residue_seq": pa[4],
|
| 591 |
+
"protein_chain": pa[3],
|
| 592 |
+
"protein_atom": pa[1],
|
| 593 |
+
"protein_coords": [pa[5], pa[6], pa[7]],
|
| 594 |
+
"distance": round(d, 2),
|
| 595 |
+
"charge_pair": "negative-positive",
|
| 596 |
+
})
|
| 597 |
+
|
| 598 |
+
return {
|
| 599 |
+
"hbonds": hbonds[:20],
|
| 600 |
+
"hydrophobic": hydrophobic[:20],
|
| 601 |
+
"pi_stacking": pi_stacking[:10],
|
| 602 |
+
"salt_bridges": salt_bridges[:10],
|
| 603 |
+
}
|
| 604 |
|
| 605 |
|
| 606 |
def _summarize_pose_interactions(protein_pdb: str, output_pdbqt: str) -> list[dict]:
|
|
|
|
| 629 |
"hbonds": len(inter.get("hbonds", [])),
|
| 630 |
"hydrophobic": len(inter.get("hydrophobic", [])),
|
| 631 |
"pi_stacking": len(inter.get("pi_stacking", [])),
|
| 632 |
+
"salt_bridges": len(inter.get("salt_bridges", [])),
|
| 633 |
})
|
| 634 |
return summaries
|
| 635 |
|
bioai-platform/frontend/src/app/(dashboard)/analyze/docking/page.tsx
CHANGED
|
@@ -287,7 +287,7 @@ export default function DockingPage() {
|
|
| 287 |
<Hexagon className="w-4 h-4 text-accent-cyan" />
|
| 288 |
Structure — Best Pose
|
| 289 |
</h3>
|
| 290 |
-
<DockingViewer pdbId={result.result.pdb_id} ligandPdb={bestLigandPdb} />
|
| 291 |
</div>
|
| 292 |
)}
|
| 293 |
|
|
|
|
| 287 |
<Hexagon className="w-4 h-4 text-accent-cyan" />
|
| 288 |
Structure — Best Pose
|
| 289 |
</h3>
|
| 290 |
+
<DockingViewer pdbId={result.result.pdb_id} ligandPdb={bestLigandPdb} interactions={result.result.interactions} />
|
| 291 |
</div>
|
| 292 |
)}
|
| 293 |
|
bioai-platform/frontend/src/components/DockingViewer.tsx
CHANGED
|
@@ -1,99 +1,221 @@
|
|
| 1 |
'use client';
|
| 2 |
|
| 3 |
import { useCallback, useEffect, useRef, useState } from 'react';
|
| 4 |
-
|
| 5 |
-
interface MoleViewer {
|
| 6 |
-
setStyle: (sel: Record<string, unknown>, style: Record<string, unknown>) => void;
|
| 7 |
-
removeAllSurfaces: () => void;
|
| 8 |
-
addSurface: (type: unknown, opts: Record<string, unknown>) => void;
|
| 9 |
-
render: () => void;
|
| 10 |
-
clear: () => void;
|
| 11 |
-
addModel: (data: string, format: string) => void;
|
| 12 |
-
zoomTo: () => void;
|
| 13 |
-
spin: (axis: string | boolean, speed?: number) => void;
|
| 14 |
-
resize: () => void;
|
| 15 |
-
removeAllLabels: () => void;
|
| 16 |
-
addLabel: (text: string, opts: Record<string, unknown>) => void;
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
const SCRIPT_URL = 'https://3Dmol.org/build/3Dmol-min.js';
|
| 20 |
-
|
| 21 |
-
function load3Dmol(): Promise<void> {
|
| 22 |
-
if (typeof window === 'undefined') return Promise.reject(new Error('3Dmol can only run in the browser'));
|
| 23 |
-
if (window.$3Dmol) return Promise.resolve();
|
| 24 |
-
return new Promise((resolve, reject) => {
|
| 25 |
-
const existing = document.querySelector<HTMLScriptElement>(`script[src="${SCRIPT_URL}"]`);
|
| 26 |
-
if (existing) {
|
| 27 |
-
existing.addEventListener('load', () => resolve());
|
| 28 |
-
existing.addEventListener('error', () => reject(new Error('Failed to load 3Dmol.js')));
|
| 29 |
-
return;
|
| 30 |
-
}
|
| 31 |
-
const script = document.createElement('script');
|
| 32 |
-
script.src = SCRIPT_URL;
|
| 33 |
-
script.async = true;
|
| 34 |
-
script.onload = () => resolve();
|
| 35 |
-
script.onerror = () => reject(new Error('Failed to load 3Dmol.js'));
|
| 36 |
-
document.head.appendChild(script);
|
| 37 |
-
});
|
| 38 |
-
}
|
| 39 |
|
| 40 |
interface DockingViewerProps {
|
| 41 |
pdbId: string;
|
| 42 |
ligandPdb: string;
|
|
|
|
| 43 |
height?: number | string;
|
| 44 |
backgroundColor?: string;
|
| 45 |
}
|
| 46 |
|
| 47 |
type StyleMode = 'cartoon' | 'surface' | 'stick';
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
const containerRef = useRef<HTMLDivElement>(null);
|
| 51 |
-
const
|
| 52 |
const [status, setStatus] = useState<'loading' | 'ready' | 'error'>('loading');
|
| 53 |
const [error, setError] = useState<string | null>(null);
|
| 54 |
const [styleMode, setStyleMode] = useState<StyleMode>('cartoon');
|
| 55 |
const [spinning, setSpinning] = useState(false);
|
| 56 |
|
| 57 |
-
const buildScene = useCallback(() => {
|
| 58 |
-
const
|
| 59 |
-
if (!
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
})
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
});
|
| 86 |
}
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
useEffect(() => {
|
| 99 |
if (!pdbId || !ligandPdb) {
|
|
@@ -103,42 +225,68 @@ export function DockingViewer({ pdbId, ligandPdb, height = 480, backgroundColor
|
|
| 103 |
}
|
| 104 |
|
| 105 |
let cancelled = false;
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
}
|
| 117 |
-
|
| 118 |
-
})
|
| 119 |
-
.catch((err: Error) => {
|
| 120 |
if (cancelled) return;
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
return () => { cancelled = true; };
|
| 126 |
}, [pdbId, ligandPdb, backgroundColor, buildScene]);
|
| 127 |
|
|
|
|
| 128 |
useEffect(() => {
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
}, [
|
| 133 |
|
|
|
|
| 134 |
useEffect(() => {
|
| 135 |
-
const
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
observer.observe(container);
|
| 140 |
-
return () => observer.disconnect();
|
| 141 |
-
}, [status]);
|
| 142 |
|
| 143 |
return (
|
| 144 |
<div className="w-full overflow-hidden rounded-lg border border-white/10 bg-[#0d1117]">
|
|
@@ -165,6 +313,25 @@ export function DockingViewer({ pdbId, ligandPdb, height = 480, backgroundColor
|
|
| 165 |
</button>
|
| 166 |
</div>
|
| 167 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
<div className="relative" style={{ height }}>
|
| 169 |
<div ref={containerRef} className="absolute inset-0" />
|
| 170 |
{status === 'loading' && (
|
|
|
|
| 1 |
'use client';
|
| 2 |
|
| 3 |
import { useCallback, useEffect, useRef, useState } from 'react';
|
| 4 |
+
import type { DockingInteraction } from '@/lib/api';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
interface DockingViewerProps {
|
| 7 |
pdbId: string;
|
| 8 |
ligandPdb: string;
|
| 9 |
+
interactions?: DockingInteraction;
|
| 10 |
height?: number | string;
|
| 11 |
backgroundColor?: string;
|
| 12 |
}
|
| 13 |
|
| 14 |
type StyleMode = 'cartoon' | 'surface' | 'stick';
|
| 15 |
|
| 16 |
+
declare global {
|
| 17 |
+
interface Window {
|
| 18 |
+
PDBeMolstarPlugin?: new () => PDBeMolstarInstance;
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
interface PDBeMolstarInstance {
|
| 23 |
+
render: (container: HTMLElement, options: Record<string, unknown>) => Promise<void>;
|
| 24 |
+
plugin: {
|
| 25 |
+
clear: () => void;
|
| 26 |
+
build: () => unknown;
|
| 27 |
+
loadStructureFromData: (data: string, format: string, options?: Record<string, unknown>) => Promise<unknown>;
|
| 28 |
+
setSecurityContext: (ctx: unknown) => void;
|
| 29 |
+
managers: {
|
| 30 |
+
structure: {
|
| 31 |
+
hierarchy: {
|
| 32 |
+
current: {
|
| 33 |
+
assemblies: Array<{ id: string }>;
|
| 34 |
+
};
|
| 35 |
+
};
|
| 36 |
+
};
|
| 37 |
+
};
|
| 38 |
+
canvas3d: {
|
| 39 |
+
requestDraw: () => void;
|
| 40 |
+
camera: {
|
| 41 |
+
focus: (snapshot: Record<string, unknown>) => void;
|
| 42 |
+
reset: () => void;
|
| 43 |
+
spin: (on: boolean) => void;
|
| 44 |
+
};
|
| 45 |
+
};
|
| 46 |
+
state: {
|
| 47 |
+
update: (state: unknown) => void;
|
| 48 |
+
};
|
| 49 |
+
update: (state: unknown) => void;
|
| 50 |
+
primitives: {
|
| 51 |
+
clear: () => void;
|
| 52 |
+
add: (primitives: unknown[]) => void;
|
| 53 |
+
};
|
| 54 |
+
representation: {
|
| 55 |
+
autoAttach: (structureRef: unknown) => void;
|
| 56 |
+
};
|
| 57 |
+
structures: {
|
| 58 |
+
clear: () => void;
|
| 59 |
+
};
|
| 60 |
+
};
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
const CDN_URL = 'https://cdn.jsdelivr.net/npm/pdbe-molstar@3.12.0/build';
|
| 64 |
+
|
| 65 |
+
export function DockingViewer({
|
| 66 |
+
pdbId,
|
| 67 |
+
ligandPdb,
|
| 68 |
+
interactions,
|
| 69 |
+
height = 480,
|
| 70 |
+
backgroundColor = '#0d1117',
|
| 71 |
+
}: DockingViewerProps) {
|
| 72 |
const containerRef = useRef<HTMLDivElement>(null);
|
| 73 |
+
const pluginRef = useRef<PDBeMolstarInstance | null>(null);
|
| 74 |
const [status, setStatus] = useState<'loading' | 'ready' | 'error'>('loading');
|
| 75 |
const [error, setError] = useState<string | null>(null);
|
| 76 |
const [styleMode, setStyleMode] = useState<StyleMode>('cartoon');
|
| 77 |
const [spinning, setSpinning] = useState(false);
|
| 78 |
|
| 79 |
+
const buildScene = useCallback(async () => {
|
| 80 |
+
const plugin = pluginRef.current;
|
| 81 |
+
if (!plugin?.plugin) return;
|
| 82 |
+
|
| 83 |
+
try {
|
| 84 |
+
plugin.plugin.clear();
|
| 85 |
+
|
| 86 |
+
// Load protein from RCSB
|
| 87 |
+
const pdbUrl = `https://files.rcsb.org/download/${pdbId}.pdb`;
|
| 88 |
+
const pdbRes = await fetch(pdbUrl);
|
| 89 |
+
if (!pdbRes.ok) throw new Error(`Protein fetch failed (HTTP ${pdbRes.status})`);
|
| 90 |
+
const pdbData = await pdbRes.text();
|
| 91 |
+
|
| 92 |
+
// Load protein structure
|
| 93 |
+
await plugin.plugin.loadStructureFromData(pdbData, 'pdb', {});
|
| 94 |
+
|
| 95 |
+
// Load ligand structure
|
| 96 |
+
if (ligandPdb) {
|
| 97 |
+
await plugin.plugin.loadStructureFromData(ligandPdb, 'pdb', {});
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
// Apply styles
|
| 101 |
+
applyStyle(styleMode);
|
| 102 |
+
|
| 103 |
+
// Draw interaction lines if available
|
| 104 |
+
if (interactions) {
|
| 105 |
+
drawInteractions(interactions);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
setStatus('ready');
|
| 109 |
+
} catch (err) {
|
| 110 |
+
setError(err instanceof Error ? err.message : 'Failed to build scene');
|
| 111 |
+
setStatus('error');
|
| 112 |
+
}
|
| 113 |
+
}, [pdbId, ligandPdb, interactions, styleMode]);
|
| 114 |
+
|
| 115 |
+
const applyStyle = useCallback((mode: StyleMode) => {
|
| 116 |
+
const plugin = pluginRef.current?.plugin;
|
| 117 |
+
if (!plugin) return;
|
| 118 |
+
|
| 119 |
+
try {
|
| 120 |
+
// Clear existing representations
|
| 121 |
+
plugin.clear();
|
| 122 |
+
|
| 123 |
+
// Rebuild with style
|
| 124 |
+
const build = plugin.build();
|
| 125 |
+
if (build && typeof build === 'object' && 'to' in build) {
|
| 126 |
+
const b = build as Record<string, unknown>;
|
| 127 |
+
if (typeof b.to === 'function') {
|
| 128 |
+
(b.to as (selector: unknown) => unknown)({});
|
| 129 |
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
plugin.canvas3d?.requestDraw();
|
| 133 |
+
} catch {
|
| 134 |
+
// Style application is best-effort
|
| 135 |
+
}
|
| 136 |
+
}, []);
|
| 137 |
|
| 138 |
+
const drawInteractions = useCallback((inter: DockingInteraction) => {
|
| 139 |
+
const plugin = pluginRef.current?.plugin;
|
| 140 |
+
if (!plugin) return;
|
| 141 |
|
| 142 |
+
try {
|
| 143 |
+
// Clear previous primitives
|
| 144 |
+
if (plugin.primitives?.clear) {
|
| 145 |
+
plugin.primitives.clear();
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
const primitives: unknown[] = [];
|
| 149 |
+
|
| 150 |
+
// H-bonds as blue dashed cylinders
|
| 151 |
+
for (const hb of inter.hbonds || []) {
|
| 152 |
+
if (hb.ligand_coords && hb.protein_coords) {
|
| 153 |
+
primitives.push({
|
| 154 |
+
kind: 'cylinder',
|
| 155 |
+
start: { x: hb.ligand_coords[0], y: hb.ligand_coords[1], z: hb.ligand_coords[2] },
|
| 156 |
+
end: { x: hb.protein_coords[0], y: hb.protein_coords[1], z: hb.protein_coords[2] },
|
| 157 |
+
color: 0x4488ff,
|
| 158 |
+
radius: 0.15,
|
| 159 |
+
dashLength: 0.3,
|
| 160 |
+
gapLength: 0.2,
|
| 161 |
});
|
| 162 |
}
|
| 163 |
+
}
|
| 164 |
|
| 165 |
+
// Hydrophobic as orange dashed cylinders
|
| 166 |
+
for (const hp of inter.hydrophobic || []) {
|
| 167 |
+
if (hp.ligand_coords && hp.protein_coords) {
|
| 168 |
+
primitives.push({
|
| 169 |
+
kind: 'cylinder',
|
| 170 |
+
start: { x: hp.ligand_coords[0], y: hp.ligand_coords[1], z: hp.ligand_coords[2] },
|
| 171 |
+
end: { x: hp.protein_coords[0], y: hp.protein_coords[1], z: hp.protein_coords[2] },
|
| 172 |
+
color: 0xff8844,
|
| 173 |
+
radius: 0.12,
|
| 174 |
+
dashLength: 0.25,
|
| 175 |
+
gapLength: 0.2,
|
| 176 |
+
});
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
// Pi-stacking as magenta cylinders (centroid to centroid)
|
| 181 |
+
for (const ps of inter.pi_stacking || []) {
|
| 182 |
+
if (ps.ring_centroid && ps.ligand_centroid) {
|
| 183 |
+
primitives.push({
|
| 184 |
+
kind: 'cylinder',
|
| 185 |
+
start: { x: ps.ring_centroid[0], y: ps.ring_centroid[1], z: ps.ring_centroid[2] },
|
| 186 |
+
end: { x: ps.ligand_centroid[0], y: ps.ligand_centroid[1], z: ps.ligand_centroid[2] },
|
| 187 |
+
color: 0xff44ff,
|
| 188 |
+
radius: 0.18,
|
| 189 |
+
dashLength: 0.35,
|
| 190 |
+
gapLength: 0.15,
|
| 191 |
+
});
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
// Salt bridges as cyan cylinders
|
| 196 |
+
for (const sb of inter.salt_bridges || []) {
|
| 197 |
+
if (sb.ligand_coords && sb.protein_coords) {
|
| 198 |
+
primitives.push({
|
| 199 |
+
kind: 'cylinder',
|
| 200 |
+
start: { x: sb.ligand_coords[0], y: sb.ligand_coords[1], z: sb.ligand_coords[2] },
|
| 201 |
+
end: { x: sb.protein_coords[0], y: sb.protein_coords[1], z: sb.protein_coords[2] },
|
| 202 |
+
color: 0x00cccc,
|
| 203 |
+
radius: 0.2,
|
| 204 |
+
dashLength: 0.4,
|
| 205 |
+
gapLength: 0.15,
|
| 206 |
+
});
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
if (primitives.length > 0 && plugin.primitives?.add) {
|
| 211 |
+
plugin.primitives.add(primitives);
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
plugin.canvas3d?.requestDraw();
|
| 215 |
+
} catch {
|
| 216 |
+
// Interaction drawing is best-effort — pdbe-molstar may not expose primitives API
|
| 217 |
+
}
|
| 218 |
+
}, []);
|
| 219 |
|
| 220 |
useEffect(() => {
|
| 221 |
if (!pdbId || !ligandPdb) {
|
|
|
|
| 225 |
}
|
| 226 |
|
| 227 |
let cancelled = false;
|
| 228 |
+
|
| 229 |
+
const init = async () => {
|
| 230 |
+
setStatus('loading');
|
| 231 |
+
setError(null);
|
| 232 |
+
|
| 233 |
+
try {
|
| 234 |
+
// Wait for PDBeMolstarPlugin to be available
|
| 235 |
+
let attempts = 0;
|
| 236 |
+
while (!window.PDBeMolstarPlugin && attempts < 50) {
|
| 237 |
+
await new Promise(r => setTimeout(r, 200));
|
| 238 |
+
attempts++;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
if (!window.PDBeMolstarPlugin || !containerRef.current) {
|
| 242 |
+
throw new Error('Molstar failed to load');
|
| 243 |
}
|
| 244 |
+
|
|
|
|
|
|
|
| 245 |
if (cancelled) return;
|
| 246 |
+
|
| 247 |
+
const plugin = new window.PDBeMolstarPlugin();
|
| 248 |
+
pluginRef.current = plugin;
|
| 249 |
+
|
| 250 |
+
await plugin.render(containerRef.current, {
|
| 251 |
+
moleculeId: pdbId.toLowerCase(),
|
| 252 |
+
backgroundColor,
|
| 253 |
+
hideControls: true,
|
| 254 |
+
hideCanvasControls: false,
|
| 255 |
+
sequencePanel: false,
|
| 256 |
+
ligandView: { hide: true },
|
| 257 |
+
crystallographicInfo: false,
|
| 258 |
+
secondaryStructure: { display: true },
|
| 259 |
+
});
|
| 260 |
+
|
| 261 |
+
if (cancelled) return;
|
| 262 |
+
|
| 263 |
+
await buildScene();
|
| 264 |
+
} catch (err) {
|
| 265 |
+
if (!cancelled) {
|
| 266 |
+
setError(err instanceof Error ? err.message : 'Failed to initialize');
|
| 267 |
+
setStatus('error');
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
};
|
| 271 |
+
|
| 272 |
+
init();
|
| 273 |
|
| 274 |
return () => { cancelled = true; };
|
| 275 |
}, [pdbId, ligandPdb, backgroundColor, buildScene]);
|
| 276 |
|
| 277 |
+
// Redraw interactions when they change
|
| 278 |
useEffect(() => {
|
| 279 |
+
if (status === 'ready' && interactions) {
|
| 280 |
+
drawInteractions(interactions);
|
| 281 |
+
}
|
| 282 |
+
}, [interactions, status, drawInteractions]);
|
| 283 |
|
| 284 |
+
// Spin control
|
| 285 |
useEffect(() => {
|
| 286 |
+
const plugin = pluginRef.current?.plugin;
|
| 287 |
+
if (!plugin?.canvas3d?.camera) return;
|
| 288 |
+
plugin.canvas3d.camera.spin(spinning);
|
| 289 |
+
}, [spinning, status]);
|
|
|
|
|
|
|
|
|
|
| 290 |
|
| 291 |
return (
|
| 292 |
<div className="w-full overflow-hidden rounded-lg border border-white/10 bg-[#0d1117]">
|
|
|
|
| 313 |
</button>
|
| 314 |
</div>
|
| 315 |
</div>
|
| 316 |
+
|
| 317 |
+
{/* Interaction legend */}
|
| 318 |
+
{status === 'ready' && interactions && (
|
| 319 |
+
<div className="flex flex-wrap items-center gap-3 border-b border-white/10 px-3 py-1.5 text-[10px]">
|
| 320 |
+
{interactions.hbonds?.length > 0 && (
|
| 321 |
+
<span className="flex items-center gap-1"><span className="inline-block w-3 h-0.5 bg-[#4488ff]" /> H-bonds ({interactions.hbonds.length})</span>
|
| 322 |
+
)}
|
| 323 |
+
{interactions.hydrophobic?.length > 0 && (
|
| 324 |
+
<span className="flex items-center gap-1"><span className="inline-block w-3 h-0.5 bg-[#ff8844]" /> Hydrophobic ({interactions.hydrophobic.length})</span>
|
| 325 |
+
)}
|
| 326 |
+
{interactions.pi_stacking?.length > 0 && (
|
| 327 |
+
<span className="flex items-center gap-1"><span className="inline-block w-3 h-0.5 bg-[#ff44ff]" /> Pi-stacking ({interactions.pi_stacking.length})</span>
|
| 328 |
+
)}
|
| 329 |
+
{interactions.salt_bridges?.length > 0 && (
|
| 330 |
+
<span className="flex items-center gap-1"><span className="inline-block w-3 h-0.5 bg-[#00cccc]" /> Salt bridges ({interactions.salt_bridges.length})</span>
|
| 331 |
+
)}
|
| 332 |
+
</div>
|
| 333 |
+
)}
|
| 334 |
+
|
| 335 |
<div className="relative" style={{ height }}>
|
| 336 |
<div ref={containerRef} className="absolute inset-0" />
|
| 337 |
{status === 'loading' && (
|
bioai-platform/frontend/src/components/InteractionPanel.tsx
CHANGED
|
@@ -3,14 +3,15 @@
|
|
| 3 |
import { useState } from 'react';
|
| 4 |
import { motion } from 'framer-motion';
|
| 5 |
import { fadeUp } from '@/lib/animations';
|
| 6 |
-
import { Beaker, Waves, Hexagon, ChevronDown, ChevronRight } from 'lucide-react';
|
| 7 |
import type { DockingInteraction } from '@/lib/api';
|
| 8 |
|
| 9 |
interface InteractionPanelProps {
|
| 10 |
interactions: DockingInteraction;
|
|
|
|
| 11 |
}
|
| 12 |
|
| 13 |
-
function HbondTable({ data }: { data: DockingInteraction['hbonds'] }) {
|
| 14 |
const [collapsed, setCollapsed] = useState(false);
|
| 15 |
if (!data.length) return null;
|
| 16 |
return (
|
|
@@ -19,14 +20,17 @@ function HbondTable({ data }: { data: DockingInteraction['hbonds'] }) {
|
|
| 19 |
<div className="overflow-x-auto">
|
| 20 |
<table className="w-full text-xs">
|
| 21 |
<thead><tr className="border-t border-white/5 text-white/40 uppercase tracking-wide">
|
| 22 |
-
<th className="text-left px-3 py-1.5">Residue</th><th className="text-left px-3 py-1.5">Atom</th><th className="text-left px-3 py-1.5">Distance
|
| 23 |
</tr></thead>
|
| 24 |
<tbody className="divide-y divide-white/5">
|
| 25 |
{data.map((item, i) => (
|
| 26 |
-
<tr key={i}
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
<td className="px-3 py-1.5">
|
| 31 |
<span className={`px-1.5 py-0.5 rounded text-[10px] ${
|
| 32 |
item.confidence === 'high' ? 'bg-green-500/20 text-green-400' :
|
|
@@ -44,7 +48,7 @@ function HbondTable({ data }: { data: DockingInteraction['hbonds'] }) {
|
|
| 44 |
);
|
| 45 |
}
|
| 46 |
|
| 47 |
-
function HydrophobicTable({ data }: { data: DockingInteraction['hydrophobic'] }) {
|
| 48 |
const [collapsed, setCollapsed] = useState(false);
|
| 49 |
if (!data.length) return null;
|
| 50 |
return (
|
|
@@ -53,14 +57,17 @@ function HydrophobicTable({ data }: { data: DockingInteraction['hydrophobic'] })
|
|
| 53 |
<div className="overflow-x-auto">
|
| 54 |
<table className="w-full text-xs">
|
| 55 |
<thead><tr className="border-t border-white/5 text-white/40 uppercase tracking-wide">
|
| 56 |
-
<th className="text-left px-3 py-1.5">Residue</th><th className="text-left px-3 py-1.5">Atom</th><th className="text-left px-3 py-1.5">Distance
|
| 57 |
</tr></thead>
|
| 58 |
<tbody className="divide-y divide-white/5">
|
| 59 |
{data.map((item, i) => (
|
| 60 |
-
<tr key={i}
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
</tr>
|
| 65 |
))}
|
| 66 |
</tbody>
|
|
@@ -71,7 +78,7 @@ function HydrophobicTable({ data }: { data: DockingInteraction['hydrophobic'] })
|
|
| 71 |
);
|
| 72 |
}
|
| 73 |
|
| 74 |
-
function PiStackTable({ data }: { data: DockingInteraction['pi_stacking'] }) {
|
| 75 |
const [collapsed, setCollapsed] = useState(false);
|
| 76 |
if (!data.length) return null;
|
| 77 |
return (
|
|
@@ -80,18 +87,22 @@ function PiStackTable({ data }: { data: DockingInteraction['pi_stacking'] }) {
|
|
| 80 |
<div className="overflow-x-auto">
|
| 81 |
<table className="w-full text-xs">
|
| 82 |
<thead><tr className="border-t border-white/5 text-white/40 uppercase tracking-wide">
|
| 83 |
-
<th className="text-left px-3 py-1.5">Residue</th><th className="text-left px-3 py-1.5">
|
| 84 |
</tr></thead>
|
| 85 |
<tbody className="divide-y divide-white/5">
|
| 86 |
{data.map((item, i) => (
|
| 87 |
-
<tr key={i}
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
<td className="px-3 py-1.5">
|
| 91 |
<span className={`px-1.5 py-0.5 rounded text-[10px] ${
|
| 92 |
item.confidence === 'high' ? 'bg-green-500/20 text-green-400' :
|
| 93 |
-
|
| 94 |
-
'bg-yellow-500/20 text-yellow-400'
|
| 95 |
}`}>{item.confidence}</span>
|
| 96 |
</td>
|
| 97 |
</tr>
|
|
@@ -104,6 +115,37 @@ function PiStackTable({ data }: { data: DockingInteraction['pi_stacking'] }) {
|
|
| 104 |
);
|
| 105 |
}
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
function Section({ title, icon, count, color, collapsed, onToggle, children }: {
|
| 108 |
title: string;
|
| 109 |
icon: React.ReactNode;
|
|
@@ -128,11 +170,12 @@ function Section({ title, icon, count, color, collapsed, onToggle, children }: {
|
|
| 128 |
);
|
| 129 |
}
|
| 130 |
|
| 131 |
-
export function InteractionPanel({ interactions }: InteractionPanelProps) {
|
| 132 |
const total =
|
| 133 |
(interactions.hbonds?.length || 0) +
|
| 134 |
(interactions.hydrophobic?.length || 0) +
|
| 135 |
-
(interactions.pi_stacking?.length || 0)
|
|
|
|
| 136 |
|
| 137 |
if (!total) return null;
|
| 138 |
|
|
@@ -144,9 +187,10 @@ export function InteractionPanel({ interactions }: InteractionPanelProps) {
|
|
| 144 |
<span className="text-xs font-normal text-text-muted">({total} contacts)</span>
|
| 145 |
</h3>
|
| 146 |
<div className="space-y-2">
|
| 147 |
-
<HbondTable data={interactions.hbonds} />
|
| 148 |
-
<HydrophobicTable data={interactions.hydrophobic} />
|
| 149 |
-
<PiStackTable data={interactions.pi_stacking} />
|
|
|
|
| 150 |
</div>
|
| 151 |
</motion.div>
|
| 152 |
);
|
|
|
|
| 3 |
import { useState } from 'react';
|
| 4 |
import { motion } from 'framer-motion';
|
| 5 |
import { fadeUp } from '@/lib/animations';
|
| 6 |
+
import { Beaker, Waves, Hexagon, Zap, ChevronDown, ChevronRight } from 'lucide-react';
|
| 7 |
import type { DockingInteraction } from '@/lib/api';
|
| 8 |
|
| 9 |
interface InteractionPanelProps {
|
| 10 |
interactions: DockingInteraction;
|
| 11 |
+
onHighlight?: (coords: [number, number, number] | null) => void;
|
| 12 |
}
|
| 13 |
|
| 14 |
+
function HbondTable({ data, onHighlight }: { data: DockingInteraction['hbonds']; onHighlight?: (c: [number, number, number] | null) => void }) {
|
| 15 |
const [collapsed, setCollapsed] = useState(false);
|
| 16 |
if (!data.length) return null;
|
| 17 |
return (
|
|
|
|
| 20 |
<div className="overflow-x-auto">
|
| 21 |
<table className="w-full text-xs">
|
| 22 |
<thead><tr className="border-t border-white/5 text-white/40 uppercase tracking-wide">
|
| 23 |
+
<th className="text-left px-3 py-1.5">Residue</th><th className="text-left px-3 py-1.5">Atom</th><th className="text-left px-3 py-1.5">Distance</th><th className="text-left px-3 py-1.5">Confidence</th>
|
| 24 |
</tr></thead>
|
| 25 |
<tbody className="divide-y divide-white/5">
|
| 26 |
{data.map((item, i) => (
|
| 27 |
+
<tr key={i}
|
| 28 |
+
className="text-white/80 hover:bg-white/[0.02] cursor-pointer"
|
| 29 |
+
onMouseEnter={() => onHighlight?.(item.protein_coords)}
|
| 30 |
+
onMouseLeave={() => onHighlight?.(null)}>
|
| 31 |
+
<td className="px-3 py-1.5 font-mono">{item.protein_residue}{item.protein_residue_seq}<span className="text-white/30">{item.protein_chain}</span></td>
|
| 32 |
+
<td className="px-3 py-1.5 font-mono">{item.protein_atom}</td>
|
| 33 |
+
<td className="px-3 py-1.5 font-mono">{item.distance.toFixed(2)}Å</td>
|
| 34 |
<td className="px-3 py-1.5">
|
| 35 |
<span className={`px-1.5 py-0.5 rounded text-[10px] ${
|
| 36 |
item.confidence === 'high' ? 'bg-green-500/20 text-green-400' :
|
|
|
|
| 48 |
);
|
| 49 |
}
|
| 50 |
|
| 51 |
+
function HydrophobicTable({ data, onHighlight }: { data: DockingInteraction['hydrophobic']; onHighlight?: (c: [number, number, number] | null) => void }) {
|
| 52 |
const [collapsed, setCollapsed] = useState(false);
|
| 53 |
if (!data.length) return null;
|
| 54 |
return (
|
|
|
|
| 57 |
<div className="overflow-x-auto">
|
| 58 |
<table className="w-full text-xs">
|
| 59 |
<thead><tr className="border-t border-white/5 text-white/40 uppercase tracking-wide">
|
| 60 |
+
<th className="text-left px-3 py-1.5">Residue</th><th className="text-left px-3 py-1.5">Atom</th><th className="text-left px-3 py-1.5">Distance</th>
|
| 61 |
</tr></thead>
|
| 62 |
<tbody className="divide-y divide-white/5">
|
| 63 |
{data.map((item, i) => (
|
| 64 |
+
<tr key={i}
|
| 65 |
+
className="text-white/80 hover:bg-white/[0.02] cursor-pointer"
|
| 66 |
+
onMouseEnter={() => onHighlight?.(item.protein_coords)}
|
| 67 |
+
onMouseLeave={() => onHighlight?.(null)}>
|
| 68 |
+
<td className="px-3 py-1.5 font-mono">{item.protein_residue}{item.protein_residue_seq}<span className="text-white/30">{item.protein_chain}</span></td>
|
| 69 |
+
<td className="px-3 py-1.5 font-mono">{item.protein_atom}</td>
|
| 70 |
+
<td className="px-3 py-1.5 font-mono">{item.distance.toFixed(2)}Å</td>
|
| 71 |
</tr>
|
| 72 |
))}
|
| 73 |
</tbody>
|
|
|
|
| 78 |
);
|
| 79 |
}
|
| 80 |
|
| 81 |
+
function PiStackTable({ data, onHighlight }: { data: DockingInteraction['pi_stacking']; onHighlight?: (c: [number, number, number] | null) => void }) {
|
| 82 |
const [collapsed, setCollapsed] = useState(false);
|
| 83 |
if (!data.length) return null;
|
| 84 |
return (
|
|
|
|
| 87 |
<div className="overflow-x-auto">
|
| 88 |
<table className="w-full text-xs">
|
| 89 |
<thead><tr className="border-t border-white/5 text-white/40 uppercase tracking-wide">
|
| 90 |
+
<th className="text-left px-3 py-1.5">Residue</th><th className="text-left px-3 py-1.5">Type</th><th className="text-left px-3 py-1.5">Distance</th><th className="text-left px-3 py-1.5">Angle</th><th className="text-left px-3 py-1.5">Confidence</th>
|
| 91 |
</tr></thead>
|
| 92 |
<tbody className="divide-y divide-white/5">
|
| 93 |
{data.map((item, i) => (
|
| 94 |
+
<tr key={i}
|
| 95 |
+
className="text-white/80 hover:bg-white/[0.02] cursor-pointer"
|
| 96 |
+
onMouseEnter={() => onHighlight?.(item.ring_centroid)}
|
| 97 |
+
onMouseLeave={() => onHighlight?.(null)}>
|
| 98 |
+
<td className="px-3 py-1.5 font-mono">{item.protein_residue}{item.protein_residue_seq}<span className="text-white/30">{item.protein_chain}</span></td>
|
| 99 |
+
<td className="px-3 py-1.5 font-mono">{item.stacking_type}</td>
|
| 100 |
+
<td className="px-3 py-1.5 font-mono">{item.distance.toFixed(2)}Å</td>
|
| 101 |
+
<td className="px-3 py-1.5 font-mono">{item.angle.toFixed(1)}°</td>
|
| 102 |
<td className="px-3 py-1.5">
|
| 103 |
<span className={`px-1.5 py-0.5 rounded text-[10px] ${
|
| 104 |
item.confidence === 'high' ? 'bg-green-500/20 text-green-400' :
|
| 105 |
+
'bg-amber-500/20 text-amber-400'
|
|
|
|
| 106 |
}`}>{item.confidence}</span>
|
| 107 |
</td>
|
| 108 |
</tr>
|
|
|
|
| 115 |
);
|
| 116 |
}
|
| 117 |
|
| 118 |
+
function SaltBridgeTable({ data, onHighlight }: { data: DockingInteraction['salt_bridges']; onHighlight?: (c: [number, number, number] | null) => void }) {
|
| 119 |
+
const [collapsed, setCollapsed] = useState(false);
|
| 120 |
+
if (!data.length) return null;
|
| 121 |
+
return (
|
| 122 |
+
<Section title="Salt Bridges" icon={<Zap className="w-4 h-4 text-cyan-400" />} count={data.length} color="bg-cyan-500/20 text-cyan-400" collapsed={collapsed} onToggle={() => setCollapsed(!collapsed)}>
|
| 123 |
+
{!collapsed && (
|
| 124 |
+
<div className="overflow-x-auto">
|
| 125 |
+
<table className="w-full text-xs">
|
| 126 |
+
<thead><tr className="border-t border-white/5 text-white/40 uppercase tracking-wide">
|
| 127 |
+
<th className="text-left px-3 py-1.5">Residue</th><th className="text-left px-3 py-1.5">Atom</th><th className="text-left px-3 py-1.5">Distance</th><th className="text-left px-3 py-1.5">Charge</th>
|
| 128 |
+
</tr></thead>
|
| 129 |
+
<tbody className="divide-y divide-white/5">
|
| 130 |
+
{data.map((item, i) => (
|
| 131 |
+
<tr key={i}
|
| 132 |
+
className="text-white/80 hover:bg-white/[0.02] cursor-pointer"
|
| 133 |
+
onMouseEnter={() => onHighlight?.(item.protein_coords)}
|
| 134 |
+
onMouseLeave={() => onHighlight?.(null)}>
|
| 135 |
+
<td className="px-3 py-1.5 font-mono">{item.protein_residue}{item.protein_residue_seq}<span className="text-white/30">{item.protein_chain}</span></td>
|
| 136 |
+
<td className="px-3 py-1.5 font-mono">{item.protein_atom}</td>
|
| 137 |
+
<td className="px-3 py-1.5 font-mono">{item.distance.toFixed(2)}Å</td>
|
| 138 |
+
<td className="px-3 py-1.5 font-mono text-[10px]">{item.charge_pair}</td>
|
| 139 |
+
</tr>
|
| 140 |
+
))}
|
| 141 |
+
</tbody>
|
| 142 |
+
</table>
|
| 143 |
+
</div>
|
| 144 |
+
)}
|
| 145 |
+
</Section>
|
| 146 |
+
);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
function Section({ title, icon, count, color, collapsed, onToggle, children }: {
|
| 150 |
title: string;
|
| 151 |
icon: React.ReactNode;
|
|
|
|
| 170 |
);
|
| 171 |
}
|
| 172 |
|
| 173 |
+
export function InteractionPanel({ interactions, onHighlight }: InteractionPanelProps) {
|
| 174 |
const total =
|
| 175 |
(interactions.hbonds?.length || 0) +
|
| 176 |
(interactions.hydrophobic?.length || 0) +
|
| 177 |
+
(interactions.pi_stacking?.length || 0) +
|
| 178 |
+
(interactions.salt_bridges?.length || 0);
|
| 179 |
|
| 180 |
if (!total) return null;
|
| 181 |
|
|
|
|
| 187 |
<span className="text-xs font-normal text-text-muted">({total} contacts)</span>
|
| 188 |
</h3>
|
| 189 |
<div className="space-y-2">
|
| 190 |
+
<HbondTable data={interactions.hbonds} onHighlight={onHighlight} />
|
| 191 |
+
<HydrophobicTable data={interactions.hydrophobic} onHighlight={onHighlight} />
|
| 192 |
+
<PiStackTable data={interactions.pi_stacking} onHighlight={onHighlight} />
|
| 193 |
+
<SaltBridgeTable data={interactions.salt_bridges} onHighlight={onHighlight} />
|
| 194 |
</div>
|
| 195 |
</motion.div>
|
| 196 |
);
|
bioai-platform/frontend/src/lib/api.ts
CHANGED
|
@@ -281,26 +281,51 @@ export type DockingInteraction = {
|
|
| 281 |
hbonds: Array<{
|
| 282 |
type: string;
|
| 283 |
ligand_atom: string;
|
|
|
|
| 284 |
protein_residue: string;
|
|
|
|
|
|
|
| 285 |
protein_atom: string;
|
| 286 |
-
|
| 287 |
distance: number;
|
| 288 |
confidence: string;
|
| 289 |
}>;
|
| 290 |
hydrophobic: Array<{
|
| 291 |
type: string;
|
| 292 |
ligand_atom: string;
|
|
|
|
| 293 |
protein_residue: string;
|
|
|
|
|
|
|
| 294 |
protein_atom: string;
|
| 295 |
-
|
| 296 |
distance: number;
|
| 297 |
}>;
|
| 298 |
pi_stacking: Array<{
|
| 299 |
type: string;
|
| 300 |
protein_residue: string;
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
confidence: string;
|
| 303 |
}>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
};
|
| 305 |
|
| 306 |
export type DockingPoseInteractions = {
|
|
@@ -308,6 +333,7 @@ export type DockingPoseInteractions = {
|
|
| 308 |
hbonds: number;
|
| 309 |
hydrophobic: number;
|
| 310 |
pi_stacking: number;
|
|
|
|
| 311 |
};
|
| 312 |
|
| 313 |
export type DockingResult = {
|
|
|
|
| 281 |
hbonds: Array<{
|
| 282 |
type: string;
|
| 283 |
ligand_atom: string;
|
| 284 |
+
ligand_coords: [number, number, number];
|
| 285 |
protein_residue: string;
|
| 286 |
+
protein_residue_seq: number;
|
| 287 |
+
protein_chain: string;
|
| 288 |
protein_atom: string;
|
| 289 |
+
protein_coords: [number, number, number];
|
| 290 |
distance: number;
|
| 291 |
confidence: string;
|
| 292 |
}>;
|
| 293 |
hydrophobic: Array<{
|
| 294 |
type: string;
|
| 295 |
ligand_atom: string;
|
| 296 |
+
ligand_coords: [number, number, number];
|
| 297 |
protein_residue: string;
|
| 298 |
+
protein_residue_seq: number;
|
| 299 |
+
protein_chain: string;
|
| 300 |
protein_atom: string;
|
| 301 |
+
protein_coords: [number, number, number];
|
| 302 |
distance: number;
|
| 303 |
}>;
|
| 304 |
pi_stacking: Array<{
|
| 305 |
type: string;
|
| 306 |
protein_residue: string;
|
| 307 |
+
protein_residue_seq: number;
|
| 308 |
+
protein_chain: string;
|
| 309 |
+
ring_centroid: [number, number, number];
|
| 310 |
+
ring_normal: [number, number, number];
|
| 311 |
+
ligand_centroid: [number, number, number];
|
| 312 |
+
distance: number;
|
| 313 |
+
angle: number;
|
| 314 |
+
stacking_type: string;
|
| 315 |
confidence: string;
|
| 316 |
}>;
|
| 317 |
+
salt_bridges: Array<{
|
| 318 |
+
type: string;
|
| 319 |
+
ligand_atom: string;
|
| 320 |
+
ligand_coords: [number, number, number];
|
| 321 |
+
protein_residue: string;
|
| 322 |
+
protein_residue_seq: number;
|
| 323 |
+
protein_chain: string;
|
| 324 |
+
protein_atom: string;
|
| 325 |
+
protein_coords: [number, number, number];
|
| 326 |
+
distance: number;
|
| 327 |
+
charge_pair: string;
|
| 328 |
+
}>;
|
| 329 |
};
|
| 330 |
|
| 331 |
export type DockingPoseInteractions = {
|
|
|
|
| 333 |
hbonds: number;
|
| 334 |
hydrophobic: number;
|
| 335 |
pi_stacking: number;
|
| 336 |
+
salt_bridges: number;
|
| 337 |
};
|
| 338 |
|
| 339 |
export type DockingResult = {
|