bkchem-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bkchem-user] Generating 2D structures images from 2D (.mol)


From: Beda Kosata
Subject: Re: [Bkchem-user] Generating 2D structures images from 2D (.mol)
Date: Wed, 18 Feb 2009 06:31:03 +0100
User-agent: Thunderbird 2.0.0.17 (X11/20080914)

Hello David,

it is indeed possible, but for molfiles it would be an overkill because,
as you suggested, BKChem needs an X server for the drawing.
However there is a simpler alternative - a library called OASA which is
the basis of BKChem an can create pictures without the need of an X server.
Here are some examples of its use:
http://bkchem.zirael.org/oasa_en.html
http://notimetolouse.blogspot.com/2009/02/pdf-and-svg-support-added-to-oasa.html

OASA is also used by pybel - the python bindings to OpenBabel:
http://openbabel.org/wiki/Install_Python_bindings

Depending on what you prefer, you can read your molfiles either by pybel
and draw them using OASA, or give both tasks to OASA.
The code would look like this..

---
from oasa import cairo_out, molfile

m = molfile.converter()
f = open("input.sdf","r")
i = 1
for mol in m.read_file( f):
    mol.remove_unimportant_hydrogens()
    mol.normalize_bond_length( 30)
    cairo_out.mol_to_cairo( mol, "out%d.png" % i, "png")
    i += 1
f.close()
---

..or like this..

---
import pybel

i = 1
for mol in pybel.readfile( "sdf", "input.sdf"):
  mol.draw( show=False, filename="out%d.png"%i)
  i += 1
---

As you can see, the OASA code is actually longer, but is gives you more
control of the output.
You can for example control display of hydrogens, bond widths,
background color, etc.

---
    cairo_out.mol_to_cairo( mol, "out%d.png" % i, "png",
                            line_width=2, font_size=12,
                            background_color=(0.9,0.8,0.8,1))
---


You can also use OASA to export SVG or PDF.
I hope this helps.

        Best regards

                Beda



David García Aristegui wrote:
> Hello, is possible to use BKchem to generate 2D images (png, for
> example) from MOL/SDF (2D) files? i see this issue was discussed before
> http://www.mail-archive.com/address@hidden/msg00030.html
> but i don't know how to implement this. Is available an example like
> smi2png.py, but working with MOL files? 
> 
> BTW, i remember that the old xchemdraw calls the X server to generate
> the PNGs, BKChem calls the X server too? 
> 
> Thank you in advanced, best regards.
> 
> 
> 
> _______________________________________________
> Bkchem-user mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/bkchem-user
> 


-- 
Bedrich Kosata
Laboratory of Informatics and Chemistry
ICT Prague
Czech Republic

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]