-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_coords_progsnn.py
175 lines (148 loc) · 6.32 KB
/
test_coords_progsnn.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from argparse import ArgumentParser
import datetime
import os
import numpy as np
from tqdm import tqdm
import torch
import torch.utils.data
from torch import nn
from torch.nn import functional as F
import pickle
import pytorch_lightning as pl
from pytorch_lightning.loggers import WandbLogger
from pytorch_lightning.callbacks.early_stopping import EarlyStopping
from pytorch_lightning.loggers import TensorBoardLogger
from pathlib import Path
from models.gsae_model import GSAE
from models.progsnn import ProGSNN_ATLAS
from torch_geometric.loader import DataLoader
from torchvision import transforms
from deshaw_processing.de_shaw_Dataset import DEShaw, Scattering
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--dataset', default='deshaw', type=str)
parser.add_argument('--input_dim', default=None, type=int)
parser.add_argument('--latent_dim', default=64, type=int)
parser.add_argument('--hidden_dim', default=64, type=int)
parser.add_argument('--embedding_dim', default=128, type=int)
parser.add_argument('--lr', default=0.001, type=float)
parser.add_argument('--alpha', default=2, type=float)
parser.add_argument('--beta', default=0.0005, type=float)
parser.add_argument('--beta_loss', default=0.5, type=float)
parser.add_argument('--gamma', default=0.0005, type=float)
# parser.add_argument('--delta', default=0.0005, type=float)
parser.add_argument('--n_epochs', default=40, type=int)
parser.add_argument('--len_epoch', default=None)
parser.add_argument('--probs', default=0.2)
parser.add_argument('--nhead', default=1)
parser.add_argument('--layers', default=1)
parser.add_argument('--task', default='reg')
parser.add_argument('--batch_size', default=64, type=int)
parser.add_argument('--n_gpus', default=1, type=int)
parser.add_argument('--save_dir', default='train_logs/', type=str)
parser.add_argument('--residue_num', default=None, type=int)
parser.add_argument('--protein', default=None, type=str)
# add args from trainer
# parser = pl.Trainer.add_argparse_args(parser)
# parse params
args = parser.parse_args()
#55 residues
if args.protein == 'murd':
with open('MurD/graphs_MurD.pkl', 'rb') as file:
full_dataset = pickle.load(file)
with open('quadratic_samples_latent_5F_10.pkl', 'rb') as file:
latent_samples = pickle.load(file)
# import pdb; pdb.set_trace()
# full_dataset = full_dataset[:1000]
# for data in full_dataset:
# y = float(data.y)
# data.y = y
# train_size = int(0.8 * len(full_dataset))
# val_size = len(full_dataset) - train_size
# train_set, val_set = torch.utils.data.random_split(full_dataset, [train_size, val_size])
# train_loader = DataLoader(train_set, batch_size=args.batch_size,
# shuffle=False, num_workers=15)
# # valid loader
# valid_loader = DataLoader(val_set, batch_size=args.batch_size,
# shuffle=False, num_workers=15)
# full_loader = DataLoader(full_dataset,
# batch_size=args.batch_size,
# shuffle=False,
# num_workers=15)
# logger
now = datetime.datetime.now()
date_suffix = now.strftime("%Y-%m-%d-%M")
save_dir = args.save_dir + 'progsnn_logs_run_{}_{}/'.format(args.dataset,date_suffix)
if not os.path.exists(save_dir):
os.makedirs(save_dir)
wandb_logger = WandbLogger(name='run_progsnn',
project='progsnn',
log_model=True,
save_dir=save_dir)
wandb_logger.log_hyperparams(args)
wandb_logger.experiment.log({"logging timestamp":date_suffix})
# print(train_loader)
# print([item for item in full_dataset])
# early stopping
early_stop_callback = EarlyStopping(
monitor='val_loss',
min_delta=0.00,
patience=5,
verbose=True,
mode='min'
)
# args.input_dim = train_set[0].x.shape[-1]
args.input_dim = 3
# print(train_set[0].x.shape[-1])
# print(full_dataset[0][0].shape)
args.prot_graph_size = max(
[item.edge_index.shape[1] for item in full_dataset])
print(args.prot_graph_size)
# import pdb; pdb.set_trace()
# args.len_epoch = len(train_loader)
args.residue_num = full_dataset[0].x.shape[0]
# init module
model = ProGSNN_ATLAS(args)
# # most basic trainer, uses good defaults
# trainer = pl.Trainer(
# max_epochs=args.n_epochs,
# #gpus=args.n_gpus,
# callbacks=[early_stop_callback],
# logger = wandb_logger
# )
# trainer.fit(model=model,
# train_dataloaders=train_loader,
# val_dataloaders=valid_loader,
# )
#test model
trained_weights = torch.load('train_logs/progsnn_logs_run_murd_2024-06-19-54/model_murd_murd.npy')
model.load_state_dict(trained_weights)
model = model.eval()
attention_maps_col = []
attention_maps_row = []
# import pdb; pdb.set_trace()
# get test set prediction
times = np.array([data.time for data in full_dataset])
test_latent = []
latent_embeddings = []
coords_recon_lst = []
# import pdb; pdb.set_trace()
latent_samples = torch.tensor(latent_samples)
# import pdb; pdb.set_trace()
with torch.no_grad():
coords_recon = model.reconstruct_coords(latent_samples)
coords_recon = coords_recon
# for x in tqdm(full_loader):
# print("Looping through test set..")
# y_hat, z_rep, _, _, _, att_map_row,coords_recon, _, _, _, _ = model(x)
# # import pdb; pdb.set_trace()
# # attention_maps_col.append(att_map_col)
# # attention_maps_row.append(att_map_row)
coords_recon_lst.append(coords_recon)
# test_latent.append(y_hat)
# latent_embeddings.append(z_rep)
# print(test_latent)
# test_predictions = torch.cat(test_latent, dim=0)
print("Saving coordinates..")
with open(f'quadratic_5F_10_coords_{args.protein}.pkl', 'wb') as file:
pickle.dump(coords_recon_lst, file)