Ticket #1972: mmcif.py-1.diff

File mmcif.py-1.diff, 1.9 KB (added by tic20@…, 6 years ago)

Added by email2trac

  • src/bundles/mmcif/src/mmcif.py

    diff --git a/src/bundles/mmcif/src/mmcif.py b/src/bundles/mmcif/src/mmcif.py
    index 17bbabf..f2e59f2 100644
    a b _mmcif_sources = {  
    271271}
    272272
    273273
    274 def fetch_mmcif(session, pdb_id, fetch_source="rcsb", ignore_cache=False, **kw):
     274def fetch_mmcif(session, pdb_id, fetch_source="rcsb", ignore_cache=False,
     275        structure_factors = False, over_sampling = 1.5, # for ChimeraX-Clipper plugin
     276        **kw):
    275277    """Get mmCIF file by PDB identifier via the Internet"""
    276278    if not _initialized:
    277279        _initialize()
    278280
    279281    if len(pdb_id) != 4:
    280282        raise UserError('PDB identifiers are 4 characters long, got "%s"' % pdb_id)
     283    if structure_factors:
     284        try:
     285            from chimerax.clipper.io import fetch_cif
     286        except ImportError:
     287            raise UserError('Working with structure factors requires the '
     288                'ChimeraX_Clipper plugin, available from the Tool Shed')
     289
    281290    import os
    282291    pdb_id = pdb_id.lower()
    283292    filename = None
    def fetch_mmcif(session, pdb_id, fetch_source="rcsb", ignore_cache=False, **kw):  
    314323    session.logger.status("Opening mmCIF %s" % (pdb_id,))
    315324    from chimerax.core import io
    316325    models, status = io.open_data(session, filename, format='mmcif', name=pdb_id, **kw)
     326    if structure_factors:
     327        sf_file = fetch_cif.fetch_structure_factors(session, pdb_id, fetch_source=fetch_source,
     328            ignore_cache=ignore_cache)
     329        from chimerax.clipper import get_map_mgr
     330        mmgr = get_map_mgr(models[0], create=True)
     331        if over_sampling < 1:
     332            warn_str = ('Map over-sampling rate cannot be less than 1. Resetting to 1.0')
     333            session.logger.warning(warn_str)
     334            over_sampling = 1
     335        mmgr.add_xmapset_from_file(sf_file, oversampling_rate = over_sampling)
     336        return [mmgr.crystal_mgr], status
    317337    return models, status