<p indent="0mm">Proton-rich nuclei exhibit many novel phenomena, such as proton emission, proton halo, and Thomas-Ehrman shift. On one hand, due to the Coulomb force, outer protons have a lower nuclear separation threshold and are strongly coupled to the continuum. Such weakly bound nuclei are called the open quantum system. On the other hand, the Coulomb barrier restricts the spatial spread of the weakly-bound outer protons, resulting in that unbound resonance nuclei beyond the proton drip line may have certain lifetimes, e.g., a millisecond lifetime. The interplay of the continuum coupling and Coulomb forces produces a complex pattern in nuclei near the proton-rich drip line, which contains rich and unique structures and dynamic information. These properties lead to new insights into nuclear forces, symmetry breaking between mirror nuclei and many-body correlations. Recent experiment observed the ground state of <sup>18</sup>Mg via its decay into 4p<italic>+</italic><sup>14</sup>O. The decay of the ground state of this nucleus is consistent with two sequential steps of 2p decay passing through the ground state of <sup>16</sup>Ne. And another excited state at <sc>1.84 MeV</sc> was also observed, which may be the first 2<sup>+</sup> excited state. The excitation energy of this 2<sup>+</sup> state is significantly higher than that in <sup>18</sup>C, which shows a typical Thomas-Ehrman shift. In addition, this 2<sup>+</sup> excitation energy of <sup>18</sup>Mg exceeds that of <sup>20</sup>Mg. It is meaningful to study these novel phenomena through <italic>ab initio</italic> calculations. However, continuum coupling is important in these proton-rich nuclei, so the continuum degrees of freedom should be treated properly. Using the Berggren basis, the Gamow shell model provides a good description of the interplay between bound state, resonance, and continuum in a self-consistent many-body framework. In the present paper, we employ two- and three-nucleon forces from chiral effective theory, perform the Gamow shell model calculations of <sup>15–18</sup>C and <sup>15</sup>F–<sup>18</sup>Mg with continuum coupling included. The Gamow Hartree-Fock method with three-body force included was used to generate the Berggren basis, it can give a good description of the bound, resonant, and scattering states. The Hamiltonian is then normal ordered with respect to the Gamow Hartree-Fock reference state, and the normal ordered two-body approximation is adopted. We use the many-body perturbation theory to construct the effective Hamiltonian for the psd model space with s<sub>1/2</sub> and d<sub>5/2</sub> partial waves treated in Berggren basis. We calculate the <inline-formula content-type="pic" id="INLINE22"><mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" display="inline"><mml:mover accent="true" other="0"><mml:mi other="0">S</mml:mi><mml:mo other="1">^</mml:mo></mml:mover></mml:math></inline-formula>-box up to the third order and <inline-formula content-type="pic" id="INLINE23"><mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" display="inline"><mml:mover accent="true" other="0"><mml:mi other="0">Q</mml:mi><mml:mo other="1">^</mml:mo></mml:mover></mml:math></inline-formula>-box up to the second order. We use the Jacobi-Davidson method to diagonalize the complex-symmetric model-space Hamiltonian, and allow at most two valence particles in the continuum. The energies of the ground and first 2<sup>+</sup> excited states are calculated for <sup>15–18</sup>C and <sup>15</sup>F–<sup>18</sup>Mg. The calculated energies agree well with experimental data or evaluations. By calculating occupation probabilities and effective single-particle energies of the <inline-formula id="INLINE24"><mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" display="inline"><mml:mrow><mml:mtext>π</mml:mtext><mml:mn>1</mml:mn><mml:msub other="0"><mml:mtext other="0">s</mml:mtext><mml:mrow other="1"><mml:mn other="1">1</mml:mn><mml:mo other="1">/</mml:mo><mml:mn other="1">2</mml:mn></mml:mrow></mml:msub></mml:mrow></mml:math></inline-formula> and <inline-formula id="INLINE25"><mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" display="inline"><mml:mrow><mml:mtext>π</mml:mtext><mml:mn>0</mml:mn><mml:msub other="0"><mml:mtext other="0">d</mml:mtext><mml:mrow other="1"><mml:mn other="1">5</mml:mn><mml:mo other="1">/</mml:mo><mml:mn other="1">2</mml:mn></mml:mrow></mml:msub></mml:mrow></mml:math></inline-formula> orbitals, we analyze the continuum-coupling effect in the ground state of <sup>18</sup>Mg. The calculation of the mirror energy difference between the 2<sup>+</sup> states of <sup>18</sup>C and <sup>18</sup>Mg is improved with continuum coupling included. We have systematically calculated the first 2<sup>+</sup> states in <italic>Z</italic>=12 isotopes, supporting the experimental observation that the 2<sup>+</sup> excitation energy in <sup>18</sup>Mg is slightly higher than that in <sup>20</sup>Mg. There have been no experimental data for <sup>20</sup>Si and <sup>22</sup>Si. We predict that the 2<sup>+</sup> excitation energy in <sup>20</sup>Si is lower than that in <sup>22</sup>Si with the real-energy shell-model calculation.