picogl.examples.utils.pdb_loader ================================ .. py:module:: picogl.examples.utils.pdb_loader .. autoapi-nested-parse:: PDB File Loader for MolViewSpec Integration This module provides functionality to: 1. Load and parse PDB files 2. Convert PDB data to MolViewSpec format 3. Integrate with PicoGL's molecular visualization system Classes ------- .. autoapisummary:: picogl.examples.utils.pdb_loader.Atom picogl.examples.utils.pdb_loader.BondType picogl.examples.utils.pdb_loader.Bond picogl.examples.utils.pdb_loader.Residue picogl.examples.utils.pdb_loader.PDBStructure picogl.examples.utils.pdb_loader.PDBLoaderResults picogl.examples.utils.pdb_loader.PDBLoader Functions --------- .. autoapisummary:: picogl.examples.utils.pdb_loader._pdb_line picogl.examples.utils.pdb_loader._optional_float picogl.examples.utils.pdb_loader._parse_atom_line picogl.examples.utils.pdb_loader._bond_key picogl.examples.utils.pdb_loader._atom_distance picogl.examples.utils.pdb_loader._parse_conect_line picogl.examples.utils.pdb_loader._find_named_atom picogl.examples.utils.pdb_loader._generate_bonds picogl.examples.utils.pdb_loader._generate_peptide_bonds picogl.examples.utils.pdb_loader._generate_intra_residue_bonds picogl.examples.utils.pdb_loader._merge_bonds picogl.examples.utils.pdb_loader.save_molviewspec Module Contents --------------- .. py:class:: Atom Represents a single atom from a PDB file .. py:attribute:: serial :type: int .. py:attribute:: name :type: str .. py:attribute:: res_name :type: str .. py:attribute:: chain_id :type: str .. py:attribute:: res_seq :type: int .. py:attribute:: x :type: float .. py:attribute:: y :type: float .. py:attribute:: z :type: float .. py:attribute:: element :type: str .. py:attribute:: charge :type: str :value: '' .. py:attribute:: occupancy :type: float :value: 1.0 .. py:attribute:: b_factor :type: float :value: 0.0 .. py:class:: BondType Bases: :py:obj:`picogl.utils.strenum.StrEnum` Python 3.10 compatible StrEnum. Behaves like Python 3.11 enum.StrEnum. .. py:attribute:: SINGLE :type: str :value: 'single' .. py:attribute:: DOUBLE :type: str :value: 'double' .. py:attribute:: TRIPLE :type: str :value: 'triple' .. py:attribute:: AROMATIC :type: str :value: 'aromatic' .. py:class:: Bond Represents a bond between two atoms .. py:attribute:: atom1_idx :type: int .. py:attribute:: atom2_idx :type: int .. py:attribute:: bond_type :type: BondType .. py:class:: Residue Represents a residue/amino acid .. py:attribute:: name :type: str .. py:attribute:: chain_id :type: str .. py:attribute:: seq_num :type: int .. py:attribute:: atoms :type: List[Atom] .. py:attribute:: start_idx :type: int .. py:class:: PDBStructure Complete PDB structure data .. py:attribute:: title :type: str .. py:attribute:: atoms :type: List[Atom] .. py:attribute:: bonds :type: List[Bond] .. py:attribute:: residues :type: List[Residue] .. py:attribute:: chains :type: List[str] .. py:attribute:: newline :type: str :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """ """ .. raw:: html
.. py:property:: calpha_atoms :type: list calpha_atoms .. py:property:: calpha_bonds Generate bonds between consecutive C-alpha atoms in the same chain. .. py:method:: get_atom_positions() -> numpy.ndarray Get all atom positions as a numpy array .. py:method:: get_atom_elements() -> List[str] Get all atom element symbols .. py:method:: get_residue_atoms(residue_idx: int) -> List[Atom] Get atoms for a specific residue .. py:property:: report :type: str .. py:function:: _pdb_line(raw_line: str) -> str Normalize a PDB text line for fixed-width field parsing. .. py:function:: _optional_float(value, default: float) -> float .. py:function:: _parse_atom_line(line: str) -> Atom Parse an ATOM or HETATM line from PDB format. .. py:function:: _bond_key(i: int, j: int) -> tuple[int, int] .. py:function:: _atom_distance(a: Atom, b: Atom) -> float .. py:function:: _parse_conect_line(line: str, serial_to_idx: Dict[int, int]) -> List[Bond] Parse a CONECT line into bonds (central atom → up to four partners). .. py:function:: _find_named_atom(residue: Residue, name: str) -> Optional[Atom] .. py:function:: _generate_bonds(atoms: List[Atom], residues: List[Residue]) -> List[Bond] Infer covalent bonds from geometry (protein/ligand sticks). PDB ``CONECT`` records usually cover ligands only. Protein connectivity must be rebuilt from residue geometry. .. py:function:: _generate_peptide_bonds(atom_index: dict[int, int], bonds: list[Bond], residues: list[Residue]) .. py:function:: _generate_intra_residue_bonds(atom_index: dict[int, int], bonds: list[Bond], residues: list[Residue]) .. py:function:: _merge_bonds(*bond_lists: List[Bond]) -> List[Bond] Union bond lists, dropping duplicate undirected pairs. .. py:class:: PDBLoaderResults Raw PDB parse output before bond inference and residue finalization. .. py:attribute:: atoms :type: List[Atom] .. py:attribute:: conect_bonds :type: List[Bond] .. py:attribute:: chains :type: set[str] .. py:attribute:: current_residue :type: Optional[Residue] .. py:attribute:: current_residue_atoms :type: List[Atom] .. py:attribute:: residues :type: List[Residue] .. py:attribute:: title :type: str :value: 'Unknown Structure' .. py:method:: to_structure() -> PDBStructure Append the last residue, infer bonds, and return the public structure. .. py:class:: PDBLoader(path: str | pathlib.Path) Loads and parses PDB files .. py:attribute:: path .. py:attribute:: structure :type: PDBStructure | None :value: None .. py:method:: _load_pdb() -> None Load and parse the PDB file. .. py:method:: open_file() -> PDBLoaderResults .. py:method:: to_molviewspec() -> Dict Convert PDB structure to MolViewSpec format .. py:method:: to_picogl_data() -> Dict Convert PDB structure to PicoGL-compatible data format .. py:function:: save_molviewspec(molviewspec: Dict, output_path: str) Save MolViewSpec data to a JSON file