Hi Julian,

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:

https://pymolwiki.org/index.php/Cif_keepinmemory

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.

Cheers,
  Thomas

> On Jun 12, 2017, at 12:21 PM, Julian Reitz <julianr1...@gmail.com> 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,
> 
> Julian 

--
Thomas Holder
PyMOL Principal Developer
Schrödinger, Inc.

import json
import urllib2
from pymol import cmd

@cmd.extend
def pdb_chain_selections(code):
    '''
DESCRIPTION

    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()[0]:
        # only include polymers
        if not mol[u'molecule_type'].startswith('poly'):
            continue

        # entity description (truncated)
        desc = mol[u'synonym'][:200]

        if has_segi:
            # 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)
        else:
            # select chains
            for chain in mol[u'in_chains']:
                cmd.select('chain_%s_%s' % (chain, desc), 'chain ' + chain)

code = '5n61'
cmd.fetch(code)
pdb_chain_selections(code)
------------------------------------------------------------------------------
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 (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to