The structural and electronic properties of all-surface KI and CsI crystals encapsulated in single-walled carbon nanotubes are investigated theoretically with an ionic and atomistic approach using the GULP program. The short-range interactions, derived from Dirac-Fock wavefunctions, were augmented with damped dipole-dipole and dipole-quadrupole dispersive attractions. The uncorrelated interionic interactions computed using the relativistic crystal ion and relativistic integral programs accounted for anion in-crystal modifications while being exact given the ion wavefunctions. All the short-range correlation energies and the uncorrelated interactions between the ions and carbon atoms were computed using the density functional theory of a uniform electron gas of infinite extent. Unphysical self-interactions were removed by scaling the exchange interaction with a Rae factor derived from a study of the adsorption of noble gases on graphite. The predictions for the nonencapsulated crystals agreed well with those previously derived from a global analytic theory based on the Born model. This provided a good description of the contraction of the interplane distance (b) relative to the separation (R(e)) in the rocksalt structured bulk material although failing to account for the observed dilation of the intraplane ionic separations (a). Introduction of the interactions with the nanotube wall, including the ion-nanotube dispersive attractions, increased the predicted a values although these were still significantly smaller than experiment. The predicted b separations were reduced compared with those for the nonencapsulated crystals to values significantly less than observed. It is explained why introducing any ion-nanotube interactions that are sufficiently attractive as to reproduce the experimental a values must significantly underestimate the b separations. The partial transfer of anion electrons to the nanotube carbon atoms, not considered hitherto, was described by decomposing the intra-atomic interactions of both the nanotube pi- and the iodide 5p-electrons into an effective one-electron term plus the repulsion between electrons in the same orbital. These energies were derived from electronic structure computations with the additional interspecies electrostatic repulsions derived from the GULP program. Structural predictions are presented as a function of the number (n) of electrons transferred from each anion. For both KI and CsI, the structure predicted by that computation, which minimized the total energy, in contrast to the other calculations, agreed well with experiment reproducing both the significant dilation of a and the smaller contraction of b. The respective n values (n(t)) predicting the lowest energies are 0.278 and 0.285. These results are supported by comparing the experimental frequencies of Raman modes attributable to vibrations of nanotubes encapsulating KI with the corresponding frequencies for systems where independently known numbers of electrons were transferred to the nanotubes. In both the enc...