  We present an extension of density matrix based linear scaling electronic
structure theory to incorporate spin degrees of freedom. When the spin
multiplicity of the system can be predetermined, the generalization of the
existing linear scaling methods to spin unrestricted cases is straightforward.
However, without calculations it is hard to determine the spin multiplicity of
some complex systems, such as, many magnetic nanostuctures, some inorganic or
bioinorganic molecules. Here we give a general prescription to obtain the
spin-unrestricted ground state of open shell systems. Our methods are
implemented into the linear scaling trace-correcting density matrix
purification algorithm. The numerical atomic orbital basis, rather than the
commonly adopted Gaussian basis functions is used. The test systems include O2
molecule, and magnetic carbon doped BN(5,5) and BN(7,6) nanotubes. Using the
newly developed method, we find the magnetic moments in carbon doped BN
nanotubes couple antiferromagnetically with each other. Our results suggest
that the linear scaling spin-unrestricted trace-correcting purification method
is very powerful to treat large magnetic systems.
