Skip to main content

Autoencoders for SMILES strings

Project description

smiles-autoencoder

GitHub version PyPI version GitHub License

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


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.1.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

smiles_autoencoder-0.1.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file smiles_autoencoder-0.1.0.tar.gz.

File metadata

  • Download URL: smiles_autoencoder-0.1.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for smiles_autoencoder-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d9230e12d06f0f6c06badd736811f6692cb98ebabbd6a80ce8bd5e71eb75958f
MD5 603e7cb7e384ae0a174d6559e62e16e0
BLAKE2b-256 44ac13290ed3031a0b13957ee59a6700040c76f68f5ee049b334b3906a7a7d18

See more details on using hashes here.

File details

Details for the file smiles_autoencoder-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for smiles_autoencoder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6adadda59f3f89fb945478f3d8703e142b814ce3dbbd35afd597f8288992e3e4
MD5 275ec33eb98f0fba98d7163433b3470a
BLAKE2b-256 0e5eb296b584efd473d185c758849d98580078358a5291ec178f91c4290cb074

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page