from __future__ import division,print_function import collections import itertools import numpy as np from numpy import sin,cos class Triclinic(object): def __init__(self,a=1,b=1,c=1,alpha=90,beta=90,gamma=90): self.a = a self.b = b self.c = c alpha = alpha*np.pi/180 beta = beta*np.pi/180 gamma = gamma*np.pi/180 self.alpha = alpha self.beta = beta self.gamma = gamma self._s11 = b**2 * c**2 * sin(alpha)**2 self._s22 = a**2 * c**2 * sin(beta)**2 self._s33 = a**2 * b**2 * sin(gamma)**2 self._s12 = a*b*c**2*(cos(alpha) * cos(beta) - cos(gamma)) self._s23 = a**2*b*c*(cos(beta) * cos(gamma) - cos(alpha)) self._s13 = a*b**2*c*(cos(gamma) * cos(alpha) - cos(beta)) self.V = (a*b*c)*np.sqrt(1-cos(alpha)**2 - cos(beta)**2 - cos(gamma)**2 + 2*cos(alpha)*cos(beta)*cos(gamma)) def __call__(self,h,k,l): return self.q(h,k,l) def d(self,h,k,l): temp = self._s11*h**2 + \ self._s22*k**2 + \ self._s33*l**2 + \ 2*self._s12*h*k+ \ 2*self._s23*k*l+ \ 2*self._s13*h*l d = self.V/np.sqrt(temp) return d 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