Automatic tube lens design from stock optics for microscope remote-refocusing systems

: The remote-refocusing approach of Botcherby et al. [Opt. Lett. 32 , 2007 (2007)] has been applied widely to 2D and 3D fluorescence microscopes to enable rapid refocusing of the optical system without mechanically perturbing the sample. In order for this approach to operate correctly, it requires that the overall magnification of the first two microscope systems matches the ratio of the refractive indices in sample and intermedia image spaces. However, commercially available tube lenses are not always suitable to produce the desired overall magnification. Therefore, a practical approach to produce tube lenses with low expense and diffraction-limited performance is required. Tube lenses can be formed using a pair of stock achromatic doublets, however, selecting appropriate pairs of achromatic doublets from stock optics is a time-consuming process, as many combinations can be considered. In this paper, we present two software packages (Catalogue Generator and Doublet Selector) developed in MATLAB that use the application programming interface (ZOS-API) to the Zemax OpticStudio optical design software to realise an automatic search of stock achromatic doublets to produce microscope tube lenses with a specified focal length, entrance pupil diameter and maximum design field angle. An algorithm to optimise principal plane positions in versions of OpticStudio before 20.2 was also introduced to enable the use of older software versions. To evaluate the performance of Catalogue Generator and Doublet Selector, we used them to generate ten tube lens designs. All of the software-produced tube lenses have a better optical performance than those using manually selected pairs of stock doublets lenses.


Introduction
The concept of remote refocusing introduced by Botcherby et al. [1,2] allows the focal plane of a microscope system employing a high numerical aperture microscope objective to be swept without causing mechanical perturbation to the specimen. This approach is therefore well-suited to high-speed 2D and 3D fluorescence microscopy, for example for extended depth-of-field spinning disc microscopy [3] and 3D multiphoton imaging [4]. The principle of remote-refocusing microscopy is also used for imaging a tilted plane in the specimen, as is done in oblique plane microscopy (OPM) [5,6].
A remote-refocusing system consists of three microscopes. The first two microscopes are placed back-to-back and the overall magnification of these two microscopes is required to be equal to the ratio of the refractive indices of the sample and intermediate spaces [1]. The sensitivity of remote-refocusing systems to magnification mismatch has been investigated by Mohanan et al. [7]. As commercially available microscope objectives are sold at discrete magnifications and as microscope tube lenses are sold at specific focal lengths, it is sometimes not possible to form the remote-refocusing system using only commercially available microscope objectives and tube lenses.
In order to rapidly and flexibly develop remote-refocusing setups in cases where suitable commercially available combinations of objectives and tube lenses are not available, it is useful to be able to form a tube lens with a specified focal length from combinations of stock optics. One approach is to modify the focal length of a commercial tube lens by adding additional achromatic doublets [8]. Another approach is to use two stock achromatic doublets [9,10]. With an appropriate choice of doublets, the latter approach can provide diffraction-limited performance at low cost and without the need to purchase custom lenses, which can be time-consuming. However, selecting the optimum pair of stock doublets requires a large number of doublet combinations to be considered due to the large number of available stock achromatic doublets, which is a time-consuming process.
In order to automate the selection of pairs of stock achromatic doublets for forming microscope tube lenses with a specific focal length that minimise aberrations, two computer software packages (Catalogue Generator and Doublet Selector) written in MATLAB (2019a) were developed using the application programming interface (ZOS-API) of the Zemax OpticStudio ray tracing software. We are not aware of any other software providing this functionality. Ten achromatic doublet-pair tube lenses were produced by Doublet Selector for different applications, comprising four remote-refocusing systems and one tertiary microscope in an oblique plane microscope (OPM) system.

Tube lens design requirements of remote-refocusing systems
In order to achieve diffraction-limited imaging of a specimen away from the design focal plane of a primary objective, the output from the primary microscope is passed into a secondary microscope, shown in Fig. 1. The magnification of the secondary microscope is chosen so that the overall magnification, M overall , from the specimen to the intermediate image formed at the output of the secondary microscope is equal to the ratio of the refractive indices of the immersion media used in the specimen and intermediate image spaces, given by where n 1 and n 2 are the refractive indices in sample and intermediate image spaces respectively as indicated in Fig. 1.   Fig. 1. Principal ray and ray just passing edge of limiting aperture traced through the remote-refocusing system. O, objective; TL, tube lens; f f , front focal length; f b , back focal length; FN, field number; P, pupil plane; n, refractive index; PD, pupil diameter. In this schematic the limiting aperture is that of P1, and the image of this limiting aperture is indicated in red in the plane of P2.
In this paper, the first infinity corrected microscope is assumed to be that of a commercially available microscope installed with the manufacturer's tube lens; therefore, Tube Lens 2 needs to be designed to satisfy the requirements of the remote-refocusing system. In order to design a suitable Tube Lens 2, three important parameters need to be considered: the maximum design field angle α TL2 , the desired focal length f TL2 and the required entrance pupil diameter PD 2 .
The maximum design field angle α TL2 can be expressed in terms of known parameters by the following method. First, calculate the field of view of O1 in specimen space (field number divided by magnification) and then calculate its effective size in intermediate image space using M overall . Then calculate the size of the field of view of O2 in intermediate image space. The effective field of view is given by the smaller of these two quantities. Second, calculate the maximum required design field angle using the back focal length of Objective 2. This can be expressed as where respectively: FN O1 and FN O2 are the field numbers of Objective 1 and Objective 2; M O1 and M O2 are the magnifications of Objective 1 and Objective 2; and f TL2D is the standard focal length of tube lens used by the microscope objective manufacturer of Objective 2.
To achieve the desired value of M overall , the required focal length of Tube Lens 2 can be expressed as In addition, we also need to define the numerical aperture required for the tube lens. We choose to define this in terms of the entrance pupil diameter PD 2 , and specify this in the conventional configuration for a tube lens, i.e. that the light is emitted from the aperture stop of a microscope objective with diameter PD 2 and the image is then formed by Tube Lens 2. This can be expressed mathematically by first projecting the pupil of Objective 1 onto that of Objective 2; the required entrance pupil diameter for tube lens 2 is then given by the smaller of these two quantities. This can be expressed mathematically by where NA O1 and NA O2 are respectively the numerical apertures of Objective 1 and 2.

Tube lens designs
Common lens designs are reviewed by Kidger [11] and include Petzval lenses consisting of a pair of achromatic doublets with the same orientation, and the Plossl eyepiece consisting of a pair of achromatic doublets with opposite orientation. There are four different possible configurations of tube lenses consisting of a pair of achromatic doublets, which are shown in Fig. 2. The Doublet Selector software allows the user to select which of these four configurations is tested when the software is run. The results from multiple runs of the software, where each run tests a different configuration (see Fig. 2), can then be compared to find the best overall combination of doublets in the best configuration. The user is able to compare the results from multiple runs of the software by comparing the cut-off field angle and the RMS wavefront errors of the best doublet combination in an Excel file produced by the Doublet Selector for each run.

Catalogue Generator
In order to select achromatic doublet lens pairs from stock optics automatically, a lens catalogue consisting of those stock doublets suitable for the conditions set by the user needs to be generated. To achieve this function, the Catalogue Generator software was developed in MATLAB to produce catalogues of achromatic doublet lenses from the libraries of Zemax OpticStudio. The simplified flow chart and the user interface of Catalogue Generator are shown in Fig. 3. Users first need to enter the desired focal length range and a diameter range of the achromatic doublets to be considered. Specific lens vendors can be selected in the user interface, which is useful when researchers only want to produce a tube lens from a particular lens vendor. The lens search then is carried out in the Zemax OpticStudio lens libraries using the ZOS-API programming interface to operate the Zemax lens search tool to find programmatically all doublets meeting the requirements set by the user.
During this process, the wavelength range of each doublet will be recorded, which can be used in the subsequent selection of potential tube lens designs. Air-spaced doublets and cemented doublets will also be identified and set with different flag values. Furthermore, doublets with inked outer surfaces with identical curvatures, thicknesses and materials as other lenses in the catalogue will be marked. Each achromatic doublet in the catalogue is then given a unique identification number so it can be identified conveniently. Finally, using the ZOS-API, for each doublet the effective focal length (EFL), entrance pupil diameter (EPD), part number, flag values and vendor's name are saved in an Excel file called "All_Lenses_app". This catalogue file is then used as the input to the second software package Doublets Selector.

Doublet Selector
Given the large number of stock achromatic doublets available commercially, manually selecting pairs of stock doublets that provide the best diffraction-limited performance for the required focal length, entrance pupil diameter and maximum design field angle, is time-consuming. Doublet Selector was developed to automate the process.
The simplified flow chart and the user interface of Doublet Selector can be seen in Fig. 4. As shown in Fig. 4, the Doublet Selector software requires the design focal length f TL2 , entrance pupil diameter PD 2 , maximum design field angle α TL2 , and working wavelength range to be entered by the user. The tube lens configuration (see Fig. 2) can then be set via the "Configuration" pop-up menu. Considering the tube lens feasibility in practice, the minimum and maximum separation of the doublets is also required to be set. This separation requirement will determine the diameters of doublets needed to form a telecentric tube lens that meets the requirements without vignetting. To analyse this, the reverse optical path (compared to Fig. 1) of the principal ray passing through the back focal plane of O2 towards Tube Lens 2 is traced paraxially, see Based on paraxial ray tracing and the thin lens approximation, the separation of two thin lenses can be expressed as [12] where f L1 and f L2 are the focal lengths of Thin Lens 1 and Thin Lens 2 in Fig. 5. The distance from the pupil plane to Thin Lens 1, l 2 , can be derived using the position of the first principal plane of Tube Lens 2, which is given by [12]  With these parameters, then the minimum diameters (D L1 and D L2 ) of both lenses can be derived by tracing the principal ray through the tube lens system as and whereh 1 andh 2 are both denoted in Fig. 5.
Once the desired tube lens design criteria are set in the user interface, the Doublet Selector will load the specified lens catalogue, which contains the vendor's name, lens diameter, focal length, part number, design wavelength range and flag values of each doublet produced by Catalogue Generator. It will then perform an initial filtering step to select those doublets with suitable design wavelengths and flag values into a potential doublet catalogue. Owing to the larger pool of commercially available cemented doublets compared to air-spaced doublets, and the typical higher cost of air-spaced doublets, the Doublet Selector software only includes cemented doublets into the potential doublet catalogue. The Doublet Selector software will then test all combinations of pairs of doublets in the potential doublet catalogue one by one. For each doublet combination, based on the thin lens approximation, the required diameters (D L1 and D L2 ) and the separation d of Doublet 1 and Doublet 2 will be calculated using Eqs. (7) and (8). Combinations not meeting the desired criteria will be rejected.
Considering that in some cases where other optical components need to be placed in front of the first doublet (Doublet 1), the distance from the entrance pupil (EP) to Doublet 1 can be set to meet different conditions. The Doublet Selector software provides four optimisation options to control this distance, including "Telecentric", "Set distance from EP to 1 st principal plane", "Variable" and "Fixed". "Telecentric" means that the tube lens system will be optimised under the condition that the first focal plane of the tube lens is placed at the pupil plane of Objective 2. The optimisation of "Set distance from P to 1 st principal plane" is similar to "Telecentric", which will be illustrated in section 2.5. As for the options of "Variable" and "Fixed", the distance from the pupil plane (P) to Doublet 1 is respectively set as variable and fixed during OpticStudio optimisations.
In the Doublet Selector software, the RMS wavefront error is used as the criterion to compare the performance of different pairs of doublets using the method described below. The "RMS refer to" pop-up menu in the user interface provides two choices: "Centroid" and "Chief Ray". If "Centroid is selected, OpticStudio is configured to calculate the RMS wavefront error with respect to the location of the centroid of the rays traced. If "Chief Ray is selected, then OpticStudio is configured to calculate the RMS wavefront error with respect to the chief ray. In this paper, all results are presented using both options. Using the centroid as reference effectively excludes the effects of distortion and provides a lower RMS wavefront error. Using the chief ray as reference includes the effects of distortion in the wavefront error calculation. The values of RMS wavefront error of each wavelength and the polychromatic curve at the maximum design field angle are all saved in an Excel file for later reference.
The best combination of doublets is then found by looking for the combination that has the greatest cut-off field angle for which the polychromatic RMS wavefront error is diffraction limited (less than λ/14). If multiple combinations have the same value, then the combination providing the lowest polychromatic RMS wavefront error at the maximum design field angle will be selected. The combination reference number of the best tube lens system will also be saved in an Exile file. Once the selection process is finished, the total number of the trial combinations will be displayed in the user interface, and the best doublet combination can also be decoded and shown. All of the work presented in this paper was performed using Zemax OpticStudio version 20.1. Since versions before 20.2 do not provide the CARD optimisation operand to control the positions of the principal planes, here we provide a method to set the doublet separation distance and first principal plane position that can be used for versions before 20.2.
According to matrix optics theory and the thin lens approximation, the ABCD matrices of a refractive surface (M Ri ) and space propagation (M Pi ) can be expressed as where i is the surface number, R i is the radius of curvature of surface i, t i is the thickness after surface i, and n i and n i+1 are respectively the refractive indices before and after surface i. Therefore, the overall ABCD matrix for a pair of doublets each consisting of three curved surfaces can be written as To achieve a telecentric tube lens system, the distance from the pupil plane to the first principal plane needs to be the tube lens focal length, f TL . Based on the matrix optics theory, the distance, S 1 , from the first principal pane to the first refractive surface is given by [13] Then the distance, d O2L1 , from the pupil plane to the first refractive surface can be expressed as In Doublet Selector, in order to realise telecentric optimisation, once two suitable doublets are inserted into the Zemax file, the radius of curvature and refractive index of each surface are extracted and used to calculate the desired doublet separation within M P3 using the ABCD matrix in Eq. (10). Then the distance d O2L1 is calculated via Eqs. (11) and (12), and the tube lens system will be optimised with a target focal length and a target distance d O2L1 .
As for the optimisation option "Set distance from P to 1 st principal plane", the distance, b, from the pupil plane to the first principal plane is no longer fixed as the focal length. Therefore, the distance from the pupil plane to the first refractive surface becomes Then the tube lens can be optimised with a target focal length and a target distance d O2L1 ′ . The "Accuracy" pop-up menu in Doublet Selector is used when either "Telecentric" or "Set distance from EP to 1 st principal plane" is selected as the optimisation option. This value determines the maximum allowed numerical error in millimetres when calculating the overall focal length of the two doublets f TL from the overall ABCD matrix M overall . For the results presented in this paper, the Accuracy value was set to 0.01 mm.
We have also produced a version of Doublet Selector that can be used with versions of OpticStudio after 20.2 that employs the CARD optimisation operand in OpticStudio. In these later versions, as OpticStudio optimises the separation of the doublets and the position of the first principal plane using finite (exact) ray tracing, this setting therefore produces slightly different numerical results. Nevertheless, we tested a number of configurations and both versions of Doublet Selector returned the same pairs of optimised doublets. Both versions of Doublet Selector have been made available so that users with older versions of OpticStudio can still use Doublet Selector.

Tube lens configurations
In order to compare the optical performance among the four tube lens configurations, 2979 doublet combinations produced for System I (see section 3.2) were evaluated in four different configurations. The best performance with RMS centroid (based on the comparison criterion mentioned in section 2.4) for each configuration and fraction of times of each configuration providing the best performance are shown in Table 1.  Table 1 shows that although the Configuration A has the greatest fraction of times where it is the best of the four combinations, the best performance is provided by the Configuration C with the greatest cut-off field angle and the lowest RMS wavefront error at the maximum design field angle.

Software-produced tube lenses
To demonstrate the feasibility of our software, Doublet Selector was used to produce eight telecentric tube lenses using stock achromatic doublet pairs in four remote-refocusing systems, which we will refer to as Systems I-IV. Two tube lenses with a fixed distance from the entrance pupil to Doublet 1 were also generated to be used as a tertiary tube lens in an OPM system [14], which we will refer to as system V. The known parameters of Systems I-IV are listed in Supplement 1 Table S1. All of these remote-refocusing systems use water immersion in sample space (n 1 =1.33) and air in the intermediate image space (n 2 =1).
System I corresponds to the system described in papers [6,15], although since those publications Tube Lens 2 has been replaced by a manually selected pair of achromatic doublets (see Supplement 1 Table S2). System II was recently used in the high-speed 3D imaging of calcium dynamics [16]. Systems III and IV are also being constructed. All systems have a manually selected pair of achromatic doublets for Tube Lens 2, see Supplement 1 Table S2, that were chosen before the software presented in this manuscript was conceived. The original manual selection was relatively time consuming and performed with up to 3 achromatic doublets (Thorlabs, Edmund and Linos) for each focal length of doublet considered, and also tested a number of configurations (see Fig. 2) for each combination of doublets.
Doublet Selector was then used to try and find improved pairs of stock achromatic doublets to be used as Tube Lens 2 for these five remote-refocusing systems. The required tube lens design parameters are shown in Supplement 1 Table S3.
The original manually selected tube lenses will be used as a control group and compared with the tube lenses generated by Doublet Selector. In System II, the manually selected pair of achromatic doublets was chosen using a field angle of 2.5 degrees, while the maximum design field angle α TL2 of this system is 3.6 degrees; therefore, the performance of the Doublet Selector result was compared with the parameter used in the design of the original system at a maximum field angle of 2.5 degrees.
Based on the tube lens design data listed in Supplement 1 Table S3 and a doublet catalogue that includes 359 stock doublets -from Linos Photonics, Befort-Wetzlar, Comar, CVI Melles Griot, Daheng Optics, Ealing, Edmund Optics, Newport Corp, Optosigma, Ross Optical and Thorlabs -with focal lengths ranging from 200 mm to 700 mm and diameters ranging from 20 mm to 50 mm, then telecentric tube lenses consisting of achromatic doublet pairs were generated by Doublet Selector. Four were generated using the RMS centroid option and four using the RMS chief ray option. In System I, two tube lenses -one optimised with RMS centroid and the other one optimised with RMS chief ray -were selected from 2979×4 doublet combinations. In System II, the two tube lenses with different RMS references were selected from 1966×4 doublet combinations, respectively, while in System III and System IV, the best tube lenses are selected from only 15×4 and 100×4 combinations. The number of combinations assessed reflects the initial filtering step performed in the Doublet Selector to only perform the Zemax ray tracing on doublet combinations meeting these requirements. The computation time required for System I (with 2979×4 combinations) was 163×4 minutes on an Dell XPS 13-9350 laptop with an Intel Core i7-6560U processor and 8.00 Gb of RAM.
The best combinations of doublets selected by Doublet Selector for Systems I-IV can be seen in Supplement 1 Tables S4 and S5. All of these 8 software-produced tube lenses are in Configuration C. All tube lenses have a smaller RMS spot radius than their corresponding Airy radius at the maximum design field angles, see Table 2. Figure 6(a)-(d) shows the comparisons of "RMS vs. Field" diagrams of the original tube lens systems and the software-produced tube lens systems optimised with RMS centroid for Systems I to IV, while Fig. 6(e)-(h) are the corresponding comparisons of the original tube lens systems and the tube lenses optimised with RMS chief ray. According to the figures plotted by RMS centroid, all systems have about a factor of two improvement in the cut-off field angle, except for System IV (see Fig. 7(a & b)). In System I, the RMS wavefront error at the maximum design field angle of the new doublet combination is 0.0435 waves, which is about half that of the original combination (0.0861 waves). In System II and System III, the RMS wavefront error at their maximum design field angles of the new doublet combinations (0.0667 waves and 0.0646 waves respectively) are both smaller than those of the original manually selected tube lens systems (0.1062 waves and 0.1076 waves respectively). As for System IV, the software-produced tube lens has a similar performance to the original tube lens system, but it still has a slightly smaller RMS wavefront error at the maximum design field angle (0.0586 waves) than that of the original one (0.0621 waves), see Fig. 7(a). As for the results of tube lenses optimised with RMS chief ray, there is an improvement of the cut-off field angle in all software-produced systems, but not by as much as a factor of two. In System III, the new doublet combination has a slightly larger RMS wavefront error at the maximum design field angle than that of the original tube lens (see Fig. 7(c)), but it still provides a larger cut-off field angle (see Fig. 7(d)).
In these four remote-refocusing systems, the tube lenses produced by Doublet Selector all have a better performance than that of the original manually selected tube lens systems. Furthermore, all these software-produced tube lenses are diffraction limited across their design fields, which means that, based on stock optics, the software can effectively produce telecentric tube lenses with a good performance for remote-refocusing systems.   In order to test the ability of the software to produce non-telecentric tube lenses, a tube lens with a fixed distance from the entrance pupil to Doublet 1 was also generated by Doublet Selector to be used as a tertiary tube lens in an OPM system (System V) [14]. A comparison between the original manually selected tube lens and the software-produced tube lens was also carried out to illustrate the ability of the software.
The known parameters of System V and the tube lens design parameters are listed in Supplement 1 Table S6. The doublet catalogue used to produce this tube lens includes 79 doublets with focal lengths ranging from 200 mm to 250 mm and diameters ranging from 34 mm to 70 mm. 324×4 doublet combinations were compared to find the best tube lens system. The original doublet combination of the tertiary tube lens and the best doublet combination produced by the software are listed in Supplement 1 Table S7.
The comparison of the original doublet combination and the software-produced doublet combinations can be seen in Fig. 8. The cut-off field angle of the software-produced doublet combination is more than two-fold of that in the original manually selected tube lens system with RMS centroid. As for RMS chief ray optimisation, the software-produced result still has a better performance.

Discussion
The results presented above demonstrate the possibility of automatically producing diffractionlimited tube lenses from stock optics for remote-refocusing setups used in fluorescence microscope systems. All of the software-produced tube lenses have a better optical performance than the original manually selected tube lenses. In System I for the optimisation performed using the RMS wavefront error relative to the centroid, the RMS wavefront error at the maximum design field angle of the software-produced tube lens is about half that of the original manually selected tube lens. In System V again for the optimisation performed using the RMS wavefront error relative to the centroid, the cut-of-field angle of the software-produced tube lens reached 2.2-fold of that of the original system. The original manual selection of doublet pairs was performed before the work presented in this paper was conceived and therefore represents a 'real-world' benchmark for the selection of pairs of doublets without the use of dedicated software. Cases where the manual selection was more thorough -and a larger number of permutations were tested -are likely to mean that the improvement offered by the design produced by Doublet Selector is smaller. Nevertheless, the Doublet Selector software produces a better solution in all cases and with minimal user input.
In OPM systems, as the third microscope system images the intermediate image space at an angle, it is important to minimise distortion, and so for Systems I-IV it is most relevant to consider the tube lenses optimised using the RMS calculated relative to the chief ray. In other applications where distortion is not an issue, the tube lenses then can be optimised using the RMS centroid to obtain a better performance across the whole design field.
The results presented in this paper were performed using Zemax version 20.1. As versions of OpticStudio prior to 20.2 do not provide the CARD optimisation operand for optimising the principal plane positions, we used the methods introduced in section 2.5 to allow this to be achieved. This method requires the user to select an accuracy setting in the user interface. Doublet Selector runs rapidly for moderate accuracy settings in the range 0.1-1 mm, but the distance calculated from the entrance pupil (EP) to Doublet 1 is only approximate. More accurate results can be achieved at the expense of time once the accuracy setting is reduced (e.g., to 0.001-0.0001 mm). We found that both versions of Doublet Selector (for use with versions of OpticStudio before and after version 20.2) produced the same pair of optimised doublets in all of the systems (Systems I-V) presented in this paper.

Conclusion
This paper has presented two software packages -Catalogue Generator and Doublet Selector respectively -that were developed to generate doublet catalogues and produce the optimum doublet combinations with given focal lengths, entrance pupil diameters and maximum design field angles [17]. Compared to manually selected achromatic doublet pairs (tube lenses) used in different remote-refocusing systems, the software can produce tube lenses formed from pairs of stock achromatic doublets with improved performance -as measured by smaller RMS wavefront errors and larger cut-off field angles. The cut-off field angle was improved in all conditions tested and without the extensive manual work that was required for the manually selected pairs used as comparison. Owing to the ZOS-API, it enables an automatic optical design process and saves the time of manually comparing a wide range of achromatic doublets from stock optics.
We believe that the software developed is a useful tool for researchers wishing to access cost-effective solutions to achieving microscope tube lenses from pairs of stock achromatic doublets.