Entities Module¶
This module contains entity-related functionality for handling ligands and molecular structures.
Ligand Utilities¶
ligand
¶
Ligand processing and CCD cache management for Boltz predictions.
This module provides utilities for processing molecular structures, generating conformers, and managing the Chemical Component Dictionary (CCD) cache used by Boltz for ligand predictions.
sanitize_mol_id
¶
Ensure molecule ID complies with CCD naming rules (max 5 characters).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mol_id
|
str
|
Original molecule identifier. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Sanitized molecule ID, truncated to 5 characters if necessary. |
Warnings
Logs a warning if the ID is truncated.
Source code in src/cofolder/modules/entities/ligand.py
add_pickled_prop
¶
Pickle and attach a property to an RDKit molecule.
Serializes a value using pickle and stores it as a hex-encoded string property on the molecule. Used for storing complex data structures in CCD format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mol
|
Mol
|
RDKit molecule object to modify. |
required |
name
|
str
|
Property name to use for storage. |
required |
value
|
any
|
Value to pickle and attach (can be any picklable Python object). |
required |
Source code in src/cofolder/modules/entities/ligand.py
extract_constraints
¶
Extract a list of values from constraint objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints
|
list
|
List of constraint objects. |
required |
key
|
str
|
Attribute name to extract. |
required |
transpose
|
bool
|
Whether to transpose the result (default False). |
False
|
Returns:
| Type | Description |
|---|---|
list or ndarray
|
Extracted values, optionally transposed. |
Source code in src/cofolder/modules/entities/ligand.py
generate_2d_conformers
¶
Generate 2D coordinate layouts for molecules in an SDF file.
Computes 2D coordinates suitable for visualization and quick analysis. Useful for preparing ligands that only have SMILES or 1D representations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sdf_in
|
str
|
Path to input SDF file. |
required |
sdf_out
|
str
|
Path to output SDF file. If None, overwrites the input file. |
None
|
Notes
Uses RDKit's Compute2DCoords for layout generation. Invalid molecules (None) are skipped.
Source code in src/cofolder/modules/entities/ligand.py
generate_3d_conformers
¶
Generate 3D conformers for molecules using ETKDG and UFF optimization.
Creates physically realistic 3D conformations by: 1. Adding hydrogens 2. Embedding with ETKDG (Experimental-Torsion Knowledge Distance Geometry) 3. Optimizing geometry with UFF (Universal Force Field)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sdf_in
|
str
|
Path to input SDF file. |
required |
sdf_out
|
str
|
Path to output SDF file. If None, overwrites the input file. |
None
|
Warnings
Logs a warning if 3D conformer generation fails for any molecule. Failed molecules are skipped and not written to output.
Notes
This is computationally more expensive than 2D conformer generation but produces geometries suitable for docking and structure prediction.
Source code in src/cofolder/modules/entities/ligand.py
iterate_sdf_records
¶
Compatibility iterator that now retains record indexes while yielding valid molblocks.
Source code in src/cofolder/modules/entities/ligand.py
csv_to_sdf
¶
csv_to_sdf(
csv_path: str,
smiles_col: str,
output_sdf_path: str | None = None,
property_cols: Optional[Union[dict, List[dict], str, List[str]]] = None,
) -> None
Compatibility wrapper that preserves the older CSV-specific API.
Source code in src/cofolder/modules/entities/ligand.py
mol_to_ccd
¶
mol_to_ccd(
resname: str,
mol: Mol,
boltz_path: Union[str, PathLike] = os.path.expanduser("~/.boltz"),
)
Convert an RDKit molecule to Boltz CCD format and cache it.
Processes an RDKit molecule by: 1. Sanitizing and preparing the structure 2. Parsing geometric and stereochemical constraints 3. Pickling all properties for Boltz compatibility 4. Saving to the CCD cache directory
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resname
|
str
|
Residue name (identifier) for the molecule. Must be 5 characters or less. |
required |
mol
|
Mol
|
RDKit molecule object to convert. |
required |
boltz_path
|
str or Path
|
Path to Boltz cache directory where CCD files are stored. |
"~/.boltz"
|
Raises:
| Type | Description |
|---|---|
Exception
|
If the molecule is None. |
Examples:
>>> from rdkit import Chem
>>> from cofolder.modules.entities.ligand import mol_to_ccd
>>> smiles = "CCO"
>>> mol = Chem.MolFromSmiles(smiles)
>>> mol_to_ccd("ETH", mol)
# Saves to ~/.boltz/mols/ETH.pkl
Notes
This function contains adapted logic from jacktday/boltztools (MIT).
The CCD format includes: - Atomic symmetries - Bond length and angle constraints - Chiral center definitions - Stereochemical bond configurations - Aromatic ring planarity constraints
Source code in src/cofolder/modules/entities/ligand.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |