{'fraction_non_alphanumeric': 0.0486782720825274, 'fraction_numerical': 0.03230634613613337, 'mean_word_length': 4.1468357430670775, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Apsidal Alignment and Anti-Alignment of Planets in Mean-Motion Resonance: Disk-Driven Migration and Eccentricity Driving

Planets migrating in their natal discs can be captured into mean-motion resonance (MMR), in which the planets' periods are related by integer ratios. Recent observations indicate that planets in MMR can be either apsidally aligned or anti-aligned. How these different configurations arise is unclear. In this paper, we study the MMR capture process of migrating planets, focusing on the property of the apsidal angles of the captured planets. We show that the standard picture of MMR capture, in which the planets undergo convergent migration and experience eccentricity damping due to planet-disc interactions, always leads to apsidal anti-alignment of the captured planets. However, when the planets experience eccentricity driving from the disc, apsidally aligned configuration in MMR can be produced. In this configuration, both planets' resonance angles circulate, but a"mixed"resonance angle librates and traps the planets near the nominal resonance location. The MMR capture process in the presence of disc eccentricity driving is generally complex and irregular, and can lead to various outcomes, including apsidal alignment and anti-alignment, as well as the disruption of the resonance. We suggest that the two resonant planets in the K2-19 system, with their moderate eccentricities and aligned apsides, have experienced eccentricity driving from their natal disc in the past.


INTRODUCTION
Even before the first detection of exoplanets, it was recognized that planets can migrate from their initial birth positions due to interactions with their natal protoplanetary disks (PPDs; Lin & Papaloizou 1979;Goldreich & Tremaine 1979, 1980, see Nelson 2018 for review). The speed and direction of migration depends on the disc density and temperature profiles. While planet-disc interactions typically circularize the planet's orbit, eccentricity excitation can also occur under some circumstances. Goldreich & Sari (2003) demonstrated how Lindblad and corotation resonances compete to either drive or damp a giant planet's eccentricity. More recently, Teyssandier & Ogilvie (2017) and Ragusa et al. (2017) found that, in long-term (≥ 10 4 orbits) hydrodynamic simulations, the eccentricity of a large, gap-opening planet exhibits growth and decay as the system evolves. Romero et al. (2021) found that luminous, super-earth mass protoplanets can be driven to eccentricities beyond the disk's aspect ratio through a thermal back-reaction effect from the perturbed gas disk.
As two planets undergo differential migrations in the PPD, they may encounter mean-motion resonance (MMR), where the planets' periods are related by integer period ratios j : j + k. For sufficiently slow, convergent migration, the mutual gravitational interaction between the planets can lead to MMR capture. The period ratio distribution of super-Earths/mini-Neptunes discovered by the Kepler mission indeed shows an excess of planet pairs near MMRs, although the observed MMR occurrence rate is much lower than the MMR capture rate predicted using the simplest migration/capture model. The "near MMR" systems typically have period ratios slightly larger (by 1-2%) than exact resonance (e.g. Fabrycky et al. 2014). These discrepancies could be explained by the instability of the captured state during disk-driven migration (Goldreich & Schlichting 2014;Deck & Batygin 2015;Delisle et al. 2015;Xu & Lai 2016;Xu et al. 2018), resonance repulsion due to tidal eccentricity damping or planet-disk interactions (Lithwick & Wu 2012;Batygin & Morbidelli 2013;Delisle & Laskar 2014;Choksi & Chiang 2020), late-time dynamical instability (Izidoro et al. 2017), and/or outward (divergent) migration due to planetesimal scatterings (Chatterjee & Ford 2015).
An interesting property of MMR capture concerns the relative apsidal angle ∆ = 1 − 2 of the captured planets. For the first-order MMR (j : j + 1), the two resonant angles are where λ1 and λ2 are the mean longitudes of the planets. In equilibrium, we expect θ1 and θ2 to be either 0 • or 180 • , implying ∆ = 0 • or 180 • . As we will see in Section 2, the conventional treatment of migration and resonance capture in PPDs always produces apsidal anti-alignment when the planet's eccentricity is damped by the disk. Only a handful of systems in or near resonance have constrained measurements of ∆ , and, indeed, most exhibit apsidal anti-alignment ( = 180 • ). Kepler-88 hosts two planets, b and c, near the 1:2 resonance with periods 10.9 d and 22.3 d and masses 214M⊕ and 9.5M⊕, respectively (Weiss et al. 2020). Kepler-9b and c are two sub-Jupiter mass planets (M b = 0.25MJ and Mc = 0.17MJ ) orbiting near the 1:2 MMR (P b = 19.2 d and Pc = 38.9 d; Holman et al. 2010). Both of these systems are constrained by their photodynamical data to have ∆ ≈ 180 • (Antoniadou & Libert 2020). The system K2-24 has two approximately Neptunemass planets (M b = 19M⊕, Mc = 15.4M⊕), K2-24b and c, near the 1:2 resonance with periods P b = 20.8 d and Pc = 42.3 d (Petigura et al. 2018). The observations of K2-24 are consistent with either the apsidally aligned or anti-aligned configuration (Antoniadou & Libert 2020). The only aligned system detected thus far is K2-19, a three planet system around a K dwarf star (M = 0.88M ; Armstrong et al. 2015). The planets K2-19b and c are near the 2:3 period ratio (P b = 7.9 d, Pc = 11.9 d), and planet K2-19d lies on an orbit interior to the other two at P d = 2.5 d. Their masses are M d < 10M⊕, M b = 32.4M⊕, and Mc = 10.8M⊕, with radii R d ≈ 1.1R⊕, R b ≈ 7.0R⊕, and Rc ≈ 4.1R⊕. The K2-19 photometry data indicates that the innermost planet has e d 0, planets b and c have moderate eccentricities, and e b ≈ ec ≈ 0.2. Their apsidal angles are constrained to within a few degrees of 0 • Petit et al. 2020). The origin of this alignment is unclear.
Investigating how the two planets in K2-19 could have formed with ∆ = 0 • through resonance capture and mutual migration (while other systems have ∆ = 180 • ) may offer us new insight into its dynamical history as well as a better understanding of the genesis of extrasolar orbital configurations in general. In this paper, we study the apsidal property of planets in MMRs produced by disk-driven migration. In Section 2, we present the standard picture of resonant capture and explore the parameter space for the coupling between the planets and the protoplanetary disk. We show that as long as the disk damps the planetary eccentricity, MMR capture always leads to apsidal anti-alignment. In Section 3, we explore the apsidal property for a test particle in the vicinity of the MMR with an eccentric planet's MMR. These results guide our analysis in Section 4, where we show that when planet-disc interaction drives the planet's eccentricity toward a finite, non-zero value, apsidal alignment can be produced under certain circumstances. We conclude in Section 5.

DISK-DRIVEN MMR CAPTURE: STANDARD APSIDAL ARCHITECTURE
Consider two planets with masses m1 and m2 orbiting a star of mass M (set to 1M throughout this paper) with semimajor axes a1 and a2 (> a1) in a gaseous disk. At low eccentricities, the orbital decay rate and eccentricity damping rate due to planet-disc interactions are given bẏ for each planet (i = 1, 2). For low-mass planets undergoing type-I migration and typical disc profiles, we have (Tanaka & Ward 2004;Cresswell & Nelson 2008) where ai is the semimajor axis (SMA), Σ is the disc surface density, h is the aspect ratio of the disk, and ni is the mean motion. Note that Te,1/Te,2 = m2/m1 = 1/q. Throughout the paper, we treat Te,1 and Te,2 as constants (independent of the semimajor axis) and use Te,0 = Te,1Te,2 as the basic timescale for eccentricity damping. We set h = 0.03 and Te,0 = 1000P2,0, where P2,0 is the initial period of m2.

Equations of motion
For two planets on coplanar orbits near the j : j+1 MMR, the Hamiltonian can be approximated to order O(e 2 ) as (Murray & Dermott 2000) H = H kep + Hres + Hsec, with the Keplerian, resonant, and secular terms given by where θ1 and θ2 are given in equations (1) and (2). Here, the fi are functions of the semimajor axis ratio α = a1/a2 that can be found in Appendix B of Murray & Dermott (2000): where D ≡ d/dα and the b m l are Laplace coefficients. Near the 2:3 MMR, we have f1 ≈ 2.0, f2 ≈ −2.5, f3 ≈ 1.15 and f4 ≈ 2.0.
The Hamiltonian system defined by equation (7) admits eight coupled ordinary differential equations, which we may integrate together with dissipative terms (equations 3 and 4) to simulate MMR capture. The canonical Poincairé momentum-coordinate variables are Figure 1. Standard MMR capture process for h = 0.03 and q = m 1 /m 2 = 2. The inner planet starts at the SMA a 1 = 1 au and the outer planet starts wide of the 2:3 resonance at P 2 /P 1 = 1.6. Both planets have very small initial eccentricities, e 1 = e 2 = 0.001. Note that to have convergent migration, we adopt T m,i < 0 (i.e. both planets migrate outwards). The planets are captured into the resonance around t = 20, 000 yrs, indicated by the libration of θ 1 → 180 • and θ 2 → 0 • and the period ratio approaching the equilibrium value ( 1.55). While in resonance, the eccentricities are driven to the equilibrium values, e 1 ≈ 0.008 and e 2 ≈ 0.016, and the periapses are anti-aligned.
We apply Hamilton's equations to generate the equations of motion (to second order in eccentricities) and add in the dissipative effects: Te,2 , λ2 = n2 + µ1n2 2f1e1 cos θ1 + 5 2 f2e2 cos θ2 Note that the right-hand sides of these equations depend on λ1 and λ2 solely through the combination (j + 1)λ2 − jλ1. By combining equations (21) and (22) into a single equation for (j + 1)λ2 − jλ1, we may reduce the number of equations to seven. We integrate the system with the Runge-Kutta method of order 5(4) included in the scipy Python package. We set a relative and absolute tolerance = 10 −9 . The resonance angles are initialized over a uniform distribution between 0 • and 360 • . At t = 0, we set a1 = 1 au, P2/P1 = 1.6, and e1 = e2 = 0.001. An example of MMR capture is shown in Fig. 1. The period ratio P2/P1 starts wide of the nominal 2:3 resonance value. After around 2 kyr of convergent migration, the planets are caught into the MMR, indicated by the stabilization of θ1 to 180 • and θ2 to 0 • . The planets' eccentricities level off at their equilibrium values at e1 ≈ 0.008 and e2 ≈ 0.016, and the planets become apsidally anti-aligned with 1 − 2 ≈ 180 • .

Equilibrium
The MMR capture shown in Fig. 1 leads to an equilibrium state in period ratio, resonant angles, eccentricities, and ∆ . By requiringė1 = 0,ė2 = 0, and˙ 1 −˙ 2 = 0, we arrive at and T e,0 = T e,1 T e,2 = 1000 yrs constant, but allow the eccentricity damping and migration timescales to vary with q, as in equations (5) and (6).
For q = 0.5, the inward migrating branch (T e,1 > T e,2 ) agrees well with the equilibrium result. However, for the outward migrating branch the analytic solution typically overestimates the final eccentricities. The results are similar for q = 1, 2.
Utilizing the scipy root finding library, assuming α = α0, we solve the four equations (27) -(29) and (34) for the equilibrium values of θ1, θ2, e1, e2. The equilibrium ei's and ∆ 's for comparable mass planets (q ∈ [0.5, 2]) are given in Figures  2a and 2b as the dashed lines. The equilibrium eccentricities go approximately as e2/e1 ∼ q, and all systems are predicted to have ∆ ≈ 180 • . To validate these analytical results, we also integrate the time dependent equations which simulate MMR capture and plot the average e1, e2, and ∆ over the last 10% of the simulation. For Te,1 < Te,2 (Te,1 > Te,2), we set Tm,i < 0 (Tm,i > 0), corresponding to outward (inward) migration. The numerical (markers) and analytical (dashed lines) results largely agree. Thus, in the standard picture of MMR capture in PPDs, comparable mass planets always end up settling down to θ1 ≈ 180 • and θ2 ≈ 0 • , and the eccentricity vectors of the planets are anti-aligned,

Survey of parameter space: Eccentricity damping timescales
In Section 2.2, we adopted the standard scaling relationwith Te,1/Te,2 = 1/q = m2/m1 and Te,i = 3.46h 2 |Tm,i|which always gives rise to apsidal anti-alignment for typical disc conditions (h 0.1) and planet masses. A real PPD may have significant surface density variation that leads to a different ratio Te,1/Te,2. Here we study the effects of different Te,1/Te,2 on the equilibrium values of ei and whether such a change could lead to apsidal alignment. We explore this possibility in Figures 3 and 4 by varying Te,1/Te,2 between 0.2 and 10, regardless of the mass ratio. The migration timescale is still set to |Tm,i| = Te,i/(3.46h 2 ). We can see that for comparable mass planets with q = 0.5, 1, and 2, varying the ratio Te,1/Te,2 around 1/q modifies the final equilibrium eccentricities by a roughly similar factor. The dashed lines of Fig. 3 show the analytic results from solving equations (27) -(29) and (34); these results agree with our time dependent integrations.
For integrations where the migration direction is the opposite of what it would be if Te,1/Te,2 = 1/q = m2/m1 (i.e., Te,1/Te,2 < 1 for q = 0.5), the analytical results systematically overestimate the final eccentricities for Te,1/Te,2 < 1, and underestimate them for Te,1/Te,2 > 1. The eccentricity ratio e1/e2 is unchanged, yet e1 and e2 are larger for more extreme values of Te,1/Te,2. The corresponding values for ∆ are shown in Fig. 4. In all cases, both the analytic equilibrium equations and the numerical integrations yield ∆ 180 • . The peaked shape of the dashed lines in Figures 2a and  3 can be explained as follows. As Tm,1/Tm,2 = Te,1/Te,2 approaches unity, the effective migration timescale Tm approaches infinity. Equation (34) therefore implies that the planets' eccentricities approach zero. We note that the equilibrium solutions are not continuous across q = 1 (Fig. 2) and Te,1/Te,2 = 1 (Figures 3 and 4), which is where we reverse the migration direction to ensure that it is convergent.
In summary, we find that varying the eccentricity damping ratio cannot account for the observed apsidal alignment in some MMR systems (such as K2-19). Before proposing a possible solution in Section 4, we consider in Section 3 the simpler problem of a test mass orbiting near a MMR with a finite-mass planet in order to gain some insight on the dynamics of apsidal angles.

MMR IN THE RESTRICTED 3-BODY PROBLEM
The dynamics of first-order MMRs with comparable mass planets is complicated by the presence of two critical arguments in the Hamiltonian, θ1 and θ2. By assuming that one of the planets is a test particle, we may ignore the dynamical evolution of the other planet. To emphasize the fact that we are formally transitioning to a different problem, we adopt the following notation: The subscript p will denote the quantities associated with the massive planet, while no subscript will indicate those associated with the test particle. Neglecting additive constants, the Hamiltonian for an exterior test particle (m2 = 0) is given by We assume that no dissipative force acts on the massive planet while implementing the same force as in Section 2 for the test particle.
3.1 Circular massive planet: ep = 0 When a test particle is caught into a stable resonance, its eccentricity grows and saturates at a finite value which depends on the ratio Te/Tm (e.g. Goldreich & Schlichting 2014;Xu et al. 2018). For an exterior test particle, If ep = 0, the system has no preferred direction, and so must circulate.

Eccentric massive planet
When the massive planet has a moderate eccentricity, the qualitative features of the ep = 0 result are preserved as long as ep eeq. In Fig. 5, we show the capture process for a system with ep = 0.04 and h = 0.03 (thus eeq = 0.028). As we can see, the particle is still captured into the 2:3 resonance and θ2 librates around 180 • . The eccentricity e librates around its equilibrium value with large amplitude, and the longitude of perihelion, , still circulates. Fig. 6 shows the capture process for ep = 0.054 (and the same eeq = 0.028). We see that, for ep eeq, the test particle's migration halts near the nominal resonance location of P2/P1 = 1.5 while both θ1 and θ2 continue to circulate. The particle's eccentricity librates with slightly larger amplitude than in Fig. 5. Eventually, the system becomes apsidally aligned.
In Fig. 7, we summarize the behavior of the final ∆ for an exterior test particle captured into the 2:3 MMR with a massive planet, for different values of ep and h (and subsequently eeq). Generally, for ep eeq, the system becomes apsidally aligned. Figure 5. The capture process of a test particle into the 2:3 MMR with a massive planet with µp = 10 −4 , ap = 1 au and eccentricity ep = 0.04. We have set h = 0.03 (which gives eeq = 0.028) and Te = 1000Pp. After the particle is captured into resonance, both θ 2 and e librate with large amplitude, and circulates. Figure 6. Same as Fig. 5, except ep = 0.054. Although P 2 /P 1 settles down to a value very close to 3/2, the resonance angle θ 2 circulates throughout the evolution. As in Fig. 5, the test particle eccentricity librates with large amplitude, but now its apsidal angle becomes aligned with p ≡ 0 • .

ECCENTRICITY DRIVING BY DISC AND APSIDAL ALIGNMENT IN MMR
We have seen in Section 2 that whenever two comparablemass planets are captured into the θ1 and θ2 resonances, the system always has ∆ ≈ 180 • because θ1 and θ2 settle down to 180 • and 0 • , respectively. The apsidally aligned K2-19 system (see Section 1) therefore poses a problem for the standard migration-driven MMR capture model. In order to match this observation, either θ1, θ2, or both angles must circulate.
In Section 3, we have seen that apsidal alignment arises whenever the massive planet has an eccentricity larger than the equilibrium eccentricity of the test particle in resonance. Guided by this result, in this section, we examine the possibility that planet-disc interaction drives planet's eccentricity to a finite value and explore its consequences for the apsidal Figure 7. The behavior of the final ∆ for a range of values for h and ep when an exterior test mass is captured into the 2:3 MMR with a planet of mass µp = 10 −4 . For a given h, the system becomes apsidally aligned for sufficiently large ep (see Fig. 6 for an example). The dashed line indicates our analytical approximation for the boundary between the -aligned and -circulating regions.
angles in MMR capture. In addition, we reformulate the 2planet Hamiltonian into a single-degree of freedom system; this allows us to identify the key dynamical processes that lead to apsidal alignment.

Effects of disc eccentricity driving on MMR
As noted in Section 1, under appropriate conditions, planetdisc interactions can increase a planet's eccentricity rather than damp it (e.g. Goldreich & Sari 2003;Teyssandier & Ogilvie 2017;Ragusa et al. 2017). A recent study demonstrates that a super-earth-sized luminous protoplanet can attain an eccentricity larger than the disc aspect ratio (Romero et al. 2021).
The planets K2-19b and c are moderately eccentric, with e b ≈ ec ≈ 0.2 . Petit et al. (2020) suggest that the apsidal alignment in this system could be caused by eccentricity driving to a common value. To mimic the effect of eccentricity driving by the disk, we modify the eccentricity damping term in equation (4) tȯ so that planet mi is driven toward e i,d on the timescale Te,i. In Fig. 8, we show the result of MMR capture for a system with e 1,d = 0.2, e 2,d = 0.0, and mass ratio q = m1/m2 = 2. We initialize the system with e1 = e2 = 0.001 at the nominal resonance location, P2/P1 = 1.5. The planets are caught in the θ1 and θ2 resonances for 10,000 years, after which the planets escape the resonance and the angles circulate. At this point, both planets' eccentricities are excited to about ei ≈ 0.2 and the planets become apsidally aligned as ∆ librates around 0 • with a large amplitude. Despite the circulation of both resonance angles, the period ratio remains locked very close to the nominal resonance value (P2/P1 = 1.5). The system is caught in a different type of resonance which we will study in the following subsection.
On the other hand, for e 2,d = 0.2 and e 1,d = 0, the system displays different resonance capture behavior. We show the result for this case in Fig. 9. We see that the angle θ2 librates with a large amplitude around its resonant value of 0 • , whereas θ1 librates around 270 • rather than 180 • . As a result, ∆ approaches 90 • , i.e. the planets' perihelia are now perpendicular to each other.

Reducing the Hamiltonian
To understand the results of Section 4.1, we carry out an analysis of the MMR Hamiltonian (equation 7). This helps to illustrate the underlying dynamics behind the capture process in Fig. 8 which leads to apsidal alignment. It can be shown that θ1 and θ2 are actually subresonances of a resonanceθ, which arises after transforming the system's Hamiltonian so that it has only a single degree of freedom (Henrard et al. 1986;Deck et al. 2013).
If we assume that the secular behavior of the semi-major axis ratio α is stationary or varying adiabatically, we may transform the resonant Hamiltonian HKep + Hres in equation (7) into the form through a series of rotations in phase space. For the details of these transformations, see Appendix A. The Hamiltonian in equation (38) is well studied in the literature (e.g., Murray & Dermott 2000). The parameter δ quantifies the system's depth into resonance. We do not include Hsec in this analysis because it is second order in eccentricities.
This angle is the same one that Petit et al. (2020) found to librate in the K2-19 system.

Three modes of resonance
The one-degree-of-freedom Hamiltonian (equation 38) admits the following conserved quantity: By enforcing dS2/dt = 0 together with the assumption dα/dt = 0, we arrive at the following equilibrium condition: where  Fig. 1, except for the initial period ratio, which we set to the nominal resonance location, P 2 /P 1 = 1.5, so that the system is very quickly caught into the θ 1 and θ 2 resonances. After about 10 kyr, the system escapes the circular resonances, indicated by the circulation of θ 1 and θ 2 . At this point, the planets becomes apsidally aligned and ∆ librates around 0 • .
The systems depicted in Figures 1, 8, and 9 are representative of three different modes of resonance, ones with ∆ 180 • , ∆ 0 • , and ∆ 90 • , respectively. These correspond to three different behaviors of the quantities σ1 and σ2 while in resonance under the influence of eccentricity forcing. In Fig. 10, we show σ1, σ2, and S2 for these systems. The top row is for the standard eccentricity damping case where e 1d = e 2d = 0. Once the system equilibrates, S2 ≈ 10 −4 is well conserved (top left) and small. Both σ1 and σ2 are also close to zero. From equations (42) and (43), we see this corresponds to e2/e1 ∼ q, as we found in Section 2. The second row of Fig. 10 corresponds to the system shown in Fig. 8, where e 1d = 0.2 and e 2d = 0. At early times, while the system is still caught in the θ1 and θ2 resonances, σ1, σ2, and S2 are small. Once the θ1 and θ2 resonances are broken, and onlyθ librates, σ1, σ2 and S2 are excited to larger values. The quantities σ1 and σ2 undergo large periodic oscillations away from zero, while S2 grows and then stabilizes at its new equilibrium value, S2 ≈ 0.5. The planets' eccentricities oscillate in such a way as to conserve S2. The bottom row of Fig. 10 corresponds to the system in Fig. 9, where e 2d = 0.2 and e 1d = 0, where the planets' perihelia are perpendicular. For this case, σ2 is conserved close to 0, while σ1 grows to a magnitude similar to its value in the apsidally aligned case.
In Fig. 11, we plot the eccentricity vectors e1, e2, andê in the reference frame rotating with e1. The three systems begin with the same configuration, caught in the θ1 and θ2 resonances; the vectors e1 and e2 are anti-aligned, whileê is aligned with e1. At later times, the system without eccentricity driving remains in this configuration (top row). The second and third rows exhibit the new resonance behaviors described above. For the apsidally aligned case (middle row), e2 circulates in a pattern strictly constrained to the second and third quadrants, andê circulates around the other two vectors. In the bottom row, e1 and e2 are perpendicular to each other andê is aligned with e2.

Dependence on e 1,d and e 2,d
Now that we have identified these three resonant modes, here we explore the (e 1d , e 2d ) parameter space for moderate values between 0 and 0.2. The top row of Fig. 12 shows the result for q = 2, h = 0.03, and initial period ratio P2/P1 = 1.5. In the left panel, we summarize the resonant behavior for each system on an e 1,d -e 2,d grid. We mark the run which becomes unstable and escapes the resonance within the timescale of our integration by an x marker. Roughly, for e 1d e 2d , the system becomes apsidally aligned (∆ = 0 • ). For e 2d > e 1d , one case exhibits ∆ = 90 • , one escapes, and the others are apsidally anti-aligned. In the right panel of Fig. 12, we plot the time-averaged final eccentricities of the planets. The points share the same color-coding as in the left panel. The eccentricities for the aligned cases fall roughly along the line e1 = e2, which reflects the fact that the angleθ does not The single x marker in the top left panel of Fig. 12 corresponds to a run which is only temporarily caught into resonance. We show the detailed evolution of this system in Fig. 13. Although all resonance angles circulate, the period ratio librates with a small amplitude around P2/P1 = 1.5. The planets remain in an anti-aligned configuration throughout. Before the escape, ∆ 180 • , while after the escape, ∆ 180 • .

Initial period ratio
In the second row of Fig. 12, we have kept all of the parameters from the first row constant, but shifted the initial location of m2 so that P2/P1 = 1.55. As we can see from the left panel, many more systems fail to be permanently captured. Fig. 14 displays the result of a system which fails to be captured in the resonance. We see that after a short period of convergent migration, the outer planet is repelled away from the resonance. Following an initial decrease, the period ratio increases and then turns around and levels off into a state which resembles the late-time behavior in Fig. 13. Fig. 15 depicts another example of failed resonance capture. Initially, both planets undergo convergent outward migration, but after some time, a1 begins to increase. Then, the planets skip the resonance as the period ratio passes through P2/P1 = 1.5 from above. It continues decreasing, turns around, and then skips the resonance from below.

Mass ratio
Now we turn to the effect of mass ratio on the resonance capture. Rows three and four of Fig. 12 summarize the results of running identical integrations to the first two rows but setting q = 0.5, reversing the migration direction, and modifying the dissipation timescales appropriately. Only one system out of the 18 in the last two rows of Fig. 12 becomes apsidally aligned, while for all cases with e 2,d = 0, the planets are anti-aligned. The top-left-most points (i.e. e 2,d > e 1,d ) all escape the resonance whenever q < 1.
In Fig. 16, we display the result of a system from the third row of Fig. 12. It has e 1d = 0.2, e 2d = 0.1, and an initial period ratio P2/P1 = 1.5. At the beginning of the integration, the two planets convergently migrate in resonance. Librations in the period ratio grow in amplitude over time. Eventually, the planets escape the resonance. The inner planet m1 is kicked outwards and m2 continues migrating inwards until the two planets' orbits cross. This behavior could be related to the instability discovered for an inner test particle in the MMR capture ( Figures 1, 8, and 9. Each row corresponds to one of the three different modes of resonance identified in this paper, ∆ = 180 • , ∆ = 0 • , and ∆ = 90 • , respectively. For ∆ = 180 • (upper row), σ 1 , σ 2 , and S 2 are conserved near zero. For the other two cases, S 2 transitions to larger values near ∼ 0.5 (middle) and ∼ 0.1 (bottom) as the eccentricity reaches an equilibrium. Both σ 1 and σ 2 are excited to factors of a few in the apsidally aligned case (middle row), while only σ 1 is excited for the ∆ = 90 • case (bottom row). For ∆ = 0 • and ∆ = 90 • cases, the eccentricities oscillate in such a way to conserve S 2 according to equation (41). 4.7 Test particle limit 4.7.1 Relationship to the comparable mass case The test particle Hamiltonian in equation (35) can also be transformed into the form of equation (38) through a canonical shift, analagous to the reducing rotation utilized in Section 4.2. Relative to the comparable mass case, the testparticle analysis is simpler because the vector ep remains constant in time. Because of this, we now return to the test particle treatment of Section 3, with the goal of obtaining a heuristic understanding of apsidal alignment in real planetary systems (i.e. 0 < q < ∞).
For simplicity, we restrict ourselves to the case of an exterior test particle (as in Fig. 7), which is equivalent to the formal limit of q = m1/m2 → ∞. We now compare the q = ∞ case to the q = 2 case, the latter of which we have investigated in Section 4 (i.e. the first two rows Fig. 12). Traversing Figure 7 along the ep axis is equivalent to traversing the e 1,d axis in Fig. 12. However, the vertical axis of Fig. 7 (h) is not equivalent to the vertical axis in Fig. 12 (e 2,d ). To relate these two quantities, we use eeq = h 1.73/j (equation 36) as a proxy for the "disk-driven eccentricity" of the test particle. One can see in Fig. 12 that, for the q = 2 systems that do not escape, the division between " − aligned" and " − anti-aligned" roughly corresponds with the division between " −aligned" and " −circulating" for the test particle systems in Fig. 7. In the following, we treat " − circulating" and " − anti-aligned" as being equivalent dynamical states. Figure 11. The eccentricity vectors e 1 , e 2 , andê in the reference frame rotating with e 1 . As in Fig. 10, each row represents the different combination of e 1d and e 2d corresponding to the three different modes of resonance. The left column shows the initial conditions of the resonance, while the right column shows the evolution at late times (at t = [34 − 38] × 10 3 orbits). The top row (∆ = 180 • ) exhibits little qualitative change between the initial and late times besides the libration amplitudes shrinking to zero. The second row (∆ = 0 • ) shows e 2 circulating around e 1 strictly contained to the second and third quadrants. The last row (∆ = 90 • ) shows e 1 and e 2 transitioning into a perpendicular arrangement. Meanwhile, theê vector circulates outside of both e 1 and e 2 in the second row, while remaining aligned with e 2 in the bottom row.

The condition for apsidal alignment
We again adopt the notation used in Section 3 for q = ∞. The resonant angleθ can now be written as tanθ = e sin θ e cos θ − |f1/f2|ep cos θp , which is the test-particle limit of equation (39) (see Appendix B for details), where we have assumed p = 0. In both the − aligned and − circulating cases, θp circulates andθ (as written in equation 44) librates around 0 • . However, θ librates around 180 • when circulates, and it circulates when librates around 0. This can be understood using the test-particle Hamiltonian (equation 35):˙ is proportional to cos θ, and so cannot librate if θ remains close to 180 • . The angle θ therefore determines the behavior of ∆ in Figure 12. The resonance architecture for systems spanning a grid of driving eccentricities e 1,d , e 2,d (left) and the numerically averaged final eccentricities (right). We hold h = 0.03 and T e,0 = 1000 yrs, while varying e 1,d and e 2,d . Systems which are not captured or become unstable and escape resonance are denoted by black "x"-marks. Roughly, for e 1d e 2d , the system becomes aligned. For e 2d e 1d , the system becomes perpendicular (∆ = 90 • ) for large values of e 2d . The other systems remain trapped in both of the θ 1 and θ 2 resonances. The time-averaged eccentricities of the apsidally aligned systems fall just below the line e 2 = e 1 . The error bars are their standard deviations. The single perpendicular system (see the top left panel) falls just above the line e 2 = 2e 1 = qe 1 , while the anti-aligned systems fall just below it. Both have small librations compared to the aligned case. resonance for a test particle. Consider equation (44): sincê θ always librates around 0, then tanθ remains finite; this implies that the denominator never reaches 0. Because θp always circulates, cos θp takes on values between −1 and 1. Thus, when θ librates around 180 • , the following condition is required forθ to librate: We assume the eccentricity librates around a central eccentricity ec eeq + ∆e, which defines the parameter ∆e, and substitute this into equation (45): Using equation (36) to relate h and eeq, we estimate the transition to aligned perihelia to occurs for h < hc(ep), where hc is given by In principle, ∆e could be zero, but we find ∆e = 0.015 to be a better approximation, which we use for the line in Figure  7. Despite the many approximations, this analysis reproduces the numerical results fairly well.

Discussion for 0 < q < ∞
The above analysis shows that test particle apsidal alignment can be understood as a competition between eeq, which is related to h, and ep, the eccentricity of the massive planet. Our interpretation of this result in the comparable mass context is to identify the disc driven eccentricities e 1,d and e 2,d of Section 4 with eeq and ep in Section 3. Apsidal behavior in the comparable mass regime is more complex than the test-mass system. We observe that |∆ | = 0, 90 • , and 180 • are all possible. Each planet's eccentricity works on the other to anti-align their periapses in resonance. However, if disc forces drive them away from the ratio e1/e2 = 1/q, the tendency of anti-alignment can be overcome, resulting in a different apsidal configuration. The resulting configuration has a complicated dependence on the planet and disk parameters, with some systems escaping resonance (see Fig. 12). A detailed analysis of the effects of different parameters q, h, Te, and e i,d would reveal transitions between the resonance modes analogous to equation (47) for the comparable mass regime.

CONCLUSION
We have studied the mean-motion resonance capture of two migrating planets in protoplanetary disks, focusing on the property of the apsidal angles of captured planets. Our study is motivated by recent observations, which show that planets in MMR can be either apsidally aligned or anti-aligned (see Section 1).
To explore the possibility of producing apsidal alignment in MMR capture, we analyze the problem of a test particle in the vicinity of an MMR with a planet of mass mp (Section 3). We find that apsidal alignment occurs when the planet's eccentricity ep is comparable or larger than the "equilibrium" eccentricity of the test particle captured in MMR (see Fig. 7), the latter results from the migration and eccentricty damping by the disc, and depends on the disc apsect ratio h (see Eq. 37). The system starts off in resonance, with θ 1 , θ 2 andθ librating. However, after 10 4 years, the system breaks out of all three resonances. Nevertheless, the period ratio remains locked around 1.5 with small librations. The eccentricities reach the equilibrium values with large librations, while the apsidal angle ∆ transitions from slightly less than 180 • to slightly larger than 180 • .
Our test particle results inform our analysis of how apsidal alignment may arise in the case of comparable-mass planets. In Section 4, we show that when the planets experience eccentricity driving due to their interactions with the disc, apsidal alignment in MMR capture can be produced. The eccentricity driving forces prevent the libration of θ1 and θ2, allowing the captured planets to settle into the apsidally aligned state (see Fig. 8) in which a "mixed" resonant angleθ librates. However, in the presence of eccentricity driving, the process of MMR capture is highly irregular; depending on the initial condition, the planet mass ratio, and the magntitudes of the driving forces, various outcomes can be produced, including apsidal alignment, anti-alignment, and a perpendicular configuration (∆ = 90 • ), as well as resonance disruption (see Fig. 12). This paper represents the first investigation into the effect of eccentricity driving in mean-motion resonant systems. The observed apsidal alignment in the K2-19 system, the moderate eccentricites of K2-19b and c, and the libration of the "mixed" resonant angle (θ; Petit et al. 2020), can all be produced by this effect. These suggest that the planets in the K2-19 system have interacted with an eccentricity driving disc in the past. In addition, our finding that MMR capture can be disrupted by eccentricity driving may also contribute to the observed underabundance of exact MMRs (with P2/P1 = (j + 1)/j) in the Kepler multi-planet systems (Fabrycky et al. 2014), simply because the exact resonant sys-tems can be pushed to slightly larger period ratios whenever the disc drives the planet eccentricities.
Our results come with the obvious caveat that we have used simple parameterized models (with constant dissipative timescales) for the planetary eccentricity damping and driving by the disc. In reality, the coupling between the disc and planet is a function of eccentricity, location in the disk, and disc profile. Long-term hydrodynamical simulations of two migrating planets in discs, including the possibility of eccentricity driving, would be needed to fully explore the effects studied in this paper. Figure 14. Same as Fig. 8 (for q = 2) but with e 1d = 0 and e 2d = 0.2 and an initial period ratio of P 2 /P 1 = 1.55. The system corresponds to one of the x marks in the left, second row of Fig. 12. The period ratio initially decreases as the planets migrate convergently. Around t = 10 4 years, the period ratio increases, then again turns around and settles down into libration around 1.525, while all resonant angles circulate. The system convergently migrates outward for some time, after which it crosses the resonance location without being captured (i.e., the kink between t = 3000 and 4000 years). The period ratio then turns around and misses the resonance again, after which it continues to grow for the rest of the integration. In this example, as opposed to 14, but with q = 0.5, e 1d = 0.2, e 2d = 0.1 and an initial period ratio P 2 /P 1 = 1.5. This corresponds to one of the x marks in the left, third row of Fig. 12. The planets are caught into all three resonances for most of the integration. The period ratio is likewise locked near 1.5 with libration that grows slightly over time. Then the system exits all three resonances at the same time, after which m 1 launches outwards leading to eventual orbit-crossing.

A1 Scaling the Hamiltonian
The Hamiltonian for two comparable mass planets near the j : j + 1 resonance is where θ1 = (j + 1)λ2 − jλ1 − 1 and θ2 = (j + 1)λ2 − jλ1 − 2 (equations 1 and 2) are the resonance angles and f1 > 0, f2 < 0 (equations 11 and 12) are functions of the SMA ratio, α = a1/a2. Define mtot = m1 + m2 and let a0 be the scale length of the problem. We will then scale the Hamiltonian by H0 = GM mtot/a0, the time by the frequency ω0 = GM/a 3 0 , and the canonical momenta by Λ0 = mtot √ GM a0. The dimensionless Hamiltonian H is then wherem = m1m2/mtot is the reduced mass. We assume the reduced mass ratio is small (μ =m/M 1). The canonical momenta, coordinate pairs are where γ1 = − 1 and γ2 = − 2. The Hamiltonian can be expressed as a function of the momenta and resonance angles, where we have used q = m1/m2.
We have Γi Λi for small eccentricities. Under this assumption, we may drop terms smaller than O(Γ 2 i /Λ 4 i ). Equation (A12) becomes where C0 is a constant of resonance which depends on initial conditions. Hence, we leave C0 out of the following calculations. Absent any dissipation, Λ1 and Λ2 are approximately constant in resonance. Hence, we may also drop the first two terms in parentheses in equation (A14), leaving only the terms which include factors of (Γ1 + Γ2): The perturbation part (equation A13) reduces to its original form, because there is already a small factor (μ) in the numerator.
Let Ψ be the counter-clockwise phase space rotation by the angle ψ, where tan ψ = g2/g1, The block matrix is symplectic (Goldstein et al. 2000). The coefficients gi depend weakly on the semimajor axis ratio α, and so M only represents a canonical transformation if α is stationary or varying slowly, which is a good approximation for the systems considered in this paper. Define the coordinates W = (w1, w2, W1, W2) ≡ M X.
After the reducing rotation, neither H0 nor Hpert depend onθ2, and so its conjugate momentum, S2, is a constant of resonance: Through a scale transformation (which changes the time units by a factor of 1/A 2 ), we can remove the A 2 term in S 1 and S 2 . This results in the momentumR = 1 A 2 S 1 = f 2 1 e 2 1 − 2|f1f2|e1e2 cos( 1 − 2) + f 2 2 e 2 2 (A32) and conserved quantity where we have used the fact f1f2 = −|f1f2|.R has the following geometric interpretation: where the ei are the Runge-Lenz vectors with magnitude ei in the direction of i. The key characteristic of theR,θ conjugate pair is that it does not depend on the planetary mass ratio (e.g. Deck et al. 2013). Altogether, we arrive at the following Hamiltonian after dropping constant terms: H(θ,R) = H0(R) + Hpert(θ,R), with coefficients given by (A40)

APPENDIX B: TEST PARTICLE HAMILTONIAN
The internal and external test particle limits are largely analagous, and so we focus on the external limit, with q approaching infinity. The inner planet now has constant m1 = mp > 0, a1 = ap, e1 = ep, and 1 = p. We may arbitrarily set p = 0 due to rotational symmetry. The test particle has m2 = 0, a2 = a, e2 = e, and 2 = . We are again neglecting dissipative and secular effects in our analysis. After transforming to the dimensionless Poincairé elements Λ = a/ap and Γ = Λ(1− √ 1 − e 2 ) ≈ 1 2 Λe 2 , the Hamiltonian is where θp = (j + 1)λ − jnpt is now an explicit function of time. The coordinate γ = − is conjugate to Γ. Utilizing the approximation that α is varying adiabatically, we can effectively treat Λ and fi as constants while in resonance. Because we are now dealing with a potential that is an explicit function of time, the test particle formulation is formally different than the comparable mass problem, which is defined only for the parameter range 0 < q < ∞. The canonical transformation described in Appendix A, which is generated by the infinitesimal rotation about the origin, must also formally change. The corresponding transformation here is generated by the infinitesimal translation towards the inner planet's Runge-Lenz vector, ep.
We will reduce equation (B1) to a single degree of freedom Hamiltonian. If ep = 0, the resonance angle is θ = θp + γ. For