training-structures-step 2026.11.25__py2.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.
- training_structures_step/__init__.py +26 -0
- training_structures_step/_version.py +21 -0
- training_structures_step/data/properties.csv +11 -0
- training_structures_step/data/references.bib +40 -0
- training_structures_step/generate.py +338 -0
- training_structures_step/metadata.py +189 -0
- training_structures_step/substep.py +99 -0
- training_structures_step/tk_training_structures.py +263 -0
- training_structures_step/training_structures.py +709 -0
- training_structures_step/training_structures_parameters.py +343 -0
- training_structures_step/training_structures_step.py +101 -0
- training_structures_step-2026.11.25.dist-info/METADATA +124 -0
- training_structures_step-2026.11.25.dist-info/RECORD +19 -0
- training_structures_step-2026.11.25.dist-info/WHEEL +6 -0
- training_structures_step-2026.11.25.dist-info/entry_points.txt +5 -0
- training_structures_step-2026.11.25.dist-info/licenses/AUTHORS.rst +5 -0
- training_structures_step-2026.11.25.dist-info/licenses/LICENSE +31 -0
- training_structures_step-2026.11.25.dist-info/top_level.txt +1 -0
- training_structures_step-2026.11.25.dist-info/zip-safe +1 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
training_structures_step
|
|
5
|
+
A SEAMM plug-in for Training Structures
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
# Bring up the classes so that they appear to be directly in
|
|
9
|
+
# the training_structures_step package.
|
|
10
|
+
|
|
11
|
+
from .training_structures import TrainingStructures # noqa: F401, E501
|
|
12
|
+
from .training_structures_parameters import TrainingStructuresParameters # noqa: F401
|
|
13
|
+
from .training_structures_step import TrainingStructuresStep # noqa: F401, E501
|
|
14
|
+
from .tk_training_structures import TkTrainingStructures # noqa: F401, E501
|
|
15
|
+
|
|
16
|
+
from .metadata import metadata # noqa: F401
|
|
17
|
+
|
|
18
|
+
# Handle versioneer
|
|
19
|
+
from ._version import get_versions
|
|
20
|
+
|
|
21
|
+
__author__ = "Paul Saxe"
|
|
22
|
+
__email__ = "psaxe@molssi.org"
|
|
23
|
+
versions = get_versions()
|
|
24
|
+
__version__ = versions["version"]
|
|
25
|
+
__git_revision__ = versions["full-revisionid"]
|
|
26
|
+
del get_versions, versions
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
# This file was generated by 'versioneer.py' (0.18) from
|
|
3
|
+
# revision-control system data, or from the parent directory name of an
|
|
4
|
+
# unpacked source archive. Distribution tarballs contain a pre-generated copy
|
|
5
|
+
# of this file.
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
version_json = '''
|
|
10
|
+
{
|
|
11
|
+
"date": "2026-11-25T16:35:50-0500",
|
|
12
|
+
"dirty": false,
|
|
13
|
+
"error": null,
|
|
14
|
+
"full-revisionid": "bcf0dcd29f557e68bdab414d33a5a2ca09215dc6",
|
|
15
|
+
"version": "2026.11.25"
|
|
16
|
+
}
|
|
17
|
+
''' # END VERSION_JSON
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_versions():
|
|
21
|
+
return json.loads(version_json)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Property,Type,Units,Description,URL
|
|
2
|
+
point type#TrainingStructures#generation,str,,"How this training structure was made: minimum, sample, scan, stretch or grid.",
|
|
3
|
+
target energy#TrainingStructures#generation,float,kJ/mol,"The harmonic energy above the minimum that this normal-mode sample was scaled to.",
|
|
4
|
+
harmonic energy#TrainingStructures#generation,float,kJ/mol,"The harmonic energy of this structure above the minimum, from the Hessian.",
|
|
5
|
+
prescreen energy#TrainingStructures#generation,float,kJ/mol,"The energy of this structure above the minimum at the generator level (the pre-screen).",
|
|
6
|
+
scan rotor#TrainingStructures#generation,json,,"The four atoms (1-based) of the dihedral scanned for this structure.",
|
|
7
|
+
scan angle#TrainingStructures#generation,float,degree,"The change of the scanned dihedral from the minimum.",
|
|
8
|
+
bond class#TrainingStructures#generation,str,,"The element pair of the bond stretched for this structure.",
|
|
9
|
+
bond#TrainingStructures#generation,json,,"The two atoms (1-based) of the bond stretched for this structure.",
|
|
10
|
+
bond change#TrainingStructures#generation,float,Å,"The change of the stretched bond's length from the minimum.",
|
|
11
|
+
hessian#TrainingStructures#generation,json,,"How the Hessian was made and checked: route, open shell, the check's errors and largest frequency, and any refusal.",
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
This is an initial library of BibTex references for the training_structures_step plug-in for SEAMM,
|
|
2
|
+
generated automatically by the cookiecutter. You may wish to edit the first entry to correct some
|
|
3
|
+
of the information.
|
|
4
|
+
|
|
5
|
+
Add other references to the end of the file and add code in the plug-in to cite the references as
|
|
6
|
+
appropriate. This is done with code like this:
|
|
7
|
+
|
|
8
|
+
self.references.cite(
|
|
9
|
+
raw=self._bibliography['doi:10.1002/jcc.21224'],
|
|
10
|
+
alias='packmol',
|
|
11
|
+
module='packmol_step',
|
|
12
|
+
level=1,
|
|
13
|
+
note='The principle PACKMOL citation.'
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
which is typically in the run() method of the plug-in.
|
|
17
|
+
|
|
18
|
+
The base node class in SEAMM automatically reads this list of references into a dictionary in
|
|
19
|
+
self._bibliography with the key being the key of the BibTex entry -- usually the name on the
|
|
20
|
+
first line of the entry after the 'article' or 'misc' (for software) keyword.
|
|
21
|
+
|
|
22
|
+
See the documentation for the Reference Handler for the other arguments to cite().
|
|
23
|
+
|
|
24
|
+
# End of initial comments #
|
|
25
|
+
|
|
26
|
+
# This is the citation for this plug-in, generated and used automatically.
|
|
27
|
+
# You might need to edit the author, address, etc. The month, year and version fields
|
|
28
|
+
# are automatically filled in with information about current version of the plug-in.
|
|
29
|
+
# This is handled in seamm/nody.py, the run() method.
|
|
30
|
+
|
|
31
|
+
@Misc{training_structures_step,
|
|
32
|
+
author = {Paul Saxe},
|
|
33
|
+
title = {Training Structures plug-in for SEAMM},
|
|
34
|
+
month = {$month},
|
|
35
|
+
year = {$year},
|
|
36
|
+
organization = {molssi-seamm},
|
|
37
|
+
url = {https://github.com/molssi-seamm/training_structures_step },
|
|
38
|
+
address = {USA},
|
|
39
|
+
version = {$version}
|
|
40
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
"""The geometry generators and filters of the Training Structures step, as plain
|
|
4
|
+
functions of coordinates, bonds and Hessians (no flowchart state), so that they
|
|
5
|
+
can be tested on their own.
|
|
6
|
+
|
|
7
|
+
Units: coordinates in Å, Hessians in E_h/bohr², gradients in E_h/bohr, energies in
|
|
8
|
+
E_h unless a name says otherwise.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import math
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
BOHR = 0.529177210903 # Å
|
|
16
|
+
KCAL_HARTREE = 627.509474 # kcal/mol per E_h
|
|
17
|
+
KJ_HARTREE = 2625.4996394799 # kJ/mol per E_h
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# --------------------------------------------------------------------------- #
|
|
21
|
+
# Connectivity
|
|
22
|
+
# --------------------------------------------------------------------------- #
|
|
23
|
+
def covalent_radii(symbols):
|
|
24
|
+
"""RDKit's covalent radii (Å) of the elements."""
|
|
25
|
+
from rdkit import Chem
|
|
26
|
+
|
|
27
|
+
table = Chem.GetPeriodicTable()
|
|
28
|
+
return np.array([table.GetRcovalent(s) for s in symbols])
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def connectivity(symbols, xyz, factor=1.3, radii=None):
|
|
32
|
+
"""The bonds (i < j) of a structure: atoms closer than ``factor`` times the
|
|
33
|
+
sum of their covalent radii."""
|
|
34
|
+
x = np.asarray(xyz, dtype=float).reshape(-1, 3)
|
|
35
|
+
r = covalent_radii(symbols) if radii is None else np.asarray(radii)
|
|
36
|
+
bonds = set()
|
|
37
|
+
for i in range(len(x)):
|
|
38
|
+
d = np.linalg.norm(x[i + 1 :] - x[i], axis=1)
|
|
39
|
+
for k in np.nonzero(d < factor * (r[i + 1 :] + r[i]))[0]:
|
|
40
|
+
bonds.add((i, i + 1 + int(k)))
|
|
41
|
+
return bonds
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def connectivity_change(
|
|
45
|
+
reference_bonds, symbols, xyz, factor=1.3, radii=None, exempt=None
|
|
46
|
+
):
|
|
47
|
+
"""None if the structure has exactly the reference bonds, else the bonds
|
|
48
|
+
broken and formed, as text (e.g. '-C1-H5 +H5-O3'). ``exempt`` is a bond
|
|
49
|
+
(i, j) not judged: a bond stretched on purpose."""
|
|
50
|
+
now = connectivity(symbols, xyz, factor, radii)
|
|
51
|
+
ref = {tuple(sorted(b)) for b in reference_bonds}
|
|
52
|
+
if exempt is not None:
|
|
53
|
+
key = tuple(sorted(exempt))
|
|
54
|
+
now.discard(key)
|
|
55
|
+
ref.discard(key)
|
|
56
|
+
if now == ref:
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
def label(b):
|
|
60
|
+
i, j = b
|
|
61
|
+
return f"{symbols[i]}{i + 1}-{symbols[j]}{j + 1}"
|
|
62
|
+
|
|
63
|
+
return " ".join(
|
|
64
|
+
[f"-{label(b)}" for b in sorted(ref - now)]
|
|
65
|
+
+ [f"+{label(b)}" for b in sorted(now - ref)]
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# --------------------------------------------------------------------------- #
|
|
70
|
+
# Rotors and torsion scans
|
|
71
|
+
# --------------------------------------------------------------------------- #
|
|
72
|
+
def _side(n_atoms, bonds, i, j):
|
|
73
|
+
"""The atoms on j's side of the bond i-j (j included), or None when the bond
|
|
74
|
+
is in a ring."""
|
|
75
|
+
neighbours = [set() for _ in range(n_atoms)]
|
|
76
|
+
for a, b in bonds:
|
|
77
|
+
neighbours[a].add(b)
|
|
78
|
+
neighbours[b].add(a)
|
|
79
|
+
seen, todo = {j}, [j]
|
|
80
|
+
while todo:
|
|
81
|
+
a = todo.pop()
|
|
82
|
+
for b in neighbours[a]:
|
|
83
|
+
if a == j and b == i:
|
|
84
|
+
continue
|
|
85
|
+
if b == i:
|
|
86
|
+
return None # back to i another way: a ring
|
|
87
|
+
if b not in seen:
|
|
88
|
+
seen.add(b)
|
|
89
|
+
todo.append(b)
|
|
90
|
+
return seen
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def find_rotors(symbols, bonds, orders=None, conjugated=None, max_rotors=None):
|
|
94
|
+
"""The heavy rotors of a molecule, most heavy atoms moved first.
|
|
95
|
+
|
|
96
|
+
A heavy rotor is an acyclic single bond i-j, not conjugated, where i and j
|
|
97
|
+
each have another heavy-atom neighbour (so methyl, OH and NH2 rotations are
|
|
98
|
+
not rotors). Rotating about it moves the smaller side; rotors are ranked by
|
|
99
|
+
the number of heavy atoms that moves, ties going to the lower atom indices.
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
symbols : [str]
|
|
104
|
+
bonds : [(int, int)]
|
|
105
|
+
0-based.
|
|
106
|
+
orders : {(i, j): int} or None
|
|
107
|
+
Bond orders (i < j); a bond without one counts as single.
|
|
108
|
+
conjugated : set of (i, j) or None
|
|
109
|
+
The conjugated bonds (i < j), e.g. from RDKit's GetIsConjugated.
|
|
110
|
+
max_rotors : int or None
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
[dict]
|
|
115
|
+
Each with "bond" (i, j), "dihedral" (a, i, j, b), "moving" (the atoms
|
|
116
|
+
that rotate, a sorted list) and "heavy moved".
|
|
117
|
+
"""
|
|
118
|
+
n = len(symbols)
|
|
119
|
+
heavy = [s != "H" for s in symbols]
|
|
120
|
+
neighbours = [set() for _ in range(n)]
|
|
121
|
+
for a, b in bonds:
|
|
122
|
+
neighbours[a].add(b)
|
|
123
|
+
neighbours[b].add(a)
|
|
124
|
+
orders = {} if orders is None else orders
|
|
125
|
+
conjugated = set() if conjugated is None else conjugated
|
|
126
|
+
rotors = []
|
|
127
|
+
for a, b in sorted({tuple(sorted(x)) for x in bonds}):
|
|
128
|
+
if not (heavy[a] and heavy[b]):
|
|
129
|
+
continue
|
|
130
|
+
if orders.get((a, b), 1) != 1 or (a, b) in conjugated:
|
|
131
|
+
continue
|
|
132
|
+
ha = sorted(x for x in neighbours[a] - {b} if heavy[x])
|
|
133
|
+
hb = sorted(x for x in neighbours[b] - {a} if heavy[x])
|
|
134
|
+
if not ha or not hb:
|
|
135
|
+
continue
|
|
136
|
+
side_b = _side(n, bonds, a, b)
|
|
137
|
+
if side_b is None:
|
|
138
|
+
continue # in a ring
|
|
139
|
+
side_a = set(range(n)) - side_b
|
|
140
|
+
heavy_a = sum(1 for x in side_a if heavy[x])
|
|
141
|
+
heavy_b = sum(1 for x in side_b if heavy[x])
|
|
142
|
+
moving = side_b if heavy_b <= heavy_a else side_a
|
|
143
|
+
rotors.append(
|
|
144
|
+
{
|
|
145
|
+
"bond": (a, b),
|
|
146
|
+
"dihedral": (ha[0], a, b, hb[0]),
|
|
147
|
+
"moving": sorted(moving),
|
|
148
|
+
"heavy moved": min(heavy_a, heavy_b),
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
rotors.sort(key=lambda r: (-r["heavy moved"], r["bond"]))
|
|
152
|
+
return rotors if max_rotors is None else rotors[:max_rotors]
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def dihedral(x, a, b, c, d):
|
|
156
|
+
"""The dihedral a-b-c-d (degrees, -180..180)."""
|
|
157
|
+
b0, b1, b2 = x[a] - x[b], x[c] - x[b], x[d] - x[c]
|
|
158
|
+
b1n = b1 / np.linalg.norm(b1)
|
|
159
|
+
v = b0 - np.dot(b0, b1n) * b1n
|
|
160
|
+
w = b2 - np.dot(b2, b1n) * b1n
|
|
161
|
+
return math.degrees(math.atan2(np.dot(np.cross(b1n, v), w), np.dot(v, w)))
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def rotate_about_bond(xyz, i, j, moving, degrees):
|
|
165
|
+
"""A copy of xyz with the atoms ``moving`` turned by ``degrees`` about the
|
|
166
|
+
i-j axis (right-handed about i -> j)."""
|
|
167
|
+
x = np.array(xyz, dtype=float).reshape(-1, 3)
|
|
168
|
+
axis = x[j] - x[i]
|
|
169
|
+
axis /= np.linalg.norm(axis)
|
|
170
|
+
t = math.radians(degrees)
|
|
171
|
+
K = np.array(
|
|
172
|
+
[[0, -axis[2], axis[1]], [axis[2], 0, -axis[0]], [-axis[1], axis[0], 0]]
|
|
173
|
+
)
|
|
174
|
+
R = np.eye(3) + math.sin(t) * K + (1 - math.cos(t)) * K @ K
|
|
175
|
+
idx = list(moving)
|
|
176
|
+
x[idx] = (x[idx] - x[j]) @ R.T + x[j]
|
|
177
|
+
return x
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def set_dihedral(xyz, rotor, target):
|
|
181
|
+
"""A copy of xyz with the rotor's dihedral set to ``target`` degrees by
|
|
182
|
+
turning its moving side."""
|
|
183
|
+
a, i, j, b = rotor["dihedral"]
|
|
184
|
+
x = np.asarray(xyz, dtype=float).reshape(-1, 3)
|
|
185
|
+
now = dihedral(x, a, i, j, b)
|
|
186
|
+
# turning the side that holds b about i -> j by t changes the dihedral by t;
|
|
187
|
+
# turning the side that holds a changes it by -t
|
|
188
|
+
sign = 1.0 if b in rotor["moving"] else -1.0
|
|
189
|
+
return rotate_about_bond(x, i, j, rotor["moving"], sign * (target - now))
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def scan_angles(start, step=15.0):
|
|
193
|
+
"""The scan's dihedral targets: start + k*step, k = 1 ... 360/step - 1 (the
|
|
194
|
+
start itself is the minimum and is not repeated), wrapped to -180..180."""
|
|
195
|
+
n = int(round(360.0 / step))
|
|
196
|
+
return [((start + k * step + 180.0) % 360.0) - 180.0 for k in range(1, n)]
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
# --------------------------------------------------------------------------- #
|
|
200
|
+
# Bond distortions
|
|
201
|
+
# --------------------------------------------------------------------------- #
|
|
202
|
+
def bond_classes(symbols, xyz, bonds, pairs=None):
|
|
203
|
+
"""{"C-H": (i, j), ...}: for each bonded element pair, the bond of median
|
|
204
|
+
length (the lower of the two middle ones; ties to the lower indices).
|
|
205
|
+
``pairs`` limits it to those classes (e.g. {"C-H", "C-C"}; order of the
|
|
206
|
+
elements does not matter)."""
|
|
207
|
+
x = np.asarray(xyz, dtype=float).reshape(-1, 3)
|
|
208
|
+
groups = {}
|
|
209
|
+
for i, j in sorted({tuple(sorted(b)) for b in bonds}):
|
|
210
|
+
key = "-".join(sorted((symbols[i], symbols[j])))
|
|
211
|
+
groups.setdefault(key, []).append((float(np.linalg.norm(x[i] - x[j])), i, j))
|
|
212
|
+
if pairs is not None:
|
|
213
|
+
wanted = {"-".join(sorted(p.replace(" ", "").split("-"))) for p in pairs}
|
|
214
|
+
groups = {k: v for k, v in groups.items() if k in wanted}
|
|
215
|
+
out = {}
|
|
216
|
+
for key, items in sorted(groups.items()):
|
|
217
|
+
items.sort()
|
|
218
|
+
_, i, j = items[(len(items) - 1) // 2]
|
|
219
|
+
out[key] = (i, j)
|
|
220
|
+
return out
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def stretch_vector(xyz, i, j):
|
|
224
|
+
"""The unit-free stretch direction (3N): -u/2 on i, +u/2 on j, u the unit
|
|
225
|
+
vector i -> j; a displacement a times it lengthens the bond by a."""
|
|
226
|
+
x = np.asarray(xyz, dtype=float).reshape(-1, 3)
|
|
227
|
+
u = (x[j] - x[i]) / np.linalg.norm(x[j] - x[i])
|
|
228
|
+
v = np.zeros_like(x)
|
|
229
|
+
v[i] = -0.5 * u
|
|
230
|
+
v[j] = 0.5 * u
|
|
231
|
+
return v.reshape(-1)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def stretch_amplitude(hessian, xyz, i, j, energy, maximum=None):
|
|
235
|
+
"""The bond-length change a (Å) whose harmonic energy along the stretch is
|
|
236
|
+
``energy`` (E_h): 1/2 a² vᵀHv = energy, exact for this two-atom
|
|
237
|
+
displacement; capped at ``maximum`` (Å)."""
|
|
238
|
+
v = stretch_vector(xyz, i, j)
|
|
239
|
+
k = float(v @ np.asarray(hessian, dtype=float) @ v) # E_h/bohr²
|
|
240
|
+
if k <= 0.0:
|
|
241
|
+
a = maximum
|
|
242
|
+
else:
|
|
243
|
+
a = math.sqrt(2.0 * energy / k) * BOHR
|
|
244
|
+
if maximum is not None:
|
|
245
|
+
a = min(a, maximum)
|
|
246
|
+
return a
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def stretch(xyz, i, j, a):
|
|
250
|
+
"""A copy of xyz with bond i-j lengthened by a (Å; negative shortens), each
|
|
251
|
+
atom moving a/2."""
|
|
252
|
+
x = np.asarray(xyz, dtype=float).reshape(-1)
|
|
253
|
+
return (x + a * stretch_vector(xyz, i, j)).reshape(-1, 3)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def diatomic_grid(hessian, xyz, energy, n_points):
|
|
257
|
+
"""Bond-length changes (Å) for a diatomic's 1-D stretch grid: n_points equally
|
|
258
|
+
spaced from -a to +a, a the displacement whose harmonic energy is ``energy``
|
|
259
|
+
(E_h); r_e itself (the minimum, already a point) is left out if it falls on
|
|
260
|
+
the grid."""
|
|
261
|
+
a = stretch_amplitude(hessian, xyz, 0, 1, energy)
|
|
262
|
+
grid = np.linspace(-a, a, n_points)
|
|
263
|
+
return [float(g) for g in grid if abs(g) > 1e-9 * a]
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
# --------------------------------------------------------------------------- #
|
|
267
|
+
# Hessian check
|
|
268
|
+
# --------------------------------------------------------------------------- #
|
|
269
|
+
def frequencies(hessian, masses_amu):
|
|
270
|
+
"""Signed harmonic frequencies (cm⁻¹) of a Cartesian Hessian (E_h/bohr²),
|
|
271
|
+
without projecting translations and rotations (for the frequency guard)."""
|
|
272
|
+
m = np.repeat(np.asarray(masses_amu, dtype=float), 3)
|
|
273
|
+
H = np.asarray(hessian, dtype=float)
|
|
274
|
+
H_mw = H / np.sqrt(np.outer(m, m))
|
|
275
|
+
lam = np.linalg.eigvalsh(0.5 * (H_mw + H_mw.T))
|
|
276
|
+
# E_h/(bohr² amu) -> (cm⁻¹)²: 5140.487^2 per unit
|
|
277
|
+
factor = 5140.48767
|
|
278
|
+
return np.sign(lam) * np.sqrt(np.abs(lam)) * factor
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def check_hessian(
|
|
282
|
+
hessian,
|
|
283
|
+
gradient,
|
|
284
|
+
xyz,
|
|
285
|
+
masses_amu,
|
|
286
|
+
rng,
|
|
287
|
+
n_displacements=3,
|
|
288
|
+
rms=0.005,
|
|
289
|
+
tolerance=0.02,
|
|
290
|
+
max_frequency=5000.0,
|
|
291
|
+
):
|
|
292
|
+
"""Test a Hessian against central differences of the gradient.
|
|
293
|
+
|
|
294
|
+
For each of ``n_displacements`` random displacements δ with an RMS of ``rms``
|
|
295
|
+
Å, e = ‖Hδ − [g(x₀+δ) − g(x₀−δ)]/2‖ / ‖Hδ‖ (2 gradients each). The Hessian
|
|
296
|
+
is refused if any e exceeds ``tolerance`` or any frequency magnitude exceeds
|
|
297
|
+
``max_frequency`` cm⁻¹.
|
|
298
|
+
|
|
299
|
+
Parameters
|
|
300
|
+
----------
|
|
301
|
+
gradient : callable
|
|
302
|
+
gradient(xyz (N, 3) Å) -> (3N,) E_h/bohr.
|
|
303
|
+
|
|
304
|
+
Returns
|
|
305
|
+
-------
|
|
306
|
+
dict
|
|
307
|
+
"errors": [e], "max frequency": the largest frequency magnitude,
|
|
308
|
+
"refused": bool and "reason": text or None.
|
|
309
|
+
"""
|
|
310
|
+
x0 = np.asarray(xyz, dtype=float).reshape(-1)
|
|
311
|
+
H = np.asarray(hessian, dtype=float)
|
|
312
|
+
nu = frequencies(H, masses_amu)
|
|
313
|
+
biggest = float(np.max(np.abs(nu)))
|
|
314
|
+
errors = []
|
|
315
|
+
for _ in range(n_displacements):
|
|
316
|
+
d = rng.standard_normal(x0.size)
|
|
317
|
+
d *= rms / math.sqrt(np.mean(d**2)) # Å
|
|
318
|
+
Hd = H @ (d / BOHR)
|
|
319
|
+
g_plus = np.asarray(gradient((x0 + d).reshape(-1, 3)), dtype=float)
|
|
320
|
+
g_minus = np.asarray(gradient((x0 - d).reshape(-1, 3)), dtype=float)
|
|
321
|
+
dg = 0.5 * (g_plus - g_minus)
|
|
322
|
+
errors.append(float(np.linalg.norm(Hd - dg) / np.linalg.norm(Hd)))
|
|
323
|
+
reason = None
|
|
324
|
+
if biggest > max_frequency:
|
|
325
|
+
reason = f"a frequency of {biggest:.0f} cm⁻¹ (> {max_frequency:.0f})"
|
|
326
|
+
elif max(errors) > tolerance:
|
|
327
|
+
reason = f"it disagrees with the gradients by {max(errors):.3f} (> {tolerance})"
|
|
328
|
+
return {
|
|
329
|
+
"errors": errors,
|
|
330
|
+
"max frequency": biggest,
|
|
331
|
+
"refused": reason is not None,
|
|
332
|
+
"reason": reason,
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def wrap(delta):
|
|
337
|
+
"""The magnitude of an angle difference, wrapped to 0..180 degrees."""
|
|
338
|
+
return abs((delta + 180.0) % 360.0 - 180.0)
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
"""This file contains metadata describing the results from TrainingStructures"""
|
|
4
|
+
|
|
5
|
+
metadata = {}
|
|
6
|
+
|
|
7
|
+
"""Description of the computational models for TrainingStructures.
|
|
8
|
+
|
|
9
|
+
Hamiltonians, approximations, and basis set or parameterizations,
|
|
10
|
+
only if appropriate for this code. For example::
|
|
11
|
+
|
|
12
|
+
metadata["computational models"] = {
|
|
13
|
+
"Hartree-Fock": {
|
|
14
|
+
"models": {
|
|
15
|
+
"PM7": {
|
|
16
|
+
"parameterizations": {
|
|
17
|
+
"PM7": {
|
|
18
|
+
"elements": "1-60,62-83",
|
|
19
|
+
"periodic": True,
|
|
20
|
+
"reactions": True,
|
|
21
|
+
"optimization": True,
|
|
22
|
+
"code": "mopac",
|
|
23
|
+
},
|
|
24
|
+
"PM7-TS": {
|
|
25
|
+
"elements": "1-60,62-83",
|
|
26
|
+
"periodic": True,
|
|
27
|
+
"reactions": True,
|
|
28
|
+
"optimization": False,
|
|
29
|
+
"code": "mopac",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
"""
|
|
37
|
+
# metadata["computational models"] = {
|
|
38
|
+
# }
|
|
39
|
+
|
|
40
|
+
"""Description of the TrainingStructures keywords.
|
|
41
|
+
|
|
42
|
+
(Only needed if this code uses keywords)
|
|
43
|
+
|
|
44
|
+
Fields
|
|
45
|
+
------
|
|
46
|
+
description : str
|
|
47
|
+
A human readable description of the keyword.
|
|
48
|
+
takes values : int (optional)
|
|
49
|
+
Number of values the keyword takes. If missing the keyword takes no values.
|
|
50
|
+
default : str (optional)
|
|
51
|
+
The default value(s) if the keyword takes values.
|
|
52
|
+
format : str (optional)
|
|
53
|
+
How the keyword is formatted in the MOPAC input.
|
|
54
|
+
|
|
55
|
+
For example::
|
|
56
|
+
metadata["keywords"] = {
|
|
57
|
+
"0SCF": {
|
|
58
|
+
"description": "Read in data, then stop",
|
|
59
|
+
},
|
|
60
|
+
"ALT_A": {
|
|
61
|
+
"description": "In PDB files with alternative atoms, select atoms A",
|
|
62
|
+
"takes values": 1,
|
|
63
|
+
"default": "A",
|
|
64
|
+
"format": "{}={}",
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
"""
|
|
68
|
+
# metadata["keywords"] = {
|
|
69
|
+
# }
|
|
70
|
+
|
|
71
|
+
"""Properties that TrainingStructures produces.
|
|
72
|
+
`metadata["results"]` describes the results that this step can produce. It is a
|
|
73
|
+
dictionary where the keys are the internal names of the results within this step, and
|
|
74
|
+
the values are a dictionary describing the result. For example::
|
|
75
|
+
|
|
76
|
+
metadata["results"] = {
|
|
77
|
+
"total_energy": {
|
|
78
|
+
"calculation": [
|
|
79
|
+
"energy",
|
|
80
|
+
"optimization",
|
|
81
|
+
],
|
|
82
|
+
"description": "The total energy",
|
|
83
|
+
"dimensionality": "scalar",
|
|
84
|
+
"methods": [
|
|
85
|
+
"ccsd",
|
|
86
|
+
"ccsd(t)",
|
|
87
|
+
"dft",
|
|
88
|
+
"hf",
|
|
89
|
+
],
|
|
90
|
+
"property": "total energy#Psi4#{model}",
|
|
91
|
+
"type": "float",
|
|
92
|
+
"units": "E_h",
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Fields
|
|
97
|
+
______
|
|
98
|
+
|
|
99
|
+
calculation : [str]
|
|
100
|
+
Optional metadata describing what subtype of the step produces this result.
|
|
101
|
+
The subtypes are completely arbitrary, but often they are types of calculations
|
|
102
|
+
which is why this is name `calculation`. To use this, the step or a substep
|
|
103
|
+
define `self._calculation` as a value. That value is used to select only the
|
|
104
|
+
results with that value in this field.
|
|
105
|
+
|
|
106
|
+
description : str
|
|
107
|
+
A human-readable description of the result.
|
|
108
|
+
|
|
109
|
+
dimensionality : str
|
|
110
|
+
The dimensions of the data. The value can be "scalar" or an array definition
|
|
111
|
+
of the form "[dim1, dim2,...]". Symmetric tringular matrices are denoted
|
|
112
|
+
"triangular[n,n]". The dimensions can be integers, other scalar
|
|
113
|
+
results, or standard parameters such as `n_atoms`. For example, '[3]',
|
|
114
|
+
[3, n_atoms], or "triangular[n_aos, n_aos]".
|
|
115
|
+
|
|
116
|
+
methods : str
|
|
117
|
+
Optional metadata like the `calculation` data. `methods` provides a second
|
|
118
|
+
level of filtering, often used for the Hamiltionian for *ab initio* calculations
|
|
119
|
+
where some properties may or may not be calculated depending on the type of
|
|
120
|
+
theory.
|
|
121
|
+
|
|
122
|
+
property : str
|
|
123
|
+
An optional definition of the property for storing this result. Must be one of
|
|
124
|
+
the standard properties defined either in SEAMM or in this steps property
|
|
125
|
+
metadata in `data/properties.csv`.
|
|
126
|
+
|
|
127
|
+
type : str
|
|
128
|
+
The type of the data: string, integer, or float.
|
|
129
|
+
|
|
130
|
+
units : str
|
|
131
|
+
Optional units for the result. If present, the value should be in these units.
|
|
132
|
+
"""
|
|
133
|
+
metadata["results"] = {
|
|
134
|
+
"number of points": {
|
|
135
|
+
"description": "The number of structures made, the minimum included",
|
|
136
|
+
"dimensionality": "scalar",
|
|
137
|
+
"type": "integer",
|
|
138
|
+
},
|
|
139
|
+
"number of sample points": {
|
|
140
|
+
"description": "The number of normal-mode samples",
|
|
141
|
+
"dimensionality": "scalar",
|
|
142
|
+
"type": "integer",
|
|
143
|
+
},
|
|
144
|
+
"number of scan points": {
|
|
145
|
+
"description": "The number of torsion-scan points",
|
|
146
|
+
"dimensionality": "scalar",
|
|
147
|
+
"type": "integer",
|
|
148
|
+
},
|
|
149
|
+
"number of stretch points": {
|
|
150
|
+
"description": "The number of bond-stretch points",
|
|
151
|
+
"dimensionality": "scalar",
|
|
152
|
+
"type": "integer",
|
|
153
|
+
},
|
|
154
|
+
"number of grid points": {
|
|
155
|
+
"description": "The number of a diatomic's stretch-grid points",
|
|
156
|
+
"dimensionality": "scalar",
|
|
157
|
+
"type": "integer",
|
|
158
|
+
},
|
|
159
|
+
"number of rotors": {
|
|
160
|
+
"description": "The number of heavy rotors scanned",
|
|
161
|
+
"dimensionality": "scalar",
|
|
162
|
+
"type": "integer",
|
|
163
|
+
},
|
|
164
|
+
"number of dropped points": {
|
|
165
|
+
"description": "The number of points refused by the checks",
|
|
166
|
+
"dimensionality": "scalar",
|
|
167
|
+
"type": "integer",
|
|
168
|
+
},
|
|
169
|
+
"dropped points": {
|
|
170
|
+
"description": "The points refused, by kind, with the reasons",
|
|
171
|
+
"dimensionality": "scalar",
|
|
172
|
+
"type": "json",
|
|
173
|
+
},
|
|
174
|
+
"hessian": {
|
|
175
|
+
"description": "How the Hessian was made and checked",
|
|
176
|
+
"dimensionality": "scalar",
|
|
177
|
+
"type": "json",
|
|
178
|
+
},
|
|
179
|
+
"random seed": {
|
|
180
|
+
"description": "The seed of the random numbers, to reproduce the points",
|
|
181
|
+
"dimensionality": "scalar",
|
|
182
|
+
"type": "integer",
|
|
183
|
+
},
|
|
184
|
+
"system name": {
|
|
185
|
+
"description": "The name of the system holding the structures",
|
|
186
|
+
"dimensionality": "scalar",
|
|
187
|
+
"type": "string",
|
|
188
|
+
},
|
|
189
|
+
}
|