Materials

We can progrommatically access the properties of the materials like this:

import molecularnodes as mn
cv = mn.Canvas(engine="EEVEE", resolution=(800, 800), transparent=True)
mol = mn.Molecule.fetch("8H1B").add_style(
    mn.StyleSurface(), material=mn.material.AmbientOcclusion()
)
cv.frame_object(mol)
cv.snapshot()

mol.styles[0].material.ambient_occlusion_distance = 0.1
cv.snapshot()
(a) Default settings
(b) Reduce AO probe distance
Figure 1: A simple Ambient Occlusion material that is performant and aesthetically pleasing. Material properties can be changed through the material interface.
mol.styles[0].material = mn.material.FlatOutline()
cv.snapshot()

mol.styles[0].material.math_value = 0.1
cv.snapshot()
(a)
(b)
Figure 2

Propeties for the material interface are based on the inputs of the nodes in the material.

[x for x in dir(mn.material.AmbientOcclusion()) if not x.startswith("_")]
['ambient_occlusion_color',
 'ambient_occlusion_distance',
 'ambient_occlusion_normal',
 'emission_color',
 'emission_strength',
 'material',
 'math_value',
 'mix_a',
 'mix_b',
 'mix_factor',
 'tree']

Render Engines and Materials

The different render engines handle materials diferently.

import MDAnalysis as mda
import itertools
from MDAnalysis.tests.datafiles import PSF, DCD

cv = mn.Canvas(resolution=(800, 800), transparent=True)
u = mda.Universe(PSF, DCD)
traj = mn.Trajectory(u)
traj.add_style(mn.StyleSpheres(geometry="Mesh", subdivisions=4))

cv.frame_view(traj)
engines = [mn.scene.Cycles(samples=32), mn.scene.EEVEE()]
materials = [
    mn.material.Default(),
    mn.material.AmbientOcclusion(),
    mn.material.FlatOutline(),
    mn.material.Squishy(),
]
for mat, eng in itertools.product(materials, engines):
    cv.engine = eng
    traj.styles[0].material = mat
    cv.snapshot()
(a) Cycles + Default
(b) EEVEE + Default
(c) Cycles + Ambient Occlusion
(d) EEVEE + Ambient Occlusion
(e) Cycles + Flat Outline
(f) EEVEE + Flat Outline
(g) Cycles + Squishy
(h) EEVEE + Squishy
Figure 3: How different materials behave in each render engine