1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """Utilities for making shapes."""
17
18 __id__ = "$Id: shapeUtils.py 2980 2009-04-02 00:14:33Z juhas $"
19
21 """Find the approximate center atom of a structure.
22
23 The center of the structure is the atom closest to (0.5, 0.5, 0.5)
24
25 Returns the index of the atom.
26 """
27 best = -1
28 bestd = len(S)
29 center = [0.5, 0.5, 0.5]
30
31 for i in range(len(S)):
32 d = S.lattice.dist(S[i].xyz, center)
33 if d < bestd:
34 bestd = d
35 best = i
36
37 return best
38
39 if __name__ == "__main__":
40
41 import os.path
42 datadir = "../../tests/testdata"
43 S = Structure()
44 S.read(os.path.join(datadir, "CdSe_bulk.stru"), "pdffit")
45 newS = makeEllipsoid(S, 20)
46 newS.write("CdSe_d20.stru", "pdffit")
47 newS = makeEllipsoid(S, 20, 10, 10)
48 newS.write("CdSe_a20_b10_c10.stru", "pdffit")
49 newS = makeEllipsoid(S, 20, 15, 10)
50 newS.write("CdSe_a20_b15_c10.stru", "pdffit")
51 S = Structure()
52 S.read(os.path.join(datadir, "Ni.stru"), "pdffit")
53 newS = makeEllipsoid(S, 20)
54 newS.write("Ni_d20.stru", "pdffit")
55 newS = makeEllipsoid(S, 20, 4)
56 newS.write("Ni_a20_b4_c20.stru", "pdffit")
57 newS = makeEllipsoid(S, 20, 15, 10)
58 newS.write("Ni_a20_b15_c10.stru", "pdffit")
59