# construct a lattice with a defined unitcell

We can construct a base-centered tetragonal unit cell by:

LatticeData["CenteredTetragonal", "Image"]


But how can we construct a lattice by 8 of this unit cell (put them together)? For example, 4 unit cells on the top and 4 unit cells on the bottom of the lattice.

Here there is a trick for simple cubic but it does not work for may lattice!

ClearAll[latticeGrid]
latticeGrid[{lattice_String, {x_, y_, z_}}, opts : OptionsPattern[]] :=
Module[{ld = LatticeData[lattice, "Image"], lengths,
tuples = Tuples[Range[0, # - 1] & /@ {x, y, z}]},
lengths = -Subtract @@@ CoordinateBounds @
DiscretizeGraphics[ld /. ( Sphere[__]:> {})];
Show[ld /. prim : (_Polygon | _Line | _Sphere) :>
Translate[prim, lengths # & /@ tuples], opts]]


Examples:

latticeGrid[{"CenteredTetragonal", {4, 1, 2}}, ViewPoint -> {1, -3, 1}]


latticeGrid[{"CenteredTetragonal", {2, 2, 3}}, ViewPoint -> {1, -3, 1}]


latticeGrid[{"FaceCenteredCubic", {3, 1, 3}}, ViewPoint -> {1, -3, 1}]


latticeGrid[{"TetrahedralPacking", {3, 1, 2}}, ViewPoint -> {1, -3, 1}]


• Glorious!!! Wonderful!!! – Inzo Babaria Nov 1 '20 at 9:03
• Is there any possibility to change the color of unit cells? Or it is by default and cannot be changed! – Inzo Babaria Nov 1 '20 at 9:07
• @InzoBabaria, you can post-process to inject the desired styles. For example, latticeGrid[{"FaceCenteredCubic", {3, 1, 1}}, ViewPoint -> {1, -3, 1}] /. {p_Polygon :> {FaceForm[Blue], EdgeForm[Cyan], p}, l__Line :> {Red, l}, s__Sphere :> {Green, s}}. – kglr Nov 1 '20 at 9:22