Open Babel  3.0
obconversion_readstring.py

Reading a smiles string in python.

1 from __future__ import print_function
2 from openbabel import openbabel as ob
3 
4 # Initialize the OBConversion object
5 conv = ob.OBConversion()
6 if not conv.SetInFormat('smi'):
7  print('could not find smiles format')
8 
9 # Read the smiles string
10 mol = ob.OBMol()
11 if not conv.ReadString(mol, 'CCCC'):
12  print('could not read the smiles string')
13 
14 # ... Use OBMol object ...