-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
138 lines (117 loc) · 3.87 KB
/
config.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import configparser
import os.path
import pathlib
import logging
class Config:
# Environment
config_path: str
filename: str
output: pathlib.Path
# Internal settings
mol_id_start = int()
mol_id_stop = 0
ref_num_start = 0
# OPSIN settings
opsin_format: str
acid: bool
radicals: bool
bad_stereo: bool
wildcard_radicals: bool
# Gaussian settings
cores: int
memory: int
checkpoint: bool
theory: str
basis: str
calc_type: list
charge: int
spin: int
modred: list
# Colors
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
SUNDERLINE = '\033[24m'
def __init__(self, config_path: str = "./config.ini"):
"""
Initialize config class with path of existing file, or if one does not exist
create a new file and read it.
:param config_path:
"""
config_logger = logging.getLogger('GCMSpyDFT.config')
self.config_path = config_path
if os.path.isfile(config_path):
config_logger.info("Config file found, loading settings...")
self.read_config()
else:
config_logger.info("Config file not found, writing settings...")
self.make_config(config_path)
self.read_config()
def __str__(self):
return str(self.__class__) + '\n' + '\n'.join(
('{} = {}'.format(item, self.__dict__[item]) for item in self.__dict__))
def read_config(self):
config = configparser.ConfigParser()
config.read(self.config_path)
# all variables to read from file into config class
self.filename = config['Environment']['input file']
self.output = pathlib.Path(config['Environment']['output dir'])
# OPSIN Settings
self.opsin_format = config['OPSIN']['output format']
self.acid = config.getboolean('OPSIN', 'allow acid')
self.radicals = config.getboolean('OPSIN', 'allow radicals')
self.bad_stereo = config.getboolean('OPSIN', 'allow bad stereo')
self.wildcard_radicals = config.getboolean('OPSIN', 'wildcard radicals')
# Gaussian file header
self.cores = int(config['File']['cores'])
self.memory = int(config['File']['memory'])
self.checkpoint = config.getboolean('File', 'checkpoint')
# old checkpoint ?
# Gaussian route commands
self.theory = config['Route']['theory']
self.basis = config['Route']['basis set']
self.calc_type = config['Route']['calc type'].split(',')
self.charge = int(config['Molecule Specs']['charge'])
self.spin = int(config['Molecule Specs']['spin'])
def make_config(self, config_path="./config.ini"):
self.config_path = config_path
config = configparser.ConfigParser()
# Added categorises and variables to be added to config file here.
config['Environment'] = {
"Input File": './input.txt',
"Output Dir": './output/',
}
config['OPSIN'] = {
"Output Format": 'SMILES',
"Allow Acid": 'Yes',
"Allow Radicals": 'Yes',
"Allow Bad Stereo": 'No',
"Wildcard Radicals": 'No'
}
config['File'] = {
"Cores": '28',
"Memory": '50',
"Checkpoint": 'Yes',
"Old Checkpoint": 'No',
}
config['Route'] = {
"Theory": 'B3LYP',
"Basis Set": '6-31G',
"Calc Type": 'Opt'
}
config['Molecule Specs'] = {
"Charge": '0',
"Spin": '1'
}
with open(config_path, 'w') as config_file:
config.write(config_file)
cfg = Config()
if __name__ == '__main__':
f = Config()
print(f)