Autoencoders for SMILES strings
Project description
smiles-autoencoder
LSTM-based autoencoders for SMILES strings
Installation
$ pip install smiles-autoencoder
or
$ git clone https://gitlab.com/tjkessler/smiles-autoencoder
$ cd smiles-autoencoder
$ pip install .
Usage
One-hot encoding
from smiles_autoencoder.encoding import SmilesEncoder
smiles: List[str] = [...]
encoder = SmilesEncoder()
encoder.fit(smiles)
encoded_smiles: numpy.ndarray = encoder.encode_many(smiles)
# encoded_smiles.shape == (n_smiles_strings, sequence_length, n_unique_characters)
Autoencoding
import torch
import torch.nn as nn
from smiles_autoencoder.model import LSTMAutoencoder
encoded_smiles = torch.tensor(encoded_smiles, dtype=torch.float32)
autoencoder = LSTMAutoencoder(
input_size=encoded_smiles.shape[2],
hidden_size=64,
latent_size=12,
num_lstm_layers=1
)
opt = torch.optim.Adam(autoencoder.parameters(), lr=0.001)
loss_crit = nn.L1Loss(reduction="sum")
for epoch in range(8):
for enc_smiles in encoded_smiles:
opt.zero_grad()
pred = autoencoder(enc_smiles)
loss = loss_crit(pred, enc_smiles)
loss.backward()
opt.step()
Decoding predictions
pred_smiles: torch.Tensor = autoencoder(encoded_smiles[0])
pred_smiles: str = encoder.decode(torch.round(pred_smiles).detach().numpy().astype(int))
Contributing, Reporting Issues and Other Support:
To contribute to smiles-autoencoder, make a pull request. Contributions should include tests for new features added, as well as extensive documentation.
To report problems with the software or feature requests, file an issue. When reporting problems, include information such as error messages, your OS/environment and Python version.
For additional support/questions, contact Travis Kessler (travis.j.kessler@gmail.com).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
smiles_autoencoder-0.0.1.tar.gz
(16.0 kB
view details)
Built Distribution
File details
Details for the file smiles_autoencoder-0.0.1.tar.gz
.
File metadata
- Download URL: smiles_autoencoder-0.0.1.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9c71cb93fc9ef82033959460007e999609e8f2592b743169296fb10e110b4b1 |
|
MD5 | 5dd0ca923d1b2a19c379ecdee363e8aa |
|
BLAKE2b-256 | 8813d7508dc8eecba87a34e9c59b89b6b8d2750800f195c495b2fe2fc87684ee |
File details
Details for the file smiles_autoencoder-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: smiles_autoencoder-0.0.1-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69ea74cf0a620fbe411ae9e1859eac616150f0b181e59d01593020aa3f40beb6 |
|
MD5 | 798fe2ea434b228ba31ab31474dc0171 |
|
BLAKE2b-256 | c94b200f92f37f9486d1a64e5d57462c92c06ac4c22349ecffbd4059d8878f8a |