From 3271daae172c7ee0e988c70cd1e95d4160b52af1 Mon Sep 17 00:00:00 2001 From: MRJD Date: Tue, 2 Jan 2024 14:57:27 +0100 Subject: [PATCH] Improved printing for RHF SCF normal with DIIS --- data/xyz/furan.xyz | 1 + src/calc_type/mod.rs | 9 +++++++++ src/calc_type/rhf.rs | 11 ++++++++--- src/main.rs | 7 ++++--- src/molecule/mod.rs | 3 +++ src/print_utils/mod.rs | 4 +++- src/print_utils/print_rhf.rs | 18 ++++++++++++++++++ 7 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 src/print_utils/print_rhf.rs diff --git a/data/xyz/furan.xyz b/data/xyz/furan.xyz index 320dba7..7793258 100644 --- a/data/xyz/furan.xyz +++ b/data/xyz/furan.xyz @@ -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 + diff --git a/src/calc_type/mod.rs b/src/calc_type/mod.rs index 5d5748c..135b47e 100644 --- a/src/calc_type/mod.rs +++ b/src/calc_type/mod.rs @@ -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 { let mut B_matr = Array2::::zeros((error_set_len + 1, error_set_len + 1)); let mut sol_vec = Array1::::zeros(error_set_len + 1); diff --git a/src/calc_type/rhf.rs b/src/calc_type/rhf.rs index fa19898..7ccb52a 100644 --- a/src/calc_type/rhf.rs +++ b/src/calc_type/rhf.rs @@ -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}; @@ -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; let mut is_scf_conv = false; @@ -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 { @@ -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); diff --git a/src/main.rs b/src/main.rs index d4c7613..697d248 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; @@ -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"); diff --git a/src/molecule/mod.rs b/src/molecule/mod.rs index 81f2ea2..0dceee4 100644 --- a/src/molecule/mod.rs +++ b/src/molecule/mod.rs @@ -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()); diff --git a/src/print_utils/mod.rs b/src/print_utils/mod.rs index 722da67..a59a12e 100644 --- a/src/print_utils/mod.rs +++ b/src/print_utils/mod.rs @@ -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#" // ___ ___ _ _____ _ ______ _____ // | \/ | | | | ___| | | ___ \/ ___| diff --git a/src/print_utils/print_rhf.rs b/src/print_utils/print_rhf.rs new file mode 100644 index 0000000..7386290 --- /dev/null +++ b/src/print_utils/print_rhf.rs @@ -0,0 +1,18 @@ +use crate::{calc_type::CalcSettings, print_utils::{print_header_for_section, fmt_f64}}; + +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}", ""); +}