def autoencoder(args, model): latent_dim = args.latent_dim data, charset = load_dataset(args.data, split = False) if os.path.isfile(args.model): model.load(charset, args.model, latent_rep_size = latent_dim) else: raise ValueError("Model file %s doesn't exist" % args.model) sampled = model.autoencoder.predict(data[0].reshape(1, 120, len(charset))).argmax(axis=2)[0] mol = decode_smiles_from_indexes(map(from_one_hot_array, data[0]), charset) sampled = decode_smiles_from_indexes(sampled, charset) print(mol) print(sampled)
def autoencoder(args, model): latent_dim = args.latent_dim data, charset = load_dataset(args.data, split=False) if os.path.isfile(args.model): model.load(charset, args.model, latent_rep_size=latent_dim) else: raise ValueError("Model file %s doesn't exist" % args.model) sampled = model.autoencoder.predict(data[0].reshape( 1, 120, len(charset))).argmax(axis=2)[0] mol = decode_smiles_from_indexes(map(from_one_hot_array, data[0]), charset) sampled = decode_smiles_from_indexes(sampled, charset) print(mol) print(sampled)
def decoder(model): latent_dim = 292 data_train, data_test, charset = load_dataset('data/processed.h5') #Here we directly raise exceptions for non-existent model if os.path.isfile('model.h5'): model.load(charset, 'model.h5', latent_rep_size=latent_dim) print("model loaded") else: raise ValueError("Model file doesn't exist") samples_all = [] with open('encoded_vec.csv', 'r') as csvfile: #good dataset/data2.csv reader = csv.reader(csvfile) rows = [row for row in reader] data = np.array(rows, dtype=float) for ix in range(len(data)): sampled = model.decoder.predict(data[ix].reshape( -1, 292)).argmax(axis=2)[0] #sampled=data_test[ix].argmax(axis=1) print(sampled) #print(np.shape(sampled)) sampled = decode_smiles_from_indexes(sampled, charset) print(np.shape(sampled)) samples_all.append(sampled) print(sampled) with open('decoded_vec.csv', 'w') as f: writer = csv.writer(f) writer.writerows(np.array(samples_all))
def decoder(args, model): latent_dim = args.latent_dim data, charset = read_latent_data(args.data) if os.path.isfile(args.model): model.load(charset, args.model, latent_rep_size = latent_dim) else: raise ValueError("Model file %s doesn't exist" % args.model) sampled = model.decoder.predict(data[0].reshape(1, latent_dim)).argmax(axis=2)[0] sampled = decode_smiles_from_indexes(sampled, charset) print(sampled)
def decoder(args, model): latent_dim = args.latent_dim data, charset = read_latent_data(args.data) if os.path.isfile(args.model): model.load(charset, args.model, latent_rep_size=latent_dim) else: raise ValueError("Model file %s doesn't exist" % args.model) sampled = model.decoder.predict(data[0].reshape( 1, latent_dim)).argmax(axis=2)[0] sampled = decode_smiles_from_indexes(sampled, charset) print(sampled)
def interpolate(source, dest, steps, charset, model, latent_dim, width): source_just = source.ljust(width) dest_just = dest.ljust(width) one_hot_encoded_fn = lambda row: map(lambda x: one_hot_array(x, len(charset)), one_hot_index(row, charset)) source_encoded = numpy.array(map(one_hot_encoded_fn, source_just)) source_x_latent = model.encoder.predict(source_encoded.reshape(1, width, len(charset))) dest_encoded = numpy.array(map(one_hot_encoded_fn, dest_just)) dest_x_latent = model.encoder.predict(dest_encoded.reshape(1, width, len(charset))) step = (dest_x_latent - source_x_latent)/float(steps) results = [] for i in range(steps): item = source_x_latent + (step * i) sampled = model.decoder.predict(item.reshape(1, latent_dim)).argmax(axis=2)[0] sampled = decode_smiles_from_indexes(sampled, charset) results.append( (i, item, sampled) ) return results
def interpolate(source, dest, steps, charset, model, latent_dim, width): source_just = source.ljust(width) dest_just = dest.ljust(width) one_hot_encoded_fn = lambda row: list(map(lambda x: one_hot_array(x, len(charset)), one_hot_index(row, charset))) source_encoded = numpy.array(list(map(one_hot_encoded_fn, source_just))) source_x_latent = model.encoder.predict(source_encoded.reshape(1, width, len(charset))) dest_encoded = numpy.array(list(map(one_hot_encoded_fn, dest_just))) dest_x_latent = model.encoder.predict(dest_encoded.reshape(1, width, len(charset))) step = (dest_x_latent - source_x_latent)/float(steps) results = [] for i in range(steps): item = source_x_latent + (step * i) sampled = model.decoder.predict(item.reshape(1, latent_dim)).argmax(axis=2)[0] sampled = decode_smiles_from_indexes(sampled, charset) results.append( (i, item, sampled) ) return results