Skip to content

Commit 7fef855

Browse files
Copilotdkratzert
andauthored
improve MoleculeWidget docs in README
Agent-Logs-Url: https://github.com/dkratzert/Fastmolwidget/sessions/3a7a33aa-7bd9-4f45-9615-45cb5003b7cc Co-authored-by: dkratzert <[email protected]>
1 parent c6f8210 commit 7fef855

1 file changed

Lines changed: 79 additions & 6 deletions

File tree

README.md

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ all drawn with a pure-Python QPainter backend (no OpenGL required).
1010

1111
![Fastmolwidget showing an ORTEP-style crystal structure](https://github.com/user-attachments/assets/7946ef73-7e74-475d-a5c6-2012243b9f77)
1212

13-
*View of a crystal structure froma CIF file with ADP ellipsoids. The control bar allows toggling display options interactively.*
13+
*View of a crystal structure from a CIF file with ADP ellipsoids. The control bar allows toggling display options interactively.*
1414

1515
## Features
1616

@@ -114,12 +114,85 @@ A self-contained widget combining `MoleculeWidget` with the control bar describe
114114

115115
### `MoleculeWidget(parent=None)`
116116

117-
The low-level renderer. Feed it atom data directly via `open_molecule()`.
117+
The low-level renderer widget. It is a plain `QWidget` subclass that you can drop into any layout.
118+
Provide atom data directly via `open_molecule()` instead of loading a file through `MoleculeLoader`.
118119

119-
- `open_molecule(atoms, cell=None, adps=None, keep_view=False)` — display a new structure
120-
- `grow_molecule(atoms, cell=None, adps=None)` — update atoms while preserving zoom/rotation
121-
- `clear()` — remove all atoms and bonds
122-
- `set_bond_width(width)`, `set_background_color(color)`, `setLabelFont(size)`, `reset_view()`
120+
#### Qt Signals
121+
122+
| Signal | Signature | Emitted when |
123+
|--------|-----------|--------------|
124+
| `atomClicked` | `(label: str)` | The user clicks on an atom; `label` is the atom name (e.g. `"C1"`) |
125+
| `bondClicked` | `(label1: str, label2: str)` | The user clicks on a bond; both atom labels are passed |
126+
127+
#### Data Methods
128+
129+
- **`open_molecule(atoms, cell=None, adps=None, keep_view=False)`**
130+
Load a new set of atoms and reset (or optionally preserve) the view.
131+
- `atoms` — list of `Atomtuple(label, type, x, y, z, part)` in Cartesian coordinates (Å)
132+
- `cell` — optional `(a, b, c, α, β, γ)` tuple of unit-cell parameters (Å / °); required for ADP rendering
133+
- `adps` — optional `dict` mapping atom labels to `(U11, U22, U33, U23, U13, U12)` ADP tensors
134+
- `keep_view` — when `True`, the current zoom, pan, and rotation are preserved (useful for live updates)
135+
136+
- **`grow_molecule(atoms, cell=None, adps=None)`**
137+
Replace the atom set while always preserving the current view.
138+
Equivalent to calling `open_molecule(..., keep_view=True)`.
139+
140+
- **`clear()`**
141+
Remove all atoms and bonds from the display.
142+
143+
#### Display Methods
144+
145+
- **`show_adps(value: bool)`**
146+
Toggle ORTEP-style ADP ellipsoid rendering. When `False`, atoms are drawn as isotropic spheres.
147+
148+
- **`show_labels(value: bool)`**
149+
Show or hide non-hydrogen atom labels.
150+
151+
- **`show_hydrogens(value: bool)`**
152+
Show or hide hydrogen / deuterium atoms and their bonds.
153+
154+
- **`show_round_bonds(value: bool)`**
155+
Switch between 3D-shaded cylinder-style bonds (`True`, default) and flat single-colour bonds (`False`).
156+
157+
- **`set_bond_width(width: int)`**
158+
Set the stroke width for bonds in pixels (valid range: 1–15).
159+
160+
- **`setLabelFont(font_size: int)`**
161+
Set the pixel size used for atom labels.
162+
163+
- **`set_background_color(color: QColor)`**
164+
Change the widget background colour.
165+
166+
- **`reset_view()`**
167+
Reset zoom, pan, and rotation to their defaults.
168+
169+
#### Example — feeding atom data directly
170+
171+
```python
172+
from fastmolwidget import MoleculeWidget
173+
from fastmolwidget.sdm import Atomtuple
174+
175+
mol = MoleculeWidget(parent=self)
176+
177+
atoms = [
178+
Atomtuple(label="C1", type="C", x=0.0, y=0.0, z=0.0, part=0),
179+
Atomtuple(label="O1", type="O", x=1.22, y=0.0, z=0.0, part=0),
180+
Atomtuple(label="H1", type="H", x=-0.5, y=0.94, z=0.0, part=0),
181+
]
182+
183+
# ADP tensors: {atom_label: (U11, U22, U33, U23, U13, U12)}
184+
adps = {
185+
"C1": (0.02, 0.02, 0.02, 0.0, 0.0, 0.0),
186+
"O1": (0.03, 0.03, 0.03, 0.0, 0.0, 0.0),
187+
}
188+
189+
cell = (5.0, 5.0, 5.0, 90.0, 90.0, 90.0) # optional
190+
191+
mol.open_molecule(atoms=atoms, cell=cell, adps=adps)
192+
mol.atomClicked.connect(lambda label: print(f"Selected: {label}"))
193+
194+
layout.addWidget(mol)
195+
```
123196

124197
### `MoleculeLoader(widget)`
125198

0 commit comments

Comments
 (0)