= Render structures using Unreal Engine = This is not strictly EMAN2 related, but I have been showing short videos around ([[https://drive.google.com/file/d/17ZMz2rqop9KoBzJ8GWJTab4riKod_HsU/view?usp=drive_link|example]]) and people ask how to make them. So here is a simple tutorial. To start, * Install Unreal Engine 5. * Start a new blank project. {{attachment:new project.png | New project |width=600}} == 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 }}} {{attachment:chimerax.png | chimerax |width=600}} 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''' {{attachment:import.png | import |width=600}} 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. {{attachment:material.png | material |width=600}} 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. {{{#!python import unreal scale=0.1 zz=2000 obj=unreal.EditorAssetLibrary.load_asset("/Game/actin.actin") root=unreal.EditorLevelLibrary.spawn_actor_from_class(unreal.StaticMeshActor,(0,0,zz)) root.set_actor_label("root") for xx in range(10): filament=unreal.EditorLevelLibrary.spawn_actor_from_class(unreal.StaticMeshActor,(xx*1000,0,zz)) filament.attach_to_actor(root,"none",unreal.AttachmentRule.KEEP_WORLD,unreal.AttachmentRule.KEEP_WORLD,unreal.AttachmentRule.KEEP_WORLD) filament.set_actor_label(f"filament_{xx:03d}") for yy in range(30): act=unreal.EditorLevelLibrary.spawn_actor_from_object(obj,(xx*1000,yy*273*2,zz), (-2*yy*166.15+xx*30,0,0)) act.set_actor_relative_scale3d((scale, scale, scale)) act.attach_to_actor(filament,"none",unreal.AttachmentRule.KEEP_WORLD,unreal.AttachmentRule.KEEP_WORLD,unreal.AttachmentRule.KEEP_WORLD) 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 '''placeactin.py''' 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/placeactin.py" }}} Now you should see the actin filament in the editor view. Navigate in the editor by holding mouse right button and press WASD. {{attachment:filament.png | filament|width=600}} == Make movie == To make movies, add a level sequence, and add a camera in the sequence. {{attachment:add_sequence.png | sequence |width=600}} 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. {{attachment:move_camera.png | move camera|width=600}} 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. {{attachment:move_object.png | move object|width=600}} After satisfied with the movie sequence, generate the final movie and save to a file. {{attachment:render_movie.png | render movie|width=600}} == Final movie == Here is my final movie for this tutorial. The quality is compromised since the wiki only supports gif... {{attachment:final_movie.gif | Final movie |width=600}} == 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 {{{ e2spt_mapptclstotomo_ue5.py --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 "from_tomo.py" }}} When multiple types of objects are present in the tomogram, run refinement for each, and repeat the process for each spt_xx folder. {{attachment:from_tomo.png | from tomograms |width=600}}