Esempio n. 1
0
def test_condense_from_molecule_fd_rmf_npa_h2o_fchk():
    # expected populations of H2O from fchk file
    expected_m = np.array([8, 1, 1]) - np.array(
        [-3.64452391E-02, 5.18222784E-01, 5.18222455E-01])
    expected_0 = np.array([8, 1, 1]) - np.array(
        [-9.00876494E-01, 4.50438267E-01, 4.50438227E-01])
    expected_p = np.array([8, 1, 1]) - np.array(
        [-1.11332869E+00, 5.66635486E-02, 5.66651430E-02])
    molecule = []
    with path('chemtools.data', 'h2o_q+0_ub3lyp_ccpvtz.fchk') as file1:
        molecule.append(Molecule.from_file(file1))
    with path('chemtools.data', 'h2o_q-1_ub3lyp_ccpvtz.fchk') as file2:
        molecule.append(Molecule.from_file(file2))
    with path('chemtools.data', 'h2o_q+1_ub3lyp_ccpvtz.fchk') as file3:
        molecule.append(Molecule.from_file(file3))
    # check from_molecule linear
    model = CondensedConceptualDFT.from_molecule(molecule, "linear", "RMF",
                                                 "npa")
    check_condensed_reactivity(model, "linear", expected_0, expected_p,
                               expected_m, 10, 0.572546)
    # check from_molecule quadratic
    model = CondensedConceptualDFT.from_molecule(molecule, "quadratic", "RMF",
                                                 "npa")
    check_condensed_reactivity(model, "quadratic", expected_0, expected_p,
                               expected_m, 10, 0.572546)
Esempio n. 2
0
    def from_file(cls, fname, spacing=0.2, extension=5.0, rotate=True):
        """
        Initialize ``UniformGrid`` class based on the grid specifications of a file.

        Parameters
        ----------
        fname : str
            Path to molecule's file.
        spacing : float, optional
            Increment between grid points along `x`, `y` and `z` direction.
        extension : float, optional
            The extension of the cube on each side of the molecule.
        rotate : bool, optional
            When True, the molecule is rotated so the axes of the cube file are
            aligned with the principle axes of rotation of the molecule.
        """
        # Load file
        logging.basicConfig(level=logging.INFO,
                            format='%(levelname)s: %(message)s')
        try:
            mol = Molecule.from_file(str(fname))
        except IOError as _:
            try:
                with path('chemtools.data.examples', str(fname)) as fname:
                    logging.info('Loading {0}'.format(str(fname)))
                    mol = Molecule.from_file(str(fname))
            except IOError as error:
                logging.info(error)
        return cls.from_molecule(mol, spacing, extension, rotate)
Esempio n. 3
0
def test_condense_from_molecule_fd_rmf_esp_h2o_fchk():
    # expected populations of H2O from fchk file
    expected_m = np.array([8, 1, 1]) - np.array(
        [4.14233893E-02, 4.79288419E-01, 4.79288192E-01])
    expected_0 = np.array([8, 1, 1]) - np.array(
        [-7.00779373E-01, 3.50389629E-01, 3.50389744E-01])
    expected_p = np.array([8, 1, 1]) - np.array(
        [-5.81613550E-01, -2.09193820E-01, -2.09192630E-01])
    molecule = []
    with path('chemtools.data', 'h2o_q+0_ub3lyp_ccpvtz.fchk') as file1:
        molecule.append(Molecule.from_file(file1))
    with path('chemtools.data', 'h2o_q-1_ub3lyp_ccpvtz.fchk') as file2:
        molecule.append(Molecule.from_file(file2))
    with path('chemtools.data', 'h2o_q+1_ub3lyp_ccpvtz.fchk') as file3:
        molecule.append(Molecule.from_file(file3))
    # check from_molecule linear
    model = CondensedConceptualDFT.from_molecule(molecule, "linear", "RMF",
                                                 "esp")
    check_condensed_reactivity(model, "linear", expected_0, expected_p,
                               expected_m, 10, 0.572546)
    # check from_molecule quadratic
    model = CondensedConceptualDFT.from_molecule(molecule, "quadratic", "RMF",
                                                 "esp")
    check_condensed_reactivity(model, "quadratic", expected_0, expected_p,
                               expected_m, 10, 0.572546)
Esempio n. 4
0
def test_condense_from_molecule_fd_rmf_mulliken_h2o_fchk():
    # expected populations of H2O from fchk file
    expected_m = np.array([8, 1, 1]) - np.array(
        [3.49417097E-01, 3.25291762E-01, 3.25291141E-01])
    expected_0 = np.array([8, 1, 1]) - np.array(
        [-4.32227787E-01, 2.16114060E-01, 2.16113727E-01])
    expected_p = np.array([8, 1, 1]) - np.array(
        [-2.64833827E-01, -3.67583325E-01, -3.67582849E-01])
    molecule = []
    with path('chemtools.data', 'h2o_q+0_ub3lyp_ccpvtz.fchk') as file1:
        molecule.append(Molecule.from_file(file1))
    with path('chemtools.data', 'h2o_q-1_ub3lyp_ccpvtz.fchk') as file2:
        molecule.append(Molecule.from_file(file2))
    with path('chemtools.data', 'h2o_q+1_ub3lyp_ccpvtz.fchk') as file3:
        molecule.append(Molecule.from_file(file3))
    # check from_molecule linear
    model = CondensedConceptualDFT.from_molecule(molecule, "linear", "RMF",
                                                 "mulliken")
    check_condensed_reactivity(model, "linear", expected_0, expected_p,
                               expected_m, 10, 0.572546)
    # check from_molecule quadratic
    model = CondensedConceptualDFT.from_molecule(molecule, "quadratic", "RMF",
                                                 "mulliken")
    check_condensed_reactivity(model, "quadratic", expected_0, expected_p,
                               expected_m, 10, 0.572546)
Esempio n. 5
0
def test_condense_linear_from_file_fmr_h_ch4_wfn():
    # expected populations of CH4 computed with HORTON
    with path('chemtools.data', 'ch4_uhf_ccpvdz.wfn') as fname:
        model1 = CondensedConceptualDFT.from_file(fname, "linear", "FMR", "h")
        model2 = CondensedConceptualDFT.from_file([fname], "linear", "FMR",
                                                  "h")
        mol = Molecule.from_file(fname)
        grid = MolecularGrid(mol.coordinates, mol.numbers, mol.pseudo_numbesr,
                             'insane', 3, False)
        model3 = CondensedConceptualDFT.from_file(fname,
                                                  "linear",
                                                  "FMR",
                                                  "h",
                                                  grid=grid)
        model4 = CondensedConceptualDFT.from_file([fname],
                                                  "linear",
                                                  "FMR",
                                                  "h",
                                                  grid=grid)
    expected = np.array(
        [6.11301651, 0.97175462, 0.97175263, 0.9717521, 0.97174353])
    # check using fname given as a string
    check_condensed_reactivity(model1, "linear", expected, None, None, 10,
                               0.736396)
    # check using fname given as a list
    check_condensed_reactivity(model2, "linear", expected, None, None, 10,
                               0.736396)
    # check using fname as a string & passing grid
    mol = Molecule.from_file(fname)
    check_condensed_reactivity(model3, "linear", expected, None, None, 10,
                               0.736396)
    # check using fname as a list & passing grid
    check_condensed_reactivity(model4, "linear", expected, None, None, 10,
                               0.736396)
Esempio n. 6
0
def test_get_matching_attr_raises():
    # check molecule
    with path('chemtools.data', 'ch4_uhf_ccpvdz.fchk') as file1:
        with path('chemtools.data', 'h2o_q+0_ub3lyp_ccpvtz.fchk') as file2:
            fname = [file1, file2]
    assert_raises(ValueError, get_matching_attr, fname, "numbers")
    assert_raises(ValueError, get_matching_attr, fname, "coordinates")
    # check matching attribute
    with path('chemtools.data', 'ch4_uhf_ccpvdz.fchk') as file1:
        with path('chemtools.data', 'h2o_q+0_ub3lyp_ccpvtz.fchk') as file2:
            molecule = [Molecule.from_file(file1), Molecule.from_file(file2)]
    assert_raises(ValueError, get_matching_attr, molecule, "numbers")
    assert_raises(ValueError, get_matching_attr, molecule, "coordinates")
Esempio n. 7
0
def test_analyze_nci_h2o_dimer_fchk():
    with path('chemtools.data', 'h2o_dimer_pbe_sto3g.fchk') as file_path:
        mol = Molecule.from_file(file_path)
    # Check against .cube files created with NCIPLOT by E.R. Johnson and J. Contreras-Garcia
    with path('chemtools.data',
              'h2o_dimer_pbe_sto3g-dens.cube') as dens_cube1_path:
        cube = UniformGrid.from_cube(dens_cube1_path)
    # Build the NCI tool
    desp = NCI.from_molecule(mol, grid=cube)
    # Check against .cube files created with NCIPLOT by E.R. Johnson and J. Contreras-Garcia
    with path('chemtools.data',
              'h2o_dimer_pbe_sto3g-grad.cube') as grad_cube1_path:
        dmol1 = Molecule.from_file(str(dens_cube1_path))
        gmol1 = Molecule.from_file(str(grad_cube1_path))

    with tmpdir(
            'chemtools.analysis.test.test_base.test_analyze_nci_h2o_dimer_fchk'
    ) as dn:
        cube2 = '%s/%s' % (dn, 'h2o_dimer_pbe_sto3g')
        desp.generate_scripts(cube2)
        cube2 = '%s/%s' % (dn, 'h2o_dimer_pbe_sto3g-dens.cube')
        mol2 = Molecule.from_file(cube2)
        # Check coordinates
        assert_almost_equal(dmol1.coordinates, mol2.coordinates, decimal=6)
        assert_equal(dmol1.numbers, mol2.numbers)
        # Check grid data
        ugrid1 = dmol1.grid
        ugrid2 = mol2.grid
        assert_almost_equal(ugrid1.grid_rvecs, ugrid2.grid_rvecs, decimal=6)
        assert_equal(ugrid1.shape, ugrid2.shape)
        data1 = dmol1.cube_data / dmol1.cube_data
        data2 = mol2.cube_data / dmol1.cube_data
        assert_almost_equal(data1, data2, decimal=4)
        assert_equal(dmol1.pseudo_numbers, mol2.pseudo_numbers)

        cube2 = '%s/%s' % (dn, 'h2o_dimer_pbe_sto3g-grad.cube')
        mol2 = Molecule.from_file(cube2)
        # Check coordinates
        assert_almost_equal(gmol1.coordinates, mol2.coordinates, decimal=6)
        assert_equal(gmol1.numbers, mol2.numbers)
        # Check grid data
        ugrid1 = gmol1.grid
        ugrid2 = mol2.grid
        assert_almost_equal(ugrid1.grid_rvecs, ugrid2.grid_rvecs, decimal=6)
        assert_equal(ugrid1.shape, ugrid2.shape)
        data1 = gmol1.cube_data / gmol1.cube_data
        data2 = mol2.cube_data / gmol1.cube_data
        assert_almost_equal(data1, data2, decimal=4)
        assert_equal(gmol1.pseudo_numbers, mol2.pseudo_numbers)
Esempio n. 8
0
def test_orbital_based_from_molecule_orbital_expression_ch4_uhf_ccpvdz():
    # load data computed with Fortran code
    with path("chemtools.data", "data_fortran_ch4_uhf_ccpvdz.npz") as fname:
        data = np.load(str(fname))
    # test from_molecule initialization with exp_beta & check against Fortran code
    with path("chemtools.data", "ch4_uhf_ccpvdz.fchk") as fname:
        molecule = Molecule.from_file(fname)
    tool = DFTBasedTool(molecule, data["points"])
    check_orbital_expression(tool, data)
    # test from_molecule initialization without exp_beta & check against Fortran code
    del molecule._exp_beta
    with path("chemtools.data", "ch4_uhf_ccpvdz.fchk") as fname:
        molecule = Molecule.from_file(fname)
    tool = DFTBasedTool(molecule, data["points"])
    check_orbital_expression(tool, data)
Esempio n. 9
0
def test_kinetic_from_molecule_ch4_uhf_ccpvdz():
    # load data computed with Fortran code
    with path("chemtools.data", "data_fortran_ch4_uhf_ccpvdz.npz") as fname:
        data = np.load(str(fname))
    # test from_molecule initialization with exp_beta & check against Fortran code
    with path("chemtools.data", "ch4_uhf_ccpvdz.fchk") as fname:
        molecule = Molecule.from_file(fname)
    tool = KED.from_molecule(molecule, data['points'])
    print('tool = ', tool)
    check_kinetic_energy_density(tool, data)
    # test from_molecule initialization without exp_beta & check against Fortran code
    del molecule._exp_beta
    with path("chemtools.data", "ch4_uhf_ccpvdz.fchk") as fname:
        molecule = Molecule.from_file(fname)
    tool = KED.from_molecule(molecule, data['points'])
    check_kinetic_energy_density(tool, data)
Esempio n. 10
0
    def from_file(cls, fname, spin='ab', index=None, grid=None, trans='inverse_rational',
                  trans_k=1, trans_a=1, denscut=0.0005):
        """Initialize class from wave-function file.

        Parameters
        ----------
        fname : str
            Path to a molecule's file.
        spin : str, optional
            Type of occupied spin orbitals; options are 'a', 'b' & 'ab'.
        index : int or sequence of int, optional
            Sequence of spin orbital indices to use. If None, all occupied spin orbitals are used.
        grid : instance of `Grid`, optional
            Grid used for computation of LOL. Only if this a CubeGrid one can generate the scripts.
            If None, a cubic grid is constructed from molecule with spacing=0.1 & extension=2.0.
        trans : str, optional
            Type of transformation applied to LOL ratio; options are 'inverse_rational' or
            'inverse_hyperbolic'.
        trans_k : float, optional
            Parameter :math:`k` of transformation.
        trans_a : float, optional
            Parameter :math:`a` of transformation.
        denscut : float, optional
            Value of density cut. LOL value of points with density < denscut is set to zero.

        """
        molecule = Molecule.from_file(fname)
        return cls.from_molecule(molecule, spin, index, grid, trans, trans_k, trans_a, denscut)
Esempio n. 11
0
def test_uniformgrid_from_molecule_o2_uhf():
    with path('chemtools.data', 'o2_uhf.fchk') as fpath:
        mol = Molecule.from_file(str(fpath))

    # create cube file from molecule:
    cube = UniformGrid.from_molecule(mol)

    # test the cube gives the right result:
    origin_result = [-5.0, -5.0, -6.1]
    axes_result = [[0.0, 0.0, 0.2], [0.0, 0.2, 0.0], [0.2, 0.0, 0.0]]
    shape_result = [61, 50, 50]
    weight_result = np.full(cube.npoints, 0.0080)

    np.testing.assert_array_almost_equal(cube.origin, origin_result, decimal=7)
    np.testing.assert_array_almost_equal(cube.axes, axes_result, decimal=7)
    np.testing.assert_array_equal(cube.shape, shape_result)
    np.testing.assert_array_almost_equal(cube.weights(), weight_result, decimal=7)
    np.testing.assert_array_almost_equal(cube.weights(method='R0'), weight_result, decimal=7)
    np.testing.assert_array_almost_equal(cube.weights(method='R'), weight_result, decimal=7)

    # test integration of Fukui functions:

    tool = LocalConceptualDFT.from_file(str(fpath), model='linear', points=cube.points)

    ffm_default = cube.integrate(tool.ff_minus)
    ffm_r = cube.integrate(tool.ff_minus, method='R')
    ffm_r0 = cube.integrate(tool.ff_minus, method='R0')

    np.testing.assert_almost_equal(ffm_default, ffm_r, decimal=7)
    np.testing.assert_almost_equal(ffm_r, ffm_r0, decimal=7)
    np.testing.assert_almost_equal(ffm_default, 1.000, decimal=2)
    np.testing.assert_almost_equal(ffm_default, 1.000, decimal=2)
    np.testing.assert_almost_equal(ffm_default, 1.000, decimal=2)
Esempio n. 12
0
def test_kinetic_from_molecule_h2o_nuclei():
    # test against multiwfn 3.6 dev src
    with path('chemtools.data',
              'data_multiwfn36_fchk_h2o_q+0_ub3lyp_ccpvtz.npz') as fname:
        data = np.load(str(fname))
    with path('chemtools.data', 'h2o_q+0_ub3lyp_ccpvtz.fchk') as fname:
        molecule = Molecule.from_file(fname)
    tool = KED.from_molecule(molecule, data['coords'])
    # check attributes
    assert_allclose(tool.density, data['nuc_dens'], rtol=1.e-6, atol=0.)
    assert_allclose(tool.gradient, data['nuc_grad'], rtol=1.e-6, atol=0.)
    assert_allclose(tool.laplacian, data['nuc_lap'], rtol=1.e-6, atol=0.)
    # check ked at the position of nuclei
    assert_allclose(tool.ked_positive_definite,
                    data['nuc_ked_pd'],
                    rtol=1.e-5,
                    atol=0.)
    assert_allclose(tool.ked_hamiltonian,
                    data['nuc_ked_ham'],
                    rtol=1.e-5,
                    atol=0.)
    assert_allclose(tool.ked_general(alpha=0.),
                    data['nuc_ked_ham'],
                    rtol=1.e-5,
                    atol=0.)
Esempio n. 13
0
def test_condense_quadratic_from_molecule_fmr_mbis_ch4_fchk():
    # expected populations of CH4 computed with HORTON
    with path('chemtools.data', 'ch4_uhf_ccpvdz.fchk') as fname:
        mol = Molecule.from_file(fname)
    expected = np.array(
        [6.46038055, 0.88489494, 0.88492901, 0.88493897, 0.88492396])
    # check from_molecule
    model = CondensedConceptualDFT.from_molecule(mol, "quadratic", "FMR",
                                                 "mbis")
    check_condensed_reactivity(model, "quadratic", expected, None, None, 10,
                               0.736396)
    # check from_molecule given as a list
    model = CondensedConceptualDFT.from_molecule([mol], "quadratic", "FMR",
                                                 "mbis")
    check_condensed_reactivity(model, "quadratic", expected, None, None, 10,
                               0.736396)
    # check from_molecule & passing grid
    grid = MolecularGrid(mol.coordinates, mol.numbers, mol.pseudo_numbesr,
                         'insane', 3, False)
    model = CondensedConceptualDFT.from_molecule(mol,
                                                 "quadratic",
                                                 "FMR",
                                                 "mbis",
                                                 grid=grid)
    check_condensed_reactivity(model, "quadratic", expected, None, None, 10,
                               0.736396)
    # check from_molecule given as a list & passing grid
    model = CondensedConceptualDFT.from_molecule([mol],
                                                 "quadratic",
                                                 "FMR",
                                                 "mbis",
                                                 grid=grid)
    check_condensed_reactivity(model, "quadratic", expected, None, None, 10,
                               0.736396)
Esempio n. 14
0
def test_condense_linear_from_file_fmr_mbis_ch4_fchk():
    # expected populations of CH4 computed with HORTON
    with path('chemtools.data', 'ch4_uhf_ccpvdz.fchk') as fname:
        model1 = CondensedConceptualDFT.from_file(fname, "linear", "FMR",
                                                  "mbis")
        model2 = CondensedConceptualDFT.from_file([fname], "linear", "FMR",
                                                  "mbis")
        mol = Molecule.from_file(fname)
        grid = MolecularGrid(mol.coordinates, mol.numbers, mol.pseudo_numbesr,
                             'insane', 3, False)
        model3 = CondensedConceptualDFT.from_file(fname,
                                                  "linear",
                                                  "FMR",
                                                  "mbis",
                                                  grid=grid)
        model4 = CondensedConceptualDFT.from_file([fname],
                                                  "linear",
                                                  "FMR",
                                                  "mbis",
                                                  grid=grid)
    expected = np.array(
        [6.46038055, 0.88489494, 0.88492901, 0.88493897, 0.88492396])
    # check using fname given as a string
    check_condensed_reactivity(model1, "linear", expected, None, None, 10,
                               0.736396)
    # check using fname given as a list
    check_condensed_reactivity(model2, "linear", expected, None, None, 10,
                               0.736396)
    # check using fname as a string & passing grid
    check_condensed_reactivity(model3, "linear", expected, None, None, 10,
                               0.736396)
    # check using fname as a list & passing grid
    check_condensed_reactivity(model4, "linear", expected, None, None, 10,
                               0.736396)
Esempio n. 15
0
def test_critical_point_h2o():
    # test against multiwfn 3.6 dev src
    with path("chemtools.data",
              "data_multiwfn36_fchk_h2o_q+0_ub3lyp_ccpvtz.npz") as fname:
        data = np.load(str(fname))
    nna, bcp = data["nna_coords"], data["bcp_coords"]
    # find critical points
    with path("chemtools.data", "h2o_q+0_ub3lyp_ccpvtz.fchk") as fpath:
        mol = Molecule.from_file(fpath)
    cub = UniformGrid.from_molecule(mol,
                                    spacing=0.15,
                                    extension=0.1,
                                    rotate=False)
    top = TopologicalTool.from_molecule(mol, points=cub.points)
    # check NA
    assert len(top.nna) == 3
    assert sum([np.allclose(top.nna[0].coordinate, c, rtol=0.0)
                for c in nna]) == 1
    assert sum([np.allclose(top.nna[1].coordinate, c, rtol=0.0)
                for c in nna]) == 1
    assert sum([np.allclose(top.nna[2].coordinate, c, rtol=0.0)
                for c in nna]) == 1
    # check BCP
    assert len(top.bcp) == 2
    assert sum([np.allclose(top.bcp[0].coordinate, c, rtol=0.0)
                for c in bcp]) == 1
    assert sum([np.allclose(top.bcp[1].coordinate, c, rtol=0.0)
                for c in bcp]) == 1
    # check total number of CP
    assert len(top.rcp) == 0
    assert len(top.ccp) == 0
    assert len(top.cps) == 5
    assert top.poincare_hopf_equation
Esempio n. 16
0
def test_condense_linear_from_molecule_fmr_h_ch4_fchk():
    # expected populations of CH4 computed with HORTON
    with path('chemtools.data', 'ch4_uhf_ccpvdz.fchk') as fname:
        mol = Molecule.from_file(fname)
    expected = np.array(
        [6.11301651, 0.97175462, 0.97175263, 0.9717521, 0.97174353])
    # check from_molecule
    model = CondensedConceptualDFT.from_molecule(mol, "linear", "FMR", "h")
    check_condensed_reactivity(model, "linear", expected, None, None, 10,
                               0.736396)
    # check from_molecule given as a list
    model = CondensedConceptualDFT.from_molecule([mol], "linear", "FMR", "h")
    check_condensed_reactivity(model, "linear", expected, None, None, 10,
                               0.736396)
    # check from_molecule & passing grid
    grid = MolecularGrid(mol.coordinates, mol.numbers, mol.pseudo_numbesr,
                         'insane', 3, False)
    model = CondensedConceptualDFT.from_molecule(mol,
                                                 "linear",
                                                 "FMR",
                                                 "h",
                                                 grid=grid)
    check_condensed_reactivity(model, "linear", expected, None, None, 10,
                               0.736396)
    # check from_molecule given as a list & passing grid
    model = CondensedConceptualDFT.from_molecule([mol],
                                                 "linear",
                                                 "FMR",
                                                 "h",
                                                 grid=grid)
    check_condensed_reactivity(model, "linear", expected, None, None, 10,
                               0.736396)
Esempio n. 17
0
def test_populations_mulliken_h2o_anion():
    # Test against Gaussian
    with path("chemtools.data", "h2o_q-1_ub3lyp_ccpvtz.fchk") as fname:
        mol = Molecule.from_file(str(fname))
    assert_raises(ValueError, OrbPart.from_molecule, mol, 'muliken')
    mot = OrbPart.from_molecule(mol)
    mulliken = np.array([-2.64833827E-01, -3.67583325E-01, -3.67582849E-01])
    assert np.allclose(mulliken, mot.charges, atol=1e-6)
Esempio n. 18
0
 def __init__(self, input_file):
     self.input_file = input_file
     # Initialize the molecule from a input_file
     self.mol = Molecule.from_file(input_file)
     self.coordinates = self.mol.coordinates
     self.charges = self.mol.numbers
     self.atoms = self.get_atom_list(self.charges)
     self.geometry = list(zip(self.atoms, self.coordinates))
Esempio n. 19
0
def test_kinetic_from_molecule_ch4_rhf_ccpvdz():
    # load data computed with Fortran code
    with path("chemtools.data",
              "data_orbitalbased_fortran_ch4_uhf_ccpvdz.npz") as fname:
        data = np.load(str(fname))
    # test from_file initialization & check against Fortran code
    with path("chemtools.data", "ch4_rhf_ccpvdz.fchk") as fname:
        molecule = Molecule.from_file(fname)
    tool = KED.from_molecule(molecule, data['points'])
    check_kinetic_energy_density(tool, data)
Esempio n. 20
0
def test_condense_quadratic_from_molecule_fmr_mbis_ch4_wfn():
    # expected populations of CH4 computed with HORTON
    with path('chemtools.data', 'ch4_uhf_ccpvdz.wfn') as fname:
        molecule = Molecule.from_file(fname)
    part = DensPart.from_molecule(molecule, scheme='mbis')
    expected = np.array(
        [6.46038055, 0.88489494, 0.88492901, 0.88493897, 0.88492396])
    computed = part.numbers - part.charges
    assert np.all(abs(expected - computed) < 1.e-2)
    assert np.all(abs(part.condense_to_atoms(part.density) - computed) < 1.e-2)
Esempio n. 21
0
    def load_file(fnames):
        """Return `Molecule` instances corresponding to fnames.

        Parameters
        ----------
        fnames : str or Sequence of str
            Strings specifying the path to molecule's file, or sequence of strings specifying
            path to molecule files.
        """
        if isinstance(fnames, (str, unicode, Path)):
            # case of one file not given as a list
            molecule = Molecule.from_file(fnames)
        elif len(fnames) == 1 and isinstance(fnames[0], (str, unicode)):
            # case of one file given as a list
            molecule = Molecule.from_file(fnames[0])
        else:
            # case of multiple files
            molecule = [Molecule.from_file(fname) for fname in fnames]
        return molecule
Esempio n. 22
0
def test_global_quadratic_fd_h2o_fchk():
    ep, e0, en = -7.599493522312368E+01, -7.645980351270224E+01, -7.635212549312298E+01
    ip, ea, energy = ep - e0, e0 - en, e0
    # check quadratic global conceptual DFT model
    with path("chemtools.data", "h2o_q+0_ub3lyp_ccpvtz.fchk") as file1:
        with path("chemtools.data", "h2o_q-1_ub3lyp_ccpvtz.fchk") as file2:
            with path("chemtools.data", "h2o_q+1_ub3lyp_ccpvtz.fchk") as file3:
                fname = [file1, file2, file3]
                model1 = GlobalConceptualDFT.from_file(fname, "quadratic")
                molecule = [Molecule.from_file(item) for item in fname]
                model2 = GlobalConceptualDFT.from_molecule(
                    molecule, "quadratic")
    # cehck from_file
    check_global_reactivity_quadratic(model1, ip, ea, energy, 10)
    # check from_molecule
    check_global_reactivity_quadratic(model2, ip, ea, energy, 10)
    # rearrange input files
    with path("chemtools.data", "h2o_q+1_ub3lyp_ccpvtz.fchk") as file1:
        with path("chemtools.data", "h2o_q+0_ub3lyp_ccpvtz.fchk") as file2:
            with path("chemtools.data", "h2o_q-1_ub3lyp_ccpvtz.fchk") as file3:
                fname = [file1, file2, file3]
                # check from_file
                model1 = GlobalConceptualDFT.from_file(fname, "quadratic")
                molecule = [Molecule.from_file(item) for item in fname]
                model2 = GlobalConceptualDFT.from_molecule(
                    molecule, "quadratic")
    check_global_reactivity_quadratic(model1, ip, ea, energy, 10)
    # check from_molecule
    check_global_reactivity_quadratic(model2, ip, ea, energy, 10)
    # rearrange input files
    with path("chemtools.data", "h2o_q-1_ub3lyp_ccpvtz.fchk") as file1:
        with path("chemtools.data", "h2o_q+1_ub3lyp_ccpvtz.fchk") as file2:
            with path("chemtools.data", "h2o_q+0_ub3lyp_ccpvtz.fchk") as file3:
                fname = [file1, file2, file3]
                model1 = GlobalConceptualDFT.from_file(fname, "quadratic")
                molecule = [Molecule.from_file(item) for item in fname]
                model2 = GlobalConceptualDFT.from_molecule(
                    molecule, "quadratic")
    # check from_file
    check_global_reactivity_quadratic(model1, ip, ea, energy, 10)
    # check from_molecule
    check_global_reactivity_quadratic(model2, ip, ea, energy, 10)
Esempio n. 23
0
def test_condense_quadratic_from_molecule_fmr_mbis_ch4_wfn():
    # expected populations of CH4 computed with HORTON
    with path('chemtools.data', 'ch4_uhf_ccpvdz.wfn') as fname:
        molecule = Molecule.from_file(fname)
    expected = np.array([6.46038055, 0.88489494, 0.88492901, 0.88493897, 0.88492396])
    # check from_molecule given as a string
    model = CondensedConceptualDFT.from_molecule(molecule, "quadratic", "FMR", "mbis")
    check_condensed_reactivity(model, "quadratic", expected, None, None, 10)
    # check from_molecule given as a list
    model = CondensedConceptualDFT.from_molecule([molecule], "quadratic", "FMR", "mbis")
    check_condensed_reactivity(model, "quadratic", expected, None, None, 10)
Esempio n. 24
0
def test_get_dict_energy_raises():
    # check molecule
    with path('chemtools.data', 'ch4_uhf_ccpvdz.fchk') as file1:
        with path('chemtools.data', 'h2o_q+0_ub3lyp_ccpvtz.fchk') as file2:
            fname = [file1, file2]
            assert_raises(ValueError, get_dict_energy, fname)
            assert_raises(ValueError, get_dict_energy, str(file1))
            assert_raises(ValueError, get_dict_energy, "gibberish")
    # check repeated molecules
    with path('chemtools.data', 'ch4_uhf_ccpvdz.fchk') as fname:
        molecule = [
            Molecule.from_file(fname),
            Molecule.from_file(fname),
        ]
    assert_raises(ValueError, get_dict_energy, molecule)
    # check molecules with the same number of molecules
    with path('chemtools.data', 'ch4_uhf_ccpvdz.fchk') as file1:
        with path('chemtools.data', 'h2o_q+0_ub3lyp_ccpvtz.fchk') as file2:
            molecule = [Molecule.from_file(file1), Molecule.from_file(file2)]
    assert_raises(ValueError, get_dict_energy, molecule)
Esempio n. 25
0
def test_global_quadratic_from_molecule_fmo_h2o_anion_fchk():
    # FMO: ip = -E(H**O) & ea = -E(LUMO)
    ip, ea, energy = -1.93118022E-01, -2.69116912E-01, -7.635212549312298E+01
    with path("chemtools.data", "h2o_q-1_ub3lyp_ccpvtz.fchk") as fname:
        molecule = Molecule.from_file(fname)
    # check quadratic global conceptual DFT model from a fname given as string
    model = GlobalConceptualDFT.from_molecule(molecule, "quadratic")
    check_global_reactivity_quadratic(model, ip, ea, energy, 11)
    # check quadratic global conceptual DFT model from a fname given as a list of string
    model = GlobalConceptualDFT.from_molecule([molecule], "quadratic")
    check_global_reactivity_quadratic(model, ip, ea, energy, 11)
Esempio n. 26
0
    def from_file(cls, fname):
        """Initialize class from wave-function file.

        Parameters
        ----------
        fname : str
            Path to molecule's wave-function file.

        """
        molecule = Molecule.from_file(fname)
        return cls.from_molecule(molecule)
Esempio n. 27
0
def test_global_linear_from_molecule_fmo_h2o_anion_fchk():
    # FMO: ip = -E(H**O) & ea = -E(LUMO)
    ip, ea, energy = -1.93118022E-01, -2.69116912E-01, -7.635212549312298E+01
    with path('chemtools.data', 'h2o_q-1_ub3lyp_ccpvtz.fchk') as fname:
        molecule = Molecule.from_file(fname)
    # check from_molecule
    model = GlobalConceptualDFT.from_molecule(molecule, "linear")
    check_global_reactivity_linear(model, ip, ea, energy, 11)
    # check from_molecule given as a list
    model = GlobalConceptualDFT.from_molecule([molecule], "linear")
    check_global_reactivity_linear(model, ip, ea, energy, 11)
Esempio n. 28
0
    def from_file(cls, fname, scheme='mulliken'):
        """Initialize class from wave-function file.

        Parameters
        ----------
        fname : str
            Path to molecule's wave-function file.
        scheme : str
            Type of population analysis scheme.

        """
        return cls.from_molecule(Molecule.from_file(fname), scheme=scheme)
Esempio n. 29
0
    def from_file(cls, fname, points):
        """Initialize class from file.

        Parameters
        ----------
        fname : str
            Path to molecule's files.
        points : np.ndarray
            Grid points, given as a 2D array with 3 columns, used for calculating local properties.
        """
        molecule = Molecule.from_file(fname)
        return cls(molecule, points)
Esempio n. 30
0
def main_mot(args):
    """Build MOTBasedTool model and dump VMD script and cube files for visualizing MO."""
    if args.info:
        mol = Molecule.from_file(args.fname)
    else:
        mol, cube = load_molecule_and_grid(args.fname, args.cube)

    hia, hib = np.array(mol.homo_index) - 1
    lia, lib = np.array(mol.lumo_index) - 1
    ea, eb = mol.energy
    print("")
    print(("File: {0}".format(args.fname)))
    # print("Charge      : % 5f" % np.sum(mol.numbers) - np.sum(ne))
    # print("Multiplicity: % 5d" % np.max(ne) - np.min(ne) + 1)
    print("")
    print("Atomic number and coordinates:")
    for index, num in enumerate(mol.numbers):
        coord = mol.coordinates[index, :]
        print(("% 2i   %10.6f   %10.6f   %10.6f" %
               (num, coord[0], coord[1], coord[2])))
    print("")
    print("Information on alpha & beta electrons:")
    print(("# electrons  :  % 3.3f       % 3.3f" % mol.mo.nelectrons))
    print(("H**O index   : % 3d        % 5d" % mol.homo_index))
    print("")
    print(("LUMO+2 index : %10.6f   %10.6f" % (ea[lia + 2], eb[lib + 2])))
    print(("LUMO+1 energy: %10.6f   %10.6f" % (ea[lia + 1], eb[lib + 1])))
    print(("LUMO   energy: %10.6f   %10.6f" % mol.lumo_energy))
    print(("H**O   energy: %10.6f   %10.6f" % mol.homo_energy))
    print(("H**O-1 energy: %10.6f   %10.6f" % (ea[hia - 1], eb[hib - 1])))
    print(("H**O-2 energy: %10.6f   %10.6f" % (ea[hia - 2], eb[hib - 2])))
    print("")

    if args.info:
        return

    index = args.index
    if index is not None:
        index = [int(item) for item in index.split(",")]
        if len(index) == 1:
            index = index[0]

    # build model
    mot = OrbPart.from_molecule(mol)

    # dump files for visualization
    if args.output is None:
        args.output = args.fname.rsplit(".")[0]
    mot.generate_scripts(args.output,
                         spin=args.spin,
                         index=index,
                         grid=cube,
                         isosurf=args.isosurface)