-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsmiles_config.py
76 lines (56 loc) · 1.86 KB
/
smiles_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
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 23 12:00:18 2018
@author: dvizard
"""
import yaml
import io
import sys
import os
import argparse
parser = argparse.ArgumentParser(
description='Fingerprint-decoding RNN for de novo compound id.')
parser.add_argument('--config', '-c', nargs="*")
if 'JUPYTER' not in os.environ:
args, unknown = parser.parse_known_args()
else:
args, unknown = parser.parse_known_args()
FILENAME_DEFAULT = "config.yaml"
config_file = [FILENAME_DEFAULT]
if 'COMPUTERNAME' in os.environ:
FILENAME_MACHINE = "config." + os.environ['COMPUTERNAME'] + '.yaml'
config_file.append(FILENAME_MACHINE)
if args.config is not None:
config_file.extend(args.config)
config = {}
import sys, os
class Error(Exception): pass
def _find(pathname, matchFunc=os.path.isfile):
for dirname in sys.path:
candidate = os.path.join(dirname, pathname)
if matchFunc(candidate):
return candidate
raise Error("Can't find file %s" % pathname)
def findFile(pathname):
return _find(pathname)
def findDir(path):
return _find(path, matchFunc=os.path.isdir)
def config_reload(config_file = config_file, extra_config = False):
global config
if not extra_config:
config = dict()
for f in config_file:
f_ = findFile(f)
with open(f_, 'r') as stream:
config_ = yaml.load(stream, Loader=yaml.FullLoader)
config.update(config_)
for k, v in config.items():
if(type(v) == str):
config[k] = v.replace('.\\', config['base_folder'])
if "extra_config" in config and not extra_config:
config_reload(config['extra_config'], extra_config = True)
def config_dump(path):
with open(path, "w") as stream:
yaml.dump(config, stream)
config_reload()
os.environ["HDF5_USE_FILE_LOCKING"]=config['hdf5_lock']