bl1231 / bilbomd-worker

Processes BilboMD jobs and run CHARMM, FoXS, and MultiFoXS
1 stars 0 forks source link

Generate molecular movie from CHARMM trajectories #423

Open dsclassen opened 2 months ago

dsclassen commented 2 months ago

It has been suggested that providing molecular movies from the CHARMM trajectories might be a nice feature to add to BilboMD

dsclassen commented 2 months ago

I would suggest creating a dedicated Docker container with PyMOL installed and tehn run something along these lines:

# Import pymol modules
import pymol
from pymol import cmd

# Initialize PyMOL without the GUI
pymol.finish_launching(['pymol', '-qc'])  # -qc means quiet and no GUI

# Load the CHARMM structure and trajectory files
structure_file = 'structure.psf'
trajectory_file = 'trajectory.dcd'

# Load the structure
cmd.load(structure_file, 'molecule')

# Load the trajectory into the same object
cmd.load_traj(trajectory_file, 'molecule')

# Customize visualization: Set display as cartoon, color by chain, etc.
cmd.show('cartoon', 'molecule')
cmd.color('chain', 'molecule')

# Optional: set camera parameters, orientation, etc.
cmd.set('ray_trace_frames', 1)  # Ray-trace the frames for high quality
cmd.zoom('molecule')

# Make the movie from the trajectory
cmd.mset('1 -1')  # Set the movie frames to correspond to the loaded trajectory

# Render the movie as PNG frames
output_prefix = 'movie_frame'
cmd.png(f'{output_prefix}_%04d.png', ray=1)  # Save each frame as a PNG file

# If you want to render a movie directly, you can use the following:
# cmd.mpng('output_movie')

# Stop PyMOL when finished
cmd.quit()
dsclassen commented 2 months ago

This potentially would take some time... especially if rendering raytraced png files so submitting to a job queue will probably be a good idea.