def reindex(hklin, hklout, change_of_basis_op, space_group=None): if not isinstance(change_of_basis_op, sgtbx.change_of_basis_op): change_of_basis_op = sgtbx.change_of_basis_op( str(clean_reindex_operator(change_of_basis_op))) if space_group is not None and not isinstance(space_group, sgtbx.space_group): space_group = sgtbx.space_group_info(str(space_group)).group() mtz_obj = iotbx.mtz.object(file_name=hklin) original_index_miller_indices = mtz_obj.extract_original_index_miller_indices( ) reindexed_miller_indices = change_of_basis_op.apply( original_index_miller_indices) if space_group is not None: mtz_obj.set_space_group(space_group) mtz_obj.replace_original_index_miller_indices(reindexed_miller_indices) mtz_obj.write(hklout)
def decide_pointgroup(self): '''Decide on the correct pointgroup for hklin.''' if not self._xdsin: self.check_hklin() self.set_task('Computing the correct pointgroup for %s' % \ self.get_hklin()) else: Debug.write('Pointless using XDS input file %s' % \ self._xdsin) self.set_task('Computing the correct pointgroup for %s' % \ self.get_xdsin()) # FIXME this should probably be a standard CCP4 keyword if self._xdsin: self.add_command_line('xdsin') self.add_command_line(self._xdsin) self.add_command_line('xmlout') self.add_command_line('%d_pointless.xml' % self.get_xpid()) if self._hklref: self.add_command_line('hklref') self.add_command_line(self._hklref) self.start() self.input('systematicabsences off') self.input('setting symmetry-based') if self._hklref: from xia2.Handlers.Phil import PhilIndex dev = PhilIndex.params.xia2.settings.developmental if dev.pointless_tolerance > 0.0: self.input('tolerance %f' % dev.pointless_tolerance) # may expect more %age variation for small molecule data if Flags.get_small_molecule() and self._hklref: self.input('tolerance 5.0') if Flags.get_small_molecule(): self.input('chirality nonchiral') if self._input_laue_group: self.input('lauegroup %s' % self._input_laue_group) self.close_wait() # check for errors self.check_for_errors() # check for fatal errors output = self.get_all_output() for j, record in enumerate(output): if 'FATAL ERROR message:' in record: raise RuntimeError, 'Pointless error: %s' % output[j+1].strip() hklin_spacegroup = '' hklin_lattice = '' for o in self.get_all_output(): if 'Spacegroup from HKLIN file' in o: # hklin_spacegroup = o.split(':')[-1].strip() hklin_spacegroup = spacegroup_name_xHM_to_old( o.replace( 'Spacegroup from HKLIN file :', '').strip()) hklin_lattice = Syminfo.get_lattice(hklin_spacegroup) if 'No alternative indexing possible' in o: # then the XML file will be broken - no worries... self._pointgroup = hklin_spacegroup self._confidence = 1.0 self._totalprob = 1.0 self._reindex_matrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self._reindex_operator = 'h,k,l' return 'ok' if '**** Incompatible symmetries ****' in o: raise RuntimeError, \ 'reindexing against a reference with different symmetry' if '***** Stopping because cell discrepancy between files' in o: raise RuntimeError, 'incompatible unit cells between data sets' if 'L-test suggests that the data may be twinned' in o: self._probably_twinned = True # parse the XML file for the information I need... xml_file = os.path.join(self.get_working_directory(), '%d_pointless.xml' % self.get_xpid()) mend_pointless_xml(xml_file) # catch the case sometimes on ppc mac where pointless adds # an extra .xml on the end... if not os.path.exists(xml_file) and \ os.path.exists('%s.xml' % xml_file): xml_file = '%s.xml' % xml_file if not self._hklref: dom = xml.dom.minidom.parse(xml_file) try: best = dom.getElementsByTagName('BestSolution')[0] except IndexError, e: raise RuntimeError, 'error getting solution from pointless' self._pointgroup = best.getElementsByTagName( 'GroupName')[0].childNodes[0].data self._confidence = float(best.getElementsByTagName( 'Confidence')[0].childNodes[0].data) self._totalprob = float(best.getElementsByTagName( 'TotalProb')[0].childNodes[0].data) self._reindex_matrix = map(float, best.getElementsByTagName( 'ReindexMatrix')[0].childNodes[0].data.split()) self._reindex_operator = clean_reindex_operator( best.getElementsByTagName( 'ReindexOperator')[0].childNodes[0].data.strip())
raise RuntimeError, 'error finding HKLREF pointgroup' self._pointgroup = hklref_pointgroup self._confidence = 1.0 self._totalprob = 1.0 if best: index = best.getElementsByTagName('Index')[0] self._reindex_matrix = map(float, index.getElementsByTagName( 'ReindexMatrix')[0].childNodes[0].data.split()) self._reindex_operator = clean_reindex_operator( index.getElementsByTagName( 'ReindexOperator')[0].childNodes[0].data.strip()) else: # no alternative indexing is possible so just # assume the default... self._reindex_matrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self._reindex_operator = 'h,k,l' if not self._input_laue_group and not self._hklref: scorelist = dom.getElementsByTagName('LaueGroupScoreList')[0]
def decide_pointgroup(self, ignore_errors=False, batches=None): """Decide on the correct pointgroup for hklin.""" if not self._xdsin: self.check_hklin() self.set_task( "Computing the correct pointgroup for %s" % self.get_hklin() ) else: Debug.write("Pointless using XDS input file %s" % self._xdsin) self.set_task( "Computing the correct pointgroup for %s" % self.get_xdsin() ) # FIXME this should probably be a standard CCP4 keyword if self._xdsin: self.add_command_line("xdsin") self.add_command_line(self._xdsin) self.add_command_line("xmlout") self.add_command_line("%d_pointless.xml" % self.get_xpid()) if self._hklref: self.add_command_line("hklref") self.add_command_line(self._hklref) self.start() if self._allow_out_of_sequence_files: self.input("allow outofsequencefiles") # https://github.com/xia2/xia2/issues/125 pass in run limits for this # HKLIN file - prevents automated RUN determination from causing errors if batches: self.input("run 1 batch %d to %d" % tuple(batches)) self.input("systematicabsences off") self.input("setting symmetry-based") if self._hklref: dev = PhilIndex.params.xia2.settings.developmental if dev.pointless_tolerance > 0.0: self.input("tolerance %f" % dev.pointless_tolerance) # may expect more %age variation for small molecule data if PhilIndex.params.xia2.settings.small_molecule: if self._hklref: self.input("tolerance 5.0") if PhilIndex.params.xia2.settings.symmetry.chirality is not None: self.input( "chirality %s" % PhilIndex.params.xia2.settings.symmetry.chirality ) if self._input_laue_group: self.input("lauegroup %s" % self._input_laue_group) self.close_wait() # check for errors self.check_for_errors() # check for fatal errors output = self.get_all_output() fatal_error = False for j, record in enumerate(output): if "FATAL ERROR message:" in record: if ignore_errors: fatal_error = True else: raise RuntimeError( "Pointless error: %s" % output[j + 1].strip() ) if ( "Resolution range of Reference data and observed data do not" in record and ignore_errors ): fatal_error = True if "All reflection pairs rejected" in record and ignore_errors: fatal_error = True if ( "Reference data and observed data do not overlap" in record and ignore_errors ): fatal_error = True hklin_spacegroup = "" # split loop - first seek hklin symmetry then later look for everything # else for o in self.get_all_output(): if "Spacegroup from HKLIN file" in o: hklin_spacegroup = spacegroup_name_xHM_to_old( o.replace("Spacegroup from HKLIN file :", "").strip() ) if "Space group from HKLREF file" in o: hklref_spacegroup = spacegroup_name_xHM_to_old( o.replace("Space group from HKLREF file :", "").strip() ) # https://github.com/xia2/xia2/issues/115 if fatal_error: assert hklref_spacegroup self._pointgroup = hklref_spacegroup self._confidence = 1.0 self._totalprob = 1.0 self._reindex_matrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self._reindex_operator = "h,k,l" return "ok" for o in self.get_all_output(): if "No alternative indexing possible" in o: # then the XML file will be broken - no worries... self._pointgroup = hklin_spacegroup self._confidence = 1.0 self._totalprob = 1.0 self._reindex_matrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self._reindex_operator = "h,k,l" return "ok" if "**** Incompatible symmetries ****" in o: raise RuntimeError( "reindexing against a reference with different symmetry" ) if "***** Stopping because cell discrepancy between files" in o: raise RuntimeError("incompatible unit cells between data sets") if "L-test suggests that the data may be twinned" in o: self._probably_twinned = True # parse the XML file for the information I need... xml_file = os.path.join( self.get_working_directory(), "%d_pointless.xml" % self.get_xpid() ) mend_pointless_xml(xml_file) # catch the case sometimes on ppc mac where pointless adds # an extra .xml on the end... if not os.path.exists(xml_file) and os.path.exists("%s.xml" % xml_file): xml_file = "%s.xml" % xml_file if not self._hklref: dom = xml.dom.minidom.parse(xml_file) try: best = dom.getElementsByTagName("BestSolution")[0] except IndexError: raise RuntimeError("error getting solution from pointless") self._pointgroup = ( best.getElementsByTagName("GroupName")[0].childNodes[0].data ) self._confidence = float( best.getElementsByTagName("Confidence")[0].childNodes[0].data ) self._totalprob = float( best.getElementsByTagName("TotalProb")[0].childNodes[0].data ) self._reindex_matrix = map( float, best.getElementsByTagName("ReindexMatrix")[0] .childNodes[0] .data.split(), ) self._reindex_operator = clean_reindex_operator( best.getElementsByTagName("ReindexOperator")[0] .childNodes[0] .data.strip() ) else: # if we have provided a HKLREF input then the xml output # is changed... # FIXME in here, need to check if there is the legend # "No possible alternative indexing" in the standard # output, as this will mean that the index scores are # not there... c/f oppf1314, with latest pointless build # 1.2.14. dom = xml.dom.minidom.parse(xml_file) try: best = dom.getElementsByTagName("IndexScores")[0] except IndexError: Debug.write("Reindex not found in xml output") # check for this legend then found = False for record in self.get_all_output(): if "No possible alternative indexing" in record: found = True if not found: raise RuntimeError("error finding solution") best = None hklref_pointgroup = "" # FIXME need to get this from the reflection file HKLREF reflection_file_elements = dom.getElementsByTagName("ReflectionFile") for rf in reflection_file_elements: stream = rf.getAttribute("stream") if stream == "HKLREF": hklref_pointgroup = ( rf.getElementsByTagName("SpacegroupName")[0] .childNodes[0] .data.strip() ) # Chatter.write('HKLREF pointgroup is %s' % \ # hklref_pointgroup) if hklref_pointgroup == "": raise RuntimeError("error finding HKLREF pointgroup") self._pointgroup = hklref_pointgroup self._confidence = 1.0 self._totalprob = 1.0 if best: index = best.getElementsByTagName("Index")[0] self._reindex_matrix = map( float, index.getElementsByTagName("ReindexMatrix")[0] .childNodes[0] .data.split(), ) self._reindex_operator = clean_reindex_operator( index.getElementsByTagName("ReindexOperator")[0] .childNodes[0] .data.strip() ) else: # no alternative indexing is possible so just # assume the default... self._reindex_matrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self._reindex_operator = "h,k,l" if not self._input_laue_group and not self._hklref: scorelist = dom.getElementsByTagName("LaueGroupScoreList")[0] scores = scorelist.getElementsByTagName("LaueGroupScore") for s in scores: lauegroup = ( s.getElementsByTagName("LaueGroupName")[0].childNodes[0].data ) netzc = float( s.getElementsByTagName("NetZCC")[0].childNodes[0].data ) # record this as a possible lattice if its Z score is positive lattice = lauegroup_to_lattice(lauegroup) if not lattice in self._possible_lattices: if netzc > 0.0: self._possible_lattices.append(lattice) # do we not always want to have access to the # solutions, even if they are unlikely - this will # only be invoked if they are known to # be right... self._lattice_to_laue[lattice] = lauegroup return "ok"
def decide_pointgroup(self): """Decide on the correct pointgroup for hklin.""" if not self._xdsin: self.check_hklin() self.set_task("Computing the correct pointgroup for %s" % self.get_hklin()) else: Debug.write("Pointless using XDS input file %s" % self._xdsin) self.set_task("Computing the correct pointgroup for %s" % self.get_xdsin()) # FIXME this should probably be a standard CCP4 keyword if self._xdsin: self.add_command_line("xdsin") self.add_command_line(self._xdsin) self.add_command_line("xmlout") self.add_command_line("%d_pointless.xml" % self.get_xpid()) if self._hklref: self.add_command_line("hklref") self.add_command_line(self._hklref) self.start() self.input("systematicabsences off") self.input("setting symmetry-based") if self._hklref: dev = PhilIndex.params.xia2.settings.developmental if dev.pointless_tolerance > 0.0: self.input("tolerance %f" % dev.pointless_tolerance) # may expect more %age variation for small molecule data if PhilIndex.params.xia2.settings.small_molecule == True: if self._hklref: self.input("tolerance 5.0") if PhilIndex.params.ccp4.pointless.chirality is not None: self.input("chirality %s" % PhilIndex.params.ccp4.pointless.chirality) if self._input_laue_group: self.input("lauegroup %s" % self._input_laue_group) self.close_wait() # check for errors self.check_for_errors() # check for fatal errors output = self.get_all_output() for j, record in enumerate(output): if "FATAL ERROR message:" in record: raise RuntimeError, "Pointless error: %s" % output[j + 1].strip() hklin_spacegroup = "" hklin_lattice = "" for o in self.get_all_output(): if "Spacegroup from HKLIN file" in o: # hklin_spacegroup = o.split(':')[-1].strip() hklin_spacegroup = spacegroup_name_xHM_to_old(o.replace("Spacegroup from HKLIN file :", "").strip()) hklin_lattice = Syminfo.get_lattice(hklin_spacegroup) if "No alternative indexing possible" in o: # then the XML file will be broken - no worries... self._pointgroup = hklin_spacegroup self._confidence = 1.0 self._totalprob = 1.0 self._reindex_matrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self._reindex_operator = "h,k,l" return "ok" if "**** Incompatible symmetries ****" in o: raise RuntimeError, "reindexing against a reference with different symmetry" if "***** Stopping because cell discrepancy between files" in o: raise RuntimeError, "incompatible unit cells between data sets" if "L-test suggests that the data may be twinned" in o: self._probably_twinned = True # parse the XML file for the information I need... xml_file = os.path.join(self.get_working_directory(), "%d_pointless.xml" % self.get_xpid()) mend_pointless_xml(xml_file) # catch the case sometimes on ppc mac where pointless adds # an extra .xml on the end... if not os.path.exists(xml_file) and os.path.exists("%s.xml" % xml_file): xml_file = "%s.xml" % xml_file if not self._hklref: dom = xml.dom.minidom.parse(xml_file) try: best = dom.getElementsByTagName("BestSolution")[0] except IndexError, e: raise RuntimeError, "error getting solution from pointless" self._pointgroup = best.getElementsByTagName("GroupName")[0].childNodes[0].data self._confidence = float(best.getElementsByTagName("Confidence")[0].childNodes[0].data) self._totalprob = float(best.getElementsByTagName("TotalProb")[0].childNodes[0].data) self._reindex_matrix = map( float, best.getElementsByTagName("ReindexMatrix")[0].childNodes[0].data.split() ) self._reindex_operator = clean_reindex_operator( best.getElementsByTagName("ReindexOperator")[0].childNodes[0].data.strip() )
def decide_pointgroup(self, ignore_errors=False, batches=None): '''Decide on the correct pointgroup for hklin.''' if not self._xdsin: self.check_hklin() self.set_task('Computing the correct pointgroup for %s' % \ self.get_hklin()) else: Debug.write('Pointless using XDS input file %s' % \ self._xdsin) self.set_task('Computing the correct pointgroup for %s' % \ self.get_xdsin()) # FIXME this should probably be a standard CCP4 keyword if self._xdsin: self.add_command_line('xdsin') self.add_command_line(self._xdsin) self.add_command_line('xmlout') self.add_command_line('%d_pointless.xml' % self.get_xpid()) if self._hklref: self.add_command_line('hklref') self.add_command_line(self._hklref) self.start() if self._allow_out_of_sequence_files: self.input('allow outofsequencefiles') # https://github.com/xia2/xia2/issues/125 pass in run limits for this # HKLIN file - prevents automated RUN determination from causing errors if batches: self.input('run 1 batch %d to %d' % tuple(batches)) self.input('systematicabsences off') self.input('setting symmetry-based') if self._hklref: dev = PhilIndex.params.xia2.settings.developmental if dev.pointless_tolerance > 0.0: self.input('tolerance %f' % dev.pointless_tolerance) # may expect more %age variation for small molecule data if PhilIndex.params.xia2.settings.small_molecule == True: if self._hklref: self.input('tolerance 5.0') if PhilIndex.params.ccp4.pointless.chirality is not None: self.input('chirality %s' %PhilIndex.params.ccp4.pointless.chirality) if self._input_laue_group: self.input('lauegroup %s' % self._input_laue_group) self.close_wait() # check for errors self.check_for_errors() # check for fatal errors output = self.get_all_output() fatal_error = False for j, record in enumerate(output): if 'FATAL ERROR message:' in record: if ignore_errors: fatal_error = True else: raise RuntimeError('Pointless error: %s' % output[j+1].strip()) if 'Resolution range of Reference data and observed data do not' \ in record and ignore_errors: fatal_error = True if 'All reflection pairs rejected' in record and ignore_errors: fatal_error = True if 'Reference data and observed data do not overlap' in record and \ ignore_errors: fatal_error = True hklin_spacegroup = '' hklin_lattice = '' # split loop - first seek hklin symmetry then later look for everything # else for o in self.get_all_output(): if 'Spacegroup from HKLIN file' in o: hklin_spacegroup = spacegroup_name_xHM_to_old( o.replace( 'Spacegroup from HKLIN file :', '').strip()) hklin_lattice = Syminfo.get_lattice(hklin_spacegroup) if 'Space group from HKLREF file' in o: hklref_spacegroup = spacegroup_name_xHM_to_old( o.replace( 'Space group from HKLREF file :', '').strip()) hklref_lattice = Syminfo.get_lattice(hklref_spacegroup) # https://github.com/xia2/xia2/issues/115 if fatal_error: assert hklref_spacegroup self._pointgroup = hklref_spacegroup self._confidence = 1.0 self._totalprob = 1.0 self._reindex_matrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self._reindex_operator = 'h,k,l' return 'ok' for o in self.get_all_output(): if 'No alternative indexing possible' in o: # then the XML file will be broken - no worries... self._pointgroup = hklin_spacegroup self._confidence = 1.0 self._totalprob = 1.0 self._reindex_matrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self._reindex_operator = 'h,k,l' return 'ok' if '**** Incompatible symmetries ****' in o: raise RuntimeError( \ 'reindexing against a reference with different symmetry') if '***** Stopping because cell discrepancy between files' in o: raise RuntimeError('incompatible unit cells between data sets') if 'L-test suggests that the data may be twinned' in o: self._probably_twinned = True # parse the XML file for the information I need... xml_file = os.path.join(self.get_working_directory(), '%d_pointless.xml' % self.get_xpid()) mend_pointless_xml(xml_file) # catch the case sometimes on ppc mac where pointless adds # an extra .xml on the end... if not os.path.exists(xml_file) and \ os.path.exists('%s.xml' % xml_file): xml_file = '%s.xml' % xml_file if not self._hklref: dom = xml.dom.minidom.parse(xml_file) try: best = dom.getElementsByTagName('BestSolution')[0] except IndexError: raise RuntimeError('error getting solution from pointless') self._pointgroup = best.getElementsByTagName( 'GroupName')[0].childNodes[0].data self._confidence = float(best.getElementsByTagName( 'Confidence')[0].childNodes[0].data) self._totalprob = float(best.getElementsByTagName( 'TotalProb')[0].childNodes[0].data) self._reindex_matrix = map(float, best.getElementsByTagName( 'ReindexMatrix')[0].childNodes[0].data.split()) self._reindex_operator = clean_reindex_operator( best.getElementsByTagName( 'ReindexOperator')[0].childNodes[0].data.strip()) else: # if we have provided a HKLREF input then the xml output # is changed... # FIXME in here, need to check if there is the legend # "No possible alternative indexing" in the standard # output, as this will mean that the index scores are # not there... c/f oppf1314, with latest pointless build # 1.2.14. dom = xml.dom.minidom.parse(xml_file) try: best = dom.getElementsByTagName('IndexScores')[0] except IndexError: Debug.write('Reindex not found in xml output') # check for this legend then found = False for record in self.get_all_output(): if 'No possible alternative indexing' in record: found = True if not found: raise RuntimeError('error finding solution') best = None hklref_pointgroup = '' # FIXME need to get this from the reflection file HKLREF reflection_file_elements = dom.getElementsByTagName( 'ReflectionFile') for rf in reflection_file_elements: stream = rf.getAttribute('stream') if stream == 'HKLREF': hklref_pointgroup = rf.getElementsByTagName( 'SpacegroupName')[0].childNodes[0].data.strip() # Chatter.write('HKLREF pointgroup is %s' % \ # hklref_pointgroup) if hklref_pointgroup == '': raise RuntimeError('error finding HKLREF pointgroup') self._pointgroup = hklref_pointgroup self._confidence = 1.0 self._totalprob = 1.0 if best: index = best.getElementsByTagName('Index')[0] self._reindex_matrix = map(float, index.getElementsByTagName( 'ReindexMatrix')[0].childNodes[0].data.split()) self._reindex_operator = clean_reindex_operator( index.getElementsByTagName( 'ReindexOperator')[0].childNodes[0].data.strip()) else: # no alternative indexing is possible so just # assume the default... self._reindex_matrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self._reindex_operator = 'h,k,l' if not self._input_laue_group and not self._hklref: scorelist = dom.getElementsByTagName('LaueGroupScoreList')[0] scores = scorelist.getElementsByTagName('LaueGroupScore') lauegroups = { } netzcs = { } likelihoods = { } for s in scores: number = int(s.getElementsByTagName( 'number')[0].childNodes[0].data) lauegroup = s.getElementsByTagName( 'LaueGroupName')[0].childNodes[0].data reindex = s.getElementsByTagName( 'ReindexOperator')[0].childNodes[0].data netzc = float(s.getElementsByTagName( 'NetZCC')[0].childNodes[0].data) likelihood = float(s.getElementsByTagName( 'Likelihood')[0].childNodes[0].data) r_merge = float(s.getElementsByTagName( 'R')[0].childNodes[0].data) delta = float(s.getElementsByTagName( 'CellDelta')[0].childNodes[0].data) # record this as a possible lattice... if it's Z score # is positive, anyway lattice = lauegroup_to_lattice(lauegroup) if not lattice in self._possible_lattices: if netzc > 0.0: self._possible_lattices.append(lattice) # do we not always want to have access to the # solutions, even if they are unlikely - this will # only be invoked if they are known to # be right... self._lattice_to_laue[lattice] = lauegroup return 'ok'