Retrosynthesis Solution
The RetrosynthesisSolution class is designed to find and visualize all possible retrosynthesis solutions given a set of fragmented molecules and their valid combinations. Retrosynthesis class is used to get valid combinations of fragments and Fragmenter class is used to obtain the fragment SMILES for visualization.
Example Use
from fragmentretro.retrosynthesis import Retrosynthesis
from fragmentretro.fragmenter import BRICSFragmenter
from fragmentretro.solutions import RetrosynthesisSolution
# Example SMILES
smiles = "COc1ccc(-n2nccn2)c(C(=O)N2CCC[C@@]2(C)c2nc3c(C)c(Cl)ccc3[nH]2)c1"
fragmenter = BRICSFragmenter(smiles)
retro_tool = Retrosynthesis(fragmenter=fragmenter, original_BBs=set())
# no need to run retrosynthesis for this example usage
# will give an example solution in the next few lines
# retro_tool.fragment_retrosynthesis 
# Example Solution
retro_solution = RetrosynthesisSolution(retro_tool)
retro_solution.solutions = [[[0, 1, 2], [3], [4], [5]]]
# Visualize solutions
images = retro_solution.visualize_solutions(retro_solution.solutions, molsPerRow=4)
for i, img in enumerate(images):
    img.save(f"solution_{i}.png")
    print(f"Solution {i} saved to solution_{i}.png")
Source Code
            fragmentretro.solutions
    
            RetrosynthesisSolution
    Source code in src/fragmentretro/solutions.py
                12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149  |  | 
            get_solutions(valid_combinations, num_fragments, solution_cap=None)
  
      staticmethod
  
    Generates all possible retrosynthesis solutions from a list of valid fragment combinations.
A valid solution is defined as a combination of fragment lists that, when combined, include all the original fragments exactly once.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                valid_combinations
             | 
            
                  list[CombType]
             | 
            
               A list of valid fragment combinations, where each combination is a tuple of fragment indices.  | 
            required | 
                num_fragments
             | 
            
                  int
             | 
            
               The total number of fragments in the retrosynthesis.  | 
            required | 
                solution_cap
             | 
            
                  int | None
             | 
            
               An optional integer specifying the maximum number of solutions to return.  | 
            
                  None
             | 
          
Returns:
| Type | Description | 
|---|---|
                  list[SolutionType]
             | 
            
               A list of retrosynthesis solutions. Each solution is a list of fragment lists.  | 
          
                  list[SolutionType]
             | 
            
               Returns an empty list if no solutions are found.  | 
          
Source code in src/fragmentretro/solutions.py
              
            fill_solutions(solution_cap=None)
    Fill the solutions list with all possible solutions.
            get_solution_smiles(solution)
    Retrieves the SMILES strings for each combination in a given solution.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                solution
             | 
            
                  SolutionType
             | 
            
               A retrosynthesis solution, which is a list of fragment combinations. Each combination is a tuple of fragment indices.  | 
            required | 
Returns:
| Type | Description | 
|---|---|
                  list[str]
             | 
            
               A list of SMILES strings, where each string corresponds to a fragment  | 
          
                  list[str]
             | 
            
               combination in the solution.  | 
          
Source code in src/fragmentretro/solutions.py
              
            visualize_solutions(solutions, molsPerRow=3, subImgSize=(200, 200))
    Visualizes a list of retrosynthesis solutions.
Generates a list of images, where each image visualizes a single retrosynthesis solution. Each solution is displayed as a grid of molecules, with the SMILES strings of the molecules as legends.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                solutions
             | 
            
                  list[SolutionType]
             | 
            
               A list of retrosynthesis solutions. Each solution is a list of fragment combinations (lists of fragment indices).  | 
            required | 
                molsPerRow
             | 
            
                  int
             | 
            
               The number of molecules to display in each row of the grid.  | 
            
                  3
             | 
          
                subImgSize
             | 
            
                  tuple[float, float]
             | 
            
               The size (width, height) of each molecule image in the grid.  | 
            
                  (200, 200)
             | 
          
Returns:
| Type | Description | 
|---|---|
                  list[Image]
             | 
            
               A list of PIL Image objects, each visualizing a retrosynthesis solution.  |