def generate_map_coefficients( model=None, # Required model output_map_coeffs_file_name=None, d_min=3, scattering_table='electron', log=sys.stdout): ''' Convenience function to create map coefficients from a model. This function typically accessed and tested through map_model_manager Summary: Supply model.manager object or parameters for generate_model, high_resolution limit of d_min and optional scattering_table ("electron" for cryo-EM, "n_gaussian" for x-ray) and optional output_map_coeffs_file_name. Writes map coefficients and returns miller_array object containing the map coefficients Parameters: ----------- model (model.manager object, None): model to use output_map_coeffs_file_name (string, None): output model file name d_min (float, 3): High-resolution limit for map coeffs (A) scattering_table (choice, 'electron'): choice of scattering table All choices: wk1995 it1992 n_gaussian neutron electron ''' assert model is not None # get map coefficients from mmtbx.utils import fmodel_from_xray_structure import iotbx.phil from mmtbx.command_line.fmodel import master_phil fmodel_params = master_phil.extract() assert model.crystal_symmetry( ) is not None # Need crystal_symmetry in model xrs = model.get_xray_structure() fmodel_params.high_resolution = float(d_min) fmodel_params.scattering_table = scattering_table fmodel = fmodel_from_xray_structure(xray_structure=xrs, params=fmodel_params, out=log) f_model = fmodel.f_model if output_map_coeffs_file_name: f_model.as_mtz_dataset(column_root_label='FWT').mtz_object().write( file_name=output_map_coeffs_file_name) print("Writing map coefficients to resolution of %s A to %s" % (d_min, output_map_coeffs_file_name), file=log) else: print("Generated map coefficients to resolution of %s A " % (d_min), file=log) return f_model
def get_amplitudes(self): if self.method == "f_calc": f_calc_complex = self.xray_structure.structure_factors( d_min=self.d_min, algorithm=self.algorithm).f_calc() f_calc_real = abs(f_calc_complex) f_calc_real.set_observation_type_xray_amplitude() return f_calc_real elif self.method == "f_model": f_model_complex = fmodel_from_xray_structure( xray_structure=self.xray_structure, f_obs=None, add_sigmas=False, params=self.params2).f_model f_model_real = abs(f_model_complex) f_model_real.set_observation_type_xray_amplitude() return f_model_real
def generate_map_coefficients(model=None, output_map_coeffs_file_name=None, high_resolution=3, scattering_table='electron', log=sys.stdout, **pass_through_kw): ''' generate_map_coefficients Convenience function to create map coefficients from a model. Supply model.manager object, high_resolution limit and optional scattering_table ("electron" for cryo-EM, "n_gaussian" for x-ray) and optional output_map_coeffs_file_name. Writes map coefficients and returns miller_array object containing the map ''' if not model: model = generate_model(log=log, **pass_through_kw) # get map coefficients from mmtbx.utils import fmodel_from_xray_structure import iotbx.phil from mmtbx.command_line.fmodel import master_phil fmodel_params = master_phil.extract() xrs = model.get_xray_structure() fmodel_params.high_resolution = float(high_resolution) fmodel_params.scattering_table = scattering_table fmodel = fmodel_from_xray_structure(xray_structure=xrs, params=fmodel_params, out=log) f_model = fmodel.f_model if output_map_coeffs_file_name: f_model.as_mtz_dataset(column_root_label='FWT').mtz_object().write( file_name=output_map_coeffs_file_name) print("Writing map coefficients to resolution of %s A to %s" % (high_resolution, output_map_coeffs_file_name), file=log) else: print("Generated map coefficients to resolution of %s A " % (high_resolution), file=log) return f_model
def from_pdb(self): out = self.out params = self.params pdb_hierarchy = self.pdb_hierarchy pdb_sg, pdb_uc = None, None pdb_symm = self.pdb_in.crystal_symmetry() if (pdb_symm is not None): pdb_sg = pdb_symm.space_group_info() pdb_uc = pdb_symm.unit_cell() apply_sg = pdb_sg apply_uc = pdb_uc if (params.crystal_symmetry.space_group is not None): apply_sg = params.crystal_symmetry.space_group else: params.crystal_symmetry.space_group = pdb_sg if (params.crystal_symmetry.unit_cell is not None): apply_uc = params.crystal_symmetry.unit_cell else: params.crystal_symmetry.unit_cell = pdb_uc if (apply_sg is None) or (apply_uc is None): raise Sorry( "Incomplete symmetry information - please specify a space " + "group and unit cell for this structure.") from cctbx import crystal, adptbx from scitbx.array_family import flex apply_symm = crystal.symmetry(unit_cell=apply_uc, space_group_info=apply_sg) if (params.modify_pdb.remove_waters): print(" Removing solvent atoms...", file=out) for model in pdb_hierarchy.models(): for chain in model.chains(): for residue_group in chain.residue_groups(): for atom_group in residue_group.atom_groups(): if (atom_group.resname in ["HOH", "WAT"]): residue_group.remove_atom_group( atom_group=atom_group) if (len(residue_group.atom_groups()) == 0): chain.remove_residue_group( residue_group=residue_group) if (len(chain.atoms()) == 0): model.remove_chain(chain=chain) if (params.modify_pdb.remove_alt_confs): print( " Removing all alternate conformations and resetting occupancies...", file=out) from mmtbx import pdbtools pdbtools.remove_alt_confs(hierarchy=pdb_hierarchy) xray_structure = self.pdb_in.xray_structure_simple( crystal_symmetry=apply_symm) sctr_keys = xray_structure.scattering_type_registry().type_count_dict() hd_selection = xray_structure.hd_selection() if (not (("H" in sctr_keys) or ("D" in sctr_keys))): print(" WARNING: this model does not contain hydrogen atoms!", file=out) print(" strongly recommend running phenix.ready_set or", file=out) print(" equivalent to ensure realistic simulated data.", file=out) print("", file=out) if (params.modify_pdb.convert_to_isotropic): xray_structure.convert_to_isotropic() set_b = None if (params.modify_pdb.set_mean_b_iso is not None): assert (not params.modify_pdb.set_wilson_b) print(" Scaling B-factors to have mean of %.2f" % \ params.modify_pdb.set_mean_b_iso, file=out) assert (params.modify_pdb.set_mean_b_iso > 0) set_b = params.modify_pdb.set_mean_b_iso elif (params.modify_pdb.set_wilson_b): print( " Scaling B-factors to match mean Wilson B for this resolution", file=out) set_b = get_mean_statistic_for_resolution(d_min=params.d_min, stat_type="wilson_b") print("", file=out) if (set_b is not None): u_iso = xray_structure.extract_u_iso_or_u_equiv() u_iso = u_iso.select(~hd_selection) u_mean = flex.mean(u_iso) b_mean = adptbx.u_as_b(u_mean) scale = set_b / b_mean xray_structure.scale_adps(scale) pdb_hierarchy.atoms().set_adps_from_scatterers( scatterers=xray_structure.scatterers(), unit_cell=xray_structure.unit_cell()) import mmtbx.command_line.fmodel from mmtbx import utils fmodel_params = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params.extract( ) fmodel_params.high_resolution = params.d_min fake_data = params.fake_data_from_fmodel fmodel_params.fmodel = fake_data.fmodel if (fmodel_params.fmodel.b_sol == 0): print(" b_sol is zero - will use mean value for d_min +/- 0.2A", file=out) print(" (this is not strongly correlated with resolution, but", file=out) print( " it is preferrable to use a real value instead of leaving", file=out) print(" it set to 0)", file=out) fmodel_params.fmodel.b_sol = 46.0 print("", file=out) if (fmodel_params.fmodel.k_sol == 0): print(" k_sol is zero - will use mean value for d_min +/- 0.2A", file=out) print(" (this is not strongly correlated with resolution, but", file=out) print( " it is preferrable to use a real value instead of leaving", file=out) print(" it set to 0)", file=out) fmodel_params.fmodel.k_sol = 0.35 print("", file=out) fmodel_params.structure_factors_accuracy = fake_data.structure_factors_accuracy fmodel_params.mask = fake_data.mask fmodel_params.r_free_flags_fraction = params.r_free_flags.fraction fmodel_params.add_sigmas = False fmodel_params.output.type = "real" fmodel_ = utils.fmodel_from_xray_structure( xray_structure=xray_structure, params=fmodel_params) f_model = fmodel_.f_model r_free_flags = fmodel_.r_free_flags return (f_model, r_free_flags)
def from_pdb (self) : out = self.out params = self.params pdb_hierarchy = self.pdb_hierarchy pdb_sg, pdb_uc = None, None pdb_symm = self.pdb_in.crystal_symmetry() if (pdb_symm is not None) : pdb_sg = pdb_symm.space_group_info() pdb_uc = pdb_symm.unit_cell() apply_sg = pdb_sg apply_uc = pdb_uc if (params.crystal_symmetry.space_group is not None) : apply_sg = params.crystal_symmetry.space_group else : params.crystal_symmetry.space_group = pdb_sg if (params.crystal_symmetry.unit_cell is not None) : apply_uc = params.crystal_symmetry.unit_cell else : params.crystal_symmetry.unit_cell = pdb_uc if (apply_sg is None) or (apply_uc is None) : raise Sorry("Incomplete symmetry information - please specify a space "+ "group and unit cell for this structure.") from cctbx import crystal, adptbx from scitbx.array_family import flex apply_symm = crystal.symmetry( unit_cell=apply_uc, space_group_info=apply_sg) if (params.modify_pdb.remove_waters) : print >> out, " Removing solvent atoms..." for model in pdb_hierarchy.models() : for chain in model.chains() : for residue_group in chain.residue_groups() : for atom_group in residue_group.atom_groups() : if (atom_group.resname in ["HOH", "WAT"]) : residue_group.remove_atom_group(atom_group=atom_group) if (len(residue_group.atom_groups()) == 0) : chain.remove_residue_group(residue_group=residue_group) if (len(chain.atoms()) == 0) : model.remove_chain(chain=chain) if (params.modify_pdb.remove_alt_confs) : print >> out, " Removing all alternate conformations and resetting occupancies..." from mmtbx import pdbtools pdbtools.remove_alt_confs(hierarchy=pdb_hierarchy) xray_structure = self.pdb_in.xray_structure_simple( crystal_symmetry=apply_symm) sctr_keys = xray_structure.scattering_type_registry().type_count_dict().keys() hd_selection = xray_structure.hd_selection() if (not (("H" in sctr_keys) or ("D" in sctr_keys))) : print >> out, " WARNING: this model does not contain hydrogen atoms!" print >> out, " strongly recommend running phenix.ready_set or" print >> out, " equivalent to ensure realistic simulated data." print >> out, "" if (params.modify_pdb.convert_to_isotropic) : xray_structure.convert_to_isotropic() set_b = None if (params.modify_pdb.set_mean_b_iso is not None) : assert (not params.modify_pdb.set_wilson_b) print >> out, " Scaling B-factors to have mean of %.2f" % \ params.modify_pdb.set_mean_b_iso assert (params.modify_pdb.set_mean_b_iso > 0) set_b = params.modify_pdb.set_mean_b_iso elif (params.modify_pdb.set_wilson_b) : print >> out, " Scaling B-factors to match mean Wilson B for this resolution" set_b = get_mean_statistic_for_resolution( d_min=params.d_min, stat_type="wilson_b") print >> out, "" if (set_b is not None) : u_iso = xray_structure.extract_u_iso_or_u_equiv() u_iso = u_iso.select(~hd_selection) u_mean = flex.mean(u_iso) b_mean = adptbx.u_as_b(u_mean) scale = set_b / b_mean xray_structure.scale_adps(scale) pdb_hierarchy.atoms().set_adps_from_scatterers( scatterers=xray_structure.scatterers(), unit_cell=xray_structure.unit_cell()) import mmtbx.command_line.fmodel from mmtbx import utils fmodel_params = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params.extract() fmodel_params.high_resolution = params.d_min fake_data = params.fake_data_from_fmodel fmodel_params.fmodel = fake_data.fmodel if (fmodel_params.fmodel.b_sol == 0) : print >> out, " b_sol is zero - will use mean value for d_min +/- 0.2A" print >> out, " (this is not strongly correlated with resolution, but" print >> out, " it is preferrable to use a real value instead of leaving" print >> out, " it set to 0)" fmodel_params.fmodel.b_sol = 46.0 print >> out, "" if (fmodel_params.fmodel.k_sol == 0) : print >> out, " k_sol is zero - will use mean value for d_min +/- 0.2A" print >> out, " (this is not strongly correlated with resolution, but" print >> out, " it is preferrable to use a real value instead of leaving" print >> out, " it set to 0)" fmodel_params.fmodel.k_sol = 0.35 print >> out, "" fmodel_params.structure_factors_accuracy = fake_data.structure_factors_accuracy fmodel_params.mask = fake_data.mask fmodel_params.r_free_flags_fraction = params.r_free_flags.fraction fmodel_params.add_sigmas = False fmodel_params.output.type = "real" fmodel_ = utils.fmodel_from_xray_structure( xray_structure=xray_structure, params=fmodel_params) f_model = fmodel_.f_model r_free_flags = fmodel_.r_free_flags return (f_model, r_free_flags)