moleditpy 1.3.1__tar.gz → 1.3.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moleditpy
3
- Version: 1.3.1
3
+ Version: 1.3.2
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
  Project-URL: Homepage, https://github.com/HiroYokoyama/python_molecular_editor
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
  [project]
6
6
  name = "moleditpy"
7
7
 
8
- version = "1.3.1"
8
+ version = "1.3.2"
9
9
 
10
10
  authors = [
11
11
  { name="HiroYokoyama", email="titech.yoko.hiro@gmail.com" },
@@ -11,7 +11,7 @@ DOI 10.5281/zenodo.17268532
11
11
  """
12
12
 
13
13
  #Version
14
- VERSION = '1.3.1'
14
+ VERSION = '1.3.2'
15
15
 
16
16
  print("-----------------------------------------------------")
17
17
  print("MoleditPy — A Python-based molecular editing software")
@@ -1522,32 +1522,78 @@ class MoleculeScene(QGraphicsScene):
1522
1522
  target_bonds = [it for it in self.selectedItems() if isinstance(it, BondItem)]
1523
1523
 
1524
1524
  if target_bonds:
1525
- needs_update = False
1525
+ any_bond_changed = False
1526
1526
  for bond in target_bonds:
1527
+ # 1. 結合の向きを考慮して、データ辞書内の現在のキーを正しく特定する
1527
1528
  id1, id2 = bond.atom1.atom_id, bond.atom2.atom_id
1528
- if id1 > id2: id1, id2 = id2, id1
1529
+ current_key = None
1530
+ if (id1, id2) in self.data.bonds:
1531
+ current_key = (id1, id2)
1532
+ elif (id2, id1) in self.data.bonds:
1533
+ current_key = (id2, id1)
1534
+
1535
+ if not current_key: continue
1536
+
1537
+ # 2. 変更前の状態を保存
1538
+ old_order, old_stereo = bond.order, bond.stereo
1539
+
1540
+ # 3. キー入力に応じてBondItemのプロパティを変更
1541
+ if key == Qt.Key.Key_W:
1542
+ if bond.stereo == 1:
1543
+ bond_data = self.data.bonds.pop(current_key)
1544
+ new_key = (current_key[1], current_key[0])
1545
+ self.data.bonds[new_key] = bond_data
1546
+ bond.atom1, bond.atom2 = bond.atom2, bond.atom1
1547
+ bond.update_position()
1548
+ was_reversed = True
1549
+ else:
1550
+ bond.order = 1; bond.stereo = 1
1551
+
1552
+ elif key == Qt.Key.Key_D:
1553
+ if bond.stereo == 2:
1554
+ bond_data = self.data.bonds.pop(current_key)
1555
+ new_key = (current_key[1], current_key[0])
1556
+ self.data.bonds[new_key] = bond_data
1557
+ bond.atom1, bond.atom2 = bond.atom2, bond.atom1
1558
+ bond.update_position()
1559
+ was_reversed = True
1560
+ else:
1561
+ bond.order = 1; bond.stereo = 2
1529
1562
 
1530
- if key == Qt.Key.Key_1 and (bond.order != 1 or bond.stereo != 0):
1531
- bond.order = 1; bond.stereo = 0; needs_update = True
1563
+ elif key == Qt.Key.Key_1 and (bond.order != 1 or bond.stereo != 0):
1564
+ bond.order = 1; bond.stereo = 0
1532
1565
  elif key == Qt.Key.Key_2 and bond.order != 2:
1533
1566
  bond.order = 2; bond.stereo = 0; needs_update = True
1534
1567
  elif key == Qt.Key.Key_3 and bond.order != 3:
1535
1568
  bond.order = 3; bond.stereo = 0; needs_update = True
1536
- elif key == Qt.Key.Key_W and bond.stereo != 1: # Wedge
1537
- bond.order = 1; bond.stereo = 1; needs_update = True
1538
- elif key == Qt.Key.Key_D and bond.stereo != 2: # Dash
1539
- bond.order = 1; bond.stereo = 2; needs_update = True
1540
-
1541
- if needs_update:
1542
- self.data.bonds[(id1, id2)]['order'] = bond.order
1543
- self.data.bonds[(id1, id2)]['stereo'] = bond.stereo
1569
+
1570
+ # 4. 実際に変更があった場合のみデータモデルを更新
1571
+ if old_order != bond.order or old_stereo != bond.stereo:
1572
+ any_bond_changed = True
1573
+
1574
+ # 5. 古いキーでデータを辞書から一度削除
1575
+ bond_data = self.data.bonds.pop(current_key)
1576
+ bond_data['order'] = bond.order
1577
+ bond_data['stereo'] = bond.stereo
1578
+
1579
+ # 6. 変更後の種類に応じて新しいキーを決定し、再登録する
1580
+ new_key_id1, new_key_id2 = bond.atom1.atom_id, bond.atom2.atom_id
1581
+ if bond.stereo == 0:
1582
+ if new_key_id1 > new_key_id2:
1583
+ new_key_id1, new_key_id2 = new_key_id2, new_key_id1
1584
+
1585
+ new_key = (new_key_id1, new_key_id2)
1586
+ self.data.bonds[new_key] = bond_data
1587
+
1544
1588
  bond.update()
1545
1589
 
1546
- if needs_update:
1590
+ if any_bond_changed:
1547
1591
  self.window.push_undo_state()
1592
+
1593
+ if key in [Qt.Key.Key_1, Qt.Key.Key_2, Qt.Key.Key_3, Qt.Key.Key_W, Qt.Key.Key_D]:
1548
1594
  event.accept()
1549
1595
  return
1550
-
1596
+
1551
1597
  # --- 3. Atomに対する操作 (原子の追加 - マージされた機能) ---
1552
1598
  if key == Qt.Key.Key_1:
1553
1599
  start_atom = None
@@ -3505,9 +3551,12 @@ class MainWindow(QMainWindow):
3505
3551
  except Exception as e:
3506
3552
  self.statusBar().showMessage(f"Error loading from InChI: {e}")
3507
3553
 
3508
- def load_mol_file(self):
3509
- options = QFileDialog.Option.DontUseNativeDialog
3510
- file_path, _ = QFileDialog.getOpenFileName(self, "Import MOL File", "", "Chemical Files (*.mol *.sdf);;All Files (*)", options=options)
3554
+ def load_mol_file(self, file_path=None):
3555
+ if not file_path:
3556
+ options = QFileDialog.Option.DontUseNativeDialog
3557
+ file_path, _ = QFileDialog.getOpenFileName(self, "Import MOL File", "", "Chemical Files (*.mol *.sdf);;All Files (*)", options=options)
3558
+ if not file_path: return
3559
+
3511
3560
  if not file_path: return
3512
3561
  try:
3513
3562
  self.dragged_atom_info = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moleditpy
3
- Version: 1.3.1
3
+ Version: 1.3.2
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
  Project-URL: Homepage, https://github.com/HiroYokoyama/python_molecular_editor
File without changes
File without changes