Skip to content

Instantly share code, notes, and snippets.

@bougui505
Created March 6, 2020 12:54
Show Gist options
  • Save bougui505/94d6457346727b654301111bea4da937 to your computer and use it in GitHub Desktop.
Save bougui505/94d6457346727b654301111bea4da937 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: UTF8 -*-
# Author: Guillaume Bouvier -- guillaume.bouvier@pasteur.fr
# https://research.pasteur.fr/en/member/guillaume-bouvier/
# 2020-03-06 13:17:44 (UTC+0100)
from pymol import cmd
from pymol import exporting
cmd.load('small03.mol2', 'mol2_in')
nstates = cmd.count_states('mol2_in')
for i in range(1, nstates + 1):
cmd.split_states('mol2_in', i, i)
molname = cmd.get_object_list()[-1]
# ------------------------------ Save a mol2 file ------------------------------
cmd.save('out.mol2', molname)
# ---------------------------- or get a mol2 string ----------------------------
mol2str = exporting.get_mol2str('mol2_in')
print(mol2str)
# ------------------------------------- - --------------------------------------
cmd.delete(molname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment