Пример #1
0
def yaml_read_irred_perts(filename, doc_tag="!IrredPerts"):
    """Read the lisr of irreducible perturbations from file."""
    with YamlTokenizer(filename) as r:
        doc = r.next_doc_with_tag(doc_tag)
        d = myaml.load(doc.text_notag)

        return d["irred_perts"]
Пример #2
0
def yaml_read_kpoints(filename, doc_tag="!Kpoints"):
    """Read the K-points from file."""
    with YamlTokenizer(filename) as r:
        doc = r.next_doc_with_tag(doc_tag)
        d = myaml.load(doc.text_notag)

        return np.array(d["reduced_coordinates_of_qpoints"])
Пример #3
0
def yaml_read_irred_perts(filename, doc_tag="!IrredPerts"):
    """Read the lisr of irreducible perturbations from file."""
    with YamlTokenizer(filename) as r:
        doc = r.next_doc_with_tag(doc_tag)
        d = myaml.load(doc.text_notag)

        return d["irred_perts"]
Пример #4
0
def yaml_read_kpoints(filename, doc_tag="!Kpoints"):
    """Read the K-points from file."""
    with YamlTokenizer(filename) as r:
        doc = r.next_doc_with_tag(doc_tag)
        d = myaml.load(doc.text_notag)

        return np.array(d["reduced_coordinates_of_qpoints"])
Пример #5
0
    def parse(filename):
        """
        This is the new parser, it will be used when we implement
        the new format in abinit.
        """
        run_completed = False
        filename = os.path.abspath(filename)
        report = EventReport(filename)

        # TODO Use CamelCase for the Fortran messages.
        w = WildCard("*Error|*Warning|*Comment|*ERROR|*WARNING|*COMMENT")

        with YamlTokenizer(filename) as tokens:

            for doc in tokens:
                #print(80*"*")
                #print("doc.tag", doc.tag)
                #print("doc",doc)
                #print(80*"*")
                if w.match(doc.tag):
                    #print("got doc.tag", doc.tag,"--")
                    try:
                        event = myaml.load(doc.text)
                    except:
                        # Wrong YAML doc. Check tha doc tag and instantiate the proper event.
                        message = "Malformatted YAML document at line: %d\n" % doc.lineno
                        message += doc.text
                        # This call is very expensive when we have many exceptions due to malformatted YAML docs.
                        #message += "Traceback:\n %s" % straceback()

                        if "error" in doc.tag.lower():
                            print("It seems an error", doc.tag)
                            event = AbinitYamlError(message=message,
                                                    src_file=__file__,
                                                    src_line=0)
                        else:
                            event = AbinitYamlWarning(message=message,
                                                      src_file=__file__,
                                                      src_line=0)

                    event.lineno = doc.lineno
                    report.append(event)

                # Check whether the calculation completed.
                if doc.tag == "!FinalSummary":
                    run_completed = True

        # TODO: Add YAML doc with FinalSummary.
        #MAGIC = "Calculation completed."
        #with open(filename) as fh:
        #    for line in fh:
        #        if MAGIC in line:
        #            run_completed = True
        #            break

        report.set_run_completed(run_completed)
        return report
Пример #6
0
    def parse(filename):
        """
        This is the new parser, it will be used when we implement
        the new format in abinit.
        """
        run_completed = False
        filename = os.path.abspath(filename)
        report = EventReport(filename)

        # TODO Use CamelCase for the Fortran messages.
        w = WildCard("*Error|*Warning|*Comment|*ERROR|*WARNING|*COMMENT")

        with YamlTokenizer(filename) as tokens:

            for doc in tokens:
                #print(80*"*")
                #print("doc.tag", doc.tag)
                #print("doc",doc)
                #print(80*"*")
                if w.match(doc.tag):
                    #print("got doc.tag", doc.tag,"--")
                    try:
                        event = myaml.load(doc.text)
                    except:
                        # Wrong YAML doc. Check tha doc tag and instantiate the proper event.
                        message = "Malformatted YAML document at line: %d\n" % doc.lineno
                        message += doc.text
                        # This call is very expensive when we have many exceptions due to malformatted YAML docs. 
                        #message += "Traceback:\n %s" % straceback()

                        if "error" in doc.tag.lower():
                            print("It seems an error",doc.tag)
                            event = AbinitYamlError(message=message, src_file=__file__, src_line=0)
                        else:
                            event = AbinitYamlWarning(message=message, src_file=__file__, src_line=0)

                    event.lineno = doc.lineno
                    report.append(event)

                # Check whether the calculation completed.
                if doc.tag == "!FinalSummary":
                    run_completed = True

        # TODO: Add YAML doc with FinalSummary.
        #MAGIC = "Calculation completed."
        #with open(filename) as fh:
        #    for line in fh:
        #        if MAGIC in line:
        #            run_completed = True
        #            break

        report.set_run_completed(run_completed)
        return report
Пример #7
0
 def from_file(cls, filepath):
     """Read the configuration parameters from a Yaml file."""
     with open(filepath, "r") as fh:
         d = myaml.load(fh)
         return cls(**d)
Пример #8
0
 def from_file(cls, filepath):
     """Read the configuration parameters from a Yaml file."""
     with open(filepath, "r") as fh:
         d = myaml.load(fh)
         return cls(**d)