Engineering molecular chains in carbon nanotubes