2019-04-17 20:24:42 +09:00
|
|
|
from __future__ import print_function
|
2005-11-18 00:53:15 +00:00
|
|
|
import openbabel
|
|
|
|
|
|
|
|
|
|
mol = openbabel.OBMol()
|
2019-04-17 20:24:42 +09:00
|
|
|
print('Should print 0 (atoms)')
|
|
|
|
|
print(mol.NumAtoms())
|
2005-11-18 00:53:15 +00:00
|
|
|
|
|
|
|
|
a = mol.NewAtom()
|
|
|
|
|
b = mol.NewAtom()
|
|
|
|
|
mol.AddBond(1, 2, 1)
|
2019-04-17 20:24:42 +09:00
|
|
|
print('Should print 2 (atoms)')
|
|
|
|
|
print(mol.NumAtoms())
|
|
|
|
|
print('Should print 1 (bond)')
|
|
|
|
|
print(mol.NumBonds())
|
2005-11-18 00:53:15 +00:00
|
|
|
|
|
|
|
|
obConversion = openbabel.OBConversion()
|
|
|
|
|
obConversion.SetInAndOutFormats("smi", "mdl")
|
|
|
|
|
|
|
|
|
|
mol.Clear()
|
|
|
|
|
obConversion.ReadString(mol, "C1=CC=CS1")
|
|
|
|
|
|
2019-04-17 20:24:42 +09:00
|
|
|
print('Should print 5 (atoms)')
|
|
|
|
|
print(mol.NumAtoms())
|
2005-11-18 00:53:15 +00:00
|
|
|
|
|
|
|
|
mol.AddHydrogens()
|
2019-04-17 20:24:42 +09:00
|
|
|
print('Should print 9 (atoms) after adding hydrogens')
|
|
|
|
|
print(mol.NumAtoms())
|
2005-11-18 00:53:15 +00:00
|
|
|
|
|
|
|
|
outMDL = obConversion.WriteString(mol)
|
|
|
|
|
|
|
|
|
|
obConversion.WriteFile(mol, 'temp.mdl')
|