Skip to content

Commit ad561b7

Browse files
authored
Option to disable rotation in initial guess (#486)
* added option to disable rotation of orbitals before calculating the initial guess energy * small typo * added rotate option to schema_input.json * fixed small typos * remove temporary files generated by updating the input parser * update .gitignore file * Revert "update .gitignore file" This reverts commit 166c32d. * Revert "remove temporary files generated by updating the input parser" This reverts commit 8240e30. * throw warning when trying to run update_input_parser.py while python/mrchem/input_parser/plumbing/pyparsing already exists
1 parent d5805a3 commit ad561b7

14 files changed

+65
-28
lines changed

doc/users/schema_input.json

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"zeta": int, # Zeta quality for AO basis
102102
"method": string, # Name of method for initial energy
103103
"localize": bool, # Use localized orbitals
104+
"rotate": bool, # Rotate orbitals in initial guess
104105
"restricted": bool, # Use spin restricted orbitals
105106
"relativity": string, # Name of relativistic method
106107
"screen": float, # Screening used in GTO evaluations

doc/users/user_inp.rst

+1
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ The ``core`` and ``sad`` guesses are fully specified with the following keywords
449449
guess_prec = 1.0e-3 # Numerical precision used in guess
450450
guess_type = sad_gto # Type of inital guess (chk, mw, cube, core_XX, sad_XX)
451451
guess_screen = 12.0 # Number of StdDev before a GTO is set to zero (sad_gto)
452+
guess_rotate = true # Localize/Diagonalize guess orbitals before calculating the initial guess energy
452453
}
453454
454455
Checkpointing

doc/users/user_ref.rst

+12-6
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ User input reference
231231

232232
**Default** ``-1``
233233

234-
:omp_threads: Force the number of OpenMP threads.
235-
234+
:omp_threads: Force the number of omp threads (leave default is better).
235+
236236
**Type** ``int``
237-
237+
238238
**Default** ``-1``
239-
240-
:Basis: Define polynomial basis.
239+
240+
:Basis: Define polynomial basis.
241241

242242
:red:`Keywords`
243243
:order: Polynomial order of multiwavelet basis. Negative value means it will be set automatically based on the world precision.
@@ -722,6 +722,12 @@ User input reference
722722
**Predicates**
723723
- ``value[-1] != '/'``
724724

725+
:guess_rotate: Localize/Diagonalize the initial guess orbitals before calculating the initial guess energy.
726+
727+
**Type** ``bool``
728+
729+
**Default** ``True``
730+
725731
:write_orbitals: Write final orbitals to disk, file name ``<path_orbitals>/phi_<p/a/b>_scf_idx_<0..Np/Na/Nb>``. Can be used as ``mw`` initial guess in subsequent calculations.
726732

727733
**Type** ``bool``
@@ -12209,4 +12215,4 @@ User input reference
1220912215
**Type** ``float``
1221012216

1221112217
**Default** ``0.00011186082063``
12212-
12218+

python/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ To run the script:
1212

1313
```bash
1414
$ cd python/mrchem
15+
$ rm -r input_parser/plumbing/pyparsing
1516
$ python update_input_parser.py
1617
```
1718

@@ -24,7 +25,7 @@ This does three things:
2425
Each of these steps can be deactivated by appropriate flags. For help on running the script, run
2526

2627
```bash
27-
$ cd python
28+
$ cd python/mrchem
2829
$ python update_input_parser.py -h
2930
```
3031

@@ -33,7 +34,8 @@ If the `Constants` and `Elements` input sections are unchanged, you can update t
3334
The utility script can also do this, by specifying the flag `--skip-template`:
3435

3536
```bash
36-
$ cd python
37+
$ cd python/mrchem
38+
$ rm -r input_parser/plumbing/pyparing
3739
$ python update_input_parser --skip-template
3840
```
3941

@@ -43,6 +45,7 @@ You can also perform these steps manually without using the utility script:
4345

4446
```bash
4547
$ cd python
48+
$ rm -r mrchem/input_parser/plumbing/pyparsing
4649
$ parselglossy generate --template template.yml --docfile user_ref.rst --doc-header="User input reference" --target="mrchem/input_parser"
4750
$ cp mrchem/input_parser/docs/user_ref.rst ../doc/users/user_ref.rst
4851
```

python/mrchem/helpers.py

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def write_scf_guess(user_dict, wf_dict):
224224
"external_field": wf_dict["external_name"],
225225
"screen": scf_dict["guess_screen"],
226226
"localize": scf_dict["localize"],
227+
"rotate": scf_dict["guess_rotate"],
227228
"restricted": user_dict["WaveFunction"]["restricted"],
228229
"file_chk": f"{scf_dict['path_checkpoint']}/phi_scf",
229230
"file_basis": file_dict["guess_basis"],

python/mrchem/input_parser/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
This file was automatically generated by parselglossy on 2024-01-29
1+
This file was automatically generated by parselglossy on 2024-05-14
22
Editing is *STRONGLY DISCOURAGED*
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# -*- coding: utf-8 -*-
22

3-
# This file was automatically generated by parselglossy on 2024-01-29
3+
# This file was automatically generated by parselglossy on 2024-05-14
44
# Editing is *STRONGLY DISCOURAGED*

python/mrchem/input_parser/api.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
# This file was automatically generated by parselglossy on 2024-02-08
3+
# This file was automatically generated by parselglossy on 2024-05-14
44
# Editing is *STRONGLY DISCOURAGED*
55

66
from copy import deepcopy
@@ -510,6 +510,9 @@ def stencil() -> JSONDict:
510510
'name': 'path_orbitals',
511511
'predicates': ["value[-1] != '/'"],
512512
'type': 'str'},
513+
{ 'default': True,
514+
'name': 'guess_rotate',
515+
'type': 'bool'},
513516
{ 'default': "user['GeometryOptimizer']['use_previous_guess']",
514517
'name': 'write_orbitals',
515518
'type': 'bool'},

python/mrchem/input_parser/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
# This file was automatically generated by parselglossy on 2024-01-29
3+
# This file was automatically generated by parselglossy on 2024-05-14
44
# Editing is *STRONGLY DISCOURAGED*
55

66
import argparse

python/mrchem/input_parser/docs/user_ref.rst

+12
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ User input reference
231231

232232
**Default** ``-1``
233233

234+
:omp_threads: Force the number of omp threads (leave default is better).
235+
236+
**Type** ``int``
237+
238+
**Default** ``-1``
239+
234240
:Basis: Define polynomial basis.
235241

236242
:red:`Keywords`
@@ -716,6 +722,12 @@ User input reference
716722
**Predicates**
717723
- ``value[-1] != '/'``
718724

725+
:guess_rotate: Localize/Diagonalize the initial guess orbitals before calculating the initial guess energy.
726+
727+
**Type** ``bool``
728+
729+
**Default** ``True``
730+
719731
:write_orbitals: Write final orbitals to disk, file name ``<path_orbitals>/phi_<p/a/b>_scf_idx_<0..Np/Na/Nb>``. Can be used as ``mw`` initial guess in subsequent calculations.
720732

721733
**Type** ``bool``

python/mrchem/input_parser/plumbing/lexer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
# This file was automatically generated by parselglossy on 2024-01-29
3+
# This file was automatically generated by parselglossy on 2024-05-14
44
# Editing is *STRONGLY DISCOURAGED*
55

66
import json

python/mrchem/update_input_parser.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -220,20 +220,24 @@ def update_periodic_table():
220220

221221
def run_parselglossy():
222222
os.chdir(root)
223-
cmd = [
224-
"parselglossy",
225-
"generate",
226-
"--template",
227-
"template.yml",
228-
"--docfile",
229-
"user_ref.rst",
230-
"--doc-header",
231-
"User input reference",
232-
"--target",
233-
target,
234-
]
223+
pyparsing_path = target.joinpath("plumbing", "pyparsing")
224+
if os.path.isdir(pyparsing_path):
225+
print(f"{pyparsing_path} already exists. Please delete this directory to run the script.")
226+
else:
227+
cmd = [
228+
"parselglossy",
229+
"generate",
230+
"--template",
231+
"template.yml",
232+
"--docfile",
233+
"user_ref.rst",
234+
"--doc-header",
235+
"User input reference",
236+
"--target",
237+
target,
238+
]
235239

236-
subprocess.call(cmd)
240+
subprocess.call(cmd)
237241

238242

239243
def update_doc():

python/template.yml

+5
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,11 @@ sections:
711711
Path to where converged orbitals will be written in connection with
712712
the ``write_orbitals`` keyword. Note: must be given in quotes if
713713
there are slashes in the path "path/to/orbitals".
714+
- name: guess_rotate
715+
type: bool
716+
default: true
717+
docstring: |
718+
Localize/Diagonalize the initial guess orbitals before calculating the initial guess energy.
714719
- name: Response
715720
docstring: |
716721
Includes parameters related to the response SCF optimization.

src/driver.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ bool driver::scf::guess_energy(const json &json_guess, Molecule &mol, FockBuilde
405405
auto environment = json_guess["environment"];
406406
auto external_field = json_guess["external_field"];
407407
auto localize = json_guess["localize"];
408+
auto rotate = json_guess["rotate"];
408409

409410
mrcpp::print::separator(0, '~');
410411
print_utils::text(0, "Calculation ", "Compute initial energy");
@@ -425,14 +426,14 @@ bool driver::scf::guess_energy(const json &json_guess, Molecule &mol, FockBuilde
425426
auto &F_mat = mol.getFockMatrix();
426427

427428
F_mat = ComplexMatrix::Zero(Phi.size(), Phi.size());
428-
if (localize) orbital::localize(prec, Phi, F_mat);
429+
if (localize && rotate) orbital::localize(prec, Phi, F_mat);
429430

430431
F.setup(prec);
431432
F_mat = F(Phi, Phi);
432433
mol.getSCFEnergy() = F.trace(Phi, nucs);
433434
F.clear();
434435

435-
if (not localize) orbital::diagonalize(prec, Phi, F_mat);
436+
if (not localize && rotate) orbital::diagonalize(prec, Phi, F_mat);
436437
if (plevel == 1) mrcpp::print::footer(1, t_scf, 2);
437438

438439
Timer t_eps;

0 commit comments

Comments
 (0)