Drkcore

18 06 2011 chemoinformatics Python Tweet

openbabelで分子のコピーをする

clone的なメソッド用意されてないのね。

この前は、こんな感じでコピーするようにしたけど、

def clone(mol):
   new_mol = ob.OBMol()
   for atom in ob.OBMolAtomIter(mol):
       new_mol.AddAtom(atom)

   for bond in ob.OBMolBondIter(mol):
       new_mol.AddBond(bond)
   return new_mol

適当なフォーマットに書きだして再読込でもいいそうなのでそうした。

def clone(mol):
   obc = ob.OBConversion()
   obc.SetInAndOutFormats("mol", "mol")
   molstring = obc.WriteString(mol)
   new_mol = ob.OBMol()
   obc.ReadString(new_mol,molstring)
   return new_mol
  • How can I clone/copy an OBMol or pybel molecule?

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021