autoparser.py 1.22 KB
Newer Older
Lauri Himanen's avatar
Lauri Himanen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import os
import json
from cp2kparser.implementation.parser import CP2KParser


#===============================================================================
def scan_path_for_files(path):

    # Define the allowed extensions
    extensions = {
        ".inp",
        ".out",
        ".xyz",
    }
    files = []
    for filename in os.listdir(path):
        extension = os.path.splitext(filename)[1]
        if extension in extensions:
            file_object = {
20
                "path": os.path.join(path, filename),
Lauri Himanen's avatar
Lauri Himanen committed
21
22
23
24
25
26
27
                "file_id": "",
            }
            files.append(file_object)
    return files


#===============================================================================
28
def get_parser(path):
Lauri Himanen's avatar
Lauri Himanen committed
29
30
31
32
33
34
35
36
37
    files = scan_path_for_files(path)
    json_input = {
        "version": "nomadparsein.json 1.0",
        "tmpDir": "/home/lauri",
        "metainfoToKeep": [],
        "metainfoToSkip": [],
        "files": files
    }
    parser = CP2KParser(json.dumps(json_input))
38
    return parser
39
40
41
42
43
44
45


#===============================================================================
if __name__ == '__main__':
    path = os.path.dirname(os.path.realpath(os.path.dirname(__file__)))
    parser = get_parser(path)
    parser.parse_all()