inference_guide.md
April 13, 2025 ยท View on GitHub
๐ Inference Guide
After downloading the trained models and relevant files from the figshare link, you can use the following examples to perform inference.
In the downloaded folder, you will find the following folders under the inference sub-directory:
model: The trained SynLlama models.reconstruction: The necessary reaction embeddings for the reconstruction algorithm.smiles: The.smifile containing the SMILES strings used in the paper.
If you want to perform synthesis planning tasks, please follow all the steps below.
If you want to perform just the synthesizable analog search or hit expansion tasks, please only follow the steps of "๐ฆ LLM inference using the trained SynLlama models" and "๐ Reconstruction algorithm using exclusively Enamine BBs".
๐ฆ LLM inference using the trained SynLlama models
In the model folder, you will find the following trained models:
SynLlama-1B-2M-91rxns: The trained model for SynLlama-1B-2M using RXN Set 1.SynLlama-1B-2M-115rxns: The trained model for SynLlama-1B-2M using RXN Set 2.
You can choose one of the models to perform inference. Here we take synllama-data/inference/model/SynLlama-1B-2M-91rxns model and the file synllama-data/inference/smiles/syn-planning/1k_chembl.smi as an example.
cd SynLlama
python synllama/llm/parallel_inference.py \
--model_path synllama-data/inference/model/SynLlama-1B-2M-91rxns \
--smiles_path synllama-data/inference/smiles/syn-planning/1k_chembl.smi \
--save_path synllama-data/inference/results/temp/1k_chembl_synllama_91rxns.pkl \
--sample_mode greedy
This will generate a .pkl file containing the inference results in the synllama-data/inference/results/temp folder using 'greedy' sampling mode. All the details of the sample_mode can be found in the synllama/llm/parallel_inference.py file and the Supplementary Information.
๐ SynLlama raw reconstruction and Molport search
In the synthesis planning task, we report that SynLlama models can generate New BBs beyond the training Enamine BBs. To validate the purchasability of the generated BBs, we first sample and filter all the New BBs that are part of valid synthetic pathways, and then use Molport to search whether the New BBs are purchasable.
To do so, we first need to filter the raw results for Molport search. Assuming that you have already generated the raw results with SynLlama-1B-2M-91rxns model and saved them in the synllama-data/inference/results/temp/1k_chembl_synllama_91rxns.pkl file, you can use the following command to filter the raw results for Molport search.
cd SynLlama
python steps/step_30_0_benchmark_filter_raw_output.py \
--llama_folder synllama-data/inference/results/temp/ \
--rxn_mapping_path synllama-data/inference/reconstruction/91rxns/rxn_embeddings/reaction_smarts_map.pkl \
--fp_searcher_path synllama-data/inference/reconstruction/91rxns/processed/fpindex.pkl \
--raw_output_only \
This will generate a synllama_reconstruct folder in the synllama-data/inference/results/temp folder, which contains the filtered results for Molport search. To conduct the Molport search, please follow this link and paste all the SMILES strings in the *_successful_bbs_not_in_enamine_1.txt file into the List Search. Further details can be found in the Supplementary Information.
Once finished, you will download the .xls file under the Selected Items column from the Molport List Search History page, and name it as *_molport_ls.xls. Place this file in the synllama-data/inference/results/temp/synllama_reconstruct folder for the next filtering step that outputs csvs containing successful synthetic pathways with SynLlama raw outputs.
cd SynLlama
python steps/step_30_1_molport_raw_reconstruct.py \
--llama_folder synllama-data/inference/results/temp/
๐ Reconstruction algorithm using exclusively Enamine BBs
In cases when SynLlama's raw outputs fail to generate a full synthetic pathway for the target molecule or analog generation is the desired task, we use the reconstruction algorithm using exclusively Enamine BBs to generate synthetic pathways for the target molecule and their close analogs. Using the same example as above, you can use the following command to generate the synthetic pathways for the target molecule and their close analogs.
cd SynLlama
python steps/step_31_enamine_reconstruct.py \
--llama_folder synllama-data/inference/results/temp/ \
--embedding_path synllama-data/inference/reconstruction/91rxns/rxn_embeddings \
--total_num_mols 1000 # change this to the total number of molecules you want to generate
Note that the llama_folder should be the folder that contains the .pkl file generated by the LLM inference step. Here, if you are trying to do analog generation, you might want to increase k and n_stacks to 10 and 50, respectively for a more thorough search. Please refer to the Supplementary Information Table S1 for more details.
๐งฉ Putting Everything Together
If you are doing synthesis planning, you can use the following command to put the raw reconstruction and Enamine reconstruction results together.
cd SynLlama
python steps/step_32_combined_stats.py \
--llama_folder synllama-data/inference/results/temp/ \
--total_num_mols 1000 # change this to the total number of molecules you want to generate
This will generate a combined_final_stats.csv file in the synllama-data/inference/results/temp folder, which contains the combined statistics of the raw reconstruction and Enamine reconstruction results.