Electrostatics

Colour a molecular surface by an electrostatic potential from APBS.

APBS solves the Poisson-Boltzmann equation for a molecule in solvent and writes the electrostatic potential on a grid, usually as a .dx file. Its values are in kT/e: thermal energy per elementary charge, about 25.7 mV at 25 °C.

This example uses the potential of one barnase-barstar pair from 1BRS (barnase chain A, barstar chain D), made with pdb2pqr and APBS by docs/dev/apbs_1brs.py. Barnase is positively charged and barstar negatively charged.

import molecularnodes as mn
from molecularnodes.nodes import geometry as mg

canvas = mn.Canvas()
/home/brady/actions-runner/_work/MolecularNodes/MolecularNodes/molecularnodes/nodes/_utils.py:4: FutureWarning: `databpy.nodes` is deprecated and will be removed in databpy 0.14.0. Node groups are handled by nodebpy (https://pypi.org/project/nodebpy/).
  from databpy.nodes import append_from_blend, get_output, swap_tree

Load the potential

Load the grid as a density and show it with Density Style ISO Surface, which meshes the potential at +1 kT/e (blue) and -1 kT/e (red).

esp = mn.entities.density.Grids.load("../../tests/data/1brs_AD_apbs.dx.gz")

with esp.tree.reset() as (volume, join):
    (
        volume
        >> mg.DensityStyleISOSurface(
            threshold=1.0,
            positive=(0.1, 0.3, 1.0, 1.0),
            negative=(1.0, 0.1, 0.1, 1.0),
            material=mn.material.Transparent(
                transparency=0.7, fresnel=True, outline_color=(0.85, 0.85, 0.85, 1.0)
            ).material,
        )
        >> join
    )

Colour the surface

Passing the density as color samples the potential at every vertex of the surface, from -5 kT/e (red) to 5 kT/e (blue). The density’s Import Volume node keeps the grid in the bundle of its output, and density styles pass it on to the mesh they make, so it can be sampled while the density shows its own style. The coordinates of 1BRS line up with the grid because pdb2pqr keeps the input coordinates.

mol = mn.Molecule.fetch("1BRS")
mol.add_style("surface", selection="chainID A D", color=esp)
<Molecule, `universe`: <Universe with 5151 atoms>, `object`: <bpy_struct, Object("1BRS") at 0x1ccf8168>
canvas.look_at(esp, viewpoint=(106.5, 0.0, -37.7))
canvas.snapshot()

Hide the potential’s own style to see only the coloured surface. Barnase (left) is mostly positive and barstar (right) mostly negative.

esp.object.hide_render = True
canvas.look_at(mol, viewpoint=(106.5, 0.0, -37.7))
canvas.snapshot()

The colour range is set on the Color Sample Grid node in the molecule’s tree, through its Min and Max inputs.