pyphyschemtools 0.1.5__py3-none-any.whl → 0.3.2__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.
@@ -283,10 +283,15 @@ class molView:
283
283
  and bond orders (detects double/triple bonds).
284
284
  Requires the `rdkit` library. If False, fallback to standard 3Dmol
285
285
  distance-based single bonds.
286
+ display_now : bool, optional
287
+ If True (default), renders the molecule immediately.
288
+ Set to False to prevent immediate display when you plan to call
289
+ further visualization methods provided by the molView class
286
290
  viewer : bool, optional
287
- If True (default), initializes the py3Dmol viewer and renders the
288
- molecule. If False, operates in 'headless' mode: only coordinates
289
- are processed for calculations (default: True).
291
+ If True (default), initializes the py3Dmol engine and prepares the 3D model.
292
+ If False, operates in 'headless' mode: only geometric data is processed
293
+ for analysis (volume, CM, etc.), saving significant memory for
294
+ high-throughput processing.
290
295
  zoom : None, optional
291
296
  scaling factor
292
297
 
@@ -311,10 +316,12 @@ class molView:
311
316
  >>> vol = mv.data.get_cage_volume()
312
317
  """
313
318
 
314
- def __init__(self, mol, source='file', style='bs', displayHbonds=True, cpk_scale=0.6, w=600, h=400,\
319
+ def __init__(self, mol, source=None, style='bs', displayHbonds=True, cpk_scale=0.6, w=600, h=400,\
315
320
  supercell=(1, 1, 1), display_now=True, detect_BondOrders=True, viewer=True, zoom=None):
321
+ # For the automatic detection or source validation
322
+ valid_sources = ['file', 'mol', 'cif', 'cid', 'rscb', 'cod', 'ase']
323
+
316
324
  self.mol = mol
317
- self.source = source
318
325
  self.style = style
319
326
  self.cpk_scale = cpk_scale
320
327
  self.displayHbonds = displayHbonds
@@ -324,6 +331,19 @@ class molView:
324
331
  self.supercell = supercell
325
332
  self.viewer = viewer
326
333
  self.zoom = zoom
334
+ if source is None and os.path.exists(str(mol)):
335
+ self.source = 'file'
336
+ elif source in valid_sources:
337
+ self.source = source
338
+ else:
339
+ # Clear error message and early exit if the source is unrecognized
340
+ error_msg = f"❌ Invalid source: '{source}'. \nAllowed sources are: {', '.join(valid_sources)}"
341
+ print(error_msg)
342
+ self.data = None
343
+ self.v = None
344
+ return
345
+ # Viewer initialization and data loading
346
+ # We only proceed if the source is valid
327
347
  self.v = py3Dmol.view(width=self.w, height=self.h) # Création du viewer une seule fois
328
348
  self._load_and_display(show=display_now)
329
349
 
@@ -615,7 +635,9 @@ class molView:
615
635
  response = requests.get(url)
616
636
  if response.status_code == 200:
617
637
  content = response.text
618
- fmt = "pdb"
638
+ fmt = "proteindatabank"
639
+ else:
640
+ raise ValueError(f"Could not find PDB ID: {self.mol} on RSCB")
619
641
 
620
642
  elif self.source == 'cod':
621
643
  url = f"https://www.crystallography.net/cod/{self.mol}.cif"
@@ -634,8 +656,21 @@ class molView:
634
656
  if self.source == 'file':
635
657
  if not os.path.exists(self.mol):
636
658
  raise FileNotFoundError(f"File not found: {self.mol}")
659
+
660
+ # Extraction de l'extension sans le point
637
661
  ext = os.path.splitext(self.mol)[1].lower().replace('.', '')
638
- fmt = 'cif' if ext == 'cif' else ext
662
+
663
+ # Mapping explicite pour ASE
664
+ if ext == 'pdb':
665
+ fmt = 'proteindatabank'
666
+ elif ext == 'xyz':
667
+ fmt = 'xyz'
668
+ elif ext == 'cif':
669
+ fmt = 'cif'
670
+ else:
671
+ # Fallback sur l'extension si format exotique
672
+ fmt = ext
673
+
639
674
  with open(self.mol, 'r') as f:
640
675
  content = f.read()
641
676
 
@@ -649,19 +684,28 @@ class molView:
649
684
 
650
685
  # --- EXTRACTION XYZData (Interne) ---
651
686
  # On extrait les données ici avant toute modification (RDKit ou Supercell)
652
- try:
653
- if self.source == 'ase':
654
- temp_atoms = self.mol
655
- else:
656
- temp_atoms = read(io.StringIO(content), format=fmt)
687
+ if self.source == 'ase':
688
+ atoms = self.mol
689
+ else:
690
+ try:
691
+ # On utilise l'alias long d'ASE pour PDB, sinon le format détecté
692
+ atoms = read(io.StringIO(content), format=fmt)
693
+ except (Exception, StopIteration):
694
+ # Si l'extraction échoue, on tente une dernière fois sans format forcé
695
+ try:
696
+ atoms = read(io.StringIO(content))
697
+ except:
698
+ print(f"❌ Extraction of coordinates is impossible for source {self.source}")
699
+ self.data = None
700
+ # --- CRUCIAL : On arrête tout ici si on n'a pas d'atomes ---
701
+ if self.viewer:
702
+ self.v.show() # On montre au moins le viewer vide ou l'erreur
703
+ return
657
704
 
658
705
  self.data = XYZData(
659
- symbols=temp_atoms.get_chemical_symbols(),
660
- positions=temp_atoms.get_positions()
706
+ symbols=atoms.get_chemical_symbols(),
707
+ positions=atoms.get_positions()
661
708
  )
662
- except Exception as e:
663
- print(f"Note: Extraction des coordonnées impossible ({e})")
664
- self.data = None
665
709
 
666
710
  # --- Modern Bond Perception with RDKit ---
667
711
  if self.detect_bonds and self.source in ['file', 'mol', 'xyz'] and fmt == 'xyz':
Binary file
pyphyschemtools/Chem3D.py CHANGED
@@ -283,10 +283,15 @@ class molView:
283
283
  and bond orders (detects double/triple bonds).
284
284
  Requires the `rdkit` library. If False, fallback to standard 3Dmol
285
285
  distance-based single bonds.
286
+ display_now : bool, optional
287
+ If True (default), renders the molecule immediately.
288
+ Set to False to prevent immediate display when you plan to call
289
+ further visualization methods provided by the molView class
286
290
  viewer : bool, optional
287
- If True (default), initializes the py3Dmol viewer and renders the
288
- molecule. If False, operates in 'headless' mode: only coordinates
289
- are processed for calculations (default: True).
291
+ If True (default), initializes the py3Dmol engine and prepares the 3D model.
292
+ If False, operates in 'headless' mode: only geometric data is processed
293
+ for analysis (volume, CM, etc.), saving significant memory for
294
+ high-throughput processing.
290
295
  zoom : None, optional
291
296
  scaling factor
292
297
 
@@ -311,10 +316,12 @@ class molView:
311
316
  >>> vol = mv.data.get_cage_volume()
312
317
  """
313
318
 
314
- def __init__(self, mol, source='file', style='bs', displayHbonds=True, cpk_scale=0.6, w=600, h=400,\
319
+ def __init__(self, mol, source=None, style='bs', displayHbonds=True, cpk_scale=0.6, w=600, h=400,\
315
320
  supercell=(1, 1, 1), display_now=True, detect_BondOrders=True, viewer=True, zoom=None):
321
+ # For the automatic detection or source validation
322
+ valid_sources = ['file', 'mol', 'cif', 'cid', 'rscb', 'cod', 'ase']
323
+
316
324
  self.mol = mol
317
- self.source = source
318
325
  self.style = style
319
326
  self.cpk_scale = cpk_scale
320
327
  self.displayHbonds = displayHbonds
@@ -324,6 +331,19 @@ class molView:
324
331
  self.supercell = supercell
325
332
  self.viewer = viewer
326
333
  self.zoom = zoom
334
+ if source is None and os.path.exists(str(mol)):
335
+ self.source = 'file'
336
+ elif source in valid_sources:
337
+ self.source = source
338
+ else:
339
+ # Clear error message and early exit if the source is unrecognized
340
+ error_msg = f"❌ Invalid source: '{source}'. \nAllowed sources are: {', '.join(valid_sources)}"
341
+ print(error_msg)
342
+ self.data = None
343
+ self.v = None
344
+ return
345
+ # Viewer initialization and data loading
346
+ # We only proceed if the source is valid
327
347
  self.v = py3Dmol.view(width=self.w, height=self.h) # Création du viewer une seule fois
328
348
  self._load_and_display(show=display_now)
329
349
 
@@ -615,7 +635,9 @@ class molView:
615
635
  response = requests.get(url)
616
636
  if response.status_code == 200:
617
637
  content = response.text
618
- fmt = "pdb"
638
+ fmt = "proteindatabank"
639
+ else:
640
+ raise ValueError(f"Could not find PDB ID: {self.mol} on RSCB")
619
641
 
620
642
  elif self.source == 'cod':
621
643
  url = f"https://www.crystallography.net/cod/{self.mol}.cif"
@@ -634,8 +656,21 @@ class molView:
634
656
  if self.source == 'file':
635
657
  if not os.path.exists(self.mol):
636
658
  raise FileNotFoundError(f"File not found: {self.mol}")
659
+
660
+ # Extraction de l'extension sans le point
637
661
  ext = os.path.splitext(self.mol)[1].lower().replace('.', '')
638
- fmt = 'cif' if ext == 'cif' else ext
662
+
663
+ # Mapping explicite pour ASE
664
+ if ext == 'pdb':
665
+ fmt = 'proteindatabank'
666
+ elif ext == 'xyz':
667
+ fmt = 'xyz'
668
+ elif ext == 'cif':
669
+ fmt = 'cif'
670
+ else:
671
+ # Fallback sur l'extension si format exotique
672
+ fmt = ext
673
+
639
674
  with open(self.mol, 'r') as f:
640
675
  content = f.read()
641
676
 
@@ -649,19 +684,28 @@ class molView:
649
684
 
650
685
  # --- EXTRACTION XYZData (Interne) ---
651
686
  # On extrait les données ici avant toute modification (RDKit ou Supercell)
652
- try:
653
- if self.source == 'ase':
654
- temp_atoms = self.mol
655
- else:
656
- temp_atoms = read(io.StringIO(content), format=fmt)
687
+ if self.source == 'ase':
688
+ atoms = self.mol
689
+ else:
690
+ try:
691
+ # On utilise l'alias long d'ASE pour PDB, sinon le format détecté
692
+ atoms = read(io.StringIO(content), format=fmt)
693
+ except (Exception, StopIteration):
694
+ # Si l'extraction échoue, on tente une dernière fois sans format forcé
695
+ try:
696
+ atoms = read(io.StringIO(content))
697
+ except:
698
+ print(f"❌ Extraction of coordinates is impossible for source {self.source}")
699
+ self.data = None
700
+ # --- CRUCIAL : On arrête tout ici si on n'a pas d'atomes ---
701
+ if self.viewer:
702
+ self.v.show() # On montre au moins le viewer vide ou l'erreur
703
+ return
657
704
 
658
705
  self.data = XYZData(
659
- symbols=temp_atoms.get_chemical_symbols(),
660
- positions=temp_atoms.get_positions()
706
+ symbols=atoms.get_chemical_symbols(),
707
+ positions=atoms.get_positions()
661
708
  )
662
- except Exception as e:
663
- print(f"Note: Extraction des coordonnées impossible ({e})")
664
- self.data = None
665
709
 
666
710
  # --- Modern Bond Perception with RDKit ---
667
711
  if self.detect_bonds and self.source in ['file', 'mol', 'xyz'] and fmt == 'xyz':
@@ -1,6 +1,6 @@
1
1
  # tools4pyPhysChem/__init__.py
2
- __version__ = "0.1.5"
3
- __last_update__ = "2026-02-02"
2
+ __version__ = "0.3.2"
3
+ __last_update__ = "2026-02-03"
4
4
 
5
5
  import importlib
6
6
  import importlib.util
@@ -7,9 +7,9 @@
7
7
  viewBox="0 0 178.01071 29.131533"
8
8
  version="1.1"
9
9
  id="svg5"
10
- inkscape:version="1.4.2 (unknown)"
11
- sodipodi:docname="pyPCBanner.svg"
12
- inkscape:export-filename="/home/romuald/ENSEIGNEMENT/0-JupyterNotebooks/L2-CHIM2-ON1/Tutos-Vidéo/Pandas-Stats-Iris/svg/logoPytChem.png"
10
+ inkscape:version="1.4.3 (unknown)"
11
+ sodipodi:docname="pyPC_LPCNO_Banner.svg"
12
+ inkscape:export-filename="pyPC_LPCNO_Banner.png"
13
13
  inkscape:export-xdpi="300.008"
14
14
  inkscape:export-ydpi="300.008"
15
15
  xml:space="preserve"
@@ -30,7 +30,7 @@
30
30
  inkscape:document-units="mm"
31
31
  showgrid="false"
32
32
  inkscape:zoom="2.1549693"
33
- inkscape:cx="154.75858"
33
+ inkscape:cx="154.75859"
34
34
  inkscape:cy="88.168309"
35
35
  inkscape:window-width="2544"
36
36
  inkscape:window-height="1344"