-
Notifications
You must be signed in to change notification settings - Fork 13
/
settings.py
61 lines (51 loc) · 2.3 KB
/
settings.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
default_settings_yaml = """
# These are the default settings for fragmenstein.
# To overide please define $FRAGMENSTEIN_SETTINGS as a yaml file.
# or pass an environment variable _prior_ to import
# e.g. ff_constraint becomes $FRAGMENSTEIN_FF_CONSTRAINT.
# These will have priority over the defaults.
# Note there are no safeguards against typos.
# For the command line interface, see fragmenstein/_cli_defaults.py
# General settings
work_path: output
monster_average_position: false
monster_throw_on_discard: false
ff_minisation: true
# During the RDKit minisation, how much lee-way to give an atom before it gets penalised.
ff_max_displacement: 0.1
# During the RDKit minisation, how much to penalise an atom that is too far from its ideal position.
ff_constraint: 5.
# During the RDKit minisation, how many iterations to run.
ff_max_iterations: 200
# During the RDKit minisation, use the neighbourhood to constrain the molecule.
ff_use_neighborhood: true
ff_neighborhood: 6.0
ff_allow_lax: true
ff_prevent_cis: true
# For Wictor, weird things happen if True
ff_minimise_ideal: false
# OpenMM settings
mm_restraint_k: 1000.0
mm_tolerance: 10.0 # mmu.kilocalorie_per_mole / (mmu.nano * mmu.meter)
mm_max_iterations: 0 # 0 is infinite
mm_mobile_radius: 8.0 # mmu.angstrom
"""
import os, yaml
from pathlib import Path
from warnings import warn
from ._cli_defaults import cli_default_settings
if not os.environ.get('FRAGMENSTEIN_SETTINGS', None):
default_settings = yaml.load(default_settings_yaml, Loader=yaml.FullLoader)
elif Path(os.environ['FRAGMENSTEIN_SETTINGS']).exists():
with open(os.environ['FRAGMENSTEIN_SETTINGS']) as r:
default_settings = yaml.load(r, Loader=yaml.FullLoader)
else:
raise ValueError(f'FRAGMENSTEIN_SETTINGS={os.environ["FRAGMENSTEIN_SETTINGS"]} does not exist as a file')
for variable in os.environ:
if 'FRAGMENSTEIN_' in variable:
key = variable.replace('FRAGMENSTEIN_', '').lower()
if key not in default_settings and key not in cli_default_settings:
# there should be some kind of check here if a CLI variable is called within Python.
warn(f'Environment variable {variable} is not a valid setting and will likely be ignored')
key_type = type(default_settings.get(key, ''))
default_settings[key] = key_type(os.environ[variable])