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,70 @@
1
+ # This script expects 9 arguments, which are:
2
+ # HOMO_cube_file A .cube file to load molecular data from.
3
+ set HOMO_cube_file [lindex $argv 0]
4
+ # LUMO_cube_file A .cube file to load molecular data from.
5
+ set LUMO_cube_file [lindex $argv 1]
6
+ # tcl_common Path to our common library to source.
7
+ set tcl_common [lindex $argv 2]
8
+ # A string describing the rendering style to use; 'silico' or 'gaussian'.
9
+ set rendering_style [lindex $argv 3]
10
+ # The isovalue to use.
11
+ set isovalue [lindex $argv 4]
12
+ # A string of x,y,z translations to perform.
13
+ set translations [lindex $argv 5]
14
+ # rotations A string list of rotations to perform.
15
+ set rotations [lindex $argv 6]
16
+ # x0y0z0 A file name to write one of the output images to (in png format).
17
+ set x0y0z0 [lindex $argv 7]
18
+ # x90y0z0 A file name to write one of the output images to (in png format).
19
+ set x90y0z0 [lindex $argv 8]
20
+ # x0y90z0 A file name to write one of the output images to (in png format).
21
+ set x0y90z0 [lindex $argv 9]
22
+ # x45y45z45 A file name to write one of the output images to (in png format).
23
+ set x45y45z45 [lindex $argv 10]
24
+
25
+ # Load our common library.
26
+ source $tcl_common
27
+
28
+ # Set our visual style
29
+ use_style $rendering_style
30
+
31
+ # Load our molecule structure and keep track of its numerical handle.
32
+ set HOMO_mol_handle [molecule new $HOMO_cube_file]
33
+
34
+ # Rotate it as we've been told.
35
+ #rotate_molecule $HOMO_mol_handle $translations $rotations
36
+
37
+ # Use standard display settings.
38
+ standard_molecule_style 0 $HOMO_mol_handle
39
+
40
+ # Display our obital (both positive and negative phases).
41
+ set HOMO_pos_orbital 1
42
+ molecule addrep $HOMO_mol_handle
43
+ standard_orbital_style $HOMO_pos_orbital $HOMO_mol_handle 0 $isovalue
44
+
45
+ set HOMO_neg_orbital 2
46
+ molecule addrep $HOMO_mol_handle
47
+ standard_orbital_style $HOMO_neg_orbital $HOMO_mol_handle 0 -$isovalue
48
+
49
+
50
+ # Also draw our LUMO.
51
+ # Load our molecule structure and keep track of its numerical handle.
52
+ set LUMO_mol_handle [molecule new $LUMO_cube_file]
53
+
54
+ # Rotate this one too
55
+ #rotate_molecule $LUMO_mol_handle $translations $rotations
56
+
57
+ # We don't need to show our skeleton again, so we can just reuse the default representation.
58
+ # Display our obital (both positive and negative phases).
59
+ set LUMO_pos_orbital 0
60
+ standard_orbital_style $LUMO_pos_orbital $LUMO_mol_handle 1 $isovalue
61
+
62
+ set LUMO_neg_orbital 1
63
+ molecule addrep $LUMO_mol_handle
64
+ standard_orbital_style $LUMO_neg_orbital $LUMO_mol_handle 1 -$isovalue
65
+
66
+ # And save our pictures.
67
+ render_images $rotations $x0y0z0 $x90y0z0 $x0y90z0 $x45y45z45
68
+
69
+ # All done.
70
+ exit
@@ -0,0 +1,45 @@
1
+ # This script expects 11 arguments, which are:
2
+ # cube_file A .cube file to load molecular data from.
3
+ set cube_file [lindex $argv 0]
4
+ # tcl_common Path to our common library to source.
5
+ set tcl_common [lindex $argv 1]
6
+ # A string describing the rendering style to use; 'silico' or 'gaussian'.
7
+ set rendering_style [lindex $argv 2]
8
+ # The isovalue to use.
9
+ set isovalue [lindex $argv 3]
10
+ # A string of x,y,z translations to perform.
11
+ set translations [lindex $argv 4]
12
+ # rotations A string list of rotations to perform.
13
+ set rotations [lindex $argv 5]
14
+ # x0y0z0 A file name to write one of the output images to (in png format).
15
+ set x0y0z0 [lindex $argv 6]
16
+ # x90y0z0 A file name to write one of the output images to (in png format).
17
+ set x90y0z0 [lindex $argv 7]
18
+ # x0y90z0 A file name to write one of the output images to (in png format).
19
+ set x0y90z0 [lindex $argv 8]
20
+ # x45y45z45 A file name to write one of the output images to (in png format).
21
+ set x45y45z45 [lindex $argv 9]
22
+
23
+ # Load our common library.
24
+ source $tcl_common
25
+
26
+ # Set our visual style
27
+ use_style $rendering_style
28
+
29
+ # Load our molecule and keep track of its numerical handle.
30
+ set mol_handle [molecule new $cube_file]
31
+
32
+ # Use standard display settings.
33
+ standard_molecule_style 0 $mol_handle
34
+
35
+ # Display our spin density (depending on the spin_type we've been asked for).
36
+ # In comparison to orbital density, we use a much smaller iso-value (bigger visible density).
37
+ set pos_orbital 1
38
+ molecule addrep $mol_handle
39
+ standard_orbital_style $pos_orbital $mol_handle 0 $isovalue
40
+
41
+ # And save our pictures.
42
+ render_images $rotations $x0y0z0 $x90y0z0 $x0y90z0 $x45y45z45
43
+
44
+ # All done.
45
+ exit
@@ -0,0 +1,68 @@
1
+ # This script expects 9 arguments, which are:
2
+ # cube_file A .cube file to load molecular data from.
3
+ set cube_file [lindex $argv 0]
4
+ # tcl_common Path to our common library to source.
5
+ set tcl_common [lindex $argv 1]
6
+ # A string describing the rendering style to use; 'silico' or 'gaussian'.
7
+ set rendering_style [lindex $argv 2]
8
+ # A string of x,y,z translations to perform.
9
+ set translations [lindex $argv 3]
10
+ # rotations A string list of rotations to perform.
11
+ set rotations [lindex $argv 4]
12
+ # dipole_start {x y z} coordinates of the start of the dipole.
13
+ set dipole1_start [lindex $argv 5]
14
+ # dipole_end {x y z} coordinates of the end of the dipole.
15
+ set dipole1_end [lindex $argv 6]
16
+ # dipole_start {x y z} coordinates of the start of the dipole.
17
+ set dipole2_start [lindex $argv 7]
18
+ # dipole_end {x y z} coordinates of the end of the dipole.
19
+ set dipole2_end [lindex $argv 8]
20
+ # x0y0z0 A file name to write one of the output images to (in png format).
21
+ set x0y0z0 [lindex $argv 9]
22
+ # x90y0z0 A file name to write one of the output images to (in png format).
23
+ set x90y0z0 [lindex $argv 10]
24
+ # x0y90z0 A file name to write one of the output images to (in png format).
25
+ set x0y90z0 [lindex $argv 11]
26
+ # x45y45z45 A file name to write one of the output images to (in png format).
27
+ set x45y45z45 [lindex $argv 12]
28
+
29
+ # Load our common library.
30
+ source $tcl_common
31
+
32
+ # Set our visual style
33
+ use_style $rendering_style
34
+
35
+ # Load our molecule and keep track of its numerical handle.
36
+ set mol_handle [molecule new $cube_file]
37
+
38
+ # Rotate as we've been told.
39
+ #rotate_molecule $mol_handle $translations $rotations
40
+
41
+ # Make our molecule transparent so we can better see our dipole arrow.
42
+ material change Opacity Transparent 0.5
43
+ molecule modmaterial 0 $mol_handle Transparent
44
+
45
+ # Use standard display settings.
46
+ standard_molecule_style 0 $mol_handle
47
+
48
+ set dipole1_start [split $dipole1_start ":"]
49
+ set dipole1_end [split $dipole1_end ":"]
50
+ set dipole2_start [split $dipole2_start ":"]
51
+ set dipole2_end [split $dipole2_end ":"]
52
+
53
+ # Draw our dipole moment.
54
+ # Only add them if they are not zero.
55
+ if {[lindex $dipole1_end 0] != 0 || [lindex $dipole1_end 1] != 0 || [lindex $dipole1_end 2] != 0} {
56
+ draw color red
57
+ draw arrow $dipole1_start $dipole1_end
58
+ }
59
+ if {[lindex $dipole2_end 0] != 0 || [lindex $dipole2_end 1] != 0 || [lindex $dipole2_end 2] != 0} {
60
+ draw color green
61
+ draw arrow $dipole2_start $dipole2_end
62
+ }
63
+
64
+ # And save our pictures.
65
+ render_images $rotations $x0y0z0 $x90y0z0 $x0y90z0 $x45y45z45
66
+
67
+ # All done.
68
+ exit
@@ -0,0 +1,57 @@
1
+ # This script expects 8 arguments, which are:
2
+ # cube_file A .cube file to load molecular data from.
3
+ set cube_file [lindex $argv 0]
4
+ # tcl_common Path to our common library to source.
5
+ set tcl_common [lindex $argv 1]
6
+ # A string describing the rendering style to use; 'silico' or 'gaussian'.
7
+ set rendering_style [lindex $argv 2]
8
+ # The isovalue to use.
9
+ set isovalue [lindex $argv 3]
10
+ # A string of x,y,z translations to perform.
11
+ set translations [lindex $argv 4]
12
+ # rotations A string list of rotations to perform.
13
+ set rotations [lindex $argv 5]
14
+ # x0y0z0 A file name to write one of the output images to (in png format).
15
+ set x0y0z0 [lindex $argv 6]
16
+ # x90y0z0 A file name to write one of the output images to (in png format).
17
+ set x90y0z0 [lindex $argv 7]
18
+ # x0y90z0 A file name to write one of the output images to (in png format).
19
+ set x0y90z0 [lindex $argv 8]
20
+ # x45y45z45 A file name to write one of the output images to (in png format).
21
+ set x45y45z45 [lindex $argv 9]
22
+
23
+ # Load our common library.
24
+ source $tcl_common
25
+
26
+ # Set our visual style
27
+ use_style $rendering_style
28
+
29
+ # Load our molecule and keep track of its numerical handle.
30
+ set mol_handle [molecule new $cube_file]
31
+
32
+ # Rotate as we've been told.
33
+ #rotate_molecule $mol_handle $translations $rotations
34
+
35
+ # Use standard display settings.
36
+ standard_molecule_style 0 $mol_handle
37
+
38
+ # Display our obital (both positive and negative phases).
39
+ set pos_orbital 1
40
+ molecule addrep $mol_handle
41
+ standard_orbital_style $pos_orbital $mol_handle 0 $isovalue
42
+ #molecule modstyle $pos_orbital $mol_handle isosurface 0.02 0 0 0 1 1
43
+ #molecule modcolor $pos_orbital $mol_handle ColorID 1
44
+ #molecule modmaterial $pos_orbital $mol_handle Translucent
45
+
46
+ set neg_orbital 2
47
+ molecule addrep $mol_handle
48
+ standard_orbital_style $neg_orbital $mol_handle 1 -$isovalue
49
+ #molecule modstyle $neg_orbital $mol_handle isosurface -0.02 0 0 0 1 1
50
+ #molecule modcolor $neg_orbital $mol_handle ColorID 0
51
+ #molecule modmaterial $neg_orbital $mol_handle Translucent
52
+
53
+ # And save our pictures.
54
+ render_images $rotations $x0y0z0 $x90y0z0 $x0y90z0 $x45y45z45
55
+
56
+ # All done.
57
+ exit
@@ -0,0 +1,66 @@
1
+ # This script expects 11 arguments, which are:
2
+ # cube_file A .cube file to load molecular data from.
3
+ set cube_file [lindex $argv 0]
4
+ # tcl_common Path to our common library to source.
5
+ set tcl_common [lindex $argv 1]
6
+ # A string describing the rendering style to use; 'silico' or 'gaussian'.
7
+ set rendering_style [lindex $argv 2]
8
+ # The isovalue to use.
9
+ set isovalue [lindex $argv 3]
10
+ # The spin type to render (positive, negative or both).
11
+ set spin_type [lindex $argv 4]
12
+ # A string of x,y,z translations to perform.
13
+ set translations [lindex $argv 5]
14
+ # rotations A string list of rotations to perform.
15
+ set rotations [lindex $argv 6]
16
+ # x0y0z0 A file name to write one of the output images to (in png format).
17
+ set x0y0z0 [lindex $argv 7]
18
+ # x90y0z0 A file name to write one of the output images to (in png format).
19
+ set x90y0z0 [lindex $argv 8]
20
+ # x0y90z0 A file name to write one of the output images to (in png format).
21
+ set x0y90z0 [lindex $argv 9]
22
+ # x45y45z45 A file name to write one of the output images to (in png format).
23
+ set x45y45z45 [lindex $argv 10]
24
+
25
+ # Load our common library.
26
+ source $tcl_common
27
+
28
+ # Set our visual style
29
+ use_style $rendering_style
30
+
31
+ # Load our molecule and keep track of its numerical handle.
32
+ set mol_handle [molecule new $cube_file]
33
+
34
+ # Rotate as we've been told.
35
+ #rotate_molecule $mol_handle $translations $rotations
36
+
37
+ # Use standard display settings.
38
+ standard_molecule_style 0 $mol_handle
39
+
40
+ # Display our spin density (depending on the spin_type we've been asked for).
41
+ # In comparison to orbital density, we use a much smaller iso-value (bigger visible density).
42
+ if {$spin_type == "positive" || $spin_type == "both"} {
43
+ set pos_orbital 1
44
+ set neg_orbital 2
45
+ molecule addrep $mol_handle
46
+ standard_orbital_style $pos_orbital $mol_handle 0 $isovalue
47
+ #molecule modstyle $pos_orbital $mol_handle isosurface 0.02 0 0 0 1 1
48
+ #molecule modcolor $pos_orbital $mol_handle ColorID 1
49
+ #molecule modmaterial $pos_orbital $mol_handle Translucent
50
+ } else {
51
+ set neg_orbital 1
52
+ }
53
+
54
+ if {$spin_type == "negative" || $spin_type == "both"} {
55
+ molecule addrep $mol_handle
56
+ standard_orbital_style $neg_orbital $mol_handle 1 -$isovalue
57
+ #molecule modstyle $neg_orbital $mol_handle isosurface -0.02 0 0 0 1 1
58
+ #molecule modcolor $neg_orbital $mol_handle ColorID 0
59
+ #molecule modmaterial $neg_orbital $mol_handle Translucent
60
+ }
61
+
62
+ # And save our pictures.
63
+ render_images $rotations $x0y0z0 $x90y0z0 $x0y90z0 $x45y45z45
64
+
65
+ # All done.
66
+ exit
@@ -0,0 +1,40 @@
1
+ # This script expects 9 arguments, which are:
2
+ # cube_file A .cube file to load molecular data from.
3
+ set cube_file [lindex $argv 0]
4
+ # tcl_common Path to our common library to source.
5
+ set tcl_common [lindex $argv 1]
6
+ # A string describing the rendering style to use; 'silico' or 'gaussian'.
7
+ set rendering_style [lindex $argv 2]
8
+ # A string of x,y,z translations to perform.
9
+ set translations [lindex $argv 3]
10
+ # rotations A string list of rotations to perform.
11
+ set rotations [lindex $argv 4]
12
+ # x0y0z0 A file name to write one of the output images to (in png format).
13
+ set x0y0z0 [lindex $argv 5]
14
+ # x90y0z0 A file name to write one of the output images to (in png format).
15
+ set x90y0z0 [lindex $argv 6]
16
+ # x0y90z0 A file name to write one of the output images to (in png format).
17
+ set x0y90z0 [lindex $argv 7]
18
+ # x45y45z45 A file name to write one of the output images to (in png format).
19
+ set x45y45z45 [lindex $argv 8]
20
+
21
+ # Load our common library.
22
+ source $tcl_common
23
+
24
+ # Set our visual style
25
+ use_style $rendering_style
26
+
27
+ # Load our molecule and keep track of its numerical handle.
28
+ set mol_handle [molecule new $cube_file]
29
+
30
+ # Rotate as we've been told.
31
+ #rotate_molecule $mol_handle $translations $rotations
32
+
33
+ # Use standard display settings.
34
+ standard_molecule_style 0 $mol_handle
35
+
36
+ # And save our pictures.
37
+ render_images $rotations $x0y0z0 $x90y0z0 $x0y90z0 $x45y45z45
38
+
39
+ # All done.
40
+ exit
digichem/datas.py ADDED
@@ -0,0 +1,14 @@
1
+ import atexit
2
+ from contextlib import ExitStack
3
+
4
+ # TODO: Can switch to non-backport importlib.resources once >= 3.9
5
+ import importlib_resources
6
+
7
+ def get_resource(name):
8
+ """
9
+ Get a pathlib path object to a package resource.
10
+ """
11
+ file_manager = ExitStack()
12
+ atexit.register(file_manager.close)
13
+ ref = importlib_resources.files('digichem') / name
14
+ return file_manager.enter_context(importlib_resources.as_file(ref))
@@ -0,0 +1,7 @@
1
+ # Import top-level object for easier access.
2
+ from .base import Digichem_exception
3
+ from .base import Result_unavailable_error
4
+ from .base import File_maker_exception
5
+ from .base import Unknown_file_type_exception
6
+ from .base import Submission_error
7
+ from .base import Format_error
@@ -0,0 +1,133 @@
1
+ # Exceptions and other errors.
2
+
3
+ class Digichem_exception(Exception):
4
+ """
5
+ General digichem exception.
6
+ """
7
+
8
+ def __init__(self, message):
9
+ self.message = message
10
+
11
+ def __str__(self, *args, **kwargs):
12
+ return self.message
13
+
14
+
15
+ class Result_unavailable_error(Digichem_exception):
16
+ """
17
+ Exception for when a requested result is not available (because it could not be found in the calculation results for example).
18
+ """
19
+
20
+ def __init__(self, result_name, reason = "result could not be found"):
21
+ """
22
+ Constructor for Result_unavailable_error objects.
23
+
24
+ :param result_name: The name of the result that is unavailable.
25
+ :param reason: Optional message explaining why the result is unavailable. If not given, a default message will be used.
26
+ """
27
+ self.result_name = result_name
28
+ self.reason = reason
29
+
30
+ def __str__(self, *args, **kwargs):
31
+ """
32
+ Stringify this error.
33
+ """
34
+ return "'{}' is not available; {}".format(self.result_name, self.reason)
35
+
36
+ class File_maker_exception(Digichem_exception):
37
+ """
38
+ Exception for when a file cannot be made/rendered for whatever reason.
39
+ """
40
+
41
+ def __init__(self, file_maker, reason = ""):
42
+ """
43
+ Constructor for File_maker_exception objects.
44
+
45
+ :param file_maker: The file_maker object where the exception occurred.
46
+ :param reason: Optional string describing why the exception occurred.
47
+ """
48
+ self.file_maker = file_maker
49
+ self.reason = reason
50
+
51
+ def __str__(self, *args, **kwargs):
52
+ """
53
+ Stringify this error.
54
+ """
55
+ return "Error making '{}' file '{}'; {}".format(type(self.file_maker).__name__, self.file_maker.output, self.reason)
56
+
57
+ class Unknown_file_type_exception(Digichem_exception):
58
+ """
59
+ Exception for when a file is given but its type cannot be determined.
60
+ """
61
+
62
+ def __init__(self, file_path, expected = None):
63
+ """
64
+ Constructor for Unknown_file_type_exception objects.
65
+
66
+ :param file_path: String-like path of the file that is unrecognised.
67
+ :param expected: An optional string-like representing the type of file that was expected.
68
+ """
69
+ self.file_path = file_path
70
+ self.expected = expected
71
+
72
+ def __str__(self, *args, **kwargs):
73
+ """
74
+ Stringify this error.
75
+ """
76
+ err_str = "Unknown file type '{}'".format(self.file_path)
77
+ if self.expected is not None:
78
+ err_str = "{}; expected file of type '{}'".format(err_str, self.expected)
79
+ return err_str
80
+
81
+ class Submission_error(Digichem_exception):
82
+ """
83
+ Exceptions for when an error occurs during calculation submission.
84
+ """
85
+
86
+ def __init__(self, calculation, reason, file_name = None):
87
+ """
88
+ Constructor for Submission_error exception objects.
89
+
90
+ :param calculation: The calculation that was in process of being submitted when the error occurred. This can be any one of a Method_target, Program_target or Calculation_target.
91
+ :param reason: String describing why the error occurred.
92
+ """
93
+ # Do some quick type checking.
94
+ if calculation.meta['TYPE'] == "destination":
95
+ # 'Calculation' is actually a Method_target.
96
+ calculation = calculation.program.calculation
97
+ elif calculation.meta['TYPE'] == "program":
98
+ # 'Calculation' is actually a Program_target.
99
+ calculation = calculation.calculation
100
+
101
+ # Decide on file name.
102
+ if file_name is None:
103
+ file_name = calculation.molecule_name
104
+ self.file_name = file_name
105
+
106
+ self.calculation = calculation
107
+ self.reason = reason
108
+
109
+ def __str__(self, *args, **kwargs):
110
+ """
111
+ Stringify this error.
112
+ """
113
+ return "Error submitting file '{}' to '{}'; {}".format(self.file_name, self.calculation.meta['name'], self.reason)
114
+
115
+
116
+ class Format_error(Digichem_exception):
117
+ """
118
+ Exceptions for when an error occurs during result formatting.
119
+ """
120
+
121
+ def __init__(self, format, reason):
122
+ """
123
+ Constructor for Format_error exception objects.
124
+ """
125
+ self.format = format
126
+ self.reason = reason
127
+
128
+ def __str__(self):
129
+ """
130
+ Stringify this error.
131
+ """
132
+ return "{} ({}); {}".format(type(self.format).__name__, ", ".join(getattr(self.format, 'CLASS_HANDLE', [])), self.reason)
133
+
@@ -0,0 +1,63 @@
1
+ import signal
2
+
3
+ class Uncatchable_exception(BaseException):
4
+ """
5
+ Superclass for exceptions that are not normally caught.
6
+
7
+ Note that no attempt is made to stop you catching these exceptions if you want, but they will not be caught by 'except Exception' clauses.
8
+ """
9
+
10
+ class Submission_paused(Uncatchable_exception):
11
+ """
12
+ Exception raised during some submission routines.
13
+
14
+ This exception signals the program that nothing further is to be done from this process; submission will continue in a second process (possible on a different machine on a different planet).
15
+
16
+ You do not normally want to catch this exception; it is raised during the normal submission process.
17
+ """
18
+
19
+ class Signal_caught(Uncatchable_exception):
20
+ """
21
+ Exception raised when a kill-type signal is sent and caught by the process.
22
+
23
+ Similarly to KeyboardInterrupt; this exception is not normally caught (so that we exit NOW, this is important because some methods (SLURM, for example) time how long it takes us to shut down, and will send SIGKILL if we're too slow (which is uncatchable by design).
24
+ However, it is valid (and expected) that vital cleanup handlers catch this exception, so long as they re-raise it once done.
25
+ """
26
+
27
+ def __init__(self, signalnum, stack_frame):
28
+ """
29
+ Constructor for Signal_caught exceptions.
30
+
31
+ :param signalnum: The signal that was raised.
32
+ :param stackframe: The current stack frame where the signal was caught (can be None).
33
+ """
34
+ self.signalnum = signalnum
35
+ self.stack_frame = stack_frame
36
+
37
+ @property
38
+ def signal_name(self):
39
+ """
40
+ Get the string name (SIGINT etc) of the signal we caught.
41
+ """
42
+ return self.signal_to_name(self.signalnum)
43
+
44
+ @classmethod
45
+ def signal_to_name(self, signalnum):
46
+ """
47
+ Convert a singal number to a string (unrecognised signals will return "???"
48
+ """
49
+ try:
50
+ return signal.Signals(signalnum).name
51
+ except Exception:
52
+ return "???"
53
+
54
+ def __str__(self, *args, **kwargs):
55
+ return "Received signal {} ({})".format(self.signalnum, self.signal_name)
56
+
57
+
58
+ @classmethod
59
+ def raise_from_signal(self, signalnum, stack_frame):
60
+ """
61
+ Method designed to be called by a signal handler; automatically raises a Signal_caught exception.
62
+ """
63
+ raise self(signalnum, stack_frame)
@@ -0,0 +1 @@
1
+ from .base import File_maker, File_converter, Dummy_file_maker