diffpy.structure 3.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffpy/Structure.py +35 -0
- diffpy/__init__.py +23 -0
- diffpy/structure/__init__.py +93 -0
- diffpy/structure/_legacy_importer.py +88 -0
- diffpy/structure/apps/__init__.py +17 -0
- diffpy/structure/apps/anyeye.py +284 -0
- diffpy/structure/apps/transtru.py +126 -0
- diffpy/structure/atom.py +544 -0
- diffpy/structure/expansion/__init__.py +27 -0
- diffpy/structure/expansion/makeellipsoid.py +129 -0
- diffpy/structure/expansion/shapeutils.py +44 -0
- diffpy/structure/expansion/supercell_mod.py +91 -0
- diffpy/structure/lattice.py +663 -0
- diffpy/structure/mmlibspacegroups.py +8154 -0
- diffpy/structure/parsers/__init__.py +83 -0
- diffpy/structure/parsers/p_auto.py +217 -0
- diffpy/structure/parsers/p_cif.py +876 -0
- diffpy/structure/parsers/p_discus.py +312 -0
- diffpy/structure/parsers/p_pdb.py +405 -0
- diffpy/structure/parsers/p_pdffit.py +290 -0
- diffpy/structure/parsers/p_rawxyz.py +149 -0
- diffpy/structure/parsers/p_xcfg.py +457 -0
- diffpy/structure/parsers/p_xyz.py +161 -0
- diffpy/structure/parsers/parser_index_mod.py +108 -0
- diffpy/structure/parsers/structureparser.py +80 -0
- diffpy/structure/pdffitstructure.py +109 -0
- diffpy/structure/sgtbxspacegroups.py +5198 -0
- diffpy/structure/spacegroupmod.py +329 -0
- diffpy/structure/spacegroups.py +1441 -0
- diffpy/structure/structure.py +866 -0
- diffpy/structure/structureerrors.py +35 -0
- diffpy/structure/symmetryutilities.py +1100 -0
- diffpy/structure/utils.py +126 -0
- diffpy/structure/version.py +26 -0
- diffpy.structure-3.2.0.dist-info/AUTHORS.rst +13 -0
- diffpy.structure-3.2.0.dist-info/LICENSE.rst +141 -0
- diffpy.structure-3.2.0.dist-info/LICENSE_DANSE.rst +50 -0
- diffpy.structure-3.2.0.dist-info/LICENSE_pymmlib.rst +203 -0
- diffpy.structure-3.2.0.dist-info/METADATA +197 -0
- diffpy.structure-3.2.0.dist-info/RECORD +42 -0
- diffpy.structure-3.2.0.dist-info/WHEEL +5 -0
- diffpy.structure-3.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.structure by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2007 trustees of the Michigan State University.
|
|
7
|
+
# All rights reserved.
|
|
8
|
+
#
|
|
9
|
+
# File coded by: Pavol Juhas
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE_DANSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
|
|
16
|
+
"""Parser for XYZ file format, where
|
|
17
|
+
|
|
18
|
+
* First line gives number of atoms.
|
|
19
|
+
* Second line has optional title.
|
|
20
|
+
* Remaining lines contain element, `x, y, z`.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import sys
|
|
24
|
+
|
|
25
|
+
from diffpy.structure import Structure
|
|
26
|
+
from diffpy.structure.parsers import StructureParser
|
|
27
|
+
from diffpy.structure.structureerrors import StructureFormatError
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class P_xyz(StructureParser):
|
|
31
|
+
"""Parser for standard XYZ structure format.
|
|
32
|
+
|
|
33
|
+
Attributes
|
|
34
|
+
----------
|
|
35
|
+
format : str
|
|
36
|
+
Format name, default "xyz".
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self):
|
|
40
|
+
StructureParser.__init__(self)
|
|
41
|
+
self.format = "xyz"
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
def parseLines(self, lines):
|
|
45
|
+
"""Parse list of lines in XYZ format.
|
|
46
|
+
|
|
47
|
+
Parameters
|
|
48
|
+
----------
|
|
49
|
+
lines : list of str
|
|
50
|
+
List of lines in XYZ format.
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
Structure
|
|
55
|
+
Parsed structure instance.
|
|
56
|
+
|
|
57
|
+
Raises
|
|
58
|
+
------
|
|
59
|
+
StructureFormatError
|
|
60
|
+
Invalid XYZ format.
|
|
61
|
+
"""
|
|
62
|
+
linefields = [line.split() for line in lines]
|
|
63
|
+
# prepare output structure
|
|
64
|
+
stru = Structure()
|
|
65
|
+
# find first valid record
|
|
66
|
+
start = 0
|
|
67
|
+
for field in linefields:
|
|
68
|
+
if len(field) == 0 or field[0] == "#":
|
|
69
|
+
start += 1
|
|
70
|
+
else:
|
|
71
|
+
break
|
|
72
|
+
# first valid line gives number of atoms
|
|
73
|
+
try:
|
|
74
|
+
lfs = linefields[start]
|
|
75
|
+
w1 = linefields[start][0]
|
|
76
|
+
if len(lfs) == 1 and str(int(w1)) == w1:
|
|
77
|
+
p_natoms = int(w1)
|
|
78
|
+
stru.title = lines[start + 1].strip()
|
|
79
|
+
start += 2
|
|
80
|
+
else:
|
|
81
|
+
emsg = "%d: invalid XYZ format, missing number of atoms" % (start + 1)
|
|
82
|
+
raise StructureFormatError(emsg)
|
|
83
|
+
except (IndexError, ValueError):
|
|
84
|
+
exc_type, exc_value, exc_traceback = sys.exc_info()
|
|
85
|
+
emsg = "%d: invalid XYZ format, missing number of atoms" % (start + 1)
|
|
86
|
+
e = StructureFormatError(emsg)
|
|
87
|
+
raise e.with_traceback(exc_traceback)
|
|
88
|
+
# find the last valid record
|
|
89
|
+
stop = len(lines)
|
|
90
|
+
while stop > start and len(linefields[stop - 1]) == 0:
|
|
91
|
+
stop -= 1
|
|
92
|
+
# get out for empty structure
|
|
93
|
+
if p_natoms == 0 or start >= stop:
|
|
94
|
+
return stru
|
|
95
|
+
# here we have at least one valid record line
|
|
96
|
+
nfields = len(linefields[start])
|
|
97
|
+
if nfields != 4:
|
|
98
|
+
emsg = "%d: invalid XYZ format, expected 4 columns" % (start + 1)
|
|
99
|
+
raise StructureFormatError(emsg)
|
|
100
|
+
# now try to read all record lines
|
|
101
|
+
try:
|
|
102
|
+
p_nl = start
|
|
103
|
+
for fields in linefields[start:]:
|
|
104
|
+
p_nl += 1
|
|
105
|
+
if fields == []:
|
|
106
|
+
continue
|
|
107
|
+
elif len(fields) != nfields:
|
|
108
|
+
emsg = ("%d: all lines must have " + "the same number of columns") % p_nl
|
|
109
|
+
raise StructureFormatError(emsg)
|
|
110
|
+
element = fields[0]
|
|
111
|
+
element = element[0].upper() + element[1:].lower()
|
|
112
|
+
xyz = [float(f) for f in fields[1:4]]
|
|
113
|
+
stru.addNewAtom(element, xyz=xyz)
|
|
114
|
+
except ValueError:
|
|
115
|
+
exc_type, exc_value, exc_traceback = sys.exc_info()
|
|
116
|
+
emsg = "%d: invalid number format" % p_nl
|
|
117
|
+
e = StructureFormatError(emsg)
|
|
118
|
+
raise e.with_traceback(exc_traceback)
|
|
119
|
+
# finally check if all the atoms have been read
|
|
120
|
+
if p_natoms is not None and len(stru) != p_natoms:
|
|
121
|
+
emsg = "expected %d atoms, read %d" % (p_natoms, len(stru))
|
|
122
|
+
raise StructureFormatError(emsg)
|
|
123
|
+
return stru
|
|
124
|
+
|
|
125
|
+
def toLines(self, stru):
|
|
126
|
+
"""Convert Structure stru to a list of lines in XYZ format.
|
|
127
|
+
|
|
128
|
+
Parameters
|
|
129
|
+
----------
|
|
130
|
+
stru : Structure
|
|
131
|
+
Structure to be converted.
|
|
132
|
+
|
|
133
|
+
Returns
|
|
134
|
+
-------
|
|
135
|
+
list of str
|
|
136
|
+
List of lines in XYZ format.
|
|
137
|
+
"""
|
|
138
|
+
lines = []
|
|
139
|
+
lines.append(str(len(stru)))
|
|
140
|
+
lines.append(stru.title)
|
|
141
|
+
for a in stru:
|
|
142
|
+
rc = a.xyz_cartn
|
|
143
|
+
s = "%-3s %g %g %g" % (a.element, rc[0], rc[1], rc[2])
|
|
144
|
+
lines.append(s)
|
|
145
|
+
return lines
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
# End of class P_xyz
|
|
149
|
+
|
|
150
|
+
# Routines -------------------------------------------------------------------
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def getParser():
|
|
154
|
+
"""Return new `parser` object for XYZ format.
|
|
155
|
+
|
|
156
|
+
Returns
|
|
157
|
+
-------
|
|
158
|
+
P_xcfg
|
|
159
|
+
Instance of `P_xyz`.
|
|
160
|
+
"""
|
|
161
|
+
return P_xyz()
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.structure by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2007 trustees of the Michigan State University.
|
|
7
|
+
# All rights reserved.
|
|
8
|
+
#
|
|
9
|
+
# File coded by: Pavol Juhas
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE_DANSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
|
|
16
|
+
"""Index of recognized structure formats, their IO capabilities and
|
|
17
|
+
associated modules where they are defined.
|
|
18
|
+
|
|
19
|
+
Attributes
|
|
20
|
+
----------
|
|
21
|
+
parser_index : dict
|
|
22
|
+
Dictionary of recognized structure formats. The keys are format names
|
|
23
|
+
and the values are dictionaries with the following keys:
|
|
24
|
+
|
|
25
|
+
module : str
|
|
26
|
+
Name of the module that defines the parser class.
|
|
27
|
+
file_extension : str
|
|
28
|
+
File extension for the format, including the leading dot.
|
|
29
|
+
file_pattern : str
|
|
30
|
+
File pattern for the format, using '|' as separator for multiple
|
|
31
|
+
patterns.
|
|
32
|
+
has_input : bool
|
|
33
|
+
``True`` if the parser can read the format.
|
|
34
|
+
has_output : bool
|
|
35
|
+
``True`` if the parser can write the format.
|
|
36
|
+
|
|
37
|
+
Note
|
|
38
|
+
----
|
|
39
|
+
Plugins for new structure formats need to be added to the parser_index
|
|
40
|
+
dictionary in this module.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
parser_index = {
|
|
44
|
+
# automatic format detection - tries all parsers one by one
|
|
45
|
+
"auto": {
|
|
46
|
+
"module": "p_auto",
|
|
47
|
+
"file_extension": "",
|
|
48
|
+
"file_pattern": "*.*",
|
|
49
|
+
"has_input": True,
|
|
50
|
+
"has_output": False,
|
|
51
|
+
},
|
|
52
|
+
# CIF format
|
|
53
|
+
"cif": {
|
|
54
|
+
"module": "p_cif",
|
|
55
|
+
"file_extension": ".cif",
|
|
56
|
+
"file_pattern": "*.cif",
|
|
57
|
+
"has_input": True,
|
|
58
|
+
"has_output": True,
|
|
59
|
+
},
|
|
60
|
+
# PDB format
|
|
61
|
+
"pdb": {
|
|
62
|
+
"module": "p_pdb",
|
|
63
|
+
"file_extension": ".pdb",
|
|
64
|
+
"file_pattern": "*.pdb",
|
|
65
|
+
"has_input": True,
|
|
66
|
+
"has_output": True,
|
|
67
|
+
},
|
|
68
|
+
# Discus structure format
|
|
69
|
+
"discus": {
|
|
70
|
+
"module": "p_discus",
|
|
71
|
+
"file_extension": ".stru",
|
|
72
|
+
"file_pattern": "*.stru|*.rstr",
|
|
73
|
+
"has_input": True,
|
|
74
|
+
"has_output": True,
|
|
75
|
+
},
|
|
76
|
+
# PDFfit structure format
|
|
77
|
+
"pdffit": {
|
|
78
|
+
"module": "p_pdffit",
|
|
79
|
+
"file_extension": ".stru",
|
|
80
|
+
"file_pattern": "*.stru|*.rstr",
|
|
81
|
+
"has_input": True,
|
|
82
|
+
"has_output": True,
|
|
83
|
+
},
|
|
84
|
+
# standard xyz file
|
|
85
|
+
"xyz": {
|
|
86
|
+
"module": "p_xyz",
|
|
87
|
+
"file_extension": ".xyz",
|
|
88
|
+
"file_pattern": "*.xyz",
|
|
89
|
+
"has_input": True,
|
|
90
|
+
"has_output": True,
|
|
91
|
+
},
|
|
92
|
+
# raw xyz file (element labels optional)
|
|
93
|
+
"rawxyz": {
|
|
94
|
+
"module": "p_rawxyz",
|
|
95
|
+
"file_extension": ".xyz",
|
|
96
|
+
"file_pattern": "*.xyz",
|
|
97
|
+
"has_input": True,
|
|
98
|
+
"has_output": True,
|
|
99
|
+
},
|
|
100
|
+
# AtomEye extended configuration format
|
|
101
|
+
"xcfg": {
|
|
102
|
+
"module": "p_xcfg",
|
|
103
|
+
"file_extension": "",
|
|
104
|
+
"file_pattern": "*.xcfg|*.eye|*.cfg",
|
|
105
|
+
"has_input": True,
|
|
106
|
+
"has_output": True,
|
|
107
|
+
},
|
|
108
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.structure 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: Pavol Juhas
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE_DANSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
|
|
16
|
+
"""Definition of StructureParser, a base class for specific parsers.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class StructureParser(object):
|
|
21
|
+
"""Base class for all structure parsers.
|
|
22
|
+
|
|
23
|
+
Attributes
|
|
24
|
+
----------
|
|
25
|
+
format : str
|
|
26
|
+
Format name of particular parser.
|
|
27
|
+
filename : str
|
|
28
|
+
Path to structure file that is read or written.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self):
|
|
32
|
+
self.format = None
|
|
33
|
+
self.filename = None
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
def parseLines(self, lines):
|
|
37
|
+
"""Create Structure instance from a list of lines.
|
|
38
|
+
|
|
39
|
+
Return Structure object or raise StructureFormatError exception.
|
|
40
|
+
|
|
41
|
+
Note
|
|
42
|
+
----
|
|
43
|
+
This method has to be overloaded in derived class.
|
|
44
|
+
"""
|
|
45
|
+
raise NotImplementedError("parseLines not defined for '%s' format" % self.format)
|
|
46
|
+
return
|
|
47
|
+
|
|
48
|
+
def toLines(self, stru):
|
|
49
|
+
"""Convert Structure stru to a list of lines.
|
|
50
|
+
|
|
51
|
+
Return list of strings.
|
|
52
|
+
|
|
53
|
+
Note
|
|
54
|
+
----
|
|
55
|
+
This method has to be overloaded in derived class.
|
|
56
|
+
"""
|
|
57
|
+
raise NotImplementedError("toLines not defined for '%s' format" % self.format)
|
|
58
|
+
|
|
59
|
+
def parse(self, s):
|
|
60
|
+
"""Create `Structure` instance from a string."""
|
|
61
|
+
lines = s.rstrip("\r\n").split("\n")
|
|
62
|
+
stru = self.parseLines(lines)
|
|
63
|
+
return stru
|
|
64
|
+
|
|
65
|
+
def tostring(self, stru):
|
|
66
|
+
"""Convert `Structure` instance to a string."""
|
|
67
|
+
lines = self.toLines(stru)
|
|
68
|
+
s = "\n".join(lines) + "\n"
|
|
69
|
+
return s
|
|
70
|
+
|
|
71
|
+
def parseFile(self, filename):
|
|
72
|
+
"""Create Structure instance from an existing file."""
|
|
73
|
+
self.filename = filename
|
|
74
|
+
with open(filename) as fp:
|
|
75
|
+
s = fp.read()
|
|
76
|
+
stru = self.parse(s)
|
|
77
|
+
return stru
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# End of class StructureParser
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.structure by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2006 trustees of the Michigan State University.
|
|
7
|
+
# All rights reserved.
|
|
8
|
+
#
|
|
9
|
+
# File coded by: Pavol Juhas
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE_DANSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
|
|
16
|
+
"""Definition of PDFFitStructure class derived from Structure
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
from diffpy.structure.structure import Structure
|
|
21
|
+
|
|
22
|
+
# ----------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class PDFFitStructure(Structure):
|
|
26
|
+
"""PDFFitStructure --> Structure with extra pdffit member.
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
----------
|
|
30
|
+
*args, **kwargs :
|
|
31
|
+
See `Structure` class constructor.
|
|
32
|
+
|
|
33
|
+
Attributes
|
|
34
|
+
----------
|
|
35
|
+
pdffit : dict
|
|
36
|
+
Dictionary for storing following extra parameters from
|
|
37
|
+
PDFFit structure files:
|
|
38
|
+
`'scale', 'delta1', 'delta2', 'sratio',
|
|
39
|
+
'rcut', 'spcgr', 'dcell', 'ncell'`
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, *args, **kwargs):
|
|
43
|
+
self.pdffit = {
|
|
44
|
+
"scale": 1.0,
|
|
45
|
+
"delta1": 0.0,
|
|
46
|
+
"delta2": 0.0,
|
|
47
|
+
"sratio": 1.0,
|
|
48
|
+
"rcut": 0.0,
|
|
49
|
+
"spcgr": "P1",
|
|
50
|
+
"spdiameter": 0.0,
|
|
51
|
+
"stepcut": 0.0,
|
|
52
|
+
"dcell": 6 * [0.0],
|
|
53
|
+
"ncell": [1, 1, 1, 0],
|
|
54
|
+
}
|
|
55
|
+
Structure.__init__(self, *args, **kwargs)
|
|
56
|
+
return
|
|
57
|
+
|
|
58
|
+
def read(self, filename, format="auto"):
|
|
59
|
+
"""Same as `Structure.read`, but update `spcgr` value in
|
|
60
|
+
`self.pdffit` when parser can get spacegroup.
|
|
61
|
+
|
|
62
|
+
See `Structure.read()` for more info.
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
filename : str
|
|
67
|
+
File to be loaded.
|
|
68
|
+
format : str, Optional
|
|
69
|
+
All structure formats are defined in parsers submodule,
|
|
70
|
+
when ``format == 'auto'`` all parsers are tried one by one.
|
|
71
|
+
|
|
72
|
+
Return
|
|
73
|
+
------
|
|
74
|
+
StructureParser
|
|
75
|
+
Instance of StructureParser used to load the data.
|
|
76
|
+
"""
|
|
77
|
+
p = Structure.read(self, filename, format)
|
|
78
|
+
sg = getattr(p, "spacegroup", None)
|
|
79
|
+
if sg:
|
|
80
|
+
self.pdffit["spcgr"] = sg.short_name
|
|
81
|
+
return p
|
|
82
|
+
|
|
83
|
+
def readStr(self, s, format="auto"):
|
|
84
|
+
"""Same as `Structure.readStr`, but update `spcgr` value in
|
|
85
|
+
`self.pdffit` when parser can get spacegroup.
|
|
86
|
+
|
|
87
|
+
See `Structure.readStr()` for more info.
|
|
88
|
+
|
|
89
|
+
Parameters
|
|
90
|
+
----------
|
|
91
|
+
s : str
|
|
92
|
+
String with structure definition.
|
|
93
|
+
format : str, Optional
|
|
94
|
+
All structure formats are defined in parsers submodule. When ``format == 'auto'``,
|
|
95
|
+
all parsers are tried one by one.
|
|
96
|
+
|
|
97
|
+
Return
|
|
98
|
+
------
|
|
99
|
+
StructureParser
|
|
100
|
+
Instance of `StructureParser` used to load the data.
|
|
101
|
+
"""
|
|
102
|
+
p = Structure.readStr(self, s, format)
|
|
103
|
+
sg = getattr(p, "spacegroup", None)
|
|
104
|
+
if sg:
|
|
105
|
+
self.pdffit["spcgr"] = sg.short_name
|
|
106
|
+
return p
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# End of class PDFFitStructure
|