aromatools 0.2.26__tar.gz → 0.2.28__tar.gz
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.
Potentially problematic release.
This version of aromatools might be problematic. Click here for more details.
- {aromatools-0.2.26 → aromatools-0.2.28}/PKG-INFO +1 -1
- aromatools-0.2.28/aromatools/arogeometric/__init__.py +1 -0
- aromatools-0.2.28/aromatools/arogeometric/arogeometric.py +359 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/amg_read_input.py +51 -39
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/amg_write_inputs.py +5 -27
- aromatools-0.2.28/aromatools/aromagnetic/aromagnetic.py +277 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/cube_to_vtk.py +1 -1
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/get_grid.py +79 -1
- aromatools-0.2.28/aromatools/aromagnetic/get_profile.py +380 -0
- aromatools-0.2.28/aromatools/aromagnetic/get_results.py +582 -0
- aromatools-0.2.28/aromatools/aromagnetic/make_input.py +116 -0
- aromatools-0.2.28/aromatools/aromagnetic/predixy.py +517 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/reset_calc.py +13 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/sum_rest.py +20 -17
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/tools.py +20 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools.egg-info/PKG-INFO +1 -1
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools.egg-info/SOURCES.txt +2 -5
- aromatools-0.2.28/aromatools.egg-info/entry_points.txt +4 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/pyproject.toml +2 -9
- aromatools-0.2.26/aromatools/arogeometric/__init__.py +0 -2
- aromatools-0.2.26/aromatools/arogeometric/arogeometric.py +0 -458
- aromatools-0.2.26/aromatools/arogeometric/reporter.py +0 -47
- aromatools-0.2.26/aromatools/aromagnetic/aromagnetic.py +0 -278
- aromatools-0.2.26/aromatools/aromagnetic/extrac_values.py +0 -220
- aromatools-0.2.26/aromatools/aromagnetic/get_integral.py +0 -229
- aromatools-0.2.26/aromatools/aromagnetic/get_nics_scan.py +0 -221
- aromatools-0.2.26/aromatools/aromagnetic/get_profile.py +0 -197
- aromatools-0.2.26/aromatools/aromagnetic/make_input.py +0 -142
- aromatools-0.2.26/aromatools/aromagnetic/nics_scan.py +0 -170
- aromatools-0.2.26/aromatools.egg-info/entry_points.txt +0 -10
- {aromatools-0.2.26 → aromatools-0.2.28}/LICENSE +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/README.md +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/__init__.py +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/arogeometric/__main__.py +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/__init__.py +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/__main__.py +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/check_out.py +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/get_cube.py +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/get_mo.py +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/insert_basis.py +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/parser_mo.py +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools/aromagnetic/pseudo_pi.py +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools.egg-info/dependency_links.txt +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools.egg-info/requires.txt +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/aromatools.egg-info/top_level.txt +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/setup.cfg +0 -0
- {aromatools-0.2.26 → aromatools-0.2.28}/setup.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .arogeometric import *
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
import math
|
|
5
|
+
import pandas as pd
|
|
6
|
+
import networkx as nx
|
|
7
|
+
import plotly.graph_objects as go
|
|
8
|
+
from ase.data import covalent_radii, atomic_numbers, chemical_symbols
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
BANNER = r"""
|
|
12
|
+
======================================================================
|
|
13
|
+
AROGEOMETRIC
|
|
14
|
+
Geometric Criteria for Aromaticity Evaluation
|
|
15
|
+
======================================================================
|
|
16
|
+
|
|
17
|
+
AroGeometric implements widely used geometric descriptors of aromaticity:
|
|
18
|
+
|
|
19
|
+
• HOMA93 (Harmonic Oscillator Model of Aromaticity with experimental data)
|
|
20
|
+
• HOMAc (Harmonic Oscillator Model of Aromaticity with computational data)
|
|
21
|
+
• HOMER (excited-state aromaticity)
|
|
22
|
+
|
|
23
|
+
Capabilities:
|
|
24
|
+
|
|
25
|
+
• Automatic ring detection from molecular geometry
|
|
26
|
+
• Quantification of bond-length equalization (BLA)
|
|
27
|
+
• Analysis of mono- and polycyclic systems
|
|
28
|
+
• Graph-based ring identification
|
|
29
|
+
• Interactive 3D visualization of rings
|
|
30
|
+
|
|
31
|
+
Geometric indices complement magnetic criteria by providing structural
|
|
32
|
+
evidence of electron delocalization in cyclic molecules.
|
|
33
|
+
|
|
34
|
+
----------------------------------------------------------------------
|
|
35
|
+
Developed by:
|
|
36
|
+
|
|
37
|
+
Fernando Martínez-Villarino
|
|
38
|
+
Gabriel Merino
|
|
39
|
+
|
|
40
|
+
Cinvestav – Mérida
|
|
41
|
+
Centro de Investigación y de Estudios Avanzados del IPN
|
|
42
|
+
|
|
43
|
+
----------------------------------------------------------------------
|
|
44
|
+
Citation:
|
|
45
|
+
|
|
46
|
+
Martínez-Villarino, F.; Orozco-Ic, M.; Merino, G.
|
|
47
|
+
AromaTools 1.0, Cinvestav Mérida, Mérida, Mexico, 2025.
|
|
48
|
+
|
|
49
|
+
======================================================================
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
R_opt = {'HOMA93': {'CC': 1.388, 'CN': 1.334, 'NN': 1.309, 'CO': 1.265},
|
|
53
|
+
'HOMER': {'CC': 1.437, 'CN': 1.39, 'NN': 1.375, 'CO': 1.379},
|
|
54
|
+
'HOMAC': {'CC': 1.392, 'CN': 1.333, 'NN': 1.318, 'CO': 1.315,
|
|
55
|
+
'SiSi': 2.163, 'CSi': 1.752}}
|
|
56
|
+
|
|
57
|
+
alpha = {'HOMA93': {'CC': 257.7, 'CN': 93.52, 'NN': 130.33, 'CO': 157.38},
|
|
58
|
+
'HOMER': {'CC': 950.74, 'CN': 506.43, 'NN': 187.36, 'CO': 164.96},
|
|
59
|
+
'HOMAC': {'CC': 153.37, 'CN': 111.83, 'NN': 98.99, 'CO': 335.16,
|
|
60
|
+
'SiSi': 325.6, 'CSi': 115.41}}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def build_graph(atoms, tol=0.45):
|
|
64
|
+
G = nx.Graph()
|
|
65
|
+
for idx, (sym, _, _, _) in enumerate(atoms):
|
|
66
|
+
G.add_node(idx, element=sym)
|
|
67
|
+
for i in range(len(atoms)):
|
|
68
|
+
sym1, x1, y1, z1 = atoms[i]
|
|
69
|
+
r1 = covalent_radii[atomic_numbers[sym1]]
|
|
70
|
+
for j in range(i + 1, len(atoms)):
|
|
71
|
+
sym2, x2, y2, z2 = atoms[j]
|
|
72
|
+
r2 = covalent_radii[atomic_numbers[sym2]]
|
|
73
|
+
dist = math.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)
|
|
74
|
+
if dist <= r1 + r2 + tol:
|
|
75
|
+
bond_type = ''.join(sorted([sym1, sym2]))
|
|
76
|
+
G.add_edge(i, j, length=dist, bond_type=bond_type)
|
|
77
|
+
return G
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def find_rings(G, max_size=8):
|
|
81
|
+
rings = set()
|
|
82
|
+
sizes = tuple(range(3, max_size + 1))
|
|
83
|
+
|
|
84
|
+
def canon_ring(path):
|
|
85
|
+
seq1 = list(path)
|
|
86
|
+
seq2 = list(reversed(path))
|
|
87
|
+
def normalize(seq):
|
|
88
|
+
m = min(seq)
|
|
89
|
+
i = seq.index(m)
|
|
90
|
+
return tuple(seq[i:] + seq[:i])
|
|
91
|
+
return min(normalize(seq1), normalize(seq2))
|
|
92
|
+
|
|
93
|
+
def dfs(path, depth):
|
|
94
|
+
if depth > max_size:
|
|
95
|
+
return
|
|
96
|
+
current = path[-1]
|
|
97
|
+
for neighbor in G.neighbors(current):
|
|
98
|
+
if neighbor == path[0] and len(path) in sizes:
|
|
99
|
+
rings.add(canon_ring(path))
|
|
100
|
+
elif neighbor not in path:
|
|
101
|
+
dfs(path + [neighbor], depth + 1)
|
|
102
|
+
|
|
103
|
+
for start in G.nodes():
|
|
104
|
+
dfs([start], 1)
|
|
105
|
+
|
|
106
|
+
return [list(r) for r in rings]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def order_ring_nodes(G, ring):
|
|
110
|
+
ordered = [ring[0]]
|
|
111
|
+
used = set(ordered)
|
|
112
|
+
while len(ordered) < len(ring):
|
|
113
|
+
current = ordered[-1]
|
|
114
|
+
for neighbor in G.neighbors(current):
|
|
115
|
+
if neighbor in ring and neighbor not in used:
|
|
116
|
+
ordered.append(neighbor)
|
|
117
|
+
used.add(neighbor)
|
|
118
|
+
break
|
|
119
|
+
else:
|
|
120
|
+
raise ValueError(f"Could not consistently order ring nodes: {ring}")
|
|
121
|
+
return ordered
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def compute_index(G, atoms, index_type):
|
|
125
|
+
rings = find_rings(G)
|
|
126
|
+
ring_data = []
|
|
127
|
+
bond_rows = []
|
|
128
|
+
coords = {i: (x, y, z) for i, (_, x, y, z) in enumerate(atoms)}
|
|
129
|
+
symbols = {i: sym for i, (sym, _, _, _) in enumerate(atoms)}
|
|
130
|
+
|
|
131
|
+
if index_type == "HOMA":
|
|
132
|
+
sub_indices = ["HOMA93", "HOMAC"]
|
|
133
|
+
elif index_type == "HOMER":
|
|
134
|
+
sub_indices = ["HOMER"]
|
|
135
|
+
else:
|
|
136
|
+
raise ValueError("Invalid index_type. Choose 'HOMA' or 'HOMER'.")
|
|
137
|
+
|
|
138
|
+
for idx, ring in enumerate(rings, start=1):
|
|
139
|
+
ordered_ring = order_ring_nodes(G, ring)
|
|
140
|
+
ring_atoms = ordered_ring + [ordered_ring[0]]
|
|
141
|
+
distances = []
|
|
142
|
+
bond_info = []
|
|
143
|
+
completo = True
|
|
144
|
+
|
|
145
|
+
for i in range(len(ring)):
|
|
146
|
+
a1, a2 = ring_atoms[i], ring_atoms[i + 1]
|
|
147
|
+
if a1 not in coords or a2 not in coords:
|
|
148
|
+
completo = False
|
|
149
|
+
break
|
|
150
|
+
x1, y1, z1 = coords[a1]
|
|
151
|
+
x2, y2, z2 = coords[a2]
|
|
152
|
+
sym1, sym2 = symbols[a1], symbols[a2]
|
|
153
|
+
dist = math.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)
|
|
154
|
+
bond_type = ''.join(sorted([sym1, sym2]))
|
|
155
|
+
bond_info.append({"type": bond_type, "length": dist})
|
|
156
|
+
distances.append(dist)
|
|
157
|
+
|
|
158
|
+
if not completo or len(distances) != len(ring):
|
|
159
|
+
continue
|
|
160
|
+
|
|
161
|
+
for b in bond_info:
|
|
162
|
+
bond_rows.append({
|
|
163
|
+
"Ring": idx,
|
|
164
|
+
"Type_Bond": b["type"],
|
|
165
|
+
"Length (Å)": round(b["length"], 4)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
row = {"Ring": f"Ring {idx}", "Bonds": [round(d, 4) for d in distances]}
|
|
169
|
+
|
|
170
|
+
for sub_index in sub_indices:
|
|
171
|
+
contribs = []
|
|
172
|
+
for b in bond_info:
|
|
173
|
+
bt = b["type"]
|
|
174
|
+
if bt in R_opt[sub_index]:
|
|
175
|
+
contribs.append(alpha[sub_index][bt] * (b["length"] - R_opt[sub_index][bt])**2)
|
|
176
|
+
else:
|
|
177
|
+
print(f"[!] Bond type {bt} not supported for {sub_index}")
|
|
178
|
+
if contribs:
|
|
179
|
+
row[sub_index] = round(1.0 - sum(contribs) / len(contribs), 4)
|
|
180
|
+
|
|
181
|
+
if len(distances) >= 3:
|
|
182
|
+
n = len(distances)
|
|
183
|
+
bla = sum(abs(distances[i] - distances[(i + 1) % n]) for i in range(n)) / n
|
|
184
|
+
row["BLA"] = round(bla, 4)
|
|
185
|
+
|
|
186
|
+
ring_data.append(row)
|
|
187
|
+
|
|
188
|
+
df_main = pd.DataFrame(ring_data)
|
|
189
|
+
df_main.index += 1
|
|
190
|
+
df_bonds = pd.DataFrame(bond_rows)
|
|
191
|
+
df_bonds.index += 1
|
|
192
|
+
ring_indices = [
|
|
193
|
+
(i, row.get("HOMAC", row.get("HOMA93", row.get("HOMER", 0.0))))
|
|
194
|
+
for i, row in enumerate(ring_data)
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
return rings, ring_indices, df_main, df_bonds
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def get_3Dgraph(G, atoms, rings, ring_indices):
|
|
201
|
+
if not isinstance(ring_indices, dict):
|
|
202
|
+
ring_indices = dict(ring_indices)
|
|
203
|
+
|
|
204
|
+
node_xyz = [(x, y, z) for _, x, y, z in atoms]
|
|
205
|
+
symbols = [atoms[i][0] for i in range(len(atoms))]
|
|
206
|
+
|
|
207
|
+
x_edges, y_edges, z_edges = [], [], []
|
|
208
|
+
for u, v in G.edges():
|
|
209
|
+
x_edges += [node_xyz[u][0], node_xyz[v][0], None]
|
|
210
|
+
y_edges += [node_xyz[u][1], node_xyz[v][1], None]
|
|
211
|
+
z_edges += [node_xyz[u][2], node_xyz[v][2], None]
|
|
212
|
+
|
|
213
|
+
node_trace = go.Scatter3d(
|
|
214
|
+
x=[c[0] for c in node_xyz],
|
|
215
|
+
y=[c[1] for c in node_xyz],
|
|
216
|
+
z=[c[2] for c in node_xyz],
|
|
217
|
+
mode='markers+text',
|
|
218
|
+
text=symbols,
|
|
219
|
+
textposition='top center',
|
|
220
|
+
marker=dict(size=5, color='lightblue'),
|
|
221
|
+
name="Atoms"
|
|
222
|
+
)
|
|
223
|
+
edge_trace = go.Scatter3d(
|
|
224
|
+
x=x_edges, y=y_edges, z=z_edges,
|
|
225
|
+
mode='lines',
|
|
226
|
+
line=dict(width=2, color='gray'),
|
|
227
|
+
name="Bonds"
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
cx_list, cy_list, cz_list = [], [], []
|
|
231
|
+
value_labels, ring_labels = [], []
|
|
232
|
+
|
|
233
|
+
for i, ring in enumerate(rings):
|
|
234
|
+
ring_coords = [node_xyz[a] for a in ring]
|
|
235
|
+
cx = sum(c[0] for c in ring_coords) / len(ring_coords)
|
|
236
|
+
cy = sum(c[1] for c in ring_coords) / len(ring_coords)
|
|
237
|
+
cz = sum(c[2] for c in ring_coords) / len(ring_coords)
|
|
238
|
+
cx_list.append(cx)
|
|
239
|
+
cy_list.append(cy)
|
|
240
|
+
cz_list.append(cz)
|
|
241
|
+
value = ring_indices.get(i)
|
|
242
|
+
value_labels.append(f"{value:.3f}" if value is not None else "")
|
|
243
|
+
ring_labels.append(f"Ring {i + 1}")
|
|
244
|
+
|
|
245
|
+
value_trace = go.Scatter3d(
|
|
246
|
+
x=cx_list, y=cy_list, z=cz_list,
|
|
247
|
+
mode='text',
|
|
248
|
+
text=value_labels,
|
|
249
|
+
textfont=dict(size=10, color='red'),
|
|
250
|
+
textposition='middle center',
|
|
251
|
+
name="Indices"
|
|
252
|
+
)
|
|
253
|
+
label_trace = go.Scatter3d(
|
|
254
|
+
x=cx_list, y=cy_list, z=cz_list,
|
|
255
|
+
mode='text',
|
|
256
|
+
text=ring_labels,
|
|
257
|
+
textfont=dict(size=12, color='black'),
|
|
258
|
+
textposition='top center',
|
|
259
|
+
hoverinfo='none',
|
|
260
|
+
showlegend=False
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
fig = go.Figure(data=[edge_trace, node_trace, value_trace, label_trace])
|
|
264
|
+
fig.update_layout(
|
|
265
|
+
margin=dict(l=0, r=0, b=0, t=30),
|
|
266
|
+
showlegend=False,
|
|
267
|
+
scene=dict(
|
|
268
|
+
xaxis=dict(visible=False),
|
|
269
|
+
yaxis=dict(visible=False),
|
|
270
|
+
zaxis=dict(visible=False)
|
|
271
|
+
)
|
|
272
|
+
)
|
|
273
|
+
return fig
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def extract_atoms_from_output(fileout):
|
|
277
|
+
atoms = []
|
|
278
|
+
with open(fileout, 'r') as f:
|
|
279
|
+
lines = f.readlines()
|
|
280
|
+
|
|
281
|
+
if fileout.endswith(".xyz"):
|
|
282
|
+
for line in lines[2:]:
|
|
283
|
+
parts = line.strip().split()
|
|
284
|
+
if len(parts) == 4:
|
|
285
|
+
symbol = parts[0]
|
|
286
|
+
x, y, z = map(float, parts[1:])
|
|
287
|
+
atoms.append((symbol, x, y, z))
|
|
288
|
+
elif any("Entering Gaussian System" in line for line in lines):
|
|
289
|
+
for i in range(len(lines) - 5):
|
|
290
|
+
if "Standard orientation" in lines[i]:
|
|
291
|
+
atoms = []
|
|
292
|
+
j = i + 5
|
|
293
|
+
while "---" not in lines[j]:
|
|
294
|
+
parts = lines[j].split()
|
|
295
|
+
symbol = chemical_symbols[int(parts[1])]
|
|
296
|
+
x, y, z = map(float, parts[3:6])
|
|
297
|
+
atoms.append((symbol, x, y, z))
|
|
298
|
+
j += 1
|
|
299
|
+
elif any("O R C A" in line for line in lines):
|
|
300
|
+
start = False
|
|
301
|
+
for line in lines:
|
|
302
|
+
if "CARTESIAN COORDINATES (ANGSTROEM)" in line:
|
|
303
|
+
atoms = []
|
|
304
|
+
start = True
|
|
305
|
+
continue
|
|
306
|
+
if start:
|
|
307
|
+
if "---" in line or not line.strip():
|
|
308
|
+
start = False
|
|
309
|
+
continue
|
|
310
|
+
parts = line.strip().split()
|
|
311
|
+
if len(parts) == 4:
|
|
312
|
+
symbol = parts[0]
|
|
313
|
+
x, y, z = map(float, parts[1:])
|
|
314
|
+
atoms.append((symbol, x, y, z))
|
|
315
|
+
|
|
316
|
+
return pd.DataFrame(atoms, columns=["Element", "X", "Y", "Z"])
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def main():
|
|
320
|
+
print(BANNER)
|
|
321
|
+
|
|
322
|
+
fileout = input("Output file (Gaussian or ORCA): ").strip()
|
|
323
|
+
index_type = input("Index type [HOMA/HOMER]: ").strip().upper()
|
|
324
|
+
|
|
325
|
+
df_atoms = extract_atoms_from_output(fileout)
|
|
326
|
+
atoms_list = [
|
|
327
|
+
(row.Element, row.X, row.Y, row.Z)
|
|
328
|
+
for row in df_atoms.itertuples(index=False)
|
|
329
|
+
if row.Element != 'H'
|
|
330
|
+
]
|
|
331
|
+
|
|
332
|
+
G = build_graph(atoms_list)
|
|
333
|
+
rings, ring_indices, df_main, df_bonds = compute_index(G, atoms_list, index_type)
|
|
334
|
+
|
|
335
|
+
if index_type == "HOMA":
|
|
336
|
+
cols = [c for c in ["Ring", "HOMA93", "HOMAC", "BLA"] if c in df_main.columns]
|
|
337
|
+
else:
|
|
338
|
+
cols = [c for c in ["Ring", "HOMER", "BLA"] if c in df_main.columns]
|
|
339
|
+
|
|
340
|
+
print("\n" + "=" * 50)
|
|
341
|
+
print(df_main[cols].to_string())
|
|
342
|
+
print("\n" + "=" * 50)
|
|
343
|
+
print(df_bonds.to_string())
|
|
344
|
+
|
|
345
|
+
base = fileout.rsplit(".", 1)[0]
|
|
346
|
+
df_main[cols].to_csv(f"{base}_indices.csv", index=False)
|
|
347
|
+
df_bonds.to_csv(f"{base}_bonds.csv", index=False)
|
|
348
|
+
print(f"\nSaved: {base}_indices.csv")
|
|
349
|
+
print(f"Saved: {base}_bonds.csv")
|
|
350
|
+
|
|
351
|
+
show = input("\nShow 3D visualization? [y/n]: ").strip().lower()
|
|
352
|
+
if show == 'y':
|
|
353
|
+
fig = get_3Dgraph(G, atoms_list, rings, dict(ring_indices))
|
|
354
|
+
fig.show()
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
if __name__ == "__main__":
|
|
358
|
+
main()
|
|
359
|
+
|
|
@@ -13,17 +13,25 @@ Value = Union[Scalar, List[Scalar], None]
|
|
|
13
13
|
_TRUE = {"YES", "Y", "TRUE", "T", "ON", "1"}
|
|
14
14
|
_FALSE = {"NO", "N", "FALSE", "F", "OFF", "0"}
|
|
15
15
|
|
|
16
|
+
_KEEP_STRING_KEYS = {
|
|
17
|
+
"KEYWORD_LINE",
|
|
18
|
+
"PROGRAM",
|
|
19
|
+
"MOLECULAR_COORDINATES",
|
|
20
|
+
"SCALE",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_MODULE_KEYS = {
|
|
24
|
+
"GRID_MODULE",
|
|
25
|
+
"VERTICAL_PROFILE",
|
|
26
|
+
"HORIZONTAL_PROFILE",
|
|
27
|
+
}
|
|
28
|
+
|
|
16
29
|
|
|
17
30
|
def _strip_comment(line: str) -> str:
|
|
18
31
|
if "#" in line:
|
|
19
32
|
line = line.split("#", 1)[0]
|
|
20
33
|
return line.strip()
|
|
21
34
|
|
|
22
|
-
def _convert_value(val):
|
|
23
|
-
parts = val.replace(",", " ").split()
|
|
24
|
-
if len(parts) == 1:
|
|
25
|
-
return _convert_scalar(parts[0])
|
|
26
|
-
return tuple(_convert_scalar(p) for p in parts)
|
|
27
35
|
|
|
28
36
|
def _as_bool(token: str) -> Optional[bool]:
|
|
29
37
|
t = token.strip().upper()
|
|
@@ -33,20 +41,8 @@ def _as_bool(token: str) -> Optional[bool]:
|
|
|
33
41
|
return False
|
|
34
42
|
return None
|
|
35
43
|
|
|
36
|
-
def _parse_atom_list(tokens: List[str]) -> List[int]:
|
|
37
|
-
out: List[int] = []
|
|
38
|
-
for tok in tokens:
|
|
39
|
-
tok = tok.strip()
|
|
40
|
-
if not tok:
|
|
41
|
-
continue
|
|
42
|
-
try:
|
|
43
|
-
out.append(int(tok))
|
|
44
|
-
except ValueError as e:
|
|
45
|
-
raise ValueError(f"Expected integer MO index, got: {tok!r}") from e
|
|
46
|
-
return out
|
|
47
44
|
|
|
48
45
|
def _parse_value(tokens: List[str], *, keep_as_string: bool = False) -> Value:
|
|
49
|
-
|
|
50
46
|
if not tokens:
|
|
51
47
|
return None
|
|
52
48
|
|
|
@@ -90,6 +86,7 @@ def _parse_value(tokens: List[str], *, keep_as_string: bool = False) -> Value:
|
|
|
90
86
|
parsed.append(tok)
|
|
91
87
|
return parsed
|
|
92
88
|
|
|
89
|
+
|
|
93
90
|
def read_input(filepath: Union[str, Path] = "INPUT.txt"):
|
|
94
91
|
|
|
95
92
|
path = Path(filepath).expanduser().resolve()
|
|
@@ -102,21 +99,19 @@ def read_input(filepath: Union[str, Path] = "INPUT.txt"):
|
|
|
102
99
|
post: Dict[str, Any] = {}
|
|
103
100
|
orca_raw_lines: List[str] = []
|
|
104
101
|
current_block: Optional[str] = None
|
|
105
|
-
|
|
106
|
-
"KEYWORD_LINE",
|
|
107
|
-
"PROGRAM",
|
|
108
|
-
"MOLECULAR_COORDINATES",
|
|
109
|
-
"SCALE",
|
|
110
|
-
}
|
|
102
|
+
|
|
111
103
|
orca_block_name = "ORCA_BLOCK"
|
|
104
|
+
|
|
112
105
|
lines = path.read_text(encoding="utf-8", errors="replace").splitlines()
|
|
113
106
|
for lineno, raw in enumerate(lines, start=1):
|
|
114
107
|
line = _strip_comment(raw)
|
|
115
108
|
if not line:
|
|
116
109
|
continue
|
|
117
110
|
upper = line.strip().upper()
|
|
111
|
+
|
|
112
|
+
# ---- block open ----
|
|
118
113
|
if upper.startswith("BEGIN_"):
|
|
119
|
-
blk = upper[len("BEGIN_")
|
|
114
|
+
blk = upper[len("BEGIN_"):].strip()
|
|
120
115
|
current_block = blk
|
|
121
116
|
if blk == orca_block_name:
|
|
122
117
|
orca_raw_lines = []
|
|
@@ -124,41 +119,51 @@ def read_input(filepath: Union[str, Path] = "INPUT.txt"):
|
|
|
124
119
|
blocks.setdefault(blk, {})
|
|
125
120
|
continue
|
|
126
121
|
|
|
122
|
+
# ---- block close ----
|
|
127
123
|
if upper.startswith("END_"):
|
|
128
|
-
blk = upper[len("END_")
|
|
124
|
+
blk = upper[len("END_"):].strip()
|
|
129
125
|
if current_block != blk:
|
|
130
126
|
raise ValueError(
|
|
131
|
-
f"INPUT.txt block mismatch at line {lineno}:
|
|
127
|
+
f"INPUT.txt block mismatch at line {lineno}: "
|
|
128
|
+
f"END_{blk} while inside {current_block}"
|
|
132
129
|
)
|
|
133
130
|
if blk == orca_block_name:
|
|
134
|
-
blocks[orca_block_name] = {
|
|
131
|
+
blocks[orca_block_name] = {
|
|
132
|
+
"raw": "\n".join(orca_raw_lines).rstrip()
|
|
133
|
+
+ ("\n" if orca_raw_lines else "")
|
|
134
|
+
}
|
|
135
135
|
current_block = None
|
|
136
136
|
continue
|
|
137
137
|
|
|
138
|
+
# ---- raw ORCA block lines ----
|
|
138
139
|
if current_block == orca_block_name:
|
|
139
140
|
orca_raw_lines.append(raw.rstrip("\n"))
|
|
140
141
|
continue
|
|
141
142
|
|
|
143
|
+
# ---- key-value pair ----
|
|
142
144
|
parts = line.split()
|
|
143
145
|
key = parts[0].strip()
|
|
144
146
|
val_tokens = parts[1:]
|
|
145
147
|
key_upper = key.upper()
|
|
146
|
-
keep_as_string = key_upper in
|
|
148
|
+
keep_as_string = key_upper in _KEEP_STRING_KEYS
|
|
147
149
|
value = _parse_value(val_tokens, keep_as_string=keep_as_string)
|
|
148
150
|
|
|
149
151
|
if current_block is None:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
# Module switches: GRID_MODULE, VERTICAL_PROFILE, HORIZONTAL_PROFILE
|
|
153
|
+
if key_upper in _MODULE_KEYS or key_upper.endswith("_MODULE"):
|
|
154
|
+
b: Optional[bool] = None
|
|
152
155
|
if isinstance(value, bool):
|
|
153
156
|
b = value
|
|
154
157
|
elif isinstance(value, str):
|
|
155
|
-
|
|
156
|
-
b = bb
|
|
158
|
+
b = _as_bool(value)
|
|
157
159
|
if b is None:
|
|
158
|
-
raise ValueError(
|
|
160
|
+
raise ValueError(
|
|
161
|
+
f"Invalid module switch value for {key} at line {lineno}: {value!r}"
|
|
162
|
+
)
|
|
159
163
|
modules[key_upper] = b
|
|
160
164
|
else:
|
|
161
165
|
general[key_upper] = value
|
|
166
|
+
|
|
162
167
|
else:
|
|
163
168
|
blk_dict = blocks.setdefault(current_block, {})
|
|
164
169
|
if current_block == "ORBITALS":
|
|
@@ -173,7 +178,8 @@ def read_input(filepath: Union[str, Path] = "INPUT.txt"):
|
|
|
173
178
|
ints.append(int(v))
|
|
174
179
|
else:
|
|
175
180
|
raise ValueError(
|
|
176
|
-
f"Invalid MO list for {key} in ORBITALS block
|
|
181
|
+
f"Invalid MO list for {key} in ORBITALS block "
|
|
182
|
+
f"at line {lineno}: {value!r}"
|
|
177
183
|
)
|
|
178
184
|
blk_dict[key_upper] = ints
|
|
179
185
|
elif isinstance(value, int):
|
|
@@ -184,26 +190,31 @@ def read_input(filepath: Union[str, Path] = "INPUT.txt"):
|
|
|
184
190
|
)
|
|
185
191
|
else:
|
|
186
192
|
blk_dict[key_upper] = value
|
|
193
|
+
|
|
194
|
+
# ---- post-processing keys ----
|
|
187
195
|
post_keys = {
|
|
188
196
|
"RING_CURRENT_STRENGHT",
|
|
189
197
|
"INTEGRAL_NICS",
|
|
190
|
-
"BINDZ_VALUES"
|
|
198
|
+
"BINDZ_VALUES",
|
|
191
199
|
}
|
|
192
200
|
for k in list(general.keys()):
|
|
193
201
|
if k in post_keys:
|
|
194
202
|
post[k] = general.pop(k)
|
|
203
|
+
|
|
195
204
|
config: Dict[str, Any] = {
|
|
196
205
|
"general": general,
|
|
197
206
|
"modules": modules,
|
|
198
207
|
"_meta": {"path": str(path)},
|
|
199
208
|
}
|
|
200
209
|
|
|
210
|
+
# Expose known blocks at top level for easy access
|
|
211
|
+
# New names: VP (Vertical Profile) and HP (Horizontal Profile)
|
|
201
212
|
if "GRID" in blocks:
|
|
202
213
|
config["GRID"] = blocks["GRID"]
|
|
203
|
-
if "
|
|
204
|
-
config["
|
|
205
|
-
if "
|
|
206
|
-
config["
|
|
214
|
+
if "VP" in blocks:
|
|
215
|
+
config["VP"] = blocks["VP"]
|
|
216
|
+
if "HP" in blocks:
|
|
217
|
+
config["HP"] = blocks["HP"]
|
|
207
218
|
if "ORBITALS" in blocks:
|
|
208
219
|
config["ORBITALS"] = blocks["ORBITALS"]
|
|
209
220
|
if "ORCA_BLOCK" in blocks:
|
|
@@ -213,5 +224,6 @@ def read_input(filepath: Union[str, Path] = "INPUT.txt"):
|
|
|
213
224
|
|
|
214
225
|
return config
|
|
215
226
|
|
|
227
|
+
|
|
216
228
|
if __name__ == "__main__":
|
|
217
229
|
cfg = read_input("INPUT.txt")
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
|
-
import re
|
|
5
|
-
import math
|
|
6
|
-
|
|
7
4
|
def iter_atoms(ase_atoms):
|
|
8
5
|
for sym, (x, y, z) in zip(ase_atoms.get_chemical_symbols(), ase_atoms.get_positions()):
|
|
9
6
|
yield sym, float(x), float(y), float(z)
|
|
@@ -12,16 +9,7 @@ def chunks(seq, n):
|
|
|
12
9
|
for i in range(0, len(seq), n):
|
|
13
10
|
yield seq[i:i+n]
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
if not text:
|
|
17
|
-
return False
|
|
18
|
-
return re.search(rf"^\s*{token}\b", text, re.IGNORECASE | re.MULTILINE) is not None
|
|
19
|
-
|
|
20
|
-
def maxcore_mb(memory_gb, procs):
|
|
21
|
-
procs = max(1, int(procs))
|
|
22
|
-
return max(1, int(math.floor((memory_gb * 1024) / procs)))
|
|
23
|
-
|
|
24
|
-
# ---------------- Guassian ----------------
|
|
12
|
+
# ---------------- Gaussian ----------------
|
|
25
13
|
|
|
26
14
|
def write_g16(fname, ase_atoms, bq_pts, cfg):
|
|
27
15
|
mem = cfg.get("memory", 16)
|
|
@@ -43,14 +31,11 @@ def write_g16(fname, ase_atoms, bq_pts, cfg):
|
|
|
43
31
|
for bq in bq_pts:
|
|
44
32
|
x, y, z = bq[-3], bq[-2], bq[-1]
|
|
45
33
|
f.write(f"Bq {x:14.8f} {y:14.8f} {z:14.8f}\n")
|
|
46
|
-
# f.write("\n")
|
|
47
34
|
|
|
48
35
|
# ---------------- ORCA ----------------
|
|
49
36
|
|
|
50
37
|
def write_orca(fname, ase_atoms, bq_pts, cfg):
|
|
51
38
|
kline = cfg.get("keyword_line", "CAM-B3LYP def2-TZVP").strip()
|
|
52
|
-
procs = cfg.get("procs", 1)
|
|
53
|
-
mem_gb = cfg.get("memory", 16)
|
|
54
39
|
charge = cfg.get("charge", 0)
|
|
55
40
|
mult = cfg.get("multiplicity", 1)
|
|
56
41
|
user = cfg.get("orca_block")
|
|
@@ -60,7 +45,7 @@ def write_orca(fname, ase_atoms, bq_pts, cfg):
|
|
|
60
45
|
if not kline.startswith("!"):
|
|
61
46
|
kline = "! " + kline
|
|
62
47
|
f.write(kline + "\n")
|
|
63
|
-
|
|
48
|
+
|
|
64
49
|
if user:
|
|
65
50
|
f.write(user.rstrip() + "\n\n")
|
|
66
51
|
|
|
@@ -85,9 +70,7 @@ def make_inputs(stub, ase_atoms, pts, cfg):
|
|
|
85
70
|
|
|
86
71
|
count = 0
|
|
87
72
|
for k, block in enumerate(chunks(pts, da_max)):
|
|
88
|
-
#
|
|
89
|
-
|
|
90
|
-
# If all fits in a single input, avoid the _0000 suffix
|
|
73
|
+
# Single chunk → no numeric suffix for cleaner filenames
|
|
91
74
|
if n <= da_max and k == 0:
|
|
92
75
|
fname = f"{name}.inp"
|
|
93
76
|
else:
|
|
@@ -95,8 +78,6 @@ def make_inputs(stub, ase_atoms, pts, cfg):
|
|
|
95
78
|
|
|
96
79
|
if "gaussian" in program:
|
|
97
80
|
write_g16(fname, ase_atoms, block, cfg)
|
|
98
|
-
elif "orca" in program:
|
|
99
|
-
write_orca(fname, ase_atoms, block, cfg)
|
|
100
81
|
else:
|
|
101
82
|
write_orca(fname, ase_atoms, block, cfg)
|
|
102
83
|
count += 1
|
|
@@ -118,13 +99,10 @@ def flatten_cfg(cfg_struct, section="GRID"):
|
|
|
118
99
|
if isinstance(cfg_struct.get("ORCA_BLOCK"), dict) else None),
|
|
119
100
|
}
|
|
120
101
|
|
|
121
|
-
# Chunk size: how many dummy points per input
|
|
122
|
-
# (make_inputs uses 'da_max', not 'ga_max')
|
|
123
102
|
if section == "GRID":
|
|
124
103
|
flat["da_max"] = int(block.get("GA_MAX", 30) or 30)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
# default big; get_profile overrides per ring anyway
|
|
104
|
+
elif section in ("VP", "PROFILE"):
|
|
105
|
+
# da_max is overridden per-ring in get_profile anyway
|
|
128
106
|
flat["da_max"] = int(block.get("NUM_GA", 1000) or 1000)
|
|
129
107
|
|
|
130
108
|
return flat
|