Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/source/background/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. Copyright 2025 NWChemEx-Project
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
.. http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.

.. _scf_background:

##############
SCF Background
##############

Literally the book Modern Quantum Chemistry by Szabo and Ostlund

.. image:: ../assets/scf_architecture.png
86 changes: 86 additions & 0 deletions docs/source/background/scf_notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!--
~ Copyright 2025 NWChemEx-Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

# SCF Procedure

## SCF Driver

1. Obtain the AO parameters as well as the chemical system (inputs)
2. Assign the AO parameters as atomic orbitals
Copy link
Member

Choose a reason for hiding this comment

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

I assume this is referring to a line where we go from an AOBasisSet to an AOSpace. There's no physical meaning behind that. That's just a type conversion.

Copy link
Member

Choose a reason for hiding this comment

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

IMHO, step 2 should read something like:

Mathematically, the inputs to the SCF procedure are a trial wavefunction and a Hamiltonian. Here, the input `ChemicalSystem` is converted to a Hamiltonian by calling a module of property type `WhateverPT`. By default, this is done subject to the Born-Openheimer approximation (i.e., the resulting Hamiltonian will contain the pair-wise interactions of all the particles, but only the kinetic energy of the electrons). 

In my mind, you wouldn't go into further details of the "Hamiltonian" module here (that would be reserved for the module documentation of "Hamiltonian" and linked to here).

3. Create the Hamitonian from the Chemical System (Submod "Hamiltonian" used, currently only the BO Approximation from NUX)
1. For the BO Approximation Hamiltonian:
1. From the Chemical System, the Electrons and Nuclei are used to form the Hamiltonian
2. Each electron gets a 1 electron kinetic energy term
3. Each nuclei gets an Electron-Nuclei potential energy term
Copy link
Member

Choose a reason for hiding this comment

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

Each electron-nuclei pair gets a term. Nuclei don't get a term unless there are electrons present (or if the code tries to give the nuclei a term when no electrons are present it shouldn't).

4. If more than 1 electron, an Electron-Electron potential energy repulson term is added
5. If more than 1 nuclei, a Nuclei-Nuclei potential energy repulsion term is added
6. In order, the Electron kinetic energy, Electron-nucleus attraction energy, and Electron-electron repulsion energy are
Copy link
Member

Choose a reason for hiding this comment

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

Order is immaterial.

formed to create the Electronic Hamiltonian
7. The Nuclear-nuclear repulsion energy is also created
Copy link
Member

Choose a reason for hiding this comment

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

How does this differ from 5?

8. The BO Approximation returns the constructed Hamiltonian, H.
4. With the guess submod, (of type InitialGuess), the inputs are the Hamiltonian and the AOs, and the return value is the
initial wavefunction
Comment on lines +34 to +35
Copy link
Member

Choose a reason for hiding this comment

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

Here I'm thinking something more like:

Given the Hamiltonian for the system and the AO basis set, we are able to compute a trial wavefunction for the SCF procedure. This is done by calling a module of type `InitialGuess`. This is where options such as core guess, superposition of atomic densities, etc. are used with the SCF.

We don't want the core guess to be the long-term default, so I'd avoid saying it's the default. Again, the details of what happens in the module should be described in the documentation for the module.

1. The main module used is the "Core guess" module, which first builds the fock operator with 0 density
2. I am not sure on what happens during lines 78-92:
```cpp
simde::type::cmos cmos(tensor{}, aos, tensor{});
NElectronCounter visitor;
H.visit(visitor);
auto n_electrons = visitor.n_electrons;
if(n_electrons % 2 != 0)
throw std::runtime_error("Assumed even number of electrons");
Comment on lines +40 to +44
Copy link
Member

Choose a reason for hiding this comment

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

This is counting the number of electrons by looping over terms in the Hamiltonian. It's an implementation detail of the module and doesn't need to be here.


typename rscf_wf::orbital_index_set_type occs;
using value_type = typename rscf_wf::orbital_index_set_type::value_type;
for(value_type i = 0; i < n_electrons / 2; ++i) occs.insert(i);
Comment on lines +46 to +48
Copy link
Member

Choose a reason for hiding this comment

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

This establishes the occupations of the orbitals based on the orbital energies and the number of electrons.


rscf_wf zero_guess(occs, cmos);
auto& update_mod = submods.at("Guess updater");
const auto& Psi0 = update_mod.run_as<update_pt>(f, zero_guess);```
Comment on lines +50 to +52
Copy link
Member

Choose a reason for hiding this comment

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

This builds the initial guess from the zero density and the corresponding Fock operator.


3. From there, Psi0 is returned

### SCF Loop

5. The work horse of the module, the submod "Optimizer", uses `scf_loop.cpp` and the module `Loop` to optimize
Copy link
Member

Choose a reason for hiding this comment

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

I like how you separated the loop from the driver. I'd finish out the driver section first though, by adding a step that says something like "the SCF energy is then optimized with respect to the wavefunction by calling a module of property type Optimize<Types,Go,Here>.

the wavefunction. It takes in a Bracket via <Psi0 | H | Psi0> = H00, and Psi0. The property type it satisfies is
```cpp
using pt = simde::Optimize<egy_pt<WfType>, WfType>;
using egy_pt = simde::eval_braket<WfType, hamiltonian, WfType>;
using wf_type = simde::type::rscf_wf;
satisfies_property_type<pt<wf_type>>;
```
and the return result type is the `WfType`, or in this case the `simde::type::rscf_wf`.
Comment on lines +60 to +66
Copy link
Member

Choose a reason for hiding this comment

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

Make sure you understand what these lines do and what the interface means.


1. Step one is to get the nuclear-nuclear repulsion via lines 125-141
1. This is a little messy, so I'll skip the explanation.
2. Compute the overlap matrix, S
1. This runs the S_mod, which is the "Overlap" module provided by the "Integrals" plugin, creating the overlap matrix.
3. Build the density matrix
4. Start the scf process
Copy link
Member

Choose a reason for hiding this comment

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

Arguably, the SCF process has already started. I'd suggest "Iteratively refine the wavefunction".

1. The fock matrix is build, starting with the one-electron fock builder, then the Fock builder, which who knows what is going on there.
2. The new wavefunction is build from the new fock matrix and the old wavefunction
3. the new density is built from the new wavefunction
4. The new electronic hamiltonian is built from the H_core and the new Fock matrix
5. the H_00 BraKet is built, and then used to calculate the new electronic energy
6. We then check for convergence:
1. We calculate delta_e for the change in energy, the delta_p for the change in density, and then the
gradient norm (FPS - SPF).
2. check to see if they have hit convergence
7. energy total is then calculated by adding the electronic energy to the nuclear energy calculated earlier.
Comment on lines +74 to +83
Copy link
Member

Choose a reason for hiding this comment

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

I'd add details about what property types are used to do these steps and what the default algorithms are currently. Would be good to add a comment to the source code where we set the defaults to say "if you change the defaults please update /path/to/this/documentation/file accordingly"


### Return results
6. From here, the energy that is of type Tensor and the optimized wavefunction is returned.
112 changes: 112 additions & 0 deletions docs/source/background/scf_notes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
.. Copyright 2025 NWChemEx-Project
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
.. http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.

SCF Procedure
=============

SCF Driver
----------

1. Obtain the AO parameters as well as the chemical system (inputs)
2. Assign the AO parameters as atomic orbitals
3. Create the Hamitonian from the Chemical System (Submod “Hamiltonian”
used, currently only the BO Approximation from NUX)

1. For the BO Approximation Hamiltonian:

1. From the Chemical System, the Electrons and Nuclei are used to
form the Hamiltonian
2. Each electron gets a 1 electron kinetic energy term
3. Each nuclei gets an Electron-Nuclei potential energy term
4. If more than 1 electron, an Electron-Electron potential energy
repulson term is added
5. If more than 1 nuclei, a Nuclei-Nuclei potential energy
repulsion term is added
6. In order, the Electron kinetic energy, Electron-nucleus
attraction energy, and Electron-electron repulsion energy are
formed to create the Electronic Hamiltonian
7. The Nuclear-nuclear repulsion energy is also created
8. The BO Approximation returns the constructed Hamiltonian, H.

4. With the guess submod, (of type InitialGuess), the inputs are the
Hamiltonian and the AOs, and the return value is the initial
wavefunction

1. The main module used is the “Core guess” module, which first
builds the fock operator with 0 density

2. I am not sure on what happens during lines 78-92: \```cpp
simde::type::cmos cmos(tensor{}, aos, tensor{}); NElectronCounter
visitor; H.visit(visitor); auto n_electrons = visitor.n_electrons;
if(n_electrons % 2 != 0) throw std::runtime_error(“Assumed even
number of electrons”);

typename rscf_wf::orbital_index_set_type occs; using value_type =
typename rscf_wf::orbital_index_set_type::value_type;
for(value_type i = 0; i < n_electrons / 2; ++i) occs.insert(i);

rscf_wf zero_guess(occs, cmos); auto& update_mod =
submods.at(“Guess updater”); const auto& Psi0 =
update_mod.run_as(f, zero_guess);``\`

3. From there, Psi0 is returned

SCF Loop
~~~~~~~~

5. The work horse of the module, the submod “Optimizer”, uses
``scf_loop.cpp`` and the module ``Loop`` to optimize the
wavefunction. It takes in a Bracket via <Psi0 \| H \| Psi0> = H00,
and Psi0. The property type it satisfies is
``cpp using pt = simde::Optimize<egy_pt<WfType>, WfType>; using egy_pt = simde::eval_braket<WfType, hamiltonian, WfType>; using wf_type = simde::type::rscf_wf; satisfies_property_type<pt<wf_type>>;``
and the return result type is the ``WfType``, or in this case the
``simde::type::rscf_wf``.

1. Step one is to get the nuclear-nuclear repulsion via lines 125-141

1. This is a little messy, so I’ll skip the explanation.

2. Compute the overlap matrix, S

1. This runs the S_mod, which is the “Overlap” module provided by
the “Integrals” plugin, creating the overlap matrix.

3. Build the density matrix
4. Start the scf process

1. The fock matrix is build, starting with the one-electron fock
builder, then the Fock builder, which who knows what is going
on there.
2. The new wavefunction is build from the new fock matrix and the
old wavefunction
3. the new density is built from the new wavefunction
4. The new electronic hamiltonian is built from the H_core and the
new Fock matrix
5. the H_00 BraKet is built, and then used to calculate the new
electronic energy
6. We then check for convergence:

1. We calculate delta_e for the change in energy, the delta_p
for the change in density, and then the gradient norm (FPS -
SPF).
2. check to see if they have hit convergence

7. energy total is then calculated by adding the electronic energy
to the nuclear energy calculated earlier.

Return results
~~~~~~~~~~~~~~

6. From here, the energy that is of type Tensor and the optimized
wavefunction is returned.
23 changes: 23 additions & 0 deletions docs/source/bibliography/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. Copyright 2025 NWChemEx-Project
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
.. http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.

##########
References
##########

You know the book

or Helgaker if you're really bought in
Comment on lines +19 to +21
Copy link
Member

Choose a reason for hiding this comment

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

These are supposed to be bibtex references. I'd just leave this blank for now.


.. bibliography::
21 changes: 21 additions & 0 deletions docs/source/developer/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. Copyright 2025 NWChemEx-Project
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
.. http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.

.. _scf_developer:

#######################
Developer Documentation
#######################

If you can do it better I'd like to see you try.
19 changes: 19 additions & 0 deletions docs/source/faqs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. Copyright 2025 NWChemEx-Project
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
.. http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.

.. _scf_faqs:

##############################
SCF Frequently Asked Questions
##############################
19 changes: 19 additions & 0 deletions docs/source/features.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. Copyright 2025 NWChemEx-Project
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
.. http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.

####################
List of SCF Features
####################

So far a pretty neat scf!
17 changes: 14 additions & 3 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@
.. See the License for the specific language governing permissions and
.. limitations under the License.

#########
###
SCF
#########
###

.. toctree::
:maxdepth: 2
:caption: APIs:

module_api/index
background/index.rst
features
install
tutorials/index
developer/index
faqs
bibliography/index.rst

.. toctree::
:maxdepth: 2
:caption: APIs:

C++ API <https://nwchemex.github.io/SCF/scf_cxx_api/index.html>
19 changes: 19 additions & 0 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. Copyright 2025 NWChemEx-Project
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
.. http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.

.. _installing_scf:

##############
Installing SCF
##############
23 changes: 23 additions & 0 deletions docs/source/tutorials/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. Copyright 2025 NWChemEx-Project
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
.. http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.

.. _scf_tutorials:


#############
SCF Tutorials
#############

I have never seen anyone do an scf by hand so we're probably just guessing at
this point.
Loading