def xds_to_mtz(self): """Use pointless to convert XDS file to MTZ.""" if not self._xdsin: raise RuntimeError("XDSIN not set") self.check_hklout() # -c for copy - just convert the file to MTZ multirecord self.add_command_line("-c") self.start() if self._pname and self._xname and self._dname: self.input( "name project %s crystal %s dataset %s" % (self._pname, self._xname, self._dname) ) self.input("xdsin %s" % self._xdsin) if self._scale_factor: Debug.write("Scaling intensities by factor %e" % self._scale_factor) self.input("multiply %e" % self._scale_factor) self.close_wait() # FIXME need to check the status and so on here if self._xdsin: from xia2.Wrappers.XDS import XDS XDS.add_xds_version_to_mtz_history(self.get_hklout())
def add_xds_version_to_mtz_history(mtz_file): import time from iotbx.reflection_file_reader import any_reflection_file from xia2.Wrappers.XDS import XDS reader = any_reflection_file(mtz_file) assert reader.file_type() == 'ccp4_mtz' mtz_object = reader.file_content() date_str = time.strftime('%d/%m/%Y at %H:%M:%S', time.gmtime()) mtz_object.add_history('From XDS %s, run on %s' % (XDS.get_xds_version(), date_str)) mtz_object.write(mtz_file)
def decide_spacegroup(self): """Given data indexed in the correct pointgroup, have a guess at the spacegroup.""" if not self._xdsin: self.check_hklin() self.set_task( "Computing the correct spacegroup for %s" % self.get_hklin() ) else: Debug.write("Pointless using XDS input file %s" % self._xdsin) self.set_task( "Computing the correct spacegroup 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()) self.add_command_line("hklout") self.add_command_line("pointless.mtz") self.start() self.input("lauegroup hklin") self.input("setting symmetry-based") if PhilIndex.params.xia2.settings.symmetry.chirality is not None: self.input( "chirality %s" % PhilIndex.params.xia2.settings.symmetry.chirality ) self.close_wait() # check for errors self.check_for_errors() xml_file = os.path.join( self.get_working_directory(), "%d_pointless.xml" % self.get_xpid() ) mend_pointless_xml(xml_file) if not os.path.exists(xml_file) and os.path.exists("%s.xml" % xml_file): xml_file = "%s.xml" % xml_file dom = xml.dom.minidom.parse(xml_file) sg_list = dom.getElementsByTagName("SpacegroupList")[0] sg_node = sg_list.getElementsByTagName("Spacegroup")[0] best_prob = float( sg_node.getElementsByTagName("TotalProb")[0].childNodes[0].data.strip() ) # FIXME 21/NOV/06 in here record a list of valid spacegroups # (that is, those which are as likely as the most likely) # for later use... self._spacegroup = ( sg_node.getElementsByTagName("SpacegroupName")[0] .childNodes[0] .data.strip() ) self._spacegroup_reindex_operator = ( sg_node.getElementsByTagName("ReindexOperator")[0] .childNodes[0] .data.strip() ) self._spacegroup_reindex_matrix = tuple( map( float, sg_node.getElementsByTagName("ReindexMatrix")[0] .childNodes[0] .data.split(), ) ) # get a list of "equally likely" spacegroups for node in sg_list.getElementsByTagName("Spacegroup"): prob = float( node.getElementsByTagName("TotalProb")[0].childNodes[0].data.strip() ) name = ( node.getElementsByTagName("SpacegroupName")[0] .childNodes[0] .data.strip() ) if math.fabs(prob - best_prob) < 0.01: # this is jolly likely! self._likely_spacegroups.append(name) # now parse the output looking for the unit cell information - # this should look familiar from mtzdump output = self.get_all_output() length = len(output) a = 0.0 b = 0.0 c = 0.0 alpha = 0.0 beta = 0.0 gamma = 0.0 self._cell_info["datasets"] = [] self._cell_info["dataset_info"] = {} for i in range(length): line = output[i][:-1] if "Dataset ID, " in line: block = 0 while output[block * 5 + i + 2].strip(): dataset_number = int(output[5 * block + i + 2].split()[0]) project = output[5 * block + i + 2][10:].strip() crystal = output[5 * block + i + 3][10:].strip() dataset = output[5 * block + i + 4][10:].strip() cell = map(float, output[5 * block + i + 5].strip().split()) wavelength = float(output[5 * block + i + 6].strip()) dataset_id = "%s/%s/%s" % (project, crystal, dataset) self._cell_info["datasets"].append(dataset_id) self._cell_info["dataset_info"][dataset_id] = {} self._cell_info["dataset_info"][dataset_id][ "wavelength" ] = wavelength self._cell_info["dataset_info"][dataset_id]["cell"] = cell self._cell_info["dataset_info"][dataset_id][ "id" ] = dataset_number block += 1 for dataset in self._cell_info["datasets"]: cell = self._cell_info["dataset_info"][dataset]["cell"] a += cell[0] b += cell[1] c += cell[2] alpha += cell[3] beta += cell[4] gamma += cell[5] n = len(self._cell_info["datasets"]) self._cell = (a / n, b / n, c / n, alpha / n, beta / n, gamma / n) if self._xdsin: from xia2.Wrappers.XDS import XDS XDS.add_xds_version_to_mtz_history(self.get_hklout()) return "ok"