Generating Geometries for Geant4

This notebook contains code blocks used to generate sample geometries used in Geant4 simulations.

[ ]:
import sys
from pathlib import Path

try:
    from fractaldna.dna_models import dnachain
except (ImportError, ModuleNotFoundError):
    sys.path.append(str(Path.cwd().parent.parent.parent))
    from fractaldna.dna_models import dnachain

import numpy as np
from mayavi import mlab

mlab.options.offscreen = True

Single DNA Segments

Straight and Turned Segments for a 50nm box.

[ ]:
%%capture
bp_separation = dnachain.BP_SEPARATION  # 3.32Å
side_length_nm = 50  # nm
num_basepairs_straight = int(side_length_nm / (0.1 * bp_separation))
num_basepairs_turned = int((side_length_nm * np.pi / 4.0) / (0.1 * bp_separation))

chain_straight = dnachain.DNAChain(
    "".join(np.random.choice(["G", "A", "T", "C"], num_basepairs_straight))
)

chain_turned = dnachain.TurnedDNAChain(
    "".join(np.random.choice(["G", "A", "T", "C"], num_basepairs_turned))
)

chain_turned_twisted = dnachain.TurnedTwistedDNAChain(
    "".join(np.random.choice(["G", "A", "T", "C"], num_basepairs_turned))
)

chain_straight.to_frame().to_csv("results/50nm_straight.csv", sep=" ", index=False)
chain_turned.to_frame().to_csv("results/50nm_turn.csv", sep=" ", index=False)
chain_turned_twisted.to_frame().to_csv(
    "results/50nm_turn_twist.csv", sep=" ", index=False
)

chain_straight.to_plot().savefig("results/50nm_straight.png", sep=" ", index=False)
chain_turned.to_plot().savefig("results/50nm_turn.png", sep=" ", index=False)
chain_turned_twisted.to_plot().savefig(
    "results/50nm_turn_twist.png", sep=" ", index=False
)

3019b1941d3a46dfbae46a10ce335e5c 064d5c013de44e86a7169c3a7191a7fa e6a50c180880473a8e37a978bd35f125

Multi Strand straight and turned segments

[ ]:
%%capture
bp_separation = dnachain.BP_SEPARATION  # 3.32Å
side_length_nm = 50  # nm
num_basepairs_straight = int(side_length_nm / (0.1 * bp_separation))
num_basepairs_turned = int((side_length_nm * np.pi / 4.0) / (0.1 * bp_separation))
strand_separation = 100  # angstroms

chain4_straight = dnachain.FourStrandDNAChain(
    "".join(np.random.choice(["G", "A", "T", "C"], num_basepairs_straight)),
    strand_separation,
)

chain4_turned = dnachain.FourStrandTurnedDNAChain(
    "".join(np.random.choice(["G", "A", "T", "C"], num_basepairs_turned)),
    strand_separation,
)

chain4_turned_twisted = dnachain.FourStrandTurnedDNAChain(
    "".join(np.random.choice(["G", "A", "T", "C"], num_basepairs_turned)),
    strand_separation,
    twist=True,
)

chain4_straight.to_frame().to_csv("results/50nm_4_straight.csv", sep=" ", index=False)
chain4_turned.to_frame().to_csv("results/50nm_4_turn.csv", sep=" ", index=False)
chain4_turned_twisted.to_frame().to_csv(
    "results/50nm_4_turn_twist.csv", sep=" ", index=False
)

chain4_straight.to_plot().savefig("results/50nm_4_straight.png")
chain4_turned.to_plot().savefig("results/50nm_4_turn.png")
chain4_turned_twisted.to_plot().savefig("results/50nm_4_turn_twist.png")

d7732330a27144c59e0c85e312b46656 a9f05d7aae774764be4b9a2f802dd3f2 b76662100895444b8d60e9de1983c74a

[ ]:
%%capture
bp_separation = dnachain.BP_SEPARATION  # 3.32Å
side_length_nm = 50  # nm
num_basepairs_straight = int(side_length_nm / (0.1 * bp_separation))
num_basepairs_turned = int((side_length_nm * np.pi / 4.0) / (0.1 * bp_separation))
strand_separation_1 = 100  # angstroms
strand_separation_2 = 250  # angstroms

chain8_straight = dnachain.EightStrandDNAChain(
    "".join(np.random.choice(["G", "A", "T", "C"], num_basepairs_straight)),
    strand_separation_1,
    strand_separation_2,
    turn=False,
    twist=False,
)

chain8_turned = dnachain.EightStrandDNAChain(
    "".join(np.random.choice(["G", "A", "T", "C"], num_basepairs_turned)),
    strand_separation_1,
    strand_separation_2,
    turn=True,
    twist=False,
)

chain8_turned_twisted = dnachain.EightStrandDNAChain(
    "".join(np.random.choice(["G", "A", "T", "C"], num_basepairs_turned)),
    strand_separation_1,
    strand_separation_2,
    turn=True,
    twist=True,
)

chain8_straight.to_frame().to_csv(
    "results/50nm_8_straight.csv",
    sep=" ",
    index=False,
)
chain8_turned.to_frame().to_csv("results/50nm_8_turn.csv", sep=" ", index=False)
chain8_turned_twisted.to_frame().to_csv(
    "results/50nm_8_turn_twist.csv", sep=" ", index=False
)

chain8_straight.to_plot().savefig("results/50nm_8_straight.png")
chain8_turned.to_plot().savefig("results/50nm_8_turn.png")
chain8_turned_twisted.to_plot().savefig("results/50nm_8_turn_twist.png")

e68d6caf6ad44b0084cffc436e0d7a28 124722a098bf453b93f590a7f0418125 ee93055e16b24c34a967c02b11d88ab0

Making Solenoidal DNA

Single Solenoids

[ ]:
side_length = 750  # angstrom
radius_solenoid = 100  # angstrom
nhistones = 38  # histones

solenoid_straight = dnachain.Solenoid(
    voxelheight=side_length, radius=radius_solenoid, nhistones=nhistones
)
solenoid_turned = dnachain.TurnedSolenoid(
    voxelheight=side_length, radius=radius_solenoid, nhistones=nhistones
)
solenoid_turned_twisted = dnachain.TurnedSolenoid(
    voxelheight=side_length, radius=radius_solenoid, nhistones=nhistones, twist=True
)

# centre around (x,y,z)=(0,0,0)
solenoid_straight.translate([0, 0, -side_length / 2.0])
solenoid_turned.translate([0, 0, -side_length / 2.0])
solenoid_turned_twisted.translate([0, 0, -side_length / 2.0])

solenoid_straight.to_frame().to_csv(
    "results/solenoid_straight.csv", sep=" ", index=False
)
solenoid_turned.to_frame().to_csv("results/solenoid_turned.csv", sep=" ", index=False)
solenoid_turned_twisted.to_frame().to_csv(
    "results/solenoid_turned_twisted.csv", sep=" ", index=False
)

plot = solenoid_straight.to_line_plot()
plot.scene.save_jpg("results/solenoid_straight.jpg")

plot = solenoid_turned.to_line_plot()
distance = 1500
mlab.view(azimuth=180, elevation=0, distance=distance, focalpoint=[0, 0, 0])
mlab.move(up=-distance, forward=distance)
mlab.pitch(90)
plot.scene.save_jpg("results/solenoid_turned.jpg")

plot = solenoid_turned_twisted.to_line_plot()
mlab.view(azimuth=180, elevation=0, distance=distance, focalpoint=[0, 0, 0])
mlab.move(up=-distance, forward=distance)
mlab.pitch(90)
plot.scene.save_jpg("results/solenoid_turned_twisted.jpg")

a4cb4dbbdb204cb6bf703303e12dd349 028e9bc8afbd4219ba39ab700cf86a80 107ddde1d7984c8b9684449ac1f0c7ff

Generating multiple solenoids in a Volume

[ ]:
side_length = 1000  # angstrom
radius_solenoid = 100  # angstrom
nhistones = 51  # histones
separation = 250  # angstroms

solenoid4_straight = dnachain.MultiSolenoidVolume(
    voxelheight=side_length,
    separation=separation,
    radius=radius_solenoid,
    nhistones=nhistones,
    chains=[1, 2, 3, 4],
    turn=False,
    twist=False,
)

solenoid4_turned = dnachain.MultiSolenoidVolume(
    voxelheight=side_length,
    separation=separation,
    radius=radius_solenoid,
    nhistones=nhistones,
    chains=[1, 2, 3, 4],
    turn=True,
    twist=False,
)

solenoid4_turned_twisted = dnachain.MultiSolenoidVolume(
    voxelheight=side_length,
    separation=separation,
    radius=radius_solenoid,
    nhistones=nhistones,
    chains=[1, 2, 3, 4],
    turn=True,
    twist=True,
)

# centre around (x,y,z)=(0,0,0)
solenoid4_straight.translate([0, 0, -side_length / 2.0])
solenoid4_turned.translate([0, 0, -side_length / 2.0])
solenoid4_turned_twisted.translate([0, 0, -side_length / 2.0])

solenoid4_straight.to_frame().to_csv(
    "results/solenoid4_straight.csv", sep=" ", index=False
)
solenoid4_turned.to_frame().to_csv("results/solenoid4_turned.csv", sep=" ", index=False)
solenoid4_turned_twisted.to_frame().to_csv(
    "results/solenoid4_turned_twisted.csv", sep=" ", index=False
)

plot = solenoid4_straight.to_line_plot()
plot.scene.save_jpg("results/solenoid4_straight.jpg")

plot = solenoid4_turned.to_line_plot()
distance = 2500
mlab.view(azimuth=180, elevation=0, distance=distance, focalpoint=[0, 0, 0])
mlab.move(up=-distance, forward=distance)
mlab.pitch(90)
plot.scene.save_jpg("results/solenoid4_turned.jpg")

plot = solenoid4_turned_twisted.to_line_plot()
mlab.view(azimuth=180, elevation=0, distance=distance, focalpoint=[0, 0, 0])
mlab.move(up=-distance, forward=distance)
mlab.pitch(90)
plot.scene.save_jpg("results/solenoid4_turned_twisted.jpg")

02488d55d9c94d3ab10c1e8b855c33fd 0dabcb6491c04cf49f8d703e7fbd9f12