Skip to content

Commit aacff41

Browse files
authored
Merge branch 'develop' into refactor/module-hamilt-remove-global-dependencies
2 parents 2773351 + 4c95474 commit aacff41

25 files changed

Lines changed: 4119 additions & 18 deletions

File tree

docs/advanced/input_files/input-main.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [ntype](#ntype)
1111
- [cell\_replica](#cell_replica)
1212
- [calculation](#calculation)
13+
- [socket\_driver](#socket_driver)
1314
- [esolver\_type](#esolver_type)
1415
- [symmetry](#symmetry)
1516
- [symmetry\_prec](#symmetry_prec)
@@ -637,6 +638,20 @@
637638
- test_neighbour: obtain information of neighboring atoms (for LCAO basis only), please specify a positive search_radius manually
638639
- **Default**: scf
639640

641+
### socket_driver
642+
643+
- **Type**: Boolean
644+
- **Description**: If set to True, ABACUS keeps the calculation type as scf and receives atomic positions from an external driver through the i-PI socket protocol.
645+
646+
> Note: Use calculation = scf with socket_driver = True. ABACUS connects to the external i-PI server selected by ABACUS_SOCKET_ADDRESS. If ABACUS_SOCKET_ADDRESS is unset, ABACUS uses localhost:31415. The value can use one of two forms:
647+
648+
- host:port, for example localhost:31415 or 127.0.0.1:31415, opens a TCP connection to that host and port. Use this when the i-PI server listens on a TCP port.
649+
- path:UNIX, for example /tmp/ipi_abacus_si:UNIX, opens a Unix-domain socket at the given filesystem path. The :UNIX suffix tells ABACUS that the preceding value is a local socket path rather than a TCP host name. This form only works on the same machine.
650+
When using the ASE AbacusSocketIO interface, this environment variable is set automatically from the port or unixsocket calculator argument.
651+
652+
Socket mode always computes energy. Force and stress extraction follows cal_force and cal_stress independently; disabled properties are sent as protocol padding and marked absent in the ABACUS i-PI extras metadata, not reported as physical zero values. This metadata extension is required for safe optional-property handling: a legacy response with empty extras is accepted only for energy-only use, while a generic client that ignores extras cannot distinguish padding from a computed zero. A non-converged SCF step is returned with scf_converged=false metadata so an external driver can choose its policy.
653+
- **Default**: False
654+
640655
### esolver_type
641656

642657
- **Type**: String
@@ -686,6 +701,7 @@
686701

687702
- **Type**: Boolean
688703
- **Description**: If set to True, calculate the force at the end of the electronic iteration.
704+
In socket_driver mode, this flag controls whether the returned frame advertises forces; it is not forced on by the socket protocol.
689705
- **Default**: False
690706

691707
### kpar
@@ -801,6 +817,7 @@
801817

802818
- **Type**: Boolean
803819
- **Description**: If set to True, calculate the stress at the end of the electronic iteration.
820+
In socket_driver mode, this flag independently controls whether the returned frame advertises stress/virial.
804821
- **Default**: False
805822

806823
### diago_proc
@@ -899,7 +916,12 @@
899916
### chg_extrap
900917

901918
- **Type**: String
902-
- **Description**: Charge extrapolation method for MD and relaxation calculations.
919+
- **Description**: Charge extrapolation method for MD, relaxation, and socket-driven calculations.
920+
921+
When set to default, ABACUS chooses second-order for md, first-order for
922+
relax/cell-relax and socket_driver calculations, and atomic for other calculations. Socket-driven
923+
molecular dynamics can explicitly set second-order if the external driver
924+
updates structures smoothly enough for second-order extrapolation.
903925
- **Default**: default
904926

905927
### nb2d

docs/advanced/interface/ase.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,104 @@ In the new implementation, we limit the range of functionalties supported to mai
103103

104104
Please read the examples in `interfaces/ASE_interface/examples/` for more details.
105105

106+
### Socket I/O with ASE
107+
108+
#### When to use socket mode
109+
110+
`AbacusSocketIO` is designed for a sequence of electronic-structure
111+
evaluations in which the atomic positions change while the simulation context
112+
remains fixed. Reuse one socket calculator only when the cell and periodic
113+
boundary conditions, atom count and species, pseudopotentials and orbitals,
114+
k-point sampling, spin settings, and other electronic-structure parameters do
115+
not change. The socket session can then keep one ABACUS process alive and
116+
receive successive position updates.
117+
118+
This pattern is suitable for fixed-cell ASE optimization and molecular
119+
dynamics, fixed-cell NEB (use an independent calculator/session for each image),
120+
finite-displacement phonon or ASE finite-difference frequency calculations,
121+
position-only P-RFO or transition-state searches, and repeated fixed-cell
122+
force evaluations in larger workflows such as thermal-property or active-
123+
learning data generation. These workflows can use the socket calculator only
124+
when their driver calls the ASE calculator interface; the existing Phonopy,
125+
ShengBTE, DP-GEN, or transition-state tools are not automatically converted
126+
to socket workflows by installing abacuslite.
127+
128+
Use the regular `Abacus` FileIO calculator when the cell, composition, or
129+
electronic-structure settings must change. Direct DFPT or dynamical-matrix
130+
calculations, and external workflows that require properties beyond energy,
131+
forces, and stress, also remain outside the current socket property interface.
132+
133+
For socket-driven ASE workflows, use the `AbacusSocketIO` calculator. ASE runs the i-PI socket server, while ABACUS keeps `calculation=scf` and is launched with `socket_driver=1` as the client. Energy, forces, and stress are independent properties controlled by `cal_force` and `cal_stress`; the fixed i-PI wire layout still contains padding fields, while extras metadata identifies which values were actually computed. See the [ASE socket I/O documentation](https://ase-lib.org/ase/calculators/socketio/socketio.html) and the i-PI reference paper, [Ceriotti et al., Comput. Phys. Commun. 185, 1019-1026 (2014)](https://doi.org/10.1016/j.cpc.2013.10.027), for the protocol background.
134+
135+
Build ABACUS as usual before using this interface. PW-only builds work with `basis_type=pw`; LCAO socket calculations require an LCAO-enabled executable. No extra socket library is required.
136+
137+
With CMake, choose the executable according to the basis:
138+
139+
```bash
140+
cmake -S . -B build-pw -DENABLE_MPI=ON -DENABLE_LCAO=OFF
141+
cmake --build build-pw --target abacus_pw_para -j
142+
143+
cmake -S . -B build-lcao -DENABLE_MPI=ON -DENABLE_LCAO=ON
144+
cmake --build build-lcao --target abacus_basic_para -j
145+
```
146+
147+
With the ABACUS toolchain workflow, build the normal ABACUS executable with LCAO support when `basis_type=lcao` is needed, then pass that executable to `AbacusProfile(command=...)`. The command can include an MPI launcher, for example `mpirun -np 4 /path/to/abacus`; ABACUS rank 0 opens the socket connection and broadcasts the i-PI data to the other ranks internally. On managed clusters, keep scheduler-specific launch options outside the calculator when possible and test the exact launcher command on a compute node.
148+
149+
For PW calculations on CUDA/ROCm with multiple MPI ranks, use a k-point layout compatible with ABACUS' GPU parallelization. In practice, make sure each k-point pool contains one MPI rank; for example, a 4-rank PW GPU socket calculation should use at least four k-points so the default GPU `kpar` adjustment can assign one rank per pool. A one-k-point PW GPU job with several MPI ranks can fail in the PW GPU transform path; reduce the rank count or use a denser k-point mesh such as a smaller `kspacing`.
150+
151+
The ASE interface can be installed from this repository with:
152+
153+
```bash
154+
cd interfaces/ASE_interface
155+
pip install .
156+
```
157+
158+
A minimal socket calculator setup is:
159+
160+
```python
161+
from ase.optimize import BFGS
162+
from abacuslite import AbacusProfile, AbacusSocketIO
163+
164+
aprof = AbacusProfile(
165+
command="mpirun -np 4 /path/to/abacus",
166+
pseudo_dir="/path/to/pseudopotentials",
167+
orbital_dir="/path/to/orbitals",
168+
omp_num_threads=1,
169+
)
170+
171+
abacus = AbacusSocketIO(
172+
profile=aprof,
173+
directory="socketio",
174+
unixsocket="abacus_si",
175+
pseudopotentials={"Si": "Si_ONCV_PBE-1.0.upf"},
176+
basissets={"Si": "Si_gga_8au_100Ry_2s2p1d.orb"},
177+
inp={"calculation": "scf", "basis_type": "lcao", "kspacing": 0.1},
178+
)
179+
180+
with abacus as calc:
181+
atoms.calc = calc
182+
BFGS(atoms).run(fmax=0.05)
183+
```
184+
185+
`AbacusSocketIO` sets `socket_driver=1` automatically. The adapter enables properties requested through ASE, restarting the client if a later request expands the active property set. Set `inp={'cal_force': 1}` and/or `inp={'cal_stress': 1}` when a fixed-cell optimizer, MD integrator, or stress evaluation client needs those properties. Energy is always available. The interface selects the socket endpoint and passes it to ABACUS through `ABACUS_SOCKET_ADDRESS`, so users normally do not set this environment variable by hand when using abacuslite.
186+
187+
There are two endpoint styles:
188+
189+
- `unixsocket="abacus_si"` uses a local Unix-domain socket. ASE creates and listens on `/tmp/ipi_abacus_si`; abacuslite launches ABACUS with `ABACUS_SOCKET_ADDRESS=/tmp/ipi_abacus_si:UNIX`. The `:UNIX` suffix is part of ABACUS' address syntax and means that `/tmp/ipi_abacus_si` is a filesystem socket path, not a TCP host. This is usually the best choice when ASE and ABACUS run on the same node because it avoids TCP port conflicts.
190+
- `port=31415` uses a TCP socket. abacuslite launches ABACUS with `ABACUS_SOCKET_ADDRESS=localhost:31415`, meaning host `localhost` and TCP port `31415`. Use this style when the socket server should listen on a TCP port. If ABACUS is launched manually instead of through `AbacusSocketIO`, set `ABACUS_SOCKET_ADDRESS` yourself to the same `host:port` or `path:UNIX` endpoint.
191+
192+
Calling `atoms.get_potential_energy()` does not force a force or stress calculation. If a requested property was disabled, ASE raises `PropertyNotImplementedError`; zero-filled i-PI padding is never treated as a physical result. When SCF does not converge, `AbacusSocketIO.last_scf_converged` is set to `False` and the caller decides whether to continue or stop.
193+
194+
The ABACUS metadata extension is required to expose force/stress presence safely. If a legacy client returns an empty extras field, the adapter accepts only an energy-only response and refuses to infer forces or stress from the fixed-wire padding. Generic i-PI/ASE clients that ignore ABACUS extras cannot distinguish mandatory padding from a computed zero; use `AbacusSocketIO` or another metadata-aware client when requesting optional properties. When launching ABACUS with a generic client, explicitly set `cal_force=1` for force-driven workflows and `cal_stress=1` for stress evaluation; an omitted switch defaults to disabled. Such clients also need their own policy for unconverged SCF results.
195+
196+
A socket calculator owns one ABACUS process initialized from one fixed `INPUT`/`STRU` setup. Reuse the same `AbacusSocketIO` instance only for position updates under the same electronic-structure settings and the same cell. Do not change `kpts`, `kspacing`, `nspin`, `basis_type`, `basissets`, pseudopotentials, species, atom count, cell, or other core `INPUT`/`STRU` parameters through an existing socket calculator; create a new `AbacusSocketIO` instance and a new ABACUS client process for those changes. `AbacusSocketIO` rejects cell changes before sending them to ABACUS, and the ABACUS socket driver also checks incoming POSDATA cells against the initial `STRU` cell and exits if they differ.
197+
198+
In socket mode, ABACUS keeps one client process alive. All SCF evaluations produced by the same `AbacusSocketIO` instance are appended to the same `OUT.ABACUS/running_scf.log`, because the ABACUS calculation type remains `scf`. The authoritative per-step energy and force results are returned through the i-PI socket to ASE. Use ASE trajectory and optimizer log files, such as `BFGS(atoms, trajectory="opt.traj", logfile="opt.log")`, when each optimizer or MD step should be saved separately. Treat `running_scf.log` mainly as the ABACUS diagnostic log for the socket client, not as one independent FileIO result per structure.
199+
200+
The i-PI protocol does not transmit element symbols. `AbacusSocketIO` therefore sorts the internal socket atoms with the same first-occurrence species grouping used when writing `STRU`, and maps returned forces back to the original ASE `Atoms` order. This avoids silent force/atom mismatches when structures are read from CIF, extxyz, POSCAR, or other formats whose atom order is not already grouped for ABACUS. Users should not manually reorder atoms for socket I/O; pass the physical ASE `Atoms` object directly to the calculator.
201+
202+
A complete fixed-cell validation and benchmark example is available in `interfaces/ASE_interface/examples/socketio.py`.
203+
106204
## SPAP Analysis
107205

108206
[SPAP](https://github.com/chuanxun/StructurePrototypeAnalysisPackage) (Structure Prototype Analysis Package) is written by Dr. Chuanxun Su to analyze symmetry and compare similarity of large amount of atomic structures. The coordination characterization function (CCF) is used to
@@ -114,3 +212,10 @@ If you use this program and method in your research, please read and cite the pu
114212
`Su C, Lv J, Li Q, Wang H, Zhang L, Wang Y, Ma Y. Construction of crystal structure prototype database: methods and applications. J Phys Condens Matter. 2017 Apr 26;29(16):165901.`
115213

116214
and you should install it first with command `pip install spap`.
215+
216+
Socket results are read directly from the completed in-memory solver frame, not
217+
parsed from output files. The client clears cached results and convergence
218+
metadata before a new request and publishes them only after validating the full
219+
response. A failed request therefore leaves no previous-frame result available
220+
in the calculator cache. This protocol guarantee does not establish SCF
221+
convergence or numerical agreement with independent single-point calculations.

docs/parameters.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ parameters:
4646
default_value: scf
4747
unit: ""
4848
availability: ""
49+
- name: socket_driver
50+
category: System variables
51+
type: Boolean
52+
description: |
53+
If set to True, ABACUS keeps the calculation type as scf and receives atomic positions from an external driver through the i-PI socket protocol.
54+
55+
[NOTE] Use calculation = scf with socket_driver = True. ABACUS connects to the external i-PI server selected by ABACUS_SOCKET_ADDRESS. If ABACUS_SOCKET_ADDRESS is unset, ABACUS uses localhost:31415. The value can use one of two forms:
56+
* host:port, for example localhost:31415 or 127.0.0.1:31415, opens a TCP connection to that host and port. Use this when the i-PI server listens on a TCP port.
57+
* path:UNIX, for example /tmp/ipi_abacus_si:UNIX, opens a Unix-domain socket at the given filesystem path. The :UNIX suffix tells ABACUS that the preceding value is a local socket path rather than a TCP host name. This form only works on the same machine.
58+
When using the ASE AbacusSocketIO interface, this environment variable is set automatically from the port or unixsocket calculator argument.
59+
60+
Socket mode always computes energy. Force and stress extraction follows cal_force and cal_stress independently; disabled properties are sent as protocol padding and marked absent in the ABACUS i-PI extras metadata, not reported as physical zero values. This metadata extension is required for safe optional-property handling: a legacy response with empty extras is accepted only for energy-only use, while a generic client that ignores extras cannot distinguish padding from a computed zero. A non-converged SCF step is returned with scf_converged=false metadata so an external driver can choose its policy.
61+
default_value: "False"
62+
unit: ""
63+
availability: ""
4964
- name: esolver_type
5065
category: System variables
5166
type: String
@@ -102,6 +117,7 @@ parameters:
102117
type: Boolean
103118
description: |
104119
If set to True, calculate the force at the end of the electronic iteration.
120+
In socket_driver mode, this flag controls whether the returned frame advertises forces; it is not forced on by the socket protocol.
105121
default_value: "False"
106122
unit: ""
107123
availability: ""
@@ -230,6 +246,7 @@ parameters:
230246
type: Boolean
231247
description: |
232248
If set to True, calculate the stress at the end of the electronic iteration.
249+
In socket_driver mode, this flag independently controls whether the returned frame advertises stress/virial.
233250
default_value: "False"
234251
unit: ""
235252
availability: ""
@@ -350,7 +367,12 @@ parameters:
350367
category: System variables
351368
type: String
352369
description: |
353-
Charge extrapolation method for MD and relaxation calculations.
370+
Charge extrapolation method for MD, relaxation, and socket-driven calculations.
371+
372+
When set to default, ABACUS chooses second-order for md, first-order for
373+
relax/cell-relax and socket_driver calculations, and atomic for other calculations. Socket-driven
374+
molecular dynamics can explicitly set second-order if the external driver
375+
updates structures smoothly enough for second-order extrapolation.
354376
default_value: default
355377
unit: ""
356378
availability: ""

interfaces/ASE_interface/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ abacuslite is a lightweight plugin for ABACUS (Atomic-orbital Based Ab-initio Co
77
### Key Features
88

99
- **Lightweight Design**: Implemented as a plugin, no need to modify ASE core code
10-
- **Version Compatibility**: No longer restricted to specific ASE versions, works with most ASE versions
10+
- **Version Compatibility**: Supports ASE versions satisfying the package requirement `ase>=3.22`
1111
- **ASE Integration**: Uses ASE as the running platform, making ABACUS a callable calculator within it
12-
- **Function Support**: Currently only supports SCF (Self-Consistent Field) functionality, returning energy, forces, stress, etc.
12+
- **Function Support**: Provides SCF-based energy, force, and stress evaluations through ASE. ASE can use these evaluations for relaxation, molecular dynamics, NEB, band-structure, and density-of-states workflows.
13+
- **Socket Support**: `AbacusSocketIO` provides fixed-cell i-PI socket calculations, with energy always available and forces/stress enabled independently when requested.
1314

1415
## Installation
1516

16-
Installation is very simple, just execute the following command in the project root directory:
17+
Install the plugin from the ASE interface directory:
1718

1819
```bash
20+
cd interfaces/ASE_interface
1921
pip install .
2022
```
2123

@@ -32,8 +34,10 @@ Please refer to the example scripts in the `examples` folder. Recommended learni
3234
7. **constraintmd.py** - Constrained molecular dynamics simulation
3335
8. **metadynamics.py** - Metadynamics simulation
3436
9. **neb.py** - Nudged Elastic Band (NEB) calculation
37+
10. **soc.py** - Noncollinear spin-orbit coupling calculation
38+
11. **socketio.py** - Fixed-cell ASE optimization with `AbacusSocketIO`, running ABACUS as an i-PI socket client
3539

36-
More usage examples will be provided in future versions.
40+
The regular `Abacus` calculator runs one ABACUS calculation for each ASE property evaluation. ASE controls the relaxation, molecular-dynamics, and other workflow steps. The socket calculator reuses one ABACUS process for position updates, while the cell and electronic-structure settings remain fixed for that calculator instance.
3741

3842
## Authors
3943

@@ -48,10 +52,10 @@ Thanks to the ABACUS development team for their support and contributions.
4852

4953
## License
5054

51-
[Fill in according to the actual project license]
55+
The applicable license terms are provided in the repository [LICENSE](../../LICENSE).
5256

5357
## Contact
5458

5559
If you have any questions or suggestions, please contact us through:
5660

57-
- GitHub: [deepmodeling/abacus-develop](https://github.com/deepmodeling/abacus-develop)
61+
- GitHub: [deepmodeling/abacus-develop](https://github.com/deepmodeling/abacus-develop)

0 commit comments

Comments
 (0)