MHCXGraph.core.pdb_graph_builder¶
- class MHCXGraph.core.pdb_graph_builder.AtomBundle[source]¶
Bases:
TypedDict- ca_cb_map: dict[str, NodeCoords]¶
- node_centroids: pandas.DataFrame¶
- raw_df: pandas.DataFrame¶
- class MHCXGraph.core.pdb_graph_builder.BuiltGraph(graph: nx.Graph, residue_index: list[tuple[str, Residue]], residue_centroids: np.ndarray, water_index: list[tuple[str, Residue]] = <factory>, water_centroids: np.ndarray | None = None, distance_matrix: np.ndarray | None = None, raw_pdb_df: pd.DataFrame | None = None, node_centroids: pd.DataFrame | None = None, dssp_df: pd.DataFrame | None = None)[source]¶
Bases:
objectContainer returned by
PDBGraphBuilder.- graph¶
Constructed graph with node/edge attributes.
- Type:
networkx.Graph
- residue_index¶
Node id to residue pairing for amino acid residues used as the main distance base.
- residue_centroids¶
Centroids for
residue_indexin the same order, shape (N, 3).- Type:
numpy.ndarray
- water_index¶
Node id to residue pairing for water residues (if included).
- water_centroids¶
Water centroids in the same order as
water_index, shape (W, 3).- Type:
numpy.ndarray or None
- distance_matrix¶
Pairwise centroid distance matrix for residues in
residue_index.- Type:
numpy.ndarray or None
- raw_pdb_df¶
Atom-level table used to derive centroids and CA/CB coordinates.
- Type:
pandas.DataFrame or None
- node_centroids¶
DataFrame indexed by
node_idwith centroid coordinatesx_coord,y_coord,z_coord.- Type:
pandas.DataFrame or None
- dssp_df¶
DSSP summary with an added “rsa” column, aligned to graph nodes.
- Type:
pandas.DataFrame or None
- graph: nx.Graph¶
- residue_centroids: np.ndarray¶
- class MHCXGraph.core.pdb_graph_builder.FixedPDBIO(*args: Any, **kwargs: Any)[source]¶
Bases:
PDBIOOverrides PDBIO to fix the left-aligned element bug in Biopython 1.86. Intercepts the generated string and right-aligns columns 77-78.
- class MHCXGraph.core.pdb_graph_builder.PDBGraphBuilder(pdb_path: str, config: GraphConfig | None = None)[source]¶
Bases:
objectBuild a structural graph from a PDB/mmCIF file.
- Parameters:
pdb_path (str) – Path to the structure file.
config (GraphBuildConfig, optional) – Graph construction options.
Notes
The distance matrix and the node labels are exported to
.pmhc_tmp/with filenames<stem>_distmat.npyand<stem>_residue_labels.txt.- build_graph() BuiltGraph[source]¶
Run the full pipeline: load → select chains → ASA/RSA → distances → graph.
- Returns:
Graph object and associated tables/arrays.
- Return type:
Notes
The residue–residue distance matrix and node labels are saved under
.pmhc_tmp/<stem>_distmat.npyand.pmhc_tmp/<stem>_residue_labels.txt.Waters are added as nodes with
rsa=1.0and connected to nearby residues.
- class MHCXGraph.core.pdb_graph_builder.ResidueInfo[source]¶
Bases:
TypedDict- canonical_aminoacid_residues: list[tuple[str, Bio.PDB.Residue.Residue, Literal['canonical_aminoacid', 'noncanonical_aminoacid', 'ligand', 'water'], ndarray]]¶
- ligands: list[tuple[str, Bio.PDB.Residue.Residue, Literal['canonical_aminoacid', 'noncanonical_aminoacid', 'ligand', 'water'], ndarray]]¶
- class MHCXGraph.core.pdb_graph_builder.StructureDict[source]¶
Bases:
TypedDict- residues: ResidueInfo¶
- MHCXGraph.core.pdb_graph_builder.capture_c_stderr(logger)[source]¶
Capture stderr output from C libraries and redirect it to logging.
- Parameters:
logger (logging.Logger) – Logger instance used to record intercepted messages.
- Yields:
None – Context manager that temporarily redirects the C-level standard error stream.
Notes
This utility is primarily used to intercept verbose output from FreeSASA and forward it to the project logging system.
- MHCXGraph.core.pdb_graph_builder.check_res_inconsistencies(res_tuples)[source]¶
Validate consistency between node identifiers and residue objects.
- Parameters:
res_tuples (list[tuple]) – List containing tuples of the form
(node_id, residue_object, kind, centroid).- Returns:
inconsistencies – List of formatted messages describing mismatches between the residue information encoded in the node identifier and the values stored in the Bio.PDB residue object.
- Return type:
- MHCXGraph.core.pdb_graph_builder.log = <VerboseLoggerAdapter MHCXGraph (WARNING)>¶
Structural graph builder for pMHC using Bio.PDB and NetworkX.
Features¶
Residue and water centroid computation.
ASA via Shrake–Rupley and RSA normalization (Tien et al. tables via Bio.PDB).
Optional RSA via DSSP with fallback for non-canonicals.
Distance-based graph construction (residue–residue and residue–water).
Distance matrix and label export for reproducibility/debugging.
Requirements¶
biopython >= 1.79
networkx
numpy
pandas
Classes¶
|
Container returned by |
|
Overrides PDBIO to fix the left-aligned element bug in Biopython 1.86. |
|
Build a structural graph from a PDB/mmCIF file. |
Functions¶
|
Capture stderr output from C libraries and redirect it to logging. |
|
Validate consistency between node identifiers and residue objects. |