{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Rendering structure with povray\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nfrom ase import Atoms\nfrom ase.io import write\nfrom ase.utils import hsv" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "atoms = Atoms('Ag', cell=(2.7, 2.7, 2.7), pbc=True) * (18, 8, 8)\n\nrotation = '-70x, -20y, -2z' # found using ASE-GUI menu 'view -> rotate'\n\n# Make colors\ncolors = hsv(atoms.positions[:, 0])\n\n# Textures\ntex = ['jmol'] * 288 + ['glass'] * 288 + ['ase3'] * 288 + ['vmd'] * 288\n\n\n# Keywords that exist for eps, png, and povs\ngeneric_projection_settings = {\n 'rotation': rotation,\n 'colors': colors,\n 'radii': None,\n}\n\npovray_settings = { # For povray files only\n 'display': False, # Display while rendering\n 'pause': False, # Pause when done rendering (only if display)\n 'transparent': False, # Transparent background\n 'canvas_width': None, # Width of canvas in pixels\n 'canvas_height': None, # Height of canvas in pixels\n 'camera_dist': 50.0, # Distance from camera to front atom\n 'image_plane': None, # Distance from front atom to image plane\n # (focal depth for perspective)\n 'camera_type': 'perspective', # perspective, ultra_wide_angle\n 'point_lights': [], # [[loc1, color1], [loc2, color2],...]\n 'area_light': [\n (2.0, 3.0, 40.0), # location\n 'White', # color\n 0.7,\n 0.7,\n 3,\n 3,\n ], # width, height, Nlamps_x, Nlamps_y\n 'background': 'White', # color\n 'textures': tex, # Length of atoms list of texture names\n 'celllinewidth': 0.05, # Radius of the cylinders representing the cell\n}\n\n# Make flat png file\n# write('flat.png', atoms, **kwargs)\n\n# Make the color of the glass beads semi-transparent\ncolors2 = np.zeros((1152, 4))\ncolors2[:, :3] = colors\ncolors2[288:576, 3] = 0.95\ngeneric_projection_settings['colors'] = colors2\n\n# Make the raytraced image\n# first write the configuration files, then call the external povray executable\nrenderer = write(\n 'nice.pov',\n atoms,\n **generic_projection_settings,\n povray_settings=povray_settings,\n)\nrenderer.render()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.5" } }, "nbformat": 4, "nbformat_minor": 0 }