def from_dict(cls, obj): assert obj['__id__'] == 'Indexer' assert obj['__name__'] == cls.__name__ return_obj = cls() for k, v in obj.iteritems(): if k == '_indxr_helper' and v is not None: from xia2.Schema.Interfaces.Indexer import _IndexerHelper v = _IndexerHelper(v) if k == '_indxr_imagesets' and len(v): assert v[0].get('__id__') == 'imageset' from dxtbx.serialize.imageset import imageset_from_dict v = [imageset_from_dict(v_, check_format=False) for v_ in v] if isinstance(v, dict): if v.get('__id__') == 'ExperimentList': from dxtbx.model.experiment.experiment_list import ExperimentListFactory v = ExperimentListFactory.from_dict(v, check_format=False) setattr(return_obj, k, v) return return_obj
def from_dict(cls, obj): assert obj['__id__'] == 'Indexer' assert obj['__name__'] == cls.__name__ return_obj = cls() for k, v in obj.iteritems(): if k == '_indxr_helper' and v is not None: from xia2.Schema.Interfaces.Indexer import _IndexerHelper v = _IndexerHelper(v) if k == '_indxr_imagesets' and len(v): assert v[0].get('__id__') == 'imageset' from dxtbx.serialize.imageset import imageset_from_dict v = [imageset_from_dict(v_, check_format=False) for v_ in v] if isinstance(v, dict): if v.get('__id__') == 'ExperimentList': from dxtbx.model.experiment_list import ExperimentListFactory v = ExperimentListFactory.from_dict(v, check_format=False) setattr(return_obj, k, v) return return_obj
def index(self): if not self.get_indexer_finish_done(): f = inspect.currentframe().f_back.f_back m = f.f_code.co_filename l = f.f_lineno Debug.write('Index in %s called from %s %d' % (self.__class__.__name__, m, l)) while not self.get_indexer_finish_done(): while not self.get_indexer_done(): while not self.get_indexer_prepare_done(): # -------------- # call prepare() # -------------- self.set_indexer_prepare_done(True) self._index_prepare() # -------------------------------------------- # then do the proper indexing - using the best # solution already stored if available (c/f # eliminate above) # -------------------------------------------- self.set_indexer_done(True) if self.get_indexer_sweeps(): xsweeps = [ s.get_name() for s in self.get_indexer_sweeps() ] if len(xsweeps) > 1: # find "SWEEPn, SWEEP(n+1), (..), SWEEPm" and aggregate to "SWEEPS n-m" xsweeps = map(lambda x: (int(x[5:]), int(x[5:])) if x.startswith('SWEEP') else x, xsweeps) xsweeps[0] = [xsweeps[0]] def compress(seen, nxt): if isinstance(seen[-1], tuple) and isinstance(nxt, tuple) and (seen[-1][1] + 1 == nxt[0]): seen[-1] = (seen[-1][0], nxt[1]) else: seen.append(nxt) return seen xsweeps = reduce(compress, xsweeps) xsweeps = map(lambda x: ('SWEEP%d' % x[0] if x[0] == x[1] else 'SWEEPS %d to %d' % (x[0], x[1])) if isinstance(x, tuple) else x, xsweeps) if len(xsweeps) > 1: sweep_names = ', '.join(xsweeps[:-1]) sweep_names += ' & ' + xsweeps[-1] else: sweep_names = xsweeps[0] if PhilIndex.params.xia2.settings.show_template: template = self.get_indexer_sweep().get_template() Chatter.banner( 'Autoindexing %s (%s)' %(sweep_names, template)) else: Chatter.banner('Autoindexing %s' %sweep_names) if not self._indxr_helper: result = self._index() if not self._indxr_done: Debug.write( 'Looks like indexing failed - try again!') continue solutions = { } for k in self._indxr_other_lattice_cell.keys(): solutions[k] = self._indxr_other_lattice_cell[k][ 'cell'] # create a helper for the indexer to manage solutions self._indxr_helper = _IndexerHelper(solutions) solution = self._indxr_helper.get() # compare these against the final solution, if different # reject solution and return - correct solution will # be used next cycle if self._indxr_lattice != solution[0] and \ not self._indxr_input_cell and \ not PhilIndex.params.xia2.settings.integrate_p1: Chatter.write('Rerunning indexing lattice %s to %s' % (self._indxr_lattice, solution[0])) Debug.write( 'Rerunning indexing with target lattice %s' % \ solution[0]) self.set_indexer_done(False) else: # rerun autoindexing with the best known current solution solution = self._indxr_helper.get() self._indxr_input_lattice = solution[0] self._indxr_input_cell = solution[1] result = self._index() # next finish up... self.set_indexer_finish_done(True) self._index_finish() if self._indxr_print: Chatter.write(self.show_indexer_solutions())
def index(self): if not self.get_indexer_finish_done(): f = inspect.currentframe().f_back.f_back m = f.f_code.co_filename l = f.f_lineno Debug.write( "Index in %s called from %s %d" % (self.__class__.__name__, m, l) ) while not self.get_indexer_finish_done(): while not self.get_indexer_done(): while not self.get_indexer_prepare_done(): # -------------- # call prepare() # -------------- self.set_indexer_prepare_done(True) self._index_prepare() # -------------------------------------------- # then do the proper indexing - using the best # solution already stored if available (c/f # eliminate above) # -------------------------------------------- self.set_indexer_done(True) if self.get_indexer_sweeps(): xsweeps = [s.get_name() for s in self.get_indexer_sweeps()] if len(xsweeps) > 1: # find "SWEEPn, SWEEP(n+1), (..), SWEEPm" and aggregate to "SWEEPS n-m" xsweeps = map( lambda x: (int(x[5:]), int(x[5:])) if x.startswith("SWEEP") else x, xsweeps, ) xsweeps[0] = [xsweeps[0]] def compress(seen, nxt): if ( isinstance(seen[-1], tuple) and isinstance(nxt, tuple) and (seen[-1][1] + 1 == nxt[0]) ): seen[-1] = (seen[-1][0], nxt[1]) else: seen.append(nxt) return seen xsweeps = reduce(compress, xsweeps) xsweeps = map( lambda x: ( "SWEEP%d" % x[0] if x[0] == x[1] else "SWEEPS %d to %d" % (x[0], x[1]) ) if isinstance(x, tuple) else x, xsweeps, ) if len(xsweeps) > 1: sweep_names = ", ".join(xsweeps[:-1]) sweep_names += " & " + xsweeps[-1] else: sweep_names = xsweeps[0] if PhilIndex.params.xia2.settings.show_template: template = self.get_indexer_sweep().get_template() Chatter.banner("Autoindexing %s (%s)" % (sweep_names, template)) else: Chatter.banner("Autoindexing %s" % sweep_names) if not self._indxr_helper: result = self._index() if not self._indxr_done: Debug.write("Looks like indexing failed - try again!") continue solutions = {} for k in self._indxr_other_lattice_cell.keys(): solutions[k] = self._indxr_other_lattice_cell[k]["cell"] # create a helper for the indexer to manage solutions self._indxr_helper = _IndexerHelper(solutions) solution = self._indxr_helper.get() # compare these against the final solution, if different # reject solution and return - correct solution will # be used next cycle if ( self._indxr_lattice != solution[0] and not self._indxr_input_cell and not PhilIndex.params.xia2.settings.integrate_p1 ): Chatter.write( "Rerunning indexing lattice %s to %s" % (self._indxr_lattice, solution[0]) ) Debug.write( "Rerunning indexing with target lattice %s" % solution[0] ) self.set_indexer_done(False) else: # rerun autoindexing with the best known current solution solution = self._indxr_helper.get() self._indxr_input_lattice = solution[0] self._indxr_input_cell = solution[1] result = self._index() # next finish up... self.set_indexer_finish_done(True) self._index_finish() if self._indxr_print: Chatter.write(self.show_indexer_solutions())
def index(self): if not self.get_indexer_finish_done(): f = inspect.currentframe().f_back.f_back m = f.f_code.co_filename l = f.f_lineno Debug.write('Index in %s called from %s %d' % (self.__class__.__name__, m, l)) while not self.get_indexer_finish_done(): while not self.get_indexer_done(): while not self.get_indexer_prepare_done(): # -------------- # call prepare() # -------------- self.set_indexer_prepare_done(True) self._index_prepare() # -------------------------------------------- # then do the proper indexing - using the best # solution already stored if available (c/f # eliminate above) # -------------------------------------------- self.set_indexer_done(True) if self.get_indexer_sweeps(): xsweeps = self.get_indexer_sweeps() if len(xsweeps) > 1: sweep_names = ', '.join(x.get_name() for x in xsweeps[:-1]) sweep_names += ' & ' + xsweeps[-1].get_name() else: sweep_names = xsweeps[0].get_name() if PhilIndex.params.xia2.settings.show_template: template = self.get_indexer_sweep().get_template() Chatter.banner( 'Autoindexing %s (%s)' %(sweep_names, template)) else: Chatter.banner('Autoindexing %s' %sweep_names) if not self._indxr_helper: result = self._index() if not self._indxr_done: Debug.write( 'Looks like indexing failed - try again!') continue solutions = { } for k in self._indxr_other_lattice_cell.keys(): solutions[k] = self._indxr_other_lattice_cell[k][ 'cell'] # create a helper for the indexer to manage solutions self._indxr_helper = _IndexerHelper(solutions) solution = self._indxr_helper.get() # compare these against the final solution, if different # reject solution and return - correct solution will # be used next cycle if self._indxr_lattice != solution[0] and \ not self._indxr_input_cell and \ not PhilIndex.params.xia2.settings.integrate_p1: Chatter.write('Rerunning indexing lattice %s to %s' % (self._indxr_lattice, solution[0])) Debug.write( 'Rerunning indexing with target lattice %s' % \ solution[0]) self.set_indexer_done(False) else: # rerun autoindexing with the best known current solution solution = self._indxr_helper.get() self._indxr_input_lattice = solution[0] self._indxr_input_cell = solution[1] result = self._index() # next finish up... self.set_indexer_finish_done(True) self._index_finish() if self._indxr_print: Chatter.write(self.show_indexer_solutions()) # FIXED 23/OCT/06 at this stage I need to look at the list of # reasonable solutions and try to figure out if the indexing # program has picked the highest - if not, then constrain the # unit cell (need to implement this somewhere, sure it's # around!) then rerun the autoindexing (perhaps?) with this # new target - this means that we are always working from the # top downwards with these things. Once we decide somewhere # else (e.g. in cell refinement) that this cell isn't good # then we can eliminate it from the list, select the next # lower symmetry solution and continue. This solution is a # general one, so may be implemented in the general indexer # interface rather than in specific code... return