openbabeltest.py
# coding: shift-jis
from openbabel import *
def ReadSdFile(inSdFilePath="test.sdf"):
#inSdFilePath = "test.sdf"
conv = OBConversion()
answer = conv.SetInAndOutFormats("sdf","can")
mol = OBMol()
end_flag = conv.ReadFile(mol,inSdFilePath)
smiles = []
while end_flag:
smile = conv.WriteString(mol).split('\t')[0] # Smiles文字のみをSplitする
smiles.append(smile)
answer = mol.Clear()
end_flag = conv.Read(mol)
return smiles
# main
smilesStrigList = ReadSdFile()
for smiles in smilesStrigList:
print smiles
コマンドプロンプト
I:\Python>python openbabeltest.py
ClCC(=O)NC1=C(SCC1)C(=O)OC
COC(=O)C1=C(CCS1)NC(=O)c1ccccc1
COC(=O)C1=C(CCS1)NC(=O)c1cccc(C)c1
COC(=O)C1=C(CCS1)NC(=O)c1ccccc1Cl
COC(=O)C1=C(CCS1)NC(=O)c1ccc(C)c(C)c1
0 件のコメント:
コメントを投稿