Algorithm & Calculation Logic#
Overview#
HBAT uses a geometric approach to identify hydrogen bonds by analyzing distance and angular criteria between donor-hydrogen-acceptor triplets. The main calculation is performed by the NPMolecularInteractionAnalyzer class in hbat/core/np_analyzer.py.
Bond Detection#
HBAT employs a prioritized approach for bond detection using three methods:
RESIDUE_LOOKUP:
Uses pre-defined bond information from CCD for standard residues
Provides chemically accurate bond connectivity
Includes bond order (single/double) and aromaticity information
Covers all standard amino acids and nucleotides
CONECT Records (if available):
Parses explicit bond information from CONECT records in the PDB file
Preserves author-specified connectivity
Distance-based Detection (fallback):
Only used when no CONECT records are present or no bonds were found
Uses optimized spatial grid algorithm for large structures
Distance-based Bond Criteria#
When detecting bonds by distance:
Van der Waals radii from
AtomicData.VDW_RADIIDistance criteria:
MIN_BOND_DISTANCE ≤ distance ≤ min(vdw_cutoff, MAX_BOND_DISTANCE)VdW cutoff formula:
vdw_cutoff = (vdw1 + vdw2) x COVALENT_CUTOFF_FACTORwhereCOVALENT_CUTOFF_FACTORbetwenn0and1.Example:
C-Cbond =(1.70 + 1.70) x 0.6 = 2.04Å maximum (but limited to2.5Å byMAX_BOND_DISTANCE)
Bond Types#
"residue_lookup": Bonds from CCD residue definitions"explicit": Bonds from CONECT records"covalent": Bonds detected by distance criteria
Spatial Grid Algorithm#
For distance-based bond detection, HBAT uses a spatial grid algorithm:
Grid Setup:
Grid cell size based on
MAX_BOND_DISTANCE(2.5Å)Atoms are assigned to grid cells based on coordinates
Only neighboring cells are checked for potential bonds
Chemical Component Dictionary (CCD) Integration#
HBAT uses RCSB Chemical Component Dictionary (CCD) for accurate bond information:
CCD Data Manager:
Automatically downloads CCD BinaryCIF files from RCSB
Atom data:
cca.bcifcontaining atomic propertiesBond data:
ccb.bcifcontaining bond connectivity informationStorage location:
~/.hbat/ccd-data/directoryAuto-download: Files are downloaded on first use and cached locally
Vector Mathematics#
The NPVec3D class (hbat/core/np_vector.py) provides NumPy-based vector operations:
3D coordinates:
NPVec3D(x, y, z)orNPVec3D(np.array([x, y, z]))Batch operations: Support for multiple vectors simultaneously
NPVec3D(np.array([[x1,y1,z1], [x2,y2,z2]]))Distance calculation:
√[(x₂-x₁)² + (y₂-y₁)² + (z₂-z₁)²]with vectorized operationsAngle calculation:
arccos(dot_product / (mag1 x mag2))using NumPy for efficiency
Interaction Types#
HBAT detects six types of molecular interactions:
Hydrogen Bonds: Classical
N-H···O,O-H···O, and weakC-H···OinteractionsHalogen Bonds:
C-X···Ainteractions (X=Cl,Br,I)π Interactions:
X-H...πandC-X···πinteractions with aromatic rings (PHE,TYR,TRP,HIS, etc.)π-π Stacking: Aromatic ring-ring interactions (parallel, T-shaped, offset)
Carbonyl Interactions:
n→π*interactions betweenC=Ogroupsn-π Interactions: Lone pair interactions with aromatic
πsystems
Hydrogen Bonds#
Hydrogen bonds are electrostatic interactions between a hydrogen atom covalently bonded to an electronegative donor atom (D) and an electronegative acceptor atom (A). HBAT distinguishes between classical (strong) hydrogen bonds and weak hydrogen bonds based on the donor atom type.
Classical Hydrogen Bonds#
Classical hydrogen bonds involve highly electronegative donor atoms such as nitrogen, oxygen, or sulfur:
Donor atoms:
N,O,S(e.g.,N-H,O-H,S-H)Acceptor atoms:
N,O,S,F,ClExamples:
N-H···O=C(backbone),O-H···O(SER),N-H···N(HIS)
Geometric Criteria#
Classical hydrogen bond detection criteria:
H···A distance: ≤
ParametersDefault.HB_DISTANCE_CUTOFF(2.5Å)D-H···A angle: ≥
ParametersDefault.HB_ANGLE_CUTOFF(``120.0``°)D···A distance: ≤
ParametersDefault.HB_DA_DISTANCE(3.5Å)
Weak Hydrogen Bonds (C-H Donors)#
Weak hydrogen bonds involve carbon as the donor atom, which is less electronegative than N, O, or S:
Donor atoms:
C(e.g.,C-Hfrom aliphatic or aromatic carbons)Acceptor atoms:
O,N,S,F,ClExamples:
C-H···O=C(protein-ligand interactions), aromaticC-H···OImportance: Significant in protein-ligand binding, crystal packing, and stabilizing protein structures
Geometric Criteria#
Weak hydrogen bond detection criteria (more permissive than classical H-bonds):
H···A distance: ≤
ParametersDefault.WHB_DISTANCE_CUTOFF(3.6Å)D-H···A angle: ≥
ParametersDefault.WHB_ANGLE_CUTOFF(``150.0``°)D···A distance: ≤
ParametersDefault.WHB_DA_DISTANCE(3.5Å)
Note: Weak hydrogen bonds require a more stringent angular cutoff (``150.0``° vs ``120.0``°) to compensate for their weaker electrostatic nature and reduce false positives.
Halogen Bonds#
Halogen bonds are non-covalent interactions between a halogen atom (X = Cl, Br, I) acting as an electrophilic species and a nucleophilic acceptor atom. The interaction arises from the anisotropic charge distribution on the halogen atom, creating a positive “σ-hole” along the C-X bond axis.
Interaction Geometry#
Donor: Halogen atom (
Cl,Br,I) covalently bonded to carbonAcceptor: Electronegative atoms with lone pairs (
O,N,S) or π systemsDirectionality: Linear
C-X···Ageometry preferred (σ-hole interaction)Strength: Increases with halogen size:
Cl<Br<I(larger σ-hole)
Geometric Criteria#
Halogen bond detection criteria:
X···A distance: ≤
ParametersDefault.XB_DISTANCE_CUTOFF(3.9Å, approximately the sum of van der Waals radii)C-X···A angle: ≥
ParametersDefault.XB_ANGLE_CUTOFF(``150.0``°, ensures linear geometry for σ-hole interaction)
π Interaction#
X-H...π and C-X···π interactions are detected using the aromatic ring center as a pseudo-acceptor.
Aromatic Ring Center Calculation#
The center of aromatic rings is calculated as the geometric centroid of specific ring atoms:
Phenylalanine (PHE):
Ring atoms:
CG,CD1,CD2,CE1,CE2,CZ(6-membered benzene ring)Forms a planar hexagonal structure
Tyrosine (TYR):
Ring atoms:
CG,CD1,CD2,CE1,CE2,CZ(6-membered benzene ring)Same as
PHEbut with hydroxyl group atCZ
Tryptophan (TRP):
Ring atoms:
CG,CD1,CD2,NE1,CE2,CE3,CZ2,CZ3,CH2(9-atom indole system)Includes both pyrrole and benzene rings
Histidine (HIS):
Ring atoms:
CG,ND1,CD2,CE1,NE2(5-membered imidazole ring)Contains two nitrogen atoms in the ring
Centroid Calculation Process#
# For each aromatic residue:
center = Vec3D(0, 0, 0)
for atom_coord in ring_atoms_coords:
center = center + atom_coord
center = center / len(ring_atoms_coords) # Average position
π Interaction Geometry Validation#
Once the aromatic center is calculated:
Distance Check:
H…π center distanceCutoff: ≤
ParametersDefault.PI_DISTANCE_CUTOFF(3.5Å)Calculation: 3D Euclidean distance from hydrogen to ring centroid
Angular Check:
D-H…π angleCutoff: ≥
ParametersDefault.PI_ANGLE_CUTOFF(``110.0``°)Calculation: Angle between donor-hydrogen vector and hydrogen-π_center vector
Uses same
angle_between_vectors()function as regular hydrogen bonds
Geometric Interpretation#
The aromatic ring center acts as a “virtual acceptor” representing the π-electron cloud
Distance measures how close the hydrogen approaches the aromatic system
Angle ensures the hydrogen is positioned to interact with the π-electron density above/below the ring plane
π-π Stacking Interactions#
π-π stacking interactions occur between aromatic ring systems and are classified based on geometry:
Stacking Types#
HBAT classifies π-π interactions into three categories based on the angle between ring planes and lateral offset:
Parallel Stacking (
plane_angle ≤ ParametersDefault.PI_PI_PARALLEL_ANGLE_CUTOFF(``30.0``°)):Ring planes are nearly parallel
Offset geometry preferred over face-to-face due to electrostatic repulsion
Maximum offset:
ParametersDefault.PI_PI_OFFSET_CUTOFF(2.0Å) for optimal interactionDistance: typically
3.3-4.0Å between centroids
T-shaped Stacking (
ParametersDefault.PI_PI_TSHAPED_ANGLE_MIN ≤ plane_angle ≤ ParametersDefault.PI_PI_TSHAPED_ANGLE_MAX(60.0-``90.0``°)):Ring planes are approximately perpendicular (edge-to-face)
One ring’s edge approaches the face of the other
Minimizes electrostatic repulsion while maximizing
C-H···πinteractionsDistance: typically
4.5-5.5Å between centroids
Offset Stacking (
ParametersDefault.PI_PI_PARALLEL_ANGLE_CUTOFF < plane_angle < ParametersDefault.PI_PI_TSHAPED_ANGLE_MIN(30.0-``60.0``°)):Intermediate geometry between parallel and T-shaped
Provides balance between π-π overlap and electrostatic favorability
Common in protein-ligand interactions
Geometric Criteria#
π-π stacking detection uses the following criteria:
Centroid distance: ≤
ParametersDefault.PI_PI_DISTANCE_CUTOFF(3.8Å, maximum separation between ring centers)Plane angle: Angle between ring normal vectors (
0°= parallel,90°= perpendicular)Offset distance: Lateral displacement from direct stacking
Ring types:
PHE,TYR,TRP,HISaromatic residues
Calculation Process#
Ring Center Calculation:
Compute geometric centroid of ring atoms (same as
X-H···πinteractions)For each aromatic residue type (
PHE,TYR,TRP,HIS)
Plane Normal Calculation:
Use cross product of two ring vectors to determine plane normal
Normalize vector for angle calculations
Geometry Classification:
Calculate angle between plane normals
Compute lateral offset for parallel configurations
Classify as parallel, T-shaped, or offset based on criteria
Validation:
Check centroid-to-centroid distance
Verify interaction is between different residues
Apply distance and angle cutoffs
Carbonyl Interactions (n→π*)#
Carbonyl-carbonyl interactions are n→π* orbital interactions between C=O groups, following the Bürgi-Dunitz trajectory:
Interaction Geometry#
Donor: Oxygen atom with lone pair electrons (
norbital)Acceptor: Carbon atom of carbonyl group (
π*orbital)Trajectory: Donor oxygen approaches acceptor carbon at characteristic angle
Bürgi-Dunitz angle:
O···C=Oangle (ParametersDefault.CARBONYL_ANGLE_MIN-ParametersDefault.CARBONYL_ANGLE_MAX,95.0-125.0°)Distance:
O···Cdistance (≤ParametersDefault.CARBONYL_DISTANCE_CUTOFF,3.2Å)
Geometric Criteria#
Carbonyl interaction detection criteria:
O···C distance: ≤
ParametersDefault.CARBONYL_DISTANCE_CUTOFF(3.2Å)Bürgi-Dunitz angle:
ParametersDefault.CARBONYL_ANGLE_MIN-ParametersDefault.CARBONYL_ANGLE_MAX(95.0-125.0°, optimal for orbital overlap)C=O bond angle: Validates proper carbonyl geometry
Residue separation: Usually requires
|i-j| ≥ 2for backbone interactions
Classification#
Carbonyl interactions are classified by context:
Backbone-backbone: Both carbonyls from peptide backbone (most common)
Backbone-sidechain: One backbone, one sidechain carbonyl
Sidechain-sidechain: Both from residue sidechains
Cross-strand: Common in β-sheets for stabilization
Same-helix: Contributes to α-helix stability
Calculation Process#
Carbonyl Identification:
Detect
C=Ogroups from backbone (C,Oatoms)Identify sidechain carbonyls (
ASP,GLU,ASN,GLN)
Geometry Validation:
Calculate
O···Cdistance between donor and acceptorCompute Bürgi-Dunitz angle (
O···C=O)Verify angle falls within optimal range
Classification:
Determine if backbone or sidechain carbonyls
Calculate residue sequence separation
Classify interaction type
n-π Interactions#
n-π interactions occur when lone pair electrons from heteroatoms (O, N, S) interact with aromatic π systems:
Interaction Geometry#
Donor: Atom with lone pair electrons (typically
O,N, orS)Acceptor: Aromatic π system (
PHE,TYR,TRP,HIS)Geometry: Lone pair approaches π system at a shallow angle to the ring plane
Distance:
ParametersDefault.N_PI_DISTANCE_CUTOFF(3.6Å) from lone pair atom to ring centerAngle: Measured as angle to plane (
90``° - ``angle_to_normal), whereangle_to_normalis the angle between the donor-to-π vector and ring plane normal
Geometric Criteria#
n-π interaction detection criteria:
Distance: ≤
ParametersDefault.N_PI_DISTANCE_CUTOFF(3.6Å) from lone pair atom to π center (ParametersDefault.N_PI_SULFUR_DISTANCE_CUTOFF(4.0Å) for sulfur)Minimum distance: ≥
ParametersDefault.N_PI_DISTANCE_MIN(2.5Å) to avoid unrealistic close contactsAngle to plane:
ParametersDefault.N_PI_ANGLE_MIN-ParametersDefault.N_PI_ANGLE_MAX(0.0-``45.0``°)Calculated as:
angle_to_plane = 90° - angle_to_normalangle_to_planerange of0-45°corresponds toangle_to_normalof45-90°This means the donor approaches at a shallow angle, not directly perpendicular to the ring
Lone pair atoms:
O,N,Sfrom backbone or sidechainsπ systems: Same aromatic residues as other π interactions
Subtypes#
n-π interactions are classified by donor atom type:
O-π: Oxygen lone pairs (backbone carbonyl
O,SER/THROH, water)N-π: Nitrogen lone pairs (backbone amide
N,LYS,ARG,HIS)S-π: Sulfur lone pairs (
CYS,MET)
Calculation Process#
Lone Pair Identification:
Identify potential donor atoms (
O,N,S)Filter by chemical environment (must have lone pairs)
π System Location:
Use aromatic ring centers from π interaction detection
Calculate ring plane normals
Geometry Validation:
Calculate distance from donor to π center
Compute angle relative to ring plane normal
Verify shallow angle approach geometry
Subtype Classification:
Classify by donor element type (
O,N,S)Determine if backbone or sidechain interaction
Cooperativity Chains#
HBAT identifies cooperative interaction chains where molecular interactions are linked through shared atoms. This occurs when an acceptor atom in one interaction simultaneously acts as a donor in another interaction.
Step 1: Interaction Collection - Combines all detected interactions: hydrogen bonds, halogen bonds, and π interactions - Requires minimum of 2 interactions to form chains
Step 2: Atom-to-Interaction Mapping Creates two lookup dictionaries:
donor_to_interactions: Maps each donor atom to interactions where it participatesacceptor_to_interactions: Maps each acceptor atom to interactions where it participates
Atom keys are tuples: (chain_id, residue_sequence, atom_name)
Step 3: Chain Building Process Starting from each unvisited interaction:
Initialize: Begin with starting interaction in chain
Follow Forward: Look for next interaction where current acceptor acts as donor
Validation: Ensure same atom serves dual role (acceptor → donor)
Iteration: Continue until no more connections found
Termination: π interactions cannot chain further as acceptors (no single acceptor atom)