Download scoobdoob/validation/aib9.py from ChatterjeeLab/ScooBDoob: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/ChatterjeeLab/ScooBDoob/resolve/main/scoobdoob/validation/aib9.py
- Command line
-
hf download hf://ChatterjeeLab/ScooBDoob/scoobdoob/validation/aib9.py
-
curl -L -o aib9.py https://huggingface.co/ChatterjeeLab/ScooBDoob/resolve/main/scoobdoob/validation/aib9.py
2.73 kB
| from __future__ import annotations | |
| import os | |
| from pathlib import Path | |
| import numpy as np | |
| N_RES = 9 | |
| CORE = slice(1, 8) | |
| OPENMM_DIR = Path( | |
| os.environ.get( | |
| "SCOOBDOOB_AIB9_DATA", Path(__file__).resolve().parents[2] / "data" / "aib9" | |
| ) | |
| ) | |
| def load_openmm_colvar(dirpath=OPENMM_DIR, stride=5): | |
| """Load interleaved phi/psi angles from the continuous PLUMED trajectory.""" | |
| def read(fn): | |
| rows = [] | |
| for l in open(os.path.join(dirpath, fn)): | |
| if l.startswith("#"): | |
| continue | |
| c = l.split() | |
| if len(c) < 10: | |
| continue | |
| rows.append([float(x) for x in c[1:10]]) | |
| return np.asarray(rows, dtype=np.float64) | |
| phi = read("COLVAR_phi") | |
| psi = read("COLVAR_psi") | |
| n = min(len(phi), len(psi)) | |
| phi, psi = phi[:n:stride], psi[:n:stride] | |
| ang = np.empty((len(phi), 18), dtype=np.float64) | |
| ang[:, 0::2] = phi | |
| ang[:, 1::2] = psi | |
| return [ang], [np.full(len(ang), np.nan)] | |
| def phi_psi(ang): | |
| """Split interleaved (T,18) -> (phi (T,9), psi (T,9)) in radians.""" | |
| ang = np.asarray(ang) | |
| return ang[:, 0::2], ang[:, 1::2] | |
| def featurize_sincos(trajs): | |
| """(T,18) dihedrals -> (T,36) [sin,cos] features for TICA (handles wrap).""" | |
| out = [] | |
| for ang in trajs: | |
| ang = np.asarray(ang) | |
| out.append(np.concatenate([np.sin(ang), np.cos(ang)], axis=1)) | |
| return out | |
| def handedness_indicator(trajs): | |
| """(T,18) -> (T,9) float, 1.0 where residue is left-handed (phi > 0).""" | |
| return [(phi_psi(a)[0] > 0).astype(np.float64) for a in trajs] | |
| def classify_microstates(state_left, core=CORE, end_thresh=0.8, half_thresh=0.6): | |
| """Label each microstate R / L / I_N / I_C / other from its handedness. | |
| ``state_left`` : (K, 9) per-microstate P(residue is left-handed). | |
| Uses core residues (termini fray). Returns an array of string labels. | |
| """ | |
| SL = np.asarray(state_left) | |
| K = SL.shape[0] | |
| core_left = SL[:, core].mean(axis=1) | |
| n_half = SL[:, 1:4].mean(axis=1) | |
| c_half = SL[:, 5:8].mean(axis=1) | |
| labels = np.array(["other"] * K, dtype=object) | |
| for i in range(K): | |
| if core_left[i] >= end_thresh: | |
| labels[i] = "L" | |
| elif core_left[i] <= 1 - end_thresh: | |
| labels[i] = "R" | |
| elif n_half[i] >= half_thresh and c_half[i] <= 1 - half_thresh: | |
| labels[i] = "I_N" | |
| elif c_half[i] >= half_thresh and n_half[i] <= 1 - half_thresh: | |
| labels[i] = "I_C" | |
| return labels | |
| def macrostate_sets(labels): | |
| """Group microstate indices by label -> dict label -> list[int].""" | |
| out = {} | |
| for k, lab in enumerate(labels): | |
| out.setdefault(lab, []).append(int(k)) | |
| return out | |