Python-Ref > Cheminformatics > OASA > Creating images with OASA
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce

Creating images with OASA

How to create images of molecules.
At the time of writing of this article, OASA is used by OpenBabel (pybel) for image generation and coordinate calculation. The following code shows how to generate an image using OASA.
Expand/Shrink
Zdroj: (oasa1-0.py)
  1   from oasa import smiles, cairo_out
  2   
  3   mol = smiles.text_to_mol( "c1cc(O)ccc1Cl")
  4   mol.normalize_bond_length( 30)
  5   cairo_out.mol_to_png( mol, "oasa_test0.png")
output image oasa_test0.png
Doba běhu: 163.0 ms
Expand/Shrink
Zdroj: (oasa1-1.py)
  1   from oasa import smiles, cairo_out
  2   
  3   mol = smiles.text_to_mol( "c1cc(O)ccc1Cl")
  4   mol.normalize_bond_length( 30)
  5   c = cairo_out.cairo_out()
  6   c.mol_to_cairo( mol, "oasa_test1.png")
output image oasa_test1.png
Doba běhu: 159.1 ms
The following example shows some of the options that are available for fine-tuning of the resulting image.
Expand/Shrink
Zdroj: (oasa1-2.py)
  1   from oasa import smiles, cairo_out
  2   
  3   mol = smiles.text_to_mol( "c1cc(O)ccc1Cl")
  4   mol.normalize_bond_length( 30)
  5   c = cairo_out.cairo_out( color_bonds=False,
  6                            color_atoms=False,
  7                            show_hydrogens_on_hetero=True,
  8                            font_size=20,
  9                            scaling=3,
 10                            line_width=3,
 11                            bond_width=8,
 12                            )
 13                            
 14   c.mol_to_cairo( mol, "oasa_test2.png")
output image oasa_test2.png
Doba běhu: 180.6 ms