def convert_to_ReSpecTh(self, filename):
root = etree.Element('<STR_LIT>')<EOL>file_author = etree.SubElement(root, '<STR_LIT>')<EOL>file_author.text = self.file_authors[<NUM_LIT:0>]['<STR_LIT:name>']<EOL>file_version = etree.SubElement(root, '<STR_LIT>')<EOL>major_version = etree.SubElement(file_version, '<STR_LIT>')<EOL>major_version.text = str(self.file_version)<EOL>minor_version = etree.SubElement(file_version, '<STR_LIT>')<EOL>minor_version.text = '<STR_LIT:0>'<EOL>respecth_version = etree.SubElement(root, '<STR_LIT>')<EOL>major_version = etree.SubElement(respecth_version, '<STR_LIT>')<EOL>major_version.text = '<STR_LIT:1>'<EOL>minor_version = etree.SubElement(respecth_version, '<STR_LIT>')<EOL>minor_version.text = '<STR_LIT:0>'<EOL>exp = etree.SubElement(root, '<STR_LIT>')<EOL>if self.experiment_type == '<STR_LIT>':<EOL><INDENT>exp.text = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError('<STR_LIT>')<EOL><DEDENT>reference = etree.SubElement(root, '<STR_LIT>')<EOL>citation = '<STR_LIT>'<EOL>for author in self.reference.authors:<EOL><INDENT>citation += author['<STR_LIT:name>'] + '<STR_LIT:U+002CU+0020>'<EOL><DEDENT>citation += (self.reference.journal + '<STR_LIT>' + str(self.reference.year) + '<STR_LIT>' +<EOL>str(self.reference.volume) + '<STR_LIT::>' + self.reference.pages + '<STR_LIT>' +<EOL>self.reference.detail<EOL>)<EOL>reference.set('<STR_LIT>', citation)<EOL>reference.set('<STR_LIT>', self.reference.doi)<EOL>apparatus = etree.SubElement(root, '<STR_LIT>')<EOL>kind = etree.SubElement(apparatus, '<STR_LIT>')<EOL>kind.text = self.apparatus.kind<EOL>common_properties = etree.SubElement(root, '<STR_LIT>')<EOL>common = []<EOL>composition = self.datapoints[<NUM_LIT:0>].composition<EOL>composition_type = self.datapoints[<NUM_LIT:0>].composition_type<EOL>if not all(dp.composition_type == composition_type for dp in self.datapoints):<EOL><INDENT>raise NotImplementedError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>if all([composition == dp.composition for dp in self.datapoints]):<EOL><INDENT>common.append('<STR_LIT>')<EOL>prop = etree.SubElement(common_properties, '<STR_LIT>')<EOL>prop.set('<STR_LIT:name>', '<STR_LIT>')<EOL>for species_name, species in composition.items():<EOL><INDENT>component = etree.SubElement(prop, '<STR_LIT>')<EOL>species_link = etree.SubElement(component, '<STR_LIT>')<EOL>species_link.set('<STR_LIT>', species_name)<EOL>if species.InChI is not None:<EOL><INDENT>species_link.set('<STR_LIT>', species.InChI)<EOL><DEDENT>amount = etree.SubElement(component, '<STR_LIT>')<EOL>amount.set('<STR_LIT>', composition_type)<EOL>amount.text = str(species.amount.magnitude)<EOL><DEDENT><DEDENT>if len(self.datapoints) > <NUM_LIT:1>:<EOL><INDENT>for prop_name in datagroup_properties:<EOL><INDENT>attribute = prop_name.replace('<STR_LIT:U+0020>', '<STR_LIT:_>')<EOL>quantities = [getattr(dp, attribute, False) for dp in self.datapoints]<EOL>if all(quantities) and quantities.count(quantities[<NUM_LIT:0>]) == len(quantities):<EOL><INDENT>common.append(prop_name)<EOL>prop = etree.SubElement(common_properties, '<STR_LIT>')<EOL>prop.set('<STR_LIT:description>', '<STR_LIT>')<EOL>prop.set('<STR_LIT:name>', prop_name)<EOL>prop.set('<STR_LIT>', str(quantities[<NUM_LIT:0>].units))<EOL>value = etree.SubElement(prop, '<STR_LIT:value>')<EOL>value.text = str(quantities[<NUM_LIT:0>].magnitude)<EOL><DEDENT><DEDENT><DEDENT>datagroup = etree.SubElement(root, '<STR_LIT>')<EOL>datagroup.set('<STR_LIT:id>', '<STR_LIT>')<EOL>datagroup_link = etree.SubElement(datagroup, '<STR_LIT>')<EOL>datagroup_link.set('<STR_LIT>', '<STR_LIT>')<EOL>datagroup_link.set('<STR_LIT>', '<STR_LIT>')<EOL>property_idx = {}<EOL>labels = {'<STR_LIT>': '<STR_LIT:T>', '<STR_LIT>': '<STR_LIT:P>',<EOL>'<STR_LIT>': '<STR_LIT>', '<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>for prop_name in datagroup_properties:<EOL><INDENT>attribute = prop_name.replace('<STR_LIT:U+0020>', '<STR_LIT:_>')<EOL>prop_indices = [i for i, dp in enumerate(self.datapoints)<EOL>if getattr(dp, attribute) is not None<EOL>]<EOL>if prop_name in common or not prop_indices:<EOL><INDENT>continue<EOL><DEDENT>prop = etree.SubElement(datagroup, '<STR_LIT>')<EOL>prop.set('<STR_LIT:description>', '<STR_LIT>')<EOL>prop.set('<STR_LIT:name>', prop_name)<EOL>units = str(getattr(self.datapoints[prop_indices[<NUM_LIT:0>]], attribute).units)<EOL>prop.set('<STR_LIT>', units)<EOL>idx = '<STR_LIT>'.format(len(property_idx) + <NUM_LIT:1>)<EOL>property_idx[idx] = {'<STR_LIT:name>': prop_name, '<STR_LIT>': units}<EOL>prop.set('<STR_LIT:id>', idx)<EOL>prop.set('<STR_LIT:label>', labels[prop_name])<EOL><DEDENT>if '<STR_LIT>' not in common:<EOL><INDENT>for dp in self.datapoints:<EOL><INDENT>for species in dp.composition.values():<EOL><INDENT>has_spec = any([species.species_name in d.values()<EOL>for d in property_idx.values()<EOL>])<EOL>if not has_spec:<EOL><INDENT>prop = etree.SubElement(datagroup, '<STR_LIT>')<EOL>prop.set('<STR_LIT:description>', '<STR_LIT>')<EOL>idx = '<STR_LIT>'.format(len(property_idx) + <NUM_LIT:1>)<EOL>property_idx[idx] = {'<STR_LIT:name>': species.species_name}<EOL>prop.set('<STR_LIT:id>', idx)<EOL>prop.set('<STR_LIT:label>', '<STR_LIT:[>' + species.species_name + '<STR_LIT:]>')<EOL>prop.set('<STR_LIT:name>', '<STR_LIT>')<EOL>prop.set('<STR_LIT>', self.datapoints[<NUM_LIT:0>].composition_type)<EOL>species_link = etree.SubElement(prop, '<STR_LIT>')<EOL>species_link.set('<STR_LIT>', species.species_name)<EOL>if species.InChI is not None:<EOL><INDENT>species_link.set('<STR_LIT>', species.InChI)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>for dp in self.datapoints:<EOL><INDENT>datapoint = etree.SubElement(datagroup, '<STR_LIT>')<EOL>for idx, val in property_idx.items():<EOL><INDENT>if val['<STR_LIT:name>'] in datagroup_properties:<EOL><INDENT>value = etree.SubElement(datapoint, idx)<EOL>quantity = getattr(dp, val['<STR_LIT:name>'].replace('<STR_LIT:U+0020>', '<STR_LIT:_>')).to(val['<STR_LIT>'])<EOL>value.text = str(quantity.magnitude)<EOL><DEDENT>else:<EOL><INDENT>for item in dp.composition.values():<EOL><INDENT>if item.species_name == val['<STR_LIT:name>']:<EOL><INDENT>value = etree.SubElement(datapoint, idx)<EOL>value.text = str(item.amount.magnitude)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>history_types = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>']<EOL>time_histories = [getattr(dp, p) for dp in self.datapoints for p in history_types]<EOL>time_histories = list(filter(None.__ne__, time_histories))<EOL>if len(self.datapoints) > <NUM_LIT:1> and len(time_histories) > <NUM_LIT:1>:<EOL><INDENT>raise NotImplementedError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>elif len(time_histories) > <NUM_LIT:0>:<EOL><INDENT>for dg_idx, hist in enumerate(time_histories):<EOL><INDENT>if hist.type not in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>warn('<STR_LIT>'<EOL>'<STR_LIT>'.format(hist.type))<EOL>continue<EOL><DEDENT>datagroup = etree.SubElement(root, '<STR_LIT>')<EOL>datagroup.set('<STR_LIT:id>', '<STR_LIT>'.format(dg_idx))<EOL>datagroup_link = etree.SubElement(datagroup, '<STR_LIT>')<EOL>datagroup_link.set('<STR_LIT>', '<STR_LIT>')<EOL>datagroup_link.set('<STR_LIT>', '<STR_LIT>')<EOL>prop = etree.SubElement(datagroup, '<STR_LIT>')<EOL>prop.set('<STR_LIT:description>', '<STR_LIT>')<EOL>prop.set('<STR_LIT:name>', '<STR_LIT:time>')<EOL>prop.set('<STR_LIT>', str(hist.time.units))<EOL>time_idx = '<STR_LIT>'.format(len(property_idx) + <NUM_LIT:1>)<EOL>property_idx[time_idx] = {'<STR_LIT:name>': '<STR_LIT:time>'}<EOL>prop.set('<STR_LIT:id>', time_idx)<EOL>prop.set('<STR_LIT:label>', '<STR_LIT:t>')<EOL>prop = etree.SubElement(datagroup, '<STR_LIT>')<EOL>prop.set('<STR_LIT:description>', '<STR_LIT>')<EOL>prop.set('<STR_LIT:name>', hist.type)<EOL>prop.set('<STR_LIT>', str(hist.quantity.units))<EOL>quant_idx = '<STR_LIT>'.format(len(property_idx) + <NUM_LIT:1>)<EOL>property_idx[quant_idx] = {'<STR_LIT:name>': hist.type}<EOL>prop.set('<STR_LIT:id>', quant_idx)<EOL>prop.set('<STR_LIT:label>', '<STR_LIT>')<EOL>for time, quantity in zip(hist.time, hist.quantity):<EOL><INDENT>datapoint = etree.SubElement(datagroup, '<STR_LIT>')<EOL>value = etree.SubElement(datapoint, time_idx)<EOL>value.text = str(time.magnitude)<EOL>value = etree.SubElement(datapoint, quant_idx)<EOL>value.text = str(quantity.magnitude)<EOL><DEDENT><DEDENT><DEDENT>ign_types = [getattr(dp, '<STR_LIT>', False) for dp in self.datapoints]<EOL>if all(ign_types) and ign_types.count(ign_types[<NUM_LIT:0>]) == len(ign_types):<EOL><INDENT>ignition = etree.SubElement(root, '<STR_LIT>')<EOL>if ign_types[<NUM_LIT:0>]['<STR_LIT:target>'] in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>ignition.set('<STR_LIT:target>', ign_types[<NUM_LIT:0>]['<STR_LIT:target>'][<NUM_LIT:0>].upper())<EOL><DEDENT>else:<EOL><INDENT>ignition.set('<STR_LIT:target>', self.datapoints[<NUM_LIT:0>].ignition_type['<STR_LIT:target>'])<EOL><DEDENT>if ign_types[<NUM_LIT:0>]['<STR_LIT:type>'] == '<STR_LIT>':<EOL><INDENT>ignition.set('<STR_LIT:type>', '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>ignition.set('<STR_LIT:type>', self.datapoints[<NUM_LIT:0>].ignition_type['<STR_LIT:type>'])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise NotImplementedError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>et = etree.ElementTree(root)<EOL>et.write(filename, encoding='<STR_LIT:utf-8>', xml_declaration=True)<EOL>xml = minidom.parse(filename)<EOL>xml_string = xml.toprettyxml(indent='<STR_LIT:U+0020>')<EOL>with open(filename, '<STR_LIT:w>') as f:<EOL><INDENT>f.write(xml_string)<EOL><DEDENT>print('<STR_LIT>' + filename)<EOL>
Convert ChemKED record to ReSpecTh XML file.

        This converter uses common information in a ChemKED file to generate a
        ReSpecTh XML file. Note that some information may be lost, as ChemKED stores
        some additional attributes.

        Arguments:
            filename (`str`): Filename for output ReSpecTh XML file.

        Example:
            >>> dataset = ChemKED(yaml_file)
            >>> dataset.convert_to_ReSpecTh(xml_file)