Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ def run_diffdock_inference(protein_pdb_content, ligand_smiles_string):
|
|
| 11 |
"""
|
| 12 |
Performs molecular docking analysis using RDKit for binding affinity estimation.
|
| 13 |
This is a lightweight alternative to full DiffDock that works on free CPU tier.
|
|
|
|
| 14 |
Returns a JSON-serializable dictionary.
|
| 15 |
"""
|
| 16 |
try:
|
|
@@ -23,7 +24,7 @@ def run_diffdock_inference(protein_pdb_content, ligand_smiles_string):
|
|
| 23 |
|
| 24 |
# Import RDKit for molecular analysis
|
| 25 |
from rdkit import Chem
|
| 26 |
-
from rdkit.Chem import Descriptors, Lipinski
|
| 27 |
|
| 28 |
# Parse SMILES string
|
| 29 |
mol = Chem.MolFromSmiles(ligand_smiles_string)
|
|
@@ -78,6 +79,31 @@ def run_diffdock_inference(protein_pdb_content, ligand_smiles_string):
|
|
| 78 |
# Clamp score between 0 and 1
|
| 79 |
confidence_score = max(0.0, min(1.0, confidence_score))
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
# Build result with explicit JSON-serializable types
|
| 82 |
result = {
|
| 83 |
"success": True,
|
|
@@ -92,7 +118,8 @@ def run_diffdock_inference(protein_pdb_content, ligand_smiles_string):
|
|
| 92 |
"rotatable_bonds": int(rotatable_bonds),
|
| 93 |
"lipinski_compliant": bool(lipinski_pass)
|
| 94 |
},
|
| 95 |
-
"
|
|
|
|
| 96 |
}
|
| 97 |
|
| 98 |
# Return dict directly - Gradio will handle JSON serialization
|
|
|
|
| 11 |
"""
|
| 12 |
Performs molecular docking analysis using RDKit for binding affinity estimation.
|
| 13 |
This is a lightweight alternative to full DiffDock that works on free CPU tier.
|
| 14 |
+
Generates PDBQT format for compatibility with AutoDock Vina.
|
| 15 |
Returns a JSON-serializable dictionary.
|
| 16 |
"""
|
| 17 |
try:
|
|
|
|
| 24 |
|
| 25 |
# Import RDKit for molecular analysis
|
| 26 |
from rdkit import Chem
|
| 27 |
+
from rdkit.Chem import Descriptors, Lipinski, AllChem
|
| 28 |
|
| 29 |
# Parse SMILES string
|
| 30 |
mol = Chem.MolFromSmiles(ligand_smiles_string)
|
|
|
|
| 79 |
# Clamp score between 0 and 1
|
| 80 |
confidence_score = max(0.0, min(1.0, confidence_score))
|
| 81 |
|
| 82 |
+
# Generate 3D structure and PDBQT format for Vina compatibility
|
| 83 |
+
ligand_pdbqt = None
|
| 84 |
+
try:
|
| 85 |
+
# Add hydrogens and generate 3D coordinates
|
| 86 |
+
mol_3d = Chem.AddHs(mol)
|
| 87 |
+
AllChem.EmbedMolecule(mol_3d, randomSeed=42)
|
| 88 |
+
AllChem.MMFFOptimizeMolecule(mol_3d)
|
| 89 |
+
|
| 90 |
+
# Convert to PDB format first
|
| 91 |
+
pdb_block = Chem.MolToPDBBlock(mol_3d)
|
| 92 |
+
|
| 93 |
+
# Simple PDBQT conversion (add charges and atom types)
|
| 94 |
+
# This is a simplified version - full PDBQT requires proper charge calculation
|
| 95 |
+
pdbqt_lines = []
|
| 96 |
+
for line in pdb_block.split('\n'):
|
| 97 |
+
if line.startswith('HETATM') or line.startswith('ATOM'):
|
| 98 |
+
# Add Gasteiger charges (simplified - just use 0.0 for now)
|
| 99 |
+
pdbqt_line = line[:66] + " 0.00 0.00 0.000 " + line[77:78]
|
| 100 |
+
pdbqt_lines.append(pdbqt_line)
|
| 101 |
+
|
| 102 |
+
ligand_pdbqt = '\n'.join(pdbqt_lines) if pdbqt_lines else None
|
| 103 |
+
except Exception as pdbqt_error:
|
| 104 |
+
# If PDBQT generation fails, continue without it
|
| 105 |
+
ligand_pdbqt = None
|
| 106 |
+
|
| 107 |
# Build result with explicit JSON-serializable types
|
| 108 |
result = {
|
| 109 |
"success": True,
|
|
|
|
| 118 |
"rotatable_bonds": int(rotatable_bonds),
|
| 119 |
"lipinski_compliant": bool(lipinski_pass)
|
| 120 |
},
|
| 121 |
+
"ligand_pdbqt": ligand_pdbqt,
|
| 122 |
+
"note": str("RDKit-based drug-likeness scoring with PDBQT generation")
|
| 123 |
}
|
| 124 |
|
| 125 |
# Return dict directly - Gradio will handle JSON serialization
|