コード例 #1
0
def store_transf_matrix(path_hdf5: str,
                        atoms: List,
                        dictCGFs: Dict,
                        basis_name: str,
                        project_name: str,
                        package_name: str = 'cp2k') -> str:
    """
    calculate the transformation of the overlap matrix from both spherical
    to cartesian and from cartesian to spherical.

    :param path_hdf5: Path to the HDF5 file.
    :param atoms: Atoms that made up the molecule.
    :param project_name: Name of the project.
    :param package_name: Name of the ab initio simulation package.
    :returns: Numpy matrix containing the transformation matrix.
    """
    # Norms of the spherical CGFs for each element
    dict_global_norms = compute_normalization_sphericals(dictCGFs)
    # Compute the transformation matrix between cartesian and spherical
    path = os.path.join(project_name, 'trans_mtx')
    with h5py.File(path_hdf5) as f5:
        if path not in f5:
            mtx = calc_transf_matrix(f5, atoms, basis_name, dict_global_norms,
                                     package_name)
            store = StoreasHDF5(f5, package_name)
            store.funHDF5(path, mtx)
    return path
コード例 #2
0
def test_compare_with_cp2k():
    """
    Test overlap matrix transformation from cartesian to spherical
    """
    # Overlap matrix in cartesian coordinates
    basisname = "DZVP-MOLOPT-SR-GTH"
    # Molecular geometry in a.u.
    atoms = change_mol_units(readXYZ('test/test_files/ethylene.xyz'))

    dictCGFs = create_dict_CGFs(path_hdf5, basisname, atoms)

    # Compute the overlap matrix using the general multipole expression
    rs = calcMtxOverlapP(atoms, dictCGFs)
    number_of_contracted = sum(len(dictCGFs[at.symbol]) for at in atoms)
    mtx_overlap = triang2mtx(rs, number_of_contracted)

    dict_global_norms = compute_normalization_sphericals(dictCGFs)

    with h5py.File(path_hdf5, 'r') as f5:
        transf_mtx = calc_transf_matrix(f5, atoms, basisname,
                                        dict_global_norms, 'cp2k')

    # Use a sparse representation of the transformation matrix
    transf_mtx = sparse.csr_matrix(transf_mtx)
    transpose = transf_mtx.transpose()

    # Compare the results with CP2K overlap matrix
    test = transf_mtx.dot(sparse.csr_matrix.dot(mtx_overlap, transpose))

    sum_diag = np.sum(np.diag(test))
    number_of_sphericals = transf_mtx.shape[0]

    assert abs(sum_diag - number_of_sphericals) < 1e-16
コード例 #3
0
def test_compare_with_cp2k():
    """
    Test overlap matrix transformation from cartesian to spherical
    """
    # Overlap matrix in cartesian coordinates
    basisname = "DZVP-MOLOPT-SR-GTH"
    # Molecular geometry in a.u.
    atoms = change_mol_units(
        readXYZ('test/test_files/Cd33Se33_fivePoints.xyz'))

    dictCGFs = create_dict_CGFs(path_hdf5, basisname, atoms)

    # Compute the overlap matrix using the general multipole expression
    rs = calcMtxOverlapP(atoms, dictCGFs)
    mtx_overlap = triang2mtx(rs, 1452)  # there are 1452 Cartesian basis CGFs

    dict_global_norms = compute_normalization_sphericals(dictCGFs)

    with h5py.File(path_hdf5, 'r') as f5:
        transf_mtx = calc_transf_matrix(f5, atoms, basisname,
                                        dict_global_norms, 'cp2k')

    # Use a sparse representation of the transformation matrix
    transf_mtx = sparse.csr_matrix(transf_mtx)
    transpose = transf_mtx.transpose()

    # Compare the results with CP2K overlap matrix
    test = transf_mtx.dot(sparse.csr_matrix.dot(mtx_overlap, transpose))
    expected = np.load('test/test_files/overlap_Cd33Se33_cp2k.npy')

    assert np.allclose(test, expected, atol=1e-5)
コード例 #4
0
def test_cube():
    """
    Test the density compute to create a cube file.
    """
    if not os.path.exists(scratch_path):
        os.makedirs(scratch_path)

    # Overlap matrix in cartesian coordinates
    basisname = "DZVP-MOLOPT-SR-GTH"

    # Read coordinates
    molecule = change_mol_units(readXYZ(path_xyz))

    # String representation of the molecule
    geometries = split_file_geometries(path_xyz)

    try:
        shutil.copy(path_original_hdf5, path_test_hdf5)
        # Contracted Gauss functions
        dictCGFs = create_dict_CGFs(path_test_hdf5, basisname, molecule)

        dict_global_norms = compute_normalization_sphericals(dictCGFs)

        # Compute the transformation matrix and store it in the HDF5
        with h5py.File(path_test_hdf5, 'r') as f5:
            transf_mtx = calc_transf_matrix(
                f5, molecule, basisname, dict_global_norms, 'cp2k')

        path_transf_mtx = join(project_name, 'trans_mtx')
        store_arrays_in_hdf5(
            path_test_hdf5, path_transf_mtx, transf_mtx)

        # voxel size and Number of steps
        grid_data = GridCube(0.300939, 80)

        rs = workflow_compute_cubes(
            'cp2k', project_name, package_args, path_time_coeffs=None,
            grid_data=grid_data, guess_args=None, geometries=geometries,
            dictCGFs=dictCGFs, calc_new_wf_guess_on_points=[],
            path_hdf5=path_test_hdf5, enumerate_from=0, package_config=None,
            traj_folders=None, work_dir=scratch_path, basisname=basisname,
            hdf5_trans_mtx=path_transf_mtx, nHOMO=6, orbitals_range=(6, 6),
            ignore_warnings=False)

        xs = retrieve_hdf5_data(path_test_hdf5, rs)[0]
        np.save("grid_density", xs)

    finally:
        # Remove intermediate results
        shutil.rmtree(scratch_path)