Generation of crystals starting from a single unit cell

This code generates first a single unit cell (of either diamond, GaAs, NaCl, or penicillin) then repeats this to form a line of unit cells (x-direction); this in turn is replicated to form a plane of unit cells (y-direction), which is then repeated vertically (z-direction) to form a crystalline cube. 

Matlab code