Package diffpy :: Package Structure :: Package expansion :: Module makeCuboctahedron
[hide private]
[frames] | no frames]

Source Code for Module diffpy.Structure.expansion.makeCuboctahedron

 1  #!/usr/bin/env python 
 2  ############################################################################## 
 3  # 
 4  # PDFgui            by DANSE Diffraction group 
 5  #                   Simon J. L. Billinge 
 6  #                   (c) 2008 trustees of the Michigan State University. 
 7  #                   All rights reserved. 
 8  # 
 9  # File coded by:    Chris Farrow 
10  # 
11  # See AUTHORS.txt for a list of people who contributed. 
12  # See LICENSE.txt for license information. 
13  # 
14  ############################################################################## 
15   
16  """Make a spheroid nanoparticle from a template structure.""" 
17   
18  __id__ = "$Id: makeCuboctahedron.py 3032 2009-04-08 19:15:37Z juhas $" 
19   
20  from math import ceil 
21  from diffpy.Structure import Structure, Atom 
22  from diffpy.Structure.expansion.shapeUtils import findCenter 
23   
24 -def makeCuboctahedron(S, dist):
25 """Make a cuboctahedron nanoparticle. 26 27 Arguments 28 S -- A Structure instance 29 dist -- Distance from center to nearest face 30 31 Returns a new structure instance 32 """ 33 34 # Create a supercell large enough for the ellipsoid 35 frac = S.lattice.fractional((dist, dist, dist)) 36 mno = map(ceil, 2*frac) 37 # Make the supercell 38 from diffpy.Structure.expansion import supercell 39 newS = supercell(S, mno) 40 lat = newS.lattice 41 42 # Find the central atom 43 ncenter = findCenter(newS) 44 45 # Make the cuboctahedron template 46 from geometry.composites import cuboctahedron 47 from geometry.operations import translate, rotate 48 c0 = translate(cuboctahedron(dist), lat.cartesian(newS[ncenter].xyz)) 49 50 # Cut out an octahedron 51 from geometry import locate 52 53 N = len(newS) 54 j = N 55 for i in xrange(N): 56 57 xyz = lat.cartesian(newS[N-1-i].xyz) 58 if locate(xyz, c0) == 1: 59 newS.pop(N-1-i) 60 61 return newS
62 63 if __name__ == "__main__": 64 65 import os.path 66 datadir = "../../tests/testdata" 67 S = Structure() 68 S.read(os.path.join(datadir, "CdSe_bulk.stru"), "pdffit") 69 newS = makeCuboctahedron(S, 12) 70 newS.write("CdSe_cuboct24.stru", "pdffit") 71 S = Structure() 72 S.read(os.path.join(datadir, "Ni.stru"), "pdffit") 73 newS = makeCuboctahedron(S, 10) 74 newS.write("Ni_cuboct20.stru", "pdffit") 75