Module Overview#
The core package is organized into specialized modules:
np_analyzer: Molecular interaction analysis engine
interactions: Data structures for molecular interactions
structure: Molecular structure classes (Atom, Bond, Residue)
pdb_parser: PDB file parsing and structure handling
pdb_fixer: PDB structure enhancement and fixing
np_vector: NumPy-based 3D vector mathematics for high-performance calculations
Main Analysis Engine#
Molecular Interaction Analyzer#
High-performance molecular interaction analyzer for HBAT.
This module provides the main analyzer using NumPy for vectorized calculations of molecular interactions in protein structures.
- class hbat.core.np_analyzer.NPMolecularInteractionAnalyzer(parameters: AnalysisParameters | None = None)[source]#
Bases:
object
High-performance analyzer for molecular interactions.
This analyzer uses vectorized NumPy operations for efficient analysis of molecular interactions in protein structures. Supports comprehensive detection of:
Hydrogen bonds: Classical N-H···O, O-H···O, N-H···N interactions
Weak hydrogen bonds: C-H···O interactions (important in protein-ligand binding)
Halogen bonds: C-X···A interactions where X is Cl, Br, I (default angle: 150°)
π interactions: Multiple subtypes including:
Hydrogen-π: C-H···π, N-H···π, O-H···π, S-H···π
Halogen-π: C-Cl···π, C-Br···π, C-I···π
Cooperativity chains: Networks of linked interactions
- Parameters:
parameters (Optional[AnalysisParameters]) – Analysis parameters with subtype-specific cutoffs
- __init__(parameters: AnalysisParameters | None = None)[source]#
Initialize analyzer with parameters.
- analyze_file(pdb_file: str) bool [source]#
Analyze a PDB file for molecular interactions.
Performs comprehensive analysis of hydrogen bonds, weak hydrogen bonds (C-H···O), halogen bonds, π interactions (including subtypes: C-H···π, N-H···π, O-H···π, S-H···π, C-Cl···π, C-Br···π, C-I···π), and cooperativity chains in the provided PDB structure. Optionally applies PDB fixing to add missing atoms if enabled in parameters.
- get_summary() Dict[str, Any] [source]#
Get comprehensive analysis summary with statistics, PDB fixing info, and timing.
Returns a dictionary containing interaction counts, averages, bond type distributions, PDB fixing information (if applied), and analysis timing.
- Returns:
Dictionary containing comprehensive analysis summary
- Return type:
Dict[str, Any]
- class hbat.core.np_analyzer.NPMolecularInteractionAnalyzer(parameters: AnalysisParameters | None = None)[source]#
Bases:
object
High-performance analyzer for molecular interactions.
This analyzer uses vectorized NumPy operations for efficient analysis of molecular interactions in protein structures. Supports comprehensive detection of:
Hydrogen bonds: Classical N-H···O, O-H···O, N-H···N interactions
Weak hydrogen bonds: C-H···O interactions (important in protein-ligand binding)
Halogen bonds: C-X···A interactions where X is Cl, Br, I (default angle: 150°)
π interactions: Multiple subtypes including:
Hydrogen-π: C-H···π, N-H···π, O-H···π, S-H···π
Halogen-π: C-Cl···π, C-Br···π, C-I···π
Cooperativity chains: Networks of linked interactions
- Parameters:
parameters (Optional[AnalysisParameters]) – Analysis parameters with subtype-specific cutoffs
High-performance molecular interaction analysis engine using vectorized NumPy operations.
Key Features:
Hydrogen bond detection with geometric and chemical criteria
Halogen bond identification with σ-hole directionality
π-π stacking and X-H…π interaction analysis
Cooperative interaction chain detection
Comprehensive statistics and PDB fixing integration
35x performance improvement through spatial grid optimization
Usage Example:
from hbat.core.np_analyzer import NPMolecularInteractionAnalyzer from hbat.constants.parameters import AnalysisParameters # Initialize analyzer with parameters params = AnalysisParameters() params.fix_pdb_enabled = True analyzer = NPMolecularInteractionAnalyzer(params) # Analyze PDB file (includes optional PDB fixing) success = analyzer.analyze_file("structure.pdb") # Get comprehensive summary with statistics and timing summary = analyzer.get_summary() print(f"Found {summary['hydrogen_bonds']['count']} hydrogen bonds") print(f"Analysis completed in {summary['timing']['analysis_duration_seconds']} seconds")
- __init__(parameters: AnalysisParameters | None = None)[source]#
Initialize analyzer with parameters.
- analyze_file(pdb_file: str) bool [source]#
Analyze a PDB file for molecular interactions.
Performs comprehensive analysis of hydrogen bonds, weak hydrogen bonds (C-H···O), halogen bonds, π interactions (including subtypes: C-H···π, N-H···π, O-H···π, S-H···π, C-Cl···π, C-Br···π, C-I···π), and cooperativity chains in the provided PDB structure. Optionally applies PDB fixing to add missing atoms if enabled in parameters.
- get_summary() Dict[str, Any] [source]#
Get comprehensive analysis summary with statistics, PDB fixing info, and timing.
Returns a dictionary containing interaction counts, averages, bond type distributions, PDB fixing information (if applied), and analysis timing.
- Returns:
Dictionary containing comprehensive analysis summary
- Return type:
Dict[str, Any]
Interaction Data Structures#
Molecular Interaction Classes#
Molecular interaction classes for HBAT analysis.
This module defines the data structures for representing different types of molecular interactions including hydrogen bonds, halogen bonds, π interactions, and cooperativity chains.
- class hbat.core.interactions.MolecularInteraction[source]#
Bases:
ABC
Base class for all molecular interactions.
This abstract base class defines the unified interface for all types of molecular interactions analyzed by HBAT, including hydrogen bonds, halogen bonds, and π interactions.
All interactions have the following core components: - Donor: The electron/proton donor (atom or virtual atom) - Acceptor: The electron/proton acceptor (atom or virtual atom) - Interaction: The mediating atom/point (e.g., hydrogen, π center) - Geometry: Distances and angles defining the interaction - Bonding: The interaction atom must be bonded to the donor atom
Bonding Requirements: - For H-bonds: Hydrogen must be covalently bonded to the donor - For X-bonds: Halogen is covalently bonded to donor carbon - For X-H…π interactions: Hydrogen must be covalently bonded to the donor - For π-π stacking (future): No bonding requirement - uses centroid distances
- abstractmethod get_interaction() Atom | NPVec3D [source]#
Get the interaction mediating atom or point.
- abstractmethod get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- abstractmethod get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- abstractmethod get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- abstractmethod get_donor_interaction_distance() float [source]#
Get the donor to interaction distance.
- Returns:
Distance from donor to interaction point in Angstroms
- Return type:
- abstractmethod get_donor_acceptor_distance() float [source]#
Get the donor to acceptor distance.
- Returns:
Distance from donor to acceptor in Angstroms
- Return type:
- abstractmethod get_donor_interaction_acceptor_angle() float [source]#
Get the donor-interaction-acceptor angle.
- Returns:
Angle in radians
- Return type:
- abstractmethod is_donor_interaction_bonded() bool [source]#
Check if the interaction atom is bonded to the donor atom.
This is a fundamental requirement for most molecular interactions (except π-π stacking which will be implemented separately).
- Returns:
True if donor and interaction atom are bonded
- Return type:
- property donor_interaction_acceptor_angle: float#
Property accessor for donor-interaction-acceptor angle.
- get_donor_atom() Atom | None [source]#
Get the donor atom if it’s an Atom instance.
- Returns:
The donor atom if it’s an Atom, None otherwise
- Return type:
Optional[Atom]
- get_acceptor_atom() Atom | None [source]#
Get the acceptor atom if it’s an Atom instance.
- Returns:
The acceptor atom if it’s an Atom, None otherwise
- Return type:
Optional[Atom]
- class hbat.core.interactions.HydrogenBond(_donor: Atom, hydrogen: Atom, _acceptor: Atom, distance: float, angle: float, _donor_acceptor_distance: float, bond_type: str, _donor_residue: str, _acceptor_residue: str)[source]#
Bases:
MolecularInteraction
Represents a hydrogen bond interaction.
This class stores all information about a detected hydrogen bond, including the participating atoms, geometric parameters, and classification information.
- Parameters:
_donor (Atom) – The hydrogen bond donor atom
hydrogen (Atom) – The hydrogen atom in the bond
_acceptor (Atom) – The hydrogen bond acceptor atom
distance (float) – H…A distance in Angstroms
angle (float) – D-H…A angle in radians
_donor_acceptor_distance (float) – D…A distance in Angstroms
bond_type (str) – Classification of the hydrogen bond type
_donor_residue (str) – Identifier for donor residue
_acceptor_residue (str) – Identifier for acceptor residue
- __init__(_donor: Atom, hydrogen: Atom, _acceptor: Atom, distance: float, angle: float, _donor_acceptor_distance: float, bond_type: str, _donor_residue: str, _acceptor_residue: str)[source]#
Initialize a HydrogenBond object.
- Parameters:
_donor (Atom) – The hydrogen bond donor atom
hydrogen (Atom) – The hydrogen atom in the bond
_acceptor (Atom) – The hydrogen bond acceptor atom
distance (float) – H…A distance in Angstroms
angle (float) – D-H…A angle in radians
_donor_acceptor_distance (float) – D…A distance in Angstroms
bond_type (str) – Classification of the hydrogen bond type
_donor_residue (str) – Identifier for donor residue
_acceptor_residue (str) – Identifier for acceptor residue
- property distance: float#
Legacy property for interaction distance.
- Returns:
Donor-interaction distance for backward compatibility
- Return type:
- property angle: float#
Legacy property for interaction angle.
- Returns:
Donor-interaction-acceptor angle for backward compatibility
- Return type:
- get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- is_donor_interaction_bonded() bool [source]#
Check if hydrogen is bonded to donor.
For hydrogen bonds, the hydrogen must be covalently bonded to the donor atom. This method assumes the bond has been validated during creation.
- Returns:
True (assumes validation was done during creation)
- Return type:
- class hbat.core.interactions.HalogenBond(halogen: Atom, _acceptor: Atom, distance: float, angle: float, bond_type: str, _halogen_residue: str, _acceptor_residue: str)[source]#
Bases:
MolecularInteraction
Represents a halogen bond interaction.
This class stores information about a detected halogen bond, where a halogen atom (Cl, Br, I) acts as an electrophilic center interacting with nucleophilic acceptors. HBAT uses updated default parameters with a 150° angle cutoff for improved detection of biologically relevant halogen bonds.
- Parameters:
halogen (Atom) – The halogen atom (F, Cl, Br, I)
_acceptor (Atom) – The electron donor/acceptor atom
distance (float) – X…A distance in Angstroms
angle (float) – C-X…A angle in radians (default cutoff: 150°)
bond_type (str) – Classification of the halogen bond type
_halogen_residue (str) – Identifier for halogen-containing residue
_acceptor_residue (str) – Identifier for acceptor residue
- __init__(halogen: Atom, _acceptor: Atom, distance: float, angle: float, bond_type: str, _halogen_residue: str, _acceptor_residue: str)[source]#
Initialize a HalogenBond object.
- Parameters:
halogen (Atom) – The halogen atom (F, Cl, Br, I)
_acceptor (Atom) – The electron donor/acceptor atom
distance (float) – X…A distance in Angstroms
angle (float) – C-X…A angle in radians
bond_type (str) – Classification of the halogen bond type
_halogen_residue (str) – Identifier for halogen-containing residue
_acceptor_residue (str) – Identifier for acceptor residue
- property distance: float#
Legacy property for interaction distance.
- Returns:
Donor-interaction distance for backward compatibility
- Return type:
- property angle: float#
Legacy property for interaction angle.
- Returns:
Donor-interaction-acceptor angle for backward compatibility
- Return type:
- get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- get_donor_interaction_distance() float [source]#
Distance from donor to interaction point (0 for halogen bonds).
- is_donor_interaction_bonded() bool [source]#
Check if halogen is bonded to donor carbon.
For halogen bonds, the halogen atom must be covalently bonded to a carbon atom. The halogen serves as both the donor and interaction point.
- Returns:
True (assumes validation was done during creation)
- Return type:
- class hbat.core.interactions.PiInteraction(_donor: Atom, hydrogen: Atom, pi_center: NPVec3D, distance: float, angle: float, _donor_residue: str, _pi_residue: str)[source]#
Bases:
MolecularInteraction
Represents a D-X…π interaction.
This class stores information about a detected D-X…π interaction, where a donor atom with an interaction atom (H, F, Cl, Br, I) interacts with an aromatic π system. Supports multiple subtypes: - C-H…π, N-H…π, O-H…π, S-H…π (hydrogen-π interactions) - C-Cl…π, C-Br…π, C-I…π (halogen-π interactions)
- Parameters:
_donor (Atom) – The donor atom (C, N, O, S)
hydrogen (Atom) – The interaction atom (H, F, Cl, Br, I) - name kept for backward compatibility
pi_center (NPVec3D) – Center of the aromatic π system
distance (float) – X…π distance in Angstroms
angle (float) – D-X…π angle in radians
_donor_residue (str) – Identifier for donor residue
_pi_residue (str) – Identifier for π-containing residue
- __init__(_donor: Atom, hydrogen: Atom, pi_center: NPVec3D, distance: float, angle: float, _donor_residue: str, _pi_residue: str)[source]#
Initialize a PiInteraction object.
- Parameters:
_donor (Atom) – The donor atom (C, N, O, S)
hydrogen (Atom) – The interaction atom (H, F, Cl, Br, I) - name kept for backward compatibility
pi_center (NPVec3D) – Center of the aromatic π system
distance (float) – X…π distance in Angstroms
angle (float) – D-X…π angle in radians
_donor_residue (str) – Identifier for donor residue
_pi_residue (str) – Identifier for π-containing residue
- property distance: float#
Legacy property for interaction distance.
- Returns:
Donor-interaction distance for backward compatibility
- Return type:
- property angle: float#
Legacy property for interaction angle.
- Returns:
Donor-interaction-acceptor angle for backward compatibility
- Return type:
- get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- is_donor_interaction_bonded() bool [source]#
Check if hydrogen is bonded to donor.
For X-H…π interactions, the hydrogen must be covalently bonded to the donor atom.
- Returns:
True (assumes validation was done during creation)
- Return type:
- property donor_acceptor_properties: str#
Get the donor-acceptor property description.
- Returns:
Property description string
- Return type:
- get_backbone_sidechain_interaction() str [source]#
Get simplified backbone/sidechain interaction description.
- Returns:
Interaction type (B-S, S-S, etc.)
- Return type:
- get_interaction_type_display() str [source]#
Get the interaction type for display purposes.
Generates display strings for different π interaction subtypes:
Hydrogen-π interactions: - “C-H…π” for carbon-hydrogen to π system - “N-H…π” for nitrogen-hydrogen to π system - “O-H…π” for oxygen-hydrogen to π system - “S-H…π” for sulfur-hydrogen to π system
Halogen-π interactions: - “C-Cl…π” for carbon-chlorine to π system - “C-Br…π” for carbon-bromine to π system - “C-I…π” for carbon-iodine to π system
- Returns:
Display format showing donor-interaction…π pattern
- Return type:
- class hbat.core.interactions.CooperativityChain(interactions: List[HydrogenBond | HalogenBond | PiInteraction], chain_length: int, chain_type: str)[source]#
Bases:
MolecularInteraction
Represents a chain of cooperative molecular interactions.
This class represents a series of linked molecular interactions where the acceptor of one interaction acts as the donor of the next, creating cooperative effects.
- Parameters:
interactions (List[Union[HydrogenBond, HalogenBond, PiInteraction]]) – List of interactions in the chain
chain_length (int) – Number of interactions in the chain
chain_type (str) – Description of the interaction types in the chain
- __init__(interactions: List[HydrogenBond | HalogenBond | PiInteraction], chain_length: int, chain_type: str)[source]#
Initialize a CooperativityChain object.
- Parameters:
interactions (List[Union[HydrogenBond, HalogenBond, PiInteraction]]) – List of interactions in the chain
chain_length (int) – Number of interactions in the chain
chain_type (str) – Description of the interaction types in the chain
- get_interaction() Atom | NPVec3D [source]#
Get the center point of the chain (middle interaction point).
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- get_donor_interaction_distance() float [source]#
Get the distance from chain start to middle interaction.
Base Interaction Class#
- class hbat.core.interactions.MolecularInteraction[source]#
Bases:
ABC
Base class for all molecular interactions.
This abstract base class defines the unified interface for all types of molecular interactions analyzed by HBAT, including hydrogen bonds, halogen bonds, and π interactions.
All interactions have the following core components: - Donor: The electron/proton donor (atom or virtual atom) - Acceptor: The electron/proton acceptor (atom or virtual atom) - Interaction: The mediating atom/point (e.g., hydrogen, π center) - Geometry: Distances and angles defining the interaction - Bonding: The interaction atom must be bonded to the donor atom
Bonding Requirements: - For H-bonds: Hydrogen must be covalently bonded to the donor - For X-bonds: Halogen is covalently bonded to donor carbon - For X-H…π interactions: Hydrogen must be covalently bonded to the donor - For π-π stacking (future): No bonding requirement - uses centroid distances
Abstract base class for all molecular interactions, providing common interface and validation.
- abstractmethod get_interaction() Atom | NPVec3D [source]#
Get the interaction mediating atom or point.
- abstractmethod get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- abstractmethod get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- abstractmethod get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- abstractmethod get_donor_interaction_distance() float [source]#
Get the donor to interaction distance.
- Returns:
Distance from donor to interaction point in Angstroms
- Return type:
- abstractmethod get_donor_acceptor_distance() float [source]#
Get the donor to acceptor distance.
- Returns:
Distance from donor to acceptor in Angstroms
- Return type:
- abstractmethod get_donor_interaction_acceptor_angle() float [source]#
Get the donor-interaction-acceptor angle.
- Returns:
Angle in radians
- Return type:
- abstractmethod is_donor_interaction_bonded() bool [source]#
Check if the interaction atom is bonded to the donor atom.
This is a fundamental requirement for most molecular interactions (except π-π stacking which will be implemented separately).
- Returns:
True if donor and interaction atom are bonded
- Return type:
- property donor_interaction_acceptor_angle: float#
Property accessor for donor-interaction-acceptor angle.
- get_donor_atom() Atom | None [source]#
Get the donor atom if it’s an Atom instance.
- Returns:
The donor atom if it’s an Atom, None otherwise
- Return type:
Optional[Atom]
- get_acceptor_atom() Atom | None [source]#
Get the acceptor atom if it’s an Atom instance.
- Returns:
The acceptor atom if it’s an Atom, None otherwise
- Return type:
Optional[Atom]
Specific Interaction Types#
- class hbat.core.interactions.HydrogenBond(_donor: Atom, hydrogen: Atom, _acceptor: Atom, distance: float, angle: float, _donor_acceptor_distance: float, bond_type: str, _donor_residue: str, _acceptor_residue: str)[source]#
Bases:
MolecularInteraction
Represents a hydrogen bond interaction.
This class stores all information about a detected hydrogen bond, including the participating atoms, geometric parameters, and classification information.
- Parameters:
_donor (Atom) – The hydrogen bond donor atom
hydrogen (Atom) – The hydrogen atom in the bond
_acceptor (Atom) – The hydrogen bond acceptor atom
distance (float) – H…A distance in Angstroms
angle (float) – D-H…A angle in radians
_donor_acceptor_distance (float) – D…A distance in Angstroms
bond_type (str) – Classification of the hydrogen bond type
_donor_residue (str) – Identifier for donor residue
_acceptor_residue (str) – Identifier for acceptor residue
Dataclass representing a hydrogen bond with donor-hydrogen-acceptor geometry.
Geometric Parameters:
Distance (D-A): Donor to acceptor distance
Angle (D-H…A): Donor-hydrogen-acceptor angle
Energy estimation based on distance and angle
- __init__(_donor: Atom, hydrogen: Atom, _acceptor: Atom, distance: float, angle: float, _donor_acceptor_distance: float, bond_type: str, _donor_residue: str, _acceptor_residue: str)[source]#
Initialize a HydrogenBond object.
- Parameters:
_donor (Atom) – The hydrogen bond donor atom
hydrogen (Atom) – The hydrogen atom in the bond
_acceptor (Atom) – The hydrogen bond acceptor atom
distance (float) – H…A distance in Angstroms
angle (float) – D-H…A angle in radians
_donor_acceptor_distance (float) – D…A distance in Angstroms
bond_type (str) – Classification of the hydrogen bond type
_donor_residue (str) – Identifier for donor residue
_acceptor_residue (str) – Identifier for acceptor residue
- property distance: float#
Legacy property for interaction distance.
- Returns:
Donor-interaction distance for backward compatibility
- Return type:
- property angle: float#
Legacy property for interaction angle.
- Returns:
Donor-interaction-acceptor angle for backward compatibility
- Return type:
- get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- is_donor_interaction_bonded() bool [source]#
Check if hydrogen is bonded to donor.
For hydrogen bonds, the hydrogen must be covalently bonded to the donor atom. This method assumes the bond has been validated during creation.
- Returns:
True (assumes validation was done during creation)
- Return type:
- class hbat.core.interactions.HalogenBond(halogen: Atom, _acceptor: Atom, distance: float, angle: float, bond_type: str, _halogen_residue: str, _acceptor_residue: str)[source]#
Bases:
MolecularInteraction
Represents a halogen bond interaction.
This class stores information about a detected halogen bond, where a halogen atom (Cl, Br, I) acts as an electrophilic center interacting with nucleophilic acceptors. HBAT uses updated default parameters with a 150° angle cutoff for improved detection of biologically relevant halogen bonds.
- Parameters:
halogen (Atom) – The halogen atom (F, Cl, Br, I)
_acceptor (Atom) – The electron donor/acceptor atom
distance (float) – X…A distance in Angstroms
angle (float) – C-X…A angle in radians (default cutoff: 150°)
bond_type (str) – Classification of the halogen bond type
_halogen_residue (str) – Identifier for halogen-containing residue
_acceptor_residue (str) – Identifier for acceptor residue
Dataclass representing a halogen bond with carbon-halogen…acceptor geometry.
Geometric Parameters:
Distance (X…A): Halogen to acceptor distance
Angle (C-X…A): Carbon-halogen-acceptor angle
σ-hole directionality validation
- __init__(halogen: Atom, _acceptor: Atom, distance: float, angle: float, bond_type: str, _halogen_residue: str, _acceptor_residue: str)[source]#
Initialize a HalogenBond object.
- Parameters:
halogen (Atom) – The halogen atom (F, Cl, Br, I)
_acceptor (Atom) – The electron donor/acceptor atom
distance (float) – X…A distance in Angstroms
angle (float) – C-X…A angle in radians
bond_type (str) – Classification of the halogen bond type
_halogen_residue (str) – Identifier for halogen-containing residue
_acceptor_residue (str) – Identifier for acceptor residue
- property distance: float#
Legacy property for interaction distance.
- Returns:
Donor-interaction distance for backward compatibility
- Return type:
- property angle: float#
Legacy property for interaction angle.
- Returns:
Donor-interaction-acceptor angle for backward compatibility
- Return type:
- get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- get_donor_interaction_distance() float [source]#
Distance from donor to interaction point (0 for halogen bonds).
- is_donor_interaction_bonded() bool [source]#
Check if halogen is bonded to donor carbon.
For halogen bonds, the halogen atom must be covalently bonded to a carbon atom. The halogen serves as both the donor and interaction point.
- Returns:
True (assumes validation was done during creation)
- Return type:
- class hbat.core.interactions.PiInteraction(_donor: Atom, hydrogen: Atom, pi_center: NPVec3D, distance: float, angle: float, _donor_residue: str, _pi_residue: str)[source]#
Bases:
MolecularInteraction
Represents a D-X…π interaction.
This class stores information about a detected D-X…π interaction, where a donor atom with an interaction atom (H, F, Cl, Br, I) interacts with an aromatic π system. Supports multiple subtypes: - C-H…π, N-H…π, O-H…π, S-H…π (hydrogen-π interactions) - C-Cl…π, C-Br…π, C-I…π (halogen-π interactions)
- Parameters:
_donor (Atom) – The donor atom (C, N, O, S)
hydrogen (Atom) – The interaction atom (H, F, Cl, Br, I) - name kept for backward compatibility
pi_center (NPVec3D) – Center of the aromatic π system
distance (float) – X…π distance in Angstroms
angle (float) – D-X…π angle in radians
_donor_residue (str) – Identifier for donor residue
_pi_residue (str) – Identifier for π-containing residue
Dataclass representing π interactions including π-π stacking and X-H…π contacts.
Geometric Parameters:
Centroid distance: Distance between aromatic centroids
Ring angles: Angle between ring planes
Offset parameters: Lateral displacement measurements
- __init__(_donor: Atom, hydrogen: Atom, pi_center: NPVec3D, distance: float, angle: float, _donor_residue: str, _pi_residue: str)[source]#
Initialize a PiInteraction object.
- Parameters:
_donor (Atom) – The donor atom (C, N, O, S)
hydrogen (Atom) – The interaction atom (H, F, Cl, Br, I) - name kept for backward compatibility
pi_center (NPVec3D) – Center of the aromatic π system
distance (float) – X…π distance in Angstroms
angle (float) – D-X…π angle in radians
_donor_residue (str) – Identifier for donor residue
_pi_residue (str) – Identifier for π-containing residue
- property distance: float#
Legacy property for interaction distance.
- Returns:
Donor-interaction distance for backward compatibility
- Return type:
- property angle: float#
Legacy property for interaction angle.
- Returns:
Donor-interaction-acceptor angle for backward compatibility
- Return type:
- get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- is_donor_interaction_bonded() bool [source]#
Check if hydrogen is bonded to donor.
For X-H…π interactions, the hydrogen must be covalently bonded to the donor atom.
- Returns:
True (assumes validation was done during creation)
- Return type:
- property donor_acceptor_properties: str#
Get the donor-acceptor property description.
- Returns:
Property description string
- Return type:
- get_backbone_sidechain_interaction() str [source]#
Get simplified backbone/sidechain interaction description.
- Returns:
Interaction type (B-S, S-S, etc.)
- Return type:
- get_interaction_type_display() str [source]#
Get the interaction type for display purposes.
Generates display strings for different π interaction subtypes:
Hydrogen-π interactions: - “C-H…π” for carbon-hydrogen to π system - “N-H…π” for nitrogen-hydrogen to π system - “O-H…π” for oxygen-hydrogen to π system - “S-H…π” for sulfur-hydrogen to π system
Halogen-π interactions: - “C-Cl…π” for carbon-chlorine to π system - “C-Br…π” for carbon-bromine to π system - “C-I…π” for carbon-iodine to π system
- Returns:
Display format showing donor-interaction…π pattern
- Return type:
- class hbat.core.interactions.CooperativityChain(interactions: List[HydrogenBond | HalogenBond | PiInteraction], chain_length: int, chain_type: str)[source]#
Bases:
MolecularInteraction
Represents a chain of cooperative molecular interactions.
This class represents a series of linked molecular interactions where the acceptor of one interaction acts as the donor of the next, creating cooperative effects.
- Parameters:
interactions (List[Union[HydrogenBond, HalogenBond, PiInteraction]]) – List of interactions in the chain
chain_length (int) – Number of interactions in the chain
chain_type (str) – Description of the interaction types in the chain
Dataclass representing chains of cooperative molecular interactions.
Chain Analysis:
Sequential interaction connectivity
Cumulative interaction strength
Chain topology classification
- __init__(interactions: List[HydrogenBond | HalogenBond | PiInteraction], chain_length: int, chain_type: str)[source]#
Initialize a CooperativityChain object.
- Parameters:
interactions (List[Union[HydrogenBond, HalogenBond, PiInteraction]]) – List of interactions in the chain
chain_length (int) – Number of interactions in the chain
chain_type (str) – Description of the interaction types in the chain
- get_interaction() Atom | NPVec3D [source]#
Get the center point of the chain (middle interaction point).
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- get_donor_interaction_distance() float [source]#
Get the distance from chain start to middle interaction.
PDB Structure Handling#
PDB File Parser#
PDB file parser for molecular structure analysis using pdbreader.
This module provides functionality to parse PDB (Protein Data Bank) files and extract atomic coordinates and molecular information using the pdbreader library.
- class hbat.core.pdb_parser.PDBParser[source]#
Bases:
object
Parser for PDB format files using pdbreader.
This class handles parsing of PDB (Protein Data Bank) format files and converts them into HBAT’s internal atom and residue representations. Uses the pdbreader library for robust PDB format handling.
- __init__() None [source]#
Initialize PDB parser.
Creates a new parser instance with empty atom and residue lists.
- parse_file(filename: str) bool [source]#
Parse a PDB file.
Reads and parses a PDB format file, extracting all ATOM and HETATM records and converting them to HBAT’s internal representation.
- parse_lines(lines: List[str]) bool [source]#
Parse PDB format lines.
Parses PDB format content provided as a list of strings, useful for processing in-memory PDB data.
- get_atoms_by_residue(res_name: str) List[Atom] [source]#
Get all atoms from residues with specific name.
- get_hydrogen_atoms() List[Atom] [source]#
Get all hydrogen atoms.
- Returns:
List of all hydrogen and deuterium atoms
- Return type:
List[Atom]
- has_hydrogens() bool [source]#
Check if structure contains hydrogen atoms.
Determines if the structure has a reasonable number of hydrogen atoms compared to heavy atoms, indicating explicit hydrogen modeling.
- Returns:
True if structure appears to contain explicit hydrogens
- Return type:
- get_residue_list() List[Residue] [source]#
Get list of all residues.
- Returns:
List of all residues in the structure
- Return type:
List[Residue]
- get_chain_ids() List[str] [source]#
Get list of unique chain IDs.
- Returns:
List of unique chain identifiers in the structure
- Return type:
List[str]
- get_statistics() Dict[str, Any] [source]#
Get basic statistics about the structure.
Provides counts of atoms, residues, chains, and element composition.
- Returns:
Dictionary containing structure statistics
- Return type:
Dict[str, Any]
- get_bonds() List[Bond] [source]#
Get list of all bonds.
- Returns:
List of all bonds in the structure
- Return type:
List[Bond]
- class hbat.core.pdb_parser.PDBParser[source]#
Bases:
object
Parser for PDB format files using pdbreader.
This class handles parsing of PDB (Protein Data Bank) format files and converts them into HBAT’s internal atom and residue representations. Uses the pdbreader library for robust PDB format handling.
High-performance PDB file parser using the pdbreader library.
Features:
Robust parsing with error handling
Automatic bond detection and validation
Structure statistics and validation
Element mapping with utility functions
Usage Example:
from hbat.core.pdb_parser import PDBParser # Parse PDB file parser = PDBParser() atoms, residues, bonds = parser.parse_file("structure.pdb") # Get structure statistics stats = parser.get_statistics() print(f"Parsed {len(atoms)} atoms in {len(residues)} residues")
- __init__() None [source]#
Initialize PDB parser.
Creates a new parser instance with empty atom and residue lists.
- parse_file(filename: str) bool [source]#
Parse a PDB file.
Reads and parses a PDB format file, extracting all ATOM and HETATM records and converting them to HBAT’s internal representation.
- parse_lines(lines: List[str]) bool [source]#
Parse PDB format lines.
Parses PDB format content provided as a list of strings, useful for processing in-memory PDB data.
- get_atoms_by_residue(res_name: str) List[Atom] [source]#
Get all atoms from residues with specific name.
- get_hydrogen_atoms() List[Atom] [source]#
Get all hydrogen atoms.
- Returns:
List of all hydrogen and deuterium atoms
- Return type:
List[Atom]
- has_hydrogens() bool [source]#
Check if structure contains hydrogen atoms.
Determines if the structure has a reasonable number of hydrogen atoms compared to heavy atoms, indicating explicit hydrogen modeling.
- Returns:
True if structure appears to contain explicit hydrogens
- Return type:
- get_residue_list() List[Residue] [source]#
Get list of all residues.
- Returns:
List of all residues in the structure
- Return type:
List[Residue]
- get_chain_ids() List[str] [source]#
Get list of unique chain IDs.
- Returns:
List of unique chain identifiers in the structure
- Return type:
List[str]
- get_statistics() Dict[str, Any] [source]#
Get basic statistics about the structure.
Provides counts of atoms, residues, chains, and element composition.
- Returns:
Dictionary containing structure statistics
- Return type:
Dict[str, Any]
- get_bonds() List[Bond] [source]#
Get list of all bonds.
- Returns:
List of all bonds in the structure
- Return type:
List[Bond]
Molecular Data Structures#
- class hbat.core.structure.Atom(serial: int, name: str, alt_loc: str, res_name: str, chain_id: str, res_seq: int, i_code: str, coords: NPVec3D, occupancy: float, temp_factor: float, element: str, charge: str, record_type: str, residue_type: str = 'L', backbone_sidechain: str = 'S', aromatic: str = 'N')[source]#
Bases:
object
Represents an atom from a PDB file.
This class stores all atomic information parsed from PDB format including coordinates, properties, and residue information.
- Parameters:
serial (int) – Atom serial number
name (str) – Atom name
alt_loc (str) – Alternate location indicator
res_name (str) – Residue name
chain_id (str) – Chain identifier
res_seq (int) – Residue sequence number
i_code (str) – Insertion code
coords (NPVec3D) – 3D coordinates
occupancy (float) – Occupancy factor
temp_factor (float) – Temperature factor
element (str) – Element symbol
charge (str) – Formal charge
record_type (str) – PDB record type (ATOM or HETATM)
residue_type (str) – Residue type classification (P=Protein, D=DNA, R=RNA, L=Ligand)
backbone_sidechain (str) – Backbone/sidechain classification (B=Backbone, S=Sidechain)
aromatic (str) – Aromatic classification (A=Aromatic, N=Non-aromatic)
Class representing an atom with comprehensive PDB information and calculated properties. Supports iteration, dictionary conversion, and field introspection.
- __init__(serial: int, name: str, alt_loc: str, res_name: str, chain_id: str, res_seq: int, i_code: str, coords: NPVec3D, occupancy: float, temp_factor: float, element: str, charge: str, record_type: str, residue_type: str = 'L', backbone_sidechain: str = 'S', aromatic: str = 'N') None [source]#
Initialize an Atom object.
- Parameters:
serial (int) – Atom serial number
name (str) – Atom name
alt_loc (str) – Alternate location indicator
res_name (str) – Residue name
chain_id (str) – Chain identifier
res_seq (int) – Residue sequence number
i_code (str) – Insertion code
coords (NPVec3D) – 3D coordinates
occupancy (float) – Occupancy factor
temp_factor (float) – Temperature factor
element (str) – Element symbol
charge (str) – Formal charge
record_type (str) – PDB record type (ATOM or HETATM)
residue_type (str) – Residue type classification (P=Protein, D=DNA, R=RNA, L=Ligand)
backbone_sidechain (str) – Backbone/sidechain classification (B=Backbone, S=Sidechain)
aromatic (str) – Aromatic classification (A=Aromatic, N=Non-aromatic)
- is_hydrogen() bool [source]#
Check if atom is hydrogen.
- Returns:
True if atom is hydrogen or deuterium
- Return type:
- is_metal() bool [source]#
Check if atom is a metal.
- Returns:
True if atom is a common metal ion
- Return type:
- __iter__() Iterator[Tuple[str, Any]] [source]#
Iterate over atom attributes as (name, value) pairs.
- Returns:
Iterator of (attribute_name, value) tuples
- Return type:
Iterator[Tuple[str, Any]]
- to_dict() Dict[str, Any] [source]#
Convert atom to dictionary.
- Returns:
Dictionary representation of the atom
- Return type:
Dict[str, Any]
- class hbat.core.structure.Residue(name: str, chain_id: str, seq_num: int, i_code: str, atoms: List[Atom])[source]#
Bases:
object
Represents a residue containing multiple atoms.
This class groups atoms belonging to the same residue and provides methods for accessing and analyzing residue-level information.
- Parameters:
Class representing a residue with atom collections and residue-level properties. Includes aromatic center calculation and atom management.
- __init__(name: str, chain_id: str, seq_num: int, i_code: str, atoms: List[Atom]) None [source]#
Initialize a Residue object.
- center_of_mass() NPVec3D [source]#
Calculate center of mass of residue.
Computes the mass-weighted centroid of all atoms in the residue.
- Returns:
Center of mass coordinates
- Return type:
- get_aromatic_center() NPVec3D | None [source]#
Calculate aromatic ring center if residue is aromatic.
For aromatic residues (PHE, TYR, TRP, HIS), calculates the geometric center of the aromatic ring atoms.
- Returns:
Center coordinates of aromatic ring, None if not aromatic
- Return type:
Optional[NPVec3D]
- __iter__() Iterator[Tuple[str, Any]] [source]#
Iterate over residue attributes as (name, value) pairs.
- Returns:
Iterator of (attribute_name, value) tuples
- Return type:
Iterator[Tuple[str, Any]]
- to_dict() Dict[str, Any] [source]#
Convert residue to dictionary.
- Returns:
Dictionary representation of the residue
- Return type:
Dict[str, Any]
- class hbat.core.structure.Bond(atom1_serial: int, atom2_serial: int, bond_type: str = 'covalent', distance: float | None = None, detection_method: str = 'distance_based')[source]#
Bases:
object
Represents a chemical bond between two atoms.
This class stores information about atomic bonds, including the atoms involved and bond type/origin.
- Parameters:
Class representing a chemical bond between two atoms with bond properties. Provides methods for bond analysis and atom involvement checking.
- __init__(atom1_serial: int, atom2_serial: int, bond_type: str = 'covalent', distance: float | None = None, detection_method: str = 'distance_based') None [source]#
Initialize a Bond object.
- Parameters:
- __iter__() Iterator[Tuple[str, Any]] [source]#
Iterate over bond attributes as (name, value) pairs.
- Returns:
Iterator of (attribute_name, value) tuples
- Return type:
Iterator[Tuple[str, Any]]
- to_dict() Dict[str, Any] [source]#
Convert bond to dictionary.
- Returns:
Dictionary representation of the bond
- Return type:
Dict[str, Any]
PDB Structure Enhancement#
PDB Structure Fixer#
PDB structure fixing module for adding missing hydrogen atoms.
This module provides functionality to add missing hydrogen atoms to PDB structures using either OpenBabel or PDBFixer tools. It integrates with HBAT’s internal data structures and provides a clean interface for structure enhancement.
- exception hbat.core.pdb_fixer.PDBFixerError[source]#
Bases:
Exception
Exception raised when PDB fixing operations fail.
- class hbat.core.pdb_fixer.PDBFixer[source]#
Bases:
object
Fix PDB structures by adding missing hydrogen atoms.
This class provides methods to add missing hydrogen atoms to protein structures using either OpenBabel or PDBFixer with OpenMM. It works with HBAT’s internal atom and residue data structures.
- add_missing_hydrogens(atoms: List[Atom], method: str = 'openbabel', pH: float = 7.0, **kwargs: Any) List[Atom] [source]#
Add missing hydrogen atoms to a list of atoms.
Takes a list of HBAT Atom objects and returns a new list with missing hydrogen atoms added using the specified method.
- Parameters:
- Returns:
List of atoms with hydrogens added
- Return type:
List[Atom]
- Raises:
PDBFixerError if fixing fails
- add_missing_heavy_atoms(atoms: List[Atom], method: str = 'pdbfixer', **kwargs: Any) List[Atom] [source]#
Add missing heavy atoms to a structure.
Uses PDBFixer to identify and add missing heavy atoms in residues. This is particularly useful for structures with incomplete side chains.
- convert_nonstandard_residues(atoms: List[Atom], custom_replacements: Dict[str, str] | None = None) List[Atom] [source]#
Convert non-standard residues to their standard equivalents using PDBFixer.
This method uses PDBFixer’s built-in findNonstandardResidues() and replaceNonstandardResidues() methods to properly handle non-standard residues.
- remove_heterogens(atoms: List[Atom], keep_water: bool = True) List[Atom] [source]#
Remove unwanted heterogens from the structure using PDBFixer.
Uses PDBFixer’s built-in removeHeterogens() method to properly handle heterogen removal with the option to keep water molecules.
- fix_structure_file(input_path: str, output_path: str | None = None, method: str = 'openbabel', pH: float = 7.0, overwrite: bool = False, **kwargs: Any) str [source]#
Fix a PDB file by adding missing hydrogen atoms.
- Parameters:
input_path (str) – Path to input PDB file
output_path (Optional[str]) – Path for output file (optional)
method (str) – Method to use (‘openbabel’ or ‘pdbfixer’)
pH (float) – pH value for protonation (pdbfixer only)
overwrite (bool) – Whether to overwrite existing output file
kwargs (Any) – Additional parameters for the fixing method
- Returns:
Path to the output file
- Return type:
- Raises:
PDBFixerError if fixing fails
- fix_pdb_file_to_file(input_pdb_path: str, output_pdb_path: str, method: str = 'openbabel', add_hydrogens: bool = True, add_heavy_atoms: bool = False, convert_nonstandard: bool = False, remove_heterogens: bool = False, keep_water: bool = True, pH: float = 7.0, **kwargs: Any) bool [source]#
Fix a PDB file and save the result to another file.
This method processes the original PDB file directly and saves the fixed structure to a new file, preserving proper PDB formatting.
- Parameters:
input_pdb_path (str) – Path to the original PDB file
output_pdb_path (str) – Path where the fixed PDB should be saved
method (str) – Method to use (‘openbabel’ or ‘pdbfixer’)
add_hydrogens (bool) – Whether to add missing hydrogen atoms
add_heavy_atoms (bool) – Whether to add missing heavy atoms (pdbfixer only)
convert_nonstandard (bool) – Whether to convert nonstandard residues (pdbfixer only)
remove_heterogens (bool) – Whether to remove heterogens (pdbfixer only)
keep_water (bool) – Whether to keep water molecules when removing heterogens
pH (float) – pH value for protonation (pdbfixer only)
kwargs (Any) – Additional parameters
- Returns:
True if fixing succeeded, False otherwise
- Return type:
- Raises:
PDBFixerError if fixing fails
- hbat.core.pdb_fixer.add_missing_hydrogens(atoms: List[Atom], method: str = 'openbabel', pH: float = 7.0, **kwargs: Any) List[Atom] [source]#
Convenience function to add missing hydrogen atoms.
- hbat.core.pdb_fixer.fix_pdb_file(input_path: str, output_path: str | None = None, method: str = 'openbabel', pH: float = 7.0, overwrite: bool = False, **kwargs: Any) str [source]#
Convenience function to fix a PDB file.
- Parameters:
input_path (str) – Path to input PDB file
output_path (Optional[str]) – Path for output file (optional)
method (str) – Method to use (‘openbabel’ or ‘pdbfixer’)
pH (float) – pH value for protonation (pdbfixer only)
overwrite (bool) – Whether to overwrite existing output file
kwargs (Any) – Additional parameters for the fixing method
- Returns:
Path to the output file
- Return type:
- hbat.core.pdb_fixer.add_missing_heavy_atoms(atoms: List[Atom], method: str = 'pdbfixer', **kwargs: Any) List[Atom] [source]#
Convenience function to add missing heavy atoms.
- hbat.core.pdb_fixer.convert_nonstandard_residues(atoms: List[Atom], custom_replacements: Dict[str, str] | None = None) List[Atom] [source]#
Convenience function to convert non-standard residues using PDBFixer.
Uses PDBFixer’s built-in findNonstandardResidues() and replaceNonstandardResidues() methods to properly handle non-standard residue conversion.
- hbat.core.pdb_fixer.remove_heterogens(atoms: List[Atom], keep_water: bool = True) List[Atom] [source]#
Convenience function to remove unwanted heterogens using PDBFixer.
Uses PDBFixer’s built-in removeHeterogens() method which only supports the option to keep or remove water molecules.
- class hbat.core.pdb_fixer.PDBFixer[source]#
Bases:
object
Fix PDB structures by adding missing hydrogen atoms.
This class provides methods to add missing hydrogen atoms to protein structures using either OpenBabel or PDBFixer with OpenMM. It works with HBAT’s internal atom and residue data structures.
Comprehensive PDB structure enhancement and fixing utility.
Fixing Capabilities:
Missing hydrogen atom addition (OpenBabel/PDBFixer)
Missing heavy atom reconstruction (PDBFixer only)
Non-standard residue conversion (PDBFixer only)
Hetrogen removal and filtering (PDBFixer only)
Direct file-to-file processing for preserved formatting
Usage Example:
from hbat.core.pdb_fixer import PDBFixer # Initialize fixer fixer = PDBFixer() # Fix structure directly from file to file success = fixer.fix_pdb_file_to_file( input_pdb_path="input.pdb", output_pdb_path="input_fixed.pdb", method="openbabel", add_hydrogens=True ) # Or use atom-based processing fixed_atoms = fixer.add_missing_hydrogens(atoms, method="pdbfixer")
- add_missing_hydrogens(atoms: List[Atom], method: str = 'openbabel', pH: float = 7.0, **kwargs: Any) List[Atom] [source]#
Add missing hydrogen atoms to a list of atoms.
Takes a list of HBAT Atom objects and returns a new list with missing hydrogen atoms added using the specified method.
- Parameters:
- Returns:
List of atoms with hydrogens added
- Return type:
List[Atom]
- Raises:
PDBFixerError if fixing fails
- add_missing_heavy_atoms(atoms: List[Atom], method: str = 'pdbfixer', **kwargs: Any) List[Atom] [source]#
Add missing heavy atoms to a structure.
Uses PDBFixer to identify and add missing heavy atoms in residues. This is particularly useful for structures with incomplete side chains.
- convert_nonstandard_residues(atoms: List[Atom], custom_replacements: Dict[str, str] | None = None) List[Atom] [source]#
Convert non-standard residues to their standard equivalents using PDBFixer.
This method uses PDBFixer’s built-in findNonstandardResidues() and replaceNonstandardResidues() methods to properly handle non-standard residues.
- remove_heterogens(atoms: List[Atom], keep_water: bool = True) List[Atom] [source]#
Remove unwanted heterogens from the structure using PDBFixer.
Uses PDBFixer’s built-in removeHeterogens() method to properly handle heterogen removal with the option to keep water molecules.
- fix_structure_file(input_path: str, output_path: str | None = None, method: str = 'openbabel', pH: float = 7.0, overwrite: bool = False, **kwargs: Any) str [source]#
Fix a PDB file by adding missing hydrogen atoms.
- Parameters:
input_path (str) – Path to input PDB file
output_path (Optional[str]) – Path for output file (optional)
method (str) – Method to use (‘openbabel’ or ‘pdbfixer’)
pH (float) – pH value for protonation (pdbfixer only)
overwrite (bool) – Whether to overwrite existing output file
kwargs (Any) – Additional parameters for the fixing method
- Returns:
Path to the output file
- Return type:
- Raises:
PDBFixerError if fixing fails
- fix_pdb_file_to_file(input_pdb_path: str, output_pdb_path: str, method: str = 'openbabel', add_hydrogens: bool = True, add_heavy_atoms: bool = False, convert_nonstandard: bool = False, remove_heterogens: bool = False, keep_water: bool = True, pH: float = 7.0, **kwargs: Any) bool [source]#
Fix a PDB file and save the result to another file.
This method processes the original PDB file directly and saves the fixed structure to a new file, preserving proper PDB formatting.
- Parameters:
input_pdb_path (str) – Path to the original PDB file
output_pdb_path (str) – Path where the fixed PDB should be saved
method (str) – Method to use (‘openbabel’ or ‘pdbfixer’)
add_hydrogens (bool) – Whether to add missing hydrogen atoms
add_heavy_atoms (bool) – Whether to add missing heavy atoms (pdbfixer only)
convert_nonstandard (bool) – Whether to convert nonstandard residues (pdbfixer only)
remove_heterogens (bool) – Whether to remove heterogens (pdbfixer only)
keep_water (bool) – Whether to keep water molecules when removing heterogens
pH (float) – pH value for protonation (pdbfixer only)
kwargs (Any) – Additional parameters
- Returns:
True if fixing succeeded, False otherwise
- Return type:
- Raises:
PDBFixerError if fixing fails
3D Vector Mathematics#
NumPy Vector Operations#
NumPy-based 3D vector mathematics for molecular analysis.
This module provides efficient vector operations for high-performance molecular geometry calculations, supporting both single vectors and batch operations on multiple vectors simultaneously.
- class hbat.core.np_vector.NPVec3D(coords: float | ndarray | List[float] | Tuple[float, float, float] = 0.0, y: float | None = None, z: float | None = None)[source]#
Bases:
object
NumPy-based 3D vector class for molecular calculations.
This class provides comprehensive 3D vector operations using NumPy, enabling efficient batch processing of multiple vectors simultaneously.
- Parameters:
- __init__(coords: float | ndarray | List[float] | Tuple[float, float, float] = 0.0, y: float | None = None, z: float | None = None)[source]#
Initialize a 3D vector or batch of vectors.
- length() float | ndarray [source]#
Calculate vector length/magnitude.
- Returns:
Euclidean length of the vector(s)
- Return type:
Union[float, np.ndarray]
- normalize() NPVec3D [source]#
Return normalized unit vector(s).
- Returns:
Unit vector(s) in the same direction
- Return type:
- to_array() ndarray [source]#
Convert to numpy array.
- Returns:
Numpy array of coordinates
- Return type:
np.ndarray
- to_list() List[float] [source]#
Convert to list [x, y, z] (single vector only).
- Returns:
Vector components as a list
- Return type:
List[float]
- hbat.core.np_vector.compute_distance_matrix(coords1: ndarray, coords2: ndarray | None = None) ndarray [source]#
Compute pairwise distance matrix between two sets of coordinates.
- Parameters:
coords1 (np.ndarray) – First set of coordinates, shape (N, 3)
coords2 (Optional[np.ndarray]) – Second set of coordinates, shape (M, 3). If None, computes self-distances
- Returns:
Distance matrix of shape (N, M) or (N, N)
- Return type:
np.ndarray
- hbat.core.np_vector.batch_angle_between(a: NPVec3D, b: NPVec3D, c: NPVec3D | None = None) float | ndarray [source]#
Calculate angles between vectors (optimized for batches).
If c is provided: Calculate angle ABC where B is the vertex. If c is None: Calculate angle between vectors a and b.
- hbat.core.np_vector.batch_dihedral_angle(a: NPVec3D, b: NPVec3D, c: NPVec3D, d: NPVec3D) float | ndarray [source]#
Calculate dihedral angles between planes ABC and BCD (optimized for batches).
- class hbat.core.np_vector.NPVec3D(coords: float | ndarray | List[float] | Tuple[float, float, float] = 0.0, y: float | None = None, z: float | None = None)[source]#
Bases:
object
NumPy-based 3D vector class for molecular calculations.
This class provides comprehensive 3D vector operations using NumPy, enabling efficient batch processing of multiple vectors simultaneously.
- Parameters:
High-performance 3D vector class using NumPy for molecular geometry calculations.
Mathematical Operations:
Standard arithmetic: addition, subtraction, multiplication, division
Vector operations: dot product, cross product, normalization
Geometric calculations: distances, angles, projections
NumPy array compatibility and vectorized operations
Usage Example:
from hbat.core.np_vector import NPVec3D # Create vectors v1 = NPVec3D(1.0, 0.0, 0.0) v2 = NPVec3D(0.0, 1.0, 0.0) # Vector operations cross_product = v1.cross(v2) # Returns NPVec3D(0.0, 0.0, 1.0) angle = v1.angle_to(v2) # Returns π/2 radians distance = v1.distance_to(v2) # Returns √2
- __init__(coords: float | ndarray | List[float] | Tuple[float, float, float] = 0.0, y: float | None = None, z: float | None = None)[source]#
Initialize a 3D vector or batch of vectors.
- length() float | ndarray [source]#
Calculate vector length/magnitude.
- Returns:
Euclidean length of the vector(s)
- Return type:
Union[float, np.ndarray]
- normalize() NPVec3D [source]#
Return normalized unit vector(s).
- Returns:
Unit vector(s) in the same direction
- Return type:
- to_array() ndarray [source]#
Convert to numpy array.
- Returns:
Numpy array of coordinates
- Return type:
np.ndarray
- to_list() List[float] [source]#
Convert to list [x, y, z] (single vector only).
- Returns:
Vector components as a list
- Return type:
List[float]
Utility Functions#
- hbat.core.np_vector.compute_distance_matrix(coords1: ndarray, coords2: ndarray | None = None) ndarray [source]#
Compute pairwise distance matrix between two sets of coordinates.
- Parameters:
coords1 (np.ndarray) – First set of coordinates, shape (N, 3)
coords2 (Optional[np.ndarray]) – Second set of coordinates, shape (M, 3). If None, computes self-distances
- Returns:
Distance matrix of shape (N, M) or (N, N)
- Return type:
np.ndarray
Compute distance matrix between two sets of coordinates using vectorized operations.
- hbat.core.np_vector.batch_angle_between(a: NPVec3D, b: NPVec3D, c: NPVec3D | None = None) float | ndarray [source]#
Calculate angles between vectors (optimized for batches).
If c is provided: Calculate angle ABC where B is the vertex. If c is None: Calculate angle between vectors a and b.
- Parameters:
- Returns:
Angle(s) in radians
- Return type:
Union[float, np.ndarray]
Calculate angle between three points with vectorized NumPy operations.
Legacy Compatibility#
Analysis Module (Backward Compatibility)#
Core analysis engine for hydrogen bond and molecular interaction analysis.
This module implements the main computational logic for detecting and analyzing molecular interactions including hydrogen bonds, halogen bonds, and X-H…π interactions.
For better maintainability, this module has been split into several focused modules: - interactions.py: Interaction data classes - parameters.py: Analysis parameters - analyzer.py: Main analysis engine
This file maintains backward compatibility by re-exporting all classes.
This module provides backward compatibility by re-exporting classes from the refactored modules.
Re-exported Classes:
NPMolecularInteractionAnalyzer from np_analyzer.py
AnalysisParameters from constants.parameters
All interaction classes from interactions.py
Migration Note:
For new code, import directly from the specific modules:
# Recommended for new code
from hbat.core.np_analyzer import NPMolecularInteractionAnalyzer
from hbat.core.interactions import HydrogenBond
# Still works (backward compatibility)
from hbat.core.analysis import NPMolecularInteractionAnalyzer, HydrogenBond
- hbat.core.analysis.MolecularInteractionAnalyzer#
alias of
NPMolecularInteractionAnalyzer
- class hbat.core.analysis.NPMolecularInteractionAnalyzer(parameters: AnalysisParameters | None = None)[source]#
Bases:
object
High-performance analyzer for molecular interactions.
This analyzer uses vectorized NumPy operations for efficient analysis of molecular interactions in protein structures. Supports comprehensive detection of:
Hydrogen bonds: Classical N-H···O, O-H···O, N-H···N interactions
Weak hydrogen bonds: C-H···O interactions (important in protein-ligand binding)
Halogen bonds: C-X···A interactions where X is Cl, Br, I (default angle: 150°)
π interactions: Multiple subtypes including:
Hydrogen-π: C-H···π, N-H···π, O-H···π, S-H···π
Halogen-π: C-Cl···π, C-Br···π, C-I···π
Cooperativity chains: Networks of linked interactions
- Parameters:
parameters (Optional[AnalysisParameters]) – Analysis parameters with subtype-specific cutoffs
- __init__(parameters: AnalysisParameters | None = None)[source]#
Initialize analyzer with parameters.
- analyze_file(pdb_file: str) bool [source]#
Analyze a PDB file for molecular interactions.
Performs comprehensive analysis of hydrogen bonds, weak hydrogen bonds (C-H···O), halogen bonds, π interactions (including subtypes: C-H···π, N-H···π, O-H···π, S-H···π, C-Cl···π, C-Br···π, C-I···π), and cooperativity chains in the provided PDB structure. Optionally applies PDB fixing to add missing atoms if enabled in parameters.
- get_summary() Dict[str, Any] [source]#
Get comprehensive analysis summary with statistics, PDB fixing info, and timing.
Returns a dictionary containing interaction counts, averages, bond type distributions, PDB fixing information (if applied), and analysis timing.
- Returns:
Dictionary containing comprehensive analysis summary
- Return type:
Dict[str, Any]
- hbat.core.analysis.HBondAnalyzer#
alias of
NPMolecularInteractionAnalyzer
- class hbat.core.analysis.AnalysisParameters(hb_distance_cutoff: float = 2.5, hb_angle_cutoff: float = 120.0, hb_donor_acceptor_cutoff: float = 3.5, whb_distance_cutoff: float = 3.6, whb_angle_cutoff: float = 150.0, whb_donor_acceptor_cutoff: float = 3.5, xb_distance_cutoff: float = 3.9, xb_angle_cutoff: float = 150.0, pi_distance_cutoff: float = 3.5, pi_angle_cutoff: float = 110.0, pi_ccl_distance_cutoff: float = 3.5, pi_ccl_angle_cutoff: float = 145, pi_cbr_distance_cutoff: float = 3.5, pi_cbr_angle_cutoff: float = 155, pi_ci_distance_cutoff: float = 3.6, pi_ci_angle_cutoff: float = 165.0, pi_ch_distance_cutoff: float = 3.5, pi_ch_angle_cutoff: float = 110.0, pi_nh_distance_cutoff: float = 3.2, pi_nh_angle_cutoff: float = 115.0, pi_oh_distance_cutoff: float = 3.0, pi_oh_angle_cutoff: float = 115.0, pi_sh_distance_cutoff: float = 3.8, pi_sh_angle_cutoff: float = 105.0, covalent_cutoff_factor: float = 0.85, analysis_mode: str = 'complete', fix_pdb_enabled: bool = True, fix_pdb_method: str = 'pdbfixer', fix_pdb_add_hydrogens: bool = True, fix_pdb_add_heavy_atoms: bool = False, fix_pdb_replace_nonstandard: bool = False, fix_pdb_remove_heterogens: bool = False, fix_pdb_keep_water: bool = True, **kwargs)[source]#
Bases:
object
Parameters for comprehensive molecular interaction analysis.
This class contains all configurable parameters for detecting and analyzing molecular interactions in protein structures. Supports multiple interaction types with subtype-specific parameters.
Hydrogen Bonds (Classical): - Strong N-H···O, O-H···O, N-H···N interactions - Default: 2.5Å H···A distance, 120° D-H···A angle
Weak Hydrogen Bonds (C-H···O): - Carbon-hydrogen donor interactions with oxygen acceptors - Default: 3.6Å H···A distance, 150° D-H···A angle - Important in protein-ligand binding and aromatic interactions
Halogen Bonds: - C-X···A interactions where X is Cl, Br, I - Default: 3.9Å X···A distance, 150° C-X···A angle (updated default)
π Interactions (Multiple Subtypes): - Hydrogen-π: C-H···π, N-H···π, O-H···π, S-H···π - Halogen-π: C-Cl···π, C-Br···π, C-I···π - Each subtype has optimized distance/angle cutoffs
- Parameters:
hb_distance_cutoff (float) – Maximum H…A distance for hydrogen bonds (Å)
hb_angle_cutoff (float) – Minimum D-H…A angle for hydrogen bonds (degrees)
hb_donor_acceptor_cutoff (float) – Maximum D…A distance for hydrogen bonds (Å)
whb_distance_cutoff (float) – Maximum H…A distance for weak hydrogen bonds (Å)
whb_angle_cutoff (float) – Minimum D-H…A angle for weak hydrogen bonds (degrees)
whb_donor_acceptor_cutoff (float) – Maximum D…A distance for weak hydrogen bonds (Å)
xb_distance_cutoff (float) – Maximum X…A distance for halogen bonds (Å)
xb_angle_cutoff (float) – Minimum C-X…A angle for halogen bonds (degrees, default: 150°)
pi_distance_cutoff (float) – Maximum H…π distance for π interactions (Å, legacy)
pi_angle_cutoff (float) – Minimum D-H…π angle for π interactions (degrees, legacy)
pi_ccl_distance_cutoff (float) – Maximum C-Cl…π distance for halogen-π interactions (Å)
pi_ccl_angle_cutoff (float) – Minimum C-Cl…π angle for halogen-π interactions (degrees)
pi_cbr_distance_cutoff (float) – Maximum C-Br…π distance for halogen-π interactions (Å)
pi_cbr_angle_cutoff (float) – Minimum C-Br…π angle for halogen-π interactions (degrees)
pi_ci_distance_cutoff (float) – Maximum C-I…π distance for halogen-π interactions (Å)
pi_ci_angle_cutoff (float) – Minimum C-I…π angle for halogen-π interactions (degrees)
pi_ch_distance_cutoff (float) – Maximum C-H…π distance for hydrogen-π interactions (Å)
pi_ch_angle_cutoff (float) – Minimum C-H…π angle for hydrogen-π interactions (degrees)
pi_nh_distance_cutoff (float) – Maximum N-H…π distance for hydrogen-π interactions (Å)
pi_nh_angle_cutoff (float) – Minimum N-H…π angle for hydrogen-π interactions (degrees)
pi_oh_distance_cutoff (float) – Maximum O-H…π distance for hydrogen-π interactions (Å)
pi_oh_angle_cutoff (float) – Minimum O-H…π angle for hydrogen-π interactions (degrees)
pi_sh_distance_cutoff (float) – Maximum S-H…π distance for hydrogen-π interactions (Å)
pi_sh_angle_cutoff (float) – Minimum S-H…π angle for hydrogen-π interactions (degrees)
covalent_cutoff_factor (float) – Factor for covalent bond detection
analysis_mode (str) – Analysis mode (‘local’ or ‘global’)
fix_pdb_enabled (bool) – Enable PDB structure fixing
fix_pdb_method (str) – PDB fixing method (‘openbabel’ or ‘pdbfixer’)
fix_pdb_add_hydrogens (bool) – Add missing hydrogen atoms (both methods)
fix_pdb_add_heavy_atoms (bool) – Add missing heavy atoms (PDBFixer only)
fix_pdb_replace_nonstandard (bool) – Replace nonstandard residues (PDBFixer only)
fix_pdb_remove_heterogens (bool) – Remove heterogens (PDBFixer only)
fix_pdb_keep_water (bool) – Keep water when removing heterogens (PDBFixer only)
- __eq__(other) bool [source]#
Compare two AnalysisParameters objects for equality.
- Parameters:
other (AnalysisParameters) – Other AnalysisParameters object to compare
- Returns:
True if all parameters are equal
- Return type:
- __hash__() int [source]#
Return hash of the parameters object for use in sets/dicts.
- Returns:
Hash value based on all parameters
- Return type:
- __init__(hb_distance_cutoff: float = 2.5, hb_angle_cutoff: float = 120.0, hb_donor_acceptor_cutoff: float = 3.5, whb_distance_cutoff: float = 3.6, whb_angle_cutoff: float = 150.0, whb_donor_acceptor_cutoff: float = 3.5, xb_distance_cutoff: float = 3.9, xb_angle_cutoff: float = 150.0, pi_distance_cutoff: float = 3.5, pi_angle_cutoff: float = 110.0, pi_ccl_distance_cutoff: float = 3.5, pi_ccl_angle_cutoff: float = 145, pi_cbr_distance_cutoff: float = 3.5, pi_cbr_angle_cutoff: float = 155, pi_ci_distance_cutoff: float = 3.6, pi_ci_angle_cutoff: float = 165.0, pi_ch_distance_cutoff: float = 3.5, pi_ch_angle_cutoff: float = 110.0, pi_nh_distance_cutoff: float = 3.2, pi_nh_angle_cutoff: float = 115.0, pi_oh_distance_cutoff: float = 3.0, pi_oh_angle_cutoff: float = 115.0, pi_sh_distance_cutoff: float = 3.8, pi_sh_angle_cutoff: float = 105.0, covalent_cutoff_factor: float = 0.85, analysis_mode: str = 'complete', fix_pdb_enabled: bool = True, fix_pdb_method: str = 'pdbfixer', fix_pdb_add_hydrogens: bool = True, fix_pdb_add_heavy_atoms: bool = False, fix_pdb_replace_nonstandard: bool = False, fix_pdb_remove_heterogens: bool = False, fix_pdb_keep_water: bool = True, **kwargs)[source]#
Initialize analysis parameters.
- Parameters:
hb_distance_cutoff (float) – Maximum H…A distance for hydrogen bonds (Å)
hb_angle_cutoff (float) – Minimum D-H…A angle for hydrogen bonds (degrees)
hb_donor_acceptor_cutoff (float) – Maximum D…A distance for hydrogen bonds (Å)
whb_distance_cutoff (float) – Maximum H…A distance for weak hydrogen bonds (Å)
whb_angle_cutoff (float) – Minimum D-H…A angle for weak hydrogen bonds (degrees)
whb_donor_acceptor_cutoff (float) – Maximum D…A distance for weak hydrogen bonds (Å)
xb_distance_cutoff (float) – Maximum X…A distance for halogen bonds (Å)
xb_angle_cutoff (float) – Minimum C-X…A angle for halogen bonds (degrees)
pi_distance_cutoff (float) – Maximum H…π distance for π interactions (Å)
pi_angle_cutoff (float) – Minimum D-H…π angle for π interactions (degrees)
covalent_cutoff_factor (float) – Factor for covalent bond detection
analysis_mode (str) – Analysis mode (‘local’ or ‘global’)
fix_pdb_enabled (bool) – Enable PDB structure fixing
fix_pdb_method (str) – PDB fixing method (‘openbabel’ or ‘pdbfixer’)
fix_pdb_add_hydrogens (bool) – Add missing hydrogen atoms (both methods)
fix_pdb_add_heavy_atoms (bool) – Add missing heavy atoms (PDBFixer only)
fix_pdb_replace_nonstandard (bool) – Replace nonstandard residues (PDBFixer only)
fix_pdb_remove_heterogens (bool) – Remove heterogens (PDBFixer only)
fix_pdb_keep_water (bool) – Keep water when removing heterogens (PDBFixer only)
kwargs (dict) – Additional parameters (for future extensibility)
- __repr__() str [source]#
Return string representation of the parameters object.
- Returns:
String representation showing all parameters
- Return type:
- classmethod from_dict(data: dict) AnalysisParameters [source]#
Create AnalysisParameters object from dictionary.
- Parameters:
data (dict) – Dictionary containing parameter values
- Returns:
New AnalysisParameters object
- Return type:
- class hbat.core.analysis.MolecularInteraction[source]#
Bases:
ABC
Base class for all molecular interactions.
This abstract base class defines the unified interface for all types of molecular interactions analyzed by HBAT, including hydrogen bonds, halogen bonds, and π interactions.
All interactions have the following core components: - Donor: The electron/proton donor (atom or virtual atom) - Acceptor: The electron/proton acceptor (atom or virtual atom) - Interaction: The mediating atom/point (e.g., hydrogen, π center) - Geometry: Distances and angles defining the interaction - Bonding: The interaction atom must be bonded to the donor atom
Bonding Requirements: - For H-bonds: Hydrogen must be covalently bonded to the donor - For X-bonds: Halogen is covalently bonded to donor carbon - For X-H…π interactions: Hydrogen must be covalently bonded to the donor - For π-π stacking (future): No bonding requirement - uses centroid distances
- property angle: float#
Legacy property for interaction angle.
- Returns:
Donor-interaction-acceptor angle for backward compatibility
- Return type:
- property distance: float#
Legacy property for interaction distance.
- Returns:
Donor-interaction distance for backward compatibility
- Return type:
- property donor_interaction_acceptor_angle: float#
Property accessor for donor-interaction-acceptor angle.
- get_acceptor_atom() Atom | None [source]#
Get the acceptor atom if it’s an Atom instance.
- Returns:
The acceptor atom if it’s an Atom, None otherwise
- Return type:
Optional[Atom]
- abstractmethod get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- abstractmethod get_donor_acceptor_distance() float [source]#
Get the donor to acceptor distance.
- Returns:
Distance from donor to acceptor in Angstroms
- Return type:
- get_donor_atom() Atom | None [source]#
Get the donor atom if it’s an Atom instance.
- Returns:
The donor atom if it’s an Atom, None otherwise
- Return type:
Optional[Atom]
- abstractmethod get_donor_interaction_acceptor_angle() float [source]#
Get the donor-interaction-acceptor angle.
- Returns:
Angle in radians
- Return type:
- abstractmethod get_donor_interaction_distance() float [source]#
Get the donor to interaction distance.
- Returns:
Distance from donor to interaction point in Angstroms
- Return type:
- abstractmethod get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- abstractmethod get_interaction() Atom | NPVec3D [source]#
Get the interaction mediating atom or point.
- abstractmethod get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- abstractmethod is_donor_interaction_bonded() bool [source]#
Check if the interaction atom is bonded to the donor atom.
This is a fundamental requirement for most molecular interactions (except π-π stacking which will be implemented separately).
- Returns:
True if donor and interaction atom are bonded
- Return type:
- class hbat.core.analysis.HydrogenBond(_donor: Atom, hydrogen: Atom, _acceptor: Atom, distance: float, angle: float, _donor_acceptor_distance: float, bond_type: str, _donor_residue: str, _acceptor_residue: str)[source]#
Bases:
MolecularInteraction
Represents a hydrogen bond interaction.
This class stores all information about a detected hydrogen bond, including the participating atoms, geometric parameters, and classification information.
- Parameters:
_donor (Atom) – The hydrogen bond donor atom
hydrogen (Atom) – The hydrogen atom in the bond
_acceptor (Atom) – The hydrogen bond acceptor atom
distance (float) – H…A distance in Angstroms
angle (float) – D-H…A angle in radians
_donor_acceptor_distance (float) – D…A distance in Angstroms
bond_type (str) – Classification of the hydrogen bond type
_donor_residue (str) – Identifier for donor residue
_acceptor_residue (str) – Identifier for acceptor residue
- __init__(_donor: Atom, hydrogen: Atom, _acceptor: Atom, distance: float, angle: float, _donor_acceptor_distance: float, bond_type: str, _donor_residue: str, _acceptor_residue: str)[source]#
Initialize a HydrogenBond object.
- Parameters:
_donor (Atom) – The hydrogen bond donor atom
hydrogen (Atom) – The hydrogen atom in the bond
_acceptor (Atom) – The hydrogen bond acceptor atom
distance (float) – H…A distance in Angstroms
angle (float) – D-H…A angle in radians
_donor_acceptor_distance (float) – D…A distance in Angstroms
bond_type (str) – Classification of the hydrogen bond type
_donor_residue (str) – Identifier for donor residue
_acceptor_residue (str) – Identifier for acceptor residue
- property angle: float#
Legacy property for interaction angle.
- Returns:
Donor-interaction-acceptor angle for backward compatibility
- Return type:
- property distance: float#
Legacy property for interaction distance.
- Returns:
Donor-interaction distance for backward compatibility
- Return type:
- property donor_acceptor_properties: str#
Get the donor-acceptor property description.
- Returns:
Property description string
- Return type:
- get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- get_backbone_sidechain_interaction() str [source]#
Get simplified backbone/sidechain interaction description.
- Returns:
Interaction type (B-B, B-S, S-B, S-S)
- Return type:
- get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- class hbat.core.analysis.HalogenBond(halogen: Atom, _acceptor: Atom, distance: float, angle: float, bond_type: str, _halogen_residue: str, _acceptor_residue: str)[source]#
Bases:
MolecularInteraction
Represents a halogen bond interaction.
This class stores information about a detected halogen bond, where a halogen atom (Cl, Br, I) acts as an electrophilic center interacting with nucleophilic acceptors. HBAT uses updated default parameters with a 150° angle cutoff for improved detection of biologically relevant halogen bonds.
- Parameters:
halogen (Atom) – The halogen atom (F, Cl, Br, I)
_acceptor (Atom) – The electron donor/acceptor atom
distance (float) – X…A distance in Angstroms
angle (float) – C-X…A angle in radians (default cutoff: 150°)
bond_type (str) – Classification of the halogen bond type
_halogen_residue (str) – Identifier for halogen-containing residue
_acceptor_residue (str) – Identifier for acceptor residue
- __init__(halogen: Atom, _acceptor: Atom, distance: float, angle: float, bond_type: str, _halogen_residue: str, _acceptor_residue: str)[source]#
Initialize a HalogenBond object.
- Parameters:
halogen (Atom) – The halogen atom (F, Cl, Br, I)
_acceptor (Atom) – The electron donor/acceptor atom
distance (float) – X…A distance in Angstroms
angle (float) – C-X…A angle in radians
bond_type (str) – Classification of the halogen bond type
_halogen_residue (str) – Identifier for halogen-containing residue
_acceptor_residue (str) – Identifier for acceptor residue
- property angle: float#
Legacy property for interaction angle.
- Returns:
Donor-interaction-acceptor angle for backward compatibility
- Return type:
- property distance: float#
Legacy property for interaction distance.
- Returns:
Donor-interaction distance for backward compatibility
- Return type:
- property donor_acceptor_properties: str#
Get the donor-acceptor property description.
- Returns:
Property description string
- Return type:
- get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- get_backbone_sidechain_interaction() str [source]#
Get simplified backbone/sidechain interaction description.
- Returns:
Interaction type (B-B, B-S, S-B, S-S)
- Return type:
- get_donor_interaction_distance() float [source]#
Distance from donor to interaction point (0 for halogen bonds).
- get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- is_donor_interaction_bonded() bool [source]#
Check if halogen is bonded to donor carbon.
For halogen bonds, the halogen atom must be covalently bonded to a carbon atom. The halogen serves as both the donor and interaction point.
- Returns:
True (assumes validation was done during creation)
- Return type:
- class hbat.core.analysis.PiInteraction(_donor: Atom, hydrogen: Atom, pi_center: NPVec3D, distance: float, angle: float, _donor_residue: str, _pi_residue: str)[source]#
Bases:
MolecularInteraction
Represents a D-X…π interaction.
This class stores information about a detected D-X…π interaction, where a donor atom with an interaction atom (H, F, Cl, Br, I) interacts with an aromatic π system. Supports multiple subtypes: - C-H…π, N-H…π, O-H…π, S-H…π (hydrogen-π interactions) - C-Cl…π, C-Br…π, C-I…π (halogen-π interactions)
- Parameters:
_donor (Atom) – The donor atom (C, N, O, S)
hydrogen (Atom) – The interaction atom (H, F, Cl, Br, I) - name kept for backward compatibility
pi_center (NPVec3D) – Center of the aromatic π system
distance (float) – X…π distance in Angstroms
angle (float) – D-X…π angle in radians
_donor_residue (str) – Identifier for donor residue
_pi_residue (str) – Identifier for π-containing residue
- __init__(_donor: Atom, hydrogen: Atom, pi_center: NPVec3D, distance: float, angle: float, _donor_residue: str, _pi_residue: str)[source]#
Initialize a PiInteraction object.
- Parameters:
_donor (Atom) – The donor atom (C, N, O, S)
hydrogen (Atom) – The interaction atom (H, F, Cl, Br, I) - name kept for backward compatibility
pi_center (NPVec3D) – Center of the aromatic π system
distance (float) – X…π distance in Angstroms
angle (float) – D-X…π angle in radians
_donor_residue (str) – Identifier for donor residue
_pi_residue (str) – Identifier for π-containing residue
- property angle: float#
Legacy property for interaction angle.
- Returns:
Donor-interaction-acceptor angle for backward compatibility
- Return type:
- property distance: float#
Legacy property for interaction distance.
- Returns:
Donor-interaction distance for backward compatibility
- Return type:
- property donor_acceptor_properties: str#
Get the donor-acceptor property description.
- Returns:
Property description string
- Return type:
- get_acceptor_residue() str [source]#
Get the acceptor residue identifier.
- Returns:
String identifier for the acceptor residue
- Return type:
- get_backbone_sidechain_interaction() str [source]#
Get simplified backbone/sidechain interaction description.
- Returns:
Interaction type (B-S, S-S, etc.)
- Return type:
- get_donor_residue() str [source]#
Get the donor residue identifier.
- Returns:
String identifier for the donor residue
- Return type:
- get_interaction_type() str [source]#
Get the interaction type.
- Returns:
String identifier for the interaction type
- Return type:
- get_interaction_type_display() str [source]#
Get the interaction type for display purposes.
Generates display strings for different π interaction subtypes:
Hydrogen-π interactions: - “C-H…π” for carbon-hydrogen to π system - “N-H…π” for nitrogen-hydrogen to π system - “O-H…π” for oxygen-hydrogen to π system - “S-H…π” for sulfur-hydrogen to π system
Halogen-π interactions: - “C-Cl…π” for carbon-chlorine to π system - “C-Br…π” for carbon-bromine to π system - “C-I…π” for carbon-iodine to π system
- Returns:
Display format showing donor-interaction…π pattern
- Return type:
- class hbat.core.analysis.CooperativityChain(interactions: List[HydrogenBond | HalogenBond | PiInteraction], chain_length: int, chain_type: str)[source]#
Bases:
MolecularInteraction
Represents a chain of cooperative molecular interactions.
This class represents a series of linked molecular interactions where the acceptor of one interaction acts as the donor of the next, creating cooperative effects.
- Parameters:
interactions (List[Union[HydrogenBond, HalogenBond, PiInteraction]]) – List of interactions in the chain
chain_length (int) – Number of interactions in the chain
chain_type (str) – Description of the interaction types in the chain
- __init__(interactions: List[HydrogenBond | HalogenBond | PiInteraction], chain_length: int, chain_type: str)[source]#
Initialize a CooperativityChain object.
- Parameters:
interactions (List[Union[HydrogenBond, HalogenBond, PiInteraction]]) – List of interactions in the chain
chain_length (int) – Number of interactions in the chain
chain_type (str) – Description of the interaction types in the chain
- get_donor_interaction_acceptor_angle() float [source]#
Get the angle across the chain (donor-middle-acceptor).
- get_donor_interaction_distance() float [source]#
Get the distance from chain start to middle interaction.
- get_interaction() Atom | NPVec3D [source]#
Get the center point of the chain (middle interaction point).
Performance Notes#
Optimization Features:
Efficient Parsing: pdbreader integration for fast PDB processing
Spatial Grid: O(n) bond detection using spatial grid partitioning (35x speedup)
Memory Management: Class structures optimized for large-scale analysis
Vectorized Operations: NumPy-accelerated vector mathematics and distance calculations
Direct File Processing: PDB fixing with preserved formatting
Bond Adjacency Maps: O(1) bond lookups for interaction analysis
Scalability:
Handles large protein complexes (>100k atoms)
Memory-efficient data structures with optimized indexing
Spatial partitioning for sub-linear interaction detection
Comprehensive timing and performance metrics