Introduction

The synthesis of active pharmaceutical ingredients (APIs) requires complex multi-step processing, involving chemical transformations, reaction quenching, work-ups, extractions and purifications. Traditionally, this has been achieved by iterative step-by-step transformations in batch, where intermediates are purified and isolated between each synthetic step [1]. However, this process has a very high space-time demand, as large inventories of intermediates must be stored and transported between different manufacturing sites. In contrast, continuous flow offers in-line purification and the addition of reagents at set points in the processing sequence, thus providing a more productive uninterrupted reaction network [2]. Consequently, there has been a rise in the use of modular flow platforms for the multi-step synthesis of APIs, thus minimising the impact of supply chain disruptions [3,4,5].

The manual, iterative, optimisation of each step in a chemical processes is labour intensive, which reduces the pace of pharmaceutical development and creates a significant bottleneck for the delivery of new medicines. Self-optimisation, which combines continuous flow reactors, online analysis and optimisation algorithms, provides a rapid and autonomous approach to process optimisation [6]. This reduces the amount of time a researcher spends conducting repetitive routine experimentation, allowing them to focus on the more challenging aspects of chemical discovery and development. Many improvements have been reported in this area over the past decade, predominantly focusing on optimisation algorithms [7,8,9] and different analytical techniques [10,11,12]. However, these reports have been limited to low complexity optimisations of single step reactions. These fail to consider downstream unit operations, which are crucial for the purification of products and intermediates in end-to-end continuous flow synthesis.

There has been a concomitant emergence of in-line liquid-liquid extraction (LLE) technologies with the advent of multi-step continuous flow processes. These include both gravity-based [13] and membrane-based LLE systems [14]. Notably, a membrane-based separator was recently developed which utilises an internal diaphragm for integrated pressure control, thus providing a modular plug-and-play device [15]. This enabled the development of a reconfigurable self-optimising flow system by Jamison et al., which was subsequently used to optimise six different transformations including multi-step chemical processes [16]. However, only the reaction conditions were varied in each optimisation, despite the potential impact variables such as pH and solvent ratios have on the efficiency and volume productivity of downstream work-ups. Typically, reactive LLEs have been optimised using either statistical [17] or physicochemical based modelling, [18, 19] which require relatively small amounts of material. However, modelling approaches suffer from an increased complexity with an increasing number of species and/or protic sites in solution, which can result in low accuracy predictions [18].

Results and discussion

Automated flow reactor

The aim of our study was to investigate an automated black-box optimisation approach for pH-based liquid-liquid extraction and multi-step reaction-extraction process in continuous flow. Initially, a modular continuous flow system was constructed which could easily be reconfigured for the optimisation of either single or multi-step processes (Fig. 1). The system was comprised of three interchangeable modules: a variable temperature (−40 to 150 °C) microreactor; a miniature continuous stirred tank reactor (CSTR), fReactor, for flow rate independent mixing of liquid-liquid biphasic mixtures; [20] a membrane-based liquid-liquid separator fitted with a hydrophobic PTFE membrane (0.5 μm) [15]. HPLC pumps were used for reagent addition at the inlets of the reactor and mixer, for the chemical transformation and reactive extraction steps respectively. The organic outlet stream from the separator was directed towards an on-line HPLC for analysis. Note, that there is no on-line pH measurement in the set-up. System parameters such as reactor temperature and pump flow rates were adjusted using a single computer terminal with integrated software control. The feedback loop was closed using the Stable Noisy Optimisation by Branch and Fit (SNOBFIT) algorithm, which is a global optimisation algorithm for bound constrained noisy optimisation of objective functions [21]. The SNOBFIT algorithm was set to conduct four experiments per iteration, thus balancing experimental speed with optimisation efficiency.

Fig. 1
figure 1

Self-optimising reconfigurable continuous flow system

Separation of structurally similar amines

Black-box optimisation

The presence of structurally similar impurities presents a significant challenge during multi-step continuous flow processes. These can arise as a result of incomplete reactions or limited product selectivity. The ability to control these during the reaction is not always possible, therefore rigorous optimisation of downstream purification steps is required to provide a robust process. In cases where compounds possess acidic or basic functional groups, in-line purification can be achieved via pH-based LLE [22]. This technique is commonly used for purifying reactions involving organic amines or acids. The protonation of amines under acidic conditions reverses their solubility properties, causing them to favourably partition into the aqueous phase. This can be used to remove either unreacted amine starting materials or products from the organic reaction medium [23]. However, the pH-based LLE of mixtures containing two or more different amines presents a significantly more challenging optimisation problem.

To study an automated black-box optimisation approach for pH-based LLE, we investigated the separation of α-methylbenzylamine 1 and N-benzyl-α-methylbenzylamine 2 in toluene (Scheme 1). The ratio of 1:2 was 95:5, thus representing a process in which 2 is formed as a minor impurity. The aim of the optimisation was to extract α-methylbenzylamine 1 into the aqueous phase whilst retaining the N-benzyl-α-methylbenzylamine 2 in the organic phase, as defined by Eq. (1). Thus, Δamine(org) = % amine 2 - % amine 1, where the % amine 2 is the percentage of 2 out of the original 5% and % amine 1 is the percentage of 1 out of the original 95%. This was achieved by forming the conjugate acid 3 of α-methylbenzylamine under acidic conditions. Three pumps were used to flow the amine mixture, nitric acid stock and diluent (water) directly into the CSTR mixing module. The inlet pH and solvent volume ratio (VR) Eq. (2) were varied by adjusting the respective pump flow rates. The optimisation boundaries were selected to provide an informative search area around the conditions required for complete protonation of the amine mixture, under the assumption of complete acid dissociation. Each experiment was run for two reactor volumes to achieve steady-state and sampled before running the next experiment.

$$ {\displaystyle \begin{array}{l}\begin{array}{l}\kern8.25em maximise\ \left[\Delta {amine}_{(org)}\right]\\ {}\mathrm{where}:\kern5.75em \Delta {amine}_{(org)}=\% amine\ \mathbf{2}-\% amine\ \mathbf{1}\end{array}\\ {}\mathrm{subject}\ \mathrm{to}:\kern8.25em \mathrm{Inlet}\ \mathrm{pH}\ \upepsilon\ \left[0.358,0.873\right]\\ {}\kern16.25em {V}_R\ \upepsilon\ \left[0.8,2.0\right]\end{array}} $$
(1)
$$ {V}_R=\frac{Volume_{(org)}}{Volume_{(aq)}} $$
(2)
Scheme 1
scheme 1

pH-based liquid-liquid extraction of α-methylbenzylamine 1 and N-benzyl-α-methylbenzylamine 2

The results of the optimisation were visualised in real-time, and the optimisation manually terminated once the user was satisfied that sufficient exploration had occurred with no further improvements. In this case, the optimum was rapidly identified in just 15 experiments, corresponding to a 90% separation at a calculated inlet pH of 0.420, and VR of 1.0. This yielded an improvement in the purity of amine 1 from 95% in the starting mixture to 99.5% in the resultant aqueous solution under the optimised conditions. The optimisation was run for an additional 46 experiments, where exploration predominantly focused on the region around the optimum, revealing the presence of a cliff edge in the local response surface (Fig. 2b). Inspection of the individual concentration profiles for each amine in the organic phase (Fig. 2a) showed that α-methylbenzylamine 1 was preferentially protonated over N-benzyl-α-methylbenzylamine 2 in an inlet pH range of 0.420–0.873 and VR range of 1.0–2.0. Any decrease in the inlet pH or VR, from the optimum conditions, resulted in a sharp decrease in the amount of N-benzyl-α-methylbenzylamine 2 remaining in the organic phase, which corresponded to the observed cliff edge in the separation response surface. These results suggested that α-methylbenzylamine 1 was more basic than N-benzyl-α-methylbenzylamine 2, which was verified by pKa determination discussed below. Furthermore, as VR directly affected the amount of acid available in the system, inclusion of this variable in the optimisation enabled the partitioning of the species to be finely-tuned.

Fig. 2
figure 2

Results of the self-optimising pH-based LLE: a percentage of each amine remaining in the organic phase,  = α-methylbenzylamine 1,  = N-benzyl-α-methylbenzylamine 2; b percentage difference of amines remaining in the organic phase

Due to the presence of a sharp change in the response surface, fine-tuning of the extraction conditions was crucial for the successful optimisation of this system. Automated continuous flow platforms are well suited for this, as they provide precisely adjustable flow rates and effectively remove human error. In addition, this approach is less labour intensive compared to manual titration-based methods, requiring only 13 h of unsupervised experiments to identify the optimum with no prior knowledge of the system. Furthermore, the use of statistical modelling approaches, such as design of experiments, are not appropriate for global optimisation problems with sharp changes in the response surface. This is due to the poor ability of polynomial models to fit sharp changes in response over a wide variable range. This is shown in Fig. 3a, where a global polynomial model of all the experimental data failed to identify the optimum, and accurately describe the true nature of the response surface around the optimum. In contrast, the SNOBFIT algorithm fits local polynomial models in subsections of the experimental space. An example of this is shown in Fig. 3b, where a local model was fit around the optimum using data in an inlet pH range of 0.358–0.500 and VR range of 0.8–1.2. This provided a model that successfully detected the experimentally observed cliff edge, which is information that is important for determining the region of process stability in a quality by design approach. However, quadratic polynomial models are relatively rigid designs, which in this case resulted in the incorrect prediction of equal gradients at either side of the optimum. In contrast, Gaussian processes (GPs) are significantly more versatile, providing global (Fig. 3c) and local (Fig. 3d) models which better reflected the morphology of the experimentally observed response surface, albeit at the cost of overfitting in regions of sparse data. This suggests that the use of GP based algorithms for self-optimisation would result in an overall more efficient optimisation. However, different GP model parameters and hyperparameters can result in significantly different models, and therefore rigorous optimisation of these settings is required to obtain reproducible predictions.

Fig. 3
figure 3

Contour plots showing statistical models derived from the self-optimisation data: a global polynomial model from all data, dashed boxed highlights local area around the optimum; b local polynomial model exclusively from data around the optimum; c global GP model from all data, dashed boxed highlights local area around the optimum, contour labels omitted for clarity; d local GP model exclusively from data around the optimum, contour labels omitted for clarity. ★ = experimental optimum with model predictions

pKa determination

The pKa of the conjugate acid (pKaH) for each amine was determined via titration with hydrochloric acid in triplicate using the “half-volume” method. The “half-volume” refers to the volume of acid added equal to half that required to reach the equivalence point, where [A] = [HA] and pKa = pH [24]. The resultant titration and first derivative plots are shown in Fig. 4. The volume added at the half-height of the peak (i.e. largest change in pH per change in volume) was correlated with the titration curves to determine the pKaH. The pKaH of α-methylbenzylamine 1 and N-benzyl-α-methylbenzylamine 2 were characterised as 9.33 ± 0.02 and 7.77 ± 0.02 respectively. These were found to be in good agreement with Conductor like Screening Model for Real Solvents (COSMO-RS) predictions of 9.32 for α-methylbenzylamine 1 and 7.73 for N-benzyl-α-methylbenzylamine 2 [25]. This data supports the previous observation that α-methylbenzylamine 1 is more basic than N-benzyl-α-methylbenzylamine 2.

Fig. 4
figure 4

Titration curves and first derivative plots carried out in triplicate: a titration curve for α-methylbenzylamine 1; b titration curve for N-benzyl-α-methylbenzylamine 2; c first derivative plot for α-methylbenzylamine 1; d first derivative plot for N-benzyl-α-methylbenzylamine 2

Tandem reaction-extraction optimisation

One of the main challenges associated with continuous multi-step process development is the identification of reaction and downstream work-up conditions that are complimentary, without any a priori knowledge of how the sequential steps are related. With a suitable system for the automated optimisation of LLEs in hand, our attention shifted to the simultaneous optimisation of a tandem reaction and extraction process. For this, the synthesis and purification of N-benzyl-α-methylbenzylamine 2 in continuous flow was investigated (Scheme 2) [7]. As previously, aqueous nitric acid was introduced into the CSTR mixing module for the removal of amine-containing impurities. The reaction was optimised with respect to residence time and temperature, and the LLE was optimised with respect to inlet pH and VR. The boundary conditions for the optimisation of the reaction and extraction were selected based on knowledge of the system gained from previous work and this work respectively [7]. The aim of the optimisation was to maximise the purity of N-benzyl-α-methylbenzylamine 2 with respect to the following impurities: (i) unreacted α-methylbenzylamine 1; (ii) unreacted benzyl bromide 5; (iii) tertiary amine by-product 6; (iv) conjugate acid of diisopropylethylamine (DIPEA) 7. The absolute purity of N-benzyl-α-methylbenzylamine 2 in the organic phase was measured via on-line HPLC. Using purity as the objective function ensured that the optimisation would favour a high yielding reaction step and efficient extraction conditions, by minimising the amount of unreacted benzyl bromide and amine-containing impurities respectively. The SNOBFIT algorithm was selected for this system, owing to its success in optimising the LLE in the previous example.

Scheme 2
scheme 2

Optimisation parameters for the continuous flow synthesis of N-benzyl-α-methylbenzylamine 2 via N-benzylation of α-methylbenzylamine 1, and subsequent downstream work-up of the crude reaction mixture

The results of the optimisation are shown in Fig. 5. An optimum purity of 71% at a yield of 63% was identified at the following process conditions: tres = 6.9 min, temperature = 127.2 °C, inlet pH = 0.772 and VR = 2.45. In terms of reaction conditions, a high purity was favoured at high temperatures and short residence times. High temperatures were found to drive the reaction to high conversions, where the reduction in unreacted starting materials outweighed the increase in the formation of tertiary amine 6 with respect to the purity of N-benzyl-α-methylbenzylamine 2 (see ESI for impurity plots). Although the highest conversions were observed at longer residence times, this corresponded to an increase in the concentration of salt 7, which was not efficiently extracted from the organic phase in this region. Similar to the previous LLE example, there was a noticeable cliff edge around the optimum, where decreasing VR from 2.45 to 1.32 corresponded to a decrease in purity from 71% to 16%. This could mainly be attributed to the salt 7 impurity, which disfavoured extraction from the organic phase when VR was less than 1.5. Nevertheless, a comparison of the optimum reaction conditions, including and excluding the downstream LLE module, showed that the optimised extraction significantly improved the purity of N-benzyl-α-methylbenzylamine 2 from 38% to 71%. The aqueous acidic work-up reduced the amount of salt 7 by 81%, whilst selectively extracting 43% of the unreacted α-methylbenzylamine 1 starting material. The purity might be improved further using a multi-stage LLE, which was beyond the scope of this study, and is the subject of current work [26].

Fig. 5
figure 5

Self-optimisation results for the continuous flow synthesis and work-up of N-benzyl-α-methylbenzylamine 2 with respect to purity.  = maximum purity

Conclusions

We have successfully developed a modular and reconfigurable continuous flow platform for the self-optimisation of multi-step reaction and extraction processes. A detailed SNOBFIT optimisation for the selective pH-based extraction of an amine mixture was conducted. Optimum conditions for the separation of α-methylbenzylamine 1 and N-benzyl-α-methylbenzylamine 2 were found to be an inlet pH of 0.420 and VR of 1.0, providing a 90% separation. The optimum was identified in just 15 experiments, and a total of 61 unsupervised experiments were conducted in 13 h, revealing a cliff edge in the local response surface around the optimum. Notably, the use of an automated black-box optimisation approach overcame the challenges associated with labour intensive manual experimentation and low accuracy polynomial modelling. Furthermore, inclusion and optimisation of VR as a variable, which is uncommon during process development, is instructive for the optimisation of work-ups, having an impact upon efficiency and volume productivity. With the increase in multi-step continuous flow processes for the synthesis of APIs, we investigated the optimisation of a tandem reaction-extraction process. By applying the same black-box optimisation methodology developed for LLEs, we were able to simultaneously optimise the continuous flow synthesis and purification of N-benzyl-α-methylbenzylamine 2 with respect to four variables in just 53 experiments with no human intervention. A purity of 71% was achieved at a residence time of 6.9 min, temperature of 127.2 °C, inlet pH of 0.772 and VR of 2.45. Inclusion of the LLE in the optimisation resulted in an increase in purity from 38% to 71%, by selective removal of salt by-products and unreacted amine starting materials. This work demonstrated that the efficient optimisation of reactive extractions and multi-step continuous flow processes can be achieved using self-optimisation technology, and highlighted that future improvements could be made by incorporating GP based algorithms. Furthermore, we envisage that by considering downstream unit operations during initial reaction optimisation, scaling transitions can be significantly simplified.