Depicting Property Maps¶
The previous chapters give examples about how to depict atom properties either by using glyphs (see Annotating Atoms and Bonds chapter) or projecting them into a 2D molecule surface (see Drawing a Molecule Surface chapter). Grapheme TK can also map atom properties into a 2D grid, called a property map, using a Gaussian function. After the grid is generated, colors are rendered to each cell using the OELinearColorGradient class that interpolates colors between a specified range.
The following Listing 1
example
demonstrates how to depict partial charges using the property map.
After constructing the molecule and preparing it for depiction, the MMFF
partial charges are calculated.
These partial charges are attached to the corresponding atom as
generic data with a specific tagname.
A OE2DPropMap object is then generated by
specifying three colors:
the background color of the property map
one that represents negative values (in this case charges), and
the color that represents positive values in the property map
When the OE2DPropMap.Render
method is called
with the tagname, the properties that were attached to the atoms as
generic data are retrieved and a 2D grid is generated along with an
OELinearColorGradient
object that is used to assign colors to the cells of the grid.
The colored grid is then rendered into the below layer of the
OE2DMolDisplay object, i.e., it appears underneath
the molecular diagram.
The image created by Listing 1
is
shown in Figure: Example of depicting a property map.
Listing 1: Depicting partial charges using property map
public class Draw2DPropMapPartialCharge
{
public static void setPartialCharge(OEMolBase mol, string tagname)
{
OEChem.OEMMFFAtomTypes(mol);
OEChem.OEMMFF94PartialCharges(mol);
uint tag = OEChem.OEGetTag(tagname);
foreach (OEAtomBase ai in mol.GetAtoms())
{
ai.SetDoubleData(tag, ai.GetPartialCharge());
}
}
public static int Main(string[] args)
{
OEGraphMol mol = new OEGraphMol();
OEChem.OESmilesToMol(mol, "Cc1cc(cc(c1[N+](=O)[O-])F)[N+]#C");
OEDepict.OEPrepareDepiction(mol);
string tagname = "PartialCharge";
setPartialCharge(mol, tagname);
OEDepict.OEPrepareDepiction(mol);
uint width = 450;
uint height = 350;
OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
opts.SetAtomColorStyle(OEAtomColorStyle.WhiteMonochrome);
opts.SetTitleLocation(OETitleLocation.Hidden);
opts.SetScale(OEGrapheme.OEGetMoleculeSurfaceScale(mol, opts));
OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);
OE2DPropMap propmap = new OE2DPropMap(opts.GetBackgroundColor());
propmap.SetNegativeColor(OEChem.OEDarkRed);
propmap.SetPositiveColor(OEChem.OEDarkBlue);
propmap.Render(disp, tagname);
OEDepict.OERenderMolecule("Draw2DPropMapPartialCharge.png", disp);
return 0;
}
}
See also
Generic Data chapter in the OEChem TK manual.
When the OE2DPropMap.Render
method is called,
the color gradient is initialized by searching for the minimum and
maximum values by the given tagname.
This means that when more than one molecule is depicted,
each depiction will have its own independent value range.
(See Figure: Example of depicting a property map).
In the Listing 2
example,
the value range of the property map is pre-set by identifying the minimum
and maximum atom partial charges for a whole molecule set.
See the result in
Figure: Example of depicting property maps in the same value range.
Each black box around the color gradient legend indicates the
range of the atom partial charges for the corresponding molecule.
Listing 2: Depicting multiple molecules using property map
public class Draw2DPropMapPChargeMulti
{
public static void setPartialCharge(OEMolBase mol, string tagname,
ref double minvalue, ref double maxvalue)
{
OEChem.OEMMFFAtomTypes(mol);
OEChem.OEMMFF94PartialCharges(mol);
uint tag = OEChem.OEGetTag(tagname);
foreach (OEAtomBase ai in mol.GetAtoms())
{
double charge = ai.GetPartialCharge();
ai.SetDoubleData(tag, charge);
minvalue = Math.Min(minvalue, charge);
maxvalue = Math.Max(maxvalue, charge);
}
}
public static int Main(string[] args)
{
List<string> smiles = new List<string>();
smiles.Add("c1ccnc(c1)[N+](=O)[O-]");
smiles.Add("c1ccccc1F");
smiles.Add("c1ccc(cc1)S(=O)(=O)[O-]");
double minvalue = double.MaxValue;
double maxvalue = double.MinValue;
string tagname = "PartialCharge";
List<OEGraphMol> molecules = new List<OEGraphMol>();
foreach (string s in smiles)
{
OEGraphMol mol = new OEGraphMol();
OEChem.OESmilesToMol(mol, s);
OEDepict.OEPrepareDepiction(mol);
setPartialCharge(mol, tagname, ref minvalue, ref maxvalue);
molecules.Add(mol);
}
uint width = 750;
uint height = 250;
OEImage image = new OEImage(width, height);
uint rows = 1;
uint cols = 3;
OEImageGrid grid = new OEImageGrid(image, rows, cols);
OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(grid.GetCellWidth(),
grid.GetCellHeight(),
OEScale.Default);
opts.SetAtomColorStyle(OEAtomColorStyle.WhiteMonochrome);
opts.SetTitleLocation(OETitleLocation.Hidden);
OE2DPropMap propmap = new OE2DPropMap(opts.GetBackgroundColor());
propmap.SetNegativeColor(OEChem.OEDarkRed);
propmap.SetPositiveColor(OEChem.OEDarkBlue);
propmap.SetLegendLocation(OELegendLocation.Left);
propmap.SetMinValue(minvalue);
propmap.SetMaxValue(maxvalue);
OEImageBaseIter ci = grid.GetCells();
foreach (OEGraphMol m in molecules)
{
OE2DMolDisplay disp = new OE2DMolDisplay(m, opts);
propmap.Render(disp, tagname);
OEDepict.OERenderMolecule(ci.Target(), disp);
ci.Increment();
}
OEDepict.OEWriteImage("Draw2DPropMapPartialChargeMulti.png", image);
return 0;
}
}
See also
OEImageGrid class in the OEDepict TK manual
The above examples show how to project atom properties (such as partial charges)
into the property map.
However, the OE2DPropMap class can also be used to visualize
bond properties by attaching a value to each bond as a generic data using a tagname.
When the OE2DPropMap.Render
method is called
with the same tagname, the property that was attached to a bond is retrieved and
projected at the middle of that bond before applying a Gaussian function to blur
out the 2D grid underneath the molecular graph.
The Table: Depicting atom or/and bond properties
table shows the differences between visualizing atom or/and bond properties using the
OE2DPropMap class.
only atom |
both atom and bond |
only bond |