aboutsummaryrefslogtreecommitdiff
path: root/schroedinger/schrodinger_solve.py
blob: a759c3a231642a825fbff91e17e29daa40f6ab2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import numpy as np
from pathlib import Path
import argparse

class Config:
    def __init__(self, path):
        current_line = 0

        # Ensure Path object
        if path is not Path:
            path = Path(path)

        def next_parameter(fd):
            '''Read next parameter, ignoring comments or empty lines'''
            content = None
            nonlocal current_line
            while not content:
                str = fd.readline()
                current_line += 1
                index = str.find('#')
                content = str[0:index].strip()
            return content

        with open(path, 'r') as fd:
            try:
                self.mass = float(next_parameter(fd))
                self.interval = [float(attr) for attr in next_parameter(fd).split()]
                self.eig_interval = [int(attr) for attr in next_parameter(fd).split()]
                self.interpolation = next_parameter(fd)

                npoints = int(next_parameter(fd))
                self.points = np.zeros((npoints, 2))
                for i in range(npoints):
                    line = next_parameter(fd)
                    self.points[i] = np.array([float(comp) for comp in line.split()])
            except:
                print('Syntax error in \'{}\' line {}'.format(path.name, current_line))


def main():
    parser = argparse.ArgumentParser(
        prog='schrodinger_solve',
        description='a',
        epilog='a')
    parser.add_argument('filename')
    args = parser.parse_args()
    conf = Config(args.filename)
    print(conf.mass)
    print(conf.interval)
    print(conf.eig_interval)
    print(conf.interpolation)
    print(conf.points)

if __name__ == '__main__':
    main()