Molecule Alignment¶
The following three code examples demonstrate how to align molecules either based on:
maximum common substructure (
Listing 1
),substructure matches (
Listing 2
), ormolecular similarity (
Listing 3
).
Molecule Alignment Based on MCS¶
The Figure: Example of depiction without alignment is generated by highlighting the maximum common substructure of two molecules (MCS), but keeping the original orientation of the compounds.
The Listing 1
code example shows how to align these
two molecules by their maximum common substructures (i.e. by the
highlighted atoms and bonds in
Figure: Example of depiction without alignment).
First, two molecules are initialized from SMILES string and prepared for depiction.
A OEMCSSearch object is initialized with the reference 2D molecule onto which the fit molecule will be aligned.
An OEImageGrid object is constructed that allows to render the two molecules in a grid next to each other.
The fit molecule is then aligned to the reference by calling the
OEPrepareAlignedDepiction
function that performs MCS search and then aligns the fit molecule to the reference based on the detected common substructure(s).An OE2DMolDisplayOptions object is initialized that stores the properties determine how the molecules are rendered. In order to render the molecules in equal size the smallest depiction scaling factor is calculated.
If the molecule alignment was successful (i.e
OEAlignmentResult.IsValid
is true), then the correspondence between the two molecules stored in the OEAlignmentResult returned by theOEPrepareAlignedDepiction
function. This OEAlignmentResult object can be used to highlight the matched common substructure by invoking theOEAddHighlighting
function.After both molecules are rendered into the separate cells of the grid layout, the image is written into a
png
file.
After initializing the two molecules and the OEMCSSearch object,
the OEMCSSearch.Match
method is called to perform the
search and return an iterator over the identified maximum common
substructures.
The first match is then utilized to call the
OEPrepareAlignedDepiction
function that aligns one molecule
to the other based on the given match.
After the alignment, the common atoms and bonds are highlighted by
invoking the OEAddHighlighting
function.
The image created by Listing 1
is shown in
Figure: Example of depiction with alignment based on MCS.
Listing 1: Example of molecule alignment based on MCS
public class MCSAlign
{
public static int Main(string[] argv)
{
OEGraphMol refmol = new OEGraphMol();
OEChem.OESmilesToMol(refmol, "c1cc(c2cc(cnc2c1)CCCO)C(=O)CCO");
OEDepict.OEPrepareDepiction(refmol);
OEGraphMol fitmol = new OEGraphMol();
OEChem.OESmilesToMol(fitmol, "c1cc2ccc(cc2c(c1)C(=O)O)CCO");
OEDepict.OEPrepareDepiction(fitmol);
OEMCSSearch mcss = new OEMCSSearch(OEMCSType.Approximate);
uint atomexpr = OEExprOpts.DefaultAtoms;
uint bondexpr = OEExprOpts.DefaultBonds;
mcss.Init(refmol, atomexpr, bondexpr);
mcss.SetMCSFunc(new OEMCSMaxBondsCompleteCycles());
OEAlignmentResult alignres = new OEAlignmentResult(OEDepict.OEPrepareAlignedDepiction(fitmol, mcss));
OEImage image = new OEImage(400, 200);
uint rows = 1;
uint cols = 2;
OEImageGrid grid = new OEImageGrid(image, rows, cols);
OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(grid.GetCellWidth(),
grid.GetCellHeight(),
OEScale.AutoScale);
opts.SetTitleLocation(OETitleLocation.Hidden);
double refscale = OEDepict.OEGetMoleculeScale(refmol, opts);
double fitscale = OEDepict.OEGetMoleculeScale(fitmol, opts);
opts.SetScale(Math.Min(refscale, fitscale));
uint hstyle = OEHighlightStyle.BallAndStick;
OE2DMolDisplay refdisp = new OE2DMolDisplay(mcss.GetPattern(), opts);
OE2DMolDisplay fitdisp = new OE2DMolDisplay(fitmol, opts);
if (alignres.IsValid()) {
OEAtomBondSet refabset = new OEAtomBondSet(alignres.GetPatternAtoms(), alignres.GetPatternBonds());
OEDepict.OEAddHighlighting(refdisp, OEChem.OEBlueTint, hstyle, refabset);
OEAtomBondSet fitabset = new OEAtomBondSet(alignres.GetTargetAtoms(), alignres.GetTargetBonds());
OEDepict.OEAddHighlighting(fitdisp, OEChem.OEBlueTint, hstyle, fitabset);
}
OEImageBase refcell = grid.GetCell(1, 1);
OEDepict.OERenderMolecule(refcell, refdisp);
OEImageBase fitcell = grid.GetCell(1, 2);
OEDepict.OERenderMolecule(fitcell, fitdisp);
OEDepict.OEWriteImage("MCSAlign.png", image);
return 0;
}
}
See also
OEMCSSearch class in the OEChem TK manual
OEImageGrid class
OEAddHighlighting
functionOERenderMolecule
functionOEWriteImage
functionAligning Molecule Based on MCS example
Molecule Alignment Based on Substructure Search¶
The Figure: Example of depiction without alignment is generated by highlighting the “O=C(O)C(N)” substructures in four amino acids, but keeping the original orientation of the compounds.
The Listing 2
code example shows how to align these
molecules by their matched substructures (i.e. by the highlighted atoms and bonds
in Figure: Example of depiction without alignment).
First, the OESubSearch object is initialized with the reference 2D molecule onto which all amino acid structures will be aligned.
Each amino acids structure is initialized from a SMILES string and prepared for depiction.
An OEImageGrid object is constructed that allows to render the molecules into a grid layout.
An OE2DMolDisplayOptions object is initialized that stores the properties determine how the molecules are rendered. In order to render the molecules in equal size the smallest depiction scaling factor is calculated.
Looping over the amino acids:
Each molecule is aligned to the reference molecule by calling the
OEPrepareAlignedDepiction
function that performs the alignment based on the detected substructure search match(es).If the molecule alignment was successful (i.e
OEAlignmentResult.IsValid
is true), then the correspondence between the two molecules stored in the OEAlignmentResult returned by theOEPrepareAlignedDepiction
function. This OEAlignmentResult object can be used to highlight the matched substructure by invoking theOEAddHighlighting
function.The aligned (and highlighted) molecule is then rendered to a next cell of the OEImageGrid object.
Finally, the image is written into a
png
file.
The image created by Listing 2
is shown in
Figure: Example of depiction with alignment based on substructure search.
Listing 2: Example of molecule alignment based on substructure search
public class SubSearchAlign
{
public static int Main(string[] argv)
{
string refsmiles = "O=C(O)C(N)";
OEGraphMol refmol = new OEGraphMol();
OEChem.OESmilesToMol(refmol, refsmiles);
OEDepict.OEPrepareDepiction(refmol);
OESubSearch ss = new OESubSearch(refmol,
OEExprOpts.DefaultAtoms,
OEExprOpts.DefaultBonds);
List<string> aminosmiles = new List<string>();
aminosmiles.Add("O=C(O)[C@@H](N)Cc1c[nH]cn1 Histidine");
aminosmiles.Add("CC(C)[C@@H](C(=O)O)N Valine");
aminosmiles.Add("C[C@H]([C@@H](C(=O)O)N)O Threonine");
aminosmiles.Add("C1C[C@H](NC1)C(=O)O Proline");
List<OEGraphMol> aminoacids = new List<OEGraphMol>();
foreach (string smiles in aminosmiles)
{
OEGraphMol mol = new OEGraphMol();
OEChem.OESmilesToMol(mol, smiles);
OEDepict.OEPrepareDepiction(mol);
aminoacids.Add(mol);
}
OEImage image = new OEImage(400, 400);
uint rows = 2;
uint cols = 2;
OEImageGrid grid = new OEImageGrid(image, rows, cols);
OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(grid.GetCellWidth(),
grid.GetCellHeight(),
OEScale.AutoScale);
opts.SetAtomStereoStyle(OEAtomStereoStyle.Display.All);
double minscale = Double.MaxValue;
foreach (OEGraphMol mol in aminoacids)
{
minscale = Math.Min(minscale, OEDepict.OEGetMoleculeScale(mol, opts));
}
opts.SetScale(minscale);
uint hstyle = OEHighlightStyle.Stick;
OEImageBaseIter celliter = grid.GetCells();
foreach (OEGraphMol mol in aminoacids)
{
OEAlignmentResult alignres = new OEAlignmentResult(OEDepict.OEPrepareAlignedDepiction(mol, ss));
OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);
if (alignres.IsValid()) {
OEDepict.OEAddHighlighting(disp, OEChem.OELightGreen, hstyle, alignres);
}
celliter.Increment();
}
OEDepict.OEWriteImage("SubSearchAlign.png", image);
return 0;
}
}
See also
OESubSearch class in the OEChem TK manual
OEImageGrid class
OEAddHighlighting
functionOERenderMolecule
functionOEWriteImage
function
Molecule Alignment Based on Molecular Similarity¶
The Figure: Example of depiction without alignment is generated by keeping the original orientation of the compounds.
The Listing 3
code example shows how to align these
molecules based on their molecular similarity.
First, two molecules are initialized from SMILES string and prepared for depiction.
An OEImageGrid object is constructed that allows to render the two molecules in a grid next to each other.
The fit molecule is then aligned to the reference. The
OEGetFPOverlap
function is utilized to return all common fragments found between two molecules based on a given fingerprint type. These common fragments reveal the similar parts of the two molecules being compared that are used by theOEPrepareMultiAlignedDepiction
function to find the best alignment between the molecules. See more fingerprint types in the Fingerprint Types chapter of the GraphSim TK manual.An OE2DMolDisplayOptions object is initialized that stores the properties determine how the molecules are rendered. In order to render the molecules in equal size the smallest depiction scaling factor is calculated.
Then both molecules are rendered into the separate cells of the grid layout, the image is written into a
png
file.
The image created by Listing 3
is shown in
Figure: Example of depiction with alignment based on molecular similarity.
Note
GraphSim TK license in not required to run the Listing 3
example.
Listing 3: Example of molecule alignment based on molecular similarity
public class FPAlign
{
public static void Main(string[] args)
{
OEGraphMol refmol = new OEGraphMol();
OEChem.OESmilesToMol(refmol, "C[C@H](C(=O)N1CCC[C@H]1C(=O)O)OC(=O)[C@@H](Cc2ccccc2)S");
OEDepict.OEPrepareDepiction(refmol);
OEGraphMol fitmol = new OEGraphMol();
OEChem.OESmilesToMol(fitmol, "C[C@H](C(=O)N1CCC[C@H]1C(=O)O)NC(=O)[C@@H](Cc2ccccn2)S");
OEDepict.OEPrepareDepiction(fitmol);
OEImage image = new OEImage(500, 300);
uint rows = 1;
uint cols = 2;
OEImageGrid grid = new OEImageGrid(image, rows, cols);
OEFPTypeBase fptype = OEGraphSim.OEGetFPType(OEFPType.Tree);
OEDepict.OEPrepareMultiAlignedDepiction(fitmol, refmol,
OEGraphSim.OEGetFPOverlap(refmol, fitmol, fptype));
OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(grid.GetCellWidth(),
grid.GetCellHeight(),
OEScale.AutoScale);
opts.SetTitleLocation(OETitleLocation.Hidden);
double refscale = OEDepict.OEGetMoleculeScale(refmol, opts);
double fitscale = OEDepict.OEGetMoleculeScale(fitmol, opts);
opts.SetScale(Math.Min(refscale, fitscale));
OEImageBase refcell = grid.GetCell(1, 1);
OE2DMolDisplay refdisp = new OE2DMolDisplay(refmol, opts);
OEDepict.OERenderMolecule(refcell, refdisp);
OEImageBase fitcell = grid.GetCell(1, 2);
OE2DMolDisplay fitdisp = new OE2DMolDisplay(fitmol, opts);
OEDepict.OERenderMolecule(fitcell, fitdisp);
OEDepict.OEWriteImage("FPAlign.png", image);
}
}
See also
OEImageGrid class
OERenderMolecule
functionOEWriteImage
function
See also
The Python script that visualizes molecule similarity based on fingerprints can be downloaded from the OpenEye Python Cookbook