Created
March 3, 2021 12:44
-
-
Save robertodr/4aec23129b314a7ac6aab1ad9c7a0429 to your computer and use it in GitHub Desktop.
Visualize two cube files with an interactive slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ipywidgets import interact, fixed, widgets | |
@interact(mol_xyz=fixed(pyridine_xyz), cube=widgets.SelectionSlider(options=["HOMO", "LUMO"], description="MO")) | |
def draw_geometry_and_cube(mol_xyz, cube): | |
# Adapted from: https://adreasnow.com/Cheat%20Sheets/Python/Psi4Interactive/#viewing-psi4-molecules-with-cubes-py3dmol | |
# read volumetric data | |
with open(f"{cube}.cube", "r") as f: | |
cube = f.read() | |
# initialize the view | |
view = p3d.view(width=400, height=400) | |
# add stick molecule to the view | |
view.addModel(mol_xyz, "xyz") | |
view.setStyle({"stick": {}}) | |
# add volumetric data to the view | |
# negative lobe | |
view.addVolumetricData(cube, "cube", {"isoval": -0.02, "color": "blue", "opacity": 0.75}) | |
# positive lobe | |
view.addVolumetricData(cube, "cube", {"isoval": 0.02, "color": "red", "opacity": 0.75}) | |
return view.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment