Exemple #1
0
def test_orb0_hf_sto3g():
    tmpdir, fn_fchk = setup_gaussian("hf_sto3g")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    weights = fchk.fields["Alpha MO coefficients"][:basis.num_dof]
    points = ref_data_hf_sto3g_orb0[:,:3]
    fns = basis.call_gint_grid(gint1_fns_basis, weights.reshape((1,-1)), points*angstrom, 1)[0]
    assert(abs(fns-ref_data_hf_sto3g_orb0[:,3]).max() < 1e-10)
Exemple #2
0
def test_orb0_hf_sto3g():
    tmpdir, fn_fchk = setup_gaussian("hf_sto3g")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    weights = fchk.fields["Alpha MO coefficients"][:basis.num_dof]
    points = ref_data_hf_sto3g_orb0[:, :3]
    fns = basis.call_gint_grid(gint1_fns_basis, weights.reshape((1, -1)),
                               points * angstrom, 1)[0]
    assert (abs(fns - ref_data_hf_sto3g_orb0[:, 3]).max() < 1e-10)
Exemple #3
0
def test_orb0_o2_cc_pvtz_pure():
    tmpdir, fn_fchk = setup_gaussian("o2_cc_pvtz_pure")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    weights = fchk.fields["Alpha MO coefficients"][:basis.num_dof]
    weights = weights[basis.g03_permutation]
    points = ref_data_o2_cc_pvtz_pure_orb0[:,:3]
    fns = basis.call_gint_grid(gint1_fns_basis, weights.reshape((1,-1)), points*angstrom, 1)[0]
    assert(abs(fns-ref_data_o2_cc_pvtz_pure_orb0[:,3]).max() < 1e-10)
Exemple #4
0
def test_orb0_o2_cc_pvtz_pure():
    tmpdir, fn_fchk = setup_gaussian("o2_cc_pvtz_pure")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    weights = fchk.fields["Alpha MO coefficients"][:basis.num_dof]
    weights = weights[basis.g03_permutation]
    points = ref_data_o2_cc_pvtz_pure_orb0[:, :3]
    fns = basis.call_gint_grid(gint1_fns_basis, weights.reshape((1, -1)),
                               points * angstrom, 1)[0]
    assert (abs(fns - ref_data_o2_cc_pvtz_pure_orb0[:, 3]).max() < 1e-10)
Exemple #5
0
def test_orb0_h_sto3g():
    tmpdir, fn_fchk = setup_gaussian("h_sto3g")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    # real test for the output
    weights = fchk.fields["Alpha MO coefficients"][:basis.num_dof]
    points = ref_data_h_sto3g_orb0[:,:3]
    fns = basis.call_gint_grid(gint1_fns_basis, weights.reshape((1,-1)), points*angstrom, 1)[0]
    assert(abs(fns-ref_data_h_sto3g_orb0[:,3]).max() < 1e-10)
    # test error mechanism
    basis.shell_types[0] = 102
    assert_raises(ValueError, basis.call_gint_grid, gint1_fns_basis, weights.reshape((1,-1)), points*angstrom, 1)
    basis.shell_types[0] = -763
    assert_raises(ValueError, basis.call_gint_grid, gint1_fns_basis, weights.reshape((1,-1)), points*angstrom, 1)
Exemple #6
0
def test_pot_h_sto3g():
    tmpdir, fn_fchk = setup_gaussian("h_sto3g")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    # real test for the output
    dmat = fchk.fields["Total SCF Density"]
    points = ref_data_h_sto3g_pot[:,:3]*angstrom
    radius = numpy.sqrt((points**2).sum(axis=1))
    ref_data_h_sto3g_pot[:,3] -= 1/radius
    potential = -basis.call_gint_grid(gint2_nai_dmat, dmat, points)
    assert(abs(potential-ref_data_h_sto3g_pot[:,3]).max() < 1e-8)
    # test error mechanism
    basis.shell_types[0] = 102
    assert_raises(ValueError, basis.call_gint_grid, gint2_nai_dmat, dmat, points*angstrom)
    basis.shell_types[0] = -763
    assert_raises(ValueError, basis.call_gint_grid, gint2_nai_dmat, dmat, points*angstrom)
Exemple #7
0
def test_dens_h_sto3g():
    tmpdir, fn_fchk = setup_gaussian("h_sto3g")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    weights = fchk.fields["Alpha MO coefficients"][:basis.num_dof]
    weights = weights[basis.g03_permutation]
    points = ref_data_h_sto3g_orb0[:,:3]
    orb0 = basis.call_gint_grid(gint1_fns_basis, weights.reshape((1,-1)), points*angstrom, 1)[0]
    num_dmat = (basis.num_dof*(basis.num_dof+1))/2
    dmat = fchk.fields["Total SCF Density"][:num_dmat]
    density = basis.call_gint_grid(gint1_fn_dmat, dmat, points*angstrom)
    assert(abs(orb0**2-density).max() < 1e-10)
    # test error mechanism
    basis.shell_types[0] = 102
    assert_raises(ValueError, basis.call_gint_grid, gint1_fn_dmat, dmat, points*angstrom, 1)
    basis.shell_types[0] = -763
    assert_raises(ValueError, basis.call_gint_grid, gint1_fn_dmat, dmat, points*angstrom, 1)
Exemple #8
0
def test_orb0_h_sto3g():
    tmpdir, fn_fchk = setup_gaussian("h_sto3g")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    # real test for the output
    weights = fchk.fields["Alpha MO coefficients"][:basis.num_dof]
    points = ref_data_h_sto3g_orb0[:, :3]
    fns = basis.call_gint_grid(gint1_fns_basis, weights.reshape((1, -1)),
                               points * angstrom, 1)[0]
    assert (abs(fns - ref_data_h_sto3g_orb0[:, 3]).max() < 1e-10)
    # test error mechanism
    basis.shell_types[0] = 102
    assert_raises(ValueError, basis.call_gint_grid, gint1_fns_basis,
                  weights.reshape((1, -1)), points * angstrom, 1)
    basis.shell_types[0] = -763
    assert_raises(ValueError, basis.call_gint_grid, gint1_fns_basis,
                  weights.reshape((1, -1)), points * angstrom, 1)
Exemple #9
0
def test_pot_o2_cc_pvtz_pure():
    tmpdir, fn_fchk = setup_gaussian("o2_cc_pvtz_pure")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    dmat = fchk.fields["Total SCF Density"]
    reorder_dmat(dmat, basis.g03_permutation)
    points = ref_data_o2_cc_pvtz_pure_pot[:,:3]*angstrom
    ref_potential = ref_data_o2_cc_pvtz_pure_pot[:,3]
    nuc_potential = 0.0
    for i in xrange(fchk.molecule.size):
        center = fchk.molecule.coordinates[i]
        Z = fchk.molecule.numbers[i]
        radius = numpy.sqrt(((points-center)**2).sum(axis=1))
        nuc_potential += Z/radius
    ref_potential -= nuc_potential
    potential = -basis.call_gint_grid(gint2_nai_dmat, dmat, points)
    assert(abs(potential-ref_potential).max() < 1e-6)
Exemple #10
0
def test_pot_o2_cc_pvtz_pure():
    tmpdir, fn_fchk = setup_gaussian("o2_cc_pvtz_pure")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    dmat = fchk.fields["Total SCF Density"]
    reorder_dmat(dmat, basis.g03_permutation)
    points = ref_data_o2_cc_pvtz_pure_pot[:, :3] * angstrom
    ref_potential = ref_data_o2_cc_pvtz_pure_pot[:, 3]
    nuc_potential = 0.0
    for i in xrange(fchk.molecule.size):
        center = fchk.molecule.coordinates[i]
        Z = fchk.molecule.numbers[i]
        radius = numpy.sqrt(((points - center)**2).sum(axis=1))
        nuc_potential += Z / radius
    ref_potential -= nuc_potential
    potential = -basis.call_gint_grid(gint2_nai_dmat, dmat, points)
    assert (abs(potential - ref_potential).max() < 1e-6)
Exemple #11
0
def test_pot_h_sto3g():
    tmpdir, fn_fchk = setup_gaussian("h_sto3g")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    # real test for the output
    dmat = fchk.fields["Total SCF Density"]
    points = ref_data_h_sto3g_pot[:, :3] * angstrom
    radius = numpy.sqrt((points**2).sum(axis=1))
    ref_data_h_sto3g_pot[:, 3] -= 1 / radius
    potential = -basis.call_gint_grid(gint2_nai_dmat, dmat, points)
    assert (abs(potential - ref_data_h_sto3g_pot[:, 3]).max() < 1e-8)
    # test error mechanism
    basis.shell_types[0] = 102
    assert_raises(ValueError, basis.call_gint_grid, gint2_nai_dmat, dmat,
                  points * angstrom)
    basis.shell_types[0] = -763
    assert_raises(ValueError, basis.call_gint_grid, gint2_nai_dmat, dmat,
                  points * angstrom)
Exemple #12
0
def test_dens_h_sto3g():
    tmpdir, fn_fchk = setup_gaussian("h_sto3g")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    weights = fchk.fields["Alpha MO coefficients"][:basis.num_dof]
    weights = weights[basis.g03_permutation]
    points = ref_data_h_sto3g_orb0[:, :3]
    orb0 = basis.call_gint_grid(gint1_fns_basis, weights.reshape((1, -1)),
                                points * angstrom, 1)[0]
    num_dmat = (basis.num_dof * (basis.num_dof + 1)) / 2
    dmat = fchk.fields["Total SCF Density"][:num_dmat]
    density = basis.call_gint_grid(gint1_fn_dmat, dmat, points * angstrom)
    assert (abs(orb0**2 - density).max() < 1e-10)
    # test error mechanism
    basis.shell_types[0] = 102
    assert_raises(ValueError, basis.call_gint_grid, gint1_fn_dmat, dmat,
                  points * angstrom, 1)
    basis.shell_types[0] = -763
    assert_raises(ValueError, basis.call_gint_grid, gint1_fn_dmat, dmat,
                  points * angstrom, 1)
Exemple #13
0
def test_dens_o2_cc_pvtz_pure():
    tmpdir, fn_fchk = setup_gaussian("o2_cc_pvtz_pure")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    num_dmat = (basis.num_dof*(basis.num_dof+1))/2

    points = ref_data_o2_cc_pvtz_pure_orb0[:,:3]

    dmat = fchk.fields["Total SCF Density"][:num_dmat]
    reorder_dmat(dmat, basis.g03_permutation)
    density = basis.call_gint_grid(gint1_fn_dmat, dmat, points*angstrom)

    num_alpha = fchk.fields["Number of alpha electrons"]
    weights = fchk.fields["Alpha MO coefficients"][:num_alpha*basis.num_dof]
    weights = weights.reshape((num_alpha, basis.num_dof))
    weights = weights[:,basis.g03_permutation]
    orbitals = basis.call_gint_grid(gint1_fns_basis, weights, points*angstrom, num_alpha)
    assert(orbitals.shape == (num_alpha, len(points)))
    expected_density = 2*(orbitals**2).sum(axis=0)

    assert(abs(density-expected_density).max() < 1e-6)
Exemple #14
0
def test_dens_o2_cc_pvtz_pure():
    tmpdir, fn_fchk = setup_gaussian("o2_cc_pvtz_pure")
    fchk = FCHKFile(fn_fchk)
    shutil.rmtree(tmpdir)
    basis = GaussianBasis.from_fchk(fchk)
    num_dmat = (basis.num_dof * (basis.num_dof + 1)) / 2

    points = ref_data_o2_cc_pvtz_pure_orb0[:, :3]

    dmat = fchk.fields["Total SCF Density"][:num_dmat]
    reorder_dmat(dmat, basis.g03_permutation)
    density = basis.call_gint_grid(gint1_fn_dmat, dmat, points * angstrom)

    num_alpha = fchk.fields["Number of alpha electrons"]
    weights = fchk.fields["Alpha MO coefficients"][:num_alpha * basis.num_dof]
    weights = weights.reshape((num_alpha, basis.num_dof))
    weights = weights[:, basis.g03_permutation]
    orbitals = basis.call_gint_grid(gint1_fns_basis, weights,
                                    points * angstrom, num_alpha)
    assert (orbitals.shape == (num_alpha, len(points)))
    expected_density = 2 * (orbitals**2).sum(axis=0)

    assert (abs(density - expected_density).max() < 1e-6)
Exemple #15
0
    def __init__(self, filename, options):
        if len(options) == 1:
            density_type = options[0]
        elif len(options) == 0:
            density_type = None
        else:
            raise ValueError("Only one option is supported for the FCHKWaveFunction")
        self.filename = filename
        self.options = options
        self.prefix = filename[:-5]
        fchk = FCHKFile(filename)
        # for use by the rest of the program
        self.charge = fchk.fields["Charge"]
        self.num_orbitals = fchk.fields["Number of basis functions"]
        self.dipole = fchk.fields["Dipole Moment"]
        self.num_electrons = fchk.fields["Number of electrons"]
        self.num_alpha = fchk.fields["Number of alpha electrons"]
        self.num_beta = fchk.fields["Number of beta electrons"]
        self.restricted = "Beta Orbital Energies" not in fchk.fields
        self.molecule = fchk.molecule
        self.nuclear_charges = fchk.fields["Nuclear charges"]
        # for internal usage
        if density_type is None:
            if "mp2" in fchk.lot.lower():
                density_type = "mp2"
            elif "mp3" in fchk.lot.lower():
                density_type = "mp3"
            elif "mp4" in fchk.lot.lower():
                density_type = "mp4"
            else:
                density_type = "scf"
        # electronic structure data
        self.basis = GaussianBasis.from_fchk(fchk)
        # orbitals
        self.alpha_orbital_energies = None
        self.beta_orbital_energies = None
        self.natural_orbitals = None
        self.alpha_orbitals = None
        self.beta_orbitals = None
        self.alpha_occupations = None
        self.beta_occupations = None
        self.natural_occupations = None
        if density_type == "scf":
            # Load orbital stuff only for scf computations.
            self.alpha_orbital_energies = fchk.fields["Alpha Orbital Energies"]
            self.beta_orbital_energies = fchk.fields.get("Beta Orbital Energies", self.alpha_orbital_energies)
            self.alpha_orbitals = fchk.fields["Alpha MO coefficients"].reshape((-1,self.basis.num_dof))
            self.alpha_orbitals = self.alpha_orbitals[:,self.basis.g03_permutation]
            self.beta_orbitals = fchk.fields.get("Beta MO coefficients")
            if self.beta_orbitals is None:
                self.beta_orbitals = self.alpha_orbitals
            else:
                self.beta_orbitals = self.beta_orbitals.reshape((-1,self.basis.num_dof))[:,self.basis.g03_permutation]
            self.alpha_occupations = numpy.zeros(self.num_orbitals, float)
            self.alpha_occupations[:self.num_alpha] = 1.0
            if self.beta_orbitals is None:
                self.beta_occupations = self.alpha_occupations
            else:
                self.beta_occupations = numpy.zeros(self.num_orbitals, float)
                self.beta_occupations[:self.num_beta] = 1.0
            if self.restricted:
                self.natural_orbitals = self.alpha_orbitals
                self.natural_occupations = self.alpha_occupations + self.beta_occupations
                self.num_natural = max(self.num_alpha, self.num_beta)

        # density matrices
        hack_fchk = self.restricted and (self.num_alpha != self.num_beta) and density_type == "scf"
        if hack_fchk:
            # construct density matrices manually because the fchk file
            # contains the wrong one. we only do this for scf computations.
            n = self.basis.num_dof
            size = (n*(n+1))/2
            self.density_matrix = numpy.zeros(size, float)
            add_orbitals_to_dmat(self.alpha_orbitals[:self.num_alpha], self.density_matrix)
            add_orbitals_to_dmat(self.beta_orbitals[:self.num_beta], self.density_matrix)
            self.spin_density_matrix = numpy.zeros(size, float)
            num_min = min(self.num_alpha, self.num_beta)
            num_max = max(self.num_alpha, self.num_beta)
            add_orbitals_to_dmat(self.alpha_orbitals[num_min:num_max], self.spin_density_matrix)
        else:
            self.density_matrix = None
            self.spin_density_matrix = None
            # load the density matrices
            for key in fchk.fields:
                if key.startswith("Total") and key.endswith("Density"):
                    if key[6:-8].lower() != density_type:
                        continue
                    assert self.density_matrix is None
                    dmat = fchk.fields[key]
                    reorder_dmat(dmat, self.basis.g03_permutation)
                    self.density_matrix = dmat
                elif key.startswith("Spin") and key.endswith("Density"):
                    if key[5:-8].lower() != density_type:
                        continue
                    assert self.spin_density_matrix is None
                    dmat = fchk.fields[key]
                    reorder_dmat(dmat, self.basis.g03_permutation)
                    self.spin_density_matrix = dmat
            if self.density_matrix is None:
                raise ValueError("Could not find the '%s' density matrix in the fchk file." % self._density_type)
Exemple #16
0
    def __init__(self, filename, options):
        if len(options) == 1:
            density_type = options[0]
        elif len(options) == 0:
            density_type = None
        else:
            raise ValueError(
                "Only one option is supported for the FCHKWaveFunction")
        self.filename = filename
        self.options = options
        self.prefix = filename[:-5]
        fchk = FCHKFile(filename)
        # for use by the rest of the program
        self.charge = fchk.fields["Charge"]
        self.num_orbitals = fchk.fields["Number of basis functions"]
        self.dipole = fchk.fields["Dipole Moment"]
        self.num_electrons = fchk.fields["Number of electrons"]
        self.num_alpha = fchk.fields["Number of alpha electrons"]
        self.num_beta = fchk.fields["Number of beta electrons"]
        self.restricted = "Beta Orbital Energies" not in fchk.fields
        self.molecule = fchk.molecule
        self.nuclear_charges = fchk.fields["Nuclear charges"]
        # for internal usage
        if density_type is None:
            if "mp2" in fchk.lot.lower():
                density_type = "mp2"
            elif "mp3" in fchk.lot.lower():
                density_type = "mp3"
            elif "mp4" in fchk.lot.lower():
                density_type = "mp4"
            else:
                density_type = "scf"
        # electronic structure data
        self.basis = GaussianBasis.from_fchk(fchk)
        # orbitals
        self.alpha_orbital_energies = None
        self.beta_orbital_energies = None
        self.natural_orbitals = None
        self.alpha_orbitals = None
        self.beta_orbitals = None
        self.alpha_occupations = None
        self.beta_occupations = None
        self.natural_occupations = None
        if density_type == "scf":
            # Load orbital stuff only for scf computations.
            self.alpha_orbital_energies = fchk.fields["Alpha Orbital Energies"]
            self.beta_orbital_energies = fchk.fields.get(
                "Beta Orbital Energies", self.alpha_orbital_energies)
            self.alpha_orbitals = fchk.fields["Alpha MO coefficients"].reshape(
                (-1, self.basis.num_dof))
            self.alpha_orbitals = self.alpha_orbitals[:, self.basis.
                                                      g03_permutation]
            self.beta_orbitals = fchk.fields.get("Beta MO coefficients")
            if self.beta_orbitals is None:
                self.beta_orbitals = self.alpha_orbitals
            else:
                self.beta_orbitals = self.beta_orbitals.reshape(
                    (-1, self.basis.num_dof))[:, self.basis.g03_permutation]
            self.alpha_occupations = numpy.zeros(self.num_orbitals, float)
            self.alpha_occupations[:self.num_alpha] = 1.0
            if self.beta_orbitals is None:
                self.beta_occupations = self.alpha_occupations
            else:
                self.beta_occupations = numpy.zeros(self.num_orbitals, float)
                self.beta_occupations[:self.num_beta] = 1.0
            if self.restricted:
                self.natural_orbitals = self.alpha_orbitals
                self.natural_occupations = self.alpha_occupations + self.beta_occupations
                self.num_natural = max(self.num_alpha, self.num_beta)

        # density matrices
        hack_fchk = self.restricted and (
            self.num_alpha != self.num_beta) and density_type == "scf"
        if hack_fchk:
            # construct density matrices manually because the fchk file
            # contains the wrong one. we only do this for scf computations.
            n = self.basis.num_dof
            size = (n * (n + 1)) / 2
            self.density_matrix = numpy.zeros(size, float)
            add_orbitals_to_dmat(self.alpha_orbitals[:self.num_alpha],
                                 self.density_matrix)
            add_orbitals_to_dmat(self.beta_orbitals[:self.num_beta],
                                 self.density_matrix)
            self.spin_density_matrix = numpy.zeros(size, float)
            num_min = min(self.num_alpha, self.num_beta)
            num_max = max(self.num_alpha, self.num_beta)
            add_orbitals_to_dmat(self.alpha_orbitals[num_min:num_max],
                                 self.spin_density_matrix)
        else:
            self.density_matrix = None
            self.spin_density_matrix = None
            # load the density matrices
            for key in fchk.fields:
                if key.startswith("Total") and key.endswith("Density"):
                    if key[6:-8].lower() != density_type:
                        continue
                    assert self.density_matrix is None
                    dmat = fchk.fields[key]
                    reorder_dmat(dmat, self.basis.g03_permutation)
                    self.density_matrix = dmat
                elif key.startswith("Spin") and key.endswith("Density"):
                    if key[5:-8].lower() != density_type:
                        continue
                    assert self.spin_density_matrix is None
                    dmat = fchk.fields[key]
                    reorder_dmat(dmat, self.basis.g03_permutation)
                    self.spin_density_matrix = dmat
            if self.density_matrix is None:
                raise ValueError(
                    "Could not find the '%s' density matrix in the fchk file."
                    % self._density_type)