Per @dr_greg_landrum's request, support updating an already existing viewer in-place.
import py3Dmol
benz='''
RDKit 3D
6 6 0 0 0 0 0 0 0 0999 V2000
-0.9517 0.7811 -0.6622 C 0 0 0 0 0 0 0 0 0 0 0 0
0.2847 1.3329 -0.3121 C 0 0 0 0 0 0 0 0 0 0 0 0
1.2365 0.5518 0.3512 C 0 0 0 0 0 0 0 0 0 0 0 0
0.9517 -0.7811 0.6644 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.2847 -1.3329 0.3144 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.2365 -0.5518 -0.3489 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 2 0
2 3 1 0
3 4 2 0
4 5 1 0
5 6 2 0
6 1 1 0
M END
$$$$'''
view = py3Dmol.view()
view.addModel(benz,'sdf')
view.setStyle({'stick':{}})
view.zoomTo()
view.show()
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol
view.setStyle({'stick':{'color':'blue'}})
view.update()
xyz = '''4
* (null), Energy -1000.0000000
N 0.000005 0.019779 -0.000003 -0.157114 0.000052 -0.012746
H 0.931955 -0.364989 0.000003 1.507100 -0.601158 -0.004108
H -0.465975 -0.364992 0.807088 0.283368 0.257996 -0.583024
H -0.465979 -0.364991 -0.807088 0.392764 0.342436 0.764260
'''
view.addModel(xyz,'xyz',{'vibrate': {'frames':10,'amplitude':1}})
view.setStyle({'model':1},{'stick':{}})
view.setBackgroundColor('0xeeeeee')
view.animate({'loop': 'backAndForth'})
view.zoomTo()
view.update()