def test(self): tree = ElementTree.parse(xml_file) root = tree.getroot() element_name = root.tag.split('}')[-1] if element_name == 'espresso': xml_conf = qeschema.PwDocument(source=xml_file) elif element_name == 'nebRun': xml_conf = qeschema.NebDocument(source=xml_file) elif element_name == 'espressoph': xml_conf = qeschema.PhononDocument(source=xml_file) elif element_name == 'tddfpt': xml_conf = qeschema.TdDocument(source=xml_file) elif element_name == 'spectrumDoc': xml_conf = qeschema.TdSpectrumDocument(source=xml_file) else: raise ValueError( "XML file %r is not a Quantum ESPRESSO document!" % xml_file) xml_conf.read(xml_file) qe_input = xml_conf.get_fortran_input().split('\n') with open(ref_in_file, 'r') as qe_input_file: k = 0 are_equals = True for ref_line in qe_input_file: ref_line = ref_line.rstrip('\n').strip(' \t') in_line = qe_input[k].strip(' \t') if ref_line != in_line: print("Unmatched lines: '%s' != '%s'" % (in_line, ref_line)) are_equals = False break else: k += 1 self.assertTrue(are_equals, xml_file)
qeschema.set_logger(args.verbosity) input_fn = getattr(args, 'in') tree = Etree.parse(input_fn) root = tree.getroot() element_name = root.tag.split('}')[-1] if element_name == 'espresso': xml_document = qeschema.PwDocument() elif element_name == 'nebRun': xml_document = qeschema.NebDocument() elif element_name == 'espressoph': xml_document = qeschema.PhononDocument() elif element_name == 'tddfpt': xml_document = qeschema.TdDocument() elif element_name == 'spectrumDoc': xml_document = qeschema.TdSpectrumDocument() else: sys.stderr.write("Could not find correct XML in %s, exiting...\n" % input_fn) sys.exit(1) root = None tree = None xml_document.read(input_fn) qe_in = xml_document.get_fortran_input() input_fn_name, input_fn_ext = os.path.splitext(input_fn) outfile = input_fn_name + '.in' with open(outfile, mode='w') as f: