def write_phenix_refine_cmd(session, model, model_file_name=None, param_file_name=None, restrain_coordination_sites=False, include_hydrogens=False, num_processors=1, num_macrocycles=6, nqh_flips=True, scattering_type='xray'): from chimerax.clipper import get_symmetry_handler sh = get_symmetry_handler(model, create=False) crystal_error_str = 'Model must be a crystal structure initialised in Clipper with experimental data!' if sh is None: raise UserError(crystal_error_str) if not len(sh.map_mgr.xmapsets): raise UserError(crystal_error_str) xmapset = sh.map_mgr.xmapsets[0] from .refine_input import write_phenix_refine_defaults write_phenix_refine_defaults( session, model, xmapset, model_file_name=model_file_name, param_file_name=param_file_name, restrain_coordination_sites=restrain_coordination_sites, include_hydrogens=include_hydrogens, num_processors=num_processors, num_macrocycles=num_macrocycles, nqh_flips=nqh_flips, scattering_type=scattering_type)
def close_models(session, models: 'string or list'): ''' Close one or more models and/or maps. Behaviour varies depending on the types of models specified. If the model is an atomic structure or a Clipper top-level manager, the manager and all maps associated with the model will be deleted. If a map, just that map will be deleted. If a map manager, all maps handled by that manager will be deleted. Args: models: a single model ID or a list of model IDs. ''' from chimerax.atomic import AtomicStructure if not isinstance(models, list): models = [models] to_close = [] not_found = [] for mid in models: m = _model_from_id(session, mid, error_if_not_found=False) if not m: session.logger.warning('Model ID {} not found!'.format(mid)) not_found.append(mid) continue if isinstance(m, AtomicStructure): from chimerax.clipper import get_symmetry_handler m = get_symmetry_handler(m) to_close.append(m) ret = { 'closed': [m.id_string for m in to_close], 'not_found': not_found, } session.models.close(to_close) return ret
def _get_symmetry_handler(model): from chimerax.atomic import AtomicStructure from chimerax.clipper import get_symmetry_handler from chimerax.clipper.symmetry import SymmetryManager if isinstance(model, AtomicStructure): return get_symmetry_handler(model) elif isinstance(model, SymmetryManager): return model else: err_string = ( 'The ID {} corresponds to an incompatible model type: {}'.format( model.id_string, type(model))) raise TypeError(err_string)
def load_model(session, file_path: 'string'): ''' Load a model from a single PDB or mmCIF file. Multi-model files are not supported. Args: file_path: the full path to a single PDB or mmCIF file Returns: {'manager': model id for the top-level Clipper manager for the model, 'model': model id for the atomic structure itself. } ''' from chimerax.open_command.cmd import provider_open from chimerax.clipper import get_symmetry_handler m = provider_open(session, [file_path])[0] sh = get_symmetry_handler(m, create=True, auto_add_to_session=True) return {'manager': sh.id_string, 'model id': m.id_string}
def load_structure_factors(session, file_path: 'string', model_id: 'string'): ''' Load a set of structure factors in MTZ or CIF format, generate maps and associate them with an existing atomic model. Data may be provided as any of the following: F / sigF I / sigI F+ / sigF+ / F- / sigF- I+ / sigI+ / I- / sigI- Free flags F / phi Only one experimental dataset should be provided, but any number of F/phi maps many be provided. If experimental data is provided, three "live" maps will be calculated: a standard 2mFo-DFc map; a second 2mFo-DFc map with a resolution-dependent sharpening or smoothing B-factor applied (sharpened at resolutions worse than 2.5A, smoothed otherwise); and a mFo-DFc map. For best results, the experimental reflections should already be corrected for anisotropy and any artefacts such as ice rings or beamstop shadows. Anomalous data will be automatically merged, and intensities converted to amplitudes using the method of Read & McCoy. CAUTION: if no free flags are provided, a new set will be automatically generated. Any of the generated maps may be closed using close_model() on its id, or the whole set may be closed at once by closing the map_mgr. Args: file_path: the full path to a single .mtz or .cif file model_id: id string (e.g. as returned by load_model()) of the atomic structure to associate the structure factors with, or its top-level Clipper manager. Returns: {'manager': model id for the top-level Clipper manager for the model/maps, 'model': model id for the atomic structure, 'map_mgr': model id for the manager of all maps associated with the structure, 'mapset': model id for the container holding the maps resulting from this call, 'maps': { 'map 1 column names': map 1 model id, ... } } ''' from chimerax.clipper.symmetry import SymmetryManager from chimerax.atomic import AtomicStructure m = _model_from_id(session, model_id) if isinstance(m, AtomicStructure): from chimerax.clipper import get_symmetry_handler sh = get_symmetry_handler(m, create=True, auto_add_to_session=True) elif isinstance(m, SymmetryManager): sh = m else: err_string = ( 'Model ID {} has unrecognised type: {}. ' 'Should be one of AtomicStructure or SymmetryManager.').format( model_id, type(m)) raise TypeError(err_string) mmgr = sh.map_mgr xmapset = mmgr.add_xmapset_from_file(file_path) return { 'manager': sh.id_string, 'model': sh.structure.id_string, 'map_mgr': mmgr.id_string, 'mapset': xmapset.id_string, 'maps': {x.name: x.id_string for x in xmapset}, }