Skip to content

Commit

Permalink
Improved printing for RHF SCF normal with DIIS
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinRJDagleish committed Jan 2, 2024
1 parent 19174cf commit 3271daa
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions data/xyz/furan.xyz
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ H -1.88835955 0.99049782 0.07887670
H -1.11155655 3.59005882 0.07876770
H -3.52166555 5.05352182 0.07863270


9 changes: 9 additions & 0 deletions src/calc_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ impl DIIS {
self.err_matr_pr_ring_buf[idx].assign(err_matr);
}

///
/// - Source: Pulay DIIS paper (1980)
/// - Link: https://doi.org/10.1016/0009-2614(80)80396-4
/// - Source: Pulay DIIS improvment paper (1982)
/// - Link: https://doi.org/10.1002/jcc.540030413
/// → using e' = A^+(FPS - SPF)A here
///
/// see also: https://en.wikipedia.org/wiki/DIIS
/// TODO: only recalculate the last row and column of B_matr
fn run_DIIS(&self, error_set_len: usize) -> Array2<f64> {
let mut B_matr = Array2::<f64>::zeros((error_set_len + 1, error_set_len + 1));
let mut sol_vec = Array1::<f64>::zeros(error_set_len + 1);
Expand Down
11 changes: 8 additions & 3 deletions src/calc_type/rhf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use crate::mol_int_and_deriv::{
te_int::calc_ERI_int_cgto,
};
use crate::molecule::Molecule;
use crate::print_utils::{fmt_f64, ExecTimes};
use crate::print_utils::{
fmt_f64,
print_rhf::print_scf_header_and_settings,
ExecTimes,
};
use ndarray::parallel::prelude::*;
use ndarray::{s, Array, Array1, Array2, Zip};
use ndarray_linalg::{Eigh, UPLO};
Expand Down Expand Up @@ -195,6 +199,7 @@ pub(crate) fn rhf_scf_normal(
// TODO:
// - [ ] Print settings
// - [ ] Print initial header
print_scf_header_and_settings(&calc_sett);
const show_all_conv_crit: bool = false;

Check warning on line 203 in src/calc_type/rhf.rs

View workflow job for this annotation

GitHub Actions / Rust project

constant `show_all_conv_crit` should have an upper case name

let mut is_scf_conv = false;
Expand Down Expand Up @@ -238,6 +243,8 @@ pub(crate) fn rhf_scf_normal(
let mut P_matr_old = P_matr.clone();
let mut F_matr = H_core.clone();
let mut F_matr_pr;
let mut diis_str = "";


// Print SCF iteration Header
match show_all_conv_crit {
Expand All @@ -254,8 +261,6 @@ pub(crate) fn rhf_scf_normal(
);
}
}

let mut diis_str = "";
for scf_iter in 0..=calc_sett.max_scf_iter {
if scf_iter == 0 {
F_matr_pr = S_matr_inv_sqrt.dot(&F_matr).dot(&S_matr_inv_sqrt);
Expand Down
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod mol_int_and_deriv;
mod molecule;
mod print_utils;

use crate::{calc_type::CalcType, print_utils::print_initial_header};
use crate::{calc_type::CalcType, print_utils::print_logo};
use basisset::BasisSet;
use calc_type::{DiisSettings, CalcSettings};
use molecule::Molecule;
Expand All @@ -23,10 +23,11 @@ fn main() {
let mut exec_times = print_utils::ExecTimes::new();
exec_times.start("Total");

print_initial_header();
print_logo();

exec_times.start("Molecule");
let mol = Molecule::new("data/xyz/water90.xyz", 0);
let mol = Molecule::new("data/xyz/furan.xyz", 0);
// let mol = Molecule::new("data/xyz/water90.xyz", 0);
// let mol = Molecule::new("data/xyz/calicheamicin_tinker_std.xtbopt.xyz", 0);
// println!("Molecule: {:?}", _mol);
exec_times.stop("Molecule");
Expand Down
3 changes: 3 additions & 0 deletions src/molecule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ impl Molecule {

// skip the comment line
for (at_idx, line) in lines.skip(1).enumerate() {
if line.is_empty() {
break;
}
let mut line_parts = line.split_whitespace(); // split whitespace does "trim" automatically

at_strs.push(line_parts.next().unwrap().to_string());
Expand Down
4 changes: 3 additions & 1 deletion src/print_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{collections::HashMap, time::Instant};

pub fn print_initial_header() {
pub mod print_rhf;

pub fn print_logo() {
// const HEADER_V1: &str = r#"
// ___ ___ _ _____ _ ______ _____
// | \/ | | | | ___| | | ___ \/ ___|
Expand Down
18 changes: 18 additions & 0 deletions src/print_utils/print_rhf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::{calc_type::CalcSettings, print_utils::{print_header_for_section, fmt_f64}};

Check warning on line 1 in src/print_utils/print_rhf.rs

View workflow job for this annotation

GitHub Actions / Rust project

unused imports: `fmt_f64`, `print_header_for_section`

pub(crate) fn print_scf_header_and_settings(calc_sett: &CalcSettings) {
println!("{:=>35}", "");
println!("{:^35}", "RHF SCF");
println!("{:=>35}", "");

println!("{:-20}", "");
println!("SCF settings:");
println!(" {:<20} {:>10e}","ΔE THRESH", calc_sett.e_diff_thrsh);
println!(" {:<20} {:>10e}","RMS FPS THRESH", calc_sett.commu_conv_thrsh);
println!(" {:<20} {:>10}", "Direct SCF", calc_sett.use_direct_scf);
println!(" {:<20} {:>10}","Use DIIS", calc_sett.use_diis);
println!(" {:<20} {:>10}","DIIS Settings", "");
println!(" {:<20} {:>8}","DIIS MIN", calc_sett.diis_sett.diis_min);
println!(" {:<20} {:>8}","DIIS MAX", calc_sett.diis_sett.diis_max);
println!("{:-20}", "");
}

0 comments on commit 3271daa

Please sign in to comment.