def create_or_restore_model(experiment_dir, nb_hidden, nb_layer, input_dim,
                            spat_dims):
    '''
  Checks if model exists and creates it if not.
  Returns model.
  '''
    model_file = os.path.join(experiment_dir, MODEL_NAME)
    if os.path.exists(model_file):
        logging.warning("Loading model...")
        m = load_model(model_file)
        logging.warning("Model restored.")
    else:
        logging.warning("Creating new model:")
        m = model.GNN(nb_hidden, nb_layer, input_dim, spat_dims)
        logging.info(m)
        save_model(m, model_file)
        logging.warning("Initial model saved.")
    return m
Exemple #2
0
    id_to_y = {l[0]: float(l[1]) for l in lines}

with open(args.key_dir + "/test_keys.pkl", "rb") as f:
    test_keys = pickle.load(f)

# Model
cmd = utils.set_cuda_visible_device(args.ngpu)
os.environ["CUDA_VISIBLE_DEVICES"] = cmd[:-1]
if args.potential == "morse":
    model = model.DTILJ(args)
elif args.potential == "morse_all_pair":
    model = model.DTILJAllPair(args)
elif args.potential == "harmonic":
    model = model.DTIHarmonic(args)
elif args.potential == "gnn":
    model = model.GNN(args)
elif args.potential == "cnn3d":
    model = model.CNN3D(args)
elif args.potential == "cnn3d_kdeep":
    model = model.CNN3D_KDEEP(args)
else:
    print(f"No {args.potential} potential")
    exit(-1)
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = utils.initialize_model(model, device, args.restart_file)

print(f"vina_hbond_coeff: {model.vina_hbond_coeff.data.cpu().numpy()[0]:.3f}")
print(f"vina_hydrophobic_coeff: \
{model.vina_hydrophobic_coeff.data.cpu().numpy()[0]:.3f}")
print(f"rotor_coeff: {model.rotor_coeff.data.cpu().numpy()[0]:.3f}")
print(f"vdw_coeff: {model.vdw_coeff.data.cpu().numpy()[0]:.3f}")