Skip to content

Commit

Permalink
ADD: Plot unit cell of Material
Browse files Browse the repository at this point in the history
Basic plot function for Material class, shows the unit cell as defined by the user.
  • Loading branch information
pseudocubic committed Mar 9, 2015
1 parent ed7729e commit 6fb2f3d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions neutronpy/form_facs.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,38 @@ def calc_str_fac(self, hkl):

return FQ

def plot_unit_cell(self):
r'''Plots the unit cell and atoms of the material.
'''

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from itertools import product, combinations

fig = plt.figure()
ax = fig.gca(projection='3d')

# draw unit cell
for s, e in combinations(np.array(list(product([0, self.abc[0]], [0, self.abc[1]], [0, self.abc[2]]))), 2):
if np.sum(np.abs(s - e)) in self.abc:
ax.plot3D(*zip(s, e), color="b")

# plot atoms
x, y, z, m = [], [], [], []
for item in self.atoms:
x.append(item.pos[0] * self.abc[0])
y.append(item.pos[1] * self.abc[1])
z.append(item.pos[2] * self.abc[2])
m.append(item.mass)

ax.scatter(x, y, z, s=m)

plt.axis('scaled')
plt.axis('off')

plt.show()


class Ion(object):
r'''Class defining a magnetic ion.
Expand Down

0 comments on commit 6fb2f3d

Please sign in to comment.