cdi-stools 0.3.0__tar.gz → 0.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.
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/CHANGELOG.md +20 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/PKG-INFO +1 -1
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/pyproject.toml +1 -1
- cdi_stools-0.3.2/src/cdi_st/__init__.py +4 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/bcdi_core.py +5 -20
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/bcdi_gui.py +332 -11
- cdi_stools-0.3.0/src/cdi_st/__init__.py +0 -11
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/LICENSE +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/README.md +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/CDI_ST_logo.png +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/__main__.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/facets.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_autophase_infer.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_autophase_model.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_autophase_train.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_data_generator.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_dataset.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_demo.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_experimental_loader.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_gui_tabs.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_phase_model.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_phase_retrieval.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_train.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/nn_visualize.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/ortho.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/recon.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/requirements.txt +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/trainlog.py +0 -0
- {cdi_stools-0.3.0 → cdi_stools-0.3.2}/src/cdi_st/viz3d.py +0 -0
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.2] - 2026-11-08
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- The launcher window was missing: `main()` opened the simulation window
|
|
8
|
+
directly, so the data-analysis tabs were unreachable from the installed
|
|
9
|
+
package. The v0.3.0 rewrite of `bcdi_gui.py` had dropped `Launcher`,
|
|
10
|
+
`CDIStSplash`, `MW_Analysis` and `ReportsDialog`. All four are restored, and
|
|
11
|
+
`MW_Sim` keeps its Reports & Suggestions button.
|
|
12
|
+
|
|
13
|
+
## [0.3.1] - 2026-11-08
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- `ModuleNotFoundError: No module named 'bcdi_core'` on launch. The modules
|
|
18
|
+
imported each other as top-level names, which works when the files sit
|
|
19
|
+
together in one folder but not from inside the `cdi_st` package. Imports are
|
|
20
|
+
now package-relative, with a fallback so the files still run directly from a
|
|
21
|
+
plain folder.
|
|
22
|
+
|
|
3
23
|
## [0.3.0] - 2026-11-08
|
|
4
24
|
|
|
5
25
|
Faceted particles, photon-budget noise, detector/sample space, standalone phase
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: cdi-stools
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Coherent Diffraction Imaging Simulation Tools — BCDI simulation and NN-based phase retrieval
|
|
5
5
|
Project-URL: Homepage, https://github.com/SAIDIsoufiane/CDI-St
|
|
6
6
|
Project-URL: Documentation, https://github.com/SAIDIsoufiane/CDI-St#readme
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cdi-stools"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.2"
|
|
8
8
|
description = "Coherent Diffraction Imaging Simulation Tools — BCDI simulation and NN-based phase retrieval"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -13,7 +13,8 @@ try:
|
|
|
13
13
|
import xrayutilities as xu; _HAS_XU=True
|
|
14
14
|
except: xu=None; _HAS_XU=False
|
|
15
15
|
warnings.filterwarnings('ignore')
|
|
16
|
-
import facets, ortho
|
|
16
|
+
if __package__: from . import facets, ortho
|
|
17
|
+
else: import facets, ortho
|
|
17
18
|
|
|
18
19
|
def _6c_R3m(z):
|
|
19
20
|
return [[0,0,z%1],[2/3,1/3,(z+1/3)%1],[1/3,2/3,(z+2/3)%1],[0,0,(1-z)%1],[2/3,1/3,(1-z+1/3)%1],[1/3,2/3,(1-z+2/3)%1]]
|
|
@@ -93,7 +94,7 @@ MATERIAL_PRESETS={
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
def load_cif_as_preset(cif_path):
|
|
96
|
-
|
|
97
|
+
|
|
97
98
|
s=PmgStructure.from_file(cif_path)
|
|
98
99
|
sga=SpacegroupAnalyzer(s,symprec=0.1)
|
|
99
100
|
sg_sym=sga.get_space_group_symbol()
|
|
@@ -124,7 +125,7 @@ def compatible_shapes(n):
|
|
|
124
125
|
return ded(base+['hexagonal']+facets.CUBIC_SHAPES+facets.HEX_SHAPES)
|
|
125
126
|
|
|
126
127
|
def cells_for_size_nm(name,size_nm):
|
|
127
|
-
|
|
128
|
+
|
|
128
129
|
c=BCDIConfig(name);M=c.lattice_vectors_cartesian;t=float(size_nm)*10.
|
|
129
130
|
return tuple(max(1,int(round(t/np.linalg.norm(M[i])))) for i in range(3))
|
|
130
131
|
def find_preset(q):
|
|
@@ -139,7 +140,6 @@ class DislocationConfig:
|
|
|
139
140
|
self.dtype=dtype;self.pos_frac=pos_frac;self.line_dir=line_dir;self.b_angstrom=b_angstrom;self.nu=nu;self.b_edge=b_edge;self.b_screw=b_screw
|
|
140
141
|
|
|
141
142
|
class DislocationLoopConfig:
|
|
142
|
-
"""Prismatic dislocation loop: atomsk-style parameters."""
|
|
143
143
|
def __init__(self,center_frac=(.5,.5,.5),radius_angstrom=20.,b_angstrom=None,
|
|
144
144
|
normal='Z',nu=.3):
|
|
145
145
|
self.center_frac=center_frac;self.radius_angstrom=radius_angstrom
|
|
@@ -504,12 +504,6 @@ class BCDISimulator:
|
|
|
504
504
|
def add_experimental_noise(vol,n_photons=None,photon_mode='total',poisson=True,air_scatter=0,
|
|
505
505
|
readout_noise=0,dark_cps=0,exposure_s=1.,dead_pixels_frac=0,
|
|
506
506
|
hot_pixels_frac=0,counting=True,seed=42):
|
|
507
|
-
"""Photon budget first, then instrument effects.
|
|
508
|
-
|
|
509
|
-
n_photons sets the counting statistics: everything else is relative to it.
|
|
510
|
-
readout_noise applies only to integrating detectors (counting=False); EIGER,
|
|
511
|
-
PILATUS, MAXIPIX, MERLIN and TIMEPIX are photon counting and have none.
|
|
512
|
-
"""
|
|
513
507
|
rng=np.random.default_rng(seed);out=np.asarray(vol,np.float64)
|
|
514
508
|
if air_scatter>0:
|
|
515
509
|
N=out.shape[0];c=N//2;r0=max(1,N//4);x=np.arange(N)-c;QX,QY,QZ=np.meshgrid(x,x,x,indexing='ij')
|
|
@@ -523,26 +517,18 @@ def add_experimental_noise(vol,n_photons=None,photon_mode='total',poisson=True,a
|
|
|
523
517
|
dead_frac=dead_pixels_frac,hot_frac=hot_pixels_frac,seed=seed)
|
|
524
518
|
|
|
525
519
|
def q_sampling(cfg,theta_B_rad=None):
|
|
526
|
-
"""Compare the simulation q voxel with a real detector pixel.
|
|
527
|
-
|
|
528
|
-
The simulated grid is set by the particle size and oversampling; the panel
|
|
529
|
-
grid by pixel size and distance. Matching them 1:1 needs N >> OS, so the
|
|
530
|
-
simulation is deliberately coarser. Returns (dq_sim, dq_pixel, implied_OS).
|
|
531
|
-
"""
|
|
532
520
|
k=2*np.pi/cfg.wavelength_angstrom
|
|
533
521
|
dq_sim=(2*np.pi/cfg.particle_size_angstrom[0])/cfg.TARGET_OVERSAMPLING
|
|
534
522
|
dq_pix=k*(cfg.DETECTOR_PIXEL_UM*1e-6)/cfg.SAMPLE_DETECTOR_DISTANCE_M
|
|
535
523
|
return dq_sim,dq_pix,(2*np.pi/cfg.particle_size_angstrom[0])/dq_pix
|
|
536
524
|
|
|
537
525
|
def offset_report(cfg,theta_B_rad,d2th_deg):
|
|
538
|
-
"""What a 2theta offset does: dq, shift in sim voxels and in real pixels."""
|
|
539
526
|
dq=(4*np.pi/cfg.wavelength_angstrom)*np.cos(theta_B_rad)*np.radians(d2th_deg/2.)
|
|
540
527
|
ds,dp,_=q_sampling(cfg)
|
|
541
528
|
N=cfg.DETECTOR_N_PIXELS
|
|
542
529
|
return dq,dq/ds,dq/dp,abs(dq/ds)>N/2
|
|
543
530
|
|
|
544
531
|
def to_frame(sim,frame='lab',vol=None):
|
|
545
|
-
"""Return (volume, label). 'lab' = orthogonal q; 'det' = raw skewed detector grid."""
|
|
546
532
|
v=sim.diff_volume if vol is None else vol
|
|
547
533
|
if frame!='det': return v,'sample / lab frame (orthogonal q)'
|
|
548
534
|
c=sim.config;tt=np.degrees(sim.reflection['two_theta_rad'])
|
|
@@ -551,7 +537,6 @@ def to_frame(sim,frame='lab',vol=None):
|
|
|
551
537
|
return ortho.lab_to_det(v,sim.q_grids,M,order=3),f'detector frame (raw grid, skew={ortho.skew(M):.3f})'
|
|
552
538
|
|
|
553
539
|
def export_measurement(sim,refl,cfg,filepath,noise_opts=None):
|
|
554
|
-
"""Export simulation as .npz (like real BCDI measurement data)."""
|
|
555
540
|
vol=sim.diff_volume.copy()
|
|
556
541
|
if noise_opts: vol=add_experimental_noise(vol,**noise_opts)
|
|
557
542
|
data={'diffraction_volume':vol,'qx':sim.q_grids['qx'],'qy':sim.q_grids['qy'],'qz':sim.q_grids['qz'],
|
|
@@ -584,7 +569,7 @@ def _sr(label,sid,mn,mx,val,step,jsfn,unit='%'):
|
|
|
584
569
|
|
|
585
570
|
|
|
586
571
|
def _loading_html(title="Rendering 3D..."):
|
|
587
|
-
|
|
572
|
+
|
|
588
573
|
return f'''<div id="loadOvr" style="position:fixed;top:0;left:0;width:100%;height:100%;background:#0d0e12;z-index:99999;display:flex;align-items:center;justify-content:center;flex-direction:column"><div style="color:#4f98a3;font-size:16px;font-weight:700;margin-bottom:20px">{title}</div><div style="width:220px;height:6px;background:#161b22;border-radius:3px;overflow:hidden"><div id="loadBar" style="width:0%;height:100%;background:#4f98a3;border-radius:3px;transition:width 0.3s"></div></div><div id="loadPct" style="color:#8b949e;font-size:11px;margin-top:8px">0%</div></div><script>(function(){{var b=document.getElementById("loadBar"),t=document.getElementById("loadPct"),o=document.getElementById("loadOvr"),p=0;var iv=setInterval(function(){{p=Math.min(p+2+Math.random()*4,90);b.style.width=p+"%";t.innerText=Math.round(p)+"%"}},200);function done(){{clearInterval(iv);b.style.width="100%";t.innerText="100%";setTimeout(function(){{o.style.opacity="0";o.style.transition="opacity 0.3s";setTimeout(function(){{o.style.display="none"}},350)}},200)}};var gd=document.querySelector(".plotly-graph-div");if(gd&&gd.on)gd.on("plotly_afterplot",done);setTimeout(done,8000)}})();</script>'''
|
|
589
574
|
|
|
590
575
|
def lattice_html_with_controls(builder,max_atoms=50000,atom_size=3,show_bonds=False,show_strain=False,show_dislocation=False):
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import sys,tempfile,os
|
|
1
|
+
import sys,tempfile,os,time
|
|
2
2
|
import numpy as np
|
|
3
3
|
from collections import Counter
|
|
4
|
-
from PyQt6.QtCore import Qt,QThread,pyqtSignal,QUrl,QSize,QTimer
|
|
5
|
-
from PyQt6.QtGui import QPalette,QColor,QFont
|
|
4
|
+
from PyQt6.QtCore import Qt,QThread,pyqtSignal,QUrl,QSize,QTimer,QRect
|
|
5
|
+
from PyQt6.QtGui import QPalette,QColor,QFont,QPixmap,QPainter,QBrush,QPen
|
|
6
6
|
from PyQt6.QtWidgets import (QApplication,QMainWindow,QWidget,QTabWidget,QVBoxLayout,QHBoxLayout,
|
|
7
7
|
QFormLayout,QGridLayout,QGroupBox,QLabel,QPushButton,QComboBox,QSpinBox,QDoubleSpinBox,
|
|
8
8
|
QLineEdit,QTableWidget,QTableWidgetItem,QHeaderView,QProgressBar,QMessageBox,QStatusBar,
|
|
9
|
-
QSplitter,QPlainTextEdit,QFrame,QCheckBox,QScrollArea,QFileDialog)
|
|
9
|
+
QSplitter,QPlainTextEdit,QFrame,QCheckBox,QScrollArea,QFileDialog,QSplashScreen)
|
|
10
10
|
try:
|
|
11
11
|
from PyQt6.QtWebEngineWidgets import QWebEngineView; _HAS_WEB=True
|
|
12
12
|
except: _HAS_WEB=False
|
|
@@ -15,11 +15,23 @@ from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
|
|
|
15
15
|
from matplotlib.backends.backend_qtagg import NavigationToolbar2QT as NavigationToolbar
|
|
16
16
|
from matplotlib.figure import Figure
|
|
17
17
|
from mpl_toolkits.axes_grid1 import make_axes_locatable
|
|
18
|
-
|
|
18
|
+
if __package__: # installed as cdi_st
|
|
19
|
+
from .bcdi_core import (MATERIAL_PRESETS,DETECTOR_PRESETS,BCDIConfig,CrystalBuilder,ReflectionCalculator,
|
|
19
20
|
BCDISimulator,DislocationConfig,DislocationLoopConfig,lattice_html_with_controls,bragg_html_with_controls,
|
|
20
21
|
add_experimental_noise,export_measurement,load_cif_as_preset,find_preset,default_shape_for_material,
|
|
21
|
-
compatible_shapes,cells_for_size_nm,to_frame)
|
|
22
|
-
import facets
|
|
22
|
+
compatible_shapes,cells_for_size_nm,to_frame,offset_report)
|
|
23
|
+
from . import facets
|
|
24
|
+
else: # run from a plain folder
|
|
25
|
+
from bcdi_core import (MATERIAL_PRESETS,DETECTOR_PRESETS,BCDIConfig,CrystalBuilder,ReflectionCalculator,
|
|
26
|
+
BCDISimulator,DislocationConfig,DislocationLoopConfig,lattice_html_with_controls,bragg_html_with_controls,
|
|
27
|
+
add_experimental_noise,export_measurement,load_cif_as_preset,find_preset,default_shape_for_material,
|
|
28
|
+
compatible_shapes,cells_for_size_nm,to_frame,offset_report)
|
|
29
|
+
import facets
|
|
30
|
+
try:
|
|
31
|
+
if __package__: from .nn_gui_tabs import T_Gen,T4,T4_Sup,T5,T6
|
|
32
|
+
else: from nn_gui_tabs import T_Gen,T4,T4_Sup,T5,T6
|
|
33
|
+
_HAS_NN=True
|
|
34
|
+
except Exception: _HAS_NN=False
|
|
23
35
|
|
|
24
36
|
QSS="""QMainWindow,QWidget{background:#0d1117;color:#e6edf3;font-family:'Segoe UI','Consolas',sans-serif;font-size:10pt}
|
|
25
37
|
QTabWidget::pane{border:1px solid #30363d;background:#0d1117;top:-1px}QTabBar::tab{background:#161b22;color:#8b949e;padding:10px 22px;margin-right:2px;border:1px solid #30363d;border-bottom:none;border-top-left-radius:6px;border-top-right-radius:6px;font-weight:600;min-width:140px}QTabBar::tab:selected{background:#0d1117;color:#4f98a3;border-bottom:2px solid #4f98a3}QTabBar::tab:disabled{color:#30363d}
|
|
@@ -304,7 +316,6 @@ class T2(QWidget):
|
|
|
304
316
|
self.os.setValue(round(v/25.6,1))
|
|
305
317
|
if hasattr(self,'ang_lbl'): self._ang_info()
|
|
306
318
|
def _ang_info(self):
|
|
307
|
-
from bcdi_core import offset_report
|
|
308
319
|
t=self.custom_angle.value()
|
|
309
320
|
if self.config is None or t<=0.01 or self._rdf is None or not len(self._rdf):
|
|
310
321
|
self.ang_lbl.setText("");return
|
|
@@ -480,24 +491,334 @@ class T3(QWidget):
|
|
|
480
491
|
self.c1.draw();self.c2.draw()
|
|
481
492
|
|
|
482
493
|
# ======================= MAIN =======================
|
|
483
|
-
class
|
|
494
|
+
class ReportsDialog(QWidget):
|
|
495
|
+
RECIPIENT = "saidisoufiane@hotmail.com"
|
|
496
|
+
def __init__(self,parent=None):
|
|
497
|
+
super().__init__(parent,Qt.WindowType.Dialog)
|
|
498
|
+
self.setWindowTitle("Reports & Suggestions");self.setFixedSize(480,360);self.setStyleSheet(QSS)
|
|
499
|
+
v=QVBoxLayout(self);v.setContentsMargins(16,16,16,16);v.setSpacing(10)
|
|
500
|
+
title=QLabel("Reports & Suggestions");title.setStyleSheet("color:#4f98a3;font-size:14pt;font-weight:700");v.addWidget(title)
|
|
501
|
+
info=QLabel("<span style='color:#8b949e;font-size:9pt'>"
|
|
502
|
+
"Both fields are required. "
|
|
503
|
+
"Your default mail client will open with the message ready to send."
|
|
504
|
+
"</span>")
|
|
505
|
+
info.setWordWrap(True);v.addWidget(info)
|
|
506
|
+
v.addWidget(QLabel("Your email:"));self.email_le=QLineEdit();self.email_le.setPlaceholderText("you@example.com");v.addWidget(self.email_le)
|
|
507
|
+
v.addWidget(QLabel("Message:"));self.msg_te=QPlainTextEdit();self.msg_te.setPlaceholderText("Describe the issue or suggestion...");self.msg_te.setMinimumHeight(140);v.addWidget(self.msg_te,1)
|
|
508
|
+
self.status=QLabel("");self.status.setWordWrap(True);self.status.setStyleSheet("font-size:9pt");v.addWidget(self.status)
|
|
509
|
+
br=QHBoxLayout();br.addStretch()
|
|
510
|
+
cancel=QPushButton("Cancel");cancel.setStyleSheet("background:#30363d;padding:7px 14px");cancel.clicked.connect(self.close);br.addWidget(cancel)
|
|
511
|
+
send=QPushButton("Send");send.setStyleSheet("background:#238636;padding:7px 18px;font-weight:600");send.clicked.connect(self._send);br.addWidget(send)
|
|
512
|
+
v.addLayout(br)
|
|
513
|
+
def _validate_email(self,e):
|
|
514
|
+
import re
|
|
515
|
+
return bool(re.match(r"^[^@\s]+@[^@\s]+\.[^@\s]+$",e))
|
|
516
|
+
def _send(self):
|
|
517
|
+
email=self.email_le.text().strip();msg=self.msg_te.toPlainText().strip()
|
|
518
|
+
if not email:
|
|
519
|
+
self.status.setText("<span style='color:#da3633'>Email is required.</span>");return
|
|
520
|
+
if not self._validate_email(email):
|
|
521
|
+
self.status.setText("<span style='color:#da3633'>Please enter a valid email address.</span>");return
|
|
522
|
+
if not msg:
|
|
523
|
+
self.status.setText("<span style='color:#da3633'>Message is required.</span>");return
|
|
524
|
+
# Open the user's default mail client via mailto:
|
|
525
|
+
import urllib.parse,webbrowser
|
|
526
|
+
subject=urllib.parse.quote(f"BCDI Software - Report from {email}")
|
|
527
|
+
body=urllib.parse.quote(f"From: {email}\n\n{msg}")
|
|
528
|
+
url=f"mailto:{self.RECIPIENT}?subject={subject}&body={body}"
|
|
529
|
+
try:
|
|
530
|
+
webbrowser.open(url,new=1)
|
|
531
|
+
self.status.setText(
|
|
532
|
+
f"<span style='color:#3fb950'>\u2713 Opening your mail client. "
|
|
533
|
+
f"Click 'Send' there to deliver the message to {self.RECIPIENT}.</span>"
|
|
534
|
+
)
|
|
535
|
+
QTimer.singleShot(2500,self.close)
|
|
536
|
+
except Exception as e:
|
|
537
|
+
# Fallback: copy mailto URL to clipboard
|
|
538
|
+
try:
|
|
539
|
+
cb=QApplication.clipboard();cb.setText(f"To: {self.RECIPIENT}\nFrom: {email}\n\n{msg}")
|
|
540
|
+
self.status.setText(
|
|
541
|
+
f"<span style='color:#f0883e'>Could not open mail client automatically. "
|
|
542
|
+
f"The message has been copied to clipboard \u2014 please paste it into "
|
|
543
|
+
f"an email to {self.RECIPIENT}.</span>"
|
|
544
|
+
)
|
|
545
|
+
except Exception as e2:
|
|
546
|
+
self.status.setText(f"<span style='color:#da3633'>Failed: {e2}</span>")
|
|
547
|
+
|
|
548
|
+
def _make_reports_button(parent):
|
|
549
|
+
btn=QPushButton("Reports && Suggestions",parent)
|
|
550
|
+
# 60% smaller than the previous version: smaller padding, smaller font, smaller height
|
|
551
|
+
btn.setStyleSheet(
|
|
552
|
+
"background:#1f6feb;color:#fff;padding:1px 6px;border-radius:3px;"
|
|
553
|
+
"font-size:7pt;font-weight:600;border:none"
|
|
554
|
+
)
|
|
555
|
+
btn.setToolTip("Send feedback or report a bug")
|
|
556
|
+
btn.setFixedHeight(16)
|
|
557
|
+
btn.adjustSize()
|
|
558
|
+
btn._dialog=None
|
|
559
|
+
def _open():
|
|
560
|
+
if btn._dialog is None or not btn._dialog.isVisible():
|
|
561
|
+
btn._dialog=ReportsDialog(parent)
|
|
562
|
+
btn._dialog.show();btn._dialog.raise_();btn._dialog.activateWindow()
|
|
563
|
+
btn.clicked.connect(_open)
|
|
564
|
+
return btn
|
|
565
|
+
|
|
566
|
+
class MW_Sim(QMainWindow):
|
|
484
567
|
def __init__(self):
|
|
485
|
-
super().__init__();self.setWindowTitle("BCDI
|
|
568
|
+
super().__init__();self.setWindowTitle("BCDI Simulation");self.resize(1500,960);self.setMinimumSize(1200,800)
|
|
486
569
|
self.tabs=QTabWidget();self.tabs.setDocumentMode(True);self.t1=T1();self.t2=T2();self.t3=T3()
|
|
487
570
|
self.tabs.addTab(self.t1," 1 Material ");self.tabs.addTab(self.t2," 2 Beam ");self.tabs.addTab(self.t3," 3 Results ")
|
|
488
571
|
self.tabs.setTabEnabled(1,False);self.tabs.setTabEnabled(2,False);self.setCentralWidget(self.tabs)
|
|
489
572
|
sb=QStatusBar();self.setStatusBar(sb);sb.showMessage("Build lattice first.")
|
|
490
573
|
self.t1.built.connect(self._ob);self.t1.nb.clicked.connect(lambda:self.tabs.setCurrentIndex(1))
|
|
491
574
|
self.t2.sim_req.connect(self._os);self.t2.nb.clicked.connect(lambda:self.tabs.setCurrentIndex(2));self._sw=None
|
|
575
|
+
self.report_btn=_make_reports_button(self);self._reposition_reports()
|
|
576
|
+
def resizeEvent(self,e):
|
|
577
|
+
super().resizeEvent(e);self._reposition_reports()
|
|
578
|
+
def _reposition_reports(self):
|
|
579
|
+
m=10;h=self.statusBar().height() if self.statusBar() else 0
|
|
580
|
+
self.report_btn.move(self.width()-self.report_btn.width()-m,self.height()-self.report_btn.height()-h-m);self.report_btn.raise_()
|
|
492
581
|
def _ob(self,c,b): self.t2.sc(c,b);self.tabs.setTabEnabled(1,True)
|
|
493
582
|
def _os(self,p):
|
|
494
583
|
self._sw=SW(p['config'],p['builder'],p['hkl']);self._sw.progress.connect(self.t2.pg.setValue);self._sw.log.connect(self.t2.lg.appendPlainText)
|
|
495
584
|
self._sw.done.connect(self._sd);self._sw.failed.connect(self._sf);self._sw.start()
|
|
496
585
|
def _sd(self,s,r,d): self.t2.sb_.setEnabled(True);self.t2.nb.setEnabled(True);self.t3.display(s,r,s.config);self.tabs.setTabEnabled(2,True)
|
|
497
586
|
def _sf(self,m): self.t2.sb_.setEnabled(True);self.t2.lg.appendPlainText(f"FAIL: {m}")
|
|
587
|
+
|
|
588
|
+
class MW_Analysis(QMainWindow):
|
|
589
|
+
def __init__(self,parent=None):
|
|
590
|
+
super().__init__(parent);self.setWindowTitle("BCDI Data Analysis");self.resize(1500,960);self.setMinimumSize(1200,800)
|
|
591
|
+
if not _HAS_NN:
|
|
592
|
+
QMessageBox.critical(self,"Missing module",
|
|
593
|
+
"The data analysis module (nn_gui_tabs) is not available. "
|
|
594
|
+
"Make sure all NN-related files are present.")
|
|
595
|
+
QTimer.singleShot(0,self.close);return
|
|
596
|
+
central=QWidget();vl=QVBoxLayout(central);vl.setContentsMargins(0,0,0,0);vl.setSpacing(0)
|
|
597
|
+
self.tabs=QTabWidget();self.tabs.setDocumentMode(True)
|
|
598
|
+
self.tg=T_Gen();self.t4=T4();self.t4s=T4_Sup();self.t5=T5();self.t6=T6()
|
|
599
|
+
self.tabs.addTab(self.tg,"Generate Data")
|
|
600
|
+
self.tabs.addTab(self.t4,"AutoPhase_NN")
|
|
601
|
+
self.tabs.addTab(self.t4s,"CDI_NN")
|
|
602
|
+
self.tabs.addTab(self.t5,"Reconstruction")
|
|
603
|
+
self.tabs.addTab(self.t6,"3D Viewer")
|
|
604
|
+
self.t5.recon_done.connect(self.t6.set_result)
|
|
605
|
+
vl.addWidget(self.tabs,1)
|
|
606
|
+
self.setCentralWidget(central)
|
|
607
|
+
sb=QStatusBar();self.setStatusBar(sb);sb.showMessage("Generate training data, train models, then run reconstruction.")
|
|
608
|
+
# Reports button bottom-right
|
|
609
|
+
self.report_btn=_make_reports_button(self)
|
|
610
|
+
self._reposition_reports()
|
|
611
|
+
def resizeEvent(self,e):
|
|
612
|
+
super().resizeEvent(e);self._reposition_reports()
|
|
613
|
+
def _reposition_reports(self):
|
|
614
|
+
if hasattr(self,'report_btn'):
|
|
615
|
+
margin=10;sb_h=self.statusBar().height() if self.statusBar() else 0
|
|
616
|
+
self.report_btn.move(self.width()-self.report_btn.width()-margin,
|
|
617
|
+
self.height()-self.report_btn.height()-sb_h-margin)
|
|
618
|
+
self.report_btn.raise_()
|
|
619
|
+
|
|
620
|
+
def _logo_path():
|
|
621
|
+
here = os.path.dirname(os.path.abspath(__file__))
|
|
622
|
+
candidates = [
|
|
623
|
+
os.path.join(here, "CDI_ST_logo.png"),
|
|
624
|
+
os.path.join(here, "CDI_NN_logo.png"),
|
|
625
|
+
os.path.join(here, "logo.png"),
|
|
626
|
+
]
|
|
627
|
+
for c in candidates:
|
|
628
|
+
if os.path.exists(c):
|
|
629
|
+
return c
|
|
630
|
+
return None
|
|
631
|
+
|
|
632
|
+
class CDIStSplash(QSplashScreen):
|
|
633
|
+
def __init__(self):
|
|
634
|
+
# Build the splash pixmap: logo image + space below for loading bar
|
|
635
|
+
logo = _logo_path()
|
|
636
|
+
if logo is not None:
|
|
637
|
+
base_pix = QPixmap(logo)
|
|
638
|
+
if base_pix.isNull():
|
|
639
|
+
base_pix = self._fallback_pixmap()
|
|
640
|
+
else:
|
|
641
|
+
base_pix = self._fallback_pixmap()
|
|
642
|
+
# Scale to a reasonable splash size if needed
|
|
643
|
+
if base_pix.width() > 700:
|
|
644
|
+
base_pix = base_pix.scaledToWidth(700, Qt.TransformationMode.SmoothTransformation)
|
|
645
|
+
# Create a final pixmap with extra space for the loading bar + status text
|
|
646
|
+
BAR_H = 64 # extra height below the logo for bar + text
|
|
647
|
+
full = QPixmap(base_pix.width(), base_pix.height() + BAR_H)
|
|
648
|
+
full.fill(QColor("#0d1117")) # dark background matching app theme
|
|
649
|
+
p = QPainter(full)
|
|
650
|
+
p.drawPixmap(0, 0, base_pix)
|
|
651
|
+
p.end()
|
|
652
|
+
super().__init__(full, Qt.WindowType.WindowStaysOnTopHint)
|
|
653
|
+
self.setFixedSize(full.size())
|
|
654
|
+
self._logo_h = base_pix.height()
|
|
655
|
+
self._bar_h = BAR_H
|
|
656
|
+
self._progress = 0
|
|
657
|
+
self._status = "Loading..."
|
|
658
|
+
# Loading bar overlay (drawn in drawContents)
|
|
659
|
+
def _fallback_pixmap(self):
|
|
660
|
+
pix = QPixmap(640, 280)
|
|
661
|
+
pix.fill(QColor("#0d1117"))
|
|
662
|
+
p = QPainter(pix)
|
|
663
|
+
# Title
|
|
664
|
+
p.setPen(QColor("#e6edf3"))
|
|
665
|
+
f = QFont(); f.setPointSize(48); f.setBold(True); f.setLetterSpacing(QFont.SpacingType.AbsoluteSpacing, 4)
|
|
666
|
+
p.setFont(f)
|
|
667
|
+
p.drawText(QRect(0, 50, 640, 80), Qt.AlignmentFlag.AlignCenter, "CDI-ST")
|
|
668
|
+
# Subtitle
|
|
669
|
+
p.setPen(QColor("#8b949e"))
|
|
670
|
+
f2 = QFont(); f2.setPointSize(13)
|
|
671
|
+
p.setFont(f2)
|
|
672
|
+
p.drawText(QRect(0, 150, 640, 30), Qt.AlignmentFlag.AlignCenter,
|
|
673
|
+
"Coherent Diffraction Imaging Simulation Tools")
|
|
674
|
+
p.end()
|
|
675
|
+
return pix
|
|
676
|
+
def set_progress(self, value, status=""):
|
|
677
|
+
self._progress = max(0, min(100, int(value)))
|
|
678
|
+
if status:
|
|
679
|
+
self._status = status
|
|
680
|
+
self.repaint()
|
|
681
|
+
def drawContents(self, painter):
|
|
682
|
+
# Draw loading bar + status text in the strip below the logo
|
|
683
|
+
w = self.width()
|
|
684
|
+
bar_y_top = self._logo_h + 18
|
|
685
|
+
bar_x = 40
|
|
686
|
+
bar_w = w - 80
|
|
687
|
+
bar_h = 8
|
|
688
|
+
# Track
|
|
689
|
+
painter.setBrush(QBrush(QColor("#161b22")))
|
|
690
|
+
painter.setPen(QPen(QColor("#30363d"), 1))
|
|
691
|
+
painter.drawRoundedRect(bar_x, bar_y_top, bar_w, bar_h, 3, 3)
|
|
692
|
+
# Filled portion
|
|
693
|
+
if self._progress > 0:
|
|
694
|
+
painter.setBrush(QBrush(QColor("#4f98a3")))
|
|
695
|
+
painter.setPen(Qt.PenStyle.NoPen)
|
|
696
|
+
painter.drawRoundedRect(bar_x, bar_y_top, int(bar_w * self._progress / 100.0), bar_h, 3, 3)
|
|
697
|
+
# Status text
|
|
698
|
+
painter.setPen(QColor("#8b949e"))
|
|
699
|
+
f = QFont(); f.setPointSize(9)
|
|
700
|
+
painter.setFont(f)
|
|
701
|
+
painter.drawText(
|
|
702
|
+
QRect(bar_x, bar_y_top + bar_h + 6, bar_w, 18),
|
|
703
|
+
Qt.AlignmentFlag.AlignCenter,
|
|
704
|
+
self._status
|
|
705
|
+
)
|
|
706
|
+
|
|
707
|
+
class Launcher(QMainWindow):
|
|
708
|
+
def __init__(self):
|
|
709
|
+
super().__init__()
|
|
710
|
+
self.setWindowTitle("CDI-ST")
|
|
711
|
+
# Sized so the 678x340 logo fits at a reasonable scale
|
|
712
|
+
self.setFixedSize(560, 540)
|
|
713
|
+
self.sim_window = None
|
|
714
|
+
self.analysis_window = None
|
|
715
|
+
central = QWidget()
|
|
716
|
+
central.setStyleSheet("background:#0d1117")
|
|
717
|
+
v = QVBoxLayout(central)
|
|
718
|
+
v.setContentsMargins(20, 16, 20, 14)
|
|
719
|
+
v.setSpacing(12)
|
|
720
|
+
# Logo image at the top (matches splash screen)
|
|
721
|
+
logo = _logo_path()
|
|
722
|
+
if logo is not None:
|
|
723
|
+
pix = QPixmap(logo)
|
|
724
|
+
if not pix.isNull():
|
|
725
|
+
# Scale so it fits in the launcher width comfortably
|
|
726
|
+
pix = pix.scaledToWidth(520, Qt.TransformationMode.SmoothTransformation)
|
|
727
|
+
logo_label = QLabel()
|
|
728
|
+
logo_label.setPixmap(pix)
|
|
729
|
+
logo_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
730
|
+
logo_label.setStyleSheet("background:transparent")
|
|
731
|
+
v.addWidget(logo_label)
|
|
732
|
+
else:
|
|
733
|
+
self._add_text_header(v)
|
|
734
|
+
else:
|
|
735
|
+
self._add_text_header(v)
|
|
736
|
+
v.addSpacing(6)
|
|
737
|
+
choose = QLabel("Choose a module:")
|
|
738
|
+
choose.setStyleSheet("color:#e6edf3;font-size:10pt;background:transparent")
|
|
739
|
+
v.addWidget(choose)
|
|
740
|
+
# Mode buttons (no tooltips — labels are self-explanatory)
|
|
741
|
+
sim_btn = QPushButton("BCDI Simulation")
|
|
742
|
+
sim_btn.setStyleSheet(
|
|
743
|
+
"background:#238636;color:#fff;padding:14px;border-radius:6px;"
|
|
744
|
+
"font-size:11pt;font-weight:600;text-align:center"
|
|
745
|
+
)
|
|
746
|
+
sim_btn.setMinimumHeight(48)
|
|
747
|
+
sim_btn.clicked.connect(self._open_sim)
|
|
748
|
+
v.addWidget(sim_btn)
|
|
749
|
+
ana_btn = QPushButton("BCDI Data Analysis")
|
|
750
|
+
ana_btn.setStyleSheet(
|
|
751
|
+
"background:#1f6feb;color:#fff;padding:14px;border-radius:6px;"
|
|
752
|
+
"font-size:11pt;font-weight:600;text-align:center"
|
|
753
|
+
)
|
|
754
|
+
ana_btn.setMinimumHeight(48)
|
|
755
|
+
ana_btn.clicked.connect(self._open_analysis)
|
|
756
|
+
v.addWidget(ana_btn)
|
|
757
|
+
v.addSpacing(4)
|
|
758
|
+
# Exit button (smaller, red)
|
|
759
|
+
exit_btn = QPushButton("Exit")
|
|
760
|
+
exit_btn.setStyleSheet(
|
|
761
|
+
"background:#da3633;color:#fff;padding:8px;border-radius:5px;"
|
|
762
|
+
"font-size:10pt;font-weight:600"
|
|
763
|
+
)
|
|
764
|
+
exit_btn.clicked.connect(self._exit_app)
|
|
765
|
+
v.addWidget(exit_btn)
|
|
766
|
+
v.addStretch()
|
|
767
|
+
self.setCentralWidget(central)
|
|
768
|
+
# Software credit bottom-right (small grey)
|
|
769
|
+
self.credit = QLabel("Software developed by Soufiane SAIDI", self)
|
|
770
|
+
self.credit.setStyleSheet(
|
|
771
|
+
"color:#6e7681;font-size:8pt;background:transparent"
|
|
772
|
+
)
|
|
773
|
+
self.credit.adjustSize()
|
|
774
|
+
self._reposition_credit()
|
|
775
|
+
def _add_text_header(self, layout):
|
|
776
|
+
title = QLabel("CDI-ST")
|
|
777
|
+
title.setStyleSheet(
|
|
778
|
+
"color:#e6edf3;font-size:32pt;font-weight:700;"
|
|
779
|
+
"background:transparent;letter-spacing:2px"
|
|
780
|
+
)
|
|
781
|
+
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
782
|
+
layout.addWidget(title)
|
|
783
|
+
sub = QLabel("Coherent Diffraction Imaging Simulation Tools")
|
|
784
|
+
sub.setStyleSheet("color:#8b949e;font-size:10pt;background:transparent")
|
|
785
|
+
sub.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
786
|
+
layout.addWidget(sub)
|
|
787
|
+
def resizeEvent(self, e):
|
|
788
|
+
super().resizeEvent(e)
|
|
789
|
+
self._reposition_credit()
|
|
790
|
+
def _reposition_credit(self):
|
|
791
|
+
if hasattr(self, 'credit'):
|
|
792
|
+
margin = 8
|
|
793
|
+
self.credit.move(
|
|
794
|
+
self.width() - self.credit.width() - margin,
|
|
795
|
+
self.height() - self.credit.height() - margin
|
|
796
|
+
)
|
|
797
|
+
self.credit.raise_()
|
|
798
|
+
def _open_sim(self):
|
|
799
|
+
if self.sim_window is None or not self.sim_window.isVisible():
|
|
800
|
+
self.sim_window = MW_Sim(); self.sim_window.show()
|
|
801
|
+
else:
|
|
802
|
+
self.sim_window.raise_(); self.sim_window.activateWindow()
|
|
803
|
+
def _open_analysis(self):
|
|
804
|
+
if self.analysis_window is None or not self.analysis_window.isVisible():
|
|
805
|
+
self.analysis_window = MW_Analysis(); self.analysis_window.show()
|
|
806
|
+
else:
|
|
807
|
+
self.analysis_window.raise_(); self.analysis_window.activateWindow()
|
|
808
|
+
def _exit_app(self):
|
|
809
|
+
if self.sim_window is not None: self.sim_window.close()
|
|
810
|
+
if self.analysis_window is not None: self.analysis_window.close()
|
|
811
|
+
QApplication.quit()
|
|
812
|
+
|
|
813
|
+
MW=MW_Sim
|
|
814
|
+
|
|
498
815
|
def main():
|
|
499
816
|
app=QApplication(sys.argv);app.setStyle("Fusion");pal=QPalette()
|
|
500
817
|
for r,c in[(QPalette.ColorRole.Window,"#0d1117"),(QPalette.ColorRole.WindowText,"#e6edf3"),(QPalette.ColorRole.Base,"#0d1117"),(QPalette.ColorRole.AlternateBase,"#161b22"),(QPalette.ColorRole.Text,"#e6edf3"),(QPalette.ColorRole.Button,"#21262d"),(QPalette.ColorRole.ButtonText,"#e6edf3"),(QPalette.ColorRole.Highlight,"#1f6feb"),(QPalette.ColorRole.HighlightedText,"#ffffff")]:
|
|
501
818
|
pal.setColor(r,QColor(c))
|
|
502
|
-
app.setPalette(pal);app.setStyleSheet(QSS)
|
|
819
|
+
app.setPalette(pal);app.setStyleSheet(QSS)
|
|
820
|
+
sp=CDIStSplash();sp.show();app.processEvents()
|
|
821
|
+
for pct,msg in[(10,"Initializing Qt..."),(30,"Loading core modules..."),(55,"Loading NN modules..."),(80,"Preparing UI..."),(100,"Ready")]:
|
|
822
|
+
sp.set_progress(pct,msg);app.processEvents();time.sleep(0.18)
|
|
823
|
+
win=Launcher();win.show();sp.finish(win);sys.exit(app.exec())
|
|
503
824
|
if __name__=="__main__": main()
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
CDI-ST: Coherent Diffraction Imaging — Simulation Tools.
|
|
3
|
-
|
|
4
|
-
A Python application for end-to-end Bragg Coherent Diffraction Imaging (BCDI):
|
|
5
|
-
crystal lattice construction, X-ray scattering simulation, neural-network
|
|
6
|
-
phase retrieval, and 3D visualization.
|
|
7
|
-
"""
|
|
8
|
-
__version__ = "0.3.0"
|
|
9
|
-
__author__ = "Soufiane SAIDI"
|
|
10
|
-
__email__ = "saidisoufiane@hotmail.com"
|
|
11
|
-
__license__ = "MIT"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|