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,115 @@
1
+ # General imports.
2
+ from PIL import Image
3
+ from io import BytesIO
4
+
5
+ import rdkit.RDLogger
6
+ from rdkit.Chem.Draw import rdMolDraw2D
7
+
8
+ # Digichem imports.
9
+ from digichem.image.base import Image_maker
10
+
11
+
12
+ class Skeletal_image_maker(Image_maker):
13
+ """
14
+ A class for rendering skeletal-style molecule structure images.
15
+ """
16
+
17
+ def __init__(self, output, atoms, *args, abs_resolution = None, rel_resolution = 100, numbering = "group", numbering_font_size = 0.7, explicit_h = False, **kwargs):
18
+ """
19
+ Constructor for Structure_image_maker objects.
20
+
21
+ :param output: A path to an output file to write to. The extension of this path is used to determine the format of the file (eg: png, jpeg).
22
+ :param atoms: A list of atom of the molecule/system to render.
23
+ :param resolution: The width and height of the rendered image.
24
+ :param render_backend: The library to prefer to use for rendering, possible options are 'rdkit' or 'obabel'. If 'rdkit' is chosen but is not available, obabel will be used as a fallback.
25
+ :param numbering: Whether to show atom numberings, either False (off), "atomic" (for atom wise) or "group" (for group wise).
26
+ :param explicit_h: Whether to show explicit H.
27
+ """
28
+ self.atoms = atoms
29
+ self.abs_resolution = abs_resolution
30
+ self.rel_resolution = rel_resolution
31
+ self.numbering = numbering
32
+ self.numbering_font_size = numbering_font_size
33
+ self.explicit_h = explicit_h
34
+ super().__init__(output, *args, **kwargs)
35
+
36
+ @classmethod
37
+ def from_options(self, output, *, atoms, options, **kwargs):
38
+ """
39
+ Constructor that takes a dictionary of config like options.
40
+ """
41
+ return self(
42
+ output,
43
+ atoms = atoms,
44
+ abs_resolution = options['skeletal_image']['resolution']['absolute'],
45
+ rel_resolution = options['skeletal_image']['resolution']['relative'],
46
+ #render_backend = options['skeletal_image']['render_backend'],
47
+ **kwargs
48
+ )
49
+
50
+ def make_files(self):
51
+ """
52
+ Make the image described by this object.
53
+ """
54
+ if self.abs_resolution:
55
+ resolution = self.abs_resolution
56
+
57
+ else:
58
+ resolution = int(self.rel_resolution * self.atoms.X_length)
59
+
60
+ molecule = self.atoms.to_rdkit_molecule()
61
+
62
+ # Calculate atom groupings.
63
+ atom_groups = self.atoms.groups
64
+
65
+ for atom in molecule.GetAtoms():
66
+
67
+ group = [group for group in atom_groups.values() if atom.GetIdx() +1 in [atom.index for atom in group.atoms]][0]
68
+
69
+ if self.numbering == "both":
70
+ # Add atom labelling.
71
+ #atom.SetProp("molAtomMapNumber", str(atom.GetIdx()+1))
72
+ atom.SetProp("atomNote", "{} ({})".format(group.id[0], atom.GetIdx()+1))
73
+
74
+ elif self.numbering == "atomic":
75
+ atom.SetProp("atomNote", "{}".format(atom.GetIdx()+1))
76
+
77
+ elif self.numbering == "group":
78
+ atom.SetProp("atomNote", "{}".format(group.id[0]))
79
+
80
+ # Remove C-H, if we've been asked to.
81
+ if not self.explicit_h:
82
+ edit_mol = rdkit.Chem.EditableMol(molecule)
83
+ atoms = list(edit_mol.GetMol().GetAtoms())
84
+ for atom_index, atom in enumerate(reversed(atoms)):
85
+ # If this atom is a hydrogen, and it has a single bond to a carbon, delete it.
86
+ if atom.GetSymbol() == "H":
87
+ bonds = list(atom.GetBonds())
88
+ if len(bonds) == 1 and bonds[0].GetOtherAtom(atom).GetSymbol() == "C":
89
+ # This is an implicit H.
90
+ edit_mol.RemoveAtom(atom.GetIdx())
91
+
92
+ molecule = edit_mol.GetMol()
93
+
94
+ # Different libraries for generating 2D depictions.
95
+ # Coordgen is supposedly superior.
96
+ #rdkit.Chem.AllChem.Compute2DCoords(molecule)
97
+
98
+ ps = rdkit.Chem.rdCoordGen.CoordGenParams()
99
+ ps.minimizerPrecision = ps.sketcherBestPrecision
100
+ rdkit.Chem.rdCoordGen.AddCoords(molecule, ps)
101
+ rdkit.Chem.rdDepictor.NormalizeDepiction(molecule)
102
+
103
+ # Then write the file, setting any options we need to.
104
+ d = rdMolDraw2D.MolDraw2DCairo(resolution, resolution)
105
+ d.drawOptions().annotationFontScale = self.numbering_font_size
106
+ d.DrawMolecule(molecule)
107
+ d.FinishDrawing()
108
+ # To save directly, but we're going to open in PIL to crop.
109
+ #d.WriteDrawingText(str(self.output))
110
+
111
+ # Crop it to remove whitespace.
112
+ with Image.open(BytesIO(d.GetDrawingText()), "r") as im:
113
+ cropped_image = self.auto_crop_image(im)
114
+
115
+ cropped_image.save(self.output)