Skip to content

Commit c252b99

Browse files
committed
update test workflows
1 parent 09c3b75 commit c252b99

19 files changed

Lines changed: 4006 additions & 25 deletions

python/pyabacus/CLAUDE.md

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ python/pyabacus/
2727
├── src/
2828
│ ├── pyabacus/ # Python package
2929
│ │ ├── __init__.py # Main package init
30+
│ │ ├── constants.py # Unit conversion constants (single source of truth)
3031
│ │ ├── ase/ # ASE Calculator integration
3132
│ │ │ ├── __init__.py
3233
│ │ │ └── calculator.py # AbacusCalculator class
3334
│ │ ├── esolver/ # ESolver Python interface
3435
│ │ │ ├── __init__.py
36+
│ │ │ ├── callbacks.py # CallbackMixin for SCF event hooks
37+
│ │ │ ├── data_access.py # DataAccessMixin for charge, energy, etc.
3538
│ │ │ ├── data_types.py # Data containers (ForceData, StressData, etc.)
36-
│ │ │ └── workflow.py # LCAOWorkflow high-level interface
39+
│ │ │ ├── workflow.py # _BaseWorkflow + LCAOWorkflow
40+
│ │ │ └── pw_workflow.py # PWWorkflow for plane wave calculations
3741
│ │ ├── cell/ # Unit cell handling
3842
│ │ ├── driver/ # ABACUS driver interface
3943
│ │ ├── hsolver/ # Hamiltonian solver
44+
│ │ ├── prepare/ # Input preparation and conversion utilities
4045
│ │ └── io/ # Input/output utilities
4146
│ └── ModuleESolver/ # C++ pybind11 bindings (requires libabacus_core)
4247
│ ├── py_esolver_lcao.hpp # ESolver C++ header
@@ -184,7 +189,23 @@ void bind_new_accessor(py::module& m) {
184189
bind_new_accessor(m);
185190
```
186191

187-
### 2. Data Types (`esolver/data_types.py`)
192+
### 2. Unit Conversion Constants (`constants.py`)
193+
194+
All unit conversion constants are defined in a single module `pyabacus/constants.py`.
195+
Every other module imports from here -- never define constants locally.
196+
197+
```python
198+
from pyabacus.constants import (
199+
RY_TO_EV, # 13.605698 (1 Ry = 13.605698 eV)
200+
BOHR_TO_ANG, # 0.529177249 (1 Bohr = 0.529177 Å)
201+
ANG_TO_BOHR, # 1 / BOHR_TO_ANG
202+
RY_BOHR_TO_EV_ANG, # ~25.7112 (Force: Ry/Bohr → eV/Å)
203+
KBAR_TO_EV_ANG3, # 1/1602.1766208 (Stress: kbar → eV/ų)
204+
ENERGY_FIELDS, # ['etot', 'eband', 'hartree_energy', ...]
205+
)
206+
```
207+
208+
### 3. Data Types (`esolver/data_types.py`)
188209

189210
Python dataclasses for structured data with unit conversion methods.
190211

@@ -197,19 +218,21 @@ Python dataclasses for structured data with unit conversion methods.
197218
- `DensityMatrixData` - DM(k), DM(R) matrices
198219
- `SCFResult` - SCF calculation results
199220

200-
**Unit Conversion Constants:**
201-
```python
202-
RY_TO_EV = 13.605693122994 # 1 Ry = 13.6057 eV
203-
BOHR_TO_ANG = 0.529177249 # 1 Bohr = 0.529177 Å
204-
RY_BOHR_TO_EV_ANG = 25.7112 # Force: Ry/Bohr → eV/Å
205-
KBAR_TO_EV_ANG3 = 1/1602.1766208 # Stress: kbar → eV/ų
206-
```
221+
### 4. Workflow Classes (`esolver/workflow.py`, `esolver/pw_workflow.py`)
207222

208-
### 3. LCAOWorkflow (`esolver/workflow.py`)
223+
The workflow layer is organized as:
209224

210-
High-level Python interface for LCAO calculations with callback support.
225+
- **`_BaseWorkflow(CallbackMixin, DataAccessMixin)`** -- base class in `workflow.py`
226+
containing all shared methods: `run_scf_step`, `before_scf`, `after_scf`,
227+
`_collect_result`, `cal_force`, `cal_stress`, `update_positions`, `update_cell`,
228+
`get_positions`, `get_cell`, `cleanup`.
229+
- **`LCAOWorkflow(_BaseWorkflow)`** -- LCAO-specific `initialize()` and `run_scf()`.
230+
- **`PWWorkflow(_BaseWorkflow)`** -- PW-specific `initialize()`, `run_scf()` (Python-side
231+
SCF loop), plus PW-only `npwx` property and `get_npw()` method.
211232

212-
**Key Methods:**
233+
When adding methods that apply to both LCAO and PW, add them to `_BaseWorkflow`.
234+
235+
**Key Methods (inherited from `_BaseWorkflow`):**
213236
- `initialize()` - Initialize calculation
214237
- `run_scf()` - Run SCF with callbacks
215238
- `cal_force()` / `cal_stress()` - Calculate forces/stress
@@ -221,7 +244,7 @@ High-level Python interface for LCAO calculations with callback support.
221244
- `before_after_scf` - Before `after_scf()` (main breakpoint)
222245
- `after_scf` - After `after_scf()` call
223246

224-
### 4. ASE Calculator (`ase/calculator.py`)
247+
### 5. ASE Calculator (`ase/calculator.py`)
225248

226249
ASE-compatible Calculator using pyabacus ESolver directly.
227250

@@ -279,7 +302,8 @@ class NewData:
279302
- Header: `ModuleESolver/py_esolver_lcao.hpp`
280303
- Implementation: `ModuleESolver/py_esolver_lcao_impl.cpp` or `ModuleESolver/accessors/py_accessors_impl.cpp`
281304

282-
4. **Add workflow methods** (`esolver/workflow.py`):
305+
4. **Add workflow methods** (in `esolver/workflow.py` `_BaseWorkflow` for shared,
306+
or in `LCAOWorkflow`/`PWWorkflow` for mode-specific):
283307
```python
284308
def new_method(self) -> NewData:
285309
accessor = self._esolver.get_new_data()
@@ -315,13 +339,15 @@ pytest tests/test_new_feature.py -v
315339

316340
### Adding Unit Conversion
317341

318-
1. Define conversion constant in `data_types.py`:
342+
1. Define conversion constant in `constants.py`:
319343
```python
320344
NEW_UNIT_CONVERSION = 1.234 # old_unit → new_unit
321345
```
322346

323-
2. Add conversion method to data class:
347+
2. Add conversion method to the relevant data class in `data_types.py`:
324348
```python
349+
from ..constants import NEW_UNIT_CONVERSION
350+
325351
def to_new_units(self) -> np.ndarray:
326352
return self.data * NEW_UNIT_CONVERSION
327353
```
@@ -342,6 +368,7 @@ python -c "from pyabacus.esolver._esolver_pack import ESolverLCAO_gamma; print(d
342368
- **Memory management**: Use pybind11's return value policies correctly
343369
- **Thread safety**: ABACUS uses MPI; be careful with parallel access
344370
- **Unit consistency**: Always document units in docstrings
371+
- **Unit constants**: All conversion constants live in `constants.py` -- never duplicate them in other modules
345372
- **ESolver module dependency**: The ESolver module requires `libabacus_core.so`. Without it, the module is not built (no placeholder mode).
346373

347374
## Resources
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
Ce24 C1 O49
2+
1.00000000000000
3+
7.5635166048882523 0.0000000000000000 0.0000000000000000
4+
0.0000000000000000 11.0463141927801018 -0.0325017638251731
5+
0.0000000000000000 -0.0982607873033930 33.7852222800298634
6+
Ce C O
7+
24 1 49
8+
Selective dynamics
9+
Direct
10+
0.0000000000000000 0.0000000000000000 0.3562166630501196 F F F
11+
0.2306253781599449 0.2405542769953649 0.6395517082503606 T T T
12+
0.5000000000000000 0.0001538732200705 0.5907150380062577 T T T
13+
0.7500000000000000 0.7500000000000000 0.4137299978300746 F F F
14+
0.2500000000000000 0.7500000000000000 0.4137299978300746 F F F
15+
0.5000000000000000 0.5000000000000000 0.3562166630501196 F F F
16+
0.7693746218400551 0.2405542769953649 0.6395517082503606 T T T
17+
0.5000000000000000 0.4989233905035561 0.4706234421803612 T T T
18+
0.7523526410840935 0.7514949193776989 0.5272548274511347 T T T
19+
-0.0000000000000000 0.5000999333168414 0.4714686922559981 T T T
20+
-0.0000000000000000 0.5006945429978595 0.5909025561385755 T T T
21+
0.7510148026046614 0.7502233707025258 0.6396829651092579 T T T
22+
0.2489851973953388 0.7502233707025258 0.6396829651092579 T T T
23+
0.5000000000000000 0.5135088385750621 0.5844661639146697 T T T
24+
0.2476473589159062 0.7514949193776989 0.5272548274511347 T T T
25+
-0.0000000000000000 -0.0055091013172945 0.5885696193528985 T T T
26+
0.0000000000000000 0.5000000000000000 0.3562166630501196 F F F
27+
0.5000000000000000 0.0000000000000000 0.3562166630501196 F F F
28+
-0.0000000000000000 0.0003298669391919 0.4712415841938251 T T T
29+
0.7492236048673507 0.2502622959147175 0.5278336617417005 T T T
30+
0.2507763951326491 0.2502622959147175 0.5278336617417005 T T T
31+
0.7500000000000000 0.2500000000000000 0.4137299978300746 F F F
32+
0.2500000000000000 0.2500000000000000 0.4137299978300746 F F F
33+
0.5000000000000000 -0.0000473166042515 0.4714576893085548 T T T
34+
0.5000000000000000 0.4991588880021700 0.7591757164693878 T T T
35+
0.7500000000000000 0.1250000000000000 0.3562166630501196 F F F
36+
0.5000000000000000 0.3750000000000000 0.4137299978300746 F F F
37+
0.5000000000000000 0.8741403202711442 0.5292362698995015 T T T
38+
-0.0000000000000000 0.8749903017660519 0.5292103571708596 T T T
39+
0.2507983503818721 0.6248962511439881 0.4716057583574854 T T T
40+
0.7492016496181277 0.6248962511439881 0.4716057583574854 T T T
41+
0.5000000000000000 0.6249275136667349 0.5293586211011583 T T T
42+
-0.0000000000000000 0.6257255182784049 0.5292961148000647 T T T
43+
0.7502827579461006 0.8751297207256905 0.4716027382162158 T T T
44+
0.2498875797010411 0.1250959104084330 0.4716189371845824 T T T
45+
0.0000000000000000 0.3750000000000000 0.4137299978300746 F F F
46+
0.2500000000000000 0.1250000000000000 0.3562166630501196 F F F
47+
-0.0000000000000000 0.8700834668403601 0.6450764333536879 T T T
48+
0.5000000000000000 0.8677646816219728 0.6449096047264896 T T T
49+
0.7507543652669063 0.6274683451400740 0.5862109143396206 T T T
50+
0.2492456347330939 0.6274683451400740 0.5862109143396206 T T T
51+
-0.0000000000000000 0.6321554429137972 0.6450031529526701 T T T
52+
0.5000000000000000 0.6159801141366454 0.6442088342456257 T T T
53+
0.2493413020778700 0.8739638923951164 0.5866375368770635 T T T
54+
0.7506586979221300 0.8739638923951164 0.5866375368770635 T T T
55+
0.2497172420538994 0.8751297207256905 0.4716027382162158 T T T
56+
0.0000000000000000 0.1250000000000000 0.4137299978300746 F F F
57+
0.5000000000000000 0.6250000000000000 0.4137299978300746 F F F
58+
0.2500000000000000 0.8750000000000000 0.3562166630501196 F F F
59+
0.7501124202989590 0.1250959104084330 0.4716189371845824 T T T
60+
0.5000000000000000 0.1254117091029763 0.5293646201891236 T T T
61+
-0.0000000000000000 0.1247684897563412 0.5293391793509492 T T T
62+
0.7498066020738142 0.3749433229404921 0.4716479649343910 T T T
63+
0.2501933979261858 0.3749433229404921 0.4716479649343910 T T T
64+
0.5000000000000000 0.3766951469854081 0.5289664577396773 T T T
65+
-0.0000000000000000 0.3678161043899972 0.6456528243179539 T T T
66+
0.5000000000000000 0.4978256122883754 0.7243866923259067 T T T
67+
0.7536689568904956 0.1238138179490171 0.5868597862293309 T T T
68+
0.2463310431095044 0.1238138179490171 0.5868597862293309 T T T
69+
-0.0000000000000000 0.1276279097039290 0.6461074330786978 T T T
70+
0.5000000000000000 0.1523513602131844 0.6461043270573759 T T T
71+
0.2659681126648215 0.3746429454411931 0.5904400830847524 T T T
72+
0.7340318873351784 0.3746429454411931 0.5904400830847524 T T T
73+
0.7500000000000000 0.3750000000000000 0.3562166630501196 F F F
74+
0.2500000000000000 0.3750000000000000 0.3562166630501196 F F F
75+
0.5000000000000000 0.1250000000000000 0.4137299978300746 F F F
76+
0.0000000000000000 0.8750000000000000 0.4137299978300746 F F F
77+
0.5000000000000000 0.8750000000000000 0.4137299978300746 F F F
78+
0.7500000000000000 0.6250000000000000 0.3562166630501196 F F F
79+
0.2500000000000000 0.6250000000000000 0.3562166630501196 F F F
80+
0.0000000000000000 0.6250000000000000 0.4137299978300746 F F F
81+
-0.0000000000000000 0.3746536491666314 0.5302041654288799 T T T
82+
0.7500000000000000 0.8750000000000000 0.3562166630501196 F F F
83+
0.5000000000000000 0.5007587433785532 0.7939769816116942 T T T
84+
85+
0.00000000E+00 0.00000000E+00 0.00000000E+00
86+
0.00000000E+00 0.00000000E+00 0.00000000E+00
87+
0.00000000E+00 0.00000000E+00 0.00000000E+00
88+
0.00000000E+00 0.00000000E+00 0.00000000E+00
89+
0.00000000E+00 0.00000000E+00 0.00000000E+00
90+
0.00000000E+00 0.00000000E+00 0.00000000E+00
91+
0.00000000E+00 0.00000000E+00 0.00000000E+00
92+
0.00000000E+00 0.00000000E+00 0.00000000E+00
93+
0.00000000E+00 0.00000000E+00 0.00000000E+00
94+
0.00000000E+00 0.00000000E+00 0.00000000E+00
95+
0.00000000E+00 0.00000000E+00 0.00000000E+00
96+
0.00000000E+00 0.00000000E+00 0.00000000E+00
97+
0.00000000E+00 0.00000000E+00 0.00000000E+00
98+
0.00000000E+00 0.00000000E+00 0.00000000E+00
99+
0.00000000E+00 0.00000000E+00 0.00000000E+00
100+
0.00000000E+00 0.00000000E+00 0.00000000E+00
101+
0.00000000E+00 0.00000000E+00 0.00000000E+00
102+
0.00000000E+00 0.00000000E+00 0.00000000E+00
103+
0.00000000E+00 0.00000000E+00 0.00000000E+00
104+
0.00000000E+00 0.00000000E+00 0.00000000E+00
105+
0.00000000E+00 0.00000000E+00 0.00000000E+00
106+
0.00000000E+00 0.00000000E+00 0.00000000E+00
107+
0.00000000E+00 0.00000000E+00 0.00000000E+00
108+
0.00000000E+00 0.00000000E+00 0.00000000E+00
109+
0.00000000E+00 0.00000000E+00 0.00000000E+00
110+
0.00000000E+00 0.00000000E+00 0.00000000E+00
111+
0.00000000E+00 0.00000000E+00 0.00000000E+00
112+
0.00000000E+00 0.00000000E+00 0.00000000E+00
113+
0.00000000E+00 0.00000000E+00 0.00000000E+00
114+
0.00000000E+00 0.00000000E+00 0.00000000E+00
115+
0.00000000E+00 0.00000000E+00 0.00000000E+00
116+
0.00000000E+00 0.00000000E+00 0.00000000E+00
117+
0.00000000E+00 0.00000000E+00 0.00000000E+00
118+
0.00000000E+00 0.00000000E+00 0.00000000E+00
119+
0.00000000E+00 0.00000000E+00 0.00000000E+00
120+
0.00000000E+00 0.00000000E+00 0.00000000E+00
121+
0.00000000E+00 0.00000000E+00 0.00000000E+00
122+
0.00000000E+00 0.00000000E+00 0.00000000E+00
123+
0.00000000E+00 0.00000000E+00 0.00000000E+00
124+
0.00000000E+00 0.00000000E+00 0.00000000E+00
125+
0.00000000E+00 0.00000000E+00 0.00000000E+00
126+
0.00000000E+00 0.00000000E+00 0.00000000E+00
127+
0.00000000E+00 0.00000000E+00 0.00000000E+00
128+
0.00000000E+00 0.00000000E+00 0.00000000E+00
129+
0.00000000E+00 0.00000000E+00 0.00000000E+00
130+
0.00000000E+00 0.00000000E+00 0.00000000E+00
131+
0.00000000E+00 0.00000000E+00 0.00000000E+00
132+
0.00000000E+00 0.00000000E+00 0.00000000E+00
133+
0.00000000E+00 0.00000000E+00 0.00000000E+00
134+
0.00000000E+00 0.00000000E+00 0.00000000E+00
135+
0.00000000E+00 0.00000000E+00 0.00000000E+00
136+
0.00000000E+00 0.00000000E+00 0.00000000E+00
137+
0.00000000E+00 0.00000000E+00 0.00000000E+00
138+
0.00000000E+00 0.00000000E+00 0.00000000E+00
139+
0.00000000E+00 0.00000000E+00 0.00000000E+00
140+
0.00000000E+00 0.00000000E+00 0.00000000E+00
141+
0.00000000E+00 0.00000000E+00 0.00000000E+00
142+
0.00000000E+00 0.00000000E+00 0.00000000E+00
143+
0.00000000E+00 0.00000000E+00 0.00000000E+00
144+
0.00000000E+00 0.00000000E+00 0.00000000E+00
145+
0.00000000E+00 0.00000000E+00 0.00000000E+00
146+
0.00000000E+00 0.00000000E+00 0.00000000E+00
147+
0.00000000E+00 0.00000000E+00 0.00000000E+00
148+
0.00000000E+00 0.00000000E+00 0.00000000E+00
149+
0.00000000E+00 0.00000000E+00 0.00000000E+00
150+
0.00000000E+00 0.00000000E+00 0.00000000E+00
151+
0.00000000E+00 0.00000000E+00 0.00000000E+00
152+
0.00000000E+00 0.00000000E+00 0.00000000E+00
153+
0.00000000E+00 0.00000000E+00 0.00000000E+00
154+
0.00000000E+00 0.00000000E+00 0.00000000E+00
155+
0.00000000E+00 0.00000000E+00 0.00000000E+00
156+
0.00000000E+00 0.00000000E+00 0.00000000E+00
157+
0.00000000E+00 0.00000000E+00 0.00000000E+00
158+
0.00000000E+00 0.00000000E+00 0.00000000E+00

0 commit comments

Comments
 (0)