🧬 Sharing My Work: A 3D Molecular Visualizer for Kivy

40 views
Skip to first unread message

Yassine Ouchen

unread,
Jun 4, 2025, 12:28:32 PMJun 4
to Kivy users support

Hi everyone,

I’m excited to share a project I've been building called Kivy3DProt, a 3D molecular visualization module written in Python, Kivy, and GLSL. The module is inspired by tools like py3Dmol, but built entirely with Kivy to support native desktop and mobile apps.

Current Capabilities

  • Visualizes molecular structures in sphere mode (atoms as GLSL spheres).

  • Loads PDB files either locally or by PDB ID.

  • Auto-rotating animations (tumbling, orbital, oscillating).

  • Smart zoom and centering: uses a constant scale factor for structural integrity and adjusts zoom to fit the molecule within the view.

  • Runs smoothly for molecules with up to 100 atoms (e.g. caffeine). 

  🎥 Here's a GIF of a rendered molecule (caffeine):  
kiv3DProt (2).gif

⚠️ Challenge 1: Rendering Beyond 100 Atoms

To store molecule data (position(x,y,z), color(r,g,b) and radius), I'm using uniforms. This works great for small molecules but:

  • GLSL shaders on most GPUs have limits (~1024–4096 uniform components).

  • Each atom uses multiple uniforms (position, color, radius), so I hit this limit quickly with 100+ atoms.

This makes my current method unsuitable for proteins, which have 1000+ atoms.

🧠 Planned Solution: Using Textures Instead of Uniforms

I plan to overcome this by:

  • Packing atom data (position, color, radius) into a floating-point texture (RGBA32F).

  • Accessing this data in the fragment shader via sampler2D.

  • This would allow rendering thousands of atoms efficiently without blowing the uniform limits.

🔧 Challenge 2: Rendering & Performance Optimization

To support large molecules:

  • I will need to implement spatial partitioning (e.g. frustrum culling or bounding boxes) to reduce fragment load.

  • Possibly move to instanced rendering if I go beyond GLSL-based spheres (e.g. OpenGL ES 3.0 with mesh instances).


🙋‍♂️ Seeking Advice
  1. Has anyone integrated sampler2D + floating-point textures with Kivy’s RenderContext? Any tips or pitfalls?

  2. For large scenes with thousands of atoms, would you recommend moving away from GLSL fragment shaders and rendering atoms as instanced spheres via mesh primitives?

  3. I'm targeting mobile (Android) too. Has anyone had success with high-performance 3D in Kivy on mobile?

This is a work in progress, and I’d love to hear your thoughts, especially if you’ve worked on large-data GLSL rendering or scientific visualizations.

Thanks for reading!
OuchenTech

ElliotG

unread,
Jun 5, 2025, 11:20:45 AMJun 5
to Kivy users support
You might be able to get some ideas from this project: http://www.kivent.org/
Reply all
Reply to author
Forward
0 new messages