def test_xyz_reader(): """Test the xyz parser from a file.""" path_qd = PATH_MOLECULES / "Cd68Cl26Se55__26_acetate.xyz" mol = readXYZ(path_qd) for atom in mol: assertion.le(len(atom.symbol), 2) assertion.len_eq(atom.xyz, 3)
def test_adf_mock(mocker: MockFixture): """Mock the ADF output.""" mol = Molecule(PATH_MOLECULES / "acetonitrile.xyz") job = adf(templates.geometry, mol) run_mocked = mocker.patch("qmflows.run") jobname = "ADFjob" dill_path = WORKDIR / jobname / "ADFjob.dill" plams_dir = WORKDIR / jobname run_mocked.return_value = ADF_Result(templates.geometry, mol, jobname, dill_path=dill_path, work_dir=plams_dir, plams_dir=plams_dir) rs = run_mocked(job) assertion.isfinite(rs.energy) assertion.isfinite(rs.h**o) assertion.isfinite(rs.lumo) # Array of runtime for each optimization assertion.isfinite(rs.runtime[-1]) # 3-dimensional vector assertion.len_eq(rs.dipole, 3) # number of steps until convergence assertion.eq(rs.optcycles, 8) # Test molecule # Molecule mol = rs.molecule assertion.isinstance(mol, Molecule) assertion.len_eq(mol, 6) # there are 6 atoms
def test_create_database_4() -> None: """Test the backwards compatiblity of pre-``0.4`` databases.""" shutil.copytree(DB_PATH_OLD4, DB_PATH_NEW4) db = Database(DB_PATH_NEW4) with db.hdf5('r', libver='latest') as f: grp = f['ligand'] scale = grp['index'] pdb = PDBContainer.from_hdf5(grp) assertion.eq(grp['atoms'].dims[0]['index'], scale) assertion.eq(grp['bonds'].dims[0]['index'], scale) assertion.eq(grp['atom_count'].dims[0]['index'], scale) assertion.eq(grp['bond_count'].dims[0]['index'], scale) assertion.eq(grp['atoms'].dims[0].label, 'index') assertion.eq(grp['bonds'].dims[0].label, 'index') assertion.eq(grp['atom_count'].dims[0].label, 'index') assertion.eq(grp['bond_count'].dims[0].label, 'index') assertion.eq(grp['atoms'].dims[1].label, 'atoms') assertion.eq(grp['bonds'].dims[1].label, 'bonds') pdb.validate_hdf5(grp) assertion.contains(grp, 'properties') formula = grp['properties/formula'] assertion.len_eq(formula, len(scale)) assertion.eq(formula.dims[0]['index'], scale) ref = np.rec.array(None, dtype=LIG_IDX_DTYPE, shape=(3, )) ref[:] = b'' assertion.eq(pdb.scale, ref, post_process=np.all)
def test_len_eq() -> None: """Test :meth:`AssertionManager.len_eq`.""" assertion.len_eq([1], 1) assertion.len_eq({1, 2, 3, 1}, 3) assertion.len_eq({1: None}, 5, invert=True) assertion.len_eq(5, 6, 7, 8, exception=TypeError) assertion.len_eq(5, 5, exception=TypeError)
def test_freq(): """Do some constraint optimizations then launch a freq calc.""" mol = Molecule(PATH_MOLECULES / "ethene.xyz", "xyz") geo_opt = dftb(templates.geometry, mol) freq_calc = dftb(templates.freq, geo_opt.molecule, job_name="freq") r = run(freq_calc) assertion.eq(int(r.frequencies[0]), 831) assertion.len_eq(r.frequencies, 12)
def test_dftb_opt_mock(mocker: MockFixture): """Mock a geometry optimization using DFTB.""" jobname = "dftb_geometry" job = dftb(templates.geometry, WATER, job_name=jobname) run_mocked = mock_runner(mocker, jobname) rs = run_mocked(job) # check the properties assertion.isfinite(rs.energy) assertion.len_eq(rs.dipole, 3) assertion.isinstance(rs.molecule, Molecule)
def test_c2pk_opt_mock(mocker: MockFixture): """Mock a call to CP2K.""" # geometry optimization input s = fill_cp2k_defaults(templates.geometry) jobname = "cp2k_opt" run_mocked = mock_runner(mocker, jobname) job = cp2k(s, ETHYLENE, job_name=jobname) rs = run_mocked(job) # check the optimized geometry mol = rs.geometry assertion.len_eq(mol, 6) atom = mol[1] assertion.len_eq(atom.coords, 3) assertion.eq(atom.symbol, 'C')
def test_orca_mock(mocker: MockFixture): """Mock a call to orca.""" methanol = Molecule(PATH_MOLECULES / "methanol.xyz") s = Settings() s.specific.orca.main = "RKS B3LYP SVP Opt NumFreq TightSCF SmallPrint" # print the orbitals s.specific.orca.scf = " print[p_mos] 1" job = orca(s, methanol) run_mocked = mocker.patch("qmflows.run") jobname = "ORCAjob" dill_path = WORKDIR / jobname / "ORCAjob.dill" plams_dir = WORKDIR / jobname run_mocked.return_value = ORCA_Result(s, methanol, jobname, dill_path=dill_path, plams_dir=plams_dir) rs = run_mocked(job) assertion.isfinite(rs.energy) assertion.isfinite(rs.runtime) assertion.isfinite(np.sum(rs.dipole)) # steps until convergence assertion.eq(rs.optcycles, 8) # Check that hessian is symmetric hess = rs.hessian assertion.isclose(np.sum(hess - hess.T), 0.0) # frequencies frequencies = rs.frequencies assertion.len_eq(frequencies, 18) # Normal modes normal_modes = rs.normal_modes assertion.shape_eq(normal_modes, (18, 18)) # Orbitals orbs = rs.orbitals assert np.isfinite(np.sum(orbs.eigenvalues)) # eigenvalues # Molecule mol = rs.molecule assertion.isinstance(mol, Molecule) assertion.len_eq(mol, 6) # there are 6 atoms
def test_update_hdf5_log1() -> None: """Test :func:`dataCAT.update_hdf5_log`.""" copyfile(HDF5_READ, HDF5_TMP) with h5py.File(HDF5_TMP, 'r+', libver='latest') as f: group = f['ligand/logger'] i = len(group['date']) n0 = group.attrs['n'] assertion.truth(n0) i += group.attrs['n_step'] group.attrs['n'] = 100 update_hdf5_log(group, index=[0]) n1 = group.attrs['n'] assertion.eq(n1, 101) for name, dset in group.items(): if name != 'version_names': assertion.len_eq(dset, i)
def test_update_prop_dset() -> None: """Test :func:`dataCAT.update_prop_dset`.""" shutil.copyfile(HDF5_READ, HDF5_TMP) with h5py.File(HDF5_TMP, 'r+') as f: dset = f['ligand/properties/formula'] data1 = np.array(['a', 'b', 'c'], dtype=np.string_) update_prop_dset(dset, data1, index=slice(None, 3)) assertion.eq(data1, dset[:3], post_process=np.all) # Resize the index idx = f['ligand/index'] n = len(idx) idx.resize(n + 3, axis=0) # Test if the automatic resizing works data2 = np.array(['d', 'e', 'f'], dtype=np.string_) update_prop_dset(dset, data2, index=slice(-3, None)) assertion.eq(data2, dset[-3:], post_process=np.all) assertion.len_eq(dset, n + 3)
def test_orca_parse_molecule(): """Test the reading of the molecule from the output.""" mol = parse_molecule(PATH_OUTPUT) assertion.isinstance(mol, plams.Molecule) assertion.len_eq(mol, 6)