Skip to content

Instantly share code, notes, and snippets.

@Mahdisadjadi
Last active September 19, 2017 01:58
Show Gist options
  • Select an option

  • Save Mahdisadjadi/30810f34b124d6cf8b30bc2218b2ce42 to your computer and use it in GitHub Desktop.

Select an option

Save Mahdisadjadi/30810f34b124d6cf8b30bc2218b2ce42 to your computer and use it in GitHub Desktop.
Image of a general periodic box with two atoms in the unit cell
import matplotlib.pyplot as plt
from itertools import product
import numpy as np
a,b = np.array([4,1]),np.array([1,3])
fig,ax = plt.subplots(1,1,figsize=(5,5))
ax.set_xlim(-6,8)
ax.set_ylim(-6,8)
ax.set_axis_off()
ax.axhline(0,color='k')
ax.axvline(0,color='k')
ax.arrow(0, 0, 4, 1, head_width=0.3, head_length=0.1, width=0.1, fc='r', ec='r',alpha=1,zorder=2)
ax.arrow(0, 0, 1, 3, head_width=0.3, head_length=0.1, width=0.1, fc='g', ec='g',alpha=1,zorder=2)
ax.plot([1, 5], [3, 4], '-b',lw=2)
ax.plot([4, 5], [1, 4], '-b',lw=2)
for f in range(-5,6):
x,y = f*b
al = 12
bl = al/4
ax.plot([-al+x,al+x],[-bl+y,bl+y],'--k',lw=1)
for f in range(-5,6):
x,y = f*a
al = 12
bl = 3*al
ax.plot([-al+x,al+x],[-bl+y,bl+y],'--k',lw=1)
p1 = np.array([0.7,1])
p2 = np.array([4.1,3])
for c,d in product(range(-2,3),repeat=2):
ax.scatter(*(p1+c*a+d*b),marker='o',color='k')
ax.scatter(*(p2+c*a+d*b),marker='x',color='k')
plt.tight_layout()
plt.savefig('pbc.pdf', dpi=100, transparent=True)
plt.show(fig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment