Align the depiction using a fixed substructure

This task comes from working with researchers who have a desktop tool which displays a large number (a few hundred) structures on a scrolling page. The structures are the database hits from searching with a given SMARTS query, and the common SMARTS substructures are aligned in each depictions. This makes it easier for them to identify the differences between the structures.

They want to replace it with something newer, and they would like more control over how the structure is displayed. (For example, some people want the depiction tool to first follow corporate guidelines on depiction layout. Doing that is outside the scope of this task.)

Implementation
Use the first 16 structures of the benzodiazepine SD file to make a 4x4 grid of depictions as a single image. The first structure is in the upper-left corner, the second is to its right, and so on. Each depiction should include the title field of the corresponding record, which in this case is the PubChem identifier.

Use "[#7]~1~[#6]~[#6]~[#7]~[#6]~[#6]~2~[#6]~[#6]~[#6]~[#6]~[#6]12" as the common SMARTS substructure. This is the fused ring of the benzodiazepine system but without bond type or atom aromaticity information. Use the first molecule as the reference depiction. All other depictions must have the depiction of their common substructure aligned to the reference.

The final image should be 400x400 pixels, which means each structure depiction should be 100x100 pixels. If the toolkit doesn't support multiple depictions in the same image then depict each to a different image. A desktop tool would need a way to write the image data to a GUI widget, but for now just write the result to a PNG or GIF file.

The point here is to show how to do the 2D structure alignment. The other details are less important. Use your own preferences for coloring scheme (eg, color on white background or on black background). You may assume the input structure has the correct MDL chemistry. (This is only relevant for toolkits which support multiple chemistry models.)

Cactvs/Tcl


prop setparam D_GIF ncols 4 nrows 4 boxwidth 100 boxheight 100 filename aligned4x4.png format png padding 0 prop setparam E_GIF headerproperty E_NAME bgcolor white atomcolor element bonds 10 set fh [molfile open benzodiazepine.sdf.gz r hydrogens add] set dh [molfile read $fh [dataset create] 16] set ss [ens create {[#7]~1~[#6]~[#6]~[#7]~[#6]~[#6]~2~[#6]~[#6]~[#6]~[#6]~[#6]12} smarts] foreach eh [dataset ens $dh] { match ss -align besteffort $ss $eh } dataset get $dh D_GIF

Cactvs/Python
The Python version is even more compact, with exactly the same result:

Prop.Setparam('D_GIF','ncols',4,'nrows',4,'boxwidth',100,'boxheight',100,'filename','aligned4x4.png','format','png','padding',0) Prop.Setparam('E_GIF','headerproperty','E_NAME','bgcolor','white','atomcolor','element','bonds',10) d=Molfile('benzodiazepine.sdf.gz','r',{'hydrogens':'add'}).read(Dataset,16) ss=Ens('[#7]~1~[#6]~[#6]~[#7]~[#6]~[#6]~2~[#6]~[#6]~[#6]~[#6]~[#6]12','smarts') for e in d.ens: match('ss',ss,e,align='besteffort') d.get('D_GIF')