def test_sp_mp2_rohf_fc_error(mtd, opts, errmsg, nh2): """cfour/???/input.dat #! single point MP2/qz2p on water """ nh2 = qcdb.set_molecule(nh2) qcdb.set_options(opts) with pytest.raises(qcng.exceptions.InputError) as e: qcdb.gradient(mtd, molecule=nh2) assert errmsg in str(e.value)
def test_4b(): system1() scf_dtz, jrec = qcdb.gradient('c4-HF/cc-pV[23]Z', return_wfn=True) assert compare_arrays(ref_scf_dtz, scf_dtz, 6, "[4] SCF/cc-pV[DT]Z Gradient, dertype=1") pp.pprint(jrec)
def test_grad(): h2o = qcdb.set_molecule( """ O 0.00000000 0.00000000 0.00000000 H 0.00000000 1.93042809 -1.10715266 H 0.00000000 -1.93042809 -1.10715266 units au""" ) qcdb.set_options( { "basis": "sto-3g", "scf__e_convergence": 1e-6, #'nwchem_driver__tight': True } ) val = qcdb.gradient("nwc-scf") scf = -74.888142460799 grads = np.array( [[0.000000, 0.000000, 0.058550], [0.000000, 0.140065, -0.029275], [0.000000, -0.140065, -0.029275]] ) assert compare_values(scf, qcdb.variable("HF TOTAL ENERGY"), 5, "scf") assert compare_arrays(grads, qcdb.variable("CURRENT GRADIENT"), 5, "scf grad")
def test_1_eom_ccsd_grad(): h2o = qcdb.set_molecule(""" O 0.000000000000 0.000000000000 -0.123909374404 H 0.000000000000 1.429936611037 0.983265845431 H 0.000000000000 -1.429936611037 0.983265845431 symmetry c1 units au """) qcdb.set_options({ "basis": "sto-3g", "memory": "1500 mb", "nwchem_scf__rhf": True, "scf__e_convergence": 1.0e-10, "nwchem_scf__tol2e": 1.0e-10, "nwchem_scf__thresh": 1.0e-10, "nwchem_scf__singlet": True, "qc_module": "TCE", "nwchem_tce__ccsd": True, "nwchem_tce__nroots": 1, }) print("Testing EOM-CCSD grad...") val = qcdb.gradient("nwc-eom-ccsd") check_eom_ccsd_grad(val)
def test_1e(): system2() scf_dz, jrec = qcdb.gradient("c4-SCF/cc-pVDZ", return_wfn=True) assert compare_arrays(ref_scf_dz_y, scf_dz, 6, "[1e] SCF/cc-pVDZ Gradient") assert compare_arrays(ref_scf_dz_y, jrec["qcvars"]["CURRENT GRADIENT"].data, 6, "[1e] SCF/cc-pVDZ Gradient") assert compare_arrays(ref_scf_dz_y, qcdb.variable("CURRENT GRADIENT"), 6, "[1e] SCF/cc-pVDZ Gradient") # assert compare_arrays(ref_scf_dz_y, jrec['qcvars']['HF/CC-PVDZ TOTAL GRADIENT'].data, 6, "[1e] SCF/cc-pVDZ Gradient") assert "CFOUR" == jrec["provenance"]["creator"], "[1e] prov"
def test_1i(): system3() scf_dz, jrec = qcdb.gradient("gms-SCF/cc-pVDZ", return_wfn=True) assert compare_arrays(ref2_scf_dz, scf_dz, 6, "[1i] SCF/cc-pVDZ Gradient") assert compare_arrays(ref2_scf_dz, jrec["qcvars"]["CURRENT GRADIENT"].data, 6, "[1i] SCF/cc-pVDZ Gradient") assert compare_arrays(ref2_scf_dz, qcdb.variable("CURRENT GRADIENT"), 6, "[1i] SCF/cc-pVDZ Gradient") ##assert compare_arrays(ref_scf_dz, jrec['qcvars']['HF/CC-PVDZ TOTAL GRADIENT'].data, 6, "[1i] SCF/cc-pVDZ Gradient") assert "GAMESS" == jrec["provenance"]["creator"], "[1i] prov"
def test_1g(): system3() scf_dz, jrec = qcdb.gradient("SCF/cc-pVDZ", return_wfn=True) assert compare_arrays(ref2_scf_dz, scf_dz, 6, "[1g] SCF/cc-pVDZ Gradient") assert compare_arrays(ref2_scf_dz, jrec["qcvars"]["CURRENT GRADIENT"].data, 6, "[1g] SCF/cc-pVDZ Gradient") assert compare_arrays(ref2_scf_dz, qcdb.variable("CURRENT GRADIENT"), 6, "[1g] SCF/cc-pVDZ Gradient") # assert compare_arrays(ref_scf_dz, jrec['qcvars']['HF/CC-PVDZ TOTAL GRADIENT'].data, 6, "[1g] SCF/cc-pVDZ Gradient") # assert ['QCDB', 'Psi4'] == [d['creator'] for d in jrec['provenance']], "[1g] prov" assert "Psi4" == jrec["provenance"]["creator"], "[1g] prov"
def test_1b(): system1() scf_dz, jrec = qcdb.gradient('c4-SCF/cc-pVDZ', return_wfn=True) assert compare_arrays(ref_scf_dz, scf_dz, 6, "[1b] SCF/cc-pVDZ Gradient") assert compare_arrays(ref_scf_dz, jrec['qcvars']['CURRENT GRADIENT'].data, 6, "[1b] SCF/cc-pVDZ Hessian") assert compare_arrays(ref_scf_dz, qcdb.get_variable('CURRENT GRADIENT'), 6, "[1b] SCF/cc-pVDZ Hessian") #assert compare_arrays(ref_scf_dz, jrec['qcvars']['HF/CC-PVDZ TOTAL GRADIENT'].data, 6, "[1b] SCF/cc-pVDZ Hessian") assert 'CFOUR' == jrec['provenance']['creator'], "[1b] prov"
def test_sp_mp2_rhf_fc(mtd, opts, h2o): """cfour/???/input.dat #! single point MP2/qz2p on water """ h2o = qcdb.set_molecule(h2o) qcdb.set_options(opts) g, jrec = qcdb.gradient(mtd, return_wfn=True, molecule=h2o) print(g) assert compare_arrays(rhf_mp2_fc, g, atol=1.0e-5)
def test_sp_mp2_rohf_ae(mtd, opts, nh2): """cfour/???/input.dat #! single point MP2/qz2p on water """ nh2 = qcdb.set_molecule(nh2) qcdb.set_options(opts) g, jrec = qcdb.gradient(mtd, return_wfn=True, molecule=nh2) print(g) assert compare_arrays(rohf_mp2_ae, g, atol=1.0e-5)
def test_sp_hf_uhf(mtd, opts, nh2): """cfour/???/input.dat #! single-point HF/qz2p on NH2 """ nh2 = qcdb.set_molecule(nh2) qcdb.set_options(opts) g, jrec = qcdb.gradient(mtd, return_wfn=True, molecule=nh2) print(g) assert compare_arrays(uhf_scf, g, atol=1.0e-5)
def test_1_hf(): qcdb.set_options({ 'basis': 'cc-pvdz', 'memory': '400 mb', 'nwchem_scf__rhf': True, 'scf__e_convergence': 1.0e-8, 'nwchem_scf__nopen': 0, #'nwchem_task_hf' : 'gradient' }) print('Testing hf...') val = qcdb.gradient('nwc-hf') check_hf(val) pprint.pprint(val)
def test_2_hf(): qcdb.set_options({ 'basis': 'cc-pvdz', 'memory': '400 mb', 'scf__e_convergence': 1.0e-4, 'nwchem_scf__rhf': True, #'nwchem_scf__thresh': 1.0e-4, 'nwchem_scf__nopen': 0, 'nwchem_mp2__tight': True, }) print('Testing hf...') val = qcdb.gradient('nwc-mp2') check_mp2(val, is_df=True, is5050=False)
def test_1_mp2(): qcdb.set_options({ 'basis': 'cc-pvdz', 'memory': '400 mb', 'nwchem_scf': 'rhf', 'nwchem_scf_thresh': 1.0e-4, 'nwchem_scf_nopen': 0, 'nwchem_mp2_tight': True, 'nwchem_task_mp2': 'gradient' }) print('Testing mp2 ...') val = qcdb.gradient('nwc-mp2') check_mp2_tot(val, is_df=True)
def test_sp_mp2_rhf_ae(mtd, opts, h2o): """cfour/???/input.dat #! single point MP2/qz2p on water """ h2o = qcdb.set_molecule(h2o) qcdb.set_options(opts) g, jrec = qcdb.gradient(mtd, return_wfn=True, molecule=h2o) #print(h2o.geometry()) #print(jrec['stdout']) #print(h2o.geometry()) print(g) assert compare_arrays(rhf_mp2_ae, g, atol=1.0e-3)
def test_1a(): system1() scf_dz, jrec = qcdb.gradient('SCF/cc-pVDZ', return_wfn=True) assert compare_arrays(ref_scf_dz, scf_dz, 6, "[1a] SCF/cc-pVDZ Gradient") assert compare_arrays(ref_scf_dz, jrec['qcvars']['CURRENT GRADIENT'].data, 6, "[1a] SCF/cc-pVDZ Hessian") assert compare_arrays(ref_scf_dz, qcdb.get_variable('CURRENT GRADIENT'), 6, "[1a] SCF/cc-pVDZ Hessian") #assert compare_arrays(ref_scf_dz, jrec['qcvars']['HF/CC-PVDZ TOTAL GRADIENT'].data, 6, "[1a] SCF/cc-pVDZ Hessian") # TODO provenance kill list assert ['QCDB', 'Psi4'] == [d['creator'] for d in jrec['provenance']], "[1a] prov" print(jrec['provenance'])
def test_1_ccsd_df(): qcdb.set_options({ 'basis': 'sto-3g', 'memory': '1500 mb', 'qc_module': 'tce', #'scf__e_convergence': 1.0e-10, 'nwchem_dft__rdft': True, #'nwchem_scf__thresh' : 1.0e-10, #'nwchem_scf__tol2e' : 1.0e-10, 'nwchem_tce__dft': True, 'nwchem_tce__ccsd': True, 'nwchem_tce__nroots': 1 }) print('Testing ccsd(dft)...') val = qcdb.gradient('nwc-ccsd') check_ccsd(val, is_df=True)
def test_2_ccsd_hf(): qcdb.set_options({ 'basis': 'sto-3g', 'memory': '1500 mb', 'qc_module': 'tce', #'scf__e_convergence': 1.0e-10, 'nwchem_scf__rhf': True, 'nwchem_scf__singlet': True, 'nwchem_scf__thresh': 1.0e-10, 'nwchem_scf__tol2e': 1.0e-10, 'nwchem_tce__scf': True, 'nwchem_tce__nroots': 1, 'nwchem_tce__ccsd': True }) print('Testing ccsd(hf)...') val = qcdb.gradient('nwc-ccsd') check_ccsd(val, is_df=False)
def test_2_hf(): h2o = qcdb.set_molecule(""" O 0.000000000000 0.000000000000 -0.065638538099 H 0.757480611647 0.000000000000 0.520865616174 H -0.757480611647 0.000000000000 0.520865616174 """) qcdb.set_options({ "basis": "cc-pvdz", "scf__e_convergence": 1.0e-4, "nwchem_scf__rhf": True, #'nwchem_scf__thresh': 1.0e-4, "nwchem_scf__nopen": 0, "nwchem_mp2__tight": True, }) print("Testing hf...") val = qcdb.gradient("nwc-mp2") check_mp2(val, is_df=True, is5050=False)
def test_1_hf(): h2o = qcdb.set_molecule(""" O 0.000000000000 0.000000000000 -0.065638538099 H 0.000000000000 -0.757480611647 0.520865616174 H 0.000000000000 0.757480611647 0.520865616174 """) qcdb.set_options({ "basis": "cc-pvdz", "nwchem_scf__rhf": True, "scf__e_convergence": 1.0e-8, "nwchem_scf__nopen": 0, #'nwchem_task_hf' : 'gradient' }) print("Testing hf...") val = qcdb.gradient("nwc-hf") check_hf(val) pprint.pprint(val)
def test_sp_rhf_ccsd(h2o): """cfour/sp-rhf-ccsd/input.dat #! single point CCSD/qz2p on water """ h2o = qcdb.set_molecule(h2o) qcdb.set_options({ #'cfour_CALC_level': 'CCSD', 'BASIS': 'cc-pvtz', 'nwchem_scf__thresh': 12, 'nwchem_ccsd__thresh': 12 }) e, jrec = qcdb.energy('nwc-ccsd', return_wfn=True, molecule=h2o) scftot = -76.057112730196 #qz2p -76.062748460117 mp2tot = -76.332242848821 #qz2p -76.332940127333 ccsdcorl = -0.280877944529 #qz2p -0.275705491773 ccsdtot = -76.337990674725 #qz2p-76.338453951890 tnm = sys._getframe().f_code.co_name assert compare_values(scftot, qcdb.get_variable('hf total energy'), 6, tnm + ' SCF') assert compare_values(mp2tot, qcdb.get_variable('mp2 total energy'), 6, tnm + ' MP2') assert compare_values(ccsdcorl, qcdb.get_variable('ccsd correlation energy'), 6, tnm + ' CCSD corl') assert compare_values(ccsdtot, qcdb.get_variable('ccsd total energy'), 6, tnm + ' CCSD') # gradient gives every appearence of working but array should be tested and reorientation to input tested e, jrec = qcdb.gradient('nwc-ccsd', return_wfn=True, molecule=h2o) assert compare_values(scftot, qcdb.get_variable('hf total energy'), 6, tnm + ' SCF') assert compare_values(mp2tot, qcdb.get_variable('mp2 total energy'), 6, tnm + ' MP2') assert compare_values(ccsdcorl, qcdb.get_variable('ccsd correlation energy'), 6, tnm + ' CCSD corl') assert compare_values(ccsdtot, qcdb.get_variable('ccsd total energy'), 6, tnm + ' CCSD')
def test_molsymm_calc(subject, qcprog): from .data_mints5 import mints5 ref_block = mints5[subject] expected = data[subject] abbr = {"cfour": "c4", "gamess": "gms", "nwchem": "nwc", "psi4": "p4"} symmol = qcdb.Molecule(data[subject]["mol"].format( isoA="")) # since no iso subjects yet. later: expected["A"] symmol.update_geometry() assert compare(expected["pg"], symmol.get_full_point_group(), "point group") assert compare(expected["rsn"], symmol.rotational_symmetry_number(), "sigma") units = "bohr" if expected.get("au", False) else "angstrom" refau = np.array(data[subject]["ref"]) * qcel.constants.conversion_factor( units, "bohr") assert compare_values(refau, symmol.full_geometry(), atol=1.0e-6) if subject == "Ih": if qcprog in ["cfour", "gamess"]: pytest.xfail("weird hang, probably atom permutations") elif qcprog == "nwchem": pytest.xfail("weird gradient rotation") elif subject == "SF6" and qcprog == "nwchem": pytest.xfail( "TODO new bug 'autosym bug : too many atoms:Received an Error in Communication' after fixed basis set for ghosts" ) extra_keywords = { "cfour": { "HOOH_dimer": { "cfour_scf_damping": 900 }, "TFCOT": { "cfour_scf_damping": 800 }, }, "gamess": { "HOOH_dimer": { "gamess_contrl__maxit": 60, "gamess_scf__conv": 1.0e-7 }, }, "nwchem": { "CN": { "nwchem_scf__thresh": 1.0e-8 }, "HOOH_dimer": { "nwchem_scf__nr": 0.0, "nwchem_scf__maxiter": 100, "nwchem_scf__thresh": 1.0e-6 }, }, "psi4": { "HOOH_dimer": { "psi4_soscf": True }, "Ih": { "psi4_guess": "gwh" }, }, } qcdb.set_options({ "scf_type": "conv", # longstanding "pk" "e_convergence": 9, "d_convergence": 9, "reference": "r{}hf".format("" if symmol.multiplicity() == 1 else "o"), }) qcdb.set_options(extra_keywords[qcprog].get(subject, {})) model = f"{abbr[qcprog]}-hf/cc-pvdz" grad, wfn = qcdb.gradient(model, return_wfn=True, molecule=symmol, local_options={"ncores": 2}) pprint.pprint(wfn, width=200) with np.printoptions(precision=3, suppress=True): # DEBUG pprint.pprint(ref_block) print("refau") print(refau) print("full_geometry") print(symmol.full_geometry(np_out=True)) print("wfn mol") print(wfn["molecule"]["geometry"]) print("frad") print(grad) dgrad = np.array2string(grad, separator=", ") print(dgrad) for i, item in enumerate([ symmol.nuclear_repulsion_energy(), wfn["qcvars"]["NUCLEAR REPULSION ENERGY"].data, wfn["extras"]["qcvars"]["NUCLEAR REPULSION ENERGY"], wfn["properties"]["nuclear_repulsion_energy"], ]): assert compare_values( ref_block["nre"], item, atol=1.0e-6, label="NRE"), f"NRE {i}: {item} != (ref) {ref_block['nre']}" for i, item in enumerate([ wfn["qcvars"]["HF TOTAL ENERGY"].data, wfn["qcvars"]["CURRENT ENERGY"].data, wfn["extras"]["qcvars"]["HF TOTAL ENERGY"], wfn["extras"]["qcvars"]["CURRENT ENERGY"], wfn["properties"]["return_energy"], wfn["properties"]["scf_total_energy"], ]): assert compare_values( ref_block["hf_total_energy"], item, atol=1.0e-6, label="ene" ), f"Energy {i}: {item} != (ref) {ref_block['hf_total_energy']}" assert compare(ref_block["elez"], wfn["molecule"]["atomic_numbers"], label="elez"), "elez" assert compare(ref_block["elea"], wfn["molecule"]["mass_numbers"], label="elea"), "elea" assert compare(False, wfn["molecule"]["fix_orientation"], label="frame"), "frame" for i, item in enumerate([ symmol.geometry(), wfn["molecule"]["geometry"], # qcdb.driver.driver_helpers.get_active_molecule().geometry(), ]): assert compare_values(np.array(ref_block["geom"]).reshape((-1, 3)), item, atol=1.0e-6, label="geom"), f"Geometry {i}" for i, item in enumerate([ grad, wfn["qcvars"]["HF TOTAL GRADIENT"].data, wfn["qcvars"]["CURRENT GRADIENT"].data, wfn["extras"]["qcvars"]["HF TOTAL GRADIENT"], wfn["extras"]["qcvars"]["CURRENT GRADIENT"], # wfn["properties"]["return_gradient"], np.array(wfn["properties"]["scf_total_gradient"]).reshape( (-1, 3)), # TODO shouldn't need to reshape ]): assert compare_values(np.array(ref_block["hf_total_gradient"]).reshape( (-1, 3)), item, atol=1.0e-6, label="grad"), f"Gradient {i}"
def test_6d(): system2() mp2_dtz = qcdb.gradient("c4-MP2/cc-pV[DT]Z") assert compare_arrays(ref_mp2_dtz_y, mp2_dtz, 6, "[6] MP2/cc-pV[DT]Z Gradient")
def test_6c(): system1() mp2_dtz = qcdb.gradient("gms-MP2/cc-pV[DT]Z") assert compare_arrays(ref_mp2_dtz, mp2_dtz, 6, "[6] MP2/cc-pV[DT]Z Gradient")
def test_5c(): system1() scf_dtqz = qcdb.gradient("gms-HF/cc-pV[DTQ]Z") assert compare_arrays(ref_scf_dtqz, scf_dtqz, 6, "[5] SCF/cc-pV[DTQ]Z Gradient")