  We present a scaling theory and Monte Carlo (MC) simulation results for a
flexible polymer chain slowly dragged by one end into a nanotube. We also
describe the situation when the completely confined chain is released and
gradually leaves the tube. MC simulations were performed for a self-avoiding
lattice model with a biased chain growth algorithm, the pruned-enriched
Rosenbluth method. The nanotube is a long channel opened at one end and its
diameter $D$ is much smaller than the size of the polymer coil in solution. We
analyze the following characteristics as functions of the chain end position
$x$ inside the tube: the free energy of confinement, the average end-to-end
distance, the average number of imprisoned monomers, and the average stretching
of the confined part of the chain for various values of $D$ and for the number
of monomers in the chain, $N$. We show that when the chain end is dragged by a
certain critical distance $x^*$ into the tube, the polymer undergoes a
first-order phase transition whereby the remaining free tail is abruptly sucked
into the tube. This is accompanied by jumps in the average size, the number of
imprisoned segments, and in the average stretching parameter. The critical
distance scales as $x^*\sim ND^{1-1/\nu}$. The transition takes place when
approximately 3/4 of the chain units are dragged into the tube. The theory
presented is based on constructing the Landau free energy as a function of an
order parameter that provides a complete description of equilibrium and
metastable states. We argue that if the trapped chain is released with all
monomers allowed to fluctuate, the reverse process in which the chain leaves
the confinement occurs smoothly without any jumps. Finally, we apply the theory
to estimate the lifetime of confined DNA in metastable states in nanotubes.
