I want to do an ionic relaxation of just the ions inside my unit cell (not the cell dimensions), with Quantum Espresso through ASE. However, I have only been able to find structure optimization methods in the [documentation][1] that:

  • Use ASE's own algorithms (not the QE methods one).
  • Do not allow me to control what to relax and what to freeze (ie, cell dimensions, ions, etc)

So far this is what I have been able to produce.

from ase.calculators.espresso import Espresso
from ase.constraints import UnitCellFilter
from ase.optimize import LBFGS
from ase import Atoms

pseudopotentials = {'Cl': 'Cl.pz-nl-rrkjus_psl.1.0.0.UPF',
                            'Na': 'Na.pz-spnl-rrkjus_psl.1.0.0.UPF'}

symbols = ["Na", "Na", "Na", "Na",
           "Cl", "Cl", "Cl", "Cl",]
cell = [[5.69, 0.00, 0.00],
        [0.00, 5.69, 0.00],
        [0.00, 0.00, 5.69]]
scaled_positions = [[0.00, 0.00, 0.00],
                    [0.00, 0.50, 0.50],
                    [0.50, 0.00, 0.50],
                    [0.50, 0.50, 0.00],
                    [0.50, 0.50, 0.50],
                    [0.50, 0.00, 0.00],
                    [0.00, 0.50, 0.00],
                    [0.00, 0.00, 0.50]]

rocksalt = Atoms(symbols=symbols,

calc = Espresso(pseudopotentials=pseudopotentials,
                kpts=(1, 1, 1))
rocksalt.calc = calc

ucf = UnitCellFilter(rocksalt)
opt = LBFGS(ucf)

I was wondering if there is something along the lines of:

rocksalt.relaxation(cell=(x=False, y=False, z=False), ions=True)


  • $\begingroup$ I think you can do that using the UnitCellFilter object. Look at the arguments for UnitCellFilter here, using the mask argument should be able to fix the cell. $\endgroup$
    – CW Tan
    May 11, 2023 at 2:48

2 Answers 2


When you use an ASE optimizer to relax your structure, it doesn't relax your unit cell by default. It is only necessary to use UnitCellFilter when you want to simultaneously optimize the ionic positions and unit cell. In that case, I often use the improved version ExpCellFilter.


i) If you do not want to relax your unit cell dimension, do not use the UnitCellFilter or equivalent.

ii) I think you are looking for the constraints module to fix positions. See also the docs.

  • $\begingroup$ As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. $\endgroup$
    – Community Bot
    Oct 24, 2023 at 13:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .