# Computationally Visualizing Crystals

**Prerequisites:** none

In condensed matter, we find ourselves in the interesting middle ground of dealing with large numbers, e.g. , of extremely small particles such as atoms, or electrons.

Luckily, the particles don’t each do their own thing, but often come in nice, structured, repeated units. *Lattices*. As our first step into the field, we will look at the most basic type, a *Bravais lattice*.

In a Bravais lattice, every site looks like every other site. Mathematically, we use three vectors, $\vec{a},\vec{b},\vec{c}$ to express how we move from one site to a neighbor.

\begin{equation} \mathbf{R}_{lmn}=l \vec{a} + m \vec{b} + n \vec{c} \;\;\;\; \text{for } l,m,n \in \mathbb{N} \end{equation}

For consistency, we have to put a constraint on these vectors; we cannot combine two of the vectors and obtain the third. If we could, then we couldn’t have sites in an entire three dimensional space.

Stay tuned for a later post where we explore more elaborate lattices.

## Define The Relevant Variables

Choose the lattice you want to look at, and use that string for the lattice variable. Current options:

- Simple Cubic = “sc”
- Plane triangular lattice = “pt”
- Body-Centered Cubic = “bcc”
- Face-Centered Cubic = “fcc”

Note: Square is Simple Cubic for Nz=1

14 distinct lattice types are possible, but these common four give the important ideas.

Also, input the size of lattice you want to look at.

```
# Another cell to just evaluate
# Here we are actually calculating the positions for every site
for i in 1:Nx #for the first row
X[i,:]=(i-1)*a;
end
for j in 2:Ny #copying the first row into the first layer
X[Nx*(j-1).+(1:Nx),:]=X[1:Nx,:].+(j-1)*bM;
end
for j in 2:Nz #copying the first layer into the entire cube
X[Ny*Nx*(j-1).+(1:Nx*Ny),:]=X[1:Nx*Ny,:].+(j-1)*cM;
end
```

### Programming Tip:

In Julia, ranges, like `1:Nx`

, are a special variable type that can be manipulated. We can add numbers to them:
`3+(1:3)=4:6`

,
or add a minus sign to force it to iterate in the opposite direction, though with different start/stop:
`-(1:3)=-1:-1:-3`

Danger! Make sure to use the parentheses around the range if you are performing these operations.

## Go Back and Fiddle!

As you might have noticed, this isn’t just a blog where you read through the posts. Interact with it. Change some lines, and see what happens. I choose body centered cubic to display first, but what do the other lattices look like?

Chose `pygui(true)`

to pop open a window and manipulate the plot in 3D.

Look at different lattice sizes.

Can you hand draw them on paper?

Let me know what you think, and enjoy the sequel as well!

*Multi-site unit cells*