Render structures using Unreal Engine

This is not strictly EMAN2 related, but I have been showing short videos around (example) and people ask how to make them. So here is a simple tutorial. To start,

New project

Prepare mesh file using ChimeraX

Here I use actin as an example. In ChimeraX command line, run

open 5ONV
open emdb:3835

Before import to Unreal, we need to make sure the model is aligned to symmetry axis. Center the EMDB map using Volume -> Map Coordinates -> Center, then fit the PDB to the map. Select two actin chains, then run

surface sel resolution 3 enclose sel


Hide everything other than the surface view of the two actin chains, and run the following command, replacing xxx with your own path for file storage.

save xxxx/actin.glb center false

Import mesh to Unreal

Now back to Unreal. Click Content Drawer -> Import, select the glb file from ChimeraX and click Open. In the import window, find Build Nanite and check the box. Click Import


Open the imported mesh actin from the Content Drawer. Make sure it looks correct, and pick a material for it. I use M_Rock_Sandstone here.


To place one object into the scene, simply drag it from the Content Drawer into the editor view. However, to place many object, particulalry with symmetry, it is easier to write a python script. Here is the script I use.

   1 import unreal
   3 scale=0.1
   4 zz=2000
   5 obj=unreal.EditorAssetLibrary.load_asset("/Game/actin.actin")
   7 root=unreal.EditorLevelLibrary.spawn_actor_from_class(unreal.StaticMeshActor,(0,0,zz))
   8 root.set_actor_label("root")
  10 for xx in range(10):
  11     filament=unreal.EditorLevelLibrary.spawn_actor_from_class(unreal.StaticMeshActor,(xx*1000,0,zz)) 
  12     filament.attach_to_actor(root,"none",unreal.AttachmentRule.KEEP_WORLD,unreal.AttachmentRule.KEEP_WORLD,unreal.AttachmentRule.KEEP_WORLD)
  13     filament.set_actor_label(f"filament_{xx:03d}")
  14     for yy in range(30):
  15         act=unreal.EditorLevelLibrary.spawn_actor_from_object(obj,(xx*1000,yy*273*2,zz), (-2*yy*166.15+xx*30,0,0))
  16         act.set_actor_relative_scale3d((scale, scale, scale))
  17         act.attach_to_actor(filament,"none",unreal.AttachmentRule.KEEP_WORLD,unreal.AttachmentRule.KEEP_WORLD,unreal.AttachmentRule.KEEP_WORLD)
  18         act.set_actor_label(f"act_{yy:03d}")

This will place 10 actin filament, each 10 nm apart. Each filament contains 60 actin units, following the helical symmetry of the filament. The unit of ChimeraX output is 0.01A. To fit everything in the scene, I use a scale factor of 0.1, so 1 unit distance in Unreal would be 0.1A. The F-actin rises 27.3A per unit. Since we have two actin chains in the model, here we set the rise to 273x2, and rotate -166.15x2 degrees for each object. Save the file as in your own folder.

To run the script in Unreal, run the following command in the Cmd box. Replace xxx with your folder.

py "xxx/"

Now you should see the actin filament in the editor view. Navigate in the editor by holding mouse right button and press WASD.


Make movie

To make movies, add a level sequence, and add a camera in the sequence.


To move the camera, go to the first frame, and add a new key for camera transform at the frame. Then go to the last frame, move the camera to the target location, and add another key for camera transform. Play the sequence, and the camera should move smoothly through the scene.

move camera

To move an object, add that object to the sequencer by clicking +Track -> Actor to Sequencer -> Add "filament_000". In the Transform track of the new object, rotate-translate the object at different time frames like you move the camera.

move object

After satisfied with the movie sequence, generate the final movie and save to a file.

render movie

Final movie

Here is my final movie for this tutorial. The quality is compromised since the wiki only supports gif...

Final movie

EMAN2 SPT to Unreal

After 2023-12-08, a new program can be used to convert particle location and orientation determined using the CryoET workflow in EMAN2 directly into a scene in Unreal Engine 5. From a CryoET project folder, run --ptcls spt_xx/aliptcls3d_03.lst --tomo tomograms/tomo_yyy__bin4.hdf --ue_objs spike_a,spike_b,spike_c --ue_dir /Game/sars/

Here, we use a coronavirus example, and spike_a, spike_b, spike_c are mesh objects that have been imported into the Unreal Engine, saved in the folder sars/ under Content/. The program will write a .py file that contains the Unreal commands. Then, in the command line of Unreal, run

py ""

When multiple types of objects are present in the tomogram, run refinement for each, and repeat the process for each spt_xx folder.

from tomograms

EMAN2/unreal_render (last edited 2023-12-08 22:32:55 by MuyuanChen)