Beispiel #1
0
def test_cube_h2o_dimer():
    # test against previous generated .cube files
    with path('chemtools.data', 'h2o_dimer_pbe_sto3g-dens.cube') as file_path:
        cube = UniformGrid.from_cube(file_path)
        mol1 = Molecule.from_file(str(file_path))

    with tmpdir('chemtools.test.test_base.test_cube_h2o_dimer') as dn:
        cube2 = '%s/%s' % (dn, 'h2o_dimer_pbe_sto3g-dens.cube')
        cube.generate_cube(cube2, mol1.cube_data)
        cube2 = '%s/%s' % (dn, 'h2o_dimer_pbe_sto3g-dens.cube')
        mol2 = Molecule.from_file(cube2)
        # Check coordinates
        np.testing.assert_array_almost_equal(mol1.coordinates, mol2.coordinates, decimal=6)
        np.testing.assert_equal(mol1.numbers, mol2.numbers)
        # Check grid data
        ugrid1 = mol1.grid
        ugrid2 = mol2.grid
        np.testing.assert_array_almost_equal(ugrid1.grid_rvecs, ugrid2.grid_rvecs, decimal=6)
        np.testing.assert_equal(ugrid1.shape, ugrid2.shape)
        data1 = mol1.cube_data / mol1.cube_data
        data2 = mol2.cube_data / mol1.cube_data
        np.testing.assert_array_almost_equal(data1, data2, decimal=4)
        np.testing.assert_equal(mol1.pseudo_numbers, mol2.pseudo_numbers)
Beispiel #2
0
def load_molecule_and_grid(fname, cube):
    """Return instances of molecule and uniform cubic grid.

    Parameters
    ----------
    fname : str
        Path to wave-function file.
    cube : str
       Uniform cubic grid specifications.

    """
    # load molecule
    mol = Molecule.from_file(fname)

    if cube.endswith(".cube"):
        # load & check cube file
        cube = UniformGrid.from_cube(cube)
        if np.allclose(mol.numbers, cube.numbers):
            raise ValueError(
                "Atomic number in {0} & {1} should be the same!".format(
                    fname, cube))
        if np.allclose(mol.coordinates, cube.coordinates):
            raise ValueError(
                "Atomic coordinates in {0} & {1} should be the same!".format(
                    cube.fname, cube.cube))
    elif len(cube.split(",")) == 2:
        # make a cubic grid
        spacing, extension = [float(item) for item in cube.split(",")]
        cube = UniformGrid.from_molecule(mol,
                                         spacing=spacing,
                                         extension=extension,
                                         rotate=True)

    else:
        raise ValueError("Argument cube={0} is not recognized!".format(cube))

    return mol, cube