molecular_simulations.build.build_ligand module¶
Ligand parameterization and complex building module.
This module provides classes for parameterizing small molecule ligands using GAFF2 force fields and building protein-ligand complex systems for molecular dynamics simulations.
- Classes:
LigandError: Custom exception for ligand parameterization failures. LigandBuilder: Parameterize ligands with GAFF2 force field. PLINDERBuilder: Build complexes from PLINDER database entries. ComplexBuilder: Build general protein-ligand complex systems.
- exception molecular_simulations.build.build_ligand.LigandError(message='This system contains ligands which we cannot model!')[source]¶
Bases:
ExceptionCustom exception for ligand parameterization errors.
Raised when antechamber or SQM fails to parameterize a ligand, or when other ligand-related issues occur during system building.
- Parameters:
message – Error message describing the failure. Defaults to a generic message about ligand modeling failure.
Example
>>> raise LigandError('Antechamber failed for molecule XYZ')
Initialize the LigandError.
- class molecular_simulations.build.build_ligand.LigandBuilder(path, lig, lig_number=0, file_prefix='')[source]¶
Bases:
objectParameterize a ligand molecule with GAFF2 force field.
Generates all relevant force field files (.frcmod, .lib, .mol2) for running tleap with small molecule ligands.
- Parameters:
- path¶
Path object for working directory.
- lig¶
Path to input ligand file.
- ln¶
Ligand number for residue naming.
- out_lig¶
Path for output ligand files (without extension).
Example
>>> builder = LigandBuilder(path='./build', lig='ligand.sdf', lig_number=0) >>> builder.parameterize_ligand()
Initialize the LigandBuilder.
- parameterize_ligand()[source]¶
Generate GAFF2 parameters for the ligand.
Ensures consistent treatment of all ligand files by: 1. Adding hydrogens using RDKit 2. Converting to mol2 format 3. Running antechamber for GAFF2 atom typing and AM1-BCC charges 4. Running parmchk2 to generate missing parameters 5. Creating a tleap library file
- Raises:
LigandError – If antechamber fails to parameterize the ligand.
- Return type:
- process_sdf()[source]¶
Process an SDF file and add hydrogens.
Uses RDKit to add hydrogens based on atom hybridization from the input SDF file. Note that incorrect hybridization in the input will result in incorrect hydrogen placement.
- Return type:
- process_pdb()[source]¶
Process a PDB file and add hydrogens.
Reads a small molecule PDB, adds hydrogens using RDKit, and writes the result to an SDF file.
- Return type:
- move_antechamber_outputs()[source]¶
Clean up antechamber output files.
Removes unnecessary outputs and renames sqm.out for later verification that antechamber completed successfully.
- Return type:
- check_sqm()[source]¶
Verify that SQM calculations completed successfully.
Checks the sqm.out file for completion message. If absent, indicates parameter generation failed.
- Raises:
LigandError – If SQM calculations did not complete.
- Return type:
- class molecular_simulations.build.build_ligand.PLINDERBuilder(path, system_id, out, **kwargs)[source]¶
Bases:
ImplicitSolventBuild protein-ligand complexes from PLINDER database entries.
Extends ImplicitSolvent to handle PLINDER-format input directories containing receptor PDB, ligand SDF files, and sequence information.
- Parameters:
- system_id¶
PLINDER system identifier.
- build_dir¶
Directory for intermediate build files.
- ions¶
List of ions extracted from ligand files.
- ligs¶
List of parameterized ligand names.
Example
>>> builder = PLINDERBuilder( ... path='./plinder_data', system_id='1abc_A_B_ligand', out='./output' ... ) >>> builder.build()
Initialize the PLINDERBuilder.
- build()[source]¶
Build the protein-ligand complex system.
Migrates files, parameterizes ligands, and assembles the final system with topology and coordinate files.
- Raises:
LigandError – If no ligands are found or parameterization fails.
- Return type:
- migrate_files()[source]¶
Prepare input files for system building.
Copies sequence files, fixes and moves the receptor PDB, and processes ligand files. Handles ions separately.
- place_ions()[source]¶
Add ion records to the PDB file.
Appends ATOM records for extracted ions to the receptor PDB. Handles various ion naming conventions for AMBER compatibility.
Note
This method handles complex PDB formatting requirements. Proceed with caution if modifications are needed.
- Return type:
- assemble_system()[source]¶
Assemble the protein-ligand complex with tleap.
Creates topology and coordinate files for the complex, including all parameterized ligands and ions.
- Return type:
- prep_protein()[source]¶
Prepare the receptor protein structure.
Runs PDBFixer to repair missing residues, then pdb4amber to remove hydrogens and waters for clean tleap input.
- Return type:
- triage_pdb(broken_pdb, repaired_pdb)[source]¶
Repair a PDB structure using PDBFixer.
Runs PDBFixer to add missing loops and atoms. Uses FASTA sequence from PLINDER to properly model missing residues, including non-canonical residues like phosphorylations.
- inject_fasta(chain_map)[source]¶
Inject FASTA sequence data for PDBFixer.
Checks FASTA against actual sequence and modifies to correctly handle non-canonical residues (e.g., SER -> SEP for phosphoserine).
- check_ptms(sequence, chain_residues)[source]¶
Check for post-translational modifications in the sequence.
Compares the full sequence from FASTA against the partial sequence from the structural model and updates non-canonical residue names appropriately.
- class molecular_simulations.build.build_ligand.ComplexBuilder(path, pdb, lig, padding=10.0, lig_param_prefix=None, **kwargs)[source]¶
Bases:
ExplicitSolventBuild protein-ligand complexes with explicit solvent.
Extends ExplicitSolvent to handle ligand parameterization and complex assembly. Supports both automatic parameterization via antechamber and pre-computed parameter files.
- Parameters:
path (
str) – Directory path for output files.pdb (
str) – Path to protein PDB file.lig (
str|list[str]) – Path to ligand file(s). Can be a single path or list of paths.padding (
float) – Box padding in Angstroms. Defaults to 10.0.lig_param_prefix (
str|None) – Optional path prefix to pre-computed ligand parameters (.frcmod, .lib, .mol2). If None, parameters are generated automatically. Defaults to None.**kwargs – Additional attributes (e.g., ‘ion’ for ion PDB path).
- lig¶
Path(s) to ligand file(s).
- build_dir¶
Directory for intermediate build files.
- lig_param_prefix¶
Prefix for pre-computed parameter files.
Example
>>> builder = ComplexBuilder( ... path='./build', pdb='protein.pdb', lig='ligand.sdf', padding=12.0 ... ) >>> builder.build()
Initialize the ComplexBuilder.
- __init__(path, pdb, lig, padding=10.0, lig_param_prefix=None, **kwargs)[source]¶
Initialize the ComplexBuilder.
- build()[source]¶
Build the solvated protein-ligand complex.
Parameterizes ligands (if needed), prepares the protein, and assembles the solvated system.
- Return type:
- add_ion_to_pdb()[source]¶
Add ion coordinates to the protein PDB file.
Reads ion coordinates from a separate file and appends them to the protein PDB before the END record.
- Return type: