def test_scramble_identity(): mill = qcel.molutil.compute_scramble(4, do_resort=False, do_shift=False, do_rotate=False, deflection=1.0, do_mirror=False) mill_str = """---------------------------------------- AlignmentMill eye ---------------------------------------- Mirror: False Atom Map: [0 1 2 3] Shift: [0. 0. 0.] Rotation: [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] ----------------------------------------""" assert compare(mill_str, mill.pretty_print(label="eye")) mill_dict = { "shift": [0.0, 0.0, 0.0], "rotation": [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]], "atommap": [0, 1, 2, 3], "mirror": False, } assert compare_recursive(mill_dict, mill.dict()) mill_dict["rotation"] = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] assert compare_recursive(mill_dict, mill.dict(encoding="json"))
def test_scramble_identity(): mill = qcel.molutil.compute_scramble(4, do_resort=False, do_shift=False, do_rotate=False, deflection=1.0, do_mirror=False) mill_str = """---------------------------------------- AlignmentMill eye ---------------------------------------- Mirror: False Atom Map: [0 1 2 3] Shift: [0. 0. 0.] Rotation: [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] ----------------------------------------""" assert compare(mill_str, mill.__str__(label='eye')) mill_dict = { 'shift': [0., 0., 0.], 'rotation': [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], 'atommap': [0, 1, 2, 3], 'mirror': False } assert compare_recursive(mill_dict, mill.dict()) mill_dict['rotation'] = [1., 0., 0., 0., 1., 0., 0., 0., 1.] assert compare_recursive(mill_dict, mill.dict(encoding="json"))
def test_dftd3__from_arrays(inp, expected): res = empirical_dispersion_resources.from_arrays(**inp[0]) assert compare_recursive(expected, res, atol=1.e-4) assert compare(inp[1], _compute_key(res), 'key') res = empirical_dispersion_resources.from_arrays(name_hint=res['fctldash'], level_hint=res['dashlevel'], param_tweaks=res['dashparams']) assert compare_recursive(expected, res, tnm() + ' idempotent', atol=1.e-4)
def test_b1_computeBE(b1_water): EnergyThre = 1e-6 BE_blyp = b1_water.computeBE("blyp") expected = 0.33100268529368293 assert compare_recursive(BE_blyp, expected, atol=EnergyThre) BE_b1lyp = b1_water.computeBE("b1lyp") expected = 0.3183329645632256 assert compare_recursive(BE_b1lyp, expected, atol=EnergyThre)
def test_formula_to_elements(): assert compare_recursive(formula_to_elements("C2H6O"), { "C": 2, "H": 6, "O": 1 }) assert compare_recursive(formula_to_elements("C2H6OOO"), { "C": 2, "H": 6, "O": 3 })
def test_diagnostic_factory_B1(qcelemental_water): calculator = MultirefPredict.diagnostic_factory("B1", molecule=qcelemental_water) diag = calculator.computeDiagnostic() B1Thre = 1e-6 expected = 0.006334860365228678 assert compare_recursive(diag, expected, atol=B1Thre)
def test_diagnostic_factory_A25PBE(qcelemental_water): calculator = MultirefPredict.diagnostic_factory("A25PBE", molecule=qcelemental_water) diag = calculator.computeDiagnostic() A25PBEThre = 1e-6 expected = 0.1626572016077259 assert compare_recursive(diag, expected, atol=A25PBEThre)
def test_diagnostic_factory_TAE(qcelemental_water): calculator = MultirefPredict.diagnostic_factory("TAE", molecule=qcelemental_water) diag = calculator.computeDiagnostic() TAEThre = 1e-6 expected = 0.28078682517214126 assert compare_recursive(diag, expected, atol=TAEThre)
def test_qchem_logfile_parser(test_case): # Get output file data data = qchem_logonly_info.get_test_data(test_case) outfiles = {"dispatch.out": data["qchem.out"]} with pytest.warns(Warning): output = qcng.get_program("qchem", check=False).parse_logfile(outfiles).dict() output["stdout"] = None output_ref = qcel.models.AtomicResult.parse_raw(data["output.json"]).dict() for key in list(output["provenance"].keys()): if key not in output_ref["provenance"]: output["provenance"].pop(key) # Modify ref to trim down total data as a molecule is now sparse output_ref["molecule"] = { k: v for k, v in output_ref["molecule"].items() if k in output["molecule"] } check, message = compare_recursive(output_ref, output, return_message=True, forgive=qchem_forgive) assert check, message
def test_qchem_logfile_parser_qcscr(test_case): # Get output file data data = qchem_info.get_test_data(test_case) outfiles = qcel.util.deserialize(data["outfiles.msgpack"], "msgpack-ext") with pytest.warns(Warning): output = qcng.get_program("qchem", check=False).parse_logfile(outfiles).dict() output["stdout"] = None output_ref = qcel.models.AtomicResult.parse_raw(data["output.json"]).dict() for key in list(output["provenance"].keys()): if key not in output_ref["provenance"]: output["provenance"].pop(key) output_ref["stdout"] = None # Modify ref to trim down total data as a molecule is now sparse output_ref["molecule"] = { k: v for k, v in output_ref["molecule"].items() if k in output["molecule"] } output_ref["model"]["method"] = output_ref["model"]["method"].lower() check, message = compare_recursive(output_ref, output, return_message=True, forgive=qchem_forgive) assert check, message
def test_fon_task(fon_trityl_radical, trityl_radical_task): with pytest.raises(ValueError): fon_task = fon_trityl_radical.FonTask(fon_trityl_radical.molecule, "psi4", "PBE") fon_task = fon_trityl_radical.FonTask(fon_trityl_radical.molecule,"terachem","PBE") Thre = 1e-6 assert compare_recursive(fon_task.dict()['keywords'], trityl_radical_task.dict()['keywords'], atol=Thre)
def test_qchem_logfile_parser_qcscr(test_case): # Get output file data data = qchem_info.get_test_data(test_case) outfiles = qcel.util.deserialize(data["outfiles.msgpack"], "msgpack-ext") with pytest.warns(Warning): output = qcng.get_program("qchem", check=False).parse_logfile(outfiles).dict() output["stdout"] = None output_ref = qcel.models.AtomicResult.parse_raw(data["output.json"]).dict() for key in list(output["provenance"].keys()): if key not in output_ref["provenance"]: output["provenance"].pop(key) output_ref["stdout"] = None # compare_recursive.forgive can be used once QCEL#174 is released output["molecule"].pop("connectivity") output_ref["molecule"].pop("connectivity") output_ref["model"]["method"] = output_ref["model"]["method"].lower() check, message = compare_recursive( output_ref, output, return_message=True, forgive=[ "root.molecule.provenance.version", "root.provenance.version", "root.provenance.routine" ], ) assert check, message
def test_fon_computeDiagnostic(fon_cu_complex): Thre = 1e-2 diag = fon_cu_complex.computeDiagnostic() expected = {'FOD': 0.980722, 'Mattito':{ 'I_D': 0.473731315028, 'I_ND': 0.431365088635}, 'Entanglement': 0.732773215873} print(diag) assert compare_recursive(diag, expected, atol=Thre)
def test_fon_b3lyp(fon_trityl_radical): Thre = 1e-2 diag2 = fon_trityl_radical.computeDiagnostic("b3lyp") expected2 = {'FOD': 0.7340689999999996, 'Mattito': {'I_D': 0.7479020997602953, 'I_ND': 0.33741997473349994}, 'Entanglement': -1} print(diag2) assert compare_recursive(diag2, expected2, atol=Thre)
def test_fon_unrestricted(fon_trityl_radical): Thre = 1e-2 diag = fon_trityl_radical.computeDiagnostic() expected = {'FOD': 0.34399500000000005, 'Mattito': {'I_D': 0.39268800205639215, 'I_ND': 0.16333423895850002}, 'Entanglement': -1} print(diag) assert compare_recursive(diag, expected, atol=Thre)
def test_terachem_output_parser(test_case): # Get output file data data = terachem_info.get_test_data(test_case) inp = qcel.models.ResultInput.parse_raw(data["input.json"]) output = qcng.get_program('terachem', check=False).parse_output(data, inp) output_ref = qcel.models.Result.parse_raw(data["output.json"]) assert compare_recursive(output_ref.dict(), output.dict())
def test_terachem_output_parser(test_case): # Get output file data data = terachem_info.get_test_data(test_case) inp = qcel.models.AtomicInput.parse_raw(data["input.json"]) output = qcng.get_program("terachem", check=False).parse_output(data, inp).dict() output_ref = qcel.models.AtomicResult.parse_raw(data["output.json"]).dict() # Forgiving molecule since it is now sparse assert compare_recursive(output_ref, output, forgive={"stdout", "provenance", "molecule"})
def test_complex_array(): datum1 = qcel.Datum('complex array', '', np.arange(3, dtype=np.complex_) + 1j) ans = { 'label': 'complex array', 'units': '', 'data': [complex(0, 1), complex(1, 1), complex(2, 1)], 'numeric': True } dicary = datum1.dict() assert compare_recursive(ans, dicary, 9)
def test_cc_computeDiagnostic(cc_water): Thre = 1e-6 diag = cc_water.computeDiagnostic() expected = { 'T1': 0.005903453140867589, 'D1': 0.012965638464472996, 'D2': 0.12885433260716933, 'New D1': 0.012965638464472996 } print(diag) assert compare_recursive(diag, expected, atol=Thre)
def test_to_dict(dataset): listans = [i * 4 / 3 for i in range(4)] ans = { 'label': 'an array', 'units': 'cm^-1', 'data': listans, 'comment': 'freqs' } dicary = dataset['ndarray'].dict() assert compare_recursive(ans, dicary, 9)
def test_complex_scalar(): datum1 = qcel.Datum('complex scalar', '', complex(1, 2)) ans = {'label': 'complex scalar', 'units': '', 'data': complex(1, 2)} assert datum1.label == 'complex scalar' assert datum1.units == '' assert datum1.data.real == 1 assert datum1.data.imag == 2 dicary = datum1.dict() assert compare_recursive(ans, dicary, 9)
def test_complex_array(): datum1 = qcel.Datum('complex array', '', np.arange(3, dtype=np.complex_) + 1j) ans = { 'label': 'complex array', 'units': '', 'data': [[0.0, 1.0, 2.0], [1.0, 1.0, 1.0]] } dicary = datum1.to_dict() assert compare_recursive(ans, dicary, 9)
def test_to_dict(dataset): listans = [i * 4 / 3 for i in range(4)] ans = { "label": "an array", "units": "cm^-1", "data": listans, "comment": "freqs", "numeric": True } dicary = dataset["ndarray"].dict() assert compare_recursive(ans, dicary, 9)
def test_dftd3__from_arrays__supplement(): ans = { 'dashlevel': 'chg', 'dashparams': { 's6': 4.05 }, 'fctldash': 'asdf-d4', 'dashparams_citation': ' mypaper\n' } supp = {'chg': {'definitions': {'asdf-d4': {'params': {'s6': 4.05}, 'citation': ' mypaper\n'}}}} res = dftd3.from_arrays(name_hint='asdf-d4', level_hint='chg', dashcoeff_supplement=supp) assert compare_recursive(ans, res, atol=1.e-4) with pytest.raises(ValueError) as e: dftd3.from_arrays(name_hint=res['fctldash'], level_hint=res['dashlevel'], param_tweaks=res['dashparams']) assert "Can't guess -D correction level" in str(e) res = dftd3.from_arrays( name_hint=res['fctldash'], level_hint=res['dashlevel'], param_tweaks=res['dashparams'], dashcoeff_supplement=supp) assert compare_recursive(ans, res, tnm() + ' idempotent', atol=1.e-4)
def test_diagnostic_factory_D2(qcelemental_water): Thre = 1e-6 calculator = MultirefPredict.diagnostic_factory("D2", molecule=qcelemental_water) diag = calculator.computeDiagnostic() expected = { 'T1': 0.005903453140867589, 'D1': 0.012965638464472996, 'D2': 0.12885433260716933, 'New D1': 0.012965638464472996 } print(diag) assert compare_recursive(diag, expected, atol=Thre)
def test_complex_array(): datum1 = qcel.Datum("complex array", "", np.arange(3, dtype=np.complex_) + 1j) ans = { "label": "complex array", "units": "", "data": [complex(0, 1), complex(1, 1), complex(2, 1)], "numeric": True, } dicary = datum1.dict() assert compare_recursive(ans, dicary, 9)
def test_entos_output_parser(test_case): # Get output file data data = entos_info.get_test_data(test_case) inp = qcel.models.AtomicInput.parse_raw(data["input.json"]) output = qcng.get_program("entos", check=False).parse_output(data, inp).dict() output.pop("provenance", None) output_ref = qcel.models.AtomicResult.parse_raw(data["output.json"]).dict() output_ref.pop("provenance", None) check = compare_recursive(output_ref, output) assert check, (output, output_ref)
def test_qchem_executor(test_case): # Get input file data data = qchem_info.get_test_data(test_case) inp = qcel.models.AtomicInput.parse_raw(data["input.json"]) # Run qchem result = qcng.compute(inp, "qchem") assert result.success is True # Get output file data output_ref = qcel.models.AtomicResult.parse_raw(data["output.json"]) atol = 1e-6 assert compare_recursive(output_ref.return_result, result.return_result, atol=atol)
def test_qchem_output_parser(test_case): # Get output file data data = qchem_info.get_test_data(test_case) inp = qcel.models.AtomicInput.parse_raw(data["input.json"]) outfiles = qcel.util.deserialize(data["outfiles.msgpack"], "msgpack-ext") output = qcng.get_program("qchem", check=False).parse_output(outfiles, inp).dict() output.pop("provenance", None) output_ref = qcel.models.AtomicResult.parse_raw(data["output.json"]).dict() output_ref.pop("provenance", None) check, message = compare_recursive(output_ref, output, return_message=True) assert check, message
def test_molpro_output_parser(test_case): # Get output file data data = molpro_info.get_test_data(test_case) inp = qcel.models.ResultInput.parse_raw(data["input.json"]) output = qcng.get_program('molpro').parse_output(data, inp).dict() output.pop("provenance", None) output_ref = qcel.models.Result.parse_raw(data["output.json"]).dict() output_ref.pop("provenance", None) # TODO add `skip` to compare_recusive check = compare_recursive(output_ref, output) assert check, check
def test_dftd3__from_arrays(inp, expected): res = dftd3.from_arrays(**inp[0]) assert compare_recursive(expected, res, atol=1.e-4) assert compare(inp[1], _compute_key(res), 'key') res = dftd3.from_arrays(name_hint=res['fctldash'], level_hint=res['dashlevel'], param_tweaks=res['dashparams']) assert compare_recursive(expected, res, tnm() + ' idempotent', atol=1.e-4)