{"id":23243312,"url":"https://github.com/deepbiolab/retrosynthesis-transformer","last_synced_at":"2025-07-23T14:08:43.633Z","repository":{"id":187135388,"uuid":"345686619","full_name":"deepbiolab/retrosynthesis-transformer","owner":"deepbiolab","description":"A TensorFlow-based Transformer model for predicting reactant molecules in retrosynthesis. This repository includes comprehensive tutorials for beginners to learn neural networks and TensorFlow, enabling users to build and understand advanced sequence-to-sequence models in computational chemistry.","archived":false,"fork":false,"pushed_at":"2024-09-21T10:35:20.000Z","size":47237,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T23:23:21.010Z","etag":null,"topics":["computational-chemistry","neural-networks","retrosynthesis","transformer","tutorials"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deepbiolab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-08T14:36:59.000Z","updated_at":"2024-09-21T10:35:24.000Z","dependencies_parsed_at":"2024-12-19T06:26:07.984Z","dependency_job_id":null,"html_url":"https://github.com/deepbiolab/retrosynthesis-transformer","commit_stats":null,"previous_names":["deepbiolab/tensorflowseries","deepbiolab/tensorflow-tutorials","deepbiolab/retrosynthesis-transformer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/deepbiolab/retrosynthesis-transformer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepbiolab%2Fretrosynthesis-transformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepbiolab%2Fretrosynthesis-transformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepbiolab%2Fretrosynthesis-transformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepbiolab%2Fretrosynthesis-transformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepbiolab","download_url":"https://codeload.github.com/deepbiolab/retrosynthesis-transformer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepbiolab%2Fretrosynthesis-transformer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266691580,"owners_count":23969182,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computational-chemistry","neural-networks","retrosynthesis","transformer","tutorials"],"created_at":"2024-12-19T06:16:15.966Z","updated_at":"2025-07-23T14:08:43.603Z","avatar_url":"https://github.com/deepbiolab.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Retrosynthesis Prediction with Transformer\n\nThis project implements a Transformer-based model for predicting reactant molecules (retrosynthesis) given a target molecule represented as a SMILES string. The model is built using TensorFlow and leverages sequence-to-sequence learning to map product SMILES to reactant SMILES.\n\n## Table of Contents\n\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Training the Model](#training-the-model)\n  - [Predicting Reactants](#predicting-reactants)\n- [Data Format](#data-format)\n- [Project Structure](#project-structure)\n- [TensorFlow Learning Path for Beginners](#tensorflow-learning-path-for-beginners)\n- [Acknowledgments](#acknowledgments)\n\n## Prerequisites\n\n- Python 3.7 or higher\n- TensorFlow 2.x\n- Other Python packages as listed in `requirements.txt`\n\nBefore diving into this project, you should have a good understanding of basic neural networks and how they are implemented in TensorFlow. If you are a beginner or want to refresh your knowledge, follow the tutorials listed in the [TensorFlow Learning Path for Beginners](#tensorflow-learning-path-for-beginners).\n\n## Installation\n\n1. **Clone the Repository:**\n\n   ```bash\n   git clone https://github.com/deepbiolab/retrosynthesis-transformer.git\n   cd retrosynthesis-transformer\n   ```\n\n2. **Create a Virtual Environment:**\n\n   It's recommended to use a virtual environment to manage dependencies.\n\n   ```bash\n   python3 -m venv venv\n   source venv/bin/activate\n   ```\n\n3. **Install Dependencies:**\n\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n## Usage\n\nThe script can be run in two modes: `train` and `predict`. Use the command-line arguments to specify the desired mode and other parameters.\n\n### Training the Model\n\nTo train the Transformer model on your dataset:\n\n```bash\npython main.py --mode train \\\n               --train_file data/retrosynthesis-train.smi \\\n               --valid_file data/retrosynthesis-valid.smi \\\n               --epochs 20 \\\n               --batch_size 64 \\\n               --checkpoint_dir ./checkpoints\n```\n\n**Arguments:**\n\n- `--mode`: Set to `train` to initiate training.\n- `--train_file`: Path to the training data file in SMILES format.\n- `--valid_file`: Path to the validation data file in SMILES format.\n- `--epochs`: Number of epochs to train the model (default: 20).\n- `--batch_size`: Batch size for training (default: 64).\n- `--checkpoint_dir`: Directory to save model checkpoints (default: `./checkpoints`).\n\n**Example:**\n\n```bash\npython main.py --mode train --epochs 30\n```\n\nThis command trains the model for 30 epochs using the default training and validation files, batch size, and checkpoint directory.\n\n### Predicting Reactants\n\nAfter training, you can use the model to predict reactants for a given product SMILES string.\n\n```bash\npython main.py --mode predict \\\n               --input_sequence \"Ic1ccc2n(CC(=O)N3CCCCC3)c3CCN(C)Cc3c2c1\" \\\n               --checkpoint_dir ./checkpoints\n```\n\n**Arguments:**\n\n- `--mode`: Set to `predict` to perform prediction.\n- `--input_sequence`: The product SMILES string for which to predict reactants.\n- `--checkpoint_dir`: Directory where model checkpoints are saved (default: `./checkpoints`).\n\n**Example:**\n\n```bash\npython main.py --mode predict --input_sequence \"Cc1ccccc1O\"\n```\n\n**Output:**\n\n```\nInput Product:       Cc1ccccc1O\nPredicted Reactants: Cc1ccccc1 + [Another Reactant]\n```\n\n**Note:** Ensure that the model has been trained and the checkpoints are available before performing predictions.\n\n## Data Format\n\n- **Training and Validation Files:** The data files should contain SMILES strings, each representing a chemical reaction in the format:\n\n  ```\n  Reactant1.Reactant2\u003e\u003eProduct\n  ```\n\n  Each line corresponds to a single reaction.\n\n## Project Structure\n\n```\nretrosynthesis-transformer/\n│\n├── data/\n│   ├── retrosynthesis-train.smi\n│   └── retrosynthesis-valid.smi\n│\n├── checkpoints/\n│   └── ... (model checkpoints)\n│\n├── transformer.py\n├── utils.py\n├── preprocess.py\n├── main.py\n└── requirements.txt\n```\n\n- `data/`: Contains training and validation data files.\n- `checkpoints/`: Stores model checkpoints during training.\n- `transformer.py`: Defines the Transformer model architecture.\n- `utils.py`: Contains utility functions for masks, loss calculation, checkpoint management, etc.\n- `preprocess.py`: Handles data preprocessing, tokenization, and dataset preparation.\n- `main.py`: The main script to train and predict using the Transformer model.\n- `requirements.txt`: Lists all Python dependencies.\n- `README.md`: Project documentation.\n\n## TensorFlow Learning Path for Beginners\n\nTo help beginners understand the fundamentals of neural networks and how to use TensorFlow, we've provided a learning path. You are encouraged to complete these tutorials before diving into this project:\n\n### Tier 1: Neural Network Basics\n\n1. **[00-Neural Network Basic](./neural_network_basics/00-Neural%20Network%20Basic.ipynb)**\n\n   - From Neuron to Single Layer Perceptrons\n   - From Single Layer Perceptrons to Multi-Layer Perceptron \n   - From Multi-Layer Perceptron to Deep Neural Network \n\n2. **[01-Keras Basic](./neural_network_basics/01-Keras%20Basic.ipynb)**\n\n   - Introduction to Keras\n   - Model creation methods\n   - Viewing model details\n   - Defining loss functions, optimizers, and compiling the model\n   - Training, evaluating, and predicting with the model\n   - Saving and restoring models\n   - Callbacks\n   - Visualizing training with TensorBoard\n   - Parameter tuning\n\n3. **[02-TensorFlow Basic](./neural_network_basics/02-TensorFlow%20Basic.ipynb)**\n\n   - Introduction to TensorFlow\n   - Tensor operations\n\n4. **[03-Training Techniques](./neural_network_basics/03-Training%20Techniques.ipynb)**\n\n   - Initialization methods\n   - Non-saturating activation functions\n   - Batch normalization\n   - Gradient clipping\n   - Optimizer selection\n   - Learning rate scheduling\n   - Regularization techniques\n\n### Tier 2: Transformer Implementation\n\nOnce you understand the basics of neural networks, follow this project's code to learn how to implement a Transformer model, which is used for advanced sequence-to-sequence tasks such as retrosynthesis prediction.\n\n\n### Additional Notes\n\n- **Data Preparation:** Ensure that your training and validation data are properly formatted and located in the specified paths. The script assumes that the data files are in SMILES format suitable for retrosynthesis tasks.\n\n- **Hardware Requirements:** Training Transformer models can be computationally intensive. It's recommended to use a machine with a GPU to accelerate the training process.\n\n- **Extensibility:** The model and training pipeline can be further enhanced by incorporating more sophisticated tokenization, data augmentation, or by experimenting with different hyperparameters.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepbiolab%2Fretrosynthesis-transformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepbiolab%2Fretrosynthesis-transformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepbiolab%2Fretrosynthesis-transformer/lists"}