File: povray_isosurface_tutorial.py

package info (click to toggle)
python-ase 3.26.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (104 lines) | stat: -rw-r--r-- 2,962 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from ase.calculators.vasp import VaspChargeDensity
from ase.io import write

spin_cut_off = 0.4
density_cut_off = 0.15

rotation = '24x, 34y, 14z'
# rotation = '0x, 0y, 0z'


vchg = VaspChargeDensity('CHGCAR')
atoms = vchg.atoms[0]

povray_settings = {
    # For povray files only
    'pause': False,  # Pause when done rendering (only if display)
    'transparent': False,  # Transparent background
    'canvas_width': None,  # Width of canvas in pixels
    'canvas_height': 1024,  # Height of canvas in pixels
    'camera_dist': 25.0,  # Distance from camera to front atom
    'camera_type': 'orthographic angle 35',  # 'perspective angle 20'
    'textures': len(atoms) * ['ase3'],
}

# some more options:
# 'image_plane'  : None,  # Distance from front atom to image plane
#                         # (focal depth for perspective)
# 'camera_type'  : 'perspective', # perspective, ultra_wide_angle
# 'point_lights' : [],             # [[loc1, color1], [loc2, color2],...]
# 'area_light'   : [(2., 3., 40.) ,# location
#                   'White',       # color
#                   .7, .7, 3, 3], # width, height, Nlamps_x, Nlamps_y
# 'background'   : 'White',        # color
# 'textures'     : tex, # Length of atoms list of texture names
# 'celllinewidth': 0.05, # Radius of the cylinders representing the cell


generic_projection_settings = {
    'rotation': rotation,
    'radii': atoms.positions.shape[0] * [0.3],
    'show_unit_cell': 1,
}

# write returns a renderer object which needs to have the render method called

write(
    'NiO_marching_cubes1.pov',
    atoms,
    **generic_projection_settings,
    povray_settings=povray_settings,
    isosurface_data=dict(density_grid=vchg.chgdiff[0], cut_off=density_cut_off),
).render()

# spin up density, how to specify color and transparency r,g,b,t and a
# material style from the standard ASE set


write(
    'NiO_marching_cubes2.pov',
    atoms,
    **generic_projection_settings,
    povray_settings=povray_settings,
    isosurface_data=dict(
        density_grid=vchg.chgdiff[0],
        cut_off=density_cut_off,
        closed_edges=True,
        color=[0.25, 0.25, 0.80, 0.1],
        material='simple',
    ),
).render()

# spin down density, how to specify a povray material
# that looks like pink jelly
fun_material = """
  material {
    texture {
      pigment { rgbt < 0.8, 0.25, 0.25, 0.5> }
      finish{ diffuse 0.85 ambient 0.99 brilliance 3 specular 0.5 \
roughness 0.001
        reflection { 0.05, 0.98 fresnel on exponent 1.5 }
        conserve_energy
      }
    }
    interior { ior 1.3 }
  }
  photons {
      target
      refraction on
      reflection on
      collect on
  }"""

write(
    'NiO_marching_cubes3.pov',
    atoms,
    **generic_projection_settings,
    povray_settings=povray_settings,
    isosurface_data=dict(
        density_grid=vchg.chgdiff[0],
        cut_off=-spin_cut_off,
        gradient_ascending=True,
        material=fun_material,
    ),
).render()