Created
September 8, 2016 17:48
-
-
Save jaimergp/09104ca2bbccb81ff430374f9c2522a7 to your computer and use it in GitHub Desktop.
Headless render images of molecules with PyChimera
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
import pychimera | |
import os | |
# os.environ['CHIMERADIR'] = '/path/to/headless/chimera' | |
pychimera.patch_environ() | |
pychimera.enable_chimera() | |
import chimera | |
from chimera import runCommand | |
from glob import glob | |
def main(mask='*.pdb', output_directory='.'): | |
try: | |
os.mkdir(output_directory) | |
except: | |
pass | |
filenames = sorted(glob(mask)) | |
for i, filename in enumerate(filenames): | |
print('{}/{} Rendering {}...'.format(i+1, len(filenames), filename)) | |
molecules = chimera.openModels.open(filename) | |
runCommand('focus') | |
runCommand('copy file {}/img{:03d}.png png width 1024'.format(output_directory, i)) | |
chimera.closeSession() | |
if __name__ == '__main__': | |
import sys | |
main(*sys.argv[1:3]) | |
# Finally, run ffmpeg with something like this: | |
# $> ffmpeg -i img%03d.png -c:v libx264 -pix_fmt yuv420p out.mp4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment