MoleditPy-linux 4.3.2__tar.gz → 4.4.1__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.
Files changed (81) hide show
  1. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/PKG-INFO +3 -3
  2. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/README.md +2 -2
  3. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/pyproject.toml +1 -1
  4. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/MoleditPy_linux.egg-info/PKG-INFO +3 -3
  5. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/app_state.py +33 -14
  6. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/compute_logic.py +5 -1
  7. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/custom_interactor_style.py +55 -2
  8. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/io_logic.py +89 -15
  9. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/molecular_scene_handler.py +3 -2
  10. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/settings_tabs/settings_3d_tabs.py +14 -0
  11. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/utils/constants.py +9 -1
  12. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/utils/default_settings.py +2 -0
  13. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/LICENSE +0 -0
  14. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/setup.cfg +0 -0
  15. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/MoleditPy_linux.egg-info/SOURCES.txt +0 -0
  16. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/MoleditPy_linux.egg-info/dependency_links.txt +0 -0
  17. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/MoleditPy_linux.egg-info/entry_points.txt +0 -0
  18. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/MoleditPy_linux.egg-info/requires.txt +0 -0
  19. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/MoleditPy_linux.egg-info/top_level.txt +0 -0
  20. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/__init__.py +0 -0
  21. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/__main__.py +0 -0
  22. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/assets/file_icon.ico +0 -0
  23. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/assets/icon.icns +0 -0
  24. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/assets/icon.ico +0 -0
  25. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/assets/icon.png +0 -0
  26. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/core/__init__.py +0 -0
  27. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/core/mol_geometry.py +0 -0
  28. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/core/molecular_data.py +0 -0
  29. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/main.py +0 -0
  30. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/plugins/__init__.py +0 -0
  31. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/plugins/plugin_interface.py +0 -0
  32. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/plugins/plugin_manager.py +0 -0
  33. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/plugins/plugin_manager_window.py +0 -0
  34. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/__init__.py +0 -0
  35. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/about_dialog.py +0 -0
  36. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/align_plane_dialog.py +0 -0
  37. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/alignment_dialog.py +0 -0
  38. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/analysis_window.py +0 -0
  39. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/angle_dialog.py +0 -0
  40. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/atom_item.py +0 -0
  41. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/atom_picking.py +0 -0
  42. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/base_picking_dialog.py +0 -0
  43. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/bond_item.py +0 -0
  44. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/bond_length_dialog.py +0 -0
  45. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/calculation_worker.py +0 -0
  46. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/color_settings_dialog.py +0 -0
  47. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/constrained_optimization_dialog.py +0 -0
  48. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/custom_qt_interactor.py +0 -0
  49. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/dialog_3d_picking_mixin.py +0 -0
  50. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/dialog_logic.py +0 -0
  51. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/dihedral_dialog.py +0 -0
  52. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/edit_3d_logic.py +0 -0
  53. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/edit_actions_logic.py +0 -0
  54. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/export_logic.py +0 -0
  55. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/geometry_base_dialog.py +0 -0
  56. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/main_window.py +0 -0
  57. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/main_window_init.py +0 -0
  58. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/mirror_dialog.py +0 -0
  59. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/molecule_scene.py +0 -0
  60. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/move_group_dialog.py +0 -0
  61. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/move_selected_atoms_dialog.py +0 -0
  62. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/periodic_table_dialog.py +0 -0
  63. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/planarize_dialog.py +0 -0
  64. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/plugin_menu_manager.py +0 -0
  65. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/settings_dialog.py +0 -0
  66. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/settings_tabs/__init__.py +0 -0
  67. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/settings_tabs/settings_2d_tab.py +0 -0
  68. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/settings_tabs/settings_other_tab.py +0 -0
  69. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/settings_tabs/settings_tab_base.py +0 -0
  70. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/string_importers.py +0 -0
  71. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/template_preview_item.py +0 -0
  72. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/template_preview_view.py +0 -0
  73. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/translation_dialog.py +0 -0
  74. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/ui_manager.py +0 -0
  75. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/user_template_dialog.py +0 -0
  76. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/view_3d_logic.py +0 -0
  77. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/ui/zoomable_view.py +0 -0
  78. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/utils/__init__.py +0 -0
  79. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/utils/sip_isdeleted_safe.py +0 -0
  80. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/utils/suppress_log.py +0 -0
  81. {moleditpy_linux-4.3.2 → moleditpy_linux-4.4.1}/src/moleditpy_linux/utils/system_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MoleditPy-linux
3
- Version: 4.3.2
3
+ Version: 4.4.1
4
4
  Summary: A cross-platform, simple, and intuitive molecular structure editor built in Python. It allows 2D molecular drawing and 3D structure visualization. It supports exporting structure files for input to DFT calculation software.
5
5
  Author-email: HiroYokoyama <titech.yoko.hiro@gmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -757,7 +757,7 @@ This application combines a modern GUI built with **PyQt6**, powerful cheminform
757
757
  * **Mirror:** Create a mirror image of the molecule across a selected plane (XY, XZ, or YZ).
758
758
  * **Set Bond Length, Angle, & Dihedral Angle:** Set precise numerical values for distances, angles, and torsional angles.
759
759
  * **Constrained Optimization:** Perform force field optimization (MMFF/UFF) while applying fixed constraints to specific distances, angles, or dihedral angles.
760
- * **3D Measurement Tools:** A dedicated "Measure" mode allows you to click on atoms in the 3D view to instantly measure and display:
760
+ * **3D Measurement Tools:** The "Select" mode allows you to click on atoms in the 3D view to instantly measure and display:
761
761
  * **Distance** (between 2 atoms)
762
762
  * **Angle** (between 3 atoms)
763
763
  * **Dihedral Angle** (between 4 atoms)
@@ -893,7 +893,7 @@ Additionally, please cite the plugins you used.
893
893
  * **鏡像作成:** 選択した平面 (XY, XZ, YZ) に対して分子の鏡像を作成します。
894
894
  * **結合長・角度・二面角:** 原子を選択し、目標値を入力することで、距離、角度、ねじれ角を正確に設定します。
895
895
  * **制約付き最適化:** 特定の距離、角度、二面角を固定したまま、力場計算 (MMFF/UFF) による構造最適化を実行します。
896
- * **3D測定ツール:** 専用の「Measure」モードで3Dビュー内の原子をクリックするだけで、以下の値を即座に測定・表示します。
896
+ * **3D測定ツール:** 「Select」モードで3Dビュー内の原子をクリックするだけで、以下の値を即座に測定・表示します。
897
897
  * **距離** (2原子間)
898
898
  * **角度** (3原子間)
899
899
  * **二面角** (4原子間)
@@ -54,7 +54,7 @@ This application combines a modern GUI built with **PyQt6**, powerful cheminform
54
54
  * **Mirror:** Create a mirror image of the molecule across a selected plane (XY, XZ, or YZ).
55
55
  * **Set Bond Length, Angle, & Dihedral Angle:** Set precise numerical values for distances, angles, and torsional angles.
56
56
  * **Constrained Optimization:** Perform force field optimization (MMFF/UFF) while applying fixed constraints to specific distances, angles, or dihedral angles.
57
- * **3D Measurement Tools:** A dedicated "Measure" mode allows you to click on atoms in the 3D view to instantly measure and display:
57
+ * **3D Measurement Tools:** The "Select" mode allows you to click on atoms in the 3D view to instantly measure and display:
58
58
  * **Distance** (between 2 atoms)
59
59
  * **Angle** (between 3 atoms)
60
60
  * **Dihedral Angle** (between 4 atoms)
@@ -190,7 +190,7 @@ Additionally, please cite the plugins you used.
190
190
  * **鏡像作成:** 選択した平面 (XY, XZ, YZ) に対して分子の鏡像を作成します。
191
191
  * **結合長・角度・二面角:** 原子を選択し、目標値を入力することで、距離、角度、ねじれ角を正確に設定します。
192
192
  * **制約付き最適化:** 特定の距離、角度、二面角を固定したまま、力場計算 (MMFF/UFF) による構造最適化を実行します。
193
- * **3D測定ツール:** 専用の「Measure」モードで3Dビュー内の原子をクリックするだけで、以下の値を即座に測定・表示します。
193
+ * **3D測定ツール:** 「Select」モードで3Dビュー内の原子をクリックするだけで、以下の値を即座に測定・表示します。
194
194
  * **距離** (2原子間)
195
195
  * **角度** (3原子間)
196
196
  * **二面角** (4原子間)
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
  [project]
6
6
  name = "MoleditPy-linux"
7
7
 
8
- version = "4.3.2"
8
+ version = "4.4.1"
9
9
 
10
10
  license = {file = "LICENSE"}
11
11
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MoleditPy-linux
3
- Version: 4.3.2
3
+ Version: 4.4.1
4
4
  Summary: A cross-platform, simple, and intuitive molecular structure editor built in Python. It allows 2D molecular drawing and 3D structure visualization. It supports exporting structure files for input to DFT calculation software.
5
5
  Author-email: HiroYokoyama <titech.yoko.hiro@gmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -757,7 +757,7 @@ This application combines a modern GUI built with **PyQt6**, powerful cheminform
757
757
  * **Mirror:** Create a mirror image of the molecule across a selected plane (XY, XZ, or YZ).
758
758
  * **Set Bond Length, Angle, & Dihedral Angle:** Set precise numerical values for distances, angles, and torsional angles.
759
759
  * **Constrained Optimization:** Perform force field optimization (MMFF/UFF) while applying fixed constraints to specific distances, angles, or dihedral angles.
760
- * **3D Measurement Tools:** A dedicated "Measure" mode allows you to click on atoms in the 3D view to instantly measure and display:
760
+ * **3D Measurement Tools:** The "Select" mode allows you to click on atoms in the 3D view to instantly measure and display:
761
761
  * **Distance** (between 2 atoms)
762
762
  * **Angle** (between 3 atoms)
763
763
  * **Dihedral Angle** (between 4 atoms)
@@ -893,7 +893,7 @@ Additionally, please cite the plugins you used.
893
893
  * **鏡像作成:** 選択した平面 (XY, XZ, YZ) に対して分子の鏡像を作成します。
894
894
  * **結合長・角度・二面角:** 原子を選択し、目標値を入力することで、距離、角度、ねじれ角を正確に設定します。
895
895
  * **制約付き最適化:** 特定の距離、角度、二面角を固定したまま、力場計算 (MMFF/UFF) による構造最適化を実行します。
896
- * **3D測定ツール:** 専用の「Measure」モードで3Dビュー内の原子をクリックするだけで、以下の値を即座に測定・表示します。
896
+ * **3D測定ツール:** 「Select」モードで3Dビュー内の原子をクリックするだけで、以下の値を即座に測定・表示します。
897
897
  * **距離** (2原子間)
898
898
  * **角度** (3原子間)
899
899
  * **二面角** (4原子間)
@@ -420,6 +420,19 @@ class StateManager:
420
420
  # Skip property access if atom data is inconsistent
421
421
  original_id = None
422
422
 
423
+ # Implicit/explicit H counts raise on an unsanitized mol
424
+ # (e.g. an XYZ import whose valences never passed
425
+ # sanitization). Default to 0 so the structure still saves
426
+ # and round-trips via the binary rather than being dropped.
427
+ try:
428
+ num_explicit_hs = atom.GetNumExplicitHs()
429
+ except (RuntimeError, ValueError):
430
+ num_explicit_hs = 0
431
+ try:
432
+ num_implicit_hs = atom.GetNumImplicitHs()
433
+ except (RuntimeError, ValueError):
434
+ num_implicit_hs = 0
435
+
423
436
  atom_3d = {
424
437
  "index": i,
425
438
  "symbol": atom.GetSymbol(),
@@ -428,8 +441,8 @@ class StateManager:
428
441
  "y": pos.y,
429
442
  "z": pos.z,
430
443
  "formal_charge": atom.GetFormalCharge(),
431
- "num_explicit_hs": atom.GetNumExplicitHs(),
432
- "num_implicit_hs": atom.GetNumImplicitHs(),
444
+ "num_explicit_hs": num_explicit_hs,
445
+ "num_implicit_hs": num_implicit_hs,
433
446
  # include original editor atom id when available for round-trip
434
447
  "original_id": original_id,
435
448
  }
@@ -462,17 +475,21 @@ class StateManager:
462
475
  "constraints_3d": json_safe_constraints,
463
476
  }
464
477
 
465
- # Molecular info
466
- json_data["molecular_info"] = {
467
- "num_atoms": self.host.view_3d_manager.current_mol.GetNumAtoms(),
468
- "num_bonds": self.host.view_3d_manager.current_mol.GetNumBonds(),
469
- "molecular_weight": Descriptors.MolWt(
470
- self.host.view_3d_manager.current_mol
471
- ),
472
- "formula": rdMolDescriptors.CalcMolFormula(
473
- self.host.view_3d_manager.current_mol
474
- ),
475
- }
478
+ # Molecular info — MolWt/CalcMolFormula can raise on an
479
+ # unsanitized mol; keep it optional so it never blocks the save.
480
+ try:
481
+ json_data["molecular_info"] = {
482
+ "num_atoms": self.host.view_3d_manager.current_mol.GetNumAtoms(),
483
+ "num_bonds": self.host.view_3d_manager.current_mol.GetNumBonds(),
484
+ "molecular_weight": Descriptors.MolWt(
485
+ self.host.view_3d_manager.current_mol
486
+ ),
487
+ "formula": rdMolDescriptors.CalcMolFormula(
488
+ self.host.view_3d_manager.current_mol
489
+ ),
490
+ }
491
+ except (AttributeError, RuntimeError, ValueError, TypeError) as e:
492
+ logging.warning("Could not compute molecular info: %s", e)
476
493
 
477
494
  # Identifiers (SMILES/InChI)
478
495
  try:
@@ -637,7 +654,9 @@ class StateManager:
637
654
  ValueError,
638
655
  TypeError,
639
656
  IndexError,
640
- ): # [RDKIT GUARD] RDKit atom property assignment may fail on invalid ids; skip silently.
657
+ ):
658
+ # [RDKIT GUARD] property set may
659
+ # fail on invalid ids; skip.
641
660
  logging.debug(
642
661
  "Suppressed non-critical error",
643
662
  exc_info=True,
@@ -455,7 +455,8 @@ class ComputeManager:
455
455
  if item:
456
456
  item.has_problem = True
457
457
  item.update()
458
- self.host.init_manager.view_2d.setFocus()
458
+ # Defer so Qt finishes routing the modal result before restoring focus.
459
+ QTimer.singleShot(0, self.host.init_manager.view_2d.setFocus)
459
460
 
460
461
  def _setup_mol_block_for_worker(self, mol: Chem.Mol) -> str:
461
462
  mol_block = self.host.state_manager.data.to_mol_block()
@@ -617,6 +618,9 @@ class ComputeManager:
617
618
  with suppress_log(TypeError, RuntimeError):
618
619
  QMessageBox.critical(self.host, "Calculation Error", msg)
619
620
 
621
+ # Restore 2D editor focus so keyboard shortcuts remain active.
622
+ QTimer.singleShot(0, self.host.init_manager.view_2d.setFocus)
623
+
620
624
  def create_atom_id_mapping(self) -> None:
621
625
  """Map 2D atom IDs to 3D RDKit indices."""
622
626
  if not self.host.view_3d_manager.current_mol:
@@ -25,6 +25,16 @@ from .atom_picking import pick_atom_index_from_screen
25
25
 
26
26
  from rdkit import Geometry
27
27
 
28
+ # VTK's trackball state id for camera rotation (VTKIS_ROTATE); the enum is not
29
+ # exposed to Python, so the literal is used with this name for clarity.
30
+ _VTKIS_ROTATE = 1
31
+
32
+ # Reference 3D-canvas size (px) that camera rotation speed is normalized to.
33
+ # VTK's stock Rotate divides motion by the live render size, so rotation slows
34
+ # as the canvas grows; normalizing to a fixed reference makes the speed
35
+ # window-size independent and matches the feel at the default window size.
36
+ _ROTATION_REFERENCE_SIZE = 640.0
37
+
28
38
 
29
39
  class CustomInteractorStyle(vtkInteractorStyleTrackballCamera):
30
40
  """VTK interactor style extending trackball-camera with 3D atom drag and measurement."""
@@ -81,6 +91,43 @@ class CustomInteractorStyle(vtkInteractorStyleTrackballCamera):
81
91
  # Safe defensive fallback catching AttributeError, RuntimeError
82
92
  logging.debug("Suppressed non-critical error", exc_info=True)
83
93
 
94
+ def _rotate_size_independent(self) -> None:
95
+ """Rotate the camera at a speed that does not depend on canvas size.
96
+
97
+ Mirrors vtkInteractorStyleTrackballCamera::Rotate but normalizes the
98
+ per-pixel azimuth/elevation to a fixed reference size instead of the
99
+ live render size, and scales by the user's rotation-sensitivity setting.
100
+ """
101
+ renderer = self.GetCurrentRenderer()
102
+ interactor = self.GetInteractor()
103
+ if renderer is None or interactor is None:
104
+ return
105
+
106
+ dx = interactor.GetEventPosition()[0] - interactor.GetLastEventPosition()[0]
107
+ dy = interactor.GetEventPosition()[1] - interactor.GetLastEventPosition()[1]
108
+
109
+ sensitivity = 1.0
110
+ mw = self.main_window
111
+ if mw is not None:
112
+ try:
113
+ sensitivity = float(
114
+ mw.get_settings().get("mouse_rotation_sensitivity", 1.0)
115
+ )
116
+ except (AttributeError, TypeError, ValueError):
117
+ sensitivity = 1.0
118
+
119
+ delta = -20.0 / _ROTATION_REFERENCE_SIZE * self.GetMotionFactor() * sensitivity
120
+ camera = renderer.GetActiveCamera()
121
+ camera.Azimuth(dx * delta)
122
+ camera.Elevation(dy * delta)
123
+ camera.OrthogonalizeViewUp()
124
+
125
+ if self.GetAutoAdjustCameraClippingRange():
126
+ renderer.ResetCameraClippingRange()
127
+ if interactor.GetLightFollowCamera():
128
+ renderer.UpdateLightsGeometryToFollowCamera()
129
+ interactor.Render()
130
+
84
131
  def _stop_vtk_left_button_state(self) -> None:
85
132
  """Clear VTK's button/drag state after a custom-handled left click."""
86
133
  try:
@@ -501,8 +548,14 @@ class CustomInteractorStyle(vtkInteractorStyleTrackballCamera):
501
548
  # Custom atom drag
502
549
  self.is_dragging = True
503
550
  else:
504
- # Delegate camera rotation to parent
505
- super().OnMouseMove()
551
+ # Camera interaction. VTK's built-in Rotate divides mouse motion by
552
+ # the live render size, so rotation slows as the canvas grows. Handle
553
+ # the rotate state ourselves for window-size-independent speed;
554
+ # delegate pan/dolly/spin to the parent unchanged.
555
+ if self.GetState() == _VTKIS_ROTATE:
556
+ self._rotate_size_independent()
557
+ else:
558
+ super().OnMouseMove()
506
559
 
507
560
  # Update cursor display
508
561
  is_edit_active = (
@@ -35,7 +35,12 @@ from PyQt6.QtWidgets import (
35
35
  from rdkit import Chem
36
36
  from rdkit.Chem import AllChem, rdGeometry, rdMolTransforms, Descriptors
37
37
 
38
- from ..utils.constants import COVALENT_RADII, DUMMY_XYZ_SYMBOLS, VERSION
38
+ from ..utils.constants import (
39
+ COVALENT_RADII,
40
+ DUMMY_XYZ_SYMBOLS,
41
+ VALID_ELEMENT_SYMBOLS,
42
+ VERSION,
43
+ )
39
44
 
40
45
 
41
46
  class IOManager:
@@ -97,6 +102,38 @@ class IOManager:
97
102
  lines[3] = self.fix_mol_counts_line(lines[3])
98
103
  return "\n".join(lines)
99
104
 
105
+ @staticmethod
106
+ def _is_numeric_token(token: str) -> bool:
107
+ """True if *token* parses as a float."""
108
+ try:
109
+ float(token)
110
+ return True
111
+ except ValueError:
112
+ return False
113
+
114
+ @staticmethod
115
+ def _extract_xyz_coords(tokens: list[str]) -> Optional[Tuple[float, float, float]]:
116
+ """Return the first three float-parseable tokens as (x, y, z).
117
+
118
+ Skips non-numeric separator/label columns so ghost-atom rows like
119
+ ``XX : x y z`` (a colon in the second column) parse the same as a
120
+ standard ``symbol x y z`` row. Returns None if fewer than three numbers
121
+ are present.
122
+ """
123
+ nums: list[float] = []
124
+ for tok in tokens:
125
+ try:
126
+ nums.append(float(tok))
127
+ except ValueError:
128
+ if nums:
129
+ break # trailing non-numeric column after the coordinates
130
+ continue # leading label/separator column before the coordinates
131
+ if len(nums) == 3:
132
+ break
133
+ if len(nums) == 3:
134
+ return (nums[0], nums[1], nums[2])
135
+ return None
136
+
100
137
  def _normalize_xyz_symbol(self, raw_symbol: str) -> Tuple[str, bool]:
101
138
  """Return the RDKit symbol for an XYZ atom and whether it is a dummy."""
102
139
  stripped = raw_symbol.strip()
@@ -105,11 +142,11 @@ class IOManager:
105
142
  if stripped.upper() in DUMMY_XYZ_SYMBOLS:
106
143
  return "*", True
107
144
  symbol = stripped.capitalize()
108
- try:
109
- atomic_num = Chem.GetPeriodicTable().GetAtomicNumber(symbol)
110
- except (RuntimeError, ValueError, TypeError):
111
- return "*", True
112
- if atomic_num <= 0:
145
+ # Membership test rather than GetAtomicNumber(symbol): the latter makes
146
+ # RDKit's C++ layer print an "Element 'Xx' not found" violation to
147
+ # stderr for any dummy/pseudo label even though we catch the exception,
148
+ # which users read as a failed load.
149
+ if symbol not in VALID_ELEMENT_SYMBOLS:
113
150
  return "*", True
114
151
  return symbol, False
115
152
 
@@ -138,9 +175,19 @@ class IOManager:
138
175
 
139
176
  atoms_data = []
140
177
  has_dummy_atoms = False
141
- atom_lines = lines[atom_start : atom_start + num_atoms]
178
+ nonstandard_rows = 0
179
+ atom_end = atom_start + num_atoms
180
+ atom_lines = lines[atom_start:atom_end]
142
181
  if len(atom_lines) < num_atoms:
143
- raise ValueError("XYZ file format error: fewer atom rows than expected")
182
+ # Header count exceeds the rows present (truncated / miscounted file).
183
+ # Load the atoms that are actually there rather than refusing the
184
+ # whole file, so any parseable XYZ still opens.
185
+ logging.warning(
186
+ "XYZ declares %d atoms but only %d rows present; loading %d.",
187
+ num_atoms,
188
+ len(atom_lines),
189
+ len(atom_lines),
190
+ )
144
191
 
145
192
  for i, line in enumerate(atom_lines):
146
193
  parts = line.split()
@@ -149,9 +196,15 @@ class IOManager:
149
196
  raw_symbol = parts[0]
150
197
  symbol, is_dummy = self._normalize_xyz_symbol(raw_symbol)
151
198
  has_dummy_atoms = has_dummy_atoms or is_dummy
152
- atoms_data.append(
153
- (symbol, float(parts[1]), float(parts[2]), float(parts[3]))
154
- )
199
+ coords = self._extract_xyz_coords(parts[1:])
200
+ if coords is None:
201
+ raise ValueError(f"Invalid atom data at line {atom_start + i + 1}")
202
+ # Standard rows put coordinates in the first three columns after the
203
+ # symbol; a non-numeric first column means an extra separator/label
204
+ # (e.g. the ':' in "XX : x y z") was skipped — flag it for the user.
205
+ if not self._is_numeric_token(parts[1]):
206
+ nonstandard_rows += 1
207
+ atoms_data.append((symbol, *coords))
155
208
 
156
209
  if not atoms_data:
157
210
  raise ValueError("No valid atoms found in XYZ file")
@@ -162,6 +215,8 @@ class IOManager:
162
215
  atom = Chem.Atom(symbol)
163
216
  atom.SetIntProp("xyz_unique_id", i)
164
217
  if atom.GetAtomicNum() == 0:
218
+ # Ghost/dummy rows (e.g. "XX : x y z") load as the wildcard "*";
219
+ # stash the real label token so it is kept for round-tripping.
165
220
  atom.SetProp("xyz_original_symbol", atom_lines[i].split()[0])
166
221
  mol.AddAtom(atom)
167
222
  conf.SetAtomPosition(i, rdGeometry.Point3D(x, y, z))
@@ -190,7 +245,16 @@ class IOManager:
190
245
  _set_prop(candidate, "_xyz_charge", charge_val)
191
246
  return candidate
192
247
  else:
193
- self.estimate_bonds_from_distances(mol)
248
+ # Distance-based bonding is best-effort: a failure here must not
249
+ # lose the molecule. The skip/dummy path only needs atoms and
250
+ # coordinates, so fall back to a bond-free structure so that any
251
+ # parseable XYZ still loads.
252
+ try:
253
+ self.estimate_bonds_from_distances(mol)
254
+ except (RuntimeError, ValueError, TypeError, AttributeError) as e:
255
+ logging.warning(
256
+ "Bond estimation failed; loading atoms without bonds: %s", e
257
+ )
194
258
  candidate = mol.GetMol()
195
259
  _set_prop(candidate, "_xyz_charge", charge_val)
196
260
  return candidate
@@ -240,6 +304,8 @@ class IOManager:
240
304
 
241
305
  if final_mol:
242
306
  final_mol.xyz_atom_data = atoms_data
307
+ if nonstandard_rows:
308
+ _set_prop(final_mol, "_xyz_nonstandard_rows", nonstandard_rows)
243
309
  return final_mol
244
310
 
245
311
  def _report_load_error(self, title: str, message: str) -> None:
@@ -866,9 +932,17 @@ class IOManager:
866
932
  self.host.view_3d_manager.update_atom_id_menu_state()
867
933
 
868
934
  if self.host.statusBar():
869
- self.host.statusBar().showMessage(
870
- f"3D Viewer Mode: Loaded {os.path.basename(file_path)}"
871
- )
935
+ message = f"3D Viewer Mode: Loaded {os.path.basename(file_path)}"
936
+ nonstandard = 0
937
+ with suppress_log(AttributeError, KeyError, RuntimeError, TypeError):
938
+ if mol.HasProp("_xyz_nonstandard_rows"):
939
+ nonstandard = mol.GetIntProp("_xyz_nonstandard_rows")
940
+ if nonstandard:
941
+ message += (
942
+ f" (non-standard columns in {nonstandard} row(s); "
943
+ "coordinates read from the numeric columns)"
944
+ )
945
+ self.host.statusBar().showMessage(message)
872
946
  self.host.set_current_file_path(file_path)
873
947
  self.host.set_has_unsaved_changes(False)
874
948
  self.host.state_manager.update_window_title()
@@ -426,11 +426,12 @@ class TemplateMixin:
426
426
  else:
427
427
  angle_step = 2 * math.pi / n
428
428
  start_angle = -math.pi / 2 if n % 2 != 0 else -math.pi / 2 - angle_step / 2
429
+ circumradius = bond_len / (2 * math.sin(math.pi / n))
429
430
  points = [
430
431
  pos
431
432
  + QPointF(
432
- bond_len * math.cos(start_angle + i * angle_step),
433
- bond_len * math.sin(start_angle + i * angle_step),
433
+ circumradius * math.cos(start_angle + i * angle_step),
434
+ circumradius * math.sin(start_angle + i * angle_step),
434
435
  )
435
436
  for i in range(n)
436
437
  ]
@@ -78,6 +78,16 @@ class Settings3DSceneTab(SettingsTabBase):
78
78
  self.projection_combo.addItems(["Perspective", "Orthographic"])
79
79
  form_layout.addRow("Projection Mode:", self.projection_combo)
80
80
 
81
+ # Camera rotation speed (0.10x–3.00x). Speed is normalized to a fixed
82
+ # reference canvas size, so it stays constant regardless of window size.
83
+ self.rotation_sens_slider, self.rotation_sens_label = self._create_slider(
84
+ 10, 300, 100.0
85
+ )
86
+ form_layout.addRow(
87
+ "Mouse Rotation Speed:",
88
+ self._wrap_layout(self.rotation_sens_slider, self.rotation_sens_label),
89
+ )
90
+
81
91
  def _select_color(self) -> None:
82
92
  color = QColorDialog.getColor(QColor(self.current_bg_color), self)
83
93
  if color.isValid():
@@ -111,6 +121,9 @@ class Settings3DSceneTab(SettingsTabBase):
111
121
  if idx >= 0:
112
122
  self.projection_combo.setCurrentIndex(idx)
113
123
 
124
+ sens_val = settings_dict.get("mouse_rotation_sensitivity", 1.0)
125
+ self.rotation_sens_slider.setValue(int(sens_val * 100))
126
+
114
127
  def get_settings(self) -> dict[str, Any]:
115
128
  return {
116
129
  "background_color": self.current_bg_color,
@@ -120,6 +133,7 @@ class Settings3DSceneTab(SettingsTabBase):
120
133
  "specular": self.specular_slider.value() / 100.0,
121
134
  "specular_power": self.spec_power_slider.value(),
122
135
  "projection_mode": self.projection_combo.currentText(),
136
+ "mouse_rotation_sensitivity": self.rotation_sens_slider.value() / 100.0,
123
137
  }
124
138
 
125
139
 
@@ -24,7 +24,8 @@ def _get_version() -> str:
24
24
 
25
25
  try:
26
26
  return version("MoleditPy-linux")
27
- except PackageNotFoundError: # [OPTIONAL] Package not installed in editable mode; fall through to pyproject.toml.
27
+ except PackageNotFoundError:
28
+ # [OPTIONAL] Not installed in editable mode; fall through to pyproject.toml.
28
29
  logging.debug("Suppressed non-critical error", exc_info=True)
29
30
  except ImportError:
30
31
  logging.debug("Suppressed non-critical error", exc_info=True)
@@ -209,6 +210,13 @@ DEFAULT_CPK_COLORS = {
209
210
 
210
211
 
211
212
  pt = Chem.GetPeriodicTable()
213
+ # Real element symbols (H..Og). Membership-test against this instead of calling
214
+ # GetAtomicNumber() on an unknown label: probing the periodic table with a
215
+ # non-element makes RDKit's C++ layer print an alarming "Element 'Xx' not found"
216
+ # violation to stderr even when the Python exception is caught.
217
+ VALID_ELEMENT_SYMBOLS: frozenset[str] = frozenset(
218
+ pt.GetElementSymbol(i) for i in range(1, 119)
219
+ )
212
220
  # 0.3-scaled vdW radii for 3D display only — not physical values
213
221
  VDW_DISPLAY_RADII = {pt.GetElementSymbol(i): pt.GetRvdw(i) * 0.3 for i in range(1, 119)}
214
222
  # Deprecated alias kept for external plugins
@@ -19,6 +19,8 @@ DEFAULT_SETTINGS = {
19
19
  "specular_power": 20,
20
20
  "light_intensity": 1.0,
21
21
  "show_3d_axes": True,
22
+ # Camera rotation speed multiplier for the 3D scene (window-size independent).
23
+ "mouse_rotation_sensitivity": 1.0,
22
24
  # --- 3D Model Parameters (Ball and Stick) ---
23
25
  "ball_stick_atom_scale": 1.0,
24
26
  "ball_stick_bond_radius": 0.1,
File without changes