コード例 #1
0
    def dump(
        driver_result: ElectronicStructureDriverResult,
        outpath: str,
        orbsym: Optional[List[str]] = None,
        isym: int = 1,
    ) -> None:
        """Convenience method to produce an FCIDump output file.

        Args:
            outpath: Path to the output file.
            driver_result: The ElectronicStructureDriverResult to be dumped. It is assumed that the
                nuclear_repulsion_energy contains the inactive core energy in its ElectronicEnergy
                property.
            orbsym: A list of spatial symmetries of the orbitals.
            isym: The spatial symmetry of the wave function.
        """
        particle_number = cast(ParticleNumber, driver_result.get_property(ParticleNumber))
        electronic_energy = cast(ElectronicEnergy, driver_result.get_property(ElectronicEnergy))
        one_body_integrals = electronic_energy.get_electronic_integral(ElectronicBasis.MO, 1)
        two_body_integrals = electronic_energy.get_electronic_integral(ElectronicBasis.MO, 2)
        dump(
            outpath,
            particle_number.num_spin_orbitals // 2,
            particle_number.num_alpha + particle_number.num_beta,
            one_body_integrals._matrices,  # type: ignore
            two_body_integrals._matrices[0:3],  # type: ignore
            electronic_energy.nuclear_repulsion_energy,
            ms2=driver_result.molecule.multiplicity - 1,
            orbsym=orbsym,
            isym=isym,
        )
コード例 #2
0
    def _populate_driver_result_electronic_energy(
            self, driver_result: ElectronicStructureDriverResult) -> None:
        # pylint: disable=import-error
        from pyquante2 import onee_integrals
        from pyquante2.ints.integrals import twoe_integrals

        basis_transform = driver_result.get_property(ElectronicBasisTransform)

        integrals = onee_integrals(self._bfs, self._mol)

        hij = integrals.T + integrals.V
        hijkl = twoe_integrals(self._bfs)

        one_body_ao = OneBodyElectronicIntegrals(ElectronicBasis.AO,
                                                 (hij, None))

        two_body_ao = TwoBodyElectronicIntegrals(
            ElectronicBasis.AO,
            (hijkl.transform(np.identity(self._nmo)), None, None, None),
        )

        one_body_mo = one_body_ao.transform_basis(basis_transform)
        two_body_mo = two_body_ao.transform_basis(basis_transform)

        electronic_energy = ElectronicEnergy(
            [one_body_ao, two_body_ao, one_body_mo, two_body_mo],
            nuclear_repulsion_energy=self._mol.nuclear_repulsion(),
            reference_energy=self._calc.energy,
        )

        if hasattr(self._calc, "orbe"):
            orbs_energy = self._calc.orbe
            orbs_energy_b = None
        else:
            orbs_energy = self._calc.orbea
            orbs_energy_b = self._calc.orbeb

        orbital_energies = ((orbs_energy, orbs_energy_b)
                            if orbs_energy_b is not None else orbs_energy)
        electronic_energy.orbital_energies = np.asarray(orbital_energies)

        electronic_energy.kinetic = OneBodyElectronicIntegrals(
            ElectronicBasis.AO, (integrals.T, None))
        electronic_energy.overlap = OneBodyElectronicIntegrals(
            ElectronicBasis.AO, (integrals.S, None))

        driver_result.add_property(electronic_energy)
コード例 #3
0
    def _populate_driver_result_electronic_energy(
        self, driver_result: ElectronicStructureDriverResult
    ) -> None:
        # pylint: disable=import-error
        from pyscf import gto

        basis_transform = driver_result.get_property(ElectronicBasisTransform)

        one_body_ao = OneBodyElectronicIntegrals(
            ElectronicBasis.AO,
            (self._calc.get_hcore(), None),
        )

        two_body_ao = TwoBodyElectronicIntegrals(
            ElectronicBasis.AO,
            (self._mol.intor("int2e", aosym=1), None, None, None),
        )

        one_body_mo = one_body_ao.transform_basis(basis_transform)
        two_body_mo = two_body_ao.transform_basis(basis_transform)

        electronic_energy = ElectronicEnergy(
            [one_body_ao, two_body_ao, one_body_mo, two_body_mo],
            nuclear_repulsion_energy=gto.mole.energy_nuc(self._mol),
            reference_energy=self._calc.e_tot,
        )

        electronic_energy.kinetic = OneBodyElectronicIntegrals(
            ElectronicBasis.AO,
            (self._mol.intor_symmetric("int1e_kin"), None),
        )
        electronic_energy.overlap = OneBodyElectronicIntegrals(
            ElectronicBasis.AO,
            (self._calc.get_ovlp(), None),
        )

        orbs_energy, orbs_energy_b = self._extract_mo_data("mo_energy")
        orbital_energies = (
            (orbs_energy, orbs_energy_b) if orbs_energy_b is not None else orbs_energy
        )
        electronic_energy.orbital_energies = np.asarray(orbital_energies)

        driver_result.add_property(electronic_energy)
コード例 #4
0
    def _populate_driver_result_electronic_dipole_moment(
        self, driver_result: ElectronicStructureDriverResult
    ) -> None:
        basis_transform = driver_result.get_property(ElectronicBasisTransform)

        self._mol.set_common_orig((0, 0, 0))
        ao_dip = self._mol.intor_symmetric("int1e_r", comp=3)

        d_m = self._calc.make_rdm1(self._calc.mo_coeff, self._calc.mo_occ)

        if not (isinstance(d_m, np.ndarray) and d_m.ndim == 2):
            d_m = d_m[0] + d_m[1]

        elec_dip = np.negative(np.einsum("xij,ji->x", ao_dip, d_m).real)
        elec_dip = np.round(elec_dip, decimals=8)
        nucl_dip = np.einsum("i,ix->x", self._mol.atom_charges(), self._mol.atom_coords())
        nucl_dip = np.round(nucl_dip, decimals=8)

        logger.info("HF Electronic dipole moment: %s", elec_dip)
        logger.info("Nuclear dipole moment: %s", nucl_dip)
        logger.info("Total dipole moment: %s", nucl_dip + elec_dip)

        x_dip_ints = OneBodyElectronicIntegrals(ElectronicBasis.AO, (ao_dip[0], None))
        y_dip_ints = OneBodyElectronicIntegrals(ElectronicBasis.AO, (ao_dip[1], None))
        z_dip_ints = OneBodyElectronicIntegrals(ElectronicBasis.AO, (ao_dip[2], None))

        x_dipole = DipoleMoment("x", [x_dip_ints, x_dip_ints.transform_basis(basis_transform)])
        y_dipole = DipoleMoment("y", [y_dip_ints, y_dip_ints.transform_basis(basis_transform)])
        z_dipole = DipoleMoment("z", [z_dip_ints, z_dip_ints.transform_basis(basis_transform)])

        driver_result.add_property(
            ElectronicDipoleMoment(
                [x_dipole, y_dipole, z_dipole],
                nuclear_dipole_moment=nucl_dip,
                reverse_dipole_sign=True,
            )
        )