7

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!

Inzo Babaria
  • 1,513
  • 7
  • 11

1 Answers1

8
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}]

![enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
  • Glorious!!! Wonderful!!! – Inzo Babaria Nov 01 '20 at 09:03
  • Is there any possibility to change the color of unit cells? Or it is by default and cannot be changed! – Inzo Babaria Nov 01 '20 at 09: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 01 '20 at 09:22