Spaces:
Runtime error
Runtime error
Use py3Dmol's built-in HTML generation for orbital visualization
Browse files- app.py +16 -25
- force_rebuild.txt +1 -1
app.py
CHANGED
|
@@ -259,38 +259,29 @@ def smiles_to_molecular_orbitals(smiles_input: str, name_input: str) -> str:
|
|
| 259 |
# Get molecular structure
|
| 260 |
mol_block = Chem.MolToMolBlock(mol_3d)
|
| 261 |
|
| 262 |
-
# Create py3Dmol viewer
|
| 263 |
import py3Dmol
|
| 264 |
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
viewer_{label}.addVolumetricData(cubeData, "cube", {{isoval: 0.02, color: "blue", alpha: 0.7}});
|
| 280 |
-
viewer_{label}.addVolumetricData(cubeData, "cube", {{isoval: -0.02, color: "red", alpha: 0.7}});
|
| 281 |
-
|
| 282 |
-
viewer_{label}.zoomTo();
|
| 283 |
-
viewer_{label}.render();
|
| 284 |
-
viewer_{label}.zoom(1.2);
|
| 285 |
-
</script>
|
| 286 |
-
</div>
|
| 287 |
-
"""
|
| 288 |
|
| 289 |
html_sections.append(
|
| 290 |
f"<div style='margin: 20px 0; padding: 10px; border: 1px solid #ddd; border-radius: 5px;'>"
|
| 291 |
f"<h3>{label} Orbital (Interactive 3D)</h3>"
|
| 292 |
f"<p><small>Blue = positive orbital lobe, Red = negative orbital lobe. Use mouse to rotate, scroll to zoom.</small></p>"
|
| 293 |
-
f"{viewer_html}"
|
| 294 |
f"</div>"
|
| 295 |
)
|
| 296 |
|
|
|
|
| 259 |
# Get molecular structure
|
| 260 |
mol_block = Chem.MolToMolBlock(mol_3d)
|
| 261 |
|
| 262 |
+
# Create py3Dmol viewer using the Python library
|
| 263 |
import py3Dmol
|
| 264 |
|
| 265 |
+
view = py3Dmol.view(width=800, height=600)
|
| 266 |
+
|
| 267 |
+
# Add molecular structure
|
| 268 |
+
view.addModel(mol_block, "sdf")
|
| 269 |
+
view.setStyle({'stick': {'radius': 0.15}, 'sphere': {'scale': 0.3}})
|
| 270 |
+
|
| 271 |
+
# Add orbital isosurfaces from cube data
|
| 272 |
+
view.addVolumetricData(cube_data, "cube", {'isoval': 0.02, 'color': "blue", 'alpha': 0.75})
|
| 273 |
+
view.addVolumetricData(cube_data, "cube", {'isoval': -0.02, 'color': "red", 'alpha': 0.75})
|
| 274 |
+
|
| 275 |
+
view.zoomTo()
|
| 276 |
+
|
| 277 |
+
# Generate standalone HTML
|
| 278 |
+
viewer_html = view._make_html()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
html_sections.append(
|
| 281 |
f"<div style='margin: 20px 0; padding: 10px; border: 1px solid #ddd; border-radius: 5px;'>"
|
| 282 |
f"<h3>{label} Orbital (Interactive 3D)</h3>"
|
| 283 |
f"<p><small>Blue = positive orbital lobe, Red = negative orbital lobe. Use mouse to rotate, scroll to zoom.</small></p>"
|
| 284 |
+
f"<div style='width: 100%; height: 600px;'>{viewer_html}</div>"
|
| 285 |
f"</div>"
|
| 286 |
)
|
| 287 |
|
force_rebuild.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
# Force rebuild
|
| 2 |
-
2025-11-08
|
|
|
|
| 1 |
# Force rebuild
|
| 2 |
+
2025-11-08 v12
|