DNA 3D model
- Peter Mortier
- Mar 13
- 1 min read
Updated: 6 days ago
DNA has a special shape called a double helix, which looks like a twisted ladder. This spiral structure helps DNA store and protect genetic information inside cells. A DNA 3D model can help us see this structure more clearly and understand how DNA functions.
In this example, we create the typical double helix structure using a limited amount of Python code. The 3D DNA model can be easily modified using the parameters at the top.
from hellotriangle import shapes
# parameters
rs = 1.0
rc = 0.3
l = 7.0
n = 16
deg = 20.
dist = 1.5
# create sphere
sphere = shapes.sphere().scale(rs)
# create cylinder
cir = shapes.circle(n=16).scale(rc)
cyl = cir.extrude(1, dir = [0.0, 0.0, 1.0], length = l)
# create 1 unit
sphere2 = sphere.translate([0.0, 0.0, l])
unit = sphere + cyl.convert('tri3') + sphere2
unitCentered = unit.translate([0.0, 0.0, -l/2.0])
# create DNA double helix
dna = unitCentered
for i in range(n):
unitCentered = unitCentered.rotate_X(deg).translate([dist, 0.0, 0.0])
dna += unitCentered
# draw
draw(dna, color = "grey")
