Example #1
0
def getXMLFromPW(xml_file):
    """
    Get the dictionary from the xml output.

    :param xml_file: The location of the .xml file that we need
    :returns: return the python dictionary that contains all the information
    """

    pw_document = qeschema.PwDocument()
    pw_document.read(xml_file)
    dict_data = pw_document.to_dict()
    
    return dict_data
Example #2
0
    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)
Example #3
0
    if __package__ is None:
        from os import path
        sys.path.append(path.abspath(path.dirname(__file__) + '/../'))

    import qeschema
    import os
    import xml.etree.ElementTree as Etree

    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
Example #4
0
    if __package__ is None:
        from os import path
        sys.path.append(path.abspath(path.dirname(__file__) + '/../'))

    import qeschema
    import os
    import xml.etree.ElementTree as Etree

    qeschema.set_logger(args.verbosity)

    input_fn = getattr(args, 'in')
    tree = Etree.parse(input_fn)
    root = tree.getroot()
    elementName = root.tag.split('}')[-1]
    if elementName == 'espresso':
        xml_conf = qeschema.PwDocument()
    elif elementName == 'nebRun':
        xml_conf = qeschema.NebDocument()
    elif elementName == 'espressoph':
        xml_conf = qeschema.PhononDocument()
    elif elementName == 'tddfpt':
        xml_conf = qeschema.TdDocument()
    elif elementName == 'spectrumDoc':
        xml_conf = qeschema.SpectrumDocument()
    else:
        sys.stderr.write("Could not find correct XML in %s, exiting...\n" %
                         input_fn)
        sys.exit(1)

    root = None
    tree = None