{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Fine tuning POV-Ray settings for high quality images\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# This script creates pictures of sample structures, the cut sqs cell will keep\n# the same crystallographic orientation in the image as the unit cell\nfrom ase import build\nfrom ase.data import covalent_radii\nfrom ase.data.colors import jmol_colors as chemical_colors\nfrom ase.io.pov import get_bondpairs, write_pov\n\nunit_cell = build.bulk('AlN', 'wurtzite', a=3.129, c=5.017)\nsqs_cell = build.cut(unit_cell, a=[1, 0, 1], b=[-2, -2, 0], c=[1, -1, -1])\nnames = ['unit_cell', 'sqs_cell']\nlist_of_atoms_obj = [unit_cell, sqs_cell]\n\n# The rest are rendering settings\n# see the gallery to see examples of the built-in styles\nstyle = 'simple'\n# reverts to jmol_colors if not unspecified\ncolor_dict_rgb255 = {'N': [23, 111, 208], 'Ga': [230, 83, 17]}\n\n# used to automatically guess bonds\ncovalent_radius_bond_cutoff_scale = 0.9\n\n# for the rendering atom radii\nradius_dict = {\n 'O': 0.8,\n 'Al': 0.6,\n}\n# for unspecified elements\nradius_scale = 0.6\n\n# use ASE GUI to find your perfect orientation\n# rotation = '45x, -35.264y, 30z' # down <111> for a cubic structure\n# rotation = '0x, 0y, 0z' # down z-axis\nrotation = '37x, -79y, -128z'\n\n# povray specific kwrds\nkwargs = {\n 'transparent': True, # Transparent background\n 'canvas_width': None, # Width of canvas in pixels\n 'canvas_height': 720, # Height of canvas in pixels\n # 'image_height' : 22,\n # 'image_width' : 102, # I think these are in atomic units\n # 'image_plane' : None, # Distance from front atom to image plane\n # # (focal depth for perspective)\n # 'camera_dist' : 170.0, # Distance from camera to front atom,\n # 'camera_type': 'orthographic angle 35', # 'perspective angle 20',\n # ultra_wide_angle\n # 'area_light' : [(2., 3., 40.) ,# location\n # 'White', # color\n # .7, .7, 3, 3], # width, height, Nlamps_x, Nlamps_y\n # 'point_lights' : [], # [[loc1, color1], [loc2, color2],...]\n # 'background' : 'White', # color\n 'depth_cueing': False,\n 'celllinewidth': 0.01, # Radius of the cylinders representing the cell\n}\n\n# generic projection settings (passed to plotting variables)\ngeneric_projection_settings = {\n 'rotation': rotation,\n 'show_unit_cell': 2,\n # 'extra_offset':(2.0, 0.0)\n}\n\n# some nice helper functions\n\n\ndef make_radius_list(atoms, radius_dict, radius_scale=0.9):\n per_atom_list = []\n for z, symbol in zip(atoms.get_atomic_numbers(), atoms.symbols):\n if symbol in radius_dict.keys():\n per_atom_list.append(radius_dict[symbol])\n else:\n per_atom_list.append(radius_scale * covalent_radii[z])\n return per_atom_list\n\n\ndef make_color_list(atoms, color_dict):\n per_atom_list = []\n for z, symbol in zip(atoms.get_atomic_numbers(), atoms.symbols):\n if symbol in color_dict.keys():\n per_atom_list.append(color_dict[symbol])\n else:\n per_atom_list.append(chemical_colors[z])\n return per_atom_list\n\n\n# converting RGB255 to RGB1 for povray.\ncolor_dict = {}\nfor symbol in color_dict_rgb255:\n color_dict[symbol] = [val / 255.0 for val in color_dict_rgb255[symbol]]\n\n# loop over atoms objects to render them\nfor atoms, name in zip(list_of_atoms_obj, names):\n radius_list = make_radius_list(\n atoms, radius_dict, radius_scale=radius_scale\n )\n bondpairs = get_bondpairs(atoms, radius=covalent_radius_bond_cutoff_scale)\n color_list = make_color_list(atoms, color_dict)\n\n # These have to be set per-atom\n kwargs['textures'] = len(atoms) * [style]\n kwargs['colors'] = color_list\n kwargs['bondatoms'] = bondpairs\n\n # PlottingVariables needs the radii to set the image plane size\n generic_projection_settings['radii'] = radius_list\n\n pov_name = name + '.pov'\n povobj = write_pov(\n pov_name, atoms, **generic_projection_settings, povray_settings=kwargs\n )\n povobj.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.13.7" } }, "nbformat": 4, "nbformat_minor": 0 }