MoleditPy 1.15.1__py3-none-any.whl → 1.16.0__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 (55) hide show
  1. moleditpy/__init__.py +4 -0
  2. moleditpy/__main__.py +29 -19748
  3. moleditpy/main.py +37 -0
  4. moleditpy/modules/__init__.py +36 -0
  5. moleditpy/modules/about_dialog.py +92 -0
  6. moleditpy/modules/align_plane_dialog.py +281 -0
  7. moleditpy/modules/alignment_dialog.py +261 -0
  8. moleditpy/modules/analysis_window.py +197 -0
  9. moleditpy/modules/angle_dialog.py +428 -0
  10. moleditpy/modules/assets/icon.icns +0 -0
  11. moleditpy/modules/atom_item.py +336 -0
  12. moleditpy/modules/bond_item.py +303 -0
  13. moleditpy/modules/bond_length_dialog.py +368 -0
  14. moleditpy/modules/calculation_worker.py +754 -0
  15. moleditpy/modules/color_settings_dialog.py +309 -0
  16. moleditpy/modules/constants.py +76 -0
  17. moleditpy/modules/constrained_optimization_dialog.py +667 -0
  18. moleditpy/modules/custom_interactor_style.py +737 -0
  19. moleditpy/modules/custom_qt_interactor.py +49 -0
  20. moleditpy/modules/dialog3_d_picking_mixin.py +96 -0
  21. moleditpy/modules/dihedral_dialog.py +431 -0
  22. moleditpy/modules/main_window.py +830 -0
  23. moleditpy/modules/main_window_app_state.py +747 -0
  24. moleditpy/modules/main_window_compute.py +1203 -0
  25. moleditpy/modules/main_window_dialog_manager.py +454 -0
  26. moleditpy/modules/main_window_edit_3d.py +531 -0
  27. moleditpy/modules/main_window_edit_actions.py +1449 -0
  28. moleditpy/modules/main_window_export.py +744 -0
  29. moleditpy/modules/main_window_main_init.py +1641 -0
  30. moleditpy/modules/main_window_molecular_parsers.py +956 -0
  31. moleditpy/modules/main_window_project_io.py +429 -0
  32. moleditpy/modules/main_window_string_importers.py +270 -0
  33. moleditpy/modules/main_window_ui_manager.py +567 -0
  34. moleditpy/modules/main_window_view_3d.py +1163 -0
  35. moleditpy/modules/main_window_view_loaders.py +350 -0
  36. moleditpy/modules/mirror_dialog.py +110 -0
  37. moleditpy/modules/molecular_data.py +290 -0
  38. moleditpy/modules/molecule_scene.py +1895 -0
  39. moleditpy/modules/move_group_dialog.py +586 -0
  40. moleditpy/modules/periodic_table_dialog.py +72 -0
  41. moleditpy/modules/planarize_dialog.py +209 -0
  42. moleditpy/modules/settings_dialog.py +1034 -0
  43. moleditpy/modules/template_preview_item.py +148 -0
  44. moleditpy/modules/template_preview_view.py +62 -0
  45. moleditpy/modules/translation_dialog.py +353 -0
  46. moleditpy/modules/user_template_dialog.py +621 -0
  47. moleditpy/modules/zoomable_view.py +98 -0
  48. {moleditpy-1.15.1.dist-info → moleditpy-1.16.0.dist-info}/METADATA +1 -1
  49. moleditpy-1.16.0.dist-info/RECORD +54 -0
  50. moleditpy-1.15.1.dist-info/RECORD +0 -9
  51. /moleditpy/{assets → modules/assets}/icon.ico +0 -0
  52. /moleditpy/{assets → modules/assets}/icon.png +0 -0
  53. {moleditpy-1.15.1.dist-info → moleditpy-1.16.0.dist-info}/WHEEL +0 -0
  54. {moleditpy-1.15.1.dist-info → moleditpy-1.16.0.dist-info}/entry_points.txt +0 -0
  55. {moleditpy-1.15.1.dist-info → moleditpy-1.16.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,368 @@
1
+ from PyQt6.QtWidgets import (
2
+ QDialog, QVBoxLayout, QLabel, QHBoxLayout, QPushButton, QLineEdit, QWidget, QRadioButton, QMessageBox
3
+ )
4
+
5
+ from .dialog3_d_picking_mixin import Dialog3DPickingMixin
6
+
7
+ from PyQt6.QtCore import Qt
8
+ import numpy as np
9
+
10
+ class BondLengthDialog(Dialog3DPickingMixin, QDialog):
11
+ def __init__(self, mol, main_window, preselected_atoms=None, parent=None):
12
+ QDialog.__init__(self, parent)
13
+ Dialog3DPickingMixin.__init__(self)
14
+ self.mol = mol
15
+ self.main_window = main_window
16
+ self.atom1_idx = None
17
+ self.atom2_idx = None
18
+
19
+ # 事前選択された原子を設定
20
+ if preselected_atoms and len(preselected_atoms) >= 2:
21
+ self.atom1_idx = preselected_atoms[0]
22
+ self.atom2_idx = preselected_atoms[1]
23
+
24
+ self.init_ui()
25
+
26
+ def init_ui(self):
27
+ self.setWindowTitle("Adjust Bond Length")
28
+ self.setModal(False) # モードレスにしてクリックを阻害しない
29
+ self.setWindowFlags(Qt.WindowType.Window | Qt.WindowType.WindowStaysOnTopHint) # 常に前面表示
30
+ layout = QVBoxLayout(self)
31
+
32
+ # Instructions
33
+ instruction_label = QLabel("Click two atoms in the 3D view to select a bond, then specify the new length.")
34
+ instruction_label.setWordWrap(True)
35
+ layout.addWidget(instruction_label)
36
+
37
+ # Selected atoms display
38
+ self.selection_label = QLabel("No atoms selected")
39
+ layout.addWidget(self.selection_label)
40
+
41
+ # Current distance display
42
+ self.distance_label = QLabel("")
43
+ layout.addWidget(self.distance_label)
44
+
45
+ # New distance input
46
+ distance_layout = QHBoxLayout()
47
+ distance_layout.addWidget(QLabel("New distance (Å):"))
48
+ self.distance_input = QLineEdit()
49
+ self.distance_input.setPlaceholderText("1.54")
50
+ distance_layout.addWidget(self.distance_input)
51
+ layout.addLayout(distance_layout)
52
+
53
+ # Movement options
54
+ group_box = QWidget()
55
+ group_layout = QVBoxLayout(group_box)
56
+ group_layout.addWidget(QLabel("Movement Options:"))
57
+
58
+ self.atom1_fix_group_radio = QRadioButton("Atom 1: Fixed, Atom 2: Move connected group")
59
+ self.atom1_fix_group_radio.setChecked(True)
60
+ group_layout.addWidget(self.atom1_fix_group_radio)
61
+
62
+ self.atom1_fix_radio = QRadioButton("Atom 1: Fixed, Atom 2: Move atom only")
63
+ group_layout.addWidget(self.atom1_fix_radio)
64
+
65
+ self.both_groups_radio = QRadioButton("Both groups: Move towards center equally")
66
+ group_layout.addWidget(self.both_groups_radio)
67
+
68
+ layout.addWidget(group_box)
69
+
70
+ # Buttons
71
+ button_layout = QHBoxLayout()
72
+ self.clear_button = QPushButton("Clear Selection")
73
+ self.clear_button.clicked.connect(self.clear_selection)
74
+ button_layout.addWidget(self.clear_button)
75
+
76
+ button_layout.addStretch()
77
+
78
+ self.apply_button = QPushButton("Apply")
79
+ self.apply_button.clicked.connect(self.apply_changes)
80
+ self.apply_button.setEnabled(False)
81
+ button_layout.addWidget(self.apply_button)
82
+
83
+ close_button = QPushButton("Close")
84
+ close_button.clicked.connect(self.reject)
85
+ button_layout.addWidget(close_button)
86
+
87
+ layout.addLayout(button_layout)
88
+
89
+ # Connect to main window's picker
90
+ self.picker_connection = None
91
+ self.enable_picking()
92
+
93
+ # 事前選択された原子がある場合は初期表示を更新
94
+ if self.atom1_idx is not None:
95
+ self.show_atom_labels()
96
+ self.update_display()
97
+
98
+ def on_atom_picked(self, atom_idx):
99
+ """原子がピックされたときの処理"""
100
+ if self.atom1_idx is None:
101
+ self.atom1_idx = atom_idx
102
+ elif self.atom2_idx is None:
103
+ self.atom2_idx = atom_idx
104
+ else:
105
+ # Reset and start over
106
+ self.atom1_idx = atom_idx
107
+ self.atom2_idx = None
108
+
109
+ # 原子ラベルを表示
110
+ self.show_atom_labels()
111
+ self.update_display()
112
+
113
+ def keyPressEvent(self, event):
114
+ """キーボードイベントを処理"""
115
+ if event.key() == Qt.Key.Key_Return or event.key() == Qt.Key.Key_Enter:
116
+ if self.apply_button.isEnabled():
117
+ self.apply_changes()
118
+ event.accept()
119
+ else:
120
+ super().keyPressEvent(event)
121
+
122
+ def closeEvent(self, event):
123
+ """ダイアログが閉じられる時の処理"""
124
+ self.clear_atom_labels()
125
+ self.disable_picking()
126
+ super().closeEvent(event)
127
+
128
+ def reject(self):
129
+ """キャンセル時の処理"""
130
+ self.clear_atom_labels()
131
+ self.disable_picking()
132
+ super().reject()
133
+
134
+ def accept(self):
135
+ """OK時の処理"""
136
+ self.clear_atom_labels()
137
+ self.disable_picking()
138
+ super().accept()
139
+
140
+ def clear_selection(self):
141
+ """選択をクリア"""
142
+ self.atom1_idx = None
143
+ self.atom2_idx = None
144
+ self.clear_selection_labels()
145
+ self.update_display()
146
+
147
+ def show_atom_labels(self):
148
+ """選択された原子にラベルを表示"""
149
+ # 既存のラベルをクリア
150
+ self.clear_atom_labels()
151
+
152
+ # 新しいラベルを表示
153
+ if not hasattr(self, 'selection_labels'):
154
+ self.selection_labels = []
155
+
156
+ selected_atoms = [self.atom1_idx, self.atom2_idx]
157
+ labels = ["1st", "2nd"]
158
+ colors = ["yellow", "yellow"]
159
+
160
+ for i, atom_idx in enumerate(selected_atoms):
161
+ if atom_idx is not None:
162
+ pos = self.main_window.atom_positions_3d[atom_idx]
163
+ label_text = f"{labels[i]}"
164
+
165
+ # ラベルを追加
166
+ label_actor = self.main_window.plotter.add_point_labels(
167
+ [pos], [label_text],
168
+ point_size=20,
169
+ font_size=12,
170
+ text_color=colors[i],
171
+ always_visible=True
172
+ )
173
+ self.selection_labels.append(label_actor)
174
+
175
+ def clear_atom_labels(self):
176
+ """原子ラベルをクリア"""
177
+ if hasattr(self, 'selection_labels'):
178
+ for label_actor in self.selection_labels:
179
+ try:
180
+ self.main_window.plotter.remove_actor(label_actor)
181
+ except:
182
+ pass
183
+ self.selection_labels = []
184
+
185
+ def clear_selection_labels(self):
186
+ """選択ラベルをクリア"""
187
+ if hasattr(self, 'selection_labels'):
188
+ for label_actor in self.selection_labels:
189
+ try:
190
+ self.main_window.plotter.remove_actor(label_actor)
191
+ except:
192
+ pass
193
+ self.selection_labels = []
194
+
195
+ def add_selection_label(self, atom_idx, label_text):
196
+ """選択された原子にラベルを追加"""
197
+ if not hasattr(self, 'selection_labels'):
198
+ self.selection_labels = []
199
+
200
+ # 原子の位置を取得
201
+ pos = self.main_window.atom_positions_3d[atom_idx]
202
+
203
+ # ラベルを追加
204
+ label_actor = self.main_window.plotter.add_point_labels(
205
+ [pos], [label_text],
206
+ point_size=20,
207
+ font_size=12,
208
+ text_color='yellow',
209
+ always_visible=True
210
+ )
211
+ self.selection_labels.append(label_actor)
212
+
213
+ def update_display(self):
214
+ """表示を更新"""
215
+ # 既存のラベルをクリア
216
+ self.clear_selection_labels()
217
+
218
+ if self.atom1_idx is None:
219
+ self.selection_label.setText("No atoms selected")
220
+ self.distance_label.setText("")
221
+ self.apply_button.setEnabled(False)
222
+ # Clear distance input when no selection
223
+ try:
224
+ self.distance_input.clear()
225
+ except Exception:
226
+ pass
227
+ elif self.atom2_idx is None:
228
+ symbol1 = self.mol.GetAtomWithIdx(self.atom1_idx).GetSymbol()
229
+ self.selection_label.setText(f"First atom: {symbol1} (index {self.atom1_idx})")
230
+ self.distance_label.setText("")
231
+ self.apply_button.setEnabled(False)
232
+ # ラベル追加
233
+ self.add_selection_label(self.atom1_idx, "1")
234
+ # Clear distance input while selection is incomplete
235
+ try:
236
+ self.distance_input.clear()
237
+ except Exception:
238
+ pass
239
+ else:
240
+ symbol1 = self.mol.GetAtomWithIdx(self.atom1_idx).GetSymbol()
241
+ symbol2 = self.mol.GetAtomWithIdx(self.atom2_idx).GetSymbol()
242
+ self.selection_label.setText(f"Bond: {symbol1}({self.atom1_idx}) - {symbol2}({self.atom2_idx})")
243
+
244
+ # Calculate current distance
245
+ conf = self.mol.GetConformer()
246
+ pos1 = np.array(conf.GetAtomPosition(self.atom1_idx))
247
+ pos2 = np.array(conf.GetAtomPosition(self.atom2_idx))
248
+ current_distance = np.linalg.norm(pos2 - pos1)
249
+ self.distance_label.setText(f"Current distance: {current_distance:.3f} Å")
250
+ self.apply_button.setEnabled(True)
251
+ # Update the distance input box to show current distance
252
+ try:
253
+ self.distance_input.setText(f"{current_distance:.3f}")
254
+ except Exception:
255
+ pass
256
+ # ラベル追加
257
+ self.add_selection_label(self.atom1_idx, "1")
258
+ self.add_selection_label(self.atom2_idx, "2")
259
+
260
+ def apply_changes(self):
261
+ """変更を適用"""
262
+ if self.atom1_idx is None or self.atom2_idx is None:
263
+ return
264
+
265
+ try:
266
+ new_distance = float(self.distance_input.text())
267
+ if new_distance <= 0:
268
+ QMessageBox.warning(self, "Invalid Input", "Distance must be positive.")
269
+ return
270
+ except ValueError:
271
+ QMessageBox.warning(self, "Invalid Input", "Please enter a valid number.")
272
+ return
273
+
274
+ # Undo状態を保存
275
+ self.main_window.push_undo_state()
276
+
277
+ # Apply the bond length change
278
+ self.adjust_bond_length(new_distance)
279
+
280
+ # キラルラベルを更新
281
+ self.main_window.update_chiral_labels()
282
+
283
+ def adjust_bond_length(self, new_distance):
284
+ """結合長を調整"""
285
+ conf = self.mol.GetConformer()
286
+ pos1 = np.array(conf.GetAtomPosition(self.atom1_idx))
287
+ pos2 = np.array(conf.GetAtomPosition(self.atom2_idx))
288
+
289
+ # Direction vector from atom1 to atom2
290
+ direction = pos2 - pos1
291
+ current_distance = np.linalg.norm(direction)
292
+
293
+ if current_distance == 0:
294
+ return
295
+
296
+ direction = direction / current_distance
297
+
298
+ if self.both_groups_radio.isChecked():
299
+ # Both groups move towards center equally
300
+ bond_center = (pos1 + pos2) / 2
301
+ half_distance = new_distance / 2
302
+
303
+ # New positions for both atoms
304
+ new_pos1 = bond_center - direction * half_distance
305
+ new_pos2 = bond_center + direction * half_distance
306
+
307
+ # Get both connected groups
308
+ group1_atoms = self.get_connected_group(self.atom1_idx, exclude=self.atom2_idx)
309
+ group2_atoms = self.get_connected_group(self.atom2_idx, exclude=self.atom1_idx)
310
+
311
+ # Calculate displacements
312
+ displacement1 = new_pos1 - pos1
313
+ displacement2 = new_pos2 - pos2
314
+
315
+ # Move group 1
316
+ for atom_idx in group1_atoms:
317
+ current_pos = np.array(conf.GetAtomPosition(atom_idx))
318
+ new_pos = current_pos + displacement1
319
+ conf.SetAtomPosition(atom_idx, new_pos.tolist())
320
+ self.main_window.atom_positions_3d[atom_idx] = new_pos
321
+
322
+ # Move group 2
323
+ for atom_idx in group2_atoms:
324
+ current_pos = np.array(conf.GetAtomPosition(atom_idx))
325
+ new_pos = current_pos + displacement2
326
+ conf.SetAtomPosition(atom_idx, new_pos.tolist())
327
+ self.main_window.atom_positions_3d[atom_idx] = new_pos
328
+
329
+ elif self.atom1_fix_radio.isChecked():
330
+ # Move only the second atom
331
+ new_pos2 = pos1 + direction * new_distance
332
+ conf.SetAtomPosition(self.atom2_idx, new_pos2.tolist())
333
+ self.main_window.atom_positions_3d[self.atom2_idx] = new_pos2
334
+ else:
335
+ # Move the connected group (default behavior)
336
+ new_pos2 = pos1 + direction * new_distance
337
+ atoms_to_move = self.get_connected_group(self.atom2_idx, exclude=self.atom1_idx)
338
+ displacement = new_pos2 - pos2
339
+
340
+ for atom_idx in atoms_to_move:
341
+ current_pos = np.array(conf.GetAtomPosition(atom_idx))
342
+ new_pos = current_pos + displacement
343
+ conf.SetAtomPosition(atom_idx, new_pos.tolist())
344
+ self.main_window.atom_positions_3d[atom_idx] = new_pos
345
+
346
+ # Update the 3D view
347
+ self.main_window.draw_molecule_3d(self.mol)
348
+
349
+ def get_connected_group(self, start_atom, exclude=None):
350
+ """指定された原子から連結されているグループを取得"""
351
+ visited = set()
352
+ to_visit = [start_atom]
353
+
354
+ while to_visit:
355
+ current = to_visit.pop()
356
+ if current in visited or current == exclude:
357
+ continue
358
+
359
+ visited.add(current)
360
+
361
+ # Get neighboring atoms
362
+ atom = self.mol.GetAtomWithIdx(current)
363
+ for bond in atom.GetBonds():
364
+ other_idx = bond.GetOtherAtomIdx(current)
365
+ if other_idx not in visited and other_idx != exclude:
366
+ to_visit.append(other_idx)
367
+
368
+ return visited