A one-liner to create chain selections looks like this:
for c in cmd.get_chains(): cmd.select("chain_" + c, "chain " + c)
PyMOL doesn't provide access to the PDB header fields. In principle PyMOL
provides a way to access everything inside mmCIF files, see:
However, instead of doing this, I recommend to use the PDBe web API which
provides the data in a friendly JSON data structure. I've attached a Python
script which creates molecule (or chain) selections for 5n61 as an example. I
recommend to load PDB structures from mmCIF or MMTF format, which not only have
chain identifiers, but also molecule identifiers ("segi" field in PyMOL).
Hope that helps.
> On Jun 12, 2017, at 12:21 PM, Julian Reitz wrote:
> Dear all,
> I have a pdb-file with multiple chains (5N61).
> Is there an easy way to create selections for all the chains that are defined
> in the pdb-header (A to U) without doing it manually for every chain (select
> A, chain A)?
> Is it also possible to use the MOLECULE information from the header to name
> the selections?
> Thank you in advance,
PyMOL Principal Developer
from pymol import cmd
Make selections for every molecule (if loaded from mmCIF/MMTF) or
every chain (if loaded from PDB), using PDBe REST API.
data = json.load(urllib2.urlopen(
'http://www.ebi.ac.uk/pdbe/api/pdb/entry/molecules/' + code))
# check if we can select by segi (label_asym_id)
has_segi = not cmd.count_atoms('segi ""')
for mol in data.values():
# only include polymers
if not mol[u'molecule_type'].startswith('poly'):
# entity description (truncated)
desc = mol[u'synonym'][:200]
# select molecules by label_asym_id (PyMOL 1.7.4+)
for chain in mol[u'in_struct_asyms']:
cmd.select('segi_%s_%s' % (chain, desc), 'segi ' + chain)
# select chains
for chain in mol[u'in_chains']:
cmd.select('chain_%s_%s' % (chain, desc), 'chain ' + chain)
code = '5n61'
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
PyMOL-users mailing list (PyMOLemail@example.com)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users