digichem-core 6.0.0rc1__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 (111) hide show
  1. digichem/__init__.py +75 -0
  2. digichem/basis.py +116 -0
  3. digichem/config/README +3 -0
  4. digichem/config/__init__.py +5 -0
  5. digichem/config/base.py +321 -0
  6. digichem/config/locations.py +14 -0
  7. digichem/config/parse.py +90 -0
  8. digichem/config/util.py +117 -0
  9. digichem/data/README +4 -0
  10. digichem/data/batoms/COPYING +18 -0
  11. digichem/data/batoms/LICENSE +674 -0
  12. digichem/data/batoms/README +2 -0
  13. digichem/data/batoms/__init__.py +0 -0
  14. digichem/data/batoms/batoms-renderer.py +351 -0
  15. digichem/data/config/digichem.yaml +714 -0
  16. digichem/data/functionals.csv +15 -0
  17. digichem/data/solvents.csv +185 -0
  18. digichem/data/tachyon/COPYING.md +5 -0
  19. digichem/data/tachyon/LICENSE +30 -0
  20. digichem/data/tachyon/tachyon_LINUXAMD64 +0 -0
  21. digichem/data/vmd/common.tcl +468 -0
  22. digichem/data/vmd/generate_combined_orbital_images.tcl +70 -0
  23. digichem/data/vmd/generate_density_images.tcl +45 -0
  24. digichem/data/vmd/generate_dipole_images.tcl +68 -0
  25. digichem/data/vmd/generate_orbital_images.tcl +57 -0
  26. digichem/data/vmd/generate_spin_images.tcl +66 -0
  27. digichem/data/vmd/generate_structure_images.tcl +40 -0
  28. digichem/datas.py +14 -0
  29. digichem/exception/__init__.py +7 -0
  30. digichem/exception/base.py +133 -0
  31. digichem/exception/uncatchable.py +63 -0
  32. digichem/file/__init__.py +1 -0
  33. digichem/file/base.py +364 -0
  34. digichem/file/cube.py +284 -0
  35. digichem/file/fchk.py +94 -0
  36. digichem/file/prattle.py +277 -0
  37. digichem/file/types.py +97 -0
  38. digichem/image/__init__.py +6 -0
  39. digichem/image/base.py +113 -0
  40. digichem/image/excited_states.py +335 -0
  41. digichem/image/graph.py +293 -0
  42. digichem/image/orbitals.py +239 -0
  43. digichem/image/render.py +617 -0
  44. digichem/image/spectroscopy.py +797 -0
  45. digichem/image/structure.py +115 -0
  46. digichem/image/vmd.py +826 -0
  47. digichem/input/__init__.py +3 -0
  48. digichem/input/base.py +78 -0
  49. digichem/input/digichem_input.py +500 -0
  50. digichem/input/gaussian.py +140 -0
  51. digichem/log.py +179 -0
  52. digichem/memory.py +166 -0
  53. digichem/misc/__init__.py +4 -0
  54. digichem/misc/argparse.py +44 -0
  55. digichem/misc/base.py +61 -0
  56. digichem/misc/io.py +239 -0
  57. digichem/misc/layered_dict.py +285 -0
  58. digichem/misc/text.py +139 -0
  59. digichem/misc/time.py +73 -0
  60. digichem/parse/__init__.py +13 -0
  61. digichem/parse/base.py +220 -0
  62. digichem/parse/cclib.py +138 -0
  63. digichem/parse/dump.py +253 -0
  64. digichem/parse/gaussian.py +130 -0
  65. digichem/parse/orca.py +96 -0
  66. digichem/parse/turbomole.py +201 -0
  67. digichem/parse/util.py +523 -0
  68. digichem/result/__init__.py +6 -0
  69. digichem/result/alignment/AA.py +114 -0
  70. digichem/result/alignment/AAA.py +61 -0
  71. digichem/result/alignment/FAP.py +148 -0
  72. digichem/result/alignment/__init__.py +3 -0
  73. digichem/result/alignment/base.py +310 -0
  74. digichem/result/angle.py +153 -0
  75. digichem/result/atom.py +742 -0
  76. digichem/result/base.py +258 -0
  77. digichem/result/dipole_moment.py +332 -0
  78. digichem/result/emission.py +402 -0
  79. digichem/result/energy.py +323 -0
  80. digichem/result/excited_state.py +821 -0
  81. digichem/result/ground_state.py +94 -0
  82. digichem/result/metadata.py +644 -0
  83. digichem/result/multi.py +98 -0
  84. digichem/result/nmr.py +1086 -0
  85. digichem/result/orbital.py +647 -0
  86. digichem/result/result.py +244 -0
  87. digichem/result/soc.py +272 -0
  88. digichem/result/spectroscopy.py +514 -0
  89. digichem/result/tdm.py +267 -0
  90. digichem/result/vibration.py +167 -0
  91. digichem/test/__init__.py +6 -0
  92. digichem/test/conftest.py +4 -0
  93. digichem/test/test_basis.py +71 -0
  94. digichem/test/test_calculate.py +30 -0
  95. digichem/test/test_config.py +78 -0
  96. digichem/test/test_cube.py +369 -0
  97. digichem/test/test_exception.py +16 -0
  98. digichem/test/test_file.py +104 -0
  99. digichem/test/test_image.py +337 -0
  100. digichem/test/test_input.py +64 -0
  101. digichem/test/test_parsing.py +79 -0
  102. digichem/test/test_prattle.py +36 -0
  103. digichem/test/test_result.py +489 -0
  104. digichem/test/test_translate.py +112 -0
  105. digichem/test/util.py +207 -0
  106. digichem/translate.py +591 -0
  107. digichem_core-6.0.0rc1.dist-info/METADATA +96 -0
  108. digichem_core-6.0.0rc1.dist-info/RECORD +111 -0
  109. digichem_core-6.0.0rc1.dist-info/WHEEL +4 -0
  110. digichem_core-6.0.0rc1.dist-info/licenses/COPYING.md +10 -0
  111. digichem_core-6.0.0rc1.dist-info/licenses/LICENSE +11 -0
@@ -0,0 +1,337 @@
1
+ import pytest
2
+ from pathlib import Path
3
+ import shutil
4
+
5
+ from digichem.image.excited_states import Excited_states_diagram_maker
6
+ from digichem.image.graph import Convergence_graph_maker
7
+ from digichem.image.orbitals import Orbital_diagram_maker
8
+ from digichem.image.spectroscopy import Absorption_graph_maker, Emission_graph_maker, \
9
+ Frequency_graph_maker, NMR_graph_maker, NMR_graph_zoom_maker
10
+ from digichem.image.structure import Skeletal_image_maker
11
+ from digichem.image.vmd import Structure_image_maker, Orbital_image_maker, Density_image_maker, \
12
+ Combined_orbital_image_maker, Permanent_dipole_image_maker, Transition_dipole_image_maker
13
+ from digichem.parse.util import open_for_parsing, parse_calculation
14
+
15
+ from digichem.test.util import digichem_options, data_directory
16
+ from digichem.test.test_result import gaussian_ES_result, turbomole_ES_result, orca_ES_result, \
17
+ gaussian_opt_result, turbomole_opt_result, orca_opt_result, orca_opt_freq_result, \
18
+ orca_nmr_result
19
+
20
+ HAS_VMD = shutil.which("vmd")
21
+
22
+ @pytest.mark.parametrize("result_set", [
23
+ pytest.lazy_fixture("gaussian_ES_result"),
24
+ pytest.lazy_fixture("turbomole_ES_result"),
25
+ pytest.lazy_fixture("orca_ES_result")
26
+ ])
27
+ def test_es_diagram(result_set, tmp_path, digichem_options):
28
+ """Can we make an excited states diagram?"""
29
+ maker = Excited_states_diagram_maker.from_options(
30
+ tmp_path / "tmp.png",
31
+ excited_states = result_set.excited_states,
32
+ ground_state = result_set.ground_state,
33
+ options = digichem_options
34
+ )
35
+
36
+ maker.get_image()
37
+ assert Path(tmp_path, "tmp.png").exists()
38
+
39
+
40
+ @pytest.mark.parametrize("result_set", [
41
+ pytest.lazy_fixture("gaussian_opt_result"),
42
+ pytest.lazy_fixture("turbomole_opt_result"),
43
+ pytest.lazy_fixture("orca_opt_result")
44
+ ])
45
+ def test_convergence_diagram(result_set, tmp_path, digichem_options):
46
+ """Can we make an optimisation graph?"""
47
+ maker = Convergence_graph_maker.from_options(
48
+ tmp_path / "tmp.png",
49
+ energies = result_set.energies.scf,
50
+ options = digichem_options
51
+ )
52
+
53
+ maker.get_image()
54
+ assert Path(tmp_path, "tmp.png").exists()
55
+
56
+
57
+ @pytest.mark.parametrize("result_set", [
58
+ pytest.lazy_fixture("gaussian_opt_result"),
59
+ pytest.lazy_fixture("turbomole_opt_result"),
60
+ pytest.lazy_fixture("orca_opt_result")
61
+ ])
62
+ def test_orbital_diagram(result_set, tmp_path, digichem_options):
63
+ """Can we make an orbital diagram?"""
64
+ maker = Orbital_diagram_maker.from_options(
65
+ tmp_path / "tmp.png",
66
+ orbitals = result_set.orbitals,
67
+ options = digichem_options
68
+ )
69
+
70
+ maker.get_image()
71
+ assert Path(tmp_path, "tmp.png").exists()
72
+
73
+
74
+ @pytest.mark.parametrize("result_set", [
75
+ pytest.lazy_fixture("gaussian_ES_result"),
76
+ pytest.lazy_fixture("turbomole_ES_result"),
77
+ pytest.lazy_fixture("orca_ES_result")
78
+ ])
79
+ def test_abs_diagram(result_set, tmp_path, digichem_options):
80
+ """Can we make an absorption spectrum?"""
81
+ maker = Absorption_graph_maker.from_options(
82
+ tmp_path / "tmp.png",
83
+ excited_states = result_set.excited_states,
84
+ options = digichem_options
85
+ )
86
+
87
+ maker.get_image()
88
+ assert Path(tmp_path, "tmp.png").exists()
89
+
90
+
91
+ @pytest.mark.parametrize("result_set", [
92
+ pytest.lazy_fixture("gaussian_ES_result"),
93
+ pytest.lazy_fixture("turbomole_ES_result"),
94
+ pytest.lazy_fixture("orca_ES_result")
95
+ ])
96
+ def test_pl_diagram(result_set, tmp_path, digichem_options):
97
+ """Can we make an emission spectrum?"""
98
+ maker = Emission_graph_maker.from_options(
99
+ tmp_path / "tmp.png",
100
+ excited_states = result_set.excited_states,
101
+ options = digichem_options
102
+ )
103
+
104
+ maker.get_image()
105
+ assert Path(tmp_path, "tmp.png").exists()
106
+
107
+
108
+ @pytest.mark.parametrize("result_set", [
109
+ pytest.lazy_fixture("gaussian_opt_result"),
110
+ pytest.lazy_fixture("turbomole_opt_result"),
111
+ pytest.lazy_fixture("orca_opt_freq_result")
112
+ ])
113
+ def test_freq_diagram(result_set, tmp_path, digichem_options):
114
+ """Can we make an IR spectrum?"""
115
+ maker = Frequency_graph_maker.from_options(
116
+ tmp_path / "tmp.png",
117
+ vibrations = result_set.vibrations,
118
+ options = digichem_options
119
+ )
120
+
121
+ maker.get_image()
122
+ assert Path(tmp_path, "tmp.png").exists()
123
+
124
+
125
+ @pytest.mark.parametrize("result_set", [
126
+ pytest.lazy_fixture("orca_nmr_result"),
127
+ ])
128
+ def test_nmr_diagram(result_set, tmp_path, digichem_options):
129
+ """Can we make an NMR spectrum?"""
130
+ # Get a suitable spectrometer object.
131
+ spectrometer = result_set.nmr.spectrometer
132
+
133
+ maker = NMR_graph_maker.from_options(
134
+ tmp_path / "tmp.png",
135
+ graph = spectrometer.get_graph(1, 1),
136
+ options = digichem_options
137
+ )
138
+
139
+ maker.get_image()
140
+ assert Path(tmp_path, "tmp.png").exists()
141
+
142
+
143
+ @pytest.mark.parametrize("result_set", [
144
+ pytest.lazy_fixture("orca_nmr_result"),
145
+ ])
146
+ def test_focus_nmr_diagram(result_set, tmp_path, digichem_options):
147
+ """Can we make an NMR spectrum?"""
148
+ # Get a suitable spectrometer object.
149
+ spectrometer = result_set.nmr.spectrometer
150
+
151
+ maker = NMR_graph_zoom_maker.from_options(
152
+ tmp_path / "tmp.png",
153
+ graph = spectrometer.get_graph(1, 1),
154
+ focus = result_set.atoms.groups[(2, "H")],
155
+ options = digichem_options
156
+ )
157
+
158
+ maker.get_image()
159
+ assert Path(tmp_path, "tmp.png").exists()
160
+
161
+
162
+ @pytest.mark.parametrize("result_set", [
163
+ pytest.lazy_fixture("gaussian_opt_result"),
164
+ pytest.lazy_fixture("turbomole_opt_result"),
165
+ pytest.lazy_fixture("orca_opt_freq_result")
166
+ ])
167
+ def test_2d_diagram(result_set, tmp_path, digichem_options):
168
+ """Can we make an IR spectrum?"""
169
+ maker = Skeletal_image_maker.from_options(
170
+ tmp_path / "tmp.png",
171
+ atoms = result_set.atoms,
172
+ options = digichem_options
173
+ )
174
+
175
+ maker.get_image()
176
+ assert Path(tmp_path, "tmp.png").exists()
177
+
178
+
179
+ @pytest.mark.skipif(not HAS_VMD,
180
+ reason="No VMD available")
181
+ @pytest.mark.parametrize("cube_file", [
182
+ Path(data_directory(), "Cubes/Pyridine.HOMO.cube")
183
+ ], ids = ["Gaussian"])
184
+ @pytest.mark.parametrize("maker_cls", [
185
+ Structure_image_maker,
186
+ Orbital_image_maker,
187
+ ])
188
+ def test_3d_image(cube_file, maker_cls, tmp_path, digichem_options):
189
+ """Can we make a 3D structure image?"""
190
+ maker = maker_cls.from_options(
191
+ tmp_path / "tmp.png",
192
+ cube_file = cube_file,
193
+ options = digichem_options
194
+ )
195
+
196
+ maker.get_file('x0y0z0')
197
+ assert Path(tmp_path, "tmp.x0y0z0.png").exists()
198
+
199
+
200
+ # @pytest.mark.parametrize("result_path", [
201
+ # Path(data_directory(), "Pyridine/Gaussian 16 Optimisation Frequencies PBE1PBE (GD3BJ) Toluene 6-31G(d,p).tar.gz")
202
+ # ], ids = ["Gaussian"])
203
+ # @pytest.mark.parametrize("density", [
204
+ # "SCF"
205
+ # ])
206
+
207
+ @pytest.mark.skipif(not HAS_VMD,
208
+ reason="No VMD available")
209
+ @pytest.mark.parametrize("cube_file", [
210
+ Path(data_directory(), "Cubes/Pyridine.SCF.cube")
211
+ ], ids = ["Gaussian"])
212
+ def test_density_image(cube_file, tmp_path, digichem_options):
213
+ """Can we make a 3D structure image?"""
214
+ maker = Density_image_maker.from_options(
215
+ tmp_path / "tmp.png",
216
+ cube_file = cube_file,
217
+ options = digichem_options
218
+ )
219
+
220
+ maker.get_file('x0y0z0')
221
+ assert Path(tmp_path, "tmp.x0y0z0.png").exists()
222
+
223
+
224
+ @pytest.mark.skipif(not HAS_VMD,
225
+ reason="No VMD available")
226
+ @pytest.mark.parametrize("cube_file", [
227
+ Path(data_directory(), "Cubes/Benzene.anion.spin.cube")
228
+ ], ids = ["Gaussian"])
229
+ def test_spin_density_image(cube_file, tmp_path, digichem_options):
230
+ """Can we make a 3D structure image?"""
231
+ maker = Density_image_maker.from_options(
232
+ tmp_path / "tmp.png",
233
+ cube_file = cube_file,
234
+ options = digichem_options
235
+ )
236
+
237
+ maker.get_file('x0y0z0')
238
+ assert Path(tmp_path, "tmp.x0y0z0.png").exists()
239
+
240
+
241
+ @pytest.mark.skipif(not HAS_VMD,
242
+ reason="No VMD available")
243
+ @pytest.mark.parametrize("homo_cube, lumo_cube", [
244
+ [Path(data_directory(), "Cubes/Pyridine.HOMO.cube"), Path(data_directory(), "Cubes/Pyridine.LUMO.cube")]
245
+ ], ids = ["Gaussian"])
246
+ def test_combined_orbital_image(homo_cube, lumo_cube, tmp_path, digichem_options):
247
+ """Can we make a 3D structure image?"""
248
+ maker = Combined_orbital_image_maker.from_options(
249
+ tmp_path / "tmp.png",
250
+ HOMO_cube_file = homo_cube,
251
+ LUMO_cube_file = lumo_cube,
252
+ options = digichem_options
253
+ )
254
+
255
+ maker.get_file('x0y0z0')
256
+ assert Path(tmp_path, "tmp.x0y0z0.png").exists()
257
+
258
+
259
+ @pytest.mark.skipif(not HAS_VMD,
260
+ reason="No VMD available")
261
+ @pytest.mark.parametrize("cube_file", [
262
+ Path(data_directory(), "Cubes/Benzene.anion.AHOMO.cube")
263
+ ], ids = ["Gaussian"])
264
+ def test_unrestricted_orbital_image(cube_file, tmp_path, digichem_options):
265
+ """Can we make a 3D structure image?"""
266
+ maker = Orbital_image_maker.from_options(
267
+ tmp_path / "tmp.png",
268
+ cube_file = cube_file,
269
+ options = digichem_options
270
+ )
271
+
272
+ maker.get_file('x0y0z0')
273
+ assert Path(tmp_path, "tmp.x0y0z0.png").exists()
274
+
275
+
276
+ @pytest.mark.skipif(not HAS_VMD,
277
+ reason="No VMD available")
278
+ @pytest.mark.parametrize("result_path, cube_file", [
279
+ [
280
+ Path(data_directory(), "Pyridine/Gaussian 16 Optimisation Frequencies PBE1PBE (GD3BJ) Toluene 6-31G(d,p).tar.gz"),
281
+ Path(data_directory(), "Cubes/Pyridine.HOMO.cube"),
282
+ ]
283
+ ])
284
+ def test_pdm_image(result_path, cube_file, tmp_path, digichem_options):
285
+ """Can we make a 3D structure image?"""
286
+ with open_for_parsing(result_path) as open_files:
287
+ result_set = parse_calculation(*open_files, options = digichem_options)
288
+ maker = Permanent_dipole_image_maker.from_options(
289
+ tmp_path / "tmp.png",
290
+ cube_file = cube_file,
291
+ dipole_moment = result_set.dipole_moment,
292
+ options = digichem_options
293
+ )
294
+
295
+ maker.get_file('x0y0z0')
296
+ assert Path(tmp_path, "tmp.x0y0z0.png").exists()
297
+
298
+
299
+ @pytest.mark.skipif(not HAS_VMD,
300
+ reason="No VMD available")
301
+ @pytest.mark.parametrize("result_path, cube_file", [
302
+ [
303
+ Path(data_directory(), "Pyridine/Gaussian 16 Excited States TDA Optimised S(1) PBE1PBE (GD3BJ) Toluene 6-31G(d,p).tar.gz"),
304
+ Path(data_directory(), "Cubes/Pyridine.HOMO.cube"),
305
+ ]
306
+ ])
307
+ def test_tdm_image(result_path, cube_file, tmp_path, digichem_options):
308
+ """Can we make a 3D structure image?"""
309
+ with open_for_parsing(result_path) as open_files:
310
+ result_set = parse_calculation(*open_files, options = digichem_options)
311
+ maker = Transition_dipole_image_maker.from_options(
312
+ tmp_path / "tmp.png",
313
+ cube_file = cube_file,
314
+ dipole_moment = result_set.excited_states.find("S(1)").transition_dipole_moment.electric,
315
+ magnetic_dipole_moment = result_set.excited_states.find("S(1)").transition_dipole_moment.magnetic,
316
+ options = digichem_options
317
+ )
318
+
319
+ maker.get_file('x0y0z0')
320
+ assert Path(tmp_path, "tmp.x0y0z0.png").exists()
321
+
322
+
323
+ @pytest.mark.skipif(not HAS_VMD,
324
+ reason="No VMD available")
325
+ @pytest.mark.parametrize("cube_file", [
326
+ Path(data_directory(), "Cubes/Pyridine.HOMO.cube"),
327
+ ])
328
+ def test_nto_image(cube_file, tmp_path, digichem_options):
329
+ """Can we make a 3D structure image?"""
330
+ maker = Orbital_image_maker.from_options(
331
+ tmp_path / "tmp.png",
332
+ cube_file = cube_file,
333
+ options = digichem_options
334
+ )
335
+
336
+ maker.get_file('x0y0z0')
337
+ assert Path(tmp_path, "tmp.x0y0z0.png").exists()
@@ -0,0 +1,64 @@
1
+ """Tests for parsing input files"""
2
+
3
+ import pytest
4
+ from pathlib import Path
5
+
6
+ from digichem.test.util import pyridine_si_v2, pyridine_si_v1, pyridine_cml,\
7
+ result_files
8
+ from digichem.input.digichem_input import si_from_file
9
+
10
+ @pytest.mark.parametrize("file_path", [
11
+ pyridine_si_v2,
12
+ pyridine_si_v1
13
+ ])
14
+ def test_input_reading(file_path):
15
+ """
16
+ Test whether we can correctly read from an existing si file.
17
+ """
18
+ si_file = si_from_file(file_path)
19
+
20
+ # Check charge and mult.
21
+ assert si_file.charge == 0
22
+ assert si_file.multiplicity == 1
23
+
24
+ # Check geometry.
25
+ # All files should contain data for pyridine.
26
+ assert len(si_file.atoms) == 11
27
+ assert str(si_file.formula) == "NC5H5"
28
+
29
+
30
+ def test_si_writing(tmp_path):
31
+ """
32
+ Test whether we can correctly write a new .si file.
33
+ """
34
+ # Read in an input file.
35
+ si_file = si_from_file(pyridine_cml)
36
+
37
+ # Write to our temp dir.
38
+ new_si_path = Path(tmp_path, "Pyrdine.si")
39
+ with open(new_si_path, "wt") as out_file:
40
+ si_file.to_file(out_file)
41
+
42
+ # Parse the newly written file.
43
+ new_si_file = si_from_file(new_si_path)
44
+
45
+ # Check they're the same.
46
+ assert new_si_file == si_file
47
+
48
+
49
+ @pytest.mark.parametrize("file_path, sha", [
50
+ [result_files['gaussian'][0], "ebd4f4e9f81cdb57ec2d2f2e1fba9cef0698f4c0"],
51
+ [result_files['turbomole'][0], "60a8ebd9e701b849cfccd9cbb41684519a7fdf0b"],
52
+ [result_files['orca'][0], "e48e7f653f4e67c1bd4c5c4bb76405fad2d441d0"],
53
+ ])
54
+ def test_input_history(file_path, sha):
55
+ """
56
+ Test whether the history attribute is set properly.
57
+ """
58
+ si_file = si_from_file(file_path)
59
+
60
+ assert si_file.history == sha
61
+
62
+ dump = si_file.dict
63
+
64
+ assert dump['history'] == sha
@@ -0,0 +1,79 @@
1
+ """Tests for result parsing and processing"""
2
+
3
+ from pathlib import Path
4
+ import itertools
5
+ import numpy
6
+ import pytest
7
+ import yaml
8
+
9
+ from digichem.parse import parse_calculation, parse_multiple_calculations, parse_and_merge_calculations
10
+ from digichem.test.util import data_directory, result_files, digichem_options
11
+ from digichem.result import Result_set
12
+
13
+ @pytest.mark.parametrize("result_data", list(itertools.chain(*list(result_files.values()))))
14
+ def test_parsing(result_data, digichem_options):
15
+ """Test whether we can parse various calc results."""
16
+ result = parse_calculation(result_data, options = digichem_options)
17
+ assert isinstance(result, Result_set)
18
+
19
+
20
+ def test_multi_parsing(digichem_options):
21
+ """Test whether we can parse in parallel."""
22
+
23
+ results = parse_multiple_calculations(*list(itertools.chain(*list(result_files.values()))), options = digichem_options)
24
+
25
+ # Check length.
26
+ assert len(results) == len(list(itertools.chain(*list(result_files.values()))))
27
+
28
+
29
+ @pytest.mark.parametrize("data_set", list(result_files.values()))
30
+ def test_merged_parsing(data_set, digichem_options):
31
+ """Test whether we can parse and merge calc results."""
32
+ result = parse_and_merge_calculations(*data_set, options = digichem_options)
33
+
34
+ assert isinstance(result, Result_set)
35
+ assert len(result.results) == len(data_set)
36
+
37
+
38
+ @pytest.mark.parametrize(
39
+ "result_files",
40
+ itertools.chain(
41
+ [(result_file,) for program_files in result_files.values() for result_file in program_files],
42
+ [(
43
+ Path(data_directory(), "Naphthalene/Gaussian 16 Optimisation Frequencies PBE1PBE (GD3BJ) Toluene 6-31G(d,p)"),
44
+ Path(data_directory(), "Naphthalene/Gaussian 16 Excited States TDA Optimised S(1) PBE1PBE (GD3BJ) Toluene 6-31G(d,p).tar.gz")
45
+ )]
46
+ )
47
+ )
48
+ def test_dump_and_parse(result_files, tmp_path, digichem_options):
49
+ """Test whether we can dump and reload a result to get the same data back again."""
50
+ # Set numpy errors (not sure why this isn't the default...)
51
+ numpy.seterr(invalid = 'raise', divide = 'raise')
52
+
53
+ # Parse the raw data.
54
+ if len(result_files) == 1:
55
+ raw = parse_calculation(result_files[0], options = digichem_options)
56
+
57
+ else:
58
+ raw = parse_and_merge_calculations(*result_files, options = digichem_options)
59
+
60
+ # Instead of just dumping to memory we'll dump to a file to test the full mechanism.
61
+ with open(Path(tmp_path, "dump.sir"), "wt") as dump_file:
62
+ dump_file.write(yaml.safe_dump(raw.dump(digichem_options = digichem_options)))
63
+
64
+ # Now load the result back again.
65
+ parsed = parse_calculation(Path(tmp_path, "dump.sir"), options = digichem_options)
66
+
67
+ # Dump both the raw and parsed result sets and compare to make sure they're the same.
68
+ raw_dump = raw.dump(digichem_options)
69
+ parsed_dump = parsed.dump(digichem_options)
70
+
71
+ # Aux files are not preserved, so don't compare these.
72
+ raw_dump['metadata'].pop("auxiliary_files")
73
+ raw_dump['metadata'].pop("log_files")
74
+ parsed_dump['metadata'].pop("auxiliary_files")
75
+ parsed_dump['metadata'].pop("log_files")
76
+
77
+
78
+ assert raw_dump == parsed_dump
79
+
@@ -0,0 +1,36 @@
1
+ """Tests for functioning of oprattle"""
2
+
3
+ import pytest
4
+
5
+ from digichem.file.prattle import Oprattle_formats, Openprattle_converter
6
+
7
+ from digichem.test.util import ethane_xyz, benzene_cdx
8
+
9
+ @pytest.mark.parametrize("readwrite", ["read", "write"])
10
+ def test_formats(readwrite):
11
+ if readwrite == "read":
12
+ assert len(Oprattle_formats().read()) > 0
13
+
14
+ else:
15
+ assert len(Oprattle_formats().write()) > 0
16
+
17
+ @pytest.mark.parametrize("file_path", [
18
+ ethane_xyz,
19
+ benzene_cdx
20
+ ])
21
+ def test_convert(file_path):
22
+ Openprattle_converter(input_file_path = file_path).convert("com")
23
+
24
+
25
+ @pytest.mark.parametrize("file_path", [
26
+ ethane_xyz,
27
+ benzene_cdx
28
+ ])
29
+ def test_gen3d(file_path):
30
+ first = Openprattle_converter(input_file_path = file_path).convert("xyz", gen3D = False)
31
+
32
+ same = Openprattle_converter(input_file_path = file_path).convert("xyz", gen3D = False)
33
+ different = Openprattle_converter(input_file_path = file_path).convert("xyz", gen3D = True)
34
+
35
+ assert first == same
36
+ assert first != different