clean up and improved cell submodule, has also an helper for printing reflections on figure
This commit is contained in:
parent
07a9311f16
commit
5a10ad1a78
64
xray/cell.py
64
xray/cell.py
|
@ -1,4 +1,6 @@
|
|||
from __future__ import division,print_function
|
||||
import collections
|
||||
import itertools
|
||||
import numpy as np
|
||||
from numpy import sin,cos
|
||||
|
||||
|
@ -34,35 +36,63 @@ class Triclinic(object):
|
|||
d = self.V/np.sqrt(temp)
|
||||
return d
|
||||
|
||||
def q(self,h,k,l):
|
||||
def Q(self,h,k,l):
|
||||
return 2*np.pi/self.d(h,k,l)
|
||||
|
||||
def reflection_list(self,maxQ=3,lim=10):
|
||||
ret=dict()
|
||||
# prepare hkl
|
||||
i = range(-lim,lim+1)
|
||||
prod = itertools.product( i,i,i )
|
||||
hkl = np.asarray( list( itertools.product( i,i,i ) ) )
|
||||
h,k,l = hkl.T
|
||||
q = self.Q(h,k,l)
|
||||
|
||||
idx = q<maxQ;
|
||||
q = q[idx]
|
||||
hkl = hkl[idx]
|
||||
|
||||
qunique = np.unique(q)
|
||||
ret = []
|
||||
for qi in qunique:
|
||||
reflec = hkl[ q == qi ]
|
||||
ret.append( (qi,tuple(np.abs(reflec)[0]),len(reflec),reflec) )
|
||||
return qunique,ret
|
||||
|
||||
# for h in range(-lim,lim+1):
|
||||
# for j in range(-lim,lim+1):
|
||||
|
||||
|
||||
class Orthorombic(Triclinic):
|
||||
def __init__(self,a=1,b=1,c=1):
|
||||
Triclinic.__init__(self,a=a,b=b,c=c,alpha=90,beta=90,gamma=90)
|
||||
|
||||
class Monoclinic(object):
|
||||
def __init__(self,a=1,b=1,c=1,beta=90.):
|
||||
self.a = a
|
||||
self.b = b
|
||||
self.c = c
|
||||
beta = beta/np.pi*180
|
||||
self.beta = beta
|
||||
|
||||
self.V = (a*b*c)
|
||||
|
||||
def __call__(self,h,k,l): return self.Q(h,k,l)
|
||||
|
||||
def Q(self,h,k,l):
|
||||
temp = h**2/self.a**2 + (k*sin(self.beta))**2/self.b**2+l**2/self.c**2+2*h*l*cos(self.beta)/self.a/self.c
|
||||
d = 1/np.sqrt(temp)
|
||||
print(d)
|
||||
return 2*np.pi/d
|
||||
Triclinic.__init__(self,a=a,b=b,c=c,alpha=90,beta=beta,gamma=90)
|
||||
|
||||
|
||||
def plotReflections(cell_instance,ax=None,line_kw=dict(),text_kw=dict()):
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import lines
|
||||
import matplotlib.transforms as transforms
|
||||
_,refl_info = cell_instance.reflection_list()
|
||||
if ax is None: ax = plt.gca()
|
||||
|
||||
# the x coords of this transformation are data, and the
|
||||
# y coord are axes
|
||||
trans = transforms.blended_transform_factory(ax.transData, ax.transAxes)
|
||||
txt_kw = dict( horizontalalignment='center', rotation=45)
|
||||
txt_kw.update(**text_kw)
|
||||
for reflection in refl_info[1:]:
|
||||
q,hkl,n,_ = reflection
|
||||
line = lines.Line2D( [q,q],[1,1.1],transform=trans,**line_kw)
|
||||
line.set_clip_on(False)
|
||||
ax.add_line(line)
|
||||
ax.text(q,1.15,str(hkl),transform=trans,**txt_kw)
|
||||
|
||||
ti3o5_lambda = Triclinic(a = 9.83776, b = 3.78674, c = 9.97069, beta = 91.2567)
|
||||
ti3o5_beta = Triclinic(a = 9.7382 , b = 3.8005 , c = 9.4333 , beta = 91.496)
|
||||
#ti3o5_beta = Monoclinic(a = 9.7382 , b = 3.8005 , c = 9.4333 , beta = 91.496)
|
||||
ti3o5_alpha = Triclinic(a = 9.8372, b = 3.7921, c = 9.9717)
|
||||
#ti3o5_alpha1 = Orthorombic(a = 9.8372, b = 3.7921, c = 9.9717)
|
||||
ti3o5_alpha1 = Orthorombic(a = 9.8372, b = 3.7921, c = 9.9717)
|
||||
|
|
Loading…
Reference in New Issue