Skip to content

Commit 4ed50cb

Browse files
authored
Feature&Doc: support fix_axes and fix_ibrav for relax_new=false and optimized doc (#6858)
* Feature&Doc: support fix_axes and fix_ibrav for relax_new=false * Fix: UT error of fixed_axes
1 parent 25b3125 commit 4ed50cb

13 files changed

Lines changed: 972 additions & 125 deletions

docs/advanced/input_files/input-main.md

Lines changed: 70 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,27 +1530,45 @@ These variables are used to control the geometry relaxation.
15301530
### relax_method
15311531

15321532
- **Type**: Vector of string
1533-
- **Description**: The methods to do geometry optimization.
1534-
the first element:
1535-
- cg: using the conjugate gradient (CG) algorithm. Note that there are two implementations of the conjugate gradient (CG) method, see [relax_new](#relax_new).
1536-
- bfgs : using the Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm.
1537-
- lbfgs: using the Limited-memory Broyden–Fletcher–Goldfarb–Shanno (LBFGS) algorithm.
1538-
- cg_bfgs: using the CG method for the initial steps, and switching to BFGS method when the force convergence is smaller than [relax_cg_thr](#relax_cg_thr).
1539-
- sd: using the steepest descent (SD) algorithm.
1540-
- fire: the Fast Inertial Relaxation Engine method (FIRE), a kind of molecular-dynamics-based relaxation algorithm, is implemented in the molecular dynamics (MD) module. The algorithm can be used by setting [calculation](#calculation) to `md` and [md_type](#md_type) to `fire`. Also ionic velocities should be set in this case. See [fire](../md.md#fire) for more details.
1541-
1542-
the second element:
1543-
when the first element is bfgs, if the second parameter is 1, it indicates the use of the new BFGS algorithm; if the second parameter is not 1, it indicates the use of the old BFGS algorithm.
1544-
- **Default**: cg 1
1545-
- **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".
1533+
- **Description**: The methods to do geometry optimization. The available algorithms depend on the [relax_new](#relax_new) setting.
1534+
1535+
**First element** (algorithm selection):
1536+
- `cg`: Conjugate gradient (CG) algorithm. Available for both `relax_new = True` (default, simultaneous optimization) and `relax_new = False` (nested optimization). See [relax_new](#relax_new) for implementation details.
1537+
- `bfgs`: Broyden–Fletcher–Goldfarb–Shanno (BFGS) quasi-Newton algorithm. **Only available when `relax_new = False`**.
1538+
- `lbfgs`: Limited-memory BFGS algorithm, suitable for large systems. **Only available when `relax_new = False`**.
1539+
- `cg_bfgs`: Mixed method starting with CG and switching to BFGS when force convergence reaches [relax_cg_thr](#relax_cg_thr). **Only available when `relax_new = False`**.
1540+
- `sd`: Steepest descent algorithm. **Only available when `relax_new = False`**. Not recommended for production use.
1541+
- `fire`: Fast Inertial Relaxation Engine method, a molecular-dynamics-based relaxation algorithm. Use by setting [calculation](#calculation) to `md` and [md_type](#md_type) to `fire`. Ionic velocities must be set in STRU file. See [fire](../md.md#fire) for details.
1542+
1543+
**Second element** (BFGS variant, only when first element is `bfgs`):
1544+
- `1`: Traditional BFGS that updates the Hessian matrix B and then inverts it.
1545+
- `2` or omitted: Default BFGS that directly updates the inverse Hessian (recommended).
1546+
1547+
- **Default**: `cg 1`
1548+
- **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".
15461549

15471550
### relax_new
15481551

15491552
- **Type**: Boolean
1550-
- **Description**: At around the end of 2022 we made a new implementation of the Conjugate Gradient (CG) method for `relax` and `cell-relax` calculations. But the old implementation was also kept.
1551-
- True: use the new implementation of CG method for `relax` and `cell-relax` calculations.
1552-
- False: use the old implementation of CG method for `relax` and `cell-relax` calculations.
1553+
- **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.
1554+
1555+
- **True** (default): Use the new CG implementation with the following features:
1556+
- Simultaneous optimization of ionic positions and cell parameters (for `cell-relax`)
1557+
- Line search algorithm for step size determination
1558+
- Only CG algorithm is available (`relax_method` must be `cg`)
1559+
- Supports advanced cell constraints: `fixed_axes = "shape"`, `"volume"`, `"a"`, `"b"`, `"c"`, etc.
1560+
- Supports `fixed_ibrav` to maintain lattice type
1561+
- More efficient for variable-cell relaxation
1562+
- Step size controlled by [relax_scale_force](#relax_scale_force)
1563+
1564+
- **False**: Use the old implementation with the following features:
1565+
- Nested optimization procedure: ionic positions optimized first, then cell parameters (for `cell-relax`)
1566+
- Multiple algorithms available: `cg`, `bfgs`, `lbfgs`, `sd`, `cg_bfgs`
1567+
- Limited cell constraints: only `fixed_axes = "volume"` is supported
1568+
- Traditional approach with separate ionic and cell optimization steps
1569+
15531570
- **Default**: True
1571+
- **Recommendation**: Use `relax_new = True` (default) for most cases, especially for `cell-relax` calculations. Use `relax_new = False` only if you need BFGS/LBFGS algorithms or for reproducing old results.
15541572

15551573
### relax_scale_force
15561574

@@ -1568,7 +1586,8 @@ These variables are used to control the geometry relaxation.
15681586
### relax_cg_thr
15691587

15701588
- **Type**: Real
1571-
- **Description**: When move-method is set to `cg_bfgs`, a mixed algorithm of conjugate gradient (CG) method and Broyden–Fletcher–Goldfarb–Shanno (BFGS) method is used. The ions first move according to CG method, then switched to BFGS method when the maximum of force on atoms is reduced below the CG force threshold, which is set by this parameter.
1589+
- **Availability**: Only used when `relax_new = False` and `relax_method = cg_bfgs`
1590+
- **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.
15721591
- **Default**: 0.5
15731592
- **Unit**: eV/Angstrom
15741593

@@ -1604,33 +1623,38 @@ These variables are used to control the geometry relaxation.
16041623
### relax_bfgs_w1
16051624

16061625
- **Type**: Real
1607-
- **Description**: Controls the Wolfe condition for Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm used in geometry relaxation. You can look into the paper Phys.Chem.Chem.Phys.,2000,2,2177 for more information.
1626+
- **Availability**: Only used when `relax_new = False` and `relax_method` is `bfgs` or `cg_bfgs`
1627+
- **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.
16081628
- **Default**: 0.01
16091629

16101630
### relax_bfgs_w2
16111631

16121632
- **Type**: Real
1613-
- **Description**: Controls the Wolfe condition for Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm used in geometry relaxation. You can look into the paper Phys.Chem.Chem.Phys.,2000,2,2177 for more information.
1633+
- **Availability**: Only used when `relax_new = False` and `relax_method` is `bfgs` or `cg_bfgs`
1634+
- **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.
16141635
- **Default**: 0.5
16151636

16161637
### relax_bfgs_rmax
16171638

16181639
- **Type**: Real
1619-
- **Description**: For geometry optimization. It stands for the maximal movement of all the atoms. The sum of the movements from all atoms can be increased during the optimization steps. However, it can not be larger than `relax_bfgs_rmax`.
1620-
- **Unit**: Bohr
1640+
- **Availability**: Only used when `relax_new = False` and `relax_method` is `bfgs` or `cg_bfgs`
1641+
- **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.
16211642
- **Default**: 0.8
1643+
- **Unit**: Bohr
16221644

16231645
### relax_bfgs_rmin
16241646

16251647
- **Type**: Real
1626-
- **Description**: In old bfgs algorithm, it indicates the minimal movement of all the atoms. When the movement of all the atoms is smaller than relax_bfgs_rmin Bohr, and the force convergence is still not achieved, the calculation will break down. In the current default bfgs algorithm, this parameter is not used.
1648+
- **Availability**: Only used when `relax_new = False` and `relax_method = bfgs 1` (traditional BFGS)
1649+
- **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`).
16271650
- **Default**: 1e-5
16281651
- **Unit**: Bohr
16291652

16301653
### relax_bfgs_init
16311654

16321655
- **Type**: Real
1633-
- **Description**: For geometry optimization. It stands for the sum of initial movements of all of the atoms.
1656+
- **Availability**: Only used when `relax_new = False` and `relax_method` is `bfgs` or `cg_bfgs`
1657+
- **Description**: Initial total displacement of all atoms in the first BFGS step. This sets the scale for the initial movement.
16341658
- **Default**: 0.5
16351659
- **Unit**: Bohr
16361660

@@ -1659,31 +1683,38 @@ These variables are used to control the geometry relaxation.
16591683
### fixed_axes
16601684

16611685
- **Type**: String
1662-
- **Availability**: Only used when `calculation` set to `cell-relax`
1663-
- **Description**: Axes that are fixed during cell relaxation. Possible choices are:
1664-
- None**: default; all of the axes can relax
1665-
- volume**: relaxation with fixed volume
1666-
- shape**: fix shape but change volume (i.e. only lattice constant changes)
1667-
- a: fix a axis during relaxation
1668-
- b: fix b axis during relaxation
1669-
- c: fix c axis during relaxation
1670-
- ab: fix both a and b axes during relaxation
1671-
- ac: fix both a and c axes during relaxation
1672-
- bc: fix both b and c axes during relaxation
1673-
1674-
> Note : fixed_axes = "shape" and "volume" are only available for [relax_new](#relax_new) = True
1686+
- **Availability**: Only used when `calculation` is set to `cell-relax`
1687+
- **Description**: Specifies which cell degrees of freedom are fixed during variable-cell relaxation. The available options depend on the [relax_new](#relax_new) setting:
1688+
1689+
**When `relax_new = True` (default)**, all options are available:
1690+
- `None`: Default; all cell parameters can relax freely
1691+
- `volume`: Relaxation with fixed volume (allows shape changes)
1692+
- `shape`: Fix shape but allow volume changes (hydrostatic pressure only)
1693+
- `a`: Fix the a-axis lattice vector during relaxation
1694+
- `b`: Fix the b-axis lattice vector during relaxation
1695+
- `c`: Fix the c-axis lattice vector during relaxation
1696+
- `ab`: Fix both a and b axes during relaxation
1697+
- `ac`: Fix both a and c axes during relaxation
1698+
- `bc`: Fix both b and c axes during relaxation
1699+
1700+
**When `relax_new = False`**, all options are now available:
1701+
- `None`: Default; all cell parameters can relax freely
1702+
- `volume`: Relaxation with fixed volume (allows shape changes). Volume is preserved by rescaling the lattice after each update.
1703+
- `shape`: Fix shape but allow volume changes (hydrostatic pressure only). Stress tensor is replaced with isotropic pressure.
1704+
- `a`, `b`, `c`, `ab`, `ac`, `bc`: Fix specific lattice vectors. Gradients for fixed vectors are set to zero.
16751705

16761706
- **Default**: None
1707+
- **Note**: For VASP users, see the [ISIF correspondence table](../opt.md#fixing-cell-parameters) in the geometry optimization documentation. Both implementations now support all constraint types.
16771708

16781709
### fixed_ibrav
16791710

16801711
- **Type**: Boolean
1681-
- **Availability**: Must be used along with [relax_new](#relax_new) set to True, and a specific [latname](#latname) must be provided
1712+
- **Availability**: Can be used with both `relax_new = True` and `relax_new = False`. A specific [latname](#latname) must be provided.
16821713
- **Description**:
1683-
- True: the lattice type will be preserved during relaxation
1714+
- True: the lattice type will be preserved during relaxation. The lattice vectors are reconstructed to match the specified Bravais lattice type after each update.
16841715
- False: No restrictions are exerted during relaxation in terms of lattice type
16851716

1686-
> Note: it is possible to use `fixed_ibrav` with `fixed_axes`, but please make sure you know what you are doing. For example, if we are doing relaxation of a simple cubic lattice (`latname` = "sc"), and we use `fixed_ibrav` along with `fixed_axes` = "volume", then the cell is never allowed to move and as a result, the relaxation never converges.
1717+
> Note: it is possible to use `fixed_ibrav` with `fixed_axes`, but please make sure you know what you are doing. For example, if we are doing relaxation of a simple cubic lattice (`latname` = "sc"), and we use `fixed_ibrav` along with `fixed_axes` = "volume", then the cell is never allowed to move and as a result, the relaxation never converges. When both are used, `fixed_ibrav` is applied first, then `fixed_axes = "volume"` rescaling is applied.
16871718
16881719
- **Default**: False
16891720

0 commit comments

Comments
 (0)