def exercise_get_atom_selections (verbose=False) : pdb_in = """\ CRYST1 15.000 15.000 15.000 90.00 90.00 90.00 P 212121 HETATM 115 O HOH A 18 3.000 5.000 5.000 1.00 10.00 O HETATM 115 O HOH A 19 5.000 5.000 8.000 1.00 10.00 O HETATM 115 O HOH A 20 5.000 5.000 8.000 1.00 10.00 O END""" log = null_out() if (verbose) : log = sys.stdout processed_pdb_files_srv = utils.process_pdb_file_srv(log=log) processed_pdb_file, pdb_inp = processed_pdb_files_srv.process_pdb_files( raw_records=pdb_in.splitlines()) selections1 = utils.get_atom_selections( all_chain_proxies=processed_pdb_file.all_chain_proxies, xray_structure=processed_pdb_file.xray_structure(), selection_strings=["resseq 18", "resseq 19", "resseq 20"], parameter_name="refine.occupancy") try : selections2 = utils.get_atom_selections( all_chain_proxies=processed_pdb_file.all_chain_proxies, xray_structure=processed_pdb_file.xray_structure(), selection_strings=["resseq 18:19", "resseq 19:20"], parameter_name="refine.occupancy") except Sorry, s : assert (str(s) == """\ One or more overlapping selections for refine.occupancy: resseq 18:19 resseq 19:20""")
def _rotate_about_axis(self): raap = self.params.rotate_about_axis sites_cart = self.xray_structure.sites_cart() if ([raap.axis, raap.atom_selection, raap.angle].count(None) == 0): axis = [] try: for a in raap.axis.split(): axis.append(float(a)) except Exception: sel = utils.get_atom_selections( iselection=False, all_chain_proxies=self.all_chain_proxies, selection_strings=raap.axis, xray_structure=self.xray_structure)[0] axis = [i for i in sites_cart.select(sel).as_double()] if (len(axis) != 6): raise Sorry("Bad selection rotate_about_axis.axis: %s" % str(raap.axis)) p1 = scitbx.matrix.col(axis[:3]) p2 = scitbx.matrix.col(axis[3:]) raa = p1.rt_for_rotation_around_axis_through(point=p2, angle=raap.angle, deg=True) # sel = utils.get_atom_selections( iselection=False, all_chain_proxies=self.all_chain_proxies, selection_strings=raap.atom_selection, xray_structure=self.xray_structure)[0] if (sel.count(True) == 0): raise Sorry("Empty selection rotate_about_axis.selection: %s" % str(raap.atom_selection)) sites_cart_rotated = raa * sites_cart.select(sel) self.xray_structure.set_sites_cart( sites_cart.set_selected(sel, sites_cart_rotated))
def exercise_get_atom_selections(verbose=False): pdb_in = """\ CRYST1 15.000 15.000 15.000 90.00 90.00 90.00 P 212121 HETATM 115 O HOH A 18 3.000 5.000 5.000 1.00 10.00 O HETATM 115 O HOH A 19 5.000 5.000 8.000 1.00 10.00 O HETATM 115 O HOH A 20 5.000 5.000 8.000 1.00 10.00 O END""" log = null_out() if (verbose): log = sys.stdout model = mmtbx.model.manager( model_input = iotbx.pdb.input(lines=pdb_in.splitlines(), source_info=None), process_input = True) processed_pdb_files_srv = utils.process_pdb_file_srv(log=log) processed_pdb_file, pdb_inp = processed_pdb_files_srv.process_pdb_files( raw_records=pdb_in.splitlines()) selections1 = utils.get_atom_selections( model = model, selection_strings=["resseq 18", "resseq 19", "resseq 20"], parameter_name="refine.occupancy") try : selections2 = utils.get_atom_selections( model = model, selection_strings=["resseq 18:19", "resseq 19:20"], parameter_name="refine.occupancy") except Sorry, s : assert (str(s) == """\ One or more overlapping selections for refine.occupancy: resseq 18:19 resseq 19:20""")
def occupancy_selections( model, add_water = False, other_individual_selection_strings = None, other_constrained_groups = None, remove_selection = None, as_flex_arrays = True, constrain_correlated_3d_groups = False, log = None): # set up defaults if(other_individual_selection_strings is not None and len(other_individual_selection_strings) == 0): other_individual_selection_strings = None if(other_constrained_groups is not None and len(other_constrained_groups) == 0): other_constrained_groups = None if(remove_selection is not None and len(remove_selection) == 0): remove_selection = None result = model.get_hierarchy().occupancy_groups_simple( common_residue_name_class_only = None, always_group_adjacent = False, ignore_hydrogens = False) exchangable_hd_pairs = mmtbx.utils.combine_hd_exchangable(hierarchy = model.get_hierarchy()) if(len(exchangable_hd_pairs)==0 and result is not None): occupancy_regroupping( pdb_hierarchy = model.get_hierarchy(), cgs = result) result = mmtbx.utils.remove_selections(selection = result, other = exchangable_hd_pairs, size = model.get_number_of_atoms()) result.extend(exchangable_hd_pairs) # extract group-[0,1]-constrained atoms withing a residue pogl = extract_partial_occupancy_selections(hierarchy = model.get_hierarchy()) rm_duplicate_with_pogl = [] for t_ in pogl: for t__ in t_: for t___ in t__: rm_duplicate_with_pogl.append(t___) result = mmtbx.utils.remove_selections(selection = result, other = pogl, size = model.get_number_of_atoms()) result.extend(pogl) # add partial occupancies occupancies = model.get_xray_structure().scatterers().extract_occupancies() sel = (occupancies != 1.) & (occupancies != 0.) result = add_occupancy_selection( result = result, size = model.get_number_of_atoms(), selection = sel, hd_special = None) # check user's input all_sel_strgs = [] if(other_individual_selection_strings is not None): all_sel_strgs = all_sel_strgs + other_individual_selection_strings if(other_constrained_groups is not None): for other_constrained_group in other_constrained_groups: for other_constrained_group in other_constrained_groups: if(len(other_constrained_group.selection)>0): all_sel_strgs = all_sel_strgs + other_constrained_group.selection if(len(all_sel_strgs) > 0): for sel_str in all_sel_strgs: sel_str_sel = get_atom_selections( model = model, selection_strings = [sel_str], iselection = True, one_selection_array = True) if(sel_str_sel.size() == 0): raise Sorry("Empty selection: %s"%sel_str) # if([other_individual_selection_strings, other_constrained_groups].count(None) == 0): sel1 = get_atom_selections( model = model, selection_strings = other_individual_selection_strings, iselection = True, one_selection_array = True) for other_constrained_group in other_constrained_groups: for other_constrained_group in other_constrained_groups: for cg_sel_strs in other_constrained_group.selection: sel2 = get_atom_selections( model = model, selection_strings = cg_sel_strs, iselection = True, one_selection_array = True) if(sel1.intersection(sel2).size() > 0): raise Sorry("Duplicate selection: same atoms selected for individual and group occupancy refinement.") # check user's input and apply remove_selection to default selection if(remove_selection is not None): sel1 = get_atom_selections( model = model, selection_strings = remove_selection, iselection = True, one_selection_array = True) if(sel1.size() == 0): # XXX check all and not total. raise Sorry("Empty selection: remove_selection.") if(other_individual_selection_strings is not None): sel2 = get_atom_selections( model = model, selection_strings = other_individual_selection_strings, iselection = True, one_selection_array = True) if(sel1.intersection(sel2).size() > 0): raise Sorry("Duplicate selection: occupancies of same atoms selected to be fixed and to be refined.") if(other_constrained_groups is not None): for other_constrained_group in other_constrained_groups: for cg_sel_strs in other_constrained_group.selection: sel2 = get_atom_selections( model = model, selection_strings = cg_sel_strs, iselection = True, one_selection_array = True) if(sel1.intersection(sel2).size() > 0): raise Sorry("Duplicate selection: occupancies of same atoms selected to be fixed and to be refined.") result = mmtbx.utils.remove_selections(selection = result, other = sel1, size = model.get_number_of_atoms()) # if(other_individual_selection_strings is not None): sel = get_atom_selections( model = model, selection_strings = other_individual_selection_strings, iselection = True, one_selection_array = True) result = mmtbx.utils.remove_selections(selection = result, other = sel, size = model.get_number_of_atoms()) result = add_occupancy_selection( result = result, size = model.get_number_of_atoms(), selection = sel, hd_special = None) if(other_constrained_groups is not None): for other_constrained_group in other_constrained_groups: cg_sel = [] for cg_sel_strs in other_constrained_group.selection: sel = get_atom_selections( model = model, selection_strings = cg_sel_strs, iselection = True, one_selection_array = True) result = mmtbx.utils.remove_selections(selection = result, other = sel, size = model.get_number_of_atoms()) if(sel.size() > 0): cg_sel.append(list(sel)) if(len(cg_sel) > 0): result.append(cg_sel) if(add_water): water_selection = get_atom_selections( model = model, selection_strings = ['water'], iselection = True, allow_empty_selection = True, one_selection_array = True) result = add_occupancy_selection( result = result, size = model.get_number_of_atoms(), selection = water_selection, hd_special = None) list_3d_as_bool_selection( list_3d=result, size=model.get_number_of_atoms()) if(len(result) == 0): result = None if(as_flex_arrays and result is not None): result_ = [] for gsel in result: result__ = [] for sel in gsel: result__.append(flex.size_t(sel)) result_.append(result__) result = result_ if (constrain_correlated_3d_groups) and (len(result) > 0): result = assemble_constraint_groups_3d( xray_structure=model.get_xray_structure(), pdb_atoms=model.get_atoms(), constraint_groups=result, log=log) return result
def run(args, command_name = "phenix.tls"): if(len(args) == 0): args = ["--help"] usage_fmt = "%s pdb_file [parameters: file or command line string]" des_fmt = "Example: %s model.pdb fit_tls_to.selection='%s' fit_tls_to.selection='%s'" command_line = (iotbx_option_parser( usage = usage_fmt % command_name, description = banner) .option("--show_defaults", action="store_true", help="Do not output to the screen (except errors).") .option("--silent", action="store_true", help="Suppress output to the screen.") ).process(args=args) # log = sys.stdout if(not command_line.options.silent): utils.print_header("TLS tools", out = log) if(command_line.options.show_defaults): master_params.show(out = log) print >> log return if(not command_line.options.silent): print >> log, banner # processed_args = utils.process_command_line_args(args = command_line.args, master_params = master_params, log = log) reflection_files = processed_args.reflection_files if(processed_args.crystal_symmetry is None): raise Sorry("No crystal symmetry found.") if(len(processed_args.pdb_file_names) == 0): raise Sorry("No PDB file found.") params = processed_args.params if(not command_line.options.silent): utils.print_header("Input parameters", out = log) params.show(out = log) params = params.extract() # if(processed_args.crystal_symmetry.unit_cell() is None or processed_args.crystal_symmetry.space_group() is None): raise Sorry("No CRYST1 record found.") mmtbx_pdb_file = utils.pdb_file( pdb_file_names = processed_args.pdb_file_names, cif_objects = processed_args.cif_objects, crystal_symmetry = processed_args.crystal_symmetry, log = log) # if(not command_line.options.silent): utils.print_header("TLS groups from PDB file header", out = log) pdb_inp_tls = mmtbx.tls.tools.tls_from_pdb_inp( remark_3_records = mmtbx_pdb_file.pdb_inp.extract_remark_iii_records(3), pdb_hierarchy = mmtbx_pdb_file.pdb_inp.construct_hierarchy()) # tls_groups = [] if(pdb_inp_tls.tls_present): if(pdb_inp_tls.error_string is not None): raise Sorry(pdb_inp_tls.error_string) mmtbx_pdb_file.set_ppf() xray_structure = get_xrs_helper(mmtbx_pdb_file = mmtbx_pdb_file, log = log, silent = command_line.options.silent) pdb_tls = mmtbx.tls.tools.extract_tls_from_pdb( pdb_inp_tls = pdb_inp_tls, all_chain_proxies = mmtbx_pdb_file.processed_pdb_file.all_chain_proxies, xray_structure = xray_structure) tls_groups = pdb_tls.pdb_inp_tls.tls_params # tls_selections_strings = [] # if(len(tls_groups) == 0 and not command_line.options.silent): print >> log, "No TLS groups found in PDB file header." else: for i_seq, tls_group in enumerate(tls_groups): tls_selections_strings.append(tls_group.selection_string) if(not command_line.options.silent): print >> log, "TLS group %d: %s" % (i_seq+1, tls_group.selection_string) mmtbx.tls.tools.show_tls_one_group(tlso = tls_group, out = log) print >> log # if(len(tls_selections_strings) > 0 and len(params.selection) > 0): raise Sorry("Two TLS selection sources found: PDB file header and parameters.") if(len(params.selection) > 0): tls_selections_strings = params.selection xray_structure = get_xrs_helper(mmtbx_pdb_file = mmtbx_pdb_file, log = log, silent = command_line.options.silent) if([params.combine_tls, params.extract_tls].count(True) > 1): raise Sorry("Cannot simultaneously pereform: combine_tls and extract_tls") if([params.combine_tls, params.extract_tls].count(True) > 0): if(len(tls_selections_strings)==0): raise Sorry("No TLS selections found.") # if(len(tls_selections_strings)): if(not command_line.options.silent): utils.print_header("TLS groups selections", out = log) selections = utils.get_atom_selections( all_chain_proxies = mmtbx_pdb_file.processed_pdb_file.all_chain_proxies, selection_strings = tls_selections_strings, xray_structure = xray_structure) if(not command_line.options.silent): print >> log, "Number of TLS groups: ", len(selections) print >> log, "Number of atoms: %d" % xray_structure.scatterers().size() n_atoms_in_tls = 0 for sel_a in selections: n_atoms_in_tls += sel_a.size() if(not command_line.options.silent): print >> log, "Number of atoms in TLS groups: %d" % n_atoms_in_tls print >> log assert len(tls_selections_strings) == len(selections) if(not command_line.options.silent): for sel_a, sel_s in zip(selections,tls_selections_strings): print >> log, "Selection string:\n%s" % sel_s print >> log, "selects %d atoms." % sel_a.size() print >> log print >> log, "Ready-to-use in phenix.refine:\n" for sel_a, sel_s in zip(selections,tls_selections_strings): print >> log, sel_s # ofn = params.output_file_name if(ofn is None): ofn = os.path.splitext(os.path.basename(processed_args.pdb_file_names[0]))[0] if(len(processed_args.pdb_file_names) > 1): ofn = ofn+"_el_al" if(params.combine_tls): ofn = ofn+"_combine_tls.pdb" elif(params.extract_tls): ofn = ofn+"_extract_tls.pdb" else: ofn = None if(ofn is not None): ofo = open(ofn, "w") # if(params.extract_tls): utils.print_header( "Fit TLS matrices to B-factors of selected sets of atoms", out = log) tlsos = mmtbx.tls.tools.generate_tlsos( selections = selections, xray_structure = xray_structure, value = 0.0) for rt,rl,rs in [[1,0,1],[1,1,1],[0,1,1], [1,0,0],[0,1,0],[0,0,1],[1,1,1], [0,0,1]]*10: tlsos = mmtbx.tls.tools.tls_from_uanisos( xray_structure = xray_structure, selections = selections, tlsos_initial = tlsos, number_of_macro_cycles = 10, max_iterations = 100, refine_T = rt, refine_L = rl, refine_S = rs, enforce_positive_definite_TL = params.enforce_positive_definite_TL, verbose = -1, out = log) mmtbx.tls.tools.show_tls(tlsos = tlsos, out = log) u_cart_from_tls = mmtbx.tls.tools.u_cart_from_tls( sites_cart = xray_structure.sites_cart(), selections = selections, tlsos = tlsos) unit_cell = xray_structure.unit_cell() for i_seq, sc in enumerate(xray_structure.scatterers()): if(u_cart_from_tls[i_seq] != (0,0,0,0,0,0)): u_star_tls = adptbx.u_cart_as_u_star(unit_cell, tuple(u_cart_from_tls[i_seq])) sc.u_star = tuple(flex.double(sc.u_star) - flex.double(u_star_tls)) for sel in selections: xray_structure.convert_to_isotropic(selection = sel) mmtbx.tls.tools.remark_3_tls(tlsos = tlsos, selection_strings = tls_selections_strings, out = ofo) # if(params.combine_tls): utils.print_header("Combine B_tls with B_residual", out = log) mmtbx.tls.tools.combine_tls_and_u_local(xray_structure = xray_structure, tls_selections = selections, tls_groups = tls_groups) print >> log, "All done." # if(ofn is not None): utils.print_header("Write output PDB file %s"%ofn, out = log) utils.write_pdb_file( xray_structure = xray_structure, pdb_hierarchy = mmtbx_pdb_file.processed_pdb_file.all_chain_proxies.pdb_hierarchy, out = ofo) ofo.close() print >> log, "All done."
def run(args, command_name="phenix.tls"): if (len(args) == 0): args = ["--help"] usage_fmt = "%s pdb_file [parameters: file or command line string]" des_fmt = "Example: %s model.pdb fit_tls_to.selection='%s' fit_tls_to.selection='%s'" command_line = (iotbx_option_parser( usage=usage_fmt % command_name, description=banner).option( "--show_defaults", action="store_true", help="Do not output to the screen (except errors).").option( "--silent", action="store_true", help="Suppress output to the screen.")).process(args=args) # log = sys.stdout if (not command_line.options.silent): utils.print_header("TLS tools", out=log) if (command_line.options.show_defaults): master_params.show(out=log) print(file=log) return if (not command_line.options.silent): print(banner, file=log) # processed_args = utils.process_command_line_args( args=command_line.args, master_params=master_params, log=log) reflection_files = processed_args.reflection_files if (processed_args.crystal_symmetry is None): raise Sorry("No crystal symmetry found.") if (len(processed_args.pdb_file_names) == 0): raise Sorry("No PDB file found.") params = processed_args.params if (not command_line.options.silent): utils.print_header("Input parameters", out=log) params.show(out=log) params = params.extract() # if (processed_args.crystal_symmetry.unit_cell() is None or processed_args.crystal_symmetry.space_group() is None): raise Sorry("No CRYST1 record found.") pdb_combined = iotbx.pdb.combine_unique_pdb_files( file_names=processed_args.pdb_file_names) pdb_combined.report_non_unique(out=log) if (len(pdb_combined.unique_file_names) == 0): raise Sorry("No coordinate file given.") raw_records = pdb_combined.raw_records try: pdb_inp = iotbx.pdb.input(source_info=None, lines=flex.std_string(raw_records)) except ValueError as e: raise Sorry("Model format (PDB or mmCIF) error:\n%s" % str(e)) model = mmtbx.model.manager( model_input=pdb_inp, restraint_objects=processed_args.cif_objects, crystal_symmetry=processed_args.crystal_symmetry, log=log) if (not command_line.options.silent): utils.print_header("TLS groups from PDB file header", out=log) pdb_inp_tls = mmtbx.tls.tools.tls_from_pdb_inp( remark_3_records=model._model_input.extract_remark_iii_records(3), pdb_hierarchy=model.get_hierarchy()) # tls_groups = [] if (pdb_inp_tls.tls_present): if (pdb_inp_tls.error_string is not None): raise Sorry(pdb_inp_tls.error_string) pdb_tls = mmtbx.tls.tools.extract_tls_from_pdb(pdb_inp_tls=pdb_inp_tls, model=model) tls_groups = pdb_tls.pdb_inp_tls.tls_params # tls_selections_strings = [] # if (len(tls_groups) == 0 and not command_line.options.silent): print("No TLS groups found in PDB file header.", file=log) else: for i_seq, tls_group in enumerate(tls_groups): tls_selections_strings.append(tls_group.selection_string) if (not command_line.options.silent): print("TLS group %d: %s" % (i_seq + 1, tls_group.selection_string), file=log) mmtbx.tls.tools.show_tls_one_group(tlso=tls_group, out=log) print(file=log) # if (len(tls_selections_strings) > 0 and len(params.selection) > 0): raise Sorry( "Two TLS selection sources found: PDB file header and parameters.") if (len(params.selection) > 0): tls_selections_strings = params.selection if ([params.combine_tls, params.extract_tls].count(True) > 1): raise Sorry( "Cannot simultaneously pereform: combine_tls and extract_tls") if ([params.combine_tls, params.extract_tls].count(True) > 0): if (len(tls_selections_strings) == 0): raise Sorry("No TLS selections found.") # if (len(tls_selections_strings)): if (not command_line.options.silent): utils.print_header("TLS groups selections", out=log) selections = utils.get_atom_selections( model=model, selection_strings=tls_selections_strings) if (not command_line.options.silent): print("Number of TLS groups: ", len(selections), file=log) print("Number of atoms: %d" % model.get_number_of_atoms(), file=log) n_atoms_in_tls = 0 for sel_a in selections: n_atoms_in_tls += sel_a.size() if (not command_line.options.silent): print("Number of atoms in TLS groups: %d" % n_atoms_in_tls, file=log) print(file=log) assert len(tls_selections_strings) == len(selections) if (not command_line.options.silent): for sel_a, sel_s in zip(selections, tls_selections_strings): print("Selection string:\n%s" % sel_s, file=log) print("selects %d atoms." % sel_a.size(), file=log) print(file=log) print("Ready-to-use in phenix.refine:\n", file=log) for sel_a, sel_s in zip(selections, tls_selections_strings): print(sel_s, file=log) # ofn = params.output_file_name if (ofn is None): ofn = os.path.splitext( os.path.basename(processed_args.pdb_file_names[0]))[0] if (len(processed_args.pdb_file_names) > 1): ofn = ofn + "_el_al" if (params.combine_tls): ofn = ofn + "_combine_tls.pdb" elif (params.extract_tls): ofn = ofn + "_extract_tls.pdb" else: ofn = None if (ofn is not None): ofo = open(ofn, "w") # if (params.extract_tls): utils.print_header( "Fit TLS matrices to B-factors of selected sets of atoms", out=log) tlsos = mmtbx.tls.tools.generate_tlsos( selections=selections, xray_structure=model.get_xray_structure(), value=0.0) for rt, rl, rs in [[1, 0, 1], [1, 1, 1], [0, 1, 1], [1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 1], [0, 0, 1]] * 10: tlsos = mmtbx.tls.tools.tls_from_uanisos( xray_structure=model.get_xray_structure(), selections=selections, tlsos_initial=tlsos, number_of_macro_cycles=10, max_iterations=100, refine_T=rt, refine_L=rl, refine_S=rs, enforce_positive_definite_TL=params. enforce_positive_definite_TL, verbose=-1, out=log) mmtbx.tls.tools.show_tls(tlsos=tlsos, out=log) u_cart_from_tls = mmtbx.tls.tools.u_cart_from_tls( sites_cart=model.get_sites_cart(), selections=selections, tlsos=tlsos) unit_cell = model.get_xray_structure().unit_cell() for i_seq, sc in enumerate(model.get_xray_structure().scatterers()): if (u_cart_from_tls[i_seq] != (0, 0, 0, 0, 0, 0)): u_star_tls = adptbx.u_cart_as_u_star( unit_cell, tuple(u_cart_from_tls[i_seq])) sc.u_star = tuple( flex.double(sc.u_star) - flex.double(u_star_tls)) for sel in selections: model.get_xray_structure().convert_to_isotropic(selection=sel) mmtbx.tls.tools.remark_3_tls(tlsos=tlsos, selection_strings=tls_selections_strings, out=ofo) # if (params.combine_tls): utils.print_header("Combine B_tls with B_residual", out=log) mmtbx.tls.tools.combine_tls_and_u_local( xray_structure=model.get_xray_structure(), tls_selections=selections, tls_groups=tls_groups) print("All done.", file=log) # if (ofn is not None): utils.print_header("Write output PDB file %s" % ofn, out=log) model.set_sites_cart_from_xrs() pdb_str = model.model_as_pdb() ofo.write(pdb_str) ofo.close() print("All done.", file=log)
def selection(self, selection_strings): return utils.get_atom_selections(iselection = False, all_chain_proxies= self.all_chain_proxies, selection_strings= selection_strings, xray_structure = self.xray_structure)[0]
def selection(self, selection_strings): return utils.get_atom_selections( iselection=False, all_chain_proxies=self.all_chain_proxies, selection_strings=selection_strings, xray_structure=self.xray_structure)[0]
def occupancy_selections( all_chain_proxies, xray_structure, add_water = False, other_individual_selection_strings = None, other_constrained_groups = None, remove_selection = None, as_flex_arrays = True, constrain_correlated_3d_groups = False, log = None): # set up defaults if(other_individual_selection_strings is not None and len(other_individual_selection_strings) == 0): other_individual_selection_strings = None if(other_constrained_groups is not None and len(other_constrained_groups) == 0): other_constrained_groups = None if(remove_selection is not None and len(remove_selection) == 0): remove_selection = None result = all_chain_proxies.pdb_hierarchy.occupancy_groups_simple( common_residue_name_class_only = None, always_group_adjacent = False, ignore_hydrogens = False) exchangable_hd_pairs = mmtbx.utils.combine_hd_exchangable(hierarchy = all_chain_proxies.pdb_hierarchy) if(len(exchangable_hd_pairs)==0 and result is not None): occupancy_regroupping( pdb_hierarchy = all_chain_proxies.pdb_hierarchy, cgs = result) result = mmtbx.utils.remove_selections(selection = result, other = exchangable_hd_pairs, size = xray_structure.scatterers().size()) result.extend(exchangable_hd_pairs) # extract group-[0,1]-constrained atoms withing a residue pogl = extract_partial_occupancy_selections(hierarchy = all_chain_proxies.pdb_hierarchy) rm_duplicate_with_pogl = [] for t_ in pogl: for t__ in t_: for t___ in t__: rm_duplicate_with_pogl.append(t___) result = mmtbx.utils.remove_selections(selection = result, other = pogl, size = xray_structure.scatterers().size()) result.extend(pogl) # add partial occupancies occupancies = xray_structure.scatterers().extract_occupancies() sel = (occupancies != 1.) & (occupancies != 0.) result = add_occupancy_selection( result = result, size = xray_structure.scatterers().size(), selection = sel, hd_special = None) # check user's input all_sel_strgs = [] if(other_individual_selection_strings is not None): all_sel_strgs = all_sel_strgs + other_individual_selection_strings if(other_constrained_groups is not None): for other_constrained_group in other_constrained_groups: for other_constrained_group in other_constrained_groups: if(len(other_constrained_group.selection)>0): all_sel_strgs = all_sel_strgs + other_constrained_group.selection if(len(all_sel_strgs) > 0): for sel_str in all_sel_strgs: sel_str_sel = get_atom_selections( all_chain_proxies = all_chain_proxies, selection_strings = [sel_str], iselection = True, xray_structure = xray_structure, one_selection_array = True) if(sel_str_sel.size() == 0): raise Sorry("Empty selection: %s"%sel_str) # if([other_individual_selection_strings, other_constrained_groups].count(None) == 0): sel1 = get_atom_selections( all_chain_proxies = all_chain_proxies, selection_strings = other_individual_selection_strings, iselection = True, xray_structure = xray_structure, one_selection_array = True) for other_constrained_group in other_constrained_groups: for other_constrained_group in other_constrained_groups: for cg_sel_strs in other_constrained_group.selection: sel2 = get_atom_selections( all_chain_proxies = all_chain_proxies, selection_strings = cg_sel_strs, iselection = True, xray_structure = xray_structure, one_selection_array = True) if(sel1.intersection(sel2).size() > 0): raise Sorry("Duplicate selection: same atoms selected for individual and group occupancy refinement.") # check user's input and apply remove_selection to default selection if(remove_selection is not None): sel1 = get_atom_selections( all_chain_proxies = all_chain_proxies, selection_strings = remove_selection, iselection = True, xray_structure = xray_structure, one_selection_array = True) if(sel1.size() == 0): # XXX check all and not total. raise Sorry("Empty selection: remove_selection.") if(other_individual_selection_strings is not None): sel2 = get_atom_selections( all_chain_proxies = all_chain_proxies, selection_strings = other_individual_selection_strings, iselection = True, xray_structure = xray_structure, one_selection_array = True) if(sel1.intersection(sel2).size() > 0): raise Sorry("Duplicate selection: occupancies of same atoms selected to be fixed and to be refined.") if(other_constrained_groups is not None): for other_constrained_group in other_constrained_groups: for cg_sel_strs in other_constrained_group.selection: sel2 = get_atom_selections( all_chain_proxies = all_chain_proxies, selection_strings = cg_sel_strs, iselection = True, xray_structure = xray_structure, one_selection_array = True) if(sel1.intersection(sel2).size() > 0): raise Sorry("Duplicate selection: occupancies of same atoms selected to be fixed and to be refined.") result = mmtbx.utils.remove_selections(selection = result, other = sel1, size = xray_structure.scatterers().size()) # if(other_individual_selection_strings is not None): sel = get_atom_selections( all_chain_proxies = all_chain_proxies, selection_strings = other_individual_selection_strings, iselection = True, xray_structure = xray_structure, one_selection_array = True) result = mmtbx.utils.remove_selections(selection = result, other = sel, size = xray_structure.scatterers().size()) result = add_occupancy_selection( result = result, size = xray_structure.scatterers().size(), selection = sel, hd_special = None) if(other_constrained_groups is not None): for other_constrained_group in other_constrained_groups: cg_sel = [] for cg_sel_strs in other_constrained_group.selection: sel = get_atom_selections( all_chain_proxies = all_chain_proxies, selection_strings = cg_sel_strs, iselection = True, xray_structure = xray_structure, one_selection_array = True) result = mmtbx.utils.remove_selections(selection = result, other = sel, size = xray_structure.scatterers().size()) if(sel.size() > 0): cg_sel.append(list(sel)) if(len(cg_sel) > 0): result.append(cg_sel) if(add_water): water_selection = get_atom_selections( all_chain_proxies = all_chain_proxies, selection_strings = ['water'], iselection = True, xray_structure = xray_structure, allow_empty_selection = True, one_selection_array = True) result = add_occupancy_selection( result = result, size = xray_structure.scatterers().size(), selection = water_selection, hd_special = None) list_3d_as_bool_selection( list_3d=result, size=xray_structure.scatterers().size()) if(len(result) == 0): result = None if(as_flex_arrays and result is not None): result_ = [] for gsel in result: result__ = [] for sel in gsel: result__.append(flex.size_t(sel)) result_.append(result__) result = result_ if (constrain_correlated_3d_groups) and (len(result) > 0) : result = assemble_constraint_groups_3d( xray_structure=xray_structure, pdb_atoms=all_chain_proxies.pdb_hierarchy.atoms(), constraint_groups=result, log=log) return result
if (len(tls_selections_strings) > 0 and len(params.selection) > 0): raise Sorry( "Two TLS selection sources found: PDB file header and parameters.") if (len(params.selection) > 0): tls_selections_strings = params.selection if ([params.combine_tls, params.extract_tls].count(True) > 1): raise Sorry( "Cannot simultaneously pereform: combine_tls and extract_tls") if ([params.combine_tls, params.extract_tls].count(True) > 0): if (len(tls_selections_strings) == 0): raise Sorry("No TLS selections found.") # if (len(tls_selections_strings)): if (not command_line.options.silent): utils.print_header("TLS groups selections", out=log) selections = utils.get_atom_selections( model=model, selection_strings=tls_selections_strings) if (not command_line.options.silent): print >> log, "Number of TLS groups: ", len(selections) print >> log, "Number of atoms: %d" % model.get_number_of_atoms() n_atoms_in_tls = 0 for sel_a in selections: n_atoms_in_tls += sel_a.size() if (not command_line.options.silent): print >> log, "Number of atoms in TLS groups: %d" % n_atoms_in_tls print >> log assert len(tls_selections_strings) == len(selections) if (not command_line.options.silent): for sel_a, sel_s in zip(selections, tls_selections_strings): print >> log, "Selection string:\n%s" % sel_s print >> log, "selects %d atoms." % sel_a.size() print >> log