def _refine_bravais(self): # type: () -> None """Run `dials.refine_bravais_settings` to determine the space group.""" dials_start = timeit.default_timer() info("\nRefining Bravais settings...") self.refls = eliminate_sys_absent(self.expts, self.refls) map_to_primitive(self.expts, self.refls) try: refined_settings = refined_settings_from_refined_triclinic( self.expts, self.refls, self.params.dials_refine_bravais) except RuntimeError as e: warning("dials.refine_bravais_settings failed.\nGiving up.") sys.exit(e) possible_bravais_settings = { solution["bravais"] for solution in refined_settings } bravais_lattice_to_space_group_table(possible_bravais_settings) try: # Old version of dials with as_str() method logger.info(refined_settings.as_str()) except AttributeError: # Newer versions of dials (>= 2.2.2) has proper __str__ method logger.info(refined_settings) info( "Successfully completed (%.1f sec)", timeit.default_timer() - dials_start, )
def refine_bravais_settings(self, reflections, experiments): # configure DIALS logging if self.dials_log: log.config(verbosity=0, logfile=self.dials_log) proc_scope = phil_scope.format(python_object=self.params) sgparams = sg_scope.fetch(proc_scope).extract() sgparams.refinement.reflections.outlier.algorithm = 'tukey' crystal_P1 = copy.deepcopy(experiments[0].crystal) # Generate Bravais settings try: Lfat = refined_settings_factory_from_refined_triclinic(sgparams, experiments, reflections, lepage_max_delta=5) except Exception as e: # If refinement fails, reset to P1 (experiments remain modified by Lfat # if there's a refinement failure, which causes issues down the line) for expt in experiments: expt.crystal = crystal_P1 return None Lfat.labelit_printout() # Filter out not-recommended (i.e. too-high rmsd and too-high max angular # difference) solutions Lfat_recommended = [s for s in Lfat if s.recommended] # If none are recommended, return None (do not reindex) if len(Lfat_recommended) == 0: return None # Find the highest symmetry group possible_bravais_settings = set(solution['bravais'] for solution in Lfat_recommended) bravais_lattice_to_space_group_table(possible_bravais_settings) lattice_to_sg_number = { 'aP': 1, 'mP': 3, 'mC': 5, 'oP': 16, 'oC': 20, 'oF': 22, 'oI': 23, 'tP': 75, 'tI': 79, 'hP': 143, 'hR': 146, 'cP': 195, 'cF': 196, 'cI': 197 } filtered_lattices = {} for key, value in lattice_to_sg_number.items(): if key in possible_bravais_settings: filtered_lattices[key] = value highest_sym_lattice = max(filtered_lattices, key=filtered_lattices.get) highest_sym_solutions = [s for s in Lfat if s['bravais'] == highest_sym_lattice] if len(highest_sym_solutions) > 1: highest_sym_solution = sorted(highest_sym_solutions, key=lambda x: x['max_angular_difference'])[0] else: highest_sym_solution = highest_sym_solutions[0] return highest_sym_solution
def refine_bravais_settings(self, reflections, experiments): # configure DIALS logging if self.dials_log: log.config(verbosity=1, logfile=self.dials_log) proc_scope = phil_scope.format(python_object=self.params) sgparams = sg_scope.fetch(proc_scope).extract() sgparams.refinement.reflections.outlier.algorithm = "tukey" crystal_P1 = copy.deepcopy(experiments[0].crystal) try: refined_settings = refined_settings_from_refined_triclinic( experiments=experiments, reflections=reflections, params=sgparams) possible_bravais_settings = { s["bravais"] for s in refined_settings } bravais_lattice_to_space_group_table(possible_bravais_settings) except Exception: for expt in experiments: expt.crystal = crystal_P1 return None # Generate Bravais settings # try: # Lfat = refined_settings_factory_from_refined_triclinic(sgparams, # experiments, # reflections, # lepage_max_delta=5) # except Exception as e: # # If refinement fails, reset to P1 (experiments remain modified by Lfat # # if there's a refinement failure, which causes issues down the line) # for expt in experiments: # expt.crystal = crystal_P1 # return None # # Lfat.labelit_printout() # # # Filter out not-recommended (i.e. too-high rmsd and too-high max angular # # difference) solutions # Lfat_recommended = [s for s in Lfat if s.recommended] # # # If none are recommended, return None (do not reindex) # if len(Lfat_recommended) == 0: # return None # # # Find the highest symmetry group # possible_bravais_settings = set(solution['bravais'] for solution in # Lfat_recommended) # bravais_lattice_to_space_group_table(possible_bravais_settings) lattice_to_sg_number = { "aP": 1, "mP": 3, "mC": 5, "oP": 16, "oC": 20, "oF": 22, "oI": 23, "tP": 75, "tI": 79, "hP": 143, "hR": 146, "cP": 195, "cF": 196, "cI": 197, } filtered_lattices = {} for key, value in lattice_to_sg_number.items(): if key in possible_bravais_settings: filtered_lattices[key] = value highest_sym_lattice = max(filtered_lattices, key=filtered_lattices.get) highest_sym_solutions = [ s for s in refined_settings if s["bravais"] == highest_sym_lattice ] if len(highest_sym_solutions) > 1: highest_sym_solution = sorted( highest_sym_solutions, key=lambda x: x["max_angular_difference"])[0] else: highest_sym_solution = highest_sym_solutions[0] return highest_sym_solution