#model and restore model parapmeters
model = CVAE(vocab_size, args)
model.restore(args.save_file)

print('Number of parameters : ',
      np.sum([np.prod(v.shape) for v in tf.trainable_variables()]))

#target property to numpy array
start_codon = np.array(
    [np.array(list(map(vocab.get, 'X'))) for _ in range(args.batch_size)])

#generate smiles
smiles = []
for _ in range(args.num_iteration):
    generated = model.sample(start_codon, args.seq_length)
    smiles += [
        convert_to_smiles(generated[i], char) for i in range(len(generated))
    ]

#write smiles and calcualte properties of them
print('number of trial : ', len(smiles))
smiles = list(set([s.split('E')[0] for s in smiles]))
print('number of generate smiles (after remove duplicated ones) : ',
      len(smiles))
ms = [Chem.MolFromSmiles(s) for s in smiles]
ms = [m for m in ms if m is not None]
print('number of valid smiles : ', len(ms))
with open(args.result_filename, 'w') as w:
    w.write('smiles\n')
    for m in ms:
print('Number of parameters : ',
      np.sum([np.prod(v.shape) for v in tf.trainable_variables()]))

#target property to numpy array
target_prop = np.array([[float(p) for p in args.target_prop.split()]
                        for _ in range(args.batch_size)])
start_codon = np.array(
    [np.array(list(map(vocab.get, 'X'))) for _ in range(args.batch_size)])

#generate smiles
smiles = []
for _ in range(args.num_iteration):
    latent_vector = s = np.random.normal(args.mean, args.stddev,
                                         (args.batch_size, args.latent_size))
    generated = model.sample(latent_vector, target_prop, start_codon,
                             args.seq_length)
    smiles += [
        convert_to_smiles(generated[i], char) for i in range(len(generated))
    ]

#write smiles and calcualte properties of them
print('number of trial : ', len(smiles))
smiles = list(set([s.split('E')[0] for s in smiles]))
print('number of generate smiles (after remove duplicated ones) : ',
      len(smiles))
ms = [Chem.MolFromSmiles(s) for s in smiles]
ms = [m for m in ms if m is not None]
print('number of valid smiles : ', len(ms))
with open(args.result_filename, 'w') as w:
    w.write('smiles\tMW\tLogP\tTPSA\n')
    for m in ms: