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
diffpy/Structure.py ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env python
2
+ ##############################################################################
3
+ #
4
+ # diffpy.structure Complex Modeling Initiative
5
+ # (c) 2017 Brookhaven Science Associates,
6
+ # Brookhaven National Laboratory.
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.txt for license information.
13
+ #
14
+ ##############################################################################
15
+
16
+ """Support import of old camel-case module names with `DeprecationWarning`.
17
+
18
+ The imported camel-case modules are aliases for the current module
19
+ instances. Their `__name__` attributes are thus all in lower-case.
20
+
21
+ Warning
22
+ -------
23
+ This module is deprecated and will be removed in the future.
24
+ """
25
+
26
+
27
+ import sys
28
+
29
+ # install legacy import hooks
30
+ import diffpy.structure._legacy_importer
31
+
32
+ # replace this module with the new one
33
+ sys.modules["diffpy.Structure"] = diffpy.structure
34
+
35
+ # End of file
diffpy/__init__.py ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env python
2
+ ##############################################################################
3
+ #
4
+ # (c) 2024 The Trustees of Columbia University in the City of New York.
5
+ # All rights reserved.
6
+ #
7
+ # File coded by: Billinge Group members and community contributors.
8
+ #
9
+ # See GitHub contributions for a more detailed list of contributors.
10
+ # https://github.com/diffpy/diffpy.structure/graphs/contributors
11
+ #
12
+ # See LICENSE.rst for license information.
13
+ #
14
+ ##############################################################################
15
+
16
+ """Blank namespace package for module diffpy."""
17
+
18
+
19
+ from pkgutil import extend_path
20
+
21
+ __path__ = extend_path(__path__, __name__)
22
+
23
+ # End of file
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env python
2
+ ##############################################################################
3
+ #
4
+ # (c) 2024 The Trustees of Columbia University in the City of New York.
5
+ # All rights reserved.
6
+ #
7
+ # File coded by: Billinge Group members and community contributors.
8
+ #
9
+ # See GitHub contributions for a more detailed list of contributors.
10
+ # https://github.com/diffpy/diffpy.structure/graphs/contributors
11
+ #
12
+ # See LICENSE.rst for license information.
13
+ #
14
+ ##############################################################################
15
+
16
+ """
17
+ Crystal structure container and parsers for structure formats.
18
+
19
+ Classes related to the structure of materials:
20
+ * Atom
21
+ * Lattice
22
+ * Structure
23
+ * PDFFitStructure
24
+
25
+ Other classes:
26
+ * SpaceGroup
27
+ * SymOp
28
+ * ExpandAsymmetricUnit
29
+ * GeneratorSite
30
+ * SymmetryConstraints
31
+
32
+ Exceptions:
33
+ * StructureFormatError
34
+ * LatticeError
35
+ * SymmetryError
36
+ """
37
+
38
+ # Interface definitions ------------------------------------------------------
39
+
40
+ from diffpy.structure.atom import Atom
41
+ from diffpy.structure.lattice import Lattice
42
+ from diffpy.structure.parsers import getParser
43
+ from diffpy.structure.pdffitstructure import PDFFitStructure
44
+ from diffpy.structure.structure import Structure
45
+ from diffpy.structure.structureerrors import LatticeError, StructureFormatError, SymmetryError
46
+
47
+ # package version
48
+ from diffpy.structure.version import __version__
49
+
50
+ # top level routines
51
+
52
+
53
+ def loadStructure(filename, fmt="auto", **kw):
54
+ """Load new structure object from the specified file.
55
+
56
+ Parameters
57
+ ----------
58
+
59
+ filename : str
60
+ Path to the file to be loaded.
61
+ fmt : str, Optional
62
+ Format of the structure file such as 'cif' or 'xyz'. Must be
63
+ one of the formats listed by the `parsers.inputFormats` function.
64
+ When 'auto', all supported formats are tried in a sequence.
65
+ kw : Optional
66
+ Extra keyword arguments that are passed to `parsers.getParser`
67
+ function. These configure the dedicated Parser object that
68
+ is used to read content in filename.
69
+
70
+ Returns
71
+ -------
72
+ stru : `Structure`, `PDFFitStructure`
73
+ The new Structure object loaded from the specified file.
74
+ Return a more specific PDFFitStructure type for 'pdffit'
75
+ and 'discus' formats.
76
+ """
77
+
78
+ p = getParser(fmt, **kw)
79
+ rv = p.parseFile(filename)
80
+ return rv
81
+
82
+
83
+ # silence pyflakes checker
84
+ assert StructureFormatError and LatticeError and SymmetryError
85
+ assert Atom
86
+ assert Lattice
87
+ assert Structure
88
+ assert PDFFitStructure
89
+
90
+ # silence the pyflakes syntax checker
91
+ assert __version__ or True
92
+
93
+ # End of file
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env python
2
+ ##############################################################################
3
+ #
4
+ # diffpy.structure Complex Modeling Initiative
5
+ # (c) 2017 Brookhaven Science Associates,
6
+ # Brookhaven National Laboratory.
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.txt for license information.
13
+ #
14
+ ##############################################################################
15
+
16
+ """
17
+ Support import of old camel-case module names with DeprecationWarning.
18
+
19
+ The imported camel-case modules are aliases for the current module
20
+ instances. Their `__name__` attributes are thus all in lower-case.
21
+
22
+ Note
23
+ ----
24
+ this module must be only imported from `diffpy.Structure`.
25
+
26
+ Warning
27
+ -------
28
+ This module is deprecated and will be removed in the future.
29
+ """
30
+
31
+
32
+ import importlib.abc
33
+ import sys
34
+ from warnings import warn
35
+
36
+ WMSG = "Module {!r} is deprecated. Use {!r} instead."
37
+
38
+ # ----------------------------------------------------------------------------
39
+
40
+
41
+ class FindRenamedStructureModule(importlib.abc.MetaPathFinder):
42
+
43
+ prefix = "diffpy.Structure."
44
+
45
+ def find_spec(self, fullname, path=None, target=None):
46
+ # only handle submodules of diffpy.Structure
47
+ if not fullname.startswith(self.prefix):
48
+ return None
49
+ lcname = fullname.lower()
50
+ spec = importlib.util.find_spec(lcname)
51
+ if spec is not None:
52
+ spec.name = fullname
53
+ spec.loader = MapRenamedStructureModule()
54
+ return spec
55
+
56
+
57
+ # end of class FindRenamedStructureModule
58
+
59
+ # ----------------------------------------------------------------------------
60
+
61
+
62
+ class MapRenamedStructureModule(importlib.abc.Loader):
63
+ """Loader for old camel-case module names.
64
+ Import the current module and alias it under the old name.
65
+ """
66
+
67
+ def create_module(self, spec):
68
+ lcname = spec.name.lower()
69
+ mod = importlib.import_module(lcname)
70
+ sys.modules[spec.name] = mod
71
+ warn(WMSG.format(spec.name, lcname), DeprecationWarning, stacklevel=2)
72
+ return mod
73
+
74
+ def exec_module(self, module):
75
+ return
76
+
77
+
78
+ # end of class MapRenamedStructureModule
79
+
80
+ # ----------------------------------------------------------------------------
81
+
82
+ # show deprecation warning for diffpy.Structure
83
+ warn(WMSG.format("diffpy.Structure", "diffpy.structure"), DeprecationWarning, stacklevel=2)
84
+
85
+ # install meta path finder for diffpy.Structure submodules
86
+ sys.meta_path.append(FindRenamedStructureModule())
87
+
88
+ # End of file
@@ -0,0 +1,17 @@
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
+ """Script applications that use the `diffpy.structure` package.
17
+ """
@@ -0,0 +1,284 @@
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
+ """
17
+ Anyeye view structure file in atomeye.
18
+
19
+ Usage: ``anyeye [options] strufile``
20
+
21
+ Anyeye understands more `Structure` formats than atomeye. It converts `strufile`
22
+ to a temporary XCFG file which is opened in atomeye. See supported file formats:
23
+ ``inputFormats``
24
+
25
+ Options:
26
+ -f, --formula
27
+ Override chemical formula in `strufile`. The formula defines
28
+ elements in the same order as in `strufile`, e.g., ``Na4Cl4``.
29
+
30
+ -w, --watch
31
+ Watch input file for changes.
32
+
33
+ --viewer=VIEWER
34
+ The structure viewer program, by default "atomeye".
35
+ The program will be executed as "VIEWER structurefile".
36
+
37
+ --formats=FORMATS
38
+ Comma-separated list of file formats that are understood
39
+ by the VIEWER, by default ``"xcfg,pdb"``. Files of other
40
+ formats will be converted to the first listed format.
41
+
42
+ -h, --help
43
+ Display this message and exit.
44
+
45
+ -V, --version
46
+ Show script version and exit.
47
+ """
48
+
49
+ from __future__ import print_function
50
+
51
+ import os
52
+ import re
53
+ import signal
54
+ import sys
55
+
56
+ from diffpy.structure.structureerrors import StructureFormatError
57
+
58
+ # parameter dictionary
59
+ pd = {
60
+ "formula": None,
61
+ "watch": False,
62
+ "viewer": "atomeye",
63
+ "formats": ["xcfg", "pdb"],
64
+ }
65
+
66
+
67
+ def usage(style=None):
68
+ """Show usage info, for ``style=="brief"`` show only first 2 lines."""
69
+ import os.path
70
+
71
+ myname = os.path.basename(sys.argv[0])
72
+ msg = __doc__.replace("anyeye", myname)
73
+ if style == "brief":
74
+ msg = msg.split("\n")[1] + "\n" + "Try `%s --help' for more information." % myname
75
+ else:
76
+ from diffpy.structure.parsers import inputFormats
77
+
78
+ fmts = [f for f in inputFormats() if f != "auto"]
79
+ msg = msg.replace("inputFormats", " ".join(fmts))
80
+ print(msg)
81
+ return
82
+
83
+
84
+ def version():
85
+ from diffpy.structure import __version__
86
+
87
+ print("anyeye", __version__)
88
+ return
89
+
90
+
91
+ def loadStructureFile(filename, format="auto"):
92
+ """Load structure from specified file.
93
+
94
+ Parameters
95
+ ----------
96
+ filename : str
97
+ Path to the structure file.
98
+ format : str, Optional
99
+ File format, by default "auto".
100
+
101
+ Returns
102
+ -------
103
+ tuple
104
+ A tuple of (Structure, fileformat).
105
+ """
106
+ from diffpy.structure import Structure
107
+
108
+ stru = Structure()
109
+ p = stru.read(filename, format)
110
+ fileformat = p.format
111
+ return (stru, fileformat)
112
+
113
+
114
+ def convertStructureFile(pd):
115
+ # make temporary directory on the first pass
116
+ if "tmpdir" not in pd:
117
+ from tempfile import mkdtemp
118
+
119
+ pd["tmpdir"] = mkdtemp()
120
+ strufile = pd["strufile"]
121
+ tmpfile = os.path.join(pd["tmpdir"], os.path.basename(strufile))
122
+ pd["tmpfile"] = tmpfile
123
+ # speed up file processing in the watch mode
124
+ fmt = pd.get("format", "auto")
125
+ stru = None
126
+ if fmt == "auto":
127
+ stru, fmt = loadStructureFile(strufile)
128
+ pd["fmt"] = fmt
129
+ # if fmt is recognized by the viewer, use as is
130
+ if fmt in pd["formats"] and pd["formula"] is None:
131
+ import shutil
132
+
133
+ shutil.copyfile(strufile, tmpfile + ".tmp")
134
+ os.rename(tmpfile + ".tmp", tmpfile)
135
+ return
136
+ # otherwise convert to the first recognized viewer format
137
+ if stru is None:
138
+ stru = loadStructureFile(strufile, fmt)[0]
139
+ if pd["formula"]:
140
+ formula = pd["formula"]
141
+ if len(formula) != len(stru):
142
+ emsg = "Formula has %i atoms while structure %i" % (len(formula), len(stru))
143
+ raise RuntimeError(emsg)
144
+ for a, el in zip(stru, formula):
145
+ a.element = el
146
+ elif format == "rawxyz":
147
+ for a in stru:
148
+ if a.element == "":
149
+ a.element = "C"
150
+ stru.write(tmpfile + ".tmp", pd["formats"][0])
151
+ os.rename(tmpfile + ".tmp", tmpfile)
152
+ return
153
+
154
+
155
+ def watchStructureFile(pd):
156
+ from time import sleep
157
+
158
+ strufile = pd["strufile"]
159
+ tmpfile = pd["tmpfile"]
160
+ while pd["watch"]:
161
+ if os.path.getmtime(tmpfile) < os.path.getmtime(strufile):
162
+ convertStructureFile(pd)
163
+ sleep(1)
164
+ return
165
+
166
+
167
+ def cleanUp(pd):
168
+ if "tmpfile" in pd:
169
+ os.remove(pd["tmpfile"])
170
+ del pd["tmpfile"]
171
+ if "tmpdir" in pd:
172
+ os.rmdir(pd["tmpdir"])
173
+ del pd["tmpdir"]
174
+ return
175
+
176
+
177
+ def parseFormula(formula):
178
+ """Parse chemical formula and return a list of elements"""
179
+ # remove all blanks
180
+ formula = re.sub(r"\s", "", formula)
181
+ if not re.match("^[A-Z]", formula):
182
+ raise RuntimeError("InvalidFormula '%s'" % formula)
183
+ elcnt = re.split("([A-Z][a-z]?)", formula)[1:]
184
+ ellst = []
185
+ try:
186
+ for i in range(0, len(elcnt), 2):
187
+ el = elcnt[i]
188
+ cnt = elcnt[i + 1]
189
+ cnt = (cnt == "") and 1 or int(cnt)
190
+ ellst.extend(cnt * [el])
191
+ except ValueError:
192
+ emsg = "Invalid formula, %r is not valid count" % elcnt[i + 1]
193
+ raise RuntimeError(emsg)
194
+ return ellst
195
+
196
+
197
+ def die(exit_status=0, pd={}):
198
+ cleanUp(pd)
199
+ sys.exit(exit_status)
200
+
201
+
202
+ def signalHandler(signum, stackframe):
203
+ # revert to default handler
204
+ signal.signal(signum, signal.SIG_DFL)
205
+ if signum == signal.SIGCHLD:
206
+ pid, exit_status = os.wait()
207
+ exit_status = (exit_status >> 8) + (exit_status & 0x00FF)
208
+ die(exit_status, pd)
209
+ else:
210
+ die(1, pd)
211
+ return
212
+
213
+
214
+ def main():
215
+ import getopt
216
+
217
+ # default parameters
218
+ pd["watch"] = False
219
+ try:
220
+ opts, args = getopt.getopt(
221
+ sys.argv[1:], "f:whV", ["formula=", "watch", "viewer=", "formats=", "help", "version"]
222
+ )
223
+ except getopt.GetoptError as errmsg:
224
+ print(errmsg, file=sys.stderr)
225
+ die(2)
226
+ # process options
227
+ for o, a in opts:
228
+ if o in ("-f", "--formula"):
229
+ try:
230
+ pd["formula"] = parseFormula(a)
231
+ except RuntimeError as msg:
232
+ print(msg, file=sys.stderr)
233
+ die(2)
234
+ elif o in ("-w", "--watch"):
235
+ pd["watch"] = True
236
+ elif o == "--viewer":
237
+ pd["viewer"] = a
238
+ elif o == "--formats":
239
+ pd["formats"] = [w.strip() for w in a.split(",")]
240
+ elif o in ("-h", "--help"):
241
+ usage()
242
+ die()
243
+ elif o in ("-V", "--version"):
244
+ version()
245
+ die()
246
+ if len(args) < 1:
247
+ usage("brief")
248
+ die()
249
+ elif len(args) > 1:
250
+ print("too many structure files", file=sys.stderr)
251
+ die(2)
252
+ pd["strufile"] = args[0]
253
+ # trap the following signals
254
+ signal.signal(signal.SIGHUP, signalHandler)
255
+ signal.signal(signal.SIGQUIT, signalHandler)
256
+ signal.signal(signal.SIGSEGV, signalHandler)
257
+ signal.signal(signal.SIGTERM, signalHandler)
258
+ signal.signal(signal.SIGINT, signalHandler)
259
+ env = os.environ.copy()
260
+ if os.path.basename(pd["viewer"]).startswith("atomeye"):
261
+ env["XLIB_SKIP_ARGB_VISUALS"] = "1"
262
+ # try to run the thing:
263
+ try:
264
+ convertStructureFile(pd)
265
+ spawnargs = (pd["viewer"], pd["viewer"], pd["tmpfile"], env)
266
+ # load strufile in atomeye
267
+ if pd["watch"]:
268
+ signal.signal(signal.SIGCLD, signalHandler)
269
+ os.spawnlpe(os.P_NOWAIT, *spawnargs)
270
+ watchStructureFile(pd)
271
+ else:
272
+ status = os.spawnlpe(os.P_WAIT, *spawnargs)
273
+ die(status, pd)
274
+ except IOError as e:
275
+ print("%s: %s" % (args[0], e.strerror), file=sys.stderr)
276
+ die(1, pd)
277
+ except StructureFormatError as e:
278
+ print("%s: %s" % (args[0], e), file=sys.stderr)
279
+ die(1, pd)
280
+ return
281
+
282
+
283
+ if __name__ == "__main__":
284
+ main()
@@ -0,0 +1,126 @@
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
+ """Translate structure file to different format.
17
+
18
+ Usage: ``transtru INFMT..OUTFMT strufile``
19
+
20
+ Translates structure file strufile from `INFMT` to `OUTFMT` format and prints it
21
+ to the screen. Use "-" as `strufile` to read from standard input. To save the
22
+ translated file, use
23
+
24
+ ``transtru INFMT..OUTFMT strufile > strufile.out``
25
+
26
+ Supported input and output structure formats are
27
+ * `INFMT`: ``inputFormats``
28
+ * `OUTFMT`: ``outputFormats``
29
+
30
+ Options:
31
+ -h, --help
32
+ Display this message.
33
+
34
+ -V, --version
35
+ Show script version.
36
+ """
37
+
38
+ from __future__ import print_function
39
+
40
+ import sys
41
+
42
+ from diffpy.structure import Structure
43
+ from diffpy.structure.structureerrors import StructureFormatError
44
+
45
+
46
+ def usage(style=None):
47
+ """Show usage info, for ``style=="brief"`` show only first 2 lines."""
48
+ import os.path
49
+
50
+ myname = os.path.basename(sys.argv[0])
51
+ msg = __doc__.replace("transtru", myname)
52
+ if style == "brief":
53
+ msg = msg.split("\n")[1] + "\n" + "Try `%s --help' for more information." % myname
54
+ else:
55
+ from diffpy.structure.parsers import inputFormats, outputFormats
56
+
57
+ msg = msg.replace("inputFormats", " ".join(inputFormats()))
58
+ msg = msg.replace("outputFormats", " ".join(outputFormats()))
59
+ print(msg)
60
+ return
61
+
62
+
63
+ def version():
64
+ from diffpy.structure import __version__
65
+
66
+ print("diffpy.structure", __version__)
67
+ return
68
+
69
+
70
+ def main():
71
+ import getopt
72
+
73
+ # default parameters
74
+ try:
75
+ opts, args = getopt.getopt(sys.argv[1:], "hV", ["help", "version"])
76
+ except getopt.GetoptError as errmsg:
77
+ print(errmsg, file=sys.stderr)
78
+ sys.exit(2)
79
+ # process options
80
+ for o, a in opts:
81
+ if o in ("-h", "--help"):
82
+ usage()
83
+ sys.exit()
84
+ elif o in ("-V", "--version"):
85
+ version()
86
+ sys.exit()
87
+ if len(args) < 1:
88
+ usage("brief")
89
+ sys.exit()
90
+ # process arguments
91
+ from diffpy.structure.parsers import inputFormats, outputFormats
92
+
93
+ try:
94
+ infmt, outfmt = args[0].split("..", 1)
95
+ if infmt not in inputFormats():
96
+ print("'%s' is not valid input format" % infmt, file=sys.stderr)
97
+ sys.exit(2)
98
+ if outfmt not in outputFormats():
99
+ print("'%s' is not valid output format" % outfmt, file=sys.stderr)
100
+ sys.exit(2)
101
+ except ValueError:
102
+ print("invalid format specification '%s' does not contain .." % args[0], file=sys.stderr)
103
+ sys.exit(2)
104
+ # ready to do some real work
105
+ try:
106
+ strufile = args[1]
107
+ stru = Structure()
108
+ if args[1] == "-":
109
+ stru.readStr(sys.stdin.read(), infmt)
110
+ else:
111
+ stru.read(strufile, infmt)
112
+ sys.stdout.write(stru.writeStr(outfmt))
113
+ except IndexError:
114
+ print("strufile not specified", file=sys.stderr)
115
+ sys.exit(2)
116
+ except IOError as e:
117
+ print("%s: %s" % (strufile, e.strerror), file=sys.stderr)
118
+ sys.exit(1)
119
+ except StructureFormatError as e:
120
+ print("%s: %s" % (strufile, e), file=sys.stderr)
121
+ sys.exit(1)
122
+ return
123
+
124
+
125
+ if __name__ == "__main__":
126
+ main()