Skip to content

Instantly share code, notes, and snippets.

@filipsPL
Last active November 12, 2015 12:35
Show Gist options
  • Save filipsPL/5c810a452559a7fcc99e to your computer and use it in GitHub Desktop.
Save filipsPL/5c810a452559a7fcc99e to your computer and use it in GitHub Desktop.
split molecule file to separate components and save to multiple files.
### split molecule file to separate components and save to multiple files.
import pybel
from openbabel import *
mol = pybel.readfile('mol2', 'ligand.mol2').next()
separated = mol.OBMol.Separate()
def writeOut( theConformer, outputPath ):
myConversion = OBConversion()
outputFormat = myConversion.FormatFromExt( outputPath )
myConversion.SetOutFormat( outputFormat )
myConversion.WriteFile( theConformer, outputPath )
i = 0
for singlemol in separated:
i+=1
print "Writing part %i" % (i)
writeOut(singlemol, "output-%i.mol2" %(i) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment