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.
- digichem/__init__.py +75 -0
- digichem/basis.py +116 -0
- digichem/config/README +3 -0
- digichem/config/__init__.py +5 -0
- digichem/config/base.py +321 -0
- digichem/config/locations.py +14 -0
- digichem/config/parse.py +90 -0
- digichem/config/util.py +117 -0
- digichem/data/README +4 -0
- digichem/data/batoms/COPYING +18 -0
- digichem/data/batoms/LICENSE +674 -0
- digichem/data/batoms/README +2 -0
- digichem/data/batoms/__init__.py +0 -0
- digichem/data/batoms/batoms-renderer.py +351 -0
- digichem/data/config/digichem.yaml +714 -0
- digichem/data/functionals.csv +15 -0
- digichem/data/solvents.csv +185 -0
- digichem/data/tachyon/COPYING.md +5 -0
- digichem/data/tachyon/LICENSE +30 -0
- digichem/data/tachyon/tachyon_LINUXAMD64 +0 -0
- digichem/data/vmd/common.tcl +468 -0
- digichem/data/vmd/generate_combined_orbital_images.tcl +70 -0
- digichem/data/vmd/generate_density_images.tcl +45 -0
- digichem/data/vmd/generate_dipole_images.tcl +68 -0
- digichem/data/vmd/generate_orbital_images.tcl +57 -0
- digichem/data/vmd/generate_spin_images.tcl +66 -0
- digichem/data/vmd/generate_structure_images.tcl +40 -0
- digichem/datas.py +14 -0
- digichem/exception/__init__.py +7 -0
- digichem/exception/base.py +133 -0
- digichem/exception/uncatchable.py +63 -0
- digichem/file/__init__.py +1 -0
- digichem/file/base.py +364 -0
- digichem/file/cube.py +284 -0
- digichem/file/fchk.py +94 -0
- digichem/file/prattle.py +277 -0
- digichem/file/types.py +97 -0
- digichem/image/__init__.py +6 -0
- digichem/image/base.py +113 -0
- digichem/image/excited_states.py +335 -0
- digichem/image/graph.py +293 -0
- digichem/image/orbitals.py +239 -0
- digichem/image/render.py +617 -0
- digichem/image/spectroscopy.py +797 -0
- digichem/image/structure.py +115 -0
- digichem/image/vmd.py +826 -0
- digichem/input/__init__.py +3 -0
- digichem/input/base.py +78 -0
- digichem/input/digichem_input.py +500 -0
- digichem/input/gaussian.py +140 -0
- digichem/log.py +179 -0
- digichem/memory.py +166 -0
- digichem/misc/__init__.py +4 -0
- digichem/misc/argparse.py +44 -0
- digichem/misc/base.py +61 -0
- digichem/misc/io.py +239 -0
- digichem/misc/layered_dict.py +285 -0
- digichem/misc/text.py +139 -0
- digichem/misc/time.py +73 -0
- digichem/parse/__init__.py +13 -0
- digichem/parse/base.py +220 -0
- digichem/parse/cclib.py +138 -0
- digichem/parse/dump.py +253 -0
- digichem/parse/gaussian.py +130 -0
- digichem/parse/orca.py +96 -0
- digichem/parse/turbomole.py +201 -0
- digichem/parse/util.py +523 -0
- digichem/result/__init__.py +6 -0
- digichem/result/alignment/AA.py +114 -0
- digichem/result/alignment/AAA.py +61 -0
- digichem/result/alignment/FAP.py +148 -0
- digichem/result/alignment/__init__.py +3 -0
- digichem/result/alignment/base.py +310 -0
- digichem/result/angle.py +153 -0
- digichem/result/atom.py +742 -0
- digichem/result/base.py +258 -0
- digichem/result/dipole_moment.py +332 -0
- digichem/result/emission.py +402 -0
- digichem/result/energy.py +323 -0
- digichem/result/excited_state.py +821 -0
- digichem/result/ground_state.py +94 -0
- digichem/result/metadata.py +644 -0
- digichem/result/multi.py +98 -0
- digichem/result/nmr.py +1086 -0
- digichem/result/orbital.py +647 -0
- digichem/result/result.py +244 -0
- digichem/result/soc.py +272 -0
- digichem/result/spectroscopy.py +514 -0
- digichem/result/tdm.py +267 -0
- digichem/result/vibration.py +167 -0
- digichem/test/__init__.py +6 -0
- digichem/test/conftest.py +4 -0
- digichem/test/test_basis.py +71 -0
- digichem/test/test_calculate.py +30 -0
- digichem/test/test_config.py +78 -0
- digichem/test/test_cube.py +369 -0
- digichem/test/test_exception.py +16 -0
- digichem/test/test_file.py +104 -0
- digichem/test/test_image.py +337 -0
- digichem/test/test_input.py +64 -0
- digichem/test/test_parsing.py +79 -0
- digichem/test/test_prattle.py +36 -0
- digichem/test/test_result.py +489 -0
- digichem/test/test_translate.py +112 -0
- digichem/test/util.py +207 -0
- digichem/translate.py +591 -0
- digichem_core-6.0.0rc1.dist-info/METADATA +96 -0
- digichem_core-6.0.0rc1.dist-info/RECORD +111 -0
- digichem_core-6.0.0rc1.dist-info/WHEEL +4 -0
- digichem_core-6.0.0rc1.dist-info/licenses/COPYING.md +10 -0
- 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)
|