---
title: "Visualize proteins on Hugging Face Spaces"
description: "Protein structures can be rendered inside a Gradio app on Hugging Face Spaces by embedding 3Dmol.js in an HTML block via an iframe srcdoc, which works around browser security rules."
url: "https://swe.quest/articles/visualize-proteins-on-hugging-face-spaces-a6655b2cad7bf6ef"
canonical: "https://huggingface.co/blog/spaces_3dmoljs"
source: "Hugging Face"
published: "2022-08-24"
difficulty: "medium"
kind: "How-to"
reading_minutes: 5
tags: ["python","frontend","scientific-computing","machine-learning"]
---

# Visualize proteins on Hugging Face Spaces

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-08-24, 5 min read, How-to. Original: [https://huggingface.co/blog/spaces\_3dmoljs](https://huggingface.co/blog/spaces_3dmoljs)

## Summary

Protein structures can be rendered inside a Gradio app on Hugging Face Spaces by embedding 3Dmol.js in an HTML block via an iframe srcdoc, which works around browser security rules. The walkthrough builds a viewer that accepts a 4-character PDB code (fetched from RCSB) or an uploaded PDB file, injects the file contents into a template literal, and configures the 3Dmol viewer's style, zoom and container size. A May 2024 update recommends the gradio\_molecule3d custom component instead, which supports on-the-fly representation changes, and the ProteinMPNN space is cited as a production example.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Python](https://swe.quest/tags/python.md) (Languages)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [Scientific computing](https://swe.quest/tags/scientific-computing.md) (Domains)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)

## Prerequisites

- Gradio basics
- JavaScript/jQuery basics ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- PDB file format

## Keywords

Gradio, 3Dmol.js, Hugging Face Spaces, PDB, AlphaFold2, ProteinMPNN, Molecule3D

## Related posts

- [How an Agent Built a 3D Paris Gallery by Chaining Two Hugging Face Spaces](https://swe.quest/articles/how-an-agent-built-a-3d-paris-gallery-by-chaining-two-hugging-face-spaces-854f07cf2fac2554.md): Hugging Face · 2026-06-09 · Medium · 9 min read · AI agents, AI for coding, Computer vision, API design
  Every Gradio Space on Hugging Face now exposes a plain-text agents.md describing its API schema, call/poll endpoints, file upload and auth, so a coding agent can drive a Space with no client library.
- [One-Shot Any Web App with Gradio's gr.HTML](https://swe.quest/articles/one-shot-any-web-app-with-gradio-s-gr-html-dbfd86d457b2c28e.md): Hugging Face · 2026-02-18 · Medium · 4 min read · Python, Frontend, AI for coding, Developer tools
  Gradio 6's gr.HTML now accepts an html\_template, scoped css\_template and js\_on\_load script, so a fully custom interactive component (frontend, backend and state) fits in one Python file that an LLM can generate in one shot.
- [Introducing Daggr: Chain apps programmatically, inspect visually](https://swe.quest/articles/introducing-daggr-chain-apps-programmatically-inspect-visually-6410fcfcb5ab3906.md): Hugging Face · 2026-01-29 · Medium · 8 min read · Python, ML platforms, Developer tools, Open source
  Daggr is an open-source Python library from the Gradio team for chaining Gradio Spaces, Hugging Face Inference Providers models and custom Python functions into workflows defined in code, with an automatically generated visual canvas.
- [Showcase Your Projects in Spaces using Gradio](https://swe.quest/articles/showcase-your-projects-in-spaces-using-gradio-939ccccc3ad428cf.md): Hugging Face · 2021-10-05 · Medium · 3 min read · Machine learning, Python, Inference & serving
  Gradio's Hugging Face Hub integration lets you build an ML demo from a Hub model ID in a few lines: gr.Interface.load plus a title, description and example inputs, backed by the Inference API.
- [The 5 Most Under-Rated Tools on Hugging Face](https://swe.quest/articles/the-5-most-under-rated-tools-on-hugging-face-d4091b1b4c6dbb61.md): Hugging Face · 2024-08-22 · Medium · 16 min read · ML platforms, Search, Data pipelines, Python
  Five overlooked Hugging Face Hub features (ZeroGPU, multi-process Docker Spaces, the Gradio API client, Hub webhooks and Nomic Atlas) can be combined into a free, automatically updating semantic search pipeline, demonstrated over a subreddit data source.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
