# Importing pymol module
import __main__
__main__.pymol_argv = [ 'pymol', '-x' ]
import pymol
import IPython
pymol.finish_launching()
from pymol import cmd,stored
cmd.reinitialize()
cmd.bg_color('white')
cmd.fetch('1lmp', 'putative_protein')
cmd.remove('solvent')
cmd.color('silver')
cmd.select('ligand', selection='hetatm')
cmd.color('wheat', 'hetatm')
# What do we see?
cmd.set('ray_trace_mode', 1)
cmd.png('first_look.png', '1920', '1080', ray=1)
IPython.display.Image('first_look.png', retina=True)
# What do we want to mutate?
# Resi 97 is an arginine
cmd.color('red', 'resi 97')
cmd.hide('cartoon', 'resi 97')
cmd.show('sticks', 'resi 97')
cmd.set('ray_trace_mode', 1)
cmd.png('protein_without_mutation.png', '1920', '1080', ray=1)
IPython.display.Image('protein_without_mutation.png', retina=True)
# Mutate ARG97 to GLY97
residue_to_mutate = 'resi 97'
cmd.wizard('mutagenesis')
cmd.refresh_wizard()
cmd.get_wizard().do_select('{0}'.format(residue_to_mutate))
cmd.get_wizard().set_mode('GLY')
cmd.refresh_wizard()
cmd.get_wizard().apply()
cmd.set_wizard()
# How does a protein mutant look like?
cmd.center('putative_protein')
cmd.zoom('putative_protein')
cmd.set('ray_trace_mode', 1)
cmd.png('protein_with_mutation.png', '1920', '1080', ray=1)
IPython.display.Image('protein_with_mutation.png', retina=True)
cmd.fetch('1lmp', 'native_protein')
cmd.remove('solvent')
cmd.select('putative_ligand', 'putative_protein and hetatm')
cmd.select('native_ligand', 'native_protein and hetatm')
cmd.show('cartoon', '(putative_protein or native_protein) and (not *ligand)')
cmd.colour('silver', 'putative_protein')
cmd.colour('skyblue', 'native_protein')
cmd.show('sticks', '*ligand')
cmd.colour('wheat', '*ligand')
cmd.show('sticks', residue_to_mutate)
cmd.colour('lightpink', 'native_protein and '+ residue_to_mutate)
cmd.colour('red', 'putative_protein and '+ residue_to_mutate)
cmd.translate('[-35, 0, 0]', 'native_protein')
cmd.center('putative_protein + native_protein')
cmd.zoom('putative_protein + native_protein')
cmd.set('ray_trace_mode', 1)
cmd.png('proteins_face_to_face.png', '1920', '1800', ray=1)
IPython.display.Image('proteins_face_to_face.png', retina=True)
num_frames = 480
cmd.hide('cartoon', residue_to_mutate)
cmd.show('sticks', residue_to_mutate)
# Creating 480 blank frames
cmd.mset('1 x{0}'.format(int(num_frames)))
# Store initial position of camera and native_protein
cmd.frame('1')
cmd.mview('store')
cmd.mview('store', object='native_protein')
# Align two proteins
# Position of camera is not altered
# Native_protein slides along the X axis by 35 pt
cmd.frame('90')
cmd.mview('store')
cmd.translate('[35, 0, 0]', object='native_protein')
cmd.mview('store', object='native_protein')
# Close-up of the proteins aligned
# Position of camera changes
# Native_protein is still aligned
cmd.frame('210')
cmd.center('native_protein')
cmd.zoom('native_protein')
cmd.mview('store', object='native_protein')
cmd.mview('store')
# Close-up of the mutated residues
# Position of camera changes
# Native_protein is still aligned
cmd.frame('300')
cmd.mview('store', object='native_protein')
cmd.center(residue_to_mutate)
cmd.zoom(residue_to_mutate)
cmd.mview('store')
# Camera turns around Y axis by 135 degrees
# Native_protein is still aligned
cmd.frame('480')
cmd.mview('store', object='native_protein')
cmd.center(residue_to_mutate)
cmd.zoom(residue_to_mutate)
cmd.turn('y', 135)
cmd.mview('store')
# Fill in the gaps between the frames
cmd.mview('reinterpolate')
cmd.mview('reinterpolate', object='native_protein')
import os
cmd.set('ray_trace_mode', 1)
for i in range(num_frames):
cmd.frame(i)
cmd.png(os.path.join(os.getcwd(), 'pics', '{0}.png'.format(str(i))), '1920', '1080', ray=1)
import subprocess
import os
where_am_i = os.getcwd()
# bash_command = 'ffmpeg -i "$where_am_i"/pics/%d.png -vcodec libx264 -crf 15 -hide_banner -loglevel panic "$where_am_i"/test.mp4'
subprocess.run(['ffmpeg', '-i', '"$where_am_i"/pics/%d.png', '-vcodec',
'libx264', '-crf', '15', '-hide_banner', '-loglevel',
'panic', '"$where_am_i"/test.mp4'], shell=True)
# %%bash
# where_am_i=`echo $PWD`
# ffmpeg -i "$where_am_i"/pics/%d.png -vcodec libx264 -crf 15 -hide_banner -loglevel panic "$where_am_i"/align.mp4
from base64 import b64encode
from IPython.display import HTML
video = open('align.mp4', 'rb').read()
encoded = b64encode(video)
HTML(data='''<video width=700px controls>
<source src="data:video/mp4; base64,{0}" type="video/mp4" />
</video>'''.format(encoded.decode('ascii')))