Constants Generator#
This module provides functionality to generate Python constants files from CCD data for standard residues. It extracts bond information from the Chemical Component Dictionary and creates optimized data structures for runtime use.
Classes#
- class hbat.ccd.constants_generator.CCDConstantsGenerator(ccd_manager: CCDDataManager)[source]#
Bases:
object
Generates Python constants files from CCD bond data.
This class uses the CCDDataManager to extract bond information and generate properly formatted Python constants files for use in HBAT.
Methods
Generate a Python constants file with residue bond information.
Attributes
- ccd_manager: CCDDataManager#
Instance of CCDDataManager for accessing CCD data
- Usage:
python -m hbat.ccd.constants_generator [output_file]
- Arguments:
output_file
(optional): Path to output constants file. Defaults tohbat/constants/residue_bonds.py
- __init__(ccd_manager: CCDDataManager)[source]#
Initialize the constants generator.
- Parameters:
ccd_manager – Initialized CCDDataManager instance
- write_residue_bonds_constants(residue_list: List[str], output_path: str = None) bool [source]#
Generate a Python constants file with residue bond information.
- Parameters:
residue_list – List of residue codes to include in constants
output_path – Output file path (defaults to constants/residue_bonds.py)
- Returns:
True if successful, False otherwise
Generated Constants Format#
The generated constants file contains:
# Auto-generated from CCD data
# Generated on: YYYY-MM-DD HH:MM:SS
from typing import Dict, List, Any
RESIDUE_BONDS: Dict[str, Dict[str, Any]] = {
"ALA": {
"bonds": [
{"atom1": "N", "atom2": "CA", "order": "SING", "aromatic": False},
{"atom1": "CA", "atom2": "C", "order": "SING", "aromatic": False},
{"atom1": "C", "atom2": "O", "order": "DOUB", "aromatic": False},
# ... more bonds
],
"bond_count": 10,
"aromatic_bonds": 0,
"bond_orders": {"SING": 9, "DOUB": 1}
},
# ... more residues
}
Bond Information Structure#
Each residue entry contains:
bonds
: List of bond dictionaries with:atom1
: First atom nameatom2
: Second atom nameorder
: Bond order (“SING”, “DOUB”, “TRIP”, “AROM”)aromatic
: Boolean indicating aromaticity
bond_count
: Total number of bondsaromatic_bonds
: Count of aromatic bondsbond_orders
: Dictionary of bond order counts
Standard Residues Included#
The generator extracts bond data for all standard amino acids and nucleotides:
Amino Acids: ALA, ARG, ASN, ASP, CYS, GLN, GLU, GLY, HIS, ILE, LEU, LYS, MET, PHE, PRO, SER, THR, TRP, TYR, VAL
Nucleotides: A, C, G, U, DA, DC, DG, DT
Usage Example#
from hbat.ccd.constants_generator import CCDConstantsGenerator
from hbat.ccd.ccd_analyzer import CCDDataManager
# Initialize generator
ccd_manager = CCDDataManager()
generator = CCDConstantsGenerator(ccd_manager)
# Generate constants file for specific residues
residue_list = ["ALA", "GLY", "VAL"]
success = generator.write_residue_bonds_constants(residue_list, "my_constants.py")
Performance Benefits#
Pre-generating constants provides:
Instant access to bond information without parsing CCD files
No runtime dependency on CCD data files
Reduced memory usage compared to loading full CCD dataset
Type-safe access to bond information