Platform wheels for RDKit - a comprehensive cheminformatics and machine-learning library with Python bindings
89
3D conformer generation, molecular embedding, and 3D descriptor calculations for spatial molecular analysis. These capabilities enable three-dimensional molecular modeling, conformational analysis, and calculation of geometry-dependent molecular properties essential for drug design and molecular recognition studies.
Generate 2D coordinates for molecular visualization and drawing.
def Compute2DCoords(mol: Mol, canonOrient: bool = True,
clearConfs: bool = True, coordMap: dict = None,
nFlipsPerSample: int = 0, nSample: int = 1,
sampleSeed: int = 0, permuteDeg4Nodes: bool = False) -> None:
"""
Generate 2D coordinates for a molecule.
Parameters:
- mol: Input molecule (modified in place)
- canonOrient: Use canonical orientation (default True)
- clearConfs: Clear existing conformers (default True)
- coordMap: Dictionary mapping atom indices to fixed coordinates
- nFlipsPerSample: Number of flips per sample for optimization
- nSample: Number of samples to generate
- sampleSeed: Random seed for reproducibility
- permuteDeg4Nodes: Permute degree-4 nodes during generation
Returns:
None (modifies molecule in place)
"""Generate three-dimensional molecular conformations using distance geometry algorithms.
def EmbedMolecule(mol: Mol, maxAttempts: int = 10, randomSeed: int = -1,
clearConfs: bool = True, useExpTorsionAnglePrefs: bool = True,
useBasicKnowledge: bool = True, enforceChirality: bool = True,
useRandomCoords: bool = False, numZeroFail: int = 1,
pruneRmsThresh: float = -1.0, coordMap: dict = None,
forceTol: float = 0.001, ignoreSmoothingFailures: bool = False,
useSmallRingTorsions: bool = False, useMacrocycleTorsions: bool = False,
ETversion: int = 1, onlyHeavyAtomsForRMS: bool = False) -> int:
"""
Generate a single 3D conformer using distance geometry.
Parameters:
- mol: Input molecule (modified in place)
- maxAttempts: Maximum embedding attempts (default 10)
- randomSeed: Random seed for reproducibility (default -1 for random)
- clearConfs: Clear existing conformers (default True)
- useExpTorsionAnglePrefs: Use experimental torsion preferences (default True)
- useBasicKnowledge: Use basic chemical knowledge (default True)
- enforceChirality: Enforce stereochemistry (default True)
- useRandomCoords: Use random starting coordinates (default False)
- numZeroFail: Number of zero-distance failures allowed (default 1)
- pruneRmsThresh: RMS threshold for conformer pruning (default -1.0)
- coordMap: Dictionary mapping atom indices to fixed coordinates
- forceTol: Force tolerance for optimization (default 0.001)
- ignoreSmoothingFailures: Ignore smoothing failures (default False)
- useSmallRingTorsions: Use small ring torsion preferences (default False)
- useMacrocycleTorsions: Use macrocycle torsion preferences (default False)
- ETversion: Embedding algorithm version (default 1)
- onlyHeavyAtomsForRMS: Only use heavy atoms for RMS calculations (default False)
Returns:
Conformer ID of generated conformer (-1 if failed)
"""
def EmbedMultipleConfs(mol: Mol, numConfs: int = 1, maxAttempts: int = 30,
pruneRmsThresh: float = 2.0, useExpTorsionAnglePrefs: bool = True,
useBasicKnowledge: bool = True, enforceChirality: bool = True,
numThreads: int = 1, randomSeed: int = -1,
clearConfs: bool = True, **kwargs) -> list:
"""
Generate multiple 3D conformers using distance geometry.
Parameters:
- mol: Input molecule (modified in place)
- numConfs: Number of conformers to generate (default 1)
- maxAttempts: Maximum attempts per conformer (default 30)
- pruneRmsThresh: RMS threshold for duplicate removal (default 2.0)
- useExpTorsionAnglePrefs: Use experimental torsion preferences (default True)
- useBasicKnowledge: Use basic chemical knowledge (default True)
- enforceChirality: Enforce stereochemistry (default True)
- numThreads: Number of parallel threads (default 1)
- randomSeed: Random seed for reproducibility (default -1)
- clearConfs: Clear existing conformers (default True)
Returns:
List of conformer IDs generated
"""Optimize 3D conformers using molecular mechanics force fields.
def MMFFOptimizeMolecule(mol: Mol, confId: int = -1, maxIters: int = 200,
nonBondedThresh: float = 100.0, ignoreInterfragInteractions: bool = True) -> int:
"""
Optimize a conformer using the MMFF force field.
Parameters:
- mol: Input molecule with conformer
- confId: Conformer ID to optimize (default -1 for default conformer)
- maxIters: Maximum optimization iterations (default 200)
- nonBondedThresh: Non-bonded interaction threshold (default 100.0)
- ignoreInterfragInteractions: Ignore inter-fragment interactions (default True)
Returns:
0 if successful, 1 if not converged, -1 if failed
"""
def UFFOptimizeMolecule(mol: Mol, confId: int = -1, maxIters: int = 200,
vdwThresh: float = 10.0, confTol: float = 1e-4,
energyTol: float = 1e-6, ignoreInterfragInteractions: bool = True) -> int:
"""
Optimize a conformer using the UFF force field.
Parameters:
- mol: Input molecule with conformer
- confId: Conformer ID to optimize (default -1 for default conformer)
- maxIters: Maximum optimization iterations (default 200)
- vdwThresh: Van der Waals threshold (default 10.0)
- confTol: Conformer tolerance (default 1e-4)
- energyTol: Energy tolerance (default 1e-6)
- ignoreInterfragInteractions: Ignore inter-fragment interactions (default True)
Returns:
0 if successful, 1 if not converged, -1 if failed
"""Calculate 3D molecular descriptors that depend on three-dimensional structure.
def CalcMolDescriptors3D(mol: Mol, confId: int = -1, force: bool = True) -> dict:
"""
Calculate all available 3D molecular descriptors.
Parameters:
- mol: Input molecule with 3D coordinates
- confId: Conformer ID to use (default -1 for default conformer)
- force: Force calculation even if descriptors exist (default True)
Returns:
Dictionary mapping 3D descriptor names to values
"""
def PMI1(mol: Mol, confId: int = -1, force: bool = True) -> float:
"""
Calculate first principal moment of inertia.
Parameters:
- mol: Input molecule with 3D coordinates
- confId: Conformer ID to use (default -1)
- force: Force calculation (default True)
Returns:
PMI1 value
"""
def PMI2(mol: Mol, confId: int = -1, force: bool = True) -> float:
"""
Calculate second principal moment of inertia.
Parameters:
- mol: Input molecule with 3D coordinates
- confId: Conformer ID to use (default -1)
- force: Force calculation (default True)
Returns:
PMI2 value
"""
def PMI3(mol: Mol, confId: int = -1, force: bool = True) -> float:
"""
Calculate third principal moment of inertia.
Parameters:
- mol: Input molecule with 3D coordinates
- confId: Conformer ID to use (default -1)
- force: Force calculation (default True)
Returns:
PMI3 value
"""
def InertialShapeFactor(mol: Mol, confId: int = -1, force: bool = True) -> float:
"""
Calculate inertial shape factor.
Parameters:
- mol: Input molecule with 3D coordinates
- confId: Conformer ID to use (default -1)
- force: Force calculation (default True)
Returns:
Inertial shape factor value
"""
def Eccentricity(mol: Mol, confId: int = -1, force: bool = True) -> float:
"""
Calculate molecular eccentricity.
Parameters:
- mol: Input molecule with 3D coordinates
- confId: Conformer ID to use (default -1)
- force: Force calculation (default True)
Returns:
Eccentricity value
"""
def SpherocityIndex(mol: Mol, confId: int = -1, force: bool = True) -> float:
"""
Calculate spherocity index.
Parameters:
- mol: Input molecule with 3D coordinates
- confId: Conformer ID to use (default -1)
- force: Force calculation (default True)
Returns:
Spherocity index value
"""Functions for analyzing and comparing molecular conformations.
def GetConformerRMS(mol: Mol, confId1: int, confId2: int,
atomIds: list = None, prealigned: bool = False) -> float:
"""
Calculate RMS distance between two conformers.
Parameters:
- mol: Input molecule with multiple conformers
- confId1: First conformer ID
- confId2: Second conformer ID
- atomIds: List of atom indices to include (default all)
- prealigned: Whether conformers are already aligned (default False)
Returns:
RMS distance between conformers
"""
def AlignMol(prbMol: Mol, refMol: Mol, prbConfId: int = -1,
refConfId: int = -1, atomMap: list = None,
weights: list = None, reflect: bool = False,
maxIters: int = 50) -> float:
"""
Align probe molecule to reference molecule.
Parameters:
- prbMol: Probe molecule to align
- refMol: Reference molecule
- prbConfId: Probe conformer ID (default -1)
- refConfId: Reference conformer ID (default -1)
- atomMap: List of (probe_idx, ref_idx) atom pairs
- weights: List of weights for alignment atoms
- reflect: Allow reflection during alignment (default False)
- maxIters: Maximum alignment iterations (default 50)
Returns:
RMS distance after alignment
"""from rdkit import Chem
from rdkit.Chem import AllChem
# Generate 3D coordinates
mol = Chem.MolFromSmiles('CCCO') # Propanol
confId = AllChem.EmbedMolecule(mol, randomSeed=42)
if confId >= 0:
print("3D coordinates generated successfully")
# Optimize the geometry
result = AllChem.MMFFOptimizeMolecule(mol)
if result == 0:
print("Optimization converged")
else:
print(f"Optimization result: {result}")
else:
print("Failed to generate 3D coordinates")from rdkit import Chem
from rdkit.Chem import AllChem
# Generate multiple conformers
mol = Chem.MolFromSmiles('CCCCCCCC') # Octane (flexible chain)
confIds = AllChem.EmbedMultipleConfs(mol, numConfs=10, randomSeed=42)
print(f"Generated {len(confIds)} conformers")
# Optimize all conformers
for confId in confIds:
AllChem.MMFFOptimizeMolecule(mol, confId=confId)
print("All conformers optimized")from rdkit import Chem
from rdkit.Chem import AllChem, Descriptors3D
# Generate 3D structure
mol = Chem.MolFromSmiles('CCCO')
AllChem.EmbedMolecule(mol, randomSeed=42)
AllChem.MMFFOptimizeMolecule(mol)
# Calculate 3D descriptors
descriptors_3d = Descriptors3D.CalcMolDescriptors3D(mol)
print(f"Calculated {len(descriptors_3d)} 3D descriptors")
# Access specific 3D descriptors
pmi1 = Descriptors3D.PMI1(mol)
pmi2 = Descriptors3D.PMI2(mol)
pmi3 = Descriptors3D.PMI3(mol)
inertial_shape = Descriptors3D.InertialShapeFactor(mol)
print(f"PMI1: {pmi1:.3f}")
print(f"PMI2: {pmi2:.3f}")
print(f"PMI3: {pmi3:.3f}")
print(f"Inertial Shape Factor: {inertial_shape:.3f}")from rdkit import Chem
from rdkit.Chem import AllChem
# Generate two conformers
mol = Chem.MolFromSmiles('CCCCCCC')
confIds = AllChem.EmbedMultipleConfs(mol, numConfs=2, randomSeed=42)
# Optimize conformers
for confId in confIds:
AllChem.MMFFOptimizeMolecule(mol, confId=confId)
# Calculate RMS difference between conformers
if len(confIds) >= 2:
rms = AllChem.GetConformerRMS(mol, confIds[0], confIds[1])
print(f"RMS between conformers: {rms:.3f} Ų")from rdkit import Chem
from rdkit.Chem import AllChem
# Generate 2D coordinates for drawing
mol = Chem.MolFromSmiles('CCO')
AllChem.Compute2DCoords(mol)
# Now the molecule has 2D coordinates suitable for drawing
print(f"Molecule has {mol.GetNumConformers()} conformer(s)")Install with Tessl CLI
npx tessl i tessl/pypi-rdkitevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10