Skip to content

Commit aba938d

Browse files
authored
Refactor(input): encode relaxation variants in relax_method (#7735)
1 parent d91ae4c commit aba938d

40 files changed

Lines changed: 248 additions & 314 deletions

File tree

docs/advanced/input_files/input-main.md

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
- [npart\_sto](#npart_sto)
134134
- [Geometry relaxation](#geometry-relaxation)
135135
- [relax\_method](#relax_method)
136-
- [relax\_new](#relax_new)
137136
- [relax\_scale\_force](#relax_scale_force)
138137
- [relax\_nmax](#relax_nmax)
139138
- [relax\_cg\_thr](#relax_cg_thr)
@@ -1605,51 +1604,32 @@
16051604
### relax_method
16061605

16071606
- **Type**: Vector of string
1608-
- **Description**: The methods to do geometry optimization. The available algorithms depend on the relax_new setting.
1607+
- **Description**: The method used for geometry optimization.
16091608

16101609
First element (algorithm selection):
16111610

1612-
- cg: Conjugate gradient (CG) algorithm. Available for both relax_new = True (default, simultaneous optimization) and relax_new = False (nested optimization). See relax_new for implementation details.
1613-
- bfgs: Broyden–Fletcher–Goldfarb–Shanno (BFGS) quasi-Newton algorithm. Only available when relax_new = False.
1614-
- lbfgs: Limited-memory BFGS algorithm, suitable for large systems. Only available when relax_new = False.
1615-
- cg_bfgs: Mixed method starting with CG and switching to BFGS when force convergence reaches relax_cg_thr. Only available when relax_new = False.
1616-
- sd: Steepest descent algorithm. Only available when relax_new = False. Not recommended for production use.
1617-
- fire: Fast Inertial Relaxation Engine method, a molecular-dynamics-based relaxation algorithm. Use by setting calculation to md and md_type to fire. Ionic velocities must be set in STRU file. See fire for details.
1611+
- cg: Conjugate gradient (CG) algorithm.
1612+
- bfgs: Broyden–Fletcher–Goldfarb–Shanno (BFGS) quasi-Newton algorithm.
1613+
- lbfgs: Limited-memory BFGS algorithm, suitable for large systems.
1614+
- cg_bfgs: Mixed method starting with CG and switching to BFGS when force convergence reaches relax_cg_thr.
1615+
- sd: Steepest descent algorithm. Not recommended for production use.
16181616

1619-
Second element (BFGS variant, only when first element is bfgs):
1617+
Optional second element:
16201618

1621-
- 1: Traditional BFGS that updates the Hessian matrix B and then inverts it.
1622-
- 2 or omitted: Default BFGS that directly updates the inverse Hessian (recommended).
1619+
- cg 1: First optimize ionic positions at fixed cell, then update the cell, and repeat.
1620+
- cg 2 or omitted: Simultaneously optimize ionic positions and cell parameters with line search (recommended).
1621+
- bfgs 1: Traditional BFGS that updates the Hessian matrix B and then inverts it.
1622+
- bfgs 2 or omitted: Default BFGS that directly updates the inverse Hessian (recommended).
16231623

1624-
> Note: In the 3.10-LTS version, the type of this parameter is std::string. It can be set to "cg", "bfgs", "cg_bfgs", "bfgs_trad", "lbfgs", "sd", "fire".
1625-
- **Default**: cg 1
1626-
1627-
### relax_new
1624+
The second element is not accepted by other methods.
16281625

1629-
- **Type**: Boolean
1630-
- **Description**: Controls which implementation of geometry relaxation to use. At the end of 2022, a new implementation of the Conjugate Gradient (CG) method was introduced for relax and cell-relax calculations, while the old implementation was kept for backward compatibility.
1631-
1632-
1633-
- True (default): Use the new CG implementation with the following features:
1634-
- Simultaneous optimization of ionic positions and cell parameters (for cell-relax)
1635-
- Line search algorithm for step size determination
1636-
- Only CG algorithm is available (relax_method must be cg)
1637-
- Supports advanced cell constraints: fixed_axes = "shape", "volume", "a", "b", "c", etc.
1638-
- Supports fixed_ibrav to maintain lattice type
1639-
- More efficient for variable-cell relaxation
1640-
- Step size controlled by relax_scale_force
1641-
1642-
- False: Use the old implementation with the following features:
1643-
- Nested optimization procedure: ionic positions optimized first, then cell parameters (for cell-relax)
1644-
- Multiple algorithms available: cg, bfgs, lbfgs, sd, cg_bfgs
1645-
- Limited cell constraints: only fixed_axes = "volume" is supported
1646-
- Traditional approach with separate ionic and cell optimization steps
1647-
- **Default**: True
1626+
> Note: In the 3.10-LTS version, the type of this parameter is std::string. It can be set to "cg", "bfgs", "cg_bfgs", "bfgs_trad", "lbfgs", "sd", "fire".
1627+
- **Default**: cg 2
16481628

16491629
### relax_scale_force
16501630

16511631
- **Type**: Real
1652-
- **Availability**: *Only used when relax_new set to True*
1632+
- **Availability**: *Only used when relax_method is cg 2*
16531633
- **Description**: The paramether controls the size of the first conjugate gradient step. A smaller value means the first step along a new CG direction is smaller. This might be helpful for large systems, where it is safer to take a smaller initial step to prevent the collapse of the whole configuration.
16541634
- **Default**: 0.5
16551635

@@ -1662,7 +1642,7 @@
16621642
### relax_cg_thr
16631643

16641644
- **Type**: Real
1665-
- **Availability**: *Only used when relax_new = False and relax_method = cg_bfgs*
1645+
- **Availability**: *Only used when relax_method is cg_bfgs*
16661646
- **Description**: When relax_method is set to cg_bfgs, a mixed algorithm of conjugate gradient (CG) and Broyden–Fletcher–Goldfarb–Shanno (BFGS) is used. The ions first move according to the CG method, then switch to the BFGS method when the maximum force on atoms is reduced below this threshold.
16671647
- **Default**: 0.5
16681648
- **Unit**: eV/Angstrom
@@ -1691,37 +1671,37 @@
16911671
### relax_bfgs_w1
16921672

16931673
- **Type**: Real
1694-
- **Availability**: *Only used when relax_new = False and relax_method is bfgs or cg_bfgs*
1674+
- **Availability**: *Only used when relax_method is bfgs or cg_bfgs*
16951675
- **Description**: Controls the Wolfe condition for the Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm used in geometry relaxation. This parameter sets the sufficient decrease condition (c1 in Wolfe conditions). For more information, see Phys. Chem. Chem. Phys., 2000, 2, 2177.
16961676
- **Default**: 0.01
16971677

16981678
### relax_bfgs_w2
16991679

17001680
- **Type**: Real
1701-
- **Availability**: *Only used when relax_new = False and relax_method is bfgs or cg_bfgs*
1681+
- **Availability**: *Only used when relax_method is bfgs or cg_bfgs*
17021682
- **Description**: Controls the Wolfe condition for the Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm used in geometry relaxation. This parameter sets the curvature condition (c2 in Wolfe conditions). For more information, see Phys. Chem. Chem. Phys., 2000, 2, 2177.
17031683
- **Default**: 0.5
17041684

17051685
### relax_bfgs_rmax
17061686

17071687
- **Type**: Real
1708-
- **Availability**: *Only used when relax_new = False and relax_method is bfgs or cg_bfgs*
1688+
- **Availability**: *Only used when relax_method is bfgs or cg_bfgs*
17091689
- **Description**: Maximum allowed total displacement of all atoms during geometry optimization. The sum of atomic displacements can increase during optimization steps but cannot exceed this value.
17101690
- **Default**: 0.8
17111691
- **Unit**: Bohr
17121692

17131693
### relax_bfgs_rmin
17141694

17151695
- **Type**: Real
1716-
- **Availability**: *Only used when relax_new = False and relax_method = bfgs 1 (traditional BFGS)*
1696+
- **Availability**: *Only used when relax_method is bfgs 1 (traditional BFGS)*
17171697
- **Description**: Minimum allowed total displacement of all atoms. When the total atomic displacement falls below this value and force convergence is not achieved, the calculation will terminate. Note: This parameter is not used in the default BFGS algorithm (relax_method = bfgs 2 or bfgs).
17181698
- **Default**: 1e-5
17191699
- **Unit**: Bohr
17201700

17211701
### relax_bfgs_init
17221702

17231703
- **Type**: Real
1724-
- **Availability**: *Only used when relax_new = False and relax_method is bfgs or cg_bfgs*
1704+
- **Availability**: *Only used when relax_method is bfgs or cg_bfgs*
17251705
- **Description**: Initial total displacement of all atoms in the first BFGS step. This sets the scale for the initial movement.
17261706
- **Default**: 0.5
17271707
- **Unit**: Bohr
@@ -1758,9 +1738,9 @@
17581738

17591739
- **Type**: String
17601740
- **Availability**: *Only used when calculation is set to cell-relax*
1761-
- **Description**: Specifies which cell degrees of freedom are fixed during variable-cell relaxation. The available options depend on the relax_new setting:
1741+
- **Description**: Specifies which cell degrees of freedom are fixed during variable-cell relaxation. The available options depend on relax_method:
17621742

1763-
When relax_new = True (default), all options are available:
1743+
With relax_method = cg 2 (default), all options are available:
17641744

17651745
- None: Default; all cell parameters can relax freely
17661746
- volume: Relaxation with fixed volume (allows shape changes)
@@ -1771,21 +1751,17 @@
17711751
- ab: Fix both a and b axes during relaxation
17721752
- ac: Fix both a and c axes during relaxation
17731753
- bc: Fix both b and c axes during relaxation
1754+
- abc: Fix all three lattice vectors during relaxation
17741755

1775-
When relax_new = False, all options are now available:
1776-
1777-
- None: Default; all cell parameters can relax freely
1778-
- volume: Relaxation with fixed volume (allows shape changes). Volume is preserved by rescaling the lattice after each update.
1779-
- shape: Fix shape but allow volume changes (hydrostatic pressure only). Stress tensor is replaced with isotropic pressure.
1780-
- a, b, c, ab, ac, bc: Fix specific lattice vectors. Gradients for fixed vectors are set to zero.
1756+
With relax_method set to cg 1, bfgs, lbfgs, sd, or cg_bfgs, None and a, b, c, ab, ac, bc, abc are available. The shape and volume options require cg 2.
17811757

1782-
> Note: For VASP users, see the ISIF correspondence table in the geometry optimization documentation. Both implementations now support all constraint types.
1758+
> Note: For VASP users, see the ISIF correspondence table in the geometry optimization documentation.
17831759
- **Default**: None
17841760

17851761
### fixed_ibrav
17861762

17871763
- **Type**: Boolean
1788-
- **Availability**: *Can be used with both relax_new = True and relax_new = False. A specific latname must be provided.*
1764+
- **Availability**: *Only used with relax_method = cg 2. A specific latname must be provided.*
17891765
- **Description**: - True: the lattice type will be preserved during relaxation. The lattice vectors are reconstructed to match the specified Bravais lattice type after each update.
17901766
- False: No restrictions are exerted during relaxation in terms of lattice type
17911767

docs/advanced/opt.md

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
By setting `calculation` to be `relax` or `cell-relax`, ABACUS supports structural relaxation and variable-cell relaxation.
44

5-
ABACUS provides two implementations for variable-cell relaxation, controlled by the [relax_new](./input_files/input-main.md#relax_new) parameter:
5+
ABACUS provides two CG implementations for variable-cell relaxation, selected by the [relax_method](./input_files/input-main.md#relax_method) parameter:
66

7-
- **New implementation** (`relax_new = True`, default since v3.8): Uses a simultaneous conjugate gradient (CG) optimization for both ionic positions and cell parameters. Both degrees of freedom are optimized together in each step.
7+
- **CG variant 2** (`relax_method = cg 2` or `relax_method = cg`, default since v3.8): Uses simultaneous conjugate gradient (CG) optimization for both ionic positions and cell parameters. Both degrees of freedom are optimized together in each step.
88

9-
- **Old implementation** (`relax_new = False`): Follows a nested procedure where fixed-cell structural relaxation is performed first, followed by an update of the cell parameters, and the process is repeated until convergence is achieved.
9+
- **CG variant 1** (`relax_method = cg 1`): Follows a nested procedure where fixed-cell structural relaxation is performed first, followed by an update of the cell parameters, and the process is repeated until convergence is achieved.
1010

11-
An example of the variable cell relaxation can be found in our [repository](https://github.com/deepmodeling/abacus-develop/tree/develop/examples/relax/pw_al), which is provided with the reference output file log.ref. When using the old implementation (`relax_new = False`), each ionic step is labelled in the following manner:
11+
An example of the variable cell relaxation can be found in our [repository](https://github.com/deepmodeling/abacus-develop/tree/develop/examples/relax/pw_al), which is provided with the reference output file log.ref. When using CG variant 1, each ionic step is labelled in the following manner:
1212
```
1313
-------------------------------------------
1414
RELAX CELL : 3
@@ -21,28 +21,22 @@ indicating that this is the first ionic step of the 3rd cell configuration, and
2121

2222
## Optimization Algorithms
2323

24-
ABACUS offers multiple optimization algorithms for structural relaxation, which can be selected using the [relax_method](./input_files/input-main.md#relax_method) keyword. The available algorithms and their behavior depend on the [relax_new](./input_files/input-main.md#relax_new) setting:
24+
ABACUS offers multiple optimization algorithms for structural relaxation, which can be selected using the [relax_method](./input_files/input-main.md#relax_method) keyword. The optional second value selects an implementation variant for CG or BFGS. For both methods, variant 1 is the traditional implementation and variant 2 is the recommended default.
2525

26-
### Algorithm Availability
26+
### Available Algorithms
2727

28-
**New implementation** (`relax_new = True`, default):
29-
- **CG (Conjugate Gradient)**: Simultaneous optimization of both ionic positions and cell parameters using CG with line search. This is the only algorithm available for the new implementation.
30-
31-
**Old implementation** (`relax_new = False`):
32-
- **CG (Conjugate Gradient)**: For ionic relaxation; CG is also used for cell parameter optimization in the nested procedure
33-
- **BFGS**: Quasi-Newton method for ionic relaxation
34-
- **LBFGS**: Limited-memory BFGS for ionic relaxation
35-
- **SD (Steepest Descent)**: Simple gradient descent for ionic relaxation
36-
- **CG-BFGS**: Mixed method that starts with CG and switches to BFGS when force convergence reaches the threshold set by [relax_cg_thr](./input_files/input-main.md#relax_cg_thr)
28+
- **CG (Conjugate Gradient)**: Variant 1 optimizes ionic positions and cell parameters in separate stages; variant 2 optimizes them simultaneously with line search.
29+
- **BFGS**: Quasi-Newton method for ionic relaxation.
30+
- **LBFGS**: Limited-memory BFGS for ionic relaxation.
31+
- **SD (Steepest Descent)**: Simple gradient descent for ionic relaxation.
32+
- **CG-BFGS**: Mixed method that starts with CG and switches to BFGS when force convergence reaches the threshold set by [relax_cg_thr](./input_files/input-main.md#relax_cg_thr).
3733

3834
We also provide a [list of keywords](./input_files/input-main.md#geometry-relaxation) for controlling the relaxation process.
3935

4036
### BFGS method
4137

4238
The [BFGS method](https://en.wikipedia.org/wiki/Broyden%E2%80%93Fletcher%E2%80%93Goldfarb%E2%80%93Shanno_algorithm) is a quasi-Newton method for solving nonlinear optimization problems. It belongs to the class of quasi-Newton methods where the Hessian matrix is approximated during the optimization process. If the initial point is not far from the extrema, BFGS tends to work better than gradient-based methods.
4339

44-
**Note**: BFGS is only available with the old implementation (`relax_new = False`).
45-
4640
ABACUS provides two BFGS implementations, controlled by the second element of [relax_method](./input_files/input-main.md#relax_method):
4741

4842
- **Default BFGS** (`relax_method = bfgs 2` or `relax_method = bfgs`): Updates the inverse of the approximate Hessian matrix B directly. This is the recommended implementation.
@@ -53,14 +47,12 @@ ABACUS provides two BFGS implementations, controlled by the second element of [r
5347

5448
The [L-BFGS (Limited-memory BFGS)](https://en.wikipedia.org/wiki/Limited-memory_BFGS) method is a memory-efficient variant of BFGS that stores only a few vectors representing the Hessian approximation instead of the full matrix. This makes it particularly suitable for large systems with many atoms.
5549

56-
**Note**: LBFGS is only available with the old implementation (`relax_new = False`). Set `relax_method = lbfgs` to use this method.
50+
Set `relax_method = lbfgs` to use this method.
5751

5852
### SD method
5953

6054
The [SD (steepest descent) method](https://en.wikipedia.org/wiki/Gradient_descent) is one of the simplest first-order optimization methods, where in each step the motion is along the direction of the gradient, where the function descends the fastest.
6155

62-
**Note**: SD is only available with the old implementation (`relax_new = False`).
63-
6456
In practice, the SD method may take many iterations to converge, and is generally not recommended for production calculations.
6557

6658
### CG method
@@ -69,9 +61,11 @@ The [CG (conjugate gradient) method](https://en.wikipedia.org/wiki/Conjugate_gra
6961

7062
ABACUS provides two implementations of the CG method:
7163

72-
- **New CG implementation** (`relax_new = True`, default): Performs simultaneous optimization of both ionic positions and cell parameters using a line search algorithm. This implementation is more efficient for `cell-relax` calculations as it optimizes all degrees of freedom together. The step size can be controlled by [relax_scale_force](./input_files/input-main.md#relax_scale_force).
64+
- **CG variant 2** (`relax_method = cg 2` or `relax_method = cg`, default): Performs simultaneous optimization of both ionic positions and cell parameters using a line search algorithm. This implementation is more efficient for `cell-relax` calculations as it optimizes all degrees of freedom together. The step size can be controlled by [relax_scale_force](./input_files/input-main.md#relax_scale_force).
65+
66+
- **CG variant 1** (`relax_method = cg 1`): Uses a nested procedure where ionic positions are optimized first using CG, followed by cell parameter optimization (also using CG) in `cell-relax` calculations. This is the traditional approach where the two optimization steps are separated.
7367

74-
- **Old CG implementation** (`relax_new = False`): Uses a nested procedure where ionic positions are optimized first using CG, followed by cell parameter optimization (also using CG) in `cell-relax` calculations. This is the traditional approach where the two optimization steps are separated.
68+
The former `relax_new` parameter has been removed. Replace `relax_new = True` with `relax_method = cg 2`, and replace `relax_new = False` with `relax_method = cg 1` when using CG. The `bfgs`, `lbfgs`, `sd`, and `cg_bfgs` methods do not require a separate switch.
7569

7670
## Constrained Optimization
7771

@@ -111,17 +105,15 @@ Sometimes we want to do variable-cell relaxation with some of the cell degrees o
111105

112106
**Available constraints by implementation:**
113107

114-
- **New implementation** (`relax_new = True`):
108+
- **CG variant 2** (`relax_method = cg 2` or `relax_method = cg`):
115109
- `fixed_axes = "shape"`: Only allows volume changes (hydrostatic pressure), cell shape is fixed
116110
- `fixed_axes = "volume"`: Allows shape changes but keeps volume constant
117-
- `fixed_axes = "a"`, `"b"`, `"c"`, etc.: Fix specific lattice vectors or combinations
111+
- `fixed_axes = "a"`, `"b"`, `"c"`, `"ab"`, `"ac"`, `"bc"`, or `"abc"`: Fix specific lattice vectors or combinations
118112
- `fixed_ibrav = True`: Maintain the Bravais lattice type during relaxation
119113

120-
- **Old implementation** (`relax_new = False`):
121-
- **All `fixed_axes` options now supported**: "shape", "volume", "a", "b", "c", "ab", "ac", "bc", "abc"
122-
- **`fixed_ibrav` now supported**: Maintains Bravais lattice type during relaxation
123-
- Can combine `fixed_axes` with `fixed_ibrav` for constrained relaxation
124-
- **Implementation approach**: Uses post-update constraint enforcement (volume rescaling and lattice reconstruction after each CG step)
114+
- **`relax_method = cg 1`, `bfgs`, `lbfgs`, `sd`, or `cg_bfgs`**:
115+
- `fixed_axes = "a"`, `"b"`, `"c"`, `"ab"`, `"ac"`, `"bc"`, or `"abc"`: Fix specific lattice vectors or combinations
116+
- `fixed_axes = "shape"`, `"volume"` and `fixed_ibrav = True` are not available
125117

126118
**VASP ISIF correspondence:**
127119

@@ -142,4 +134,4 @@ Providing a file named `EXIT`:
142134
```
143135
stop_ion true
144136
```
145-
ABACUS will end normally and produce a complete file.
137+
ABACUS will end normally and produce a complete file.

0 commit comments

Comments
 (0)