def test_psz_main(): """Checks that the main function on the psithonyzer script returns the correct values for precomputed psithon outputs.""" root = os.getcwd() d = os.path.join(root, "crystalatte", "data", "out") os.chdir(d) results, crystal_lattice_energy = crystalatte.psz_main(2) a = [] a.append("2mer-0+1 | 0.87719178 | 6 | 2.63157535 | 2.63157535 | 1.748924e-03 | 2.588 ") a.append("3mer-0+1+2 | 0.03591565 | 3 | 0.03591565 | 2.66749100 | 6.255109e-07 | 2.428 2.588 2.588 ") a.append("3mer-0+1+5 | -0.10631085 | 3 | -0.10631085 | 2.56118015 | 6.255109e-07 | 2.588 2.588 2.588 ") a.append("4mer-0+1+2+3 | 0.00643113 | 1 | 0.00160778 | 2.56278793 | 9.355871e-12 | 2.428 2.428 2.428 2.588 2.588 2.588 ") a.append("5mer-0+1+2+3+4 | -0.00086359 | 3 | -0.00051816 | 2.56226977 | 4.005201e-25 | 2.428 2.428 2.428 2.588 2.588 2.588 2.588 2.588 3.945 5.012 ") assert compare(a[0], results[0]) assert compare(a[1], results[1]) assert compare(a[2], results[2]) assert compare(a[3], results[3]) assert compare(a[4], results[4]) assert compare_values(2.56226977, crystal_lattice_energy, atol=1.e-9) # Change directory back to root. os.chdir(root) # Clean-up generated test files. subprocess.call(["rm", "crystalatte/data/out/Ammonia.csv"])
def test_molsymm_alone(subject): pg = data[subject]["pg"] sigma = data[subject]["rsn"] if subject.startswith("iso"): isbohr = data[subject[3:]].get("au", False) molstr = data[subject[3:]]["mol"].format(isoA=data[subject]["A"]) refgeomang = None else: isbohr = data[subject].get("au", False) molstr = data[subject]["mol"].format(isoA="") refgeomang = data[subject]["ref"] symmol = qcdb.Molecule(molstr) symmol.update_geometry() # symmol.axis_representation() assert compare(pg, symmol.get_full_point_group(), pg + " point group: " + subject) assert compare(sigma, symmol.rotational_symmetry_number(), pg + " sigma") if isbohr: geom_now = symmol.full_geometry() else: geom_now = qcdb.util.vecutil.mscale(symmol.full_geometry(), qcel.constants.bohr2angstroms) if refgeomang: assert compare_values(refgeomang, geom_now, pg + " orientation", atol=1.0e-6)
def test_parse_nucleus_label(inp, expected): lbl_A, lbl_Z, lbl_E, lbl_mass, lbl_real, lbl_user = qcelemental.molparse.nucleus.parse_nucleus_label(inp) assert compare(expected["real"], lbl_real, inp + " real") assert compare(expected["A"], lbl_A, inp + " A") assert compare(expected["Z"], lbl_Z, inp + " Z") assert compare(expected["E"], lbl_E, inp + " symbol") assert compare(expected["user"], lbl_user, inp + " user") assert compare_values(expected["mass"], lbl_mass, inp + " mass", passnone=True, atol=1.0e-6)
def test_validate_and_fill_chgmult(inp, expected): system = _systemtranslator[inp[0]] kwargs = inp[5] if len(inp) > 5 else {} ans = qcelemental.molparse.validate_and_fill_chgmult(system[0], system[1], inp[1], inp[2], inp[3], inp[4], **kwargs) assert compare(1, ans == dict(zip(_keys, expected)), """{}: {}, {}, {}, {} --> {}""".format(*inp, expected))
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 _asserter(asserter_args, contractual_args, contractual_fn): """For expectations in `contractual_fn`, check that the QCVars are present in P::e.globals and wfn and match expected ref_block.""" qcvar_stores, ref_block, atol, ref_block_conv, atol_conv, tnm = asserter_args for obj in qcvar_stores: for rpv, pv, present in contractual_fn(*contractual_args): label = tnm + " " + pv if present: # verify exact match to method (may be df) and near match to conventional (non-df) method tf, errmsg = compare_values( ref_block[rpv], query_qcvar(obj, pv), label, atol=atol, return_message=True, quiet=True ) assert compare_values(ref_block[rpv], query_qcvar(obj, pv), label, atol=atol), errmsg tf, errmsg = compare_values( ref_block_conv[rpv], query_qcvar(obj, pv), label, atol=atol_conv, return_message=True, quiet=True, ) assert compare_values(ref_block_conv[rpv], query_qcvar(obj, pv), label, atol=atol_conv), errmsg # Note that the double compare_values lines are to collect the errmsg in the first for assertion in the second. # If the errmsg isn't present in the assert, the string isn't accessible through `e.value`. # If a plain bool is compared in the assert, the printed message will show booleans and not numbers. else: # verify and forgive known contract violations assert compare(False, query_has_qcvar(obj, pv), label + " SKIP")
def test_scramble_specific(): mill = qcel.molutil.compute_scramble( 4, do_resort=[1, 2, 0, 3], do_shift=[-1.82564537, 2.25391838, -2.56591963], do_rotate=[ [0.39078817, -0.9101616, -0.13744259], [0.36750838, 0.29117465, -0.88326379], [0.84393258, 0.29465774, 0.44827962], ], ) mill_str = """---------------------------------------- AlignmentMill ---------------------------------------- Mirror: False Atom Map: [1 2 0 3] Shift: [-1.82564537 2.25391838 -2.56591963] Rotation: [[ 0.39078817 -0.9101616 -0.13744259] [ 0.36750838 0.29117465 -0.88326379] [ 0.84393258 0.29465774 0.44827962]] ----------------------------------------""" assert compare(mill_str, mill.pretty_print())
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_atom_labels(qcprog, basis, keywords): kmol = qcel.models.Molecule.from_data(""" H 0 0 0 H5 5 0 0 H_other 0 5 0 H_4sq 5 5 0 units au """) assert compare(["H", "H", "H", "H"], kmol.symbols, "elem") assert compare(["", "5", "_other", "_4sq"], kmol.atom_labels, "elbl") atin = qcel.models.AtomicInput( **{ "molecule": kmol, "model": { "method": "mp2", "basis": basis }, "driver": "energy", "keywords": keywords }) atres = qcng.compute(atin, qcprog) pprint.pprint(atres.dict(), width=200) nre = 1.0828427 assert compare_values( nre, atres.properties.nuclear_repulsion_energy, atol=1.0e-4, label="nre" ), f"nre: {atres.properties.nuclear_repulsion_energy} != {nre}" nmo = 36 assert compare( nmo, atres.properties.calcinfo_nmo, label="nmo"), f"nmo: {atres.properties.calcinfo_nmo} != {nmo}" scf = -1.656138508 assert compare_values( scf, atres.properties.scf_total_energy, atol=3.0e-6, label="scf ene" ), f"scf ene: {atres.properties.scf_total_energy} != {scf}" mp2 = -1.7926264513 assert compare_values(mp2, atres.return_result, atol=3.0e-6, label="ene"), f"ene: {atres.return_result} != {mp2}"
def test_dibromobutRS_SR(): mol, data = dibromobutRS.align(dibromobutSR, do_plot=do_plot, verbose=verbose, uno_cutoff=uno_cutoff, run_mirror=True) assert compare_values(0.004, data['rmsd'], '2,3-dibromobutane SR, RS', atol=1.e-3) assert compare(True, data['mill'].mirror, '2,3-dibromobutane SR, RS identical')
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_dibromobutSS_RR(): mol, data = dibromobutSS.align(dibromobutRR, do_plot=do_plot, verbose=verbose, uno_cutoff=uno_cutoff, run_mirror=run_mirror) assert compare_values(1.296e-2, data['rmsd'], '2,3-dibromobutane RR, SS', atol=1.e-3) assert compare(True, data['mill'].mirror, '2,3-dibromobutane RR, SS enantiomers')
def test_clbrbutSR_vs_RS(): mol, data = clbrbutSR.align(clbrbutRS, do_plot=do_plot, verbose=verbose, uno_cutoff=uno_cutoff, run_mirror=run_mirror) assert compare_values(8.652e-3, data['rmsd'], '2-chloro-3-bromobutane RS, SR', atol=2.e-3) assert compare(True, data['mill'].mirror, '2-chloro-3-bromobutane RS, SR enantiomers')
def test_clbrbutSS(): mol, data = clbrbutSS.align(clbrbutRR, do_plot=do_plot, verbose=verbose, uno_cutoff=uno_cutoff, run_mirror=run_mirror) assert compare_values(5.411e-3, data['rmsd'], '2-chloro-3-bromobutane RR, SS', atol=1.e-3) assert compare(True, data['mill'].mirror, '2-chloro-3-bromobutane RR, SS enantiomers')
def test_input_parser(): """Test the input parser function of the CrystaLattE program.""" # Execute the main function of crystalatte and retrieve the N-mers dictionary. keywords = crystalatte.input_parser( "crystalatte/data/cle/input_parser.cle") # For debug. #import pprint #pprint.pprint(keywords) assert compare_values( 3, keywords['cif_a']) # Checks automatic choosing of odd a. assert compare_values(3, keywords['cif_b']) assert compare_values(3, keywords['cif_c']) assert compare_values(1.2, keywords['bfs_thresh']) assert compare_values(2, keywords['nmers_up_to']) assert compare_values(6.5, keywords['r_cut_com']) assert compare_values(2.6, keywords['r_cut_dimer']) assert compare_values(3.5, keywords['r_cut_monomer']) assert compare_values(6.1, keywords['r_cut_pentamer']) assert compare_values(3.7, keywords['r_cut_tetramer']) assert compare_values(3.7, keywords['r_cut_trimer']) assert compare_values(2, keywords['verbose']) assert compare("crystalatte/data/cif/Ammonia.cif", keywords['cif_input']) assert compare("crystalatte/data/Ammonia.xyz", keywords['cif_output']) assert compare(["test"], keywords['cle_run_type']) assert compare("ChSEV", keywords['uniq_filter']) assert compare("nocp", keywords['psi4_bsse']) assert compare("500 MB", keywords['psi4_memory']) assert compare('HF/STO-3G', keywords['psi4_method']) # Clean-up generated test files subprocess.call(["rm", "crystalatte/data/Ammonia.xyz"])
def test_dibromobutRS_SR_nomirror(): # Table satisfied by non-mirror identical, but 787 finds even better match mol, data = dibromobutRS.align(dibromobutSR, do_plot=do_plot, verbose=verbose, uno_cutoff=uno_cutoff, run_mirror=False) assert compare_values(4.534e-2, data['rmsd'], '2,3-dibromobutane SR, RS (force non-mirror)', atol=2.e-2) assert compare(False, data['mill'].mirror, '2,3-dibromobutane SR, RS identical (force non-mirror)')
def test_cle_write_xyz(): """"Checks that the function to write xyz files from given atomic coordinates, box size, and an output file name is able to correctly generate a new xyz file.""" atoms = [("C", 0.0000000, 0.0000000, 0.0000000), ("H", 0.6405128, -0.6405128, 0.6405128), ("H", 0.6405128, 0.6405128, -0.6405128), ("H", -0.6405128, 0.6405128, 0.6405128), ("H", -0.6405128, -0.6405128, -0.6405128)] box = (1.0, 1.0, 1.0) with open("sc.xyz", "w") as f: crystalatte.write_xyz(atoms, box, f) l0 = None l1 = None l2 = None l3 = None l4 = None l5 = None l6 = None with open("sc.xyz", "r") as xyz: for l in xyz: if "5" in l: l0 = True if "Crystal created from CIF file. Box size: 1.00000 1.00000 1.00000" in l: l1 = True if "C 0.000000 0.000000 0.000000" in l: l2 = True if "H 0.640513 -0.640513 0.640513" in l: l3 = True if "H 0.640513 0.640513 -0.640513" in l: l4 = True if "H -0.640513 0.640513 0.640513" in l: l5 = True if "H -0.640513 -0.640513 -0.640513" in l: l6 = True assert compare(True, l0) assert compare(True, l1) assert compare(True, l2) assert compare(True, l3) assert compare(True, l4) assert compare(True, l5) assert compare(True, l6) # Clean-up generated test files. subprocess.call(["rm", "sc.xyz"])
def test_psz_success_check(): """Checks that the psithonyzer success checker function retruns a True boolean value when it finds a Psi4's successful execution string.""" with open("beer.out", "w") as f: f.write("# This is a dummy Psi4 output test file.") f.write("Psi4 exiting successfully. Buy a developer a beer!") with open("coffee.out", "w") as f: f.write("Psi4 encountered an error. Buy a developer more coffee!") beer = crystalatte.psz_success_check("beer.out", 2) coffee = crystalatte.psz_success_check("coffee.out", 2) assert compare(True, beer) assert compare(False, coffee) # Clean-up generated test files. subprocess.call(["rm", "beer.out"]) subprocess.call(["rm", "coffee.out"])
def test_cle_cif_driver(): """Checks that the CIF driver produces a correct list of arguments to be passed to the main CIF converter function.""" ref = [ '', '-i', 'crystalatte/data/cif/Ammonia.cif', '-o', 'sc.xyz', '-b', '3', '3', '3', '-r' ] args = crystalatte.cif_driver("crystalatte/data/cif/Ammonia.cif", "sc.xyz", "3", "3", "3", 2) assert compare(ref, args)
def test_simpleS(): mol, data = simpleS.align(simpleR, do_plot=do_plot, verbose=verbose, uno_cutoff=uno_cutoff, run_mirror=run_mirror) assert compare_values(1.093e-4, data['rmsd'], 'bromochlorofluoromethane R, S', atol=1.e-4) assert compare(True, data['mill'].mirror, 'bromochlorofluoromethane R, S enantiomers')
def test_input_parser(): """ .""" # Execute the main function of crystalatte and retrieve the N-mers dictionary. keywords = crystalatte.input_parser("crystalatte/data/Ammonia.cle") # For debug. #import pprint #pprint.pprint(keywords) assert compare_values(3, keywords['cif_a']) assert compare_values(3, keywords['cif_b']) assert compare_values(3, keywords['cif_c']) assert compare_values(1.2, keywords['bfs_thresh']) assert compare_values(2, keywords['nmers_up_to']) assert compare_values(6.5, keywords['r_cut_com']) assert compare_values(2.6, keywords['r_cut_dimer']) assert compare_values(3.5, keywords['r_cut_monomer']) assert compare_values(6.1, keywords['r_cut_pentamer']) assert compare_values(3.7, keywords['r_cut_tetramer']) assert compare_values(3.7, keywords['r_cut_trimer']) assert compare_values(2, keywords['verbose']) assert compare("crystalatte/data/Ammonia.cif", keywords['cif_input']) assert compare("crystalatte/data/Ammonia.xyz", keywords['cif_output']) assert compare(["test"], keywords['cle_run_type']) assert compare("nocp", keywords['psi4_bsse']) assert compare("500 MB", keywords['psi4_memory']) assert compare('HF/STO-3G', keywords['psi4_method'])
def test_simple_ghost(program, basis, keywords, hene): resi = { "molecule": hene, "driver": "energy", "model": { "method": "hf", "basis": basis }, "keywords": keywords } if program == "gamess": with pytest.raises(qcng.exceptions.InputError) as e: res = qcng.compute(resi, program, raise_error=True, return_dict=True) pytest.xfail("no ghosts with gamess") res = qcng.compute(resi, program, raise_error=True, return_dict=True) assert res["driver"] == "energy" assert "provenance" in res assert res["success"] is True pprint.pprint(res, width=200) atol = 1.0e-6 assert compare_values(0.0, res["properties"]["nuclear_repulsion_energy"], atol=atol, label="nre") assert compare(32, res["properties"]["calcinfo_nbasis"], label="nbas") assert compare(32, res["properties"]["calcinfo_nmo"], label="nmo") assert compare_values(-2.8557143339397539, res["return_result"], atol=atol, label="ene")
def test_psithonyzer(): """Checks that the CSV file produced by the psithonyzer script contains correct information.""" # Get the root directory and chenge to the output directory. root = os.getcwd() d = os.path.join(root, "crystalatte", "data", "out") os.chdir(d) # Execute the psithonyzer script. subprocess.call(["./../../psithonyzer.py"]) # Change directory back to root; do this before test, # or else a failed test may leave us in the wrong directory. os.chdir(root) csv_lines = [] with open("crystalatte/data/out/Ammonia.csv", 'r') as csv: for line in csv: if "Energy" in line: continue else: csv_lines.append(line[:-1].replace(" ", "")) results = [] results.append( '2mer-0+1,0.87719178,6,2.63157535,2.63157535,8.552209e-03,3.8830,2.5880,2.588' ) results.append( '3mer-0+1+2,0.03591565,3,0.03591565,2.66749100,7.570855e-07,3.7280,2.5347,2.428,2.588,2.588' ) results.append( '3mer-0+1+5,-0.10631085,3,-0.10631085,2.56118015,6.255109e-07,3.8830,2.5880,2.588,2.588,2.588' ) results.append( '4mer-0+1+2+3,0.00643113,1,0.00160778,2.56278793,6.937449e-13,3.6505,2.5080,2.428,2.428,2.428,2.588,2.588,2.588' ) results.append( '5mer-0+1+2+3+4,-0.00086359,3,-0.00051816,2.56226977,1.441820e-22,4.1234,2.9181,2.428,2.428,2.428,2.588,2.588,2.588,2.588,2.588,3.945,5.012' ) assert compare(csv_lines, results) # Clean-up generated test files. subprocess.call(["rm", "crystalatte/data/out/Ammonia.csv"])
def test_psz_main(): """Checks that the main function on the psithonyzer script returns the correct values for precomputed psithon outputs.""" kwargs = {'com_mode': False, 'sort_by_avg_com_dist': False, 'sort_by_nmer_cutoff': False, 'src_directory': "crystalatte/data/out"} results, crystal_lattice_energy = crystalatte.psz_main(2, **kwargs) a = [] a.append("2mer-0+1 | 0.87719178 | 6 | 2.63157535 | 2.63157535 | 1.748924e-03 | 2.588 ") a.append("3mer-0+1+2 | 0.03591565 | 3 | 0.03591565 | 2.66749100 | 6.255109e-07 | 2.428 2.588 2.588 ") a.append("3mer-0+1+5 | -0.10631085 | 3 | -0.10631085 | 2.56118015 | 6.255109e-07 | 2.588 2.588 2.588 ") a.append("4mer-0+1+2+3 | 0.00643113 | 1 | 0.00160778 | 2.56278793 | 9.355871e-12 | 2.428 2.428 2.428 2.588 2.588 2.588 ") a.append("5mer-0+1+2+3+4 | -0.00086359 | 3 | -0.00051816 | 2.56226977 | 4.005201e-25 | 2.428 2.428 2.428 2.588 2.588 2.588 2.588 2.588 3.945 5.012 ") assert compare(a[0], results[0]) assert compare(a[1], results[1]) assert compare(a[2], results[2]) assert compare(a[3], results[3]) assert compare(a[4], results[4]) assert compare_values(2.56226977, crystal_lattice_energy, atol=1.e-9) # Clean-up generated test files. subprocess.call(["rm", "Ammonia.csv"])
def test_input_parser(): """Checks that the input parser function of the CrystaLattE program automatically assigns a name for the supercell .xyz file.""" # Execute the main function of crystalatte and retrieve the N-mers dictionary. keywords = crystalatte.input_parser("crystalatte/data/cle/no_xyz.cle") # For debug. #import pprint #pprint.pprint(keywords) # Check that the .xyz name has been autogenerated. assert compare("crystalatte/data/cif/Ammonia.xyz", keywords['cif_output']) # Clean-up generated test files subprocess.call(["rm", "crystalatte/data/cif/Ammonia.xyz"])
def test_nuclearrepulsionenergy_nelectrons(): mol = Molecule.from_data(""" 0 1 -- O 0.75119 -0.61395 0.00271 H 1.70471 -0.34686 0.00009 -- 1 1 N -2.77793 0.00179 -0.00054 H -2.10136 0.51768 0.60424 H -3.45559 -0.51904 0.60067 H -2.26004 -0.67356 -0.60592 H -3.29652 0.68076 -0.60124 units ang """) assert compare_values(34.60370459, mol.nuclear_repulsion_energy(), 'D', atol=1.e-5) assert compare_values(4.275210518, mol.nuclear_repulsion_energy(ifr=0), 'M1', atol=1.e-5) assert compare_values(16.04859029, mol.nuclear_repulsion_energy(ifr=1), 'M2', atol=1.e-5) assert compare(20, mol.nelectrons(), 'D') assert compare(10, mol.nelectrons(ifr=0), 'M1') assert compare(10, mol.nelectrons(ifr=1), 'M2') mol = mol.get_fragment([1], 0) # Notice the 0th/1st fragments change. Got to stop get_fragment from reordering ifr0 = 1 ifr1 = 0 assert compare_values(16.04859029, mol.nuclear_repulsion_energy(), 'D', atol=1.e-5) assert compare_values(0.0, mol.nuclear_repulsion_energy(ifr=ifr0), 'M1', atol=1.e-5) assert compare_values(16.04859029, mol.nuclear_repulsion_energy(ifr=ifr1), 'M2', atol=1.e-5) assert compare(10, mol.nelectrons(), 'D') assert compare(0, mol.nelectrons(ifr=ifr0), 'M1') assert compare(10, mol.nelectrons(ifr=ifr1), 'M2')
def test_nuclearrepulsionenergy_nelectrons(): mol = Molecule.from_data(""" 0 1 -- O 0.75119 -0.61395 0.00271 H 1.70471 -0.34686 0.00009 -- 1 1 N -2.77793 0.00179 -0.00054 H -2.10136 0.51768 0.60424 H -3.45559 -0.51904 0.60067 H -2.26004 -0.67356 -0.60592 H -3.29652 0.68076 -0.60124 units ang """) assert compare_values(34.60370459, mol.nuclear_repulsion_energy(), "D", atol=1.0e-5) assert compare_values(4.275210518, mol.nuclear_repulsion_energy(ifr=0), "M1", atol=1.0e-5) assert compare_values(16.04859029, mol.nuclear_repulsion_energy(ifr=1), "M2", atol=1.0e-5) assert compare(20, mol.nelectrons(), "D") assert compare(10, mol.nelectrons(ifr=0), "M1") assert compare(10, mol.nelectrons(ifr=1), "M2") mol = mol.get_fragment([1], 0, group_fragments=False) # Notice the 0th/1st fragments change if default group_fragments=True. ifr0 = 0 ifr1 = 1 assert compare_values(16.04859029, mol.nuclear_repulsion_energy(), "D", atol=1.0e-5) assert compare_values(0.0, mol.nuclear_repulsion_energy(ifr=ifr0), "M1", atol=1.0e-5) assert compare_values(16.04859029, mol.nuclear_repulsion_energy(ifr=ifr1), "M2", atol=1.0e-5) assert compare(10, mol.nelectrons(), "D") assert compare(0, mol.nelectrons(ifr=ifr0), "M1") assert compare(10, mol.nelectrons(ifr=ifr1), "M2")
def test_center_supercell(): """Checks the routine to read the supercell XYZ file and create Numpy arrays from it containing the center of the supercell, its coordinates and elements.""" args = [ '', '-i', 'crystalatte/data/cif/Ammonia.cif', '-o', 'sc.xyz', '-b', '1', '1', '1', '-r' ] crystalatte.cif_main(args) # Execute the main function of crystalatte and retrieve the N-mers dictionary. scell_geom_max_coords, scell_geom, scell_elem = crystalatte.center_supercell( "sc.xyz", 2) scgmc = np.array([4.84761994, 4.84761994, 4.84761994]) sce = np.array([ 'N', 'N', 'N', 'N', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H' ]) l_scg = [[-0.91910799, 3.92851196, 3.16646478], [3.92851196, 3.16646478, -0.91910799], [3.16646478, -0.91910799, 3.92851196], [-1.68115516, -1.68115516, -1.68115516], [2.3947252, 3.71327782, 0.], [-1.46592103, 4.84761994, 4.70025154], [-2.45289475, 3.38169892, 2.24735679], [0., 2.3947252, 3.71327782], [4.84761994, 4.70025154, -1.46592103], [3.38169892, 2.24735679, -2.45289475], [2.24735679, -2.45289475, 3.38169892], [3.71327782, 0., 2.3947252], [4.70025154, -1.46592103, 4.84761994], [-2.60026315, -0.1473684, -1.13434212], [-1.13434212, -2.60026315, -0.1473684], [-0.1473684, -1.13434212, -2.60026315]] scg = np.array(l_scg) assert compare_values(scgmc, scell_geom_max_coords) assert compare_values(scg, scell_geom) assert compare(sce, scell_elem) # Clean-up generated test files subprocess.call(["rm", "sc.xyz"])
def test_nbody_number(driver, bsse_type, return_total_data, nbody_number, return_result, stdoutkey): eneyne = psi4.geometry(""" C 0.000000 -0.667578 -2.124659 C 0.000000 0.667578 -2.124659 H 0.923621 -1.232253 -2.126185 H -0.923621 -1.232253 -2.126185 H -0.923621 1.232253 -2.126185 H 0.923621 1.232253 -2.126185 -- C 0.000000 0.000000 2.900503 C 0.000000 0.000000 1.693240 H 0.000000 0.000000 0.627352 H 0.000000 0.000000 3.963929 """) atin = { "driver": driver, "model": { "method": "mp2", "basis": "cc-pvdz", }, "molecule": eneyne.to_schema(dtype=2), "keywords": { "function_kwargs": { "bsse_type": bsse_type, "return_total_data": return_total_data, }, }, } ret = psi4.schema_wrapper.run_qcschema(atin) assert compare_values(return_result, ret.return_result, atol=1.e-6, label="manybody") assert compare(nbody_number, ret.extras["qcvars"]["NBODY NUMBER"], label="nbody number") assert re.search( _stdouts[stdoutkey], ret.stdout, re.MULTILINE), f"N-Body pattern not found: {_stdouts[stdoutkey]}"
def test_cle_read_cif(): """Checks that the read CIF function can take a CIF and produce a correct dictionary containing the unit cell structural data for an ammonia crystal.""" ref = { '_cell_length_a': 5.1305, '_cell_length_b': 5.1305, '_cell_length_c': 5.1305, '_cell_angle_alpha': 90.0, '_cell_angle_beta': 90.0, '_cell_angle_gamma': 90.0, '_cell_volume': 135.05, '_symmetry_equiv_pos_as_xyz': ['x,y,z'], '_atom_site_label': [ 'N', 'N', 'N', 'N', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H' ], '_atom_site_fract_x': [ 0.2107, 0.7107, 0.7893, 0.2893, 0.3689, 0.2671, 0.1159, 0.8689, 0.7671, 0.6159, 0.7329, 0.8841, 0.3841, 0.1311, 0.2329, 0.6311 ], '_atom_site_fract_y': [ 0.2107, 0.2893, 0.7107, 0.7893, 0.2671, 0.1159, 0.3689, 0.2329, 0.3841, 0.1311, 0.6159, 0.8689, 0.6311, 0.7329, 0.8841, 0.7671 ], '_atom_site_fract_z': [ 0.2107, 0.7893, 0.2893, 0.7107, 0.1159, 0.3689, 0.2671, 0.8841, 0.6311, 0.7329, 0.1311, 0.2329, 0.7671, 0.6159, 0.8689, 0.3841 ] } data = crystalatte.read_cif("crystalatte/data/cif/Ammonia.cif") assert compare(ref, data)
def test_3(): sys = qcel.molparse.from_string(seneyne)['qm'] resinp = { 'schema_name': 'qcschema_input', 'schema_version': 1, 'molecule': qcel.molparse.to_schema(sys, dtype=2), 'driver': 'energy', 'model': { 'method': 'b3lyp', }, 'keywords': { 'level_hint': 'd3bj' }, } res = qcng.compute(resinp, 'dftd3', raise_error=True) res = res.dict() #res = dftd3.run_dftd3_from_arrays(molrec=sys, name_hint='b3lyp', level_hint='d3bj') assert compare('B3LYP-D3(BJ)', _compute_key(res['extras']['info']), 'key')
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)