Skip to content

Feature/constraints#1155

Draft
cpignedoli wants to merge 2 commits intoaiidateam:mainfrom
cpignedoli:feature/constraints
Draft

Feature/constraints#1155
cpignedoli wants to merge 2 commits intoaiidateam:mainfrom
cpignedoli:feature/constraints

Conversation

@cpignedoli
Copy link
Contributor

This is the first draft allowing for the constraint "distance"
It forces the key ion_dynamics 'fire' in the 'relax' calculation.
Still, I think we should warn/enforce no_symm.
Following this line, I could add other constraints (angle and dihedral); @mbercx what do you think?

@AndresOrtegaGuerrero
Copy link
Collaborator

I think some changes and check should be done in PwRelaxWorkChain (src/aiida_quantumespresso/workflows/pw/relax.py), since in principle the CONSTRAINTS are applied to the relaxation workflow, depending on the RelaxType (src/aiida_quantumespresso/common/types.py)

# ============ I prepare the CONSTRAINTS card =============
constraints = settings.pop('CONSTRAINTS', None)
if constraints is not None:
input_params['IONS']['ion_dynamics'] = 'fire'
Copy link
Member

@mbercx mbercx Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? If so, I would validate this in validate_inputs. We can also set this there if it's more user-friendly, and raise a warning.

EDIT: Seems you can also set damp or verlet, and there may be a use case for this?

https://www.quantum-espresso.org/Doc/INPUT_PW.html#idm1620

Copy link
Contributor Author

@cpignedoli cpignedoli Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbercx you are right, I overlooked the damp option we should support it as well.
verlet is for md type of calculation, I did not have this in mind at teh moment, I was focusing on relax

constraints = settings.pop('CONSTRAINTS', None)
if constraints is not None:
input_params['IONS']['ion_dynamics'] = 'fire'
constraints_card_list = ['CONSTRAINTS\n']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you show me an example from an input file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mbercx, here is an example I ran (it fails due to symmetries, but the constraint is parsed).
In the first line of the constraint, you have '1 1e-6': the total number of constraints and the tolerance (unfortunately, only a global tolerance seems to be allowed)

&CONTROL
  calculation = 'relax'
  etot_conv_thr =   9.0000000000d-04
  forc_conv_thr =   1.0000000000d-03
  max_seconds =   4.1040000000d+04
  nstep = 50
  outdir = './out/'
  prefix = 'aiida'
  pseudo_dir = './pseudo/'
  tprnfor = .true.
  tstress = .true.
  verbosity = 'high'
/
&SYSTEM
  degauss =   2.7500000000d-02
  ecutrho =   4.0000000000d+02
  ecutwfc =   5.0000000000d+01
  ibrav = 0
  nat = 9
  nosym = .false.
  ntyp = 2
  occupations = 'smearing'
  smearing = 'cold'
  tot_charge =   0.0000000000d+00
  vdw_corr = 'none'
/
&ELECTRONS
  conv_thr =   3.6000000000d-09
  electron_maxstep = 80
  mixing_beta =   4.0000000000d-01
/
&IONS
  ion_dynamics = 'fire'
/
ATOMIC_SPECIES
O      15.999 O.pbesol-n-kjpaw_psl.0.1.UPF
Si     28.085 Si.pbesol-n-rrkjus_psl.1.0.0.UPF
ATOMIC_POSITIONS angstrom
Si           1.1911527876       2.0631371475       0.0000000000 1 1 1
Si           2.6106944249       0.0000000000       3.6186666668 1 1 1
Si          -1.3053472125       2.2609276935       1.8093333333 1 1 1
O           -0.8256234071       3.6317748754       2.5091163607 1 1 1
O           -0.2358975994       1.7931665587       0.6997830273 1 1 1
O            1.0615210065       3.2231882479       4.3184496942 1 1 1
O            3.5580210066       1.1008765932       2.9188836393 1 1 1
O            1.6708765929       0.6922899656       4.7282169727 1 1 1
O            2.2606024006       2.5308982824       1.1095503059 1 1 1
K_POINTS automatic
5 5 4 0 0 0
CONSTRAINTS
1 1e-6
distance 1 5 1.65
CELL_PARAMETERS angstrom
      4.9930000000       0.0000000000       0.0000000000
     -2.4965000000       4.3240648411       0.0000000000
      0.0000000000       0.0000000000       5.4280000000

@mbercx
Copy link
Member

mbercx commented Sep 25, 2025

I think some changes and check should be done in PwRelaxWorkChain (src/aiida_quantumespresso/workflows/pw/relax.py), since in principle the CONSTRAINTS are applied to the relaxation workflow, depending on the RelaxType (src/aiida_quantumespresso/common/types.py)

Can you elaborate on the changes/checks you think are required? I'm not very familiar with CONSTRAINTS, so I'm trying to understand.

@mbercx
Copy link
Member

mbercx commented Sep 25, 2025

Thanks @cpignedoli! Would be a nice addition. I've left a few questions so far. Could you show me an example snippet of usage? Then I can test it more easily, thanks!

@mbercx
Copy link
Member

mbercx commented Sep 25, 2025

Note: I'll be adapting our devops stack soon, including our formatter/linter, so that might lead to merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants