py3dmol icon indicating copy to clipboard operation
py3dmol copied to clipboard

Cannot render PDB with addModel

Open data2code opened this issue 2 years ago • 0 comments

I know this package is not maintained, but just curious if you are still able to shed some light on the issue I encountered. I want to use py3dmol to create an html (not within Jupyter) to visualize proteins.

My code is below. If I use the first if branch, the resultant html works. But if I use the second approach, the molecule cannot be rendered. I tried on different browsers, the error occurs at the last rendering call. For what I can find from Google, it seems the second approach should work. The reason I tried the second approach is b/c I want to add two pdb structures to the same view later on.

Thank you!

import py3Dmol pdb_code = '1crn' if False: view = py3Dmol.view(query=f'pdb:{pdb_code}') view.setStyle({'cartoon': {'color':'spectrum'}}) view.zoomTo() print(view._make_html()) else: view = py3Dmol.view() view.addModel(f'pdb:{pdb_code}', 'pdb') view.setStyle({'cartoon': {'color':'spectrum'}}) view.zoomTo() print(view._make_html())

data2code avatar Apr 04 '23 03:04 data2code