Visualizing Electron Density

Problem

You want to visualize how a ligand fits into an electron density grid in a 2D molecule diagram (see Figure 1). The electron density grid with various contour levels and the 3D molecule is shown in Table 1.

../_images/elecdensity2img-1eta.png

Figure 1. Example of visualizing ligand electron density fit (PDB: 1ETS)

Table 1. Example of ligand electron density fit at various contour levels (1ETS)

contour 1.0

contour 1.5

contour 2.0

../_images/1eta_screenshot_contour_1_0_small.png ../_images/1eta_screenshot_contour_1_5_small.png ../_images/1eta_screenshot_contour_2_0_small.png

Ingredients

Difficulty Level

../_images/chilly.png ../_images/chilly.png ../_images/chilly.png

Download

Download code

elecdensity2img.py

See also the Usage subsection.

Solution

The set_electron_density_contour_overlap function tags an atom if its coordinates inside the grid at the given contour level.

 1def set_electron_density_contour_overlap(mol, edgrid, contour, contour_tag):
 2    """
 3    Sets whether atoms are inside the electron density grid at the given
 4    contour level.
 5
 6    :type mol: oechem.OEMolBase
 7    :type edgrid: oegrid.OESkewGrid
 8    :type contour: float
 9    :type: contour_tag: int
10    """
11
12    center = oechem.OEFloatArray(3)
13    extents = oechem.OEFloatArray(3)
14    oechem.OEGetCenterAndExtents(mol, center, extents)
15
16    subgrid = oegrid.OEScalarGrid()
17
18    # expand the grid a bit for proper overlaps
19
20    extents[0] += 2.5
21    extents[1] += 2.5
22    extents[2] += 2.5
23    oegrid.OEMakeRegularSubGrid(subgrid, edgrid, center, extents, 0.5, edgrid.GetReentrant() >= 7)
24
25    for atom in mol.GetAtoms(oechem.OEIsHeavy()):
26        xyz = mol.GetCoords(atom)
27        val = subgrid.GetValue(xyz[0], xyz[1], xyz[2])
28        if val > contour:
29            atom.SetData(contour_tag, val)

The depict_erlectron_density_fit function shows how to project the electron density fit with various contour levels into a 2D molecule diagram. First the image is divided into two image frames since both a molecule and a color gradient will be depicted. Then the set_electron_density_contour_overlap function is called that calculates whether the atoms of the molecule are inside the electron density grid at various contour levels (see lines 21-23). The molecule is then prepared for depiction generating its 2D coordinates by calling the OEPrepareDepictionFrom3D function (lines 27-32). After constructing a color gradient that will assign colors to various contour levels, the function loops over the atoms and draws a circle around them if they are embedded into the electron density grid (> 0.2) with a color and radius that corresponds to the given contour level (lines 42-51). Finally, the molecule along with the color gradient is rendered to the image (lines 55-62). You can see the result in Figure 1.

 1def depict_electron_density_fit(image, mol, edgrid, opts):
 2    """
 3    Depicts the molecule with electron density fit.
 4
 5    :type image: oedepict.OEImageBase
 6    :type mol: oechem.OEMolBase
 7    :type edgrid: oegrid.OESkewGrid
 8    :type opts: oedepict.OE2DMolDisplayOptions
 9    """
10
11    # generate image frames
12
13    width, height = image.GetWidth(), image.GetHeight()
14    mframe = oedepict.OEImageFrame(image, width, height * 0.90,
15                                   oedepict.OE2DPoint(0.0, 0.0))
16    lframe = oedepict.OEImageFrame(image, width, height * 0.10,
17                                   oedepict.OE2DPoint(0.0, height * 0.90))
18
19    # calculate fit to electron density at various contours
20
21    contours = [1.0, 1.5, 2.0]
22    for contour in contours:
23        set_electron_density_contour_overlap(mol, edgrid, contour, get_contour_tag(contour))
24
25    # prepare molecule for depiction
26
27    width, height = mframe.GetWidth(), mframe.GetHeight()
28    opts.SetDimensions(width, height, oedepict.OEScale_AutoScale)
29
30    oegrapheme.OEPrepareDepictionFrom3D(mol)
31    opts.SetScale(oedepict.OEGetMoleculeScale(mol, opts) * 0.95)
32    disp = oedepict.OE2DMolDisplay(mol, opts)
33
34    # create color gradient
35
36    colorg = oechem.OELinearColorGradient()
37    colorg.AddStop(oechem.OEColorStop(min(contours), oechem.OEColor(190, 190, 255)))  # light blue
38    colorg.AddStop(oechem.OEColorStop(max(contours), oechem.OEColor(80, 80, 255)))  # medium blue
39
40    # visualize electron density fit
41
42    layer = disp.GetLayer(oedepict.OELayerPosition_Below)
43    for contour in contours:
44        contour_tag = get_contour_tag(contour)
45        radius = get_contour_radius(contour, contours, disp)
46        color = colorg.GetColorAt(contour)
47        pen = oedepict.OEPen(color, color, oedepict.OEFill_On, 1.0)
48        for atom in mol.GetAtoms():
49            if atom.HasData(contour_tag):
50                adisp = disp.GetAtomDisplay(atom)
51                layer.DrawCircle(adisp.GetCoords(), radius, pen)
52
53    # render molecule
54
55    oedepict.OERenderMolecule(mframe, disp)
56
57    # draw color gradient
58
59    copts = oegrapheme.OEColorGradientDisplayOptions()
60    copts.SetColorStopPrecision(1)
61    copts.AddMarkedValues(contours)
62    oegrapheme.OEDrawColorGradient(lframe, colorg, copts)

Usage

Usage

elecdensity2img.py and supporting data 1eta_sigma.mtz and 1eta_ligand.pdb

prompt > python3 elecdensity2img.py -grid 1eta.mtz -ligand 1eta_ligand.sdf -out 1eta.png

Command Line Parameters

Simple parameter list
    -height : Height of output image
    -width : Width of output image

    molecule display options :
      -titleloc : Location of the molecule title

    input/output options
      -ligand : Input filename of the ligand
      -grid : Input filename of electron density map (MTZ)
      -out : Output filename of the generated image

Discussion

Visualizing electron density helps to evaluate the quality of protein-ligand structures. The Iridium database divides the protein-ligand structures into three categories:

  • Iridium-NT (not trustworthy)

  • Iridium-MT (moderately trustworthy)

  • Iridium-HT (highly trustworthy)

Not surprisingly the 1ETS complex (Figure 1 is considered “not trustworthy” by the Iridium database. The Table 2 shows examples from the MT and HT categories of the Iridium database

Table 2. Examples from the Iridium database

1COY - Iridium MT

1D3H - Iridium HT

../_images/elecdensity2img-1coy.png ../_images/elecdensity2img-1d3h.png

The visualization also helps to compare the “deposited” starting models of the Iridium database with the models that are refined by AFITT. See example in Table 3.

Table 3. Examples from the Iridium database

deposited starting model

model after AFITT refinement

../_images/elecdensity2img-1cx2-start.png ../_images/elecdensity2img-1cx2-refined.png

Command Line Parameters

Simple parameter list
    input/output options
      -complex : Input filename of the protein-ligand complex
      -out : Output filename of the generated image

    residue options
      -ignore-isolated : Removes isolated atoms prior to depiction
      -ignore-water : Removes water molecule prior to depiction
      -max-residues : Controls the maximum number of residues depicted in each
                      line

See also in OEChem TK manual

API

Theory

See also in OEDepict TK manual

Theory

API

See also in GraphemeTM TK manual

API

See also