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.
Files changed (42) hide show
  1. diffpy/Structure.py +35 -0
  2. diffpy/__init__.py +23 -0
  3. diffpy/structure/__init__.py +93 -0
  4. diffpy/structure/_legacy_importer.py +88 -0
  5. diffpy/structure/apps/__init__.py +17 -0
  6. diffpy/structure/apps/anyeye.py +284 -0
  7. diffpy/structure/apps/transtru.py +126 -0
  8. diffpy/structure/atom.py +544 -0
  9. diffpy/structure/expansion/__init__.py +27 -0
  10. diffpy/structure/expansion/makeellipsoid.py +129 -0
  11. diffpy/structure/expansion/shapeutils.py +44 -0
  12. diffpy/structure/expansion/supercell_mod.py +91 -0
  13. diffpy/structure/lattice.py +663 -0
  14. diffpy/structure/mmlibspacegroups.py +8154 -0
  15. diffpy/structure/parsers/__init__.py +83 -0
  16. diffpy/structure/parsers/p_auto.py +217 -0
  17. diffpy/structure/parsers/p_cif.py +876 -0
  18. diffpy/structure/parsers/p_discus.py +312 -0
  19. diffpy/structure/parsers/p_pdb.py +405 -0
  20. diffpy/structure/parsers/p_pdffit.py +290 -0
  21. diffpy/structure/parsers/p_rawxyz.py +149 -0
  22. diffpy/structure/parsers/p_xcfg.py +457 -0
  23. diffpy/structure/parsers/p_xyz.py +161 -0
  24. diffpy/structure/parsers/parser_index_mod.py +108 -0
  25. diffpy/structure/parsers/structureparser.py +80 -0
  26. diffpy/structure/pdffitstructure.py +109 -0
  27. diffpy/structure/sgtbxspacegroups.py +5198 -0
  28. diffpy/structure/spacegroupmod.py +329 -0
  29. diffpy/structure/spacegroups.py +1441 -0
  30. diffpy/structure/structure.py +866 -0
  31. diffpy/structure/structureerrors.py +35 -0
  32. diffpy/structure/symmetryutilities.py +1100 -0
  33. diffpy/structure/utils.py +126 -0
  34. diffpy/structure/version.py +26 -0
  35. diffpy.structure-3.2.0.dist-info/AUTHORS.rst +13 -0
  36. diffpy.structure-3.2.0.dist-info/LICENSE.rst +141 -0
  37. diffpy.structure-3.2.0.dist-info/LICENSE_DANSE.rst +50 -0
  38. diffpy.structure-3.2.0.dist-info/LICENSE_pymmlib.rst +203 -0
  39. diffpy.structure-3.2.0.dist-info/METADATA +197 -0
  40. diffpy.structure-3.2.0.dist-info/RECORD +42 -0
  41. diffpy.structure-3.2.0.dist-info/WHEEL +5 -0
  42. diffpy.structure-3.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,83 @@
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
+ """Conversion plugins for various structure formats.
17
+
18
+ The recognized structure formats are defined by subclassing `StructureParser`,
19
+ by convention these classes are named `P_<format>.py`. The parser classes should
20
+ to override the `parseLines()` and `toLines()` methods of `StructureParser`.
21
+ Any structure parser needs to be registered in `parser_index` module.
22
+
23
+ For normal usage it should be sufficient to use the routines provided
24
+ in this module.
25
+
26
+ Content:
27
+ * StructureParser: base class for a concrete Parser
28
+ * parser_index: dictionary of known structure formats
29
+ * getParser: factory for Parser at given format
30
+ * inputFormats: list of available input formats
31
+ * outputFormats: list of available output formats
32
+ """
33
+
34
+ from diffpy.structure.parsers.parser_index_mod import parser_index
35
+ from diffpy.structure.parsers.structureparser import StructureParser
36
+ from diffpy.structure.structureerrors import StructureFormatError
37
+
38
+ # silence pyflakes checker
39
+ assert StructureParser
40
+
41
+
42
+ def getParser(format, **kw):
43
+ """Return Parser instance for a given structure format.
44
+
45
+ Parameters
46
+ ----------
47
+ format : str
48
+ String with the format name, see `parser_index_mod`.
49
+ **kw : dict
50
+ Keyword arguments passed to the Parser init function.
51
+
52
+ Returns
53
+ -------
54
+ Parser
55
+ Parser instance for the given format.
56
+
57
+ Raises
58
+ ------
59
+ StructureFormatError
60
+ When the format is not defined.
61
+ """
62
+ if format not in parser_index:
63
+ emsg = "no parser for '%s' format" % format
64
+ raise StructureFormatError(emsg)
65
+ pmod = parser_index[format]["module"]
66
+ ns = {}
67
+ import_cmd = "from diffpy.structure.parsers import %s as pm" % pmod
68
+ exec(import_cmd, ns)
69
+ return ns["pm"].getParser(**kw)
70
+
71
+
72
+ def inputFormats():
73
+ """Return list of implemented input structure formats."""
74
+ input_formats = [fmt for fmt, prop in parser_index.items() if prop["has_input"]]
75
+ input_formats.sort()
76
+ return input_formats
77
+
78
+
79
+ def outputFormats():
80
+ """Return list of implemented output structure formats."""
81
+ output_formats = [fmt for fmt, prop in parser_index.items() if prop["has_output"]]
82
+ output_formats.sort()
83
+ return output_formats
@@ -0,0 +1,217 @@
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 automatic file format detection.
17
+
18
+ This Parser does not provide the the `toLines()` method.
19
+ """
20
+
21
+ import os
22
+
23
+ from diffpy.structure.parsers import StructureParser, parser_index
24
+ from diffpy.structure.structureerrors import StructureFormatError
25
+
26
+
27
+ class P_auto(StructureParser):
28
+ """Parser with automatic detection of structure format.
29
+
30
+ This parser attempts to automatically detect the format of a given
31
+ structure file and parse it accordingly. When successful, it sets
32
+ its `format` attribute to the detected structure format.
33
+
34
+ Parameters
35
+ ----------
36
+ **kw : dict
37
+ Keyword arguments for the structure parser.
38
+
39
+ Attributes
40
+ ----------
41
+ format : str
42
+ Detected structure format. Initially set to "auto" and updated
43
+ after successful detection of the structure format.
44
+ pkw : dict
45
+ Keyword arguments passed to the parser.
46
+ """
47
+
48
+ def __init__(self, **kw):
49
+ StructureParser.__init__(self)
50
+ self.format = "auto"
51
+ self.pkw = kw
52
+ return
53
+
54
+ # parseLines helpers
55
+ def _getOrderedFormats(self):
56
+ """Build a list of relevance ordered structure formats.
57
+ This only works when `self.filename` has a known extension.
58
+ """
59
+ from diffpy.structure.parsers import inputFormats
60
+
61
+ ofmts = [fmt for fmt in inputFormats() if fmt != "auto"]
62
+ if not self.filename:
63
+ return ofmts
64
+ # filename is defined here
65
+ filebase = os.path.basename(self.filename)
66
+ from fnmatch import fnmatch
67
+
68
+ # loop over copy of ofmts
69
+ for fmt in list(ofmts):
70
+ pattern = parser_index[fmt]["file_pattern"]
71
+ if pattern in ("*.*", "*"):
72
+ continue
73
+ anymatch = [1 for p in pattern.split("|") if fnmatch(filebase, p)]
74
+ if anymatch:
75
+ ofmts.remove(fmt)
76
+ ofmts.insert(0, fmt)
77
+ return ofmts
78
+
79
+ def parseLines(self, lines):
80
+ """Detect format and create `Structure` instance from a list of lines.
81
+
82
+ Set format attribute to the detected file format.
83
+
84
+ Parameters
85
+ ----------
86
+ lines : list
87
+ List of lines with structure data.
88
+
89
+ Returns
90
+ -------
91
+ Structure
92
+ `Structure` object.
93
+
94
+ Raises
95
+ ------
96
+ StructureFormatError
97
+ """
98
+ return self._wrapParseMethod("parseLines", lines)
99
+
100
+ def parse(self, s):
101
+ """Detect format and create `Structure` instance from a string.
102
+
103
+ Set format attribute to the detected file format.
104
+
105
+ Parameters
106
+ ----------
107
+ s : str
108
+ String with structure data.
109
+
110
+ Returns
111
+ -------
112
+ Structure
113
+ `Structure` object.
114
+
115
+ Raises
116
+ ------
117
+ StructureFormatError
118
+ """
119
+ return self._wrapParseMethod("parse", s)
120
+
121
+ def parseFile(self, filename):
122
+ """Detect format and create Structure instance from an existing file.
123
+
124
+ Set format attribute to the detected file format.
125
+
126
+ Parameters
127
+ ----------
128
+ filename : str
129
+ Path to structure file.
130
+
131
+ Returns
132
+ -------
133
+ Structure
134
+ `Structure` object.
135
+
136
+ Raises
137
+ ------
138
+ StructureFormatError
139
+ If the structure format is unknown or invalid.
140
+ IOError
141
+ If the file cannot be read.
142
+ """
143
+ self.filename = filename
144
+ return self._wrapParseMethod("parseFile", filename)
145
+
146
+ def _wrapParseMethod(self, method, *args, **kwargs):
147
+ """A helper evaluator method that try the specified parse method with
148
+ each registered structure parser and return the first successful
149
+ resul.
150
+
151
+ Structure parsers that match structure file extension are
152
+ tried first.
153
+
154
+ Parameters
155
+ ----------
156
+ method : str
157
+ Name of the parse method to call.
158
+ *args : tuple
159
+ Positional arguments for the parse method.
160
+ **kwargs : dict
161
+ Keyword arguments for the parse method.
162
+
163
+ Returns
164
+ -------
165
+ Structure
166
+ `Structure` object.
167
+
168
+ Raises
169
+ ------
170
+ StructureFormatError
171
+ """
172
+ from diffpy.structure.parsers import getParser
173
+
174
+ ofmts = self._getOrderedFormats()
175
+ stru = None
176
+ # try all parsers in sequence
177
+ parsers_emsgs = []
178
+ for fmt in ofmts:
179
+ p = getParser(fmt, **self.pkw)
180
+ try:
181
+ pmethod = getattr(p, method)
182
+ stru = pmethod(*args, **kwargs)
183
+ self.format = fmt
184
+ break
185
+ except StructureFormatError as err:
186
+ parsers_emsgs.append("%s: %s" % (fmt, err))
187
+ except NotImplementedError:
188
+ pass
189
+ if stru is None:
190
+ emsg = "\n".join(
191
+ ["Unknown or invalid structure format.", "Errors per each tested structure format:"]
192
+ + parsers_emsgs
193
+ )
194
+ raise StructureFormatError(emsg)
195
+ self.__dict__.update(p.__dict__)
196
+ return stru
197
+
198
+
199
+ # End of class P_auto
200
+
201
+ # Routines -------------------------------------------------------------------
202
+
203
+
204
+ def getParser(**kw):
205
+ """Return a new instance of the automatic parser.
206
+
207
+ Parameters
208
+ ----------
209
+ **kw : dict
210
+ Keyword arguments for the structure parser
211
+
212
+ Returns
213
+ -------
214
+ P_auto
215
+ Instance of `P_auto`.
216
+ """
217
+ return P_auto(**kw)