Python-Ref > Cheminformatics > OpenBabel > Coordinate optimalization
 
 

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

Coordinate optimalization

How to optimalize coordinates and generate 3D structure from 2D.
OpenBabel includes some force-field routines for geometry optimalization. Using pybel, it is possible to use these to optimize a 3D structure or create 3D coordinates from 2D.
The following example shows how a picture of a molecule looks when rotated.
Expand/Shrink
Zdroj: (babel5-1.py)
  1   import pybel
  2   import openbabel
  3   
  4   mol = pybel.readstring( "smi", "C1CCCCC1C(=O)O")
  5   mol.draw( show=False, filename="cyclohexanecarboxylic_acid.png", update=True)
  6   # we cannot pass python lists to OB, we must use a special conversion function
  7   mol.OBMol.Rotate( openbabel.double_array( [0.98, 0.1987, 0.0,
  8                                              0.0, -0.1987, 0.98,
  9                                              0.0, 0.0, 0.0]))
 10   mol.draw( show=False, filename="cyclohexanecarboxylic_acid_rot.png", usecoords=True)
output image cyclohexanecarboxylic_acid_rot.png
output image cyclohexanecarboxylic_acid.png
Doba běhu: 197.2 ms
Below you see the difference when 3D coordinates are generated.
Expand/Shrink
Zdroj: (babel5-2.py)
  1   import pybel
  2   import openbabel
  3   
  4   mol = pybel.readstring( "smi", "C1CCCCC1C(=O)O")
  5   mol.draw( show=False, filename="cyclohexanecarboxylic_acid.png", update=True)
  6   mol.make3D() 
  7   # we cannot pass python lists to OB, we must use a special conversion function
  8   mol.OBMol.Rotate( openbabel.double_array( [0.98, 0.1987, 0.0,
  9                                              0.0, -0.1987, 0.98,
 10                                              0.0, 0.0, 0.0]))
 11   mol.draw( show=False, filename="cyclohexanecarboxylic_acid_rot_3d.png", usecoords=True)
output image cyclohexanecarboxylic_acid_rot_3d.png
output image cyclohexanecarboxylic_acid.png
Doba běhu: 388.2 ms