1
2
3
4
5
6
7
8
9
10
11
12
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
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
35 frac = S.lattice.fractional((dist, dist, dist))
36 mno = map(ceil, 2*frac)
37
38 from diffpy.Structure.expansion import supercell
39 newS = supercell(S, mno)
40 lat = newS.lattice
41
42
43 ncenter = findCenter(newS)
44
45
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
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