Molecular Trajectory Video with Live 2D Plot
Install
npm install -g @lmctl-ai/lmctl
lmvideo 0.1.38 is released. Source examples are pinned to public commit aab2677.
900x560 poster; 1280x720, 30fps, 120 frames (4 seconds) video; procedural ball-and-stick molecule, orbital path, projected atom labels, synchronized live energy plot, and cached frames.
Verified acceptance capture, reproducible with the lmvideo 0.1.38 prerelease runtime.
Run this example
lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmvideo/aab2677a4b6264ae6afae8ad64a1d7c1dcd3a052/examples/showcase/bench-15-molecular-trajectory.lms
Source
# B15 / P.7: projected molecular orbit with native disk frame cache.
mkdir("build"); mkdir("build/bench-15-frames"); program=_lmcode_ cli="lmvideo" install="github:lmctl-ai/lmvideo@v0.1.38";
video.size(1280,720); video.fps(30); video.frames(120); video.crf(20); video.output("build/bench-15-molecular-trajectory.mp4"); video.begin();
let scene=scene3d().threads(4).background("#09111f").ambient(0.18).threads(4); scene.camera(camera3d().look_at(0.0,1.6,5.0,0.0,0.4,0.0).perspective(40.0,0.1,20.0)); let oxygen=scene.add(mesh_sphere(0.52,24,32),"#d95356"); let h1=scene.add(mesh_sphere(0.32,16,24),"#c9e2f1"); let h2=scene.add(mesh_sphere(0.32,16,24),"#c9e2f1"); let b1=scene.add(mesh_cylinder(0.10,0.9823,20),"#778d9d"); let b2=scene.add(mesh_cylinder(0.10,0.9823,20),"#778d9d"); scene.directional_light(1.0,3.0,4.0,"#ffffff",1.0);
let cache=frame_cache("build/bench-15-frame-cache",67108864); let destination=image_create(820,560,"#00000000");let composed_buffer=image_create(1280,720,"#00000000");let projection_buffer=scene.projection(820,560); let plot=canvas.plot(860.0,90.0,360.0,500.0).title("Live potential energy").xlabel("time (s)").ylabel("E").x_range(0.0,4.0).y_range(-1.2,1.2).background("#ffffff"); let trace=plot.series("E","line","#e76f51");
for(frame in range(0,video.count())) { video.frame(); let t=float(frame)/30.0; let angle=6.283185307*t/4.0; let ox=0.22*sin(angle); let oy=0.4+0.18*cos(angle); oxygen.position(ox,oy,0.0); h1.position(ox-0.95,oy+0.25,0.0); h2.position(ox+0.95,oy+0.25,0.0); b1.position(ox-0.475,oy+0.125,0.0).rotation(0.0,0.0,75.256); b2.position(ox+0.475,oy+0.125,0.0).rotation(0.0,0.0,-75.256); let rendered=cache.render(scene,820,560,2,destination); let projection=scene.projection(820,560,projection_buffer); let oa=projection.at(ox,oy,0.0); let h1a=projection.at(ox-0.95,oy+0.25,0.0); let h2a=projection.at(ox+0.95,oy+0.25,0.0); canvas.clear("#09111f"); canvas.image(rendered,20.0,80.0); for(k in range(0,24)){let a0=6.283185307*float(k)/24.0; let a1=6.283185307*float(k+1)/24.0; let p0=projection.at(0.82*cos(a0),0.4+0.34*sin(a0),0.0); let p1=projection.at(0.82*cos(a1),0.4+0.34*sin(a1),0.0); if(p0.visible()&&p1.visible()){canvas.line(20.0+p0.x(),80.0+p0.y(),20.0+p1.x(),80.0+p1.y(),paint().color("#6fa8d6").stroke().stroke_width(2.0));}} if(oa.visible()){canvas.text("O",20.0+oa.x(),80.0+oa.y(),font(22.0),paint().color("#ffffff"));} if(h1a.visible()){canvas.text("H",20.0+h1a.x(),80.0+h1a.y(),font(18.0),paint().color("#d9f1ff"));} if(h2a.visible()){canvas.text("H",20.0+h2a.x(),80.0+h2a.y(),font(18.0),paint().color("#d9f1ff"));} trace.add(t,0.8*cos(angle)-0.2); plot.draw(); canvas.snapshot(composed_buffer).save("build/bench-15-frames/frame-"+str(frame)+".png"); if(frame==video.count()-1){canvas.snapshot(composed_buffer).save("build/bench-15-molecular-trajectory.png"); canvas.snapshot(composed_buffer).resize(900,560).save("build/bench-15-molecular-trajectory-still.png");} }
video.end();
for(frame in range(0,video.count())) { let t=float(frame)/30.0; let angle=6.283185307*t/4.0; let ox=0.22*sin(angle); let oy=0.4+0.18*cos(angle); oxygen.position(ox,oy,0.0); h1.position(ox-0.95,oy+0.25,0.0); h2.position(ox+0.95,oy+0.25,0.0); b1.position(ox-0.475,oy+0.125,0.0).rotation(0.0,0.0,75.256); b2.position(ox+0.475,oy+0.125,0.0).rotation(0.0,0.0,-75.256); cache.render(scene,820,560,2,destination); }
image_assert_true(cache.misses()==120&&cache.hits()==120); out.print("B15: projected trajectory labels, world orbital path, live energy plot, frame_cache 120 misses + 120 hits");
end _lmcode_
r=run_lmcode(program); assert(r.ok,(r.ok ? "" : r.message));println(json_stringify(r.result));
