Skip to content

Commit

Permalink
Option to disable rotation in initial guess (#486)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
msnik1999 committed May 30, 2024
1 parent d5805a3 commit ad561b7
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 28 deletions.
1 change: 1 addition & 0 deletions doc/users/schema_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"zeta": int, # Zeta quality for AO basis
"method": string, # Name of method for initial energy
"localize": bool, # Use localized orbitals
"rotate": bool, # Rotate orbitals in initial guess
"restricted": bool, # Use spin restricted orbitals
"relativity": string, # Name of relativistic method
"screen": float, # Screening used in GTO evaluations
Expand Down
1 change: 1 addition & 0 deletions doc/users/user_inp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ The ``core`` and ``sad`` guesses are fully specified with the following keywords
guess_prec = 1.0e-3 # Numerical precision used in guess
guess_type = sad_gto # Type of inital guess (chk, mw, cube, core_XX, sad_XX)
guess_screen = 12.0 # Number of StdDev before a GTO is set to zero (sad_gto)
guess_rotate = true # Localize/Diagonalize guess orbitals before calculating the initial guess energy
}
Checkpointing
Expand Down
18 changes: 12 additions & 6 deletions doc/users/user_ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ User input reference

**Default** ``-1``

:omp_threads: Force the number of OpenMP threads.

:omp_threads: Force the number of omp threads (leave default is better).
**Type** ``int``

**Default** ``-1``

:Basis: Define polynomial basis.
:Basis: Define polynomial basis.

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

:guess_rotate: Localize/Diagonalize the initial guess orbitals before calculating the initial guess energy.

**Type** ``bool``

**Default** ``True``

: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.

**Type** ``bool``
Expand Down Expand Up @@ -12209,4 +12215,4 @@ User input reference
**Type** ``float``

**Default** ``0.00011186082063``


7 changes: 5 additions & 2 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ To run the script:

```bash
$ cd python/mrchem
$ rm -r input_parser/plumbing/pyparsing
$ python update_input_parser.py
```

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

```bash
$ cd python
$ cd python/mrchem
$ python update_input_parser.py -h
```

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

```bash
$ cd python
$ cd python/mrchem
$ rm -r input_parser/plumbing/pyparing
$ python update_input_parser --skip-template
```

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

```bash
$ cd python
$ rm -r mrchem/input_parser/plumbing/pyparsing
$ parselglossy generate --template template.yml --docfile user_ref.rst --doc-header="User input reference" --target="mrchem/input_parser"
$ cp mrchem/input_parser/docs/user_ref.rst ../doc/users/user_ref.rst
```
1 change: 1 addition & 0 deletions python/mrchem/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def write_scf_guess(user_dict, wf_dict):
"external_field": wf_dict["external_name"],
"screen": scf_dict["guess_screen"],
"localize": scf_dict["localize"],
"rotate": scf_dict["guess_rotate"],
"restricted": user_dict["WaveFunction"]["restricted"],
"file_chk": f"{scf_dict['path_checkpoint']}/phi_scf",
"file_basis": file_dict["guess_basis"],
Expand Down
2 changes: 1 addition & 1 deletion python/mrchem/input_parser/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This file was automatically generated by parselglossy on 2024-01-29
This file was automatically generated by parselglossy on 2024-05-14
Editing is *STRONGLY DISCOURAGED*
2 changes: 1 addition & 1 deletion python/mrchem/input_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

# This file was automatically generated by parselglossy on 2024-01-29
# This file was automatically generated by parselglossy on 2024-05-14
# Editing is *STRONGLY DISCOURAGED*
5 changes: 4 additions & 1 deletion python/mrchem/input_parser/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

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

from copy import deepcopy
Expand Down Expand Up @@ -510,6 +510,9 @@ def stencil() -> JSONDict:
'name': 'path_orbitals',
'predicates': ["value[-1] != '/'"],
'type': 'str'},
{ 'default': True,
'name': 'guess_rotate',
'type': 'bool'},
{ 'default': "user['GeometryOptimizer']['use_previous_guess']",
'name': 'write_orbitals',
'type': 'bool'},
Expand Down
2 changes: 1 addition & 1 deletion python/mrchem/input_parser/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

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

import argparse
Expand Down
12 changes: 12 additions & 0 deletions python/mrchem/input_parser/docs/user_ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ User input reference

**Default** ``-1``

:omp_threads: Force the number of omp threads (leave default is better).

**Type** ``int``

**Default** ``-1``

:Basis: Define polynomial basis.

:red:`Keywords`
Expand Down Expand Up @@ -716,6 +722,12 @@ User input reference
**Predicates**
- ``value[-1] != '/'``

:guess_rotate: Localize/Diagonalize the initial guess orbitals before calculating the initial guess energy.

**Type** ``bool``

**Default** ``True``

: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.

**Type** ``bool``
Expand Down
2 changes: 1 addition & 1 deletion python/mrchem/input_parser/plumbing/lexer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

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

import json
Expand Down
30 changes: 17 additions & 13 deletions python/mrchem/update_input_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,24 @@ def update_periodic_table():

def run_parselglossy():
os.chdir(root)
cmd = [
"parselglossy",
"generate",
"--template",
"template.yml",
"--docfile",
"user_ref.rst",
"--doc-header",
"User input reference",
"--target",
target,
]
pyparsing_path = target.joinpath("plumbing", "pyparsing")
if os.path.isdir(pyparsing_path):
print(f"{pyparsing_path} already exists. Please delete this directory to run the script.")
else:
cmd = [
"parselglossy",
"generate",
"--template",
"template.yml",
"--docfile",
"user_ref.rst",
"--doc-header",
"User input reference",
"--target",
target,
]

subprocess.call(cmd)
subprocess.call(cmd)


def update_doc():
Expand Down
5 changes: 5 additions & 0 deletions python/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,11 @@ sections:
Path to where converged orbitals will be written in connection with
the ``write_orbitals`` keyword. Note: must be given in quotes if
there are slashes in the path "path/to/orbitals".
- name: guess_rotate
type: bool
default: true
docstring: |
Localize/Diagonalize the initial guess orbitals before calculating the initial guess energy.
- name: Response
docstring: |
Includes parameters related to the response SCF optimization.
Expand Down
5 changes: 3 additions & 2 deletions src/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ bool driver::scf::guess_energy(const json &json_guess, Molecule &mol, FockBuilde
auto environment = json_guess["environment"];
auto external_field = json_guess["external_field"];
auto localize = json_guess["localize"];
auto rotate = json_guess["rotate"];

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

F_mat = ComplexMatrix::Zero(Phi.size(), Phi.size());
if (localize) orbital::localize(prec, Phi, F_mat);
if (localize && rotate) orbital::localize(prec, Phi, F_mat);

F.setup(prec);
F_mat = F(Phi, Phi);
mol.getSCFEnergy() = F.trace(Phi, nucs);
F.clear();

if (not localize) orbital::diagonalize(prec, Phi, F_mat);
if (not localize && rotate) orbital::diagonalize(prec, Phi, F_mat);
if (plevel == 1) mrcpp::print::footer(1, t_scf, 2);

Timer t_eps;
Expand Down

0 comments on commit ad561b7

Please sign in to comment.