To view an sdf chemical file in Python, you can use the RDKit library. Here's a sample code that shows how to load and view an sdf file:
main.py383 chars20 lines
This code loads a sdf file using Chem.SDMolSupplier, which creates an iterable object that allows you to get individual molecules from the file. We then get the first molecule using [0].
We create a 2D drawing of the molecule using rdMolDraw2D.MolDraw2DSVG, which creates an SVG object that we can manipulate. We draw the molecule using drawer.DrawMolecule(mol) and finish the drawing using drawer.FinishDrawing().
Finally, we get the SVG string using drawer.GetDrawingText() and print it using print(svg). You can also write this SVG string to a file or display it in a web page.
gistlibby LogSnag