From 4b03a45e58045793d30cc39aaaaf2bdb94949c3d Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Tue, 27 Aug 2024 23:32:11 +0200 Subject: [PATCH 01/11] added class for RHF --- tests/test_hf.py | 204 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 tests/test_hf.py diff --git a/tests/test_hf.py b/tests/test_hf.py new file mode 100644 index 0000000..f25183f --- /dev/null +++ b/tests/test_hf.py @@ -0,0 +1,204 @@ + +import os +from pathlib import Path +import subprocess +import platform +from datetime import datetime + +current_date = datetime.now() + +quack_root = os.getenv('QUACK_ROOT') + +# User Name +user_name = os.getlogin() + +# Operating System +os_name = platform.system() +os_release = platform.release() +os_version = platform.version() + +# CPU Information +machine = platform.machine() +processor = platform.processor() + +# System Architecture +architecture = platform.architecture()[0] + +# Python Version +python_version_full = platform.python_version_tuple() +PYTHON_VERSION = "{}.{}".format(python_version_full[0], python_version_full[1]) + + +print(f"The current date and time is {current_date.strftime('%Y-%m-%d %H:%M:%S')}") +print(f"User Name: {user_name}") +print(f"Operating System: {os_name} {os_release} ({os_version})") +print(f"CPU: {processor} ({machine})") +print(f"System Architecture: {architecture}") +print(f"QUACK_ROOT: {quack_root}") +print(f"Python version: {python_version_full}\n\n") + +# --- + +mp2 = "# MP2 MP3\n F F\n" +cc = "# CCD pCCD DCD CCSD CCSD(T)\n F F F F F\n" +rcc = "# drCCD rCCD crCCD lCCD\n F F F F\n" +ci = "# CIS CIS(D) CID CISD FCI\n F F F F F\n" +rpa = "# phRPA phRPAx crRPA ppRPA\n F F F F\n" +gf = "# G0F2 evGF2 qsGF2 ufGF2 G0F3 evGF3\n F F F F F F\n" +gw = "# G0W0 evGW qsGW SRG-qsGW ufG0W0 ufGW\n F F F F F F\n" +gtpp = "# G0T0pp evGTpp qsGTpp ufG0T0pp\n F F F F\n" +gteh = "# G0T0eh evGTeh qsGTeh\n F F F\n" +tests = "# Rtest Utest Gtest\n F F F\n" + +# --- + +hf_opt = "# HF: maxSCF thresh DIIS guess mix shift stab search\n 256 0.00001 5 1 0.0 0.0 F F\n" +mp_opt = "# MP: reg\n F\n" +cc_opt = "# CC: maxSCF thresh DIIS\n 64 0.00001 5\n" +tda_opt = "# spin: TDA singlet triplet\n F T T\n" +gf_opt = "# GF: maxSCF thresh DIIS lin eta renorm reg\n 256 0.00001 5 F 0.0 0 F\n" +gw_opt = "# GW: maxSCF thresh DIIS lin eta TDA_W reg\n 256 0.00001 5 F 0.0 F F\n" +gt_opt = "# GT: maxSCF thresh DIIS lin eta TDA_T reg\n 256 0.00001 5 F 0.0 F F\n" +acfdt_opt = "# ACFDT: AC Kx XBS\n F F T\n" +bse_opt = "# BSE: phBSE phBSE2 ppBSE dBSE dTDA\n F F F F T\n" +list_opt = [hf_opt, mp_opt, cc_opt, tda_opt, gf_opt, gw_opt, gt_opt, acfdt_opt, bse_opt] + +# --- + +mol_multip = { + "Ne": 1, + "H2O": 1, +} + +list_basis = ["cc-pvdz", "cc-pvtz", "cc-pvqz"] + +# --- + +class class_RHF: + + def gen_input(): + + f = open("methods", "w") + f.write("# RHF UHF GHF ROHF\n") + f.write(" T F F F\n") + f.write("{}{}{}{}{}{}{}{}{}{}".format(mp2, cc, rcc, ci, rpa, gf, gw, gtpp, gteh, tests)) + f.close() + + f = open("options", "w") + for opt in list_opt: + f.write("{}".format(opt)) + f.close() + + def run_job(file_out, mol, bas, multip): + + os.chdir('..') + print(f" :$ cd ..") + + for file_in in ["methods", "options"]: + command = ['cp', 'tests/{}'.format(file_in), 'input/{}'.format(file_in)] + print(f" :$ {' '.join(command)}") + result = subprocess.run(command, capture_output=True, text=True) + if result.returncode != 0: + print("Error moving file: {}".format(result.stderr)) + + command = [ + 'python{}'.format(PYTHON_VERSION), 'PyDuck.py', + '-x', '{}'.format(mol), + '-b', '{}'.format(bas), + '-m', '{}'.format(multip) + ] + print(f" :$ {' '.join(command)}") + with open(file_out, 'w') as fobj: + result = subprocess.run(command, stdout=fobj, stderr=subprocess.PIPE, text=True) + if result.stderr: + print("Error output:", result.stderr) + + os.chdir('tests') + print(f" :$ cd tests") + + +# --- + +class class_UHF: + def gen_input(): + f = open("methods", "w") + f.write("# RHF UHF GHF ROHF\n") + f.write(" F T F F\n") + f.write("{}{}{}{}{}{}{}{}{}{}".format(mp2, cc, rcc, ci, rpa, gf, gw, gtpp, gteh, tests)) + f.close() + +# --- + +class class_GHF: + def gen_input(): + f = open("methods", "w") + f.write("# RHF UHF GHF ROHF\n") + f.write(" F F T F\n") + f.write("{}{}{}{}{}{}{}{}{}{}".format(mp2, cc, rcc, ci, rpa, gf, gw, gtpp, gteh, tests)) + f.close() + +# --- + +class class_ROHF: + def gen_input(): + f = open("methods", "w") + f.write("# RHF UHF GHF ROHF\n") + f.write(" F F F T\n") + f.write("{}{}{}{}{}{}{}{}{}{}".format(mp2, cc, rcc, ci, rpa, gf, gw, gtpp, gteh, tests)) + f.close() + +# --- + +class_map = { + "RHF": class_RHF, + "UHF": class_UHF, + "GHF": class_GHF, + "ROHF": class_ROHF, +} + +def main(): + + work_path = Path('{}/tests/work'.format(quack_root)) + if not work_path.exists(): + work_path.mkdir(parents=True, exist_ok=True) + print(f"Directory '{work_path}' created.\n") + + for methd in ["RHF", "UHF", "GHF", "ROHF"]: + + work_methd = Path('{}/{}'.format(work_path, methd)) + if not work_methd.exists(): + work_methd.mkdir(parents=True, exist_ok=True) + print(f"Directory '{work_methd}' created.\n") + + class_methd = class_map.get(methd) + + # create input files + class_methd.gen_input() + + for mol in mol_multip: + + multip = mol_multip[mol] + + for bas in list_basis: + + file_out = "{}/{}/{}_{}_{}.out".format(work_path, methd, mol, multip, bas) + + print(" testing {} for {}@{} (2S+1 = {})".format(methd, mol, bas, multip)) + print(" file_out: {}".format(file_out)) + + class_methd.run_job(file_out, mol, bas, multip) + + print("\n") + print("\n\n") + + print(" --- --- --- ---") + print("\n\n\n") + + +main() + + + + + + From 1a195f90ccc6983415fce92fd9eb0088fd955a20 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Wed, 28 Aug 2024 01:06:31 +0200 Subject: [PATCH 02/11] add SQLite database --- tests/create_database.py | 42 ++++++++++++++++++++ tests/molecule.py | 86 ++++++++++++++++++++++++++++++++++++++++ tests/test_hf.py | 58 +++++++++++++-------------- 3 files changed, 157 insertions(+), 29 deletions(-) create mode 100644 tests/create_database.py create mode 100644 tests/molecule.py diff --git a/tests/create_database.py b/tests/create_database.py new file mode 100644 index 0000000..3a91252 --- /dev/null +++ b/tests/create_database.py @@ -0,0 +1,42 @@ + +import sqlite3 + +from molecule import Molecule +from molecule import save_molecules_to_json, load_molecules_from_json +from molecule import create_database, add_molecule_to_db + + + +molecules = [ + Molecule( + name="H2O", + multiplicity=1, + geometry=[ + {"element": "O", "x": 0.000000, "y": 0.000000, "z": 0.117790}, + {"element": "H", "x": 0.000000, "y": 0.755453, "z": -0.471161}, + {"element": "H", "x": 0.000000, "y": -0.755453, "z": -0.471161} + ], + energies={ + "RHF": { + "cc-pvdz": -76.0267058009, + "cc-pvtz": -76.0570239304, + "cc-pvqz": -76.0646816616 + }, + } + ), +] + + +# Save molecules to JSON +save_molecules_to_json(molecules, 'molecules.json') + +# Load molecules from JSON +loaded_molecules = load_molecules_from_json('molecules.json') +print(loaded_molecules) + +# Create a database and add molecules +db_name = 'molecules.db' +create_database(db_name) +for molecule in molecules: + add_molecule_to_db(db_name, molecule) + diff --git a/tests/molecule.py b/tests/molecule.py new file mode 100644 index 0000000..9d7b648 --- /dev/null +++ b/tests/molecule.py @@ -0,0 +1,86 @@ + +import json +import sqlite3 + +class Molecule: + def __init__(self, name, multiplicity, geometry, energies): + self.name = name + self.multiplicity = multiplicity + self.geometry = geometry # List of tuples (atom, x, y, z) + self.energies = energies # Dictionary of dictionaries: {method: {basis: energy}} + + def get_energy(self, method, basis): + """Retrieve energy for a specific method and basis set.""" + return self.energies.get(method, {}).get(basis, None) + + def to_dict(self): + return { + "name": self.name, + "multiplicity": self.multiplicity, + "geometry": self.geometry, + "energies": self.energies, + } + + @staticmethod + def from_dict(data): + return Molecule( + name=data["name"], + multiplicity=data["multiplicity"], + geometry=data["geometry"], + energies=data["energies"] + ) + +def save_molecules_to_json(molecules, filename): + with open(filename, 'w') as f: + json_data = [molecule.to_dict() for molecule in molecules] + json.dump(json_data, f, indent=4) + +def load_molecules_from_json(filename): + with open(filename, 'r') as f: + json_data = json.load(f) + return [Molecule.from_dict(data) for data in json_data] + + +def create_database(db_name): + conn = sqlite3.connect(db_name) + cursor = conn.cursor() + cursor.execute('''CREATE TABLE IF NOT EXISTS molecules + (name TEXT, multiplicity INTEGER, geometry TEXT, energies TEXT)''') + conn.commit() + conn.close() + +def add_molecule_to_db(db_name, molecule): + conn = sqlite3.connect(db_name) + cursor = conn.cursor() + geometry_str = json.dumps(molecule.geometry) + energies_str = json.dumps(molecule.energies) + cursor.execute("INSERT INTO molecules VALUES (?, ?, ?, ?)", + (molecule.name, molecule.multiplicity, geometry_str, energies_str)) + conn.commit() + conn.close() + +def get_molecules_from_db(db_name): + conn = sqlite3.connect(db_name) + cursor = conn.cursor() + cursor.execute("SELECT name, multiplicity, geometry, energies FROM molecules") + rows = cursor.fetchall() + molecules = [] + for row in rows: + name, multiplicity, geometry_str, energies_str = row + geometry = json.loads(geometry_str) + energies = json.loads(energies_str) # energies is a dictionary of dictionaries + molecules.append(Molecule(name, multiplicity, geometry, energies)) + conn.close() + return molecules + +def write_geometry_to_xyz(molecule, filename): + with open(filename, 'w') as f: + # First line: number of atoms + f.write(f"{len(molecule.geometry)}\n") + # Second line: empty comment line + f.write("\n") + # Remaining lines: atom positions + for atom, x, y, z in molecule.geometry: + f.write(f"{atom} {x:.6f} {y:.6f} {z:.6f}\n") + + diff --git a/tests/test_hf.py b/tests/test_hf.py index f25183f..fd04121 100644 --- a/tests/test_hf.py +++ b/tests/test_hf.py @@ -5,6 +5,9 @@ import subprocess import platform from datetime import datetime +from molecule import get_molecules_from_db + + current_date = datetime.now() quack_root = os.getenv('QUACK_ROOT') @@ -65,15 +68,6 @@ list_opt = [hf_opt, mp_opt, cc_opt, tda_opt, gf_opt, gw_opt, gt_opt, acfdt_opt, # --- -mol_multip = { - "Ne": 1, - "H2O": 1, -} - -list_basis = ["cc-pvdz", "cc-pvtz", "cc-pvqz"] - -# --- - class class_RHF: def gen_input(): @@ -163,30 +157,36 @@ def main(): work_path.mkdir(parents=True, exist_ok=True) print(f"Directory '{work_path}' created.\n") - for methd in ["RHF", "UHF", "GHF", "ROHF"]: + for mol in molecules: - work_methd = Path('{}/{}'.format(work_path, methd)) - if not work_methd.exists(): - work_methd.mkdir(parents=True, exist_ok=True) - print(f"Directory '{work_methd}' created.\n") + mol_name = mol.name + mol_mult = mol.multiplicity - class_methd = class_map.get(methd) - # create input files - class_methd.gen_input() + for methd in list_methd: - for mol in mol_multip: + if methd not in mol.energies: + print(f"Method {methd} does not exist for {mol_name}.") + continue - multip = mol_multip[mol] + for bas, _ in mol.energies[methd].items(): - for bas in list_basis: + work_methd = Path('{}/{}'.format(work_path, methd)) + if not work_methd.exists(): + work_methd.mkdir(parents=True, exist_ok=True) + print(f"Directory '{work_methd}' created.\n") + + class_methd = class_map.get(methd) + + # create input files + class_methd.gen_input() + + file_out = "{}/{}/{}_{}_{}.out".format(work_path, methd, mol_name, mol_mult, bas) - file_out = "{}/{}/{}_{}_{}.out".format(work_path, methd, mol, multip, bas) - - print(" testing {} for {}@{} (2S+1 = {})".format(methd, mol, bas, multip)) + print(" testing {} for {}@{} (2S+1 = {})".format(methd, mol_name, bas, mol_mult)) print(" file_out: {}".format(file_out)) - class_methd.run_job(file_out, mol, bas, multip) + class_methd.run_job(file_out, mol_name, bas, mol_mult) print("\n") print("\n\n") @@ -195,10 +195,10 @@ def main(): print("\n\n\n") +db_name = 'molecules.db' +molecules = get_molecules_from_db(db_name) + +list_methd = ["RHF", "UHF", "GHF", "ROHF"] + main() - - - - - From 0262e733536b20bafa1e8c4127ca003ff8b29c7e Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Thu, 29 Aug 2024 09:45:30 +0200 Subject: [PATCH 03/11] saving (found BUG in RGWC) --- tests/bulk_set.py | 0 tests/create_database.py | 31 ++++------------ tests/equi_set.py | 0 tests/methods.test | 22 ++++++++++++ tests/swift_set.py | 76 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 24 deletions(-) create mode 100644 tests/bulk_set.py create mode 100644 tests/equi_set.py create mode 100644 tests/methods.test create mode 100644 tests/swift_set.py diff --git a/tests/bulk_set.py b/tests/bulk_set.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/create_database.py b/tests/create_database.py index 3a91252..224b9b3 100644 --- a/tests/create_database.py +++ b/tests/create_database.py @@ -1,42 +1,25 @@ import sqlite3 -from molecule import Molecule from molecule import save_molecules_to_json, load_molecules_from_json from molecule import create_database, add_molecule_to_db +from swift_set import swiftset -molecules = [ - Molecule( - name="H2O", - multiplicity=1, - geometry=[ - {"element": "O", "x": 0.000000, "y": 0.000000, "z": 0.117790}, - {"element": "H", "x": 0.000000, "y": 0.755453, "z": -0.471161}, - {"element": "H", "x": 0.000000, "y": -0.755453, "z": -0.471161} - ], - energies={ - "RHF": { - "cc-pvdz": -76.0267058009, - "cc-pvtz": -76.0570239304, - "cc-pvqz": -76.0646816616 - }, - } - ), -] - # Save molecules to JSON -save_molecules_to_json(molecules, 'molecules.json') +save_molecules_to_json(swiftset, 'swiftset.json') # Load molecules from JSON -loaded_molecules = load_molecules_from_json('molecules.json') +loaded_molecules = load_molecules_from_json('swiftset.json') print(loaded_molecules) # Create a database and add molecules -db_name = 'molecules.db' +db_name = 'swiftset.db' create_database(db_name) -for molecule in molecules: +for molecule in swiftset: add_molecule_to_db(db_name, molecule) + + diff --git a/tests/equi_set.py b/tests/equi_set.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/methods.test b/tests/methods.test new file mode 100644 index 0000000..e315154 --- /dev/null +++ b/tests/methods.test @@ -0,0 +1,22 @@ +# RHF UHF GHF ROHF + T F F F +# MP2 MP3 + T T +# CCD pCCD DCD CCSD CCSD(T) + T T T T F +# drCCD rCCD crCCD lCCD + T T T T +# CIS CIS(D) CID CISD FCI + T F F F F +# phRPA phRPAx crRPA ppRPA + T T T T +# G0F2 evGF2 qsGF2 ufGF2 G0F3 evGF3 + T T F F F F +# G0W0 evGW qsGW SRG-qsGW ufG0W0 ufGW + T T F F F F +# G0T0pp evGTpp qsGTpp ufG0T0pp + T T F F +# G0T0eh evGTeh qsGTeh + F F F +# Rtest Utest Gtest + T F F diff --git a/tests/swift_set.py b/tests/swift_set.py new file mode 100644 index 0000000..5c846ce --- /dev/null +++ b/tests/swift_set.py @@ -0,0 +1,76 @@ + +from molecule import Molecule + + +He = Molecule( + name="He", + multiplicity=1, + geometry=[ + {"element": "He", "x": 0.0, "y": 0.0, "z": 0.0} + ], + properties={ + "6-31g": { + "RHF energy": -2.855160426884076, + "RHF HOMO energy": -0.914126628614305, + "RHF LUMO energy": 1.399859335225087, + "RHF dipole moment": 0.000000000000000, + "RMP2 correlation energy": -0.011200122910187, + "CCD correlation energy": -0.014985063408247, + "DCD correlation energy": -0.014985062907429, + "CCSD correlation energy": -0.015001711549550, + "drCCD correlation energy": -0.018845374502248, + "rCCD correlation energy": -0.016836324636164, + "crCCD correlation energy": 0.008524677369855, + "lCCD correlation energy": -0.008082420815100, + "pCCD correlation energy": -0.014985062519068, + "RCIS singlet excitation energy": 1.911193619935257, + "RCIS triplet excitation energy": 1.455852629402236, + "phRRPA correlation energy": -0.018845374129105, + "phRRPAx correlation energy": -0.015760565121283, + "crRRPA correlation energy": -0.008868581132405, + "ppRRPA correlation energy": -0.008082420815100, + "RG0F2 correlation energy": -0.011438430540374, + "RG0F2 HOMO energy": -0.882696116247871, + "RG0F2 LUMO energy": 1.383080391811630, + "evRGF2 correlation energy": -0.011448483158486, + "evRGF2 HOMO energy": -0.881327878713477, + "evRGF2 LUMO energy": 1.382458968133448, + "RG0W0 correlation energy": -0.019314094399756, + "RG0W0 HOMO energy": -0.870533880190454, + "RG0W0 LUMO energy": 1.377171287010956, + "evRGW correlation energy": -0.019335511771724, + "evRGW HOMO energy": -0.868460640957913, + "evRGW LUMO energy": 1.376287581471769, + "RG0T0pp correlation energy": -0.008082420815100, + "RG0T0pp HOMO energy": -0.914126628614305, + "RG0T0pp LUMO energy": 1.399859335225087, + "evRGTpp correlation energy": -0.008082420815100, + "evRGTpp HOMO energy": -0.914126628614305, + "evRGTpp LUMO energy": 1.399859335225087 + } + } +) + +# --- + +H2O = Molecule( + name="H2O", + multiplicity=1, + geometry=[ + {"element": "O", "x": 0.0000, "y": 0.0000, "z": 0.0000}, + {"element": "H", "x": 0.7571, "y": 0.0000, "z": 0.5861}, + {"element": "H", "x": -0.7571, "y": 0.0000, "z": 0.5861} + ], + properties={ + "cc-pvdz": { + } +) + +# --- + +SwiftSet = [He, H2O] + + + + + From 0b28512edcf8eb7d71abf88d335c2b7b64ffe91a Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Thu, 29 Aug 2024 14:05:21 +0200 Subject: [PATCH 04/11] fixed small bugs --- src/GT/GTpp_excitation_density.f90 | 470 +++++++++++++++-------------- src/GW/evRGW.f90 | 4 +- 2 files changed, 239 insertions(+), 235 deletions(-) diff --git a/src/GT/GTpp_excitation_density.f90 b/src/GT/GTpp_excitation_density.f90 index 05f9c2d..6bfe164 100644 --- a/src/GT/GTpp_excitation_density.f90 +++ b/src/GT/GTpp_excitation_density.f90 @@ -135,131 +135,132 @@ subroutine GTpp_excitation_density(ispin,nBas,nC,nO,nV,nR,nOO,nVV,ERI,X1,Y1,rho1 dim_1 = (nBas - nO) * (nBas - nO - 1) / 2 dim_2 = nO * (nO - 1) / 2 - allocate(ERI_1(nBas,nBas,dim_1), ERI_2(nBas,nBas,dim_2)) - ERI_1 = 0.d0 - ERI_2 = 0.d0 + if((dim_1 .eq. 0) .or. (dim_2 .eq. 0)) then - !$OMP PARALLEL DEFAULT(NONE) & - !$OMP PRIVATE(p, q, c, d, cd, k, l, kl) & - !$OMP SHARED(nC, nBas, nR, nO, ERI_1, ERI_2, ERI) - !$OMP DO COLLAPSE(2) - do q = nC+1, nBas-nR - do p = nC+1, nBas-nR - cd = 0 - do c = nO+1, nBas-nR - do d = c+1, nBas-nR - cd = cd + 1 - ERI_1(p,q,cd) = ERI(p,q,c,d) - ERI(p,q,d,c) - enddo - enddo - kl = 0 - do k = nC+1, nO - do l = k+1, nO - kl = kl + 1 - ERI_2(p,q,kl) = ERI(p,q,k,l) - ERI(p,q,l,k) - end do - end do - enddo - enddo + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP PRIVATE(p, q, a, b, ab, c, d, cd, i, j, ij, k, l, kl) & + !$OMP SHARED(nC, nBas, nR, nO, rho1, rho2, ERI, X1, Y1, X2, Y2) + !$OMP DO COLLAPSE(2) + do q = nC+1, nBas-nR + do p = nC+1, nBas-nR + + ab = 0 + + do a = nO+1, nBas-nR + do b = a+1, nBas-nR + + ab = ab + 1 + + cd = 0 + do c = nO+1, nBas-nR + do d = c+1, nBas-nR + + cd = cd + 1 + + rho1(p,q,ab) = rho1(p,q,ab) & + + (ERI(p,q,c,d) - ERI(p,q,d,c))*X1(cd,ab) + end do ! d + end do ! c + + kl = 0 + do k = nC+1, nO + do l = k+1, nO + + kl = kl + 1 + + rho1(p,q,ab) = rho1(p,q,ab) & + + (ERI(p,q,k,l) - ERI(p,q,l,k))*Y1(kl,ab) + end do ! l + end do ! k + end do ! b + end do ! a + + ij = 0 + do i = nC+1, nO + do j = i+1, nO + + ij = ij + 1 + + cd = 0 + + do c = nO+1, nBas-nR + do d = c+1, nBas-nR + + cd = cd + 1 + + rho2(p,q,ij) = rho2(p,q,ij) & + + (ERI(p,q,c,d) - ERI(p,q,d,c))*X2(cd,ij) + end do ! d + end do ! c + + kl = 0 + do k = nC+1, nO + do l = k+1, nO + + kl = kl + 1 + + rho2(p,q,ij) = rho2(p,q,ij) & + + (ERI(p,q,k,l) - ERI(p,q,l,k))*Y2(kl,ij) + end do ! l + end do ! k + end do ! j + end do ! i + end do ! p + end do ! q !$OMP END DO !$OMP END PARALLEL - call dgemm("N", "N", nBas*nBas, dim_1, dim_1, 1.d0, & - ERI_1(1,1,1), nBas*nBas, X1(1,1), dim_1, & - 0.d0, rho1(1,1,1), nBas*nBas) + else - call dgemm("N", "N", nBas*nBas, dim_1, dim_2, 1.d0, & - ERI_2(1,1,1), nBas*nBas, Y1(1,1), dim_2, & - 1.d0, rho1(1,1,1), nBas*nBas) + allocate(ERI_1(nBas,nBas,dim_1), ERI_2(nBas,nBas,dim_2)) + ERI_1 = 0.d0 + ERI_2 = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP PRIVATE(p, q, c, d, cd, k, l, kl) & + !$OMP SHARED(nC, nBas, nR, nO, ERI_1, ERI_2, ERI) + !$OMP DO COLLAPSE(2) + do q = nC+1, nBas-nR + do p = nC+1, nBas-nR + cd = 0 + do c = nO+1, nBas-nR + do d = c+1, nBas-nR + cd = cd + 1 + ERI_1(p,q,cd) = ERI(p,q,c,d) - ERI(p,q,d,c) + enddo + enddo + kl = 0 + do k = nC+1, nO + do l = k+1, nO + kl = kl + 1 + ERI_2(p,q,kl) = ERI(p,q,k,l) - ERI(p,q,l,k) + end do + end do + enddo + enddo + !$OMP END DO + !$OMP END PARALLEL + + call dgemm("N", "N", nBas*nBas, dim_1, dim_1, 1.d0, & + ERI_1(1,1,1), nBas*nBas, X1(1,1), dim_1, & + 0.d0, rho1(1,1,1), nBas*nBas) + + call dgemm("N", "N", nBas*nBas, dim_1, dim_2, 1.d0, & + ERI_2(1,1,1), nBas*nBas, Y1(1,1), dim_2, & + 1.d0, rho1(1,1,1), nBas*nBas) + + call dgemm("N", "N", nBas*nBas, dim_2, dim_1, 1.d0, & + ERI_1(1,1,1), nBas*nBas, X2(1,1), dim_1, & + 0.d0, rho2(1,1,1), nBas*nBas) + + call dgemm("N", "N", nBas*nBas, dim_2, dim_2, 1.d0, & + ERI_2(1,1,1), nBas*nBas, Y2(1,1), dim_2, & + 1.d0, rho2(1,1,1), nBas*nBas) + + deallocate(ERI_1, ERI_2) - call dgemm("N", "N", nBas*nBas, dim_2, dim_1, 1.d0, & - ERI_1(1,1,1), nBas*nBas, X2(1,1), dim_1, & - 0.d0, rho2(1,1,1), nBas*nBas) - - call dgemm("N", "N", nBas*nBas, dim_2, dim_2, 1.d0, & - ERI_2(1,1,1), nBas*nBas, Y2(1,1), dim_2, & - 1.d0, rho2(1,1,1), nBas*nBas) - - deallocate(ERI_1, ERI_2) - - -! !$OMP PARALLEL DEFAULT(NONE) & -! !$OMP PRIVATE(p, q, a, b, ab, c, d, cd, i, j, ij, k, l, kl) & -! !$OMP SHARED(nC, nBas, nR, nO, rho1, rho2, ERI, X1, Y1, X2, Y2) -! !$OMP DO COLLAPSE(2) -! do q = nC+1, nBas-nR -! do p = nC+1, nBas-nR -! -! ab = 0 -! -! do a = nO+1, nBas-nR -! do b = a+1, nBas-nR -! -! ab = ab + 1 -! -! cd = 0 -! do c = nO+1, nBas-nR -! do d = c+1, nBas-nR -! -! cd = cd + 1 -! -! rho1(p,q,ab) = rho1(p,q,ab) & -! + (ERI(p,q,c,d) - ERI(p,q,d,c))*X1(cd,ab) -! end do ! d -! end do ! c -! -! kl = 0 -! do k = nC+1, nO -! do l = k+1, nO -! -! kl = kl + 1 -! -! rho1(p,q,ab) = rho1(p,q,ab) & -! + (ERI(p,q,k,l) - ERI(p,q,l,k))*Y1(kl,ab) -! end do ! l -! end do ! k -! -! end do ! b -! end do ! a -! -! ij = 0 -! do i = nC+1, nO -! do j = i+1, nO -! -! ij = ij + 1 -! -! cd = 0 -! -! do c = nO+1, nBas-nR -! do d = c+1, nBas-nR -! -! cd = cd + 1 -! -! rho2(p,q,ij) = rho2(p,q,ij) & -! + (ERI(p,q,c,d) - ERI(p,q,d,c))*X2(cd,ij) -! end do ! d -! end do ! c -! -! kl = 0 -! do k = nC+1, nO -! do l = k+1, nO -! -! kl = kl + 1 -! -! rho2(p,q,ij) = rho2(p,q,ij) & -! + (ERI(p,q,k,l) - ERI(p,q,l,k))*Y2(kl,ij) -! end do ! l -! end do ! k -! -! end do ! j -! end do ! i -! -! end do ! p -! end do ! q -! !$OMP END DO -! !$OMP END PARALLEL - - end if + endif + endif !---------------------------------------------- ! alpha-beta block @@ -270,125 +271,126 @@ subroutine GTpp_excitation_density(ispin,nBas,nC,nO,nV,nR,nOO,nVV,ERI,X1,Y1,rho1 dim_1 = (nBas - nO) * (nBas - nO) dim_2 = nO * nO - allocate(ERI_1(nBas,nBas,dim_1), ERI_2(nBas,nBas,dim_2)) - ERI_1 = 0.d0 - ERI_2 = 0.d0 + if((dim_1 .eq. 0) .or. (dim_2 .eq. 0)) then - !$OMP PARALLEL DEFAULT(NONE) & - !$OMP PRIVATE(p, q, c, d, cd, k, l, kl) & - !$OMP SHARED(nC, nBas, nR, nO, ERI_1, ERI_2, ERI) - !$OMP DO COLLAPSE(2) - do q = nC+1, nBas-nR - do p = nC+1, nBas-nR - cd = 0 - do c = nO+1, nBas-nR - do d = nO+1, nBas-nR - cd = cd + 1 - ERI_1(p,q,cd) = ERI(p,q,c,d) - enddo - enddo - kl = 0 - do k = nC+1, nO - do l = nC+1, nO - kl = kl + 1 - ERI_2(p,q,kl) = ERI(p,q,k,l) + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP PRIVATE(p, q, a, b, ab, c, d, cd, i, j, ij, k, l, kl) & + !$OMP SHARED(nC, nBas, nR, nO, rho1, rho2, ERI, X1, Y1, X2, Y2) + !$OMP DO COLLAPSE(2) + + do q = nC+1, nBas-nR + do p = nC+1, nBas-nR + + ab = 0 + do a = nO+1, nBas-nR + do b = nO+1, nBas-nR + + ab = ab + 1 + + cd = 0 + do c = nO+1, nBas-nR + do d = nO+1, nBas-nR + + cd = cd + 1 + + rho1(p,q,ab) = rho1(p,q,ab) + ERI(p,q,c,d)*X1(cd,ab) + end do + end do + + kl = 0 + do k = nC+1, nO + do l = nC+1, nO + + kl = kl + 1 + + rho1(p,q,ab) = rho1(p,q,ab) + ERI(p,q,k,l)*Y1(kl,ab) + end do + end do + end do + end do + + ij = 0 + do i = nC+1, nO + do j = nC+1, nO + + ij = ij + 1 + + cd = 0 + do c = nO+1, nBas-nR + do d = nO+1, nBas-nR + + cd = cd + 1 + + rho2(p,q,ij) = rho2(p,q,ij) + ERI(p,q,c,d)*X2(cd,ij) + end do + end do + + kl = 0 + do k = nC+1, nO + do l = nC+1, nO + + kl = kl + 1 + + rho2(p,q,ij) = rho2(p,q,ij) + ERI(p,q,k,l)*Y2(kl,ij) + end do + end do + end do end do end do + end do + !$OMP END DO + !$OMP END PARALLEL + + else + + allocate(ERI_1(nBas,nBas,dim_1), ERI_2(nBas,nBas,dim_2)) + ERI_1 = 0.d0 + ERI_2 = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP PRIVATE(p, q, c, d, cd, k, l, kl) & + !$OMP SHARED(nC, nBas, nR, nO, ERI_1, ERI_2, ERI) + !$OMP DO COLLAPSE(2) + do q = nC+1, nBas-nR + do p = nC+1, nBas-nR + cd = 0 + do c = nO+1, nBas-nR + do d = nO+1, nBas-nR + cd = cd + 1 + ERI_1(p,q,cd) = ERI(p,q,c,d) + enddo + enddo + kl = 0 + do k = nC+1, nO + do l = nC+1, nO + kl = kl + 1 + ERI_2(p,q,kl) = ERI(p,q,k,l) + end do + end do + enddo enddo - enddo - !$OMP END DO - !$OMP END PARALLEL + !$OMP END DO + !$OMP END PARALLEL + + call dgemm("N", "N", nBas*nBas, dim_1, dim_1, 1.d0, & + ERI_1(1,1,1), nBas*nBas, X1(1,1), dim_1, & + 0.d0, rho1(1,1,1), nBas*nBas) + + call dgemm("N", "N", nBas*nBas, dim_1, dim_2, 1.d0, & + ERI_2(1,1,1), nBas*nBas, Y1(1,1), dim_2, & + 1.d0, rho1(1,1,1), nBas*nBas) + + call dgemm("N", "N", nBas*nBas, dim_2, dim_1, 1.d0, & + ERI_1(1,1,1), nBas*nBas, X2(1,1), dim_1, & + 0.d0, rho2(1,1,1), nBas*nBas) + + call dgemm("N", "N", nBas*nBas, dim_2, dim_2, 1.d0, & + ERI_2(1,1,1), nBas*nBas, Y2(1,1), dim_2, & + 1.d0, rho2(1,1,1), nBas*nBas) + + deallocate(ERI_1, ERI_2) - call dgemm("N", "N", nBas*nBas, dim_1, dim_1, 1.d0, & - ERI_1(1,1,1), nBas*nBas, X1(1,1), dim_1, & - 0.d0, rho1(1,1,1), nBas*nBas) - - call dgemm("N", "N", nBas*nBas, dim_1, dim_2, 1.d0, & - ERI_2(1,1,1), nBas*nBas, Y1(1,1), dim_2, & - 1.d0, rho1(1,1,1), nBas*nBas) - - call dgemm("N", "N", nBas*nBas, dim_2, dim_1, 1.d0, & - ERI_1(1,1,1), nBas*nBas, X2(1,1), dim_1, & - 0.d0, rho2(1,1,1), nBas*nBas) - - call dgemm("N", "N", nBas*nBas, dim_2, dim_2, 1.d0, & - ERI_2(1,1,1), nBas*nBas, Y2(1,1), dim_2, & - 1.d0, rho2(1,1,1), nBas*nBas) - - deallocate(ERI_1, ERI_2) - - -! !$OMP PARALLEL DEFAULT(NONE) & -! !$OMP PRIVATE(p, q, a, b, ab, c, d, cd, i, j, ij, k, l, kl) & -! !$OMP SHARED(nC, nBas, nR, nO, rho1, rho2, ERI, X1, Y1, X2, Y2) -! !$OMP DO COLLAPSE(2) -! -! do q = nC+1, nBas-nR -! do p = nC+1, nBas-nR -! -! ab = 0 -! do a = nO+1, nBas-nR -! do b = nO+1, nBas-nR -! -! ab = ab + 1 -! -! cd = 0 -! do c = nO+1, nBas-nR -! do d = nO+1, nBas-nR -! -! cd = cd + 1 -! -! rho1(p,q,ab) = rho1(p,q,ab) + ERI(p,q,c,d)*X1(cd,ab) -! end do -! end do -! -! kl = 0 -! do k = nC+1, nO -! do l = nC+1, nO -! -! kl = kl + 1 -! -! rho1(p,q,ab) = rho1(p,q,ab) + ERI(p,q,k,l)*Y1(kl,ab) -! end do -! end do -! -! end do -! end do -! -! ij = 0 -! do i = nC+1, nO -! do j = nC+1, nO -! -! ij = ij + 1 -! -! cd = 0 -! do c = nO+1, nBas-nR -! do d = nO+1, nBas-nR -! -! cd = cd + 1 -! -! rho2(p,q,ij) = rho2(p,q,ij) + ERI(p,q,c,d)*X2(cd,ij) -! end do -! end do -! -! kl = 0 -! do k = nC+1, nO -! do l = nC+1, nO -! -! kl = kl + 1 -! -! rho2(p,q,ij) = rho2(p,q,ij) + ERI(p,q,k,l)*Y2(kl,ij) -! end do -! end do -! -! end do -! end do -! -! end do -! end do -! !$OMP END DO -! !$OMP END PARALLEL - - end if + endif + endif end subroutine diff --git a/src/GW/evRGW.f90 b/src/GW/evRGW.f90 index ee92faf..acd44d3 100644 --- a/src/GW/evRGW.f90 +++ b/src/GW/evRGW.f90 @@ -209,7 +209,9 @@ subroutine evRGW(dotest,maxSCF,thresh,max_diis,doACFDT,exchange_kernel,doXBS,dop ! Cumulant expansion ! !--------------------! - call RGWC(dotest,nBas,nC,nO,nR,nS,Om,rho,eGW,Z) + ! TODO + !call RGWC(dotest, eta, nBas, nC, nO, nV, nR, nS, Om, rho, eHF, eGW, eGW, Z) + call RGWC(dotest, eta, nBas, nC, nO, nV, nR, nS, Om, rho, eHF, eHF, eGW, Z) ! Deallocate memory From 8d7fb2a29255637fb824c691422c0c1436ba0cd4 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Thu, 29 Aug 2024 15:19:16 +0200 Subject: [PATCH 05/11] few modifs in QuAck tests --- src/test/check_test_value.f90 | 10 +++++----- src/test/dump_test_value.f90 | 17 +++++++++-------- src/test/init_test.f90 | 6 +++--- src/test/stop_test.f90 | 6 +++--- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/test/check_test_value.f90 b/src/test/check_test_value.f90 index 2ee9bde..8828f82 100755 --- a/src/test/check_test_value.f90 +++ b/src/test/check_test_value.f90 @@ -9,12 +9,12 @@ subroutine check_test_value(branch) ! Local variables character(len=30) :: description - double precision :: value + double precision :: val double precision :: reference character(len=15) :: answer logical :: failed - double precision,parameter :: cutoff = 1d-10 + double precision,parameter :: thresh = 1d-10 ! Output variables @@ -45,19 +45,19 @@ subroutine check_test_value(branch) do read(11,'(A30)',end=11) description - read(11,'(F20.15)',end=11) value + read(11,'(F20.15)',end=11) val read(12,*,end=12) read(12,'(F20.15)',end=12) reference - if(abs(value-reference) < cutoff) then + if(dabs(val-reference)/(1d-15+dabs(reference)) < thresh) then answer = '.......... :-)' else answer = '.......... :-( ' failed = .true. end if write(*,'(1X,A1,1X,A30,1X,A1,1X,3F15.10,1X,A1,1X,A15,1X,A1)') & - '|',description,'|',value,reference,abs(value-reference),'|',answer,'|' + '|',description,'|',val,reference,abs(val-reference),'|',answer,'|' end do diff --git a/src/test/dump_test_value.f90 b/src/test/dump_test_value.f90 index ea00afe..e903e28 100755 --- a/src/test/dump_test_value.f90 +++ b/src/test/dump_test_value.f90 @@ -1,4 +1,4 @@ -subroutine dump_test_value(branch,description,value) +subroutine dump_test_value(branch, description, val) implicit none @@ -7,7 +7,7 @@ subroutine dump_test_value(branch,description,value) character(len=1),intent(in) :: branch character(len=*),intent(in) :: description - double precision,intent(in) :: value + double precision,intent(in) :: val ! Local variables @@ -15,18 +15,19 @@ subroutine dump_test_value(branch,description,value) if(branch == 'R') then - write(11,*) trim(description) - write(11,'(F20.15)') value + !write(1231597, '(A, ": ", F20.15)') '"' // trim(description) // '"', val + write(1231597, *) trim(description) + write(1231597, '(F20.15)') val elseif(branch == 'U') then - write(12,*) trim(description) - write(12,'(F20.15)') value + write(1232584,*) trim(description) + write(1232584,'(F20.15)') val elseif(branch == 'G') then - write(13,*) trim(description) - write(13,'(F20.15)') value + write(1234181,*) trim(description) + write(1234181,'(F20.15)') val else diff --git a/src/test/init_test.f90 b/src/test/init_test.f90 index 602ba54..b5ef295 100755 --- a/src/test/init_test.f90 +++ b/src/test/init_test.f90 @@ -12,10 +12,10 @@ subroutine init_test(doRtest,doUtest,doGtest) ! Output variables - if(doRtest) open(unit=11,file='test/Rtest.dat') + if(doRtest) open(unit=1231597, file='test/Rtest.dat') - if(doUtest) open(unit=12,file='test/Utest.dat') + if(doUtest) open(unit=1232584, file='test/Utest.dat') - if(doGtest) open(unit=13,file='test/Gtest.dat') + if(doGtest) open(unit=1234181, file='test/Gtest.dat') end subroutine diff --git a/src/test/stop_test.f90 b/src/test/stop_test.f90 index d41e2b0..185cbc5 100755 --- a/src/test/stop_test.f90 +++ b/src/test/stop_test.f90 @@ -12,10 +12,10 @@ subroutine stop_test(doRtest,doUtest,doGtest) ! Output variables - if(doRtest) close(unit=11) + if(doRtest) close(unit=1231597) - if(doUtest) close(unit=12) + if(doUtest) close(unit=1231597) - if(doGtest) close(unit=13) + if(doGtest) close(unit=1234181) end subroutine From 9aebbe74f060bf6cb1f7e4866c37fe4b2f0e8db3 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Thu, 29 Aug 2024 20:48:16 +0200 Subject: [PATCH 06/11] saving --- .gitignore | 3 + tests/.gitignore | 6 + tests/{bulk_set.py => balance_bench.py} | 0 tests/create_database.py | 10 +- tests/feather_bench.py | 93 +++++++++++ tests/{methods.test => inp/methods.RHF} | 0 tests/inp/options.RHF | 18 +++ tests/lunch_bench.py | 205 ++++++++++++++++++++++++ tests/molecule.py | 63 +++++--- tests/swift_set.py | 76 --------- tests/test_hf.py | 204 ----------------------- tests/{equi_set.py => titan_bench.py} | 0 tests/utils.py | 39 +++++ 13 files changed, 410 insertions(+), 307 deletions(-) create mode 100644 tests/.gitignore rename tests/{bulk_set.py => balance_bench.py} (100%) create mode 100644 tests/feather_bench.py rename tests/{methods.test => inp/methods.RHF} (100%) create mode 100644 tests/inp/options.RHF create mode 100644 tests/lunch_bench.py delete mode 100644 tests/swift_set.py delete mode 100644 tests/test_hf.py rename tests/{equi_set.py => titan_bench.py} (100%) create mode 100644 tests/utils.py diff --git a/.gitignore b/.gitignore index 288e294..899b091 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ *.o *. +__pycache__ + +.ninja_deps diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..89c22b8 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,6 @@ + +FeatherBench.db +FeatherBench.json + +*.xyz + diff --git a/tests/bulk_set.py b/tests/balance_bench.py similarity index 100% rename from tests/bulk_set.py rename to tests/balance_bench.py diff --git a/tests/create_database.py b/tests/create_database.py index 224b9b3..55c5718 100644 --- a/tests/create_database.py +++ b/tests/create_database.py @@ -4,21 +4,21 @@ import sqlite3 from molecule import save_molecules_to_json, load_molecules_from_json from molecule import create_database, add_molecule_to_db -from swift_set import swiftset +from feather_bench import FeatherBench # Save molecules to JSON -save_molecules_to_json(swiftset, 'swiftset.json') +save_molecules_to_json(FeatherBench, 'FeatherBench.json') # Load molecules from JSON -loaded_molecules = load_molecules_from_json('swiftset.json') +loaded_molecules = load_molecules_from_json('FeatherBench.json') print(loaded_molecules) # Create a database and add molecules -db_name = 'swiftset.db' +db_name = 'FeatherBench.db' create_database(db_name) -for molecule in swiftset: +for molecule in FeatherBench: add_molecule_to_db(db_name, molecule) diff --git a/tests/feather_bench.py b/tests/feather_bench.py new file mode 100644 index 0000000..1cfd07e --- /dev/null +++ b/tests/feather_bench.py @@ -0,0 +1,93 @@ + +from molecule import Molecule + + +He = Molecule( + name="He", + multiplicity=1, + geometry=[ + {"element": "He", "x": 0.0, "y": 0.0, "z": 0.0} + ], + properties={ + "properties_rhf":{ + "6-31g": { + "RHF energy": -2.855160426884076, + "RHF HOMO energy": -0.914126628614305, + "RHF LUMO energy": 1.399859335225087, + "RHF dipole moment": 0.000000000000000, + "RMP2 correlation energy": -0.011200122910187, + "CCD correlation energy": -0.014985063408247, + "DCD correlation energy": -0.014985062907429, + "CCSD correlation energy": -0.015001711549550, + "drCCD correlation energy": -0.018845374502248, + "rCCD correlation energy": -0.016836324636164, + "crCCD correlation energy": 0.008524677369855, + "lCCD correlation energy": -0.008082420815100, + "pCCD correlation energy": -0.014985062519068, + "RCIS singlet excitation energy": 1.911193619935257, + "RCIS triplet excitation energy": 1.455852629402236, + "phRRPA correlation energy": -0.018845374129105, + "phRRPAx correlation energy": -0.015760565121283, + "crRRPA correlation energy": -0.008868581132405, + "ppRRPA correlation energy": -0.008082420815100, + "RG0F2 correlation energy": -0.011438430540374, + "RG0F2 HOMO energy": -0.882696116247871, + "RG0F2 LUMO energy": 1.383080391811630, + "evRGF2 correlation energy": -0.011448483158486, + "evRGF2 HOMO energy": -0.881327878713477, + "evRGF2 LUMO energy": 1.382458968133448, + "RG0W0 correlation energy": -0.019314094399756, + "RG0W0 HOMO energy": -0.870533880190454, + "RG0W0 LUMO energy": 1.377171287010956, + "evRGW correlation energy": -0.019335511771724, + "evRGW HOMO energy": -0.868460640957913, + "evRGW LUMO energy": 1.376287581471769, + "RG0T0pp correlation energy": -0.008082420815100, + "RG0T0pp HOMO energy": -0.914126628614305, + "RG0T0pp LUMO energy": 1.399859335225087, + "evRGTpp correlation energy": -0.008082420815100, + "evRGTpp HOMO energy": -0.914126628614305, + "evRGTpp LUMO energy": 1.399859335225087 + } + }, + "properties_uhf":{ + "6-31g": { + } + }, + "properties_ghf":{ + "6-31g": { + } + }, + "properties_rohf":{ + "6-31g": { + } + } + } +) + +# --- + +#H2O = Molecule( +# name="H2O", +# multiplicity=1, +# geometry=[ +# {"element": "O", "x": 0.0000, "y": 0.0000, "z": 0.0000}, +# {"element": "H", "x": 0.7571, "y": 0.0000, "z": 0.5861}, +# {"element": "H", "x": -0.7571, "y": 0.0000, "z": 0.5861} +# ], +# properties={ +# "cc-pvdz": { +# } +#) + +# --- + +FeatherBench = [ + He, + #H2O +] + + + + + diff --git a/tests/methods.test b/tests/inp/methods.RHF similarity index 100% rename from tests/methods.test rename to tests/inp/methods.RHF diff --git a/tests/inp/options.RHF b/tests/inp/options.RHF new file mode 100644 index 0000000..92084cd --- /dev/null +++ b/tests/inp/options.RHF @@ -0,0 +1,18 @@ +# HF: maxSCF thresh DIIS guess mix shift stab search + 10000 0.0000001 5 1 0.0 0.0 F F +# MP: reg + F +# CC: maxSCF thresh DIIS + 64 0.0000001 5 +# spin: TDA singlet triplet + F T T +# GF: maxSCF thresh DIIS lin eta renorm reg + 256 0.00001 5 F 0.0 0 F +# GW: maxSCF thresh DIIS lin eta TDA_W reg + 256 0.00001 5 F 0.0 F F +# GT: maxSCF thresh DIIS lin eta TDA_T reg + 256 0.00001 5 F 0.0 F F +# ACFDT: AC Kx XBS + F F T +# BSE: phBSE phBSE2 ppBSE dBSE dTDA + F F F F T diff --git a/tests/lunch_bench.py b/tests/lunch_bench.py new file mode 100644 index 0000000..8f8bbba --- /dev/null +++ b/tests/lunch_bench.py @@ -0,0 +1,205 @@ + +import sys +import os +import shutil +from pathlib import Path +import subprocess +import platform +from datetime import datetime +import argparse + +from molecule import get_molecules_from_db +from molecule import generate_xyz +from utils import print_col + + +current_date = datetime.now() + +quack_root = os.getenv('QUACK_ROOT') + +# User Name +user_name = os.getlogin() + +# Operating System +os_name = platform.system() +os_release = platform.release() +os_version = platform.version() + +# CPU Information +machine = platform.machine() +processor = platform.processor() + +# System Architecture +architecture = platform.architecture()[0] + +# Python Version +python_version_full = platform.python_version_tuple() +PYTHON_VERSION = "{}.{}".format(python_version_full[0], python_version_full[1]) + + + +print(f"The current date and time is {current_date.strftime('%Y-%m-%d %H:%M:%S')}") +print(f"User Name: {user_name}") +print(f"Operating System: {os_name} {os_release} ({os_version})") +print(f"CPU: {processor} ({machine})") +print(f"System Architecture: {architecture}") +print(f"QUACK_ROOT: {quack_root}") +print(f"Python version: {python_version_full}\n\n") + + +parser = argparse.ArgumentParser(description="Benchmark Data Sets") + +parser.add_argument( + '-s', '--set_type', + choices=['light', 'medium', 'heavy'], + default='light', + help="Specify the type of data set: light (default), medium, or heavy." +) + +args = parser.parse_args() + +if args.set_type == 'light': + bench = 'FeatherBench' + bench_title = "\n\nSelected Light Benchmark: {}\n\n".format(bench) +elif args.set_type == 'medium': + bench = 'BalanceBench' + bench_title = "\n\nSelected Medium Benchmark: {}\n\n".format(bench) +elif args.set_type == 'heavy': + bench = 'TitanBench' + bench_title = "\n\nSelected Heavy Benchmark: {}\n\n".format(bench) +else: + bench_title = "\n\nSelected Light Benchmark: {}\n\n".format(bench) + +print(bench_title.center(150, '-')) +print("\n\n") + +# --- + +class Quack_Job: + + def __init__(self, mol, multip, basis, geom, methd): + self.mol = mol + self.multip = multip + self.basis = basis + self.geom = geom + self.methd = methd + + def prep_inp(self): + + # geometry + generate_xyz(self.geom, filename="{}.xyz".format(self.mol)) + + # input files + for inp in ["methods", "options"]: + inp_file = "{}.{}".format(inp, self.methd.upper()) + if os.path.exists("inp/{}".format(inp_file)): + shutil.copy("inp/{}".format(inp_file), "../mol/{}".format(inp_file)) + else: + print_col("File 'inp/{}' does not exist.".format(inp_file), "red") + sys.exit(1) + + def run(file_out, mol, bas, multip): + + os.chdir('..') + print(f" :$ cd ..") + + for file_in in ["methods", "options"]: + command = ['cp', 'tests/{}.RHF'.format(file_in), 'input/{}'.format(file_in)] + print(f" :$ {' '.join(command)}") + result = subprocess.run(command, capture_output=True, text=True) + if result.returncode != 0: + print("Error moving file: {}".format(result.stderr)) + + command = [ + 'python{}'.format(PYTHON_VERSION), 'PyDuck.py', + '-x', '{}'.format(mol), + '-b', '{}'.format(bas), + '-m', '{}'.format(multip) + ] + print(f" :$ {' '.join(command)}") + with open(file_out, 'w') as fobj: + result = subprocess.run(command, stdout=fobj, stderr=subprocess.PIPE, text=True) + if result.stderr: + print("Error output:", result.stderr) + + os.chdir('tests') + print(f" :$ cd tests") + + +# --- + + +def main(): + + work_path = Path('{}/tests/work'.format(quack_root)) + if not work_path.exists(): + work_path.mkdir(parents=True, exist_ok=True) + print(f"Directory '{work_path}' created.\n") + + for mol in molecules: + + mol_name = mol.name + mol_mult = mol.multiplicity + mol_geom = mol.geometry + mol_data = mol.properties + + print_col(" Molecule: {} (2S+1 = {})".format(mol_name, mol_mult), "blue") + + for mol_prop_name, mol_prop_data in mol_data.items(): + + print_col(" Testing {}".format(mol_prop_name), "cyan") + + methd = mol_prop_name[len('properties_'):] + + if(len(mol_prop_data) == 0): + print_col(" {} is empty. Skipping...".format(mol_prop_name), "cyan") + print() + continue + + for basis_name, basis_data in mol_prop_data.items(): + print_col(" Basis set = {}".format(basis_name), "yellow") + + if(len(basis_data) == 0): + print_col(" {} is empty. Skipping...".format(basis_name), "yellow") + print() + continue + + work_methd = Path('{}/{}'.format(work_path, methd)) + if not work_methd.exists(): + work_methd.mkdir(parents=True, exist_ok=True) + #print(f"Directory '{work_methd}' created.\n") + + New_Quack_Job = Quack_Job(mol_name, mol_mult, basis_name, mol_geom, methd) + New_Quack_Job.prep_inp() + +# for name, val in basis_data.items(): +# print(f" name = {name}") +# print(f" val = {val}") + + print() + print() + print() + + quit() + + +# # create input files +# class_methd.gen_input() +# +# file_out = "{}/{}/{}_{}_{}.out".format(work_path, prop, mol_name, mol_mult, bas) +# +# print(" testing {} for {}@{} (2S+1 = {})".format(prop, mol_name, bas, mol_mult)) +# print(" file_out: {}".format(file_out)) +# +# class_methd.run_job(file_out, mol_name, bas, mol_mult) + + + + + +db_name = '{}.db'.format(bench) + +molecules = get_molecules_from_db(db_name) + +main() + diff --git a/tests/molecule.py b/tests/molecule.py index 9d7b648..147c53e 100644 --- a/tests/molecule.py +++ b/tests/molecule.py @@ -3,22 +3,18 @@ import json import sqlite3 class Molecule: - def __init__(self, name, multiplicity, geometry, energies): + def __init__(self, name, multiplicity, geometry, properties): self.name = name self.multiplicity = multiplicity - self.geometry = geometry # List of tuples (atom, x, y, z) - self.energies = energies # Dictionary of dictionaries: {method: {basis: energy}} - - def get_energy(self, method, basis): - """Retrieve energy for a specific method and basis set.""" - return self.energies.get(method, {}).get(basis, None) + self.geometry = geometry + self.properties = properties def to_dict(self): return { "name": self.name, "multiplicity": self.multiplicity, "geometry": self.geometry, - "energies": self.energies, + "properties": self.properties, } @staticmethod @@ -27,7 +23,7 @@ class Molecule: name=data["name"], multiplicity=data["multiplicity"], geometry=data["geometry"], - energies=data["energies"] + properties=data["properties"] ) def save_molecules_to_json(molecules, filename): @@ -45,7 +41,7 @@ def create_database(db_name): conn = sqlite3.connect(db_name) cursor = conn.cursor() cursor.execute('''CREATE TABLE IF NOT EXISTS molecules - (name TEXT, multiplicity INTEGER, geometry TEXT, energies TEXT)''') + (name TEXT, multiplicity INTEGER, geometry TEXT, properties TEXT)''') conn.commit() conn.close() @@ -53,7 +49,7 @@ def add_molecule_to_db(db_name, molecule): conn = sqlite3.connect(db_name) cursor = conn.cursor() geometry_str = json.dumps(molecule.geometry) - energies_str = json.dumps(molecule.energies) + energies_str = json.dumps(molecule.properties) cursor.execute("INSERT INTO molecules VALUES (?, ?, ?, ?)", (molecule.name, molecule.multiplicity, geometry_str, energies_str)) conn.commit() @@ -62,25 +58,48 @@ def add_molecule_to_db(db_name, molecule): def get_molecules_from_db(db_name): conn = sqlite3.connect(db_name) cursor = conn.cursor() - cursor.execute("SELECT name, multiplicity, geometry, energies FROM molecules") + cursor.execute("SELECT name, multiplicity, geometry, properties FROM molecules") rows = cursor.fetchall() molecules = [] for row in rows: name, multiplicity, geometry_str, energies_str = row geometry = json.loads(geometry_str) - energies = json.loads(energies_str) # energies is a dictionary of dictionaries - molecules.append(Molecule(name, multiplicity, geometry, energies)) + properties = json.loads(energies_str) + molecules.append(Molecule(name, multiplicity, geometry, properties)) conn.close() return molecules -def write_geometry_to_xyz(molecule, filename): + +def generate_xyz(elements, filename="output.xyz", verbose=False): + """ + Generate an XYZ file from a list of elements. + + Parameters: + elements (list): A list of dictionaries, where each dictionary represents + an atom with its element and x, y, z coordinates. + filename (str): The name of the output XYZ file. Default is 'output.xyz'. + """ + + # Get the number of atoms + num_atoms = len(elements) + + # Open the file in write mode with open(filename, 'w') as f: - # First line: number of atoms - f.write(f"{len(molecule.geometry)}\n") - # Second line: empty comment line - f.write("\n") - # Remaining lines: atom positions - for atom, x, y, z in molecule.geometry: - f.write(f"{atom} {x:.6f} {y:.6f} {z:.6f}\n") + # Write the number of atoms + f.write(f"{num_atoms}\n") + + # Write a comment line (can be left blank or customized) + f.write("XYZ file generated by generate_xyz function\n") + + # Write the element and coordinates + for atom in elements: + element = atom['element'] + x = atom['x'] + y = atom['y'] + z = atom['z'] + f.write(f"{element} {x:.6f} {y:.6f} {z:.6f}\n") + + if(verbose): + print(f"XYZ file '{filename}' generated successfully!") diff --git a/tests/swift_set.py b/tests/swift_set.py deleted file mode 100644 index 5c846ce..0000000 --- a/tests/swift_set.py +++ /dev/null @@ -1,76 +0,0 @@ - -from molecule import Molecule - - -He = Molecule( - name="He", - multiplicity=1, - geometry=[ - {"element": "He", "x": 0.0, "y": 0.0, "z": 0.0} - ], - properties={ - "6-31g": { - "RHF energy": -2.855160426884076, - "RHF HOMO energy": -0.914126628614305, - "RHF LUMO energy": 1.399859335225087, - "RHF dipole moment": 0.000000000000000, - "RMP2 correlation energy": -0.011200122910187, - "CCD correlation energy": -0.014985063408247, - "DCD correlation energy": -0.014985062907429, - "CCSD correlation energy": -0.015001711549550, - "drCCD correlation energy": -0.018845374502248, - "rCCD correlation energy": -0.016836324636164, - "crCCD correlation energy": 0.008524677369855, - "lCCD correlation energy": -0.008082420815100, - "pCCD correlation energy": -0.014985062519068, - "RCIS singlet excitation energy": 1.911193619935257, - "RCIS triplet excitation energy": 1.455852629402236, - "phRRPA correlation energy": -0.018845374129105, - "phRRPAx correlation energy": -0.015760565121283, - "crRRPA correlation energy": -0.008868581132405, - "ppRRPA correlation energy": -0.008082420815100, - "RG0F2 correlation energy": -0.011438430540374, - "RG0F2 HOMO energy": -0.882696116247871, - "RG0F2 LUMO energy": 1.383080391811630, - "evRGF2 correlation energy": -0.011448483158486, - "evRGF2 HOMO energy": -0.881327878713477, - "evRGF2 LUMO energy": 1.382458968133448, - "RG0W0 correlation energy": -0.019314094399756, - "RG0W0 HOMO energy": -0.870533880190454, - "RG0W0 LUMO energy": 1.377171287010956, - "evRGW correlation energy": -0.019335511771724, - "evRGW HOMO energy": -0.868460640957913, - "evRGW LUMO energy": 1.376287581471769, - "RG0T0pp correlation energy": -0.008082420815100, - "RG0T0pp HOMO energy": -0.914126628614305, - "RG0T0pp LUMO energy": 1.399859335225087, - "evRGTpp correlation energy": -0.008082420815100, - "evRGTpp HOMO energy": -0.914126628614305, - "evRGTpp LUMO energy": 1.399859335225087 - } - } -) - -# --- - -H2O = Molecule( - name="H2O", - multiplicity=1, - geometry=[ - {"element": "O", "x": 0.0000, "y": 0.0000, "z": 0.0000}, - {"element": "H", "x": 0.7571, "y": 0.0000, "z": 0.5861}, - {"element": "H", "x": -0.7571, "y": 0.0000, "z": 0.5861} - ], - properties={ - "cc-pvdz": { - } -) - -# --- - -SwiftSet = [He, H2O] - - - - - diff --git a/tests/test_hf.py b/tests/test_hf.py deleted file mode 100644 index fd04121..0000000 --- a/tests/test_hf.py +++ /dev/null @@ -1,204 +0,0 @@ - -import os -from pathlib import Path -import subprocess -import platform -from datetime import datetime - -from molecule import get_molecules_from_db - - -current_date = datetime.now() - -quack_root = os.getenv('QUACK_ROOT') - -# User Name -user_name = os.getlogin() - -# Operating System -os_name = platform.system() -os_release = platform.release() -os_version = platform.version() - -# CPU Information -machine = platform.machine() -processor = platform.processor() - -# System Architecture -architecture = platform.architecture()[0] - -# Python Version -python_version_full = platform.python_version_tuple() -PYTHON_VERSION = "{}.{}".format(python_version_full[0], python_version_full[1]) - - -print(f"The current date and time is {current_date.strftime('%Y-%m-%d %H:%M:%S')}") -print(f"User Name: {user_name}") -print(f"Operating System: {os_name} {os_release} ({os_version})") -print(f"CPU: {processor} ({machine})") -print(f"System Architecture: {architecture}") -print(f"QUACK_ROOT: {quack_root}") -print(f"Python version: {python_version_full}\n\n") - -# --- - -mp2 = "# MP2 MP3\n F F\n" -cc = "# CCD pCCD DCD CCSD CCSD(T)\n F F F F F\n" -rcc = "# drCCD rCCD crCCD lCCD\n F F F F\n" -ci = "# CIS CIS(D) CID CISD FCI\n F F F F F\n" -rpa = "# phRPA phRPAx crRPA ppRPA\n F F F F\n" -gf = "# G0F2 evGF2 qsGF2 ufGF2 G0F3 evGF3\n F F F F F F\n" -gw = "# G0W0 evGW qsGW SRG-qsGW ufG0W0 ufGW\n F F F F F F\n" -gtpp = "# G0T0pp evGTpp qsGTpp ufG0T0pp\n F F F F\n" -gteh = "# G0T0eh evGTeh qsGTeh\n F F F\n" -tests = "# Rtest Utest Gtest\n F F F\n" - -# --- - -hf_opt = "# HF: maxSCF thresh DIIS guess mix shift stab search\n 256 0.00001 5 1 0.0 0.0 F F\n" -mp_opt = "# MP: reg\n F\n" -cc_opt = "# CC: maxSCF thresh DIIS\n 64 0.00001 5\n" -tda_opt = "# spin: TDA singlet triplet\n F T T\n" -gf_opt = "# GF: maxSCF thresh DIIS lin eta renorm reg\n 256 0.00001 5 F 0.0 0 F\n" -gw_opt = "# GW: maxSCF thresh DIIS lin eta TDA_W reg\n 256 0.00001 5 F 0.0 F F\n" -gt_opt = "# GT: maxSCF thresh DIIS lin eta TDA_T reg\n 256 0.00001 5 F 0.0 F F\n" -acfdt_opt = "# ACFDT: AC Kx XBS\n F F T\n" -bse_opt = "# BSE: phBSE phBSE2 ppBSE dBSE dTDA\n F F F F T\n" -list_opt = [hf_opt, mp_opt, cc_opt, tda_opt, gf_opt, gw_opt, gt_opt, acfdt_opt, bse_opt] - -# --- - -class class_RHF: - - def gen_input(): - - f = open("methods", "w") - f.write("# RHF UHF GHF ROHF\n") - f.write(" T F F F\n") - f.write("{}{}{}{}{}{}{}{}{}{}".format(mp2, cc, rcc, ci, rpa, gf, gw, gtpp, gteh, tests)) - f.close() - - f = open("options", "w") - for opt in list_opt: - f.write("{}".format(opt)) - f.close() - - def run_job(file_out, mol, bas, multip): - - os.chdir('..') - print(f" :$ cd ..") - - for file_in in ["methods", "options"]: - command = ['cp', 'tests/{}'.format(file_in), 'input/{}'.format(file_in)] - print(f" :$ {' '.join(command)}") - result = subprocess.run(command, capture_output=True, text=True) - if result.returncode != 0: - print("Error moving file: {}".format(result.stderr)) - - command = [ - 'python{}'.format(PYTHON_VERSION), 'PyDuck.py', - '-x', '{}'.format(mol), - '-b', '{}'.format(bas), - '-m', '{}'.format(multip) - ] - print(f" :$ {' '.join(command)}") - with open(file_out, 'w') as fobj: - result = subprocess.run(command, stdout=fobj, stderr=subprocess.PIPE, text=True) - if result.stderr: - print("Error output:", result.stderr) - - os.chdir('tests') - print(f" :$ cd tests") - - -# --- - -class class_UHF: - def gen_input(): - f = open("methods", "w") - f.write("# RHF UHF GHF ROHF\n") - f.write(" F T F F\n") - f.write("{}{}{}{}{}{}{}{}{}{}".format(mp2, cc, rcc, ci, rpa, gf, gw, gtpp, gteh, tests)) - f.close() - -# --- - -class class_GHF: - def gen_input(): - f = open("methods", "w") - f.write("# RHF UHF GHF ROHF\n") - f.write(" F F T F\n") - f.write("{}{}{}{}{}{}{}{}{}{}".format(mp2, cc, rcc, ci, rpa, gf, gw, gtpp, gteh, tests)) - f.close() - -# --- - -class class_ROHF: - def gen_input(): - f = open("methods", "w") - f.write("# RHF UHF GHF ROHF\n") - f.write(" F F F T\n") - f.write("{}{}{}{}{}{}{}{}{}{}".format(mp2, cc, rcc, ci, rpa, gf, gw, gtpp, gteh, tests)) - f.close() - -# --- - -class_map = { - "RHF": class_RHF, - "UHF": class_UHF, - "GHF": class_GHF, - "ROHF": class_ROHF, -} - -def main(): - - work_path = Path('{}/tests/work'.format(quack_root)) - if not work_path.exists(): - work_path.mkdir(parents=True, exist_ok=True) - print(f"Directory '{work_path}' created.\n") - - for mol in molecules: - - mol_name = mol.name - mol_mult = mol.multiplicity - - - for methd in list_methd: - - if methd not in mol.energies: - print(f"Method {methd} does not exist for {mol_name}.") - continue - - for bas, _ in mol.energies[methd].items(): - - work_methd = Path('{}/{}'.format(work_path, methd)) - if not work_methd.exists(): - work_methd.mkdir(parents=True, exist_ok=True) - print(f"Directory '{work_methd}' created.\n") - - class_methd = class_map.get(methd) - - # create input files - class_methd.gen_input() - - file_out = "{}/{}/{}_{}_{}.out".format(work_path, methd, mol_name, mol_mult, bas) - - print(" testing {} for {}@{} (2S+1 = {})".format(methd, mol_name, bas, mol_mult)) - print(" file_out: {}".format(file_out)) - - class_methd.run_job(file_out, mol_name, bas, mol_mult) - - print("\n") - print("\n\n") - - print(" --- --- --- ---") - print("\n\n\n") - - -db_name = 'molecules.db' -molecules = get_molecules_from_db(db_name) - -list_methd = ["RHF", "UHF", "GHF", "ROHF"] - -main() - diff --git a/tests/equi_set.py b/tests/titan_bench.py similarity index 100% rename from tests/equi_set.py rename to tests/titan_bench.py diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000..297cb4c --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,39 @@ + +def print_col(text, color): + + if(color == "black"): + + print("\033[30m{}\033[0m".format(text)) + + elif(color == "red"): + + print("\033[31m{}\033[0m".format(text)) + + elif(color == "green"): + + print("\033[32m{}\033[0m".format(text)) + + elif(color == "yellow"): + + print("\033[33m{}\033[0m".format(text)) + + elif(color == "blue"): + + print("\033[34m{}\033[0m".format(text)) + + elif(color == "magenta"): + + print("\033[35m{}\033[0m".format(text)) + + elif(color == "cyan"): + + print("\033[36m{}\033[0m".format(text)) + + elif(color == "white"): + + print("\033[37m{}\033[0m".format(text)) + + else: + + print("{}".format(text)) + From 76c797fa4a35e989f938fa303d9dd1b7c5b3a252 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Thu, 29 Aug 2024 23:18:44 +0200 Subject: [PATCH 07/11] spinner simulation --- tests/.gitignore | 1 + tests/lunch_bench.py | 95 ++++++++++++++++++++++++-------------------- tests/utils.py | 49 +++++++++++++++++++++++ 3 files changed, 102 insertions(+), 43 deletions(-) diff --git a/tests/.gitignore b/tests/.gitignore index 89c22b8..afb251f 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -3,4 +3,5 @@ FeatherBench.db FeatherBench.json *.xyz +work diff --git a/tests/lunch_bench.py b/tests/lunch_bench.py index 8f8bbba..678a4fc 100644 --- a/tests/lunch_bench.py +++ b/tests/lunch_bench.py @@ -1,4 +1,6 @@ +import time +import threading import sys import os import shutil @@ -10,7 +12,7 @@ import argparse from molecule import get_molecules_from_db from molecule import generate_xyz -from utils import print_col +from utils import print_col, stdout_col current_date = datetime.now() @@ -98,34 +100,54 @@ class Quack_Job: print_col("File 'inp/{}' does not exist.".format(inp_file), "red") sys.exit(1) - def run(file_out, mol, bas, multip): + def run(self, work_path): - os.chdir('..') - print(f" :$ cd ..") + def display_spinner(): + spinner = ['|', '/', '-', '\\'] + idx = 0 + while not done_event.is_set(): + stdout_col(f'\r Testing {self.methd} ({self.basis}) {spinner[idx]}', "yellow") + sys.stdout.flush() + idx = (idx + 1) % len(spinner) + time.sleep(0.1) + stdout_col(f'\r Testing {self.methd} ({self.basis}) ', "yellow") - for file_in in ["methods", "options"]: - command = ['cp', 'tests/{}.RHF'.format(file_in), 'input/{}'.format(file_in)] - print(f" :$ {' '.join(command)}") - result = subprocess.run(command, capture_output=True, text=True) - if result.returncode != 0: - print("Error moving file: {}".format(result.stderr)) + done_event = threading.Event() + spinner_thread = threading.Thread(target=display_spinner) + spinner_thread.start() - command = [ - 'python{}'.format(PYTHON_VERSION), 'PyDuck.py', - '-x', '{}'.format(mol), - '-b', '{}'.format(bas), - '-m', '{}'.format(multip) - ] - print(f" :$ {' '.join(command)}") - with open(file_out, 'w') as fobj: - result = subprocess.run(command, stdout=fobj, stderr=subprocess.PIPE, text=True) - if result.stderr: - print("Error output:", result.stderr) + try: + + os.chdir('..') + #print_col(f" Starting QuAck..", "magenta") + #print_col(f" $ cd ..", "magenta") + + command = [ + 'python{}'.format(PYTHON_VERSION), 'PyDuck.py', + '-x', '{}'.format(self.mol), + '-b', '{}'.format(self.basis), + '-m', '{}'.format(self.multip) + ] + #print_col(f" $ {' '.join(command)}", "magenta") + + file_out = "{}/{}/{}_{}_{}.out".format(work_path, self.methd, self.mol, self.multip, self.basis) + with open(file_out, 'w') as fobj: + result = subprocess.run(command, stdout=fobj, stderr=subprocess.PIPE, text=True) + if result.stderr: + print("Error output:", result.stderr) + + os.chdir('tests') + #print_col(f" $ cd tests", "magenta") + + except Exception as e: - os.chdir('tests') - print(f" :$ cd tests") + print_col(f"An error occurred: {str(e)}", "red") + finally: + done_event.set() + spinner_thread.join() + # --- @@ -147,21 +169,21 @@ def main(): for mol_prop_name, mol_prop_data in mol_data.items(): - print_col(" Testing {}".format(mol_prop_name), "cyan") + #print_col(" Testing {}".format(mol_prop_name), "cyan") methd = mol_prop_name[len('properties_'):] if(len(mol_prop_data) == 0): - print_col(" {} is empty. Skipping...".format(mol_prop_name), "cyan") - print() + #print_col(" {} is empty. Skipping...".format(mol_prop_name), "cyan") + #print() continue for basis_name, basis_data in mol_prop_data.items(): - print_col(" Basis set = {}".format(basis_name), "yellow") + #print_col(" Basis set: {}".format(basis_name), "yellow") if(len(basis_data) == 0): - print_col(" {} is empty. Skipping...".format(basis_name), "yellow") - print() + #print_col(" {} is empty. Skipping...".format(basis_name), "yellow") + #print() continue work_methd = Path('{}/{}'.format(work_path, methd)) @@ -171,6 +193,7 @@ def main(): New_Quack_Job = Quack_Job(mol_name, mol_mult, basis_name, mol_geom, methd) New_Quack_Job.prep_inp() + New_Quack_Job.run(work_path) # for name, val in basis_data.items(): # print(f" name = {name}") @@ -183,20 +206,6 @@ def main(): quit() -# # create input files -# class_methd.gen_input() -# -# file_out = "{}/{}/{}_{}_{}.out".format(work_path, prop, mol_name, mol_mult, bas) -# -# print(" testing {} for {}@{} (2S+1 = {})".format(prop, mol_name, bas, mol_mult)) -# print(" file_out: {}".format(file_out)) -# -# class_methd.run_job(file_out, mol_name, bas, mol_mult) - - - - - db_name = '{}.db'.format(bench) molecules = get_molecules_from_db(db_name) diff --git a/tests/utils.py b/tests/utils.py index 297cb4c..a5f090f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,4 +1,9 @@ +import sys + + + + def print_col(text, color): if(color == "black"): @@ -37,3 +42,47 @@ def print_col(text, color): print("{}".format(text)) + +# --- + +def stdout_col(text, color): + + if(color == "black"): + + sys.stdout.write("\033[30m{}\033[0m".format(text)) + + elif(color == "red"): + + sys.stdout.write("\033[31m{}\033[0m".format(text)) + + elif(color == "green"): + + sys.stdout.write("\033[32m{}\033[0m".format(text)) + + elif(color == "yellow"): + + sys.stdout.write("\033[33m{}\033[0m".format(text)) + + elif(color == "blue"): + + sys.stdout.write("\033[34m{}\033[0m".format(text)) + + elif(color == "magenta"): + + sys.stdout.write("\033[35m{}\033[0m".format(text)) + + elif(color == "cyan"): + + sys.stdout.write("\033[36m{}\033[0m".format(text)) + + elif(color == "white"): + + sys.stdout.write("\033[37m{}\033[0m".format(text)) + + else: + + sys.stdout.write("{}".format(text)) + +# --- + + From fadd1b39291511753bba04c78c486d54a9de168b Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Fri, 30 Aug 2024 00:10:19 +0200 Subject: [PATCH 08/11] added eval diff with ref --- tests/create_database.py | 6 ++-- tests/lunch_bench.py | 61 ++++++++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/tests/create_database.py b/tests/create_database.py index 55c5718..59cdee2 100644 --- a/tests/create_database.py +++ b/tests/create_database.py @@ -9,11 +9,11 @@ from feather_bench import FeatherBench # Save molecules to JSON -save_molecules_to_json(FeatherBench, 'FeatherBench.json') +#save_molecules_to_json(FeatherBench, 'FeatherBench.json') # Load molecules from JSON -loaded_molecules = load_molecules_from_json('FeatherBench.json') -print(loaded_molecules) +#loaded_molecules = load_molecules_from_json('FeatherBench.json') +#print(loaded_molecules) # Create a database and add molecules db_name = 'FeatherBench.db' diff --git a/tests/lunch_bench.py b/tests/lunch_bench.py index 678a4fc..69a6093 100644 --- a/tests/lunch_bench.py +++ b/tests/lunch_bench.py @@ -57,9 +57,21 @@ parser.add_argument( default='light', help="Specify the type of data set: light (default), medium, or heavy." ) +parser.add_argument( + '-t', '--thresh', + type=float, + default=1e-8, + help='Threshold for acceptable difference (default: 1e-8)' +) + + + + args = parser.parse_args() +THRESH = args.thresh + if args.set_type == 'light': bench = 'FeatherBench' bench_title = "\n\nSelected Light Benchmark: {}\n\n".format(bench) @@ -106,11 +118,11 @@ class Quack_Job: spinner = ['|', '/', '-', '\\'] idx = 0 while not done_event.is_set(): - stdout_col(f'\r Testing {self.methd} ({self.basis}) {spinner[idx]}', "yellow") + stdout_col(f'\r Testing {self.methd} ({self.basis}) {spinner[idx]}', "cyan") sys.stdout.flush() idx = (idx + 1) % len(spinner) - time.sleep(0.1) - stdout_col(f'\r Testing {self.methd} ({self.basis}) ', "yellow") + time.sleep(0.05) + stdout_col(f'\r Testing {self.methd} ({self.basis}) \n', "cyan") done_event = threading.Event() spinner_thread = threading.Thread(target=display_spinner) @@ -147,7 +159,37 @@ class Quack_Job: done_event.set() spinner_thread.join() + + def check_data(self, data_ref): + filepath = '../test/Rtest.dat' + data_new = {} + try: + # read data_new + with open(filepath, 'r') as f: + lines = f.readlines() + for i in range(0, len(lines) - 1, 2): + key = lines[i].strip() + value = lines[i + 1].strip() + data_new[key] = float(value) # Convert value to float + + # Compare with data_ref + for key in data_ref: + if key not in data_new: + print_col(f" 😐 {key} missing ⚠ī¸ ", "yellow") + else: + diff = abs(data_new[key] - data_ref[key]) / (1e-15 + abs(data_ref[key])) + if(diff <= THRESH): + print_col(f" 🙂 {key}: ✔ī¸ ", "green") + else: + print_col(f" ☚ī¸ {key}: ❌ {data_ref[key]} ≠ {data_new[key]}", "red") + except FileNotFoundError: + print_col(f"Error: The file '{filepath}' does not exist.", "red") + sys.exist(1) + except Exception as e: + print_col(f"An error occurred: {str(e)}", "red") + sys.exist(1) + # --- @@ -169,35 +211,24 @@ def main(): for mol_prop_name, mol_prop_data in mol_data.items(): - #print_col(" Testing {}".format(mol_prop_name), "cyan") - methd = mol_prop_name[len('properties_'):] if(len(mol_prop_data) == 0): - #print_col(" {} is empty. Skipping...".format(mol_prop_name), "cyan") - #print() continue for basis_name, basis_data in mol_prop_data.items(): - #print_col(" Basis set: {}".format(basis_name), "yellow") if(len(basis_data) == 0): - #print_col(" {} is empty. Skipping...".format(basis_name), "yellow") - #print() continue work_methd = Path('{}/{}'.format(work_path, methd)) if not work_methd.exists(): work_methd.mkdir(parents=True, exist_ok=True) - #print(f"Directory '{work_methd}' created.\n") New_Quack_Job = Quack_Job(mol_name, mol_mult, basis_name, mol_geom, methd) New_Quack_Job.prep_inp() New_Quack_Job.run(work_path) - -# for name, val in basis_data.items(): -# print(f" name = {name}") -# print(f" val = {val}") + New_Quack_Job.check_data(basis_data) print() print() From 2c312cfc579690f4a17ab2a27571a770e446e99a Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Fri, 30 Aug 2024 20:15:39 +0200 Subject: [PATCH 09/11] v0 of FeatherBench --- src/LR/ppLR.f90 | 61 +++++++++--------- test/export_tobench.py | 26 ++++++++ tests/create_database.py | 35 +++++++++-- tests/feather_bench.py | 130 ++++++++++++++++++++++----------------- tests/inp/methods.RHF | 6 +- tests/lunch_bench.py | 2 +- tests/molecule.py | 63 ++++++++++++++++--- 7 files changed, 223 insertions(+), 100 deletions(-) create mode 100644 test/export_tobench.py diff --git a/src/LR/ppLR.f90 b/src/LR/ppLR.f90 index 64d533c..582e28f 100644 --- a/src/LR/ppLR.f90 +++ b/src/LR/ppLR.f90 @@ -72,38 +72,43 @@ subroutine ppLR(TDA, nOO, nVV, Bpp, Cpp, Dpp, Om1, X1, Y1, Om2, X2, Y2, EcRPA) M( 1:nVV ,nVV+1:nOO+nVV) = - Bpp(1:nVV,1:nOO) M(nVV+1:nOO+nVV, 1:nVV) = + transpose(Bpp(1:nVV,1:nOO)) - !! Diagonalize the p-p matrix - !if(nOO+nVV > 0) call diagonalize_general_matrix(nOO+nVV, M, Om, Z) - !! Split the various quantities in p-p and h-h parts - !call sort_ppRPA(nOO, nVV, Om, Z, Om1, X1, Y1, Om2, X2, Y2) + if((nOO .eq. 0) .or. (nVV .eq. 0)) then + ! Diagonalize the p-p matrix + if(nOO+nVV > 0) call diagonalize_general_matrix(nOO+nVV, M, Om, Z) + ! Split the various quantities in p-p and h-h parts + call sort_ppRPA(nOO, nVV, Om, Z, Om1, X1, Y1, Om2, X2, Y2) - thr_d = 1d-6 ! to determine if diagonal elements of L.T x R are close enouph to 1 - thr_nd = 1d-6 ! to determine if non-diagonal elements of L.T x R are close enouph to 1 - thr_deg = 1d-8 ! to determine if two eigenvectors are degenerate or not - imp_bio = .True. ! impose bi-orthogonality - verbose = .False. - call diagonalize_nonsym_matrix(N, M, Z, Om, thr_d, thr_nd, thr_deg, imp_bio, verbose) + else - do i = 1, nOO - Om2(i) = Om(i) - do j = 1, nVV - X2(j,i) = Z(j,i) - enddo - do j = 1, nOO - Y2(j,i) = Z(nVV+j,i) - enddo - enddo + thr_d = 1d-6 ! to determine if diagonal elements of L.T x R are close enouph to 1 + thr_nd = 1d-6 ! to determine if non-diagonal elements of L.T x R are close enouph to 1 + thr_deg = 1d-8 ! to determine if two eigenvectors are degenerate or not + imp_bio = .True. ! impose bi-orthogonality + verbose = .False. + call diagonalize_nonsym_matrix(N, M, Z, Om, thr_d, thr_nd, thr_deg, imp_bio, verbose) + + do i = 1, nOO + Om2(i) = Om(i) + do j = 1, nVV + X2(j,i) = Z(j,i) + enddo + do j = 1, nOO + Y2(j,i) = Z(nVV+j,i) + enddo + enddo + + do i = 1, nVV + Om1(i) = Om(nOO+i) + do j = 1, nVV + X1(j,i) = M(j,nOO+i) + enddo + do j = 1, nOO + Y1(j,i) = M(nVV+j,nOO+i) + enddo + enddo - do i = 1, nVV - Om1(i) = Om(nOO+i) - do j = 1, nVV - X1(j,i) = M(j,nOO+i) - enddo - do j = 1, nOO - Y1(j,i) = M(nVV+j,nOO+i) - enddo - enddo + endif end if diff --git a/test/export_tobench.py b/test/export_tobench.py new file mode 100644 index 0000000..526716b --- /dev/null +++ b/test/export_tobench.py @@ -0,0 +1,26 @@ + +import sys + + +def read_quantities_from_file(filename): + quantities = {} + + with open(filename, 'r') as file: + lines = file.readlines() + for i in range(0, len(lines), 2): + # Remove any leading or trailing whitespace/newline characters + quantity_name = lines[i].strip() + quantity_value = float(lines[i+1].strip()) + quantities[quantity_name] = quantity_value + + return quantities + +def print_quantities(quantities): + for key, value in quantities.items(): + print(f'"{key}": {value},') + +filename = sys.argv[1] + +quantities = read_quantities_from_file(filename) +print_quantities(quantities) + diff --git a/tests/create_database.py b/tests/create_database.py index 59cdee2..14ed3f6 100644 --- a/tests/create_database.py +++ b/tests/create_database.py @@ -1,12 +1,39 @@ -import sqlite3 +import argparse from molecule import save_molecules_to_json, load_molecules_from_json -from molecule import create_database, add_molecule_to_db +from molecule import create_database, add_molecule_to_db, remove_database from feather_bench import FeatherBench +parser = argparse.ArgumentParser(description="Benchmark Data Sets") + +parser.add_argument( + '-s', '--set_type', + choices=['light', 'medium', 'heavy'], + default='light', + help="Specify the type of data set: light (default), medium, or heavy." +) + + +args = parser.parse_args() + +if args.set_type == 'light': + bench = 'FeatherBench' + bench_title = "\n\nSelected Light Benchmark: {}\n\n".format(bench) +elif args.set_type == 'medium': + bench = 'BalanceBench' + bench_title = "\n\nSelected Medium Benchmark: {}\n\n".format(bench) +elif args.set_type == 'heavy': + bench = 'TitanBench' + bench_title = "\n\nSelected Heavy Benchmark: {}\n\n".format(bench) +else: + bench_title = "\n\nSelected Light Benchmark: {}\n\n".format(bench) + + +db_name = '{}.db'.format(bench) + # Save molecules to JSON #save_molecules_to_json(FeatherBench, 'FeatherBench.json') @@ -15,8 +42,8 @@ from feather_bench import FeatherBench #loaded_molecules = load_molecules_from_json('FeatherBench.json') #print(loaded_molecules) -# Create a database and add molecules -db_name = 'FeatherBench.db' +#remove_database(db_name) + create_database(db_name) for molecule in FeatherBench: add_molecule_to_db(db_name, molecule) diff --git a/tests/feather_bench.py b/tests/feather_bench.py index 1cfd07e..b6d8f26 100644 --- a/tests/feather_bench.py +++ b/tests/feather_bench.py @@ -11,43 +11,35 @@ He = Molecule( properties={ "properties_rhf":{ "6-31g": { - "RHF energy": -2.855160426884076, - "RHF HOMO energy": -0.914126628614305, - "RHF LUMO energy": 1.399859335225087, - "RHF dipole moment": 0.000000000000000, - "RMP2 correlation energy": -0.011200122910187, - "CCD correlation energy": -0.014985063408247, - "DCD correlation energy": -0.014985062907429, - "CCSD correlation energy": -0.015001711549550, - "drCCD correlation energy": -0.018845374502248, - "rCCD correlation energy": -0.016836324636164, - "crCCD correlation energy": 0.008524677369855, - "lCCD correlation energy": -0.008082420815100, - "pCCD correlation energy": -0.014985062519068, - "RCIS singlet excitation energy": 1.911193619935257, - "RCIS triplet excitation energy": 1.455852629402236, - "phRRPA correlation energy": -0.018845374129105, - "phRRPAx correlation energy": -0.015760565121283, - "crRRPA correlation energy": -0.008868581132405, - "ppRRPA correlation energy": -0.008082420815100, - "RG0F2 correlation energy": -0.011438430540374, - "RG0F2 HOMO energy": -0.882696116247871, - "RG0F2 LUMO energy": 1.383080391811630, - "evRGF2 correlation energy": -0.011448483158486, - "evRGF2 HOMO energy": -0.881327878713477, - "evRGF2 LUMO energy": 1.382458968133448, - "RG0W0 correlation energy": -0.019314094399756, - "RG0W0 HOMO energy": -0.870533880190454, - "RG0W0 LUMO energy": 1.377171287010956, - "evRGW correlation energy": -0.019335511771724, - "evRGW HOMO energy": -0.868460640957913, - "evRGW LUMO energy": 1.376287581471769, - "RG0T0pp correlation energy": -0.008082420815100, - "RG0T0pp HOMO energy": -0.914126628614305, - "RG0T0pp LUMO energy": 1.399859335225087, - "evRGTpp correlation energy": -0.008082420815100, - "evRGTpp HOMO energy": -0.914126628614305, - "evRGTpp LUMO energy": 1.399859335225087 + "RHF energy": -2.855160426154444, + "RHF HOMO energy": -0.914126628640145, + "RHF LUMO energy": 1.399859335255765, + "RHF dipole moment": 0.0, + "MP2 correlation energy": -0.011200122909934, + "CCD correlation energy": -0.014985063116, + "CCSD correlation energy": -0.015001711549092, + "drCCD correlation energy": -0.01884537385338, + "rCCD correlation energy": -0.016836322809386, + "crCCD correlation energy": 0.008524676641474, + "lCCD correlation energy": -0.00808242082105, + "CIS singlet excitation energy": 1.911193619991987, + "CIS triplet excitation energy": 1.455852629458543, + "phRPA correlation energy": -0.018845374128748, + "phRPAx correlation energy": -0.015760565120758, + "crRPA correlation energy": -0.008868581132249, + "ppRPA correlation energy": -0.008082420814972, + "G0F2 correlation energy": -0.011438430540104, + "G0F2 HOMO energy": -0.882696116274599, + "G0F2 LUMO energy": 1.383080391842522, + "G0W0 correlation energy": -0.019314094399372, + "G0W0 HOMO energy": -0.87053388021722, + "G0W0 LUMO energy": 1.377171287041735, + "evGW correlation energy": -0.019335511771337, + "evGW HOMO energy": -0.868460640984803, + "evGW LUMO energy": 1.376287581502582, + "G0T0pp correlation energy": -0.008161908540634, + "G0T0pp HOMO energy": -0.898869172597701, + "G0T0pp LUMO energy": 1.383928087417952, } }, "properties_uhf":{ @@ -58,8 +50,51 @@ He = Molecule( "6-31g": { } }, - "properties_rohf":{ - "6-31g": { + } +) + +# --- + +H2O = Molecule( + name="H2O", + multiplicity=1, + geometry=[ + {"element": "O", "x": 0.0000, "y": 0.0000, "z": 0.0000}, + {"element": "H", "x": 0.7571, "y": 0.0000, "z": 0.5861}, + {"element": "H", "x": -0.7571, "y": 0.0000, "z": 0.5861} + ], + properties={ + "properties_rhf":{ + "cc-pvdz": { + "RHF energy": -85.21935817501823, + "RHF HOMO energy": -0.493132793449897, + "RHF LUMO energy": 0.185534869842355, + "RHF dipole moment": 0.233813698748474, + "MP2 correlation energy": -0.203978216774657, + "CCD correlation energy": -0.212571260121257, + "CCSD correlation energy": -0.213302190845899, + "drCCD correlation energy": -0.231281853419338, + "rCCD correlation energy": -0.277238348710547, + "crCCD correlation energy": 0.18014617422324, + "lCCD correlation energy": -0.15128653432796, + "CIS singlet excitation energy": 0.338828950934568, + "CIS triplet excitation energy": 0.304873339484139, + "phRPA correlation energy": -0.231281866582435, + "phRPAx correlation energy": -0.310796738307943, + "crRPA correlation energy": -0.246289801609294, + "ppRPA correlation energy": -0.151286536255888, + "G0F2 correlation energy": -0.217807591229668, + "G0F2 HOMO energy": -0.404541451101377, + "G0F2 LUMO energy": 0.16650398400197, + "G0W0 correlation energy": -0.23853664665404, + "G0W0 HOMO energy": -0.446828623007469, + "G0W0 LUMO energy": 0.173026609033024, + "evGW correlation energy": -0.239414217281308, + "evGW HOMO energy": -0.443076613314424, + "evGW LUMO energy": 0.172691758111392, + "G0T0pp correlation energy": -0.156214864467344, + "G0T0pp HOMO energy": -0.452117482732615, + "G0T0pp LUMO energy": 0.16679206983464, } } } @@ -67,24 +102,9 @@ He = Molecule( # --- -#H2O = Molecule( -# name="H2O", -# multiplicity=1, -# geometry=[ -# {"element": "O", "x": 0.0000, "y": 0.0000, "z": 0.0000}, -# {"element": "H", "x": 0.7571, "y": 0.0000, "z": 0.5861}, -# {"element": "H", "x": -0.7571, "y": 0.0000, "z": 0.5861} -# ], -# properties={ -# "cc-pvdz": { -# } -#) - -# --- - FeatherBench = [ He, - #H2O + H2O ] diff --git a/tests/inp/methods.RHF b/tests/inp/methods.RHF index e315154..2ddb2bb 100644 --- a/tests/inp/methods.RHF +++ b/tests/inp/methods.RHF @@ -3,7 +3,7 @@ # MP2 MP3 T T # CCD pCCD DCD CCSD CCSD(T) - T T T T F + T F F T F # drCCD rCCD crCCD lCCD T T T T # CIS CIS(D) CID CISD FCI @@ -11,11 +11,11 @@ # phRPA phRPAx crRPA ppRPA T T T T # G0F2 evGF2 qsGF2 ufGF2 G0F3 evGF3 - T T F F F F + T F F F F F # G0W0 evGW qsGW SRG-qsGW ufG0W0 ufGW T T F F F F # G0T0pp evGTpp qsGTpp ufG0T0pp - T T F F + T F F F # G0T0eh evGTeh qsGTeh F F F # Rtest Utest Gtest diff --git a/tests/lunch_bench.py b/tests/lunch_bench.py index 69a6093..f9e52d7 100644 --- a/tests/lunch_bench.py +++ b/tests/lunch_bench.py @@ -181,7 +181,7 @@ class Quack_Job: if(diff <= THRESH): print_col(f" 🙂 {key}: ✔ī¸ ", "green") else: - print_col(f" ☚ī¸ {key}: ❌ {data_ref[key]} ≠ {data_new[key]}", "red") + print_col(f" ☚ī¸ {key}: ❌ {data_ref[key]} ≠ {data_new[key]}", "red") except FileNotFoundError: print_col(f"Error: The file '{filepath}' does not exist.", "red") sys.exist(1) diff --git a/tests/molecule.py b/tests/molecule.py index 147c53e..b5f33eb 100644 --- a/tests/molecule.py +++ b/tests/molecule.py @@ -1,7 +1,11 @@ +import os import json import sqlite3 +from utils import print_col + + class Molecule: def __init__(self, name, multiplicity, geometry, properties): self.name = name @@ -38,23 +42,64 @@ def load_molecules_from_json(filename): def create_database(db_name): - conn = sqlite3.connect(db_name) - cursor = conn.cursor() - cursor.execute('''CREATE TABLE IF NOT EXISTS molecules - (name TEXT, multiplicity INTEGER, geometry TEXT, properties TEXT)''') - conn.commit() - conn.close() + if os.path.exists(db_name): + conn = sqlite3.connect(db_name) + cursor = conn.cursor() + # Check if the table already exists + cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='molecules';") + table_exists = cursor.fetchone() + + if table_exists: + print_col(f"Database '{db_name}' already exists and table 'molecules' is already created.", "yellow") + else: + # Create the table if it does not exist + cursor.execute('''CREATE TABLE molecules + (name TEXT, multiplicity INTEGER, geometry TEXT, properties TEXT)''') + conn.commit() + print_col(f"Table 'molecules' created in existing database '{db_name}' successfully.", "green") + conn.close() + else: + # Create the database and table + conn = sqlite3.connect(db_name) + cursor = conn.cursor() + cursor.execute('''CREATE TABLE molecules + (name TEXT, multiplicity INTEGER, geometry TEXT, properties TEXT)''') + conn.commit() + conn.close() + print_col(f"Database '{db_name}' created and table 'molecules' added successfully.", "green") def add_molecule_to_db(db_name, molecule): + conn = sqlite3.connect(db_name) cursor = conn.cursor() + + # Convert geometry and properties to JSON strings geometry_str = json.dumps(molecule.geometry) energies_str = json.dumps(molecule.properties) - cursor.execute("INSERT INTO molecules VALUES (?, ?, ?, ?)", - (molecule.name, molecule.multiplicity, geometry_str, energies_str)) - conn.commit() + + # Check if the molecule already exists + cursor.execute("SELECT COUNT(*) FROM molecules WHERE name = ?", (molecule.name,)) + count = cursor.fetchone()[0] + + if count > 0: + print_col(f"Molecule '{molecule.name}' already exists in {db_name}.", "yellow") + else: + # Insert the molecule if it does not exist + cursor.execute("INSERT INTO molecules (name, multiplicity, geometry, properties) VALUES (?, ?, ?, ?)", + (molecule.name, molecule.multiplicity, geometry_str, energies_str)) + conn.commit() + print_col(f"'{molecule.name}' added to {db_name} successfully.", "green") + conn.close() + +def remove_database(db_name): + if os.path.exists(db_name): + os.remove(db_name) + print_col(f"Database '{db_name}' removed successfully.", "red") + else: + print_col(f"Database '{db_name}' does not exist.", "red") + def get_molecules_from_db(db_name): conn = sqlite3.connect(db_name) cursor = conn.cursor() From a44839e67d20797bdda66e7dc8d147082fdc69d3 Mon Sep 17 00:00:00 2001 From: AbdAmmar Date: Fri, 30 Aug 2024 20:38:00 +0200 Subject: [PATCH 10/11] absolute path for bench --- tests/lunch_bench.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/lunch_bench.py b/tests/lunch_bench.py index f9e52d7..be543b5 100644 --- a/tests/lunch_bench.py +++ b/tests/lunch_bench.py @@ -60,7 +60,7 @@ parser.add_argument( parser.add_argument( '-t', '--thresh', type=float, - default=1e-8, + default=1e-7, help='Threshold for acceptable difference (default: 1e-8)' ) @@ -101,13 +101,14 @@ class Quack_Job: def prep_inp(self): # geometry - generate_xyz(self.geom, filename="{}.xyz".format(self.mol)) + generate_xyz(self.geom, filename="{}/mol/{}.xyz".format(quack_root, self.mol)) # input files for inp in ["methods", "options"]: inp_file = "{}.{}".format(inp, self.methd.upper()) if os.path.exists("inp/{}".format(inp_file)): - shutil.copy("inp/{}".format(inp_file), "../mol/{}".format(inp_file)) + shutil.copy("{}/tests/inp/{}".format(quack_root, inp_file), + "{}/input/{}".format(quack_root, inp)) else: print_col("File 'inp/{}' does not exist.".format(inp_file), "red") sys.exit(1) @@ -184,10 +185,10 @@ class Quack_Job: print_col(f" ☚ī¸ {key}: ❌ {data_ref[key]} ≠ {data_new[key]}", "red") except FileNotFoundError: print_col(f"Error: The file '{filepath}' does not exist.", "red") - sys.exist(1) + sys.exit(1) except Exception as e: print_col(f"An error occurred: {str(e)}", "red") - sys.exist(1) + sys.exit(1) # --- From 294ff753ac68f9d57eee4f567ae369ffed60dd0e Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Sat, 31 Aug 2024 13:30:34 +0200 Subject: [PATCH 11/11] few modifs --- src/utils/non_sym_diag.f90 | 4 ++-- tests/lunch_bench.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/non_sym_diag.f90 b/src/utils/non_sym_diag.f90 index 04279ac..0f44099 100644 --- a/src/utils/non_sym_diag.f90 +++ b/src/utils/non_sym_diag.f90 @@ -3,7 +3,7 @@ subroutine diagonalize_nonsym_matrix(N, A, L, e_re, thr_d, thr_nd, thr_deg, imp_bio, verbose) - ! Diagonalize a non-symmetric matrix + ! Diagonalize a non-symmetric matrix A ! ! Output ! right-eigenvectors are saved in A @@ -278,7 +278,7 @@ subroutine check_biorthog_binormalize(n, m, Vl, Vr, thr_d, thr_nd, stop_ifnot) do i = 1, m if(S(i,i) <= 0.d0) then - print *, ' overap negative' + print *, ' negative overlap !' print *, i, S(i,i) exit endif diff --git a/tests/lunch_bench.py b/tests/lunch_bench.py index be543b5..02d6db5 100644 --- a/tests/lunch_bench.py +++ b/tests/lunch_bench.py @@ -123,7 +123,7 @@ class Quack_Job: sys.stdout.flush() idx = (idx + 1) % len(spinner) time.sleep(0.05) - stdout_col(f'\r Testing {self.methd} ({self.basis}) \n', "cyan") + stdout_col(f'\r Testing {self.methd} ({self.basis}) \n\n', "cyan") done_event = threading.Event() spinner_thread = threading.Thread(target=display_spinner) @@ -180,7 +180,7 @@ class Quack_Job: else: diff = abs(data_new[key] - data_ref[key]) / (1e-15 + abs(data_ref[key])) if(diff <= THRESH): - print_col(f" 🙂 {key}: ✔ī¸ ", "green") + print_col(f" 🙂 {key}", "green") else: print_col(f" ☚ī¸ {key}: ❌ {data_ref[key]} ≠ {data_new[key]}", "red") except FileNotFoundError: