Package pyxsd :: Package transforms :: Module expandCell
[hide private]
[frames] | no frames]

Source Code for Module pyxsd.transforms.expandCell

 1  from cellSizer import CellSizer 
 2   
 3  """ 
 4  ===================== 
 5  Transform: ExpandCell 
 6  ===================== 
 7   
 8  :Author: Karl Norby <knorby@uchicago.edu> 
 9  :Date: Fri, 1 Sept 2006 
10  :Category: Computational Materials Science 
11  :Description: Expands a cell by given parameters 
12  :Copyright: pyXSD License 
13   
14  """ 
15   
16  #============================================================ 
17  # 
18 -class ExpandCell (CellSizer):
19 20 #============================================================ 21 #
22 - def __init__(self, root):
23 self.root = root 24 self.cellSizerInit()
25 26 #============================================================ 27 #
28 - def __call__(self, a1Expand, a2Expand, a3Expand):
29 return self.expand(a1Expand, a2Expand, a3Expand)
30 31 #============================================================ 32 #
33 - def expand(self, a1Expand, a2Expand, a3Expand):
34 atoms = self.getAtoms() 35 newAtoms = [] 36 37 vectors = self.getBravaisVectors() 38 39 a1 = vectors['a1'] 40 a2 = vectors['a2'] 41 a3 = vectors['a3'] 42 43 a1Length = a1.findLength() 44 a2Length = a2.findLength() 45 a3Length = a3.findLength() 46 47 newA1 = a1 * a1Expand 48 newA2 = a2 * a2Expand 49 newA3 = a3 * a3Expand 50 51 newA1Length = newA1.findLength() 52 newA2Length = newA2.findLength() 53 newA3Length = newA3.findLength() 54 55 newVectors = dict([('a1', newA1), ('a2', newA2), ('a3', newA3)]) 56 57 for x in range(0, a1Expand): 58 for y in range(0, a2Expand): 59 for z in range(0, a3Expand): 60 for atom in atoms: 61 position = atom.position 62 position = map(lambda x: float(x), position) 63 newPosition = [] 64 newPosition.append(((position[0] + x)*a1Length)/newA1Length) 65 newPosition.append(((position[1] + y)*a2Length)/newA2Length)#/newA2Length) 66 newPosition.append(((position[2] + z)*a3Length)/newA3Length)#/newA3Length) 67 newAtom = self.makeAtom(newPosition, atom.atomType) 68 newAtoms.append(newAtom) 69 70 newLattice = self.makeBravaisLattice(newVectors, newAtoms) 71 72 return self.makeNewXml(newLattice)
73