-
Notifications
You must be signed in to change notification settings - Fork 2
/
rlmm_runner.py
87 lines (68 loc) · 2.83 KB
/
rlmm_runner.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
def setup_temp_files(config):
try:
os.mkdir(config.configs['tempdir'])
except FileExistsError:
pass
if config.configs['tempdir'][-1] == '/':
config.configs['tempdir'] = config.configs['tempdir'][:-1]
if not config.configs['overwrite_static']:
config.configs['tempdir'] = config.configs['tempdir'] + "/{}".format(
datetime.now().strftime("rlmm_%d_%m_%YT%H%M%S"))
try:
os.mkdir(config.configs['tempdir'])
except FileExistsError:
print("Somehow the directory already exists... exiting")
exit()
else:
try:
shutil.rmtree(config.configs['tempdir'])
os.mkdir(config.configs['tempdir'])
except FileExistsError:
print("Somehow the directory already exists... exiting")
exit()
config.configs['tempdir'] = FileContext(simulation_workers=1, tmpdir=config.configs['tempdir'])
for k, v in config.configs.items():
if k in ['actions', 'systemloader', 'openmmWrapper', 'obsmethods']:
for k_, v_ in config.configs.items():
if k_ != k:
v.update(k_, v_)
def run_from_yaml(yaml, steps=100):
oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Warning)
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
logging.getLogger('openforcefield').setLevel(logging.ERROR)
logging.getLogger('openmmtools').setLevel(logging.ERROR)
warnings.filterwarnings("ignore")
conf_file = yaml
config = Config.load_yaml(conf_file)
setup_temp_files(config)
shutil.copy(conf_file, f"{config.configs['tempdir']()}/config.yaml")
env = OpenMMEnv(OpenMMEnv.Config(config.configs))
policy = get_policy(env, config.configs['policy'], orig_pdb=config.configs['systemloader'].pdb_file_name)
obs, _, _, data = env.reset()
for i in range(config.configs['general']['max_iters']):
env.config.tempdir.start_step(i + 1)
if data['flew_away']:
obs = data['init_obs']
choice = policy.choose_action(obs)
print("Action taken: ", choice[1])
obs, reward, done, data = env.step(choice)
with open(config.configs['tempdir']() + "/rundata.pkl", 'wb') as f:
pickle.dump(env.data, f)
if __name__ == "__main__":
import logging
import os
import pickle
import shutil
import warnings
from datetime import datetime
from openeye import oechem
from rlmm.environment.openmmEnv import OpenMMEnv
from rlmm.rl.Expert import ExpertPolicy, get_policy
from rlmm.utils.config import Config
from rlmm.utils.filecontext import FileContext
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-c', type=str, default='expiriments/jak2/jak2_example_cuda.yaml')
args = parser.parse_args()
run_from_yaml(args.c)