Ticket #1972: pdb.py.diff

File pdb.py.diff, 2.1 KB (added by tic20@…, 6 years ago)

Added by email2trac

  • src/bundles/pdb/src/pdb.py

    diff --git a/src/bundles/pdb/src/pdb.py b/src/bundles/pdb/src/pdb.py
    index 05ceec21e..2e7519b72 100644
    a b _pdb_sources = {  
    125125    # "pdbj": "https://pdbj.org/rest/downloadPDBfile?format=pdb&id=%s",
    126126}
    127127
    128 def fetch_pdb(session, pdb_id, *, fetch_source="rcsb", ignore_cache=False, **kw):
     128def fetch_pdb(session, pdb_id, *, fetch_source="rcsb", ignore_cache=False,
     129        structure_factors=False, over_sampling=1.5, # for ChimeraX-Clipper plugin
     130        **kw):
    129131    if len(pdb_id) != 4:
    130132        from chimerax.core.errors import UserError
    131133        raise UserError('PDB identifiers are 4 characters long, got "%s"' % pdb_id)
     134    if structure_factors:
     135        try:
     136            from chimerax.clipper.io import fetch_cif
     137        except ImportError:
     138            raise UserError('Working with structure factors requires the '
     139                'ChimeraX_Clipper plugin, available from the Tool Shed')
    132140    import os
    133141    pdb_id = pdb_id.lower()
    134142    # check on local system -- TODO: configure location
    def fetch_pdb(session, pdb_id, *, fetch_source="rcsb", ignore_cache=False, **kw)  
    149157    session.logger.status("Opening PDB %s" % (pdb_id,))
    150158    from chimerax.core import io
    151159    models, status = io.open_data(session, filename, format='pdb', name=pdb_id, **kw)
     160    if structure_factors:
     161        sf_file = fetch_cif.fetch_structure_factors(session, pdb_id, fetch_source=fetch_source,
     162            ignore_cache=ignore_cache)
     163        from chimerax.clipper import get_map_mgr
     164        mmgr = get_map_mgr(models[0], create=True)
     165        if over_sampling < 1:
     166            warn_str = ('Map over-sampling rate cannot be less than 1. Resetting to 1.0')
     167            session.logger.warning(warn_str)
     168            over_sampling = 1
     169        mmgr.add_xmapset_from_file(sf_file, oversampling_rate = over_sampling)
     170        return [mmgr.crystal_mgr], status
     171
    152172    return models, status
    153173
    154174def fetch_pdb_pdbe(session, pdb_id, **kw):
    def _process_src(src, caption):  
    587607            html += '   <td>%s</td>\n' % formatted
    588608            html += '  </tr>\n'
    589609    return html
    590