Results of ab initio pseudopotential calculations are presented concerning the atomic structure and magnetic properties of GaN doped with selected rare earth atoms. Effects of codoping these materials with Si are also discussed. It has been found that the doping of a Eu atom on a Ga site in bulk GaN creates significant local deformation and it costs 1.84eV. However, the addition of a Si atom makes Eu doping in bulk GaN energetically favorable as strain from an oversized Eu atom and an undersized Si atom is compensated. Therefore codoping of Si facilitates doping of rare earths in GaN. The excess charge due to codoping of Si tends to cause Eu to be in a 2+ state and the magnetic moment on Eu ion is enhanced to 7μB. Further studies have shown that Eu atoms tend to cluster with interatomic separation of about 5Å and there is ferromagnetic coupling. For rare earth atoms in nanoparticles, ab initio calculations have been performed on (GaN)n (n=12, 16, 22, and 32) nanoclusters with Eu, Gd, and Nd atoms substituting on Ga sites. These studies have yielded preferred atomic structures and magnetic behavior. Cage structures of these GaN nanoclusters were found to be lower in energy as compared to bulk fragments. Specific results show that Eu-doping in GaN nanoparticles is favorable compared with bulk GaN since a large fraction of atoms in a nanocluster lie on the surface where strain can be lower. Codoping of Si further facilitates Eu doping as in the case of bulk GaN. © 2016 Elsevier Ltd. All rights reserved.