def make_overhead_snapshot(group_name, **kwargs): """Make a snapshot of the overhead view.""" sns_this = kwargs.pop('sns') snaps_drop_dn = kwargs.pop('snapshot_drop') if kwargs: raise Exception('unprocessed kwargs: %s' % kwargs) tempdir = get_snapshots_folder(snaps_drop_dn, overwrite_snaps=True) for sn_this in sns_this: slice_path = calc_contacts['extras'][sn_this]['slice_path'] if not hasattr(work, 'source'): work.parse_sources() gro, xtc = [ os.path.join(work.postdir, '%s.%s' % (slice_path, i)) for i in ['gro', 'xtc'] ] tpr = work.source.get_last(sn_this, subtype='tpr') kwargs_vmdmake = { 'CGBONDSPATH': '/home/share/libs/cg_bonds.tcl', 'GMXDUMP': '/usr/local/gromacs/bin/gmx' } frame = 500 view = vmdmake.VMDWrap(site=tempdir, gro=gro, xtc=xtc, tpr=tpr, frames='', res=(2000, 2000), **kwargs_vmdmake) view.do('load_dynamic', 'standard', 'bonder') view['snapshot_filename'] = snapshot_namer(sn=sn_this, frame=frame, group=group_name) view.set_color_cursor('black') view.select( **{ 'protein': 'noh and protein', 'style': 'cartoon', 'structure_color': False, 'goodsell': do_goodsell, 'smooth': False, 'xy': True, 'color_specific': True }) for resname in lipid_colors.keys(): view.set_color_cursor(lipid_colors[resname]) view.select( **{ 'residue_lipid_%s' % resname: 'noh and resname %s' % resname, 'goodsell': do_goodsell, 'smooth': False, 'style': licorice_thick, 'color_specific': True, 'xy': True }) view.command("animate goto %d" % frame) view.do('reset', 'zview') view.command('scale by 0.8') view.do('snapshot') view.show(quit=True)
def snapshots(): """Make many snapshots.""" # ongoing snapshot_batches = { 'v1': { 'sns': sns_contacts, 'snapshot_drop': 'snapshots_overhead' }, } # render snapshots and summaries if 0: for key, val in snapshot_batches.items(): make_overhead_snapshot(group_name=key, **val) # combine overhead snapshots if 0: replicate_mapping = [ ('pip2_20_no_chol', ['mdia2bilayer_nochl2', 'mdia2bilayer_nochl3']), ('pip2_10', ['mdia2bilayer10', 'mdia2bilayer10_2']), ('pip2_20', ['mdia2bilayerphys', 'mdia2bilayerphys2']), ('pip2_30', ['mdia2bilayer30', 'mdia2bilayer30_2']) ] #! hardcoded sns = sns_contacts ncols = 1 group_name = 'v1' #! frame is fixed frame = 500 snaps_drop_dn = 'snapshots_overhead' # plot panels together figsize = (6, 12) nrows, ncols = 4, 2 axes, fig = panelplot(layout={ 'out': { 'hspace': 0.5, 'wspace': 0.5, 'grid': [1, ncols] }, 'ins': [{ 'hspace': 0.0, 'wspace': 0.0, 'grid': [nrows, 1] } for i in range(len(sns))] }, figsize=figsize) for rnum, (name, sns_those) in enumerate(replicate_mapping): for snum, sn in enumerate(sns_those): ax = axes[snum][rnum] tempdir = get_snapshots_folder(snaps_drop_dn, overwrite_snaps=True) fn = os.path.join( work.plotdir, tempdir, snapshot_namer(sn=sn, group=group_name, frame=frame) + '.png') image = scipy.ndimage.imread(fn) ax.imshow(image) ax.axis('off') ax.set_title(work.meta[sn]['label']) picturesave('fig.snapshots_overhead.%s' % group_name, directory=work.plotdir, meta={}) # nice side view of one simulation if 1: # one target for the nice rendering sn_this = 'mdia2bilayerphys' snaps_drop_dn = 'snapshots_side' tempdir = get_snapshots_folder(snaps_drop_dn, overwrite_snaps=True) licorice_thick = 'Licorice 0.5 12.0 12.0' lipid_colors_full = dict(POPC='gray', **lipid_colors) alt_views = 'transparent brushedmetal diffuse ghost glass1 glass2 glass3 glossy hardplastic metallicpastel steel translucent edgy edgyshiny edgyglass aoshiny aochalky aoedgy blownglass glassbubble rtchrome'.split( ) # after doing the survey it looks best with edgy on the outside and maybe standard_view = ['goodsell', 'aochalky'][-1] alt_views = ['aochalky'] xres, yres = 2000, 1400 frame = 300 zoom = 2.0 slice_path = calc_contacts['extras'][sn_this]['slice_path'] if not hasattr(work, 'source'): work.parse_sources() gro, xtc = [ os.path.join(work.postdir, '%s.%s' % (slice_path, i)) for i in ['gro', 'xtc'] ] tpr = work.source.get_last(sn_this, subtype='tpr') kwargs_vmdmake = { 'CGBONDSPATH': '/home/share/libs/cg_bonds.tcl', 'GMXDUMP': '/usr/local/gromacs/bin/gmx' } # loop over alternative view on the sides for comparison representations for aa, alt_view in enumerate(alt_views): view = vmdmake.VMDWrap(site=tempdir, gro=gro, xtc=xtc, tpr=tpr, frames='', res=(xres, yres), **kwargs_vmdmake) view.do('load_dynamic', 'standard', 'bonder') extra_tag = '.rep_side_%s' % alt_views if len( alt_views) > 1 else '' view['snapshot_filename'] = 'snap.side.v1.%s.frame_%d%s' % ( sn_this, frame, extra_tag) view.set_color_cursor('black') #! note that we do not plot the proteins in the images so be careful to zoom all the way view.select( **{ 'protein': 'noh and protein', 'style': licorice_thick, 'structure_color': False, 'smooth': False, 'ystrip': False, 'goodsell': True }) view.set_color_cursor('black') view.select( **{ 'protein_cartoon': 'noh and protein', 'style': 'cartoon', 'structure_color': False, 'smooth': False, 'ystrip': False, 'color_specific': True, 'goodsell': True }) for resname in lipid_colors_full.keys(): view.set_color_cursor(lipid_colors_full[resname]) view.select( **{ 'residue_lipid_%s' % resname: 'noh and resname %s' % resname, 'smooth': False, 'style': licorice_thick, standard_view: True, 'color_specific': True }) view.select( **{ 'residue_lipid_%s_glass' % resname: 'noh and resname %s' % resname, 'style': licorice_thick, 'smooth': False, alt_view: True, 'color_specific': True, 'ystrip': True }) view.command("animate goto %d" % frame) view.command('package require pbctools') view.command('pbc box -color black') view.do('reset', 'xview') view.command('scale by %.2f' % zoom) view.do('snapshot') view.show(quit=True) print('done %d/%d' % (aa, len(alt_views)))
} #---loop over video styles for cut_name,cut_spec in film_cuts.items(): #---loop over simulations for sn in sns_ordered: #---settings ptdins_cutoff = 10.0 non_ptdins_atom_names = 'name P or name P3' ptdins_resname = work.meta[sn]['ptdins_resname'] #---make a video of the nearby PIP2 slice_path = calc['extras'][sn]['slice_path'] gro,xtc = [os.path.join(work.postdir,'%s.%s'%(slice_path,j)) for j in ['gro','xtc']] tpr = work.raw.get_last(sn,subtype='tpr') view = vmdmake.VMDWrap(site=tempdir,gro=gro,xtc=xtc,tpr=tpr, frames='',xres=4000,yres=4000,**kwargs_vmdmake) view.do('load_dynamic','standard','bonder') view.select(protein='protein',style='cartoon',structure_color=True,smooth=do_smooth,goodsell=True) if cut_spec.get('protein_residue_highlight',None): view.select(lys='protein and (%s)'%' or '.join(['resname %s'%i for i in cut_spec['protein_residue_highlight']]), style='licorice',smooth=do_smooth,goodsell=True,resname_color=True) if cut_spec.get('show_near_ptdins',True): select_ptdins = ('not hydrogen and (resname %s and ' 'same residue as (resname %s and within %.1f of protein))'%( ptdins_resname,ptdins_resname,ptdins_cutoff)) view.select(near_pip2=select_ptdins,smooth=do_smooth,goodsell=True,style='licorice',update=True) #---loop over lipids for lipid_name,lipid_color in lipid_colors.items(): view.set_color_cursor(lipid_color) if cut_spec['lipid_style']=='phosphate_beads':
def render_lipid_pair(**kwargs): """ Abstracted the vmdmake routine for looping. """ global special_ion_color #---default settings hbond_style = ['dashed','cylinder'][-1] licorice_thick = 0.4 hbond_cylinder_radius = 0.15 goodsell_ions = False goodsell_lipids = True #---unpack the kwargs sn = kwargs.pop('sn') frame = kwargs.pop('frame') tempdir = kwargs.pop('tempdir') hydrogen_bonds = kwargs.pop('hydrogen_bonds',{}) pair = kwargs.pop('pair',{}) snapshot_fn = kwargs.pop('fn') associates = kwargs.pop('associates',None) lipid_color_specific = kwargs.pop('lipid_color_specific',None) if not pair: raise Exception('render_lipid_pair requires a pair') gro,xtc,tpr = [kwargs.pop(i) for i in 'gro xtc tpr'.split()] lipid_atoms = kwargs.pop('lipid_atoms',None) lipid_style = kwargs.pop('lipid_style',{}) show_water = kwargs.pop('show_water',False) lipid_colors = kwargs.pop('lipid_colors',False) if kwargs: raise Exception('unprocessed arguments: %s'%kwargs) #---run VMD to make the snapshots via vmdmake view = vmdmake.VMDWrap(site=tempdir,gro=gro,xtc=xtc,tpr=tpr, frames='',res=(4000,4000),**kwargs_vmdmake) view.do('load_dynamic','standard','bonder') view.command("animate goto %d"%(frame)) selections = [] #---change water oxygen color for show_water (starting with v15) view.command('color Name O pink') #---show both lipids sel1 = "(resname %s and resid %s) and not hydrogen"%(pair['resname_1'],pair['resid_1']) sel2 = "(resname %s and resid %s) and not hydrogen"%(pair['resname_2'],pair['resid_2']) if lipid_atoms is not None: sel1 = '(%s) and (%s)'%(sel1,' or '.join(['name %s'%i for i in lipid_atoms])) sel2 = '(%s) and (%s)'%(sel2,' or '.join(['name %s'%i for i in lipid_atoms])) selections.append(sel1) #---disallow the two lipid coloring schemes to work at the same time if lipid_color_specific and lipid_colors: raise Exception('incompatible arguments: lipid_color_specific and lipid_colors') if lipid_color_specific: view.set_color_cursor(lipid_color_specific) if lipid_colors: view.set_color_cursor(lipid_colors[pair['resname_1']]) view.select(**dictsum({'partner_1':selections[-1], 'style':'Licorice %.3f 12.000000 12.000000'%licorice_thick,'goodsell':goodsell_lipids},lipid_style, {'color_specific':True} if lipid_color_specific or lipid_colors else {})) selections.append(sel2) if lipid_colors: view.set_color_cursor(lipid_colors[pair['resname_2']]) view.select(**dictsum({'partner_2':selections[-1], 'style':'Licorice %.3f 12.000000 12.000000'%licorice_thick,'goodsell':goodsell_lipids},lipid_style, {'color_specific':True} if lipid_color_specific or lipid_colors else {})) #---show associates if associates: for assoc_num,assoc in enumerate(associates): if lipid_colors: view.set_color_cursor(lipid_colors[assoc['resname']]) selections.append("(resname %s and resid %s) and not hydrogen"%(assoc['resname'],assoc['resid'])) view.select(**dictsum({'assoc_%d'%assoc_num:selections[-1],'style': 'Licorice %.3f 12.000000 12.000000'%licorice_thick,'goodsell':goodsell_lipids}, {'color_specific':True} if lipid_color_specific or lipid_colors else {})) #---for each hydrogen bond, show the lipids with the hydrogen (both are plotted to include the bond) if lipid_color_specific: view.set_color_cursor(lipid_color_specific) this_style = dictsum({'style':'Licorice %.3f 12.000000 12.000000'%licorice_thick, 'goodsell':goodsell_lipids},lipid_style,{'color_specific':True} if lipid_color_specific else {}) for hnum,hbond in enumerate(hydrogen_bonds): #---the first residue in the pair is the donor and we draw it here selstring = "(resname %s and resid %s)"%(hbond['resname_1'],hbond['resid_1']) if lipid_atoms is not None: selstring = '(%s) and (%s)'%(selstring,' or '.join(['name %s'%i for i in lipid_atoms])) selections.append('(%s and not hydrogen) or (%s and name %s)'%(selstring,selstring,hbond['name_h'])) select_args = dict(**{'partner_1_hbond_%d'%hnum:selections[-1]}) select_args.update(**this_style) view.select(**select_args) #---also set the endpoints for the bond itself #---! currently set for heavy-heavy dashed line below #view.select(**{'partner_1_hbond_%d_ref'%hnum:'(%s and name %s)'%(selstring,hbond['name_h'])}) view.command('set partner_1_hbond_%d_ref [atomselect top "%s"]'%( hnum,'(%s and name %s)'%(selstring,hbond['name_1']))) #---draw the other lipid selstring = "(resname %s and resid %s)"%(hbond['resname_2'],hbond['resid_2']) if lipid_atoms is not None: selstring = '(%s) and (%s)'%(selstring,' or '.join(['name %s'%i for i in lipid_atoms])) selections.append('(%s and not hydrogen)'%selstring) select_args = dict(**{'partner_2_hbond_%d'%hnum:selections[-1]}) select_args.update(**this_style) view.select(**select_args) view.command('set partner_2_hbond_%d_ref [atomselect top "%s"]'%( hnum,'(%s and name %s)'%(selstring,hbond['name_2']))) #---set the selections #---! debugging this now view.command('set me [atomselect top "%s"]'%' or '.join(['(%s)'%i for i in selections[:2]])) #---removed the VMD HBonds call because it is too permissive (allows too many atom types) #---set selections for the vmd_render_good_side_bond method over a bond (or at least two points) #---we could use representative points like "C14" or "P" but the conformations are too dynamic for resid_ind in [1,2]: view.command("set %s [atomselect top \"(resname %s and resid %s and name %s)\"]"%( 'partner_%d_bead'%resid_ind,pair['resname_%d'%resid_ind], pair['resid_%d'%resid_ind],pair['name_%d'%resid_ind])) #---show the good side view.command(vmd_render_good_side_bond) #---see vmdmake.py for vmd colors cation = work.meta[sn].get('cation_relevant',work.meta[sn]['cation']) #---trying to fix color #---previously used the special_ion_color when show_water but reverting to original colors for v15 if lipid_colors or (show_water and False): view.set_color_cursor(special_ion_color) elif show_water: view.set_color_cursor({'MG':'red','Cal':'blue'}.get(cation,'purple')) else: view.set_color_cursor({'MG':'pink','Cal':'blue','NA':'green','K':'tan'}.get(cation,'purple')) #---show ions near both residues for resid_ind in [1,2]: view.select(**{'near_ions_%d'%resid_ind: "name %s and within 4.6 of (resname %s and resid %s)"%( cation,work.meta[sn]['ptdins_resname'],pair['resid_%d'%resid_ind]), 'smooth':False,'style':'VDW 0.4 12.0','goodsell':goodsell_ions,'color_specific':True}) #---option to show waters near the ions if show_water: if show_water.get('distance_color',False): for resid_ind in [1,2]: view.command('set pivots [atomselect top "[$near_ions_%d text]"]'%resid_ind) view.command(custom_water_coloring) #---deprecated method which passed the show water dictionary through to the view select elif show_water.get('deprecated_method',False): #---! this representation HAS MAJOR PROBLEMS. cg_bonds.tcl can be used to fix the extralong bonds #---! ...in PIP2 but it erases the bonds with water. we always just use the VDW representation #---! ...with large spheres. enormous amount of wasted time trying to fix this annoying bug. #---! ...need to get some kind of way of loading the TPR natively in VMD for resid_ind in [1,2]: view.select(**dictsum({'near_water_near_ions_%d'%resid_ind: "same residue as (water and within 3.0 of "+ "(name %s and within 4.6 of (resname %s and resid %s)))"%( cation,work.meta[sn]['ptdins_resname'],pair['resid_%d'%resid_ind]), 'smooth':False,'style':'licorice','goodsell':True},show_water)) #---note that version 8 used normal water coloring but the other colors were not quite right #---...while version 14 colored waters by distance but probably went out too far #---deprecated method elif show_water.get('hydration_shell',False): for resid_ind in [1,2]: view.select(**{'near_water_near_ions_%d'%resid_ind: "same residue as (water and within 3.05 of "+ "(name %s and within 4.6 of (resname %s and resid %s)))"%( cation,work.meta[sn]['ptdins_resname'],pair['resid_%d'%resid_ind]), 'smooth':False,'style':'licorice','goodsell':True}) else: raise Exception('no valid show_water methods') #---emphasize the hydrogen bonds for hnum,hbond in enumerate(hydrogen_bonds): if hbond_style=='cylinder': if not show_water: view.command('draw color black') #---changed cylinder from silver to cyan for v15 else: view.command('draw color iceblue') view.command(("draw cylinder [expr [$partner_1_hbond_%d_ref get {x y z}]] "+ "[expr [$partner_2_hbond_%d_ref get {x y z}]] radius %.3f")%( hnum,hnum,hbond_cylinder_radius)) elif hbond_style=='dashed': view.command(("draw line [expr [$partner_1_hbond_%d_ref get {x y z}]] "+ "[expr [$partner_2_hbond_%d_ref get {x y z}]] style dashed")%(hnum,hnum)) else: raise Exception('unclear hydrogen bond style %s'%hbond_style) #---render to disk view['snapshot_filename'] = snapshot_fn view.do('snapshot') view.show(quit=True)
gro,xtc = [os.path.join(work.postdir,'%s.%s'%(calc['extras'][sn]['slice_path'],suf)) for suf in ['gro','xtc']] #---get the tpr from the raw data tpr = work.raw.get_last(sn,subtype='tpr') #---precompute snapshot filenames and plot if any are missing snapshot_fns = [snapshot_namer(sn=work.raw.prefixer(sn_this),tag=tag,pos=pos) for (sn_this,pos),val in reps.items() if sn_this==sn] if any([not os.path.isfile(os.path.join(tempdir,i+'.png')) for i in snapshot_fns]): #---each render needs to start from the beginning because we move things around for the good side #---loop over desired lipid/frame pairs for rendering for key in [r for r in reps if r[0]==sn]: #---run VMD to make the snapshots via vmdmake view = vmdmake.VMDWrap(site=tempdir,gro=gro,xtc=xtc,tpr=tpr, frames='',res=(2000,2000),**kwargs_vmdmake) view.do('load_dynamic','standard','bonder') val = reps[key] frame,resid_rel,angle = [val[i] for i in ['frame','resid_rel','theta']] sn,pos = key view['snapshot_filename'] = snapshot_namer(sn=work.raw.prefixer(sn),pos=pos,tag=tag) view.command("set lipids_select [atomselect top \"resname %s\"]"% work.meta[sn]['ptdins_resname']) view.command("set my_index [lindex [lsort -unique [$lipids_select get resid]] %d]"% resid_rel) headsel = '(%s)'%' or '.join(['name %s'%i for i in work.vars['head_atoms'].split()]) view.select(**{'me':"resname %s and resid $my_index and not hydrogen and %s"%( work.meta[sn]['ptdins_resname'],headsel), 'smooth':False,'style':'licorice','goodsell':True}) view.command("animate goto %d"%frame)
} for key in ['ptdins', 'P35P', 'PIPP', 'PIPU', 'SAPI', 'PI2P']: lipid_colors[key] = 'magenta' cation_color = 'green' anion_color = 'gray' gro, xtc = [ os.path.join(work.postdir, '%s.%s' % (calc['extras'][sn]['slice_path'], suf)) for suf in ['gro', 'xtc'] ] #---get the tpr from the raw data tpr = work.raw.get_last(sn, subtype='tpr') view = vmdmake.VMDWrap(site=work.paths['post_plot_spot'], gro=gro, xtc=xtc, tpr=tpr, frames='', res=(4000, 4000)) view['snapshot_filename'] = vmd_fn view.do('load_dynamic', 'standard', 'bonder') view.command("animate goto %d" % (frame)) resname = work.meta[sn]['ptdins_resname'] select = {'ptdins': 'resname %s and not hydrogen' % resname} if do_ptdins_color: view.set_color_cursor(lipid_colors[resname]) view.select(**dictsum(select, lipid_style, {'color_specific': True})) else: view.select(**dictsum(select, lipid_style)) #---show other lipids in their respective colors for resname in [ i for i in lipid_colors