def Render(Frac, Bead, Dens): data = import_file('./../frac_' + str(Frac) + '/m_' + str(Bead) + '/d_' + str(Dens) + '/final_snapshot.xyz') data.add_to_scene() vis_element = data.source.data.particles.vis vis_element.radius = .9 cell_vis = data.source.data.cell.vis cell_vis.render_cell = False vp = Viewport(type=Viewport.Type.Bottom) vp.zoom_all(size=(600, 500)) image = vp.render_image(size=(600, 500), alpha=True) image.save("f-" + str(int((1 - Frac) * 10 % 10)) + "/b-" + str(Bead) + "_d-" + str(Dens) + ".png") data.remove_from_scene()
def Render1(item, Renderer, selector0, delector): pipeline = import_file('./../frac_' + str(item[0]) + '/m_' + str(item[1]) + '/d_' + str(item[2]) + '/final_snapshot.xyz') pipeline.modifiers.append(selector0) pipeline.modifiers.append(delector) pipeline.add_to_scene() vis_element = pipeline.source.data.particles.vis vis_element.radius = .5 cell_vis = pipeline.source.data.cell.vis cell_vis.render_cell = False vp = Viewport(type=Viewport.Type.Left) vp.zoom_all(size=(600, 500)) image = vp.render_image(size=(600, 500), alpha=True, renderer=Renderer) image.save("f-" + str(int((1 - item[0]) * 10 % 10)) + "/rand/b-" + str(item[1]) + "_d-" + str(item[2]) + "(phobic).png") pipeline.remove_from_scene()
def show_ovito(particle, cell, outfile=None, radius=0.35, viewport=None, callback=None, tmpdir=None, camera_dir=(0, 1, 0), camera_pos=(0, -10, 0), size=(640, 480), zoom=True, perspective=False): """ Render particle in cell using ovito """ import os try: from ovito.io import import_file except ImportError: _log.warning('install ovito to display the particles') return from ovito.vis import Viewport, TachyonRenderer from ovito.vis import ParticlesVis import tempfile from atooms.core.utils import mkdir # Make sure dirname exists if outfile is not None: mkdir(os.path.dirname(outfile)) # Get a temporary file to write the sample fh = tempfile.NamedTemporaryFile('w', dir=tmpdir, suffix='.xyz', delete=False) tmp_file = fh.name # Self-contained EXYZ dump (it is not clean to use trajectories here) fh.write('{}\n'.format(len(particle))) fh.write( 'Properties=species:S:1:pos:R:3 Lattice="{},0.,0.,0.,{},0.,0.,0.,{}"\n' .format(*cell.side)) for p in particle: fh.write('{} {} {} {}\n'.format(p.species, *p.position)) fh.close() # Ovito stuff. Can be customized by client code. pipeline = import_file(tmp_file) # Ovito seems to ignore the lattice info of exyz file # so we forcibly set the cell info here pipeline.source.data.cell_[0, 0] = cell.side[0] pipeline.source.data.cell_[1, 1] = cell.side[1] pipeline.source.data.cell_[2, 2] = cell.side[2] pipeline.source.data.cell_[:, 3] = -cell.side / 2 # Scale radius by default vis_element = pipeline.source.data.particles.vis vis_element.radius = radius # Apply client code callback if callback: callback(pipeline) pipeline.add_to_scene() # Define viewport if viewport: vp = vieport else: if perspective: vp = Viewport(type=Viewport.Type.Perspective, camera_dir=camera_dir, camera_pos=camera_pos) else: vp = Viewport(type=Viewport.Type.Ortho, camera_dir=camera_dir, camera_pos=camera_pos) # Render if zoom: vp.zoom_all() if outfile is None: outfile = tmp_file + '.png' vp.render_image(filename=outfile, size=size, renderer=TachyonRenderer()) # Scene is a singleton, so we must clear it pipeline.remove_from_scene() from atooms.core.utils import rmf rmf(tmp_file) # Try to display the image (e.g. in a jupyter notebook) try: from IPython.display import Image return Image(outfile) except ImportError: return outfile
def ovito_view(sample_path, filename, view="Perspective"): """ Use the package ovito to make visualizaitons of molecules. Parameters ---------- sample_path : str The path of the file to visualize filename : str The name of the output file image view : str (optional) The view to use """ if use_ovito: # Import the sample file. pipeline = import_file(sample_path) pipeline.source.data.cell.vis.enabled = False pipeline.source.data.particles.vis.radius = 0.5 pipeline.add_to_scene() vp = Viewport() if view == "Perspective": vp.type = Viewport.Type.Perspective vp.camera_dir = (-1, -1, -1) elif view == "Ortho": vp.type = Viewport.Type.Ortho vp.camera_dir = (-1, -1, -1) elif view == "Top": vp.type = Viewport.Type.Top elif view == "Bottom": vp.type = Viewport.Type.Bottom elif view == "Front": vp.type = Viewport.Type.Front elif view == "Back": vp.type = Viewport.Type.Back elif view == "Left": vp.type = Viewport.Type.Left elif view == "Right": vp.type = Viewport.Type.Right vp.zoom_all() vp.render_image(size=(800, 600), filename=filename, background=(0, 0, 0), frame=0) pipeline.remove_from_scene() else: print( "Cannot use function ovito_view - the package ovito is not installed or cannot be found." )