-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathshapeutils.py
More file actions
63 lines (52 loc) · 1.58 KB
/
shapeutils.py
File metadata and controls
63 lines (52 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
##############################################################################
#
# diffpy.structure by DANSE Diffraction group
# Simon J. L. Billinge
# (c) 2008 trustees of the Michigan State University.
# All rights reserved.
#
# File coded by: Chris Farrow
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE_DANSE.txt for license information.
#
##############################################################################
from diffpy.utils._deprecator import build_deprecation_message, deprecated
base = "diffpy.structure"
removal_version = "4.0.0"
findCenter_deprecation_msg = build_deprecation_message(
base,
"findCenter",
"find_center",
removal_version,
)
"""Utilities for making shapes."""
@deprecated(findCenter_deprecation_msg)
def findCenter(S):
"""This function has been deprecated and will be removed in version
4.0.0.
Please use diffpy.structure.find_center instead.
"""
return find_center(S)
def find_center(S):
"""Find the approximate center `Atom` of a `Structure`.
The center of the `Structure` is the `Atom` closest to ``(0.5, 0.5, 0.5)``.
Parameters
----------
S : Structure
A `Structure` instance.
Returns
-------
int
The index of the center `Atom`.
"""
best = -1
bestd = len(S)
center = [0.5, 0.5, 0.5] # the canonical center
for i in range(len(S)):
d = S.lattice.dist(S[i].xyz, center)
if d < bestd:
bestd = d
best = i
return best