Ejemplo n.º 1
0
    def form_operators(self) -> None:

        if self.program == Program.PySCF:
            from pyresponse.pyscf import integrals

            integral_generator = integrals.IntegralsPyscf(self.program_obj)
        elif self.program == Program.Psi4:
            from pyresponse.psi4 import integrals

            integral_generator = integrals.IntegralsPsi4(self.program_obj)
        else:
            raise RuntimeError

        if self.use_giao:
            integrals_angmom_ao = integral_generator.integrals(
                integrals.ANGMOM_GIAO)
        else:
            integrals_angmom_ao = integral_generator.integrals(
                integrals.ANGMOM_COMMON_GAUGE)
        operator_angmom = Operator(label="angmom",
                                   is_imaginary=True,
                                   is_spin_dependent=False,
                                   triplet=False)
        operator_angmom.ao_integrals = integrals_angmom_ao
        self.driver.add_operator(operator_angmom)
Ejemplo n.º 2
0
    def form_operators(self) -> None:

        if self.program == Program.PySCF:
            from pyresponse.pyscf import integrals

            integral_generator = integrals.IntegralsPyscf(self.program_obj)
        elif self.program == Program.Psi4:
            from pyresponse.psi4 import integrals

            integral_generator = integrals.IntegralsPsi4(self.program_obj)
        else:
            raise RuntimeError

        operator_angmom = Operator(
            label="angmom", is_imaginary=True, is_spin_dependent=False, triplet=False
        )
        operator_angmom.ao_integrals = integral_generator.integrals(integrals.ANGMOM_COMMON_GAUGE)
        self.driver.add_operator(operator_angmom)

        operator_diplen = Operator(
            label="dipole", is_imaginary=False, is_spin_dependent=False, triplet=False
        )
        operator_diplen.ao_integrals = integral_generator.integrals(integrals.DIPOLE)
        self.driver.add_operator(operator_diplen)

        if self.do_dipvel:
            operator_dipvel = Operator(
                label="dipvel", is_imaginary=True, is_spin_dependent=False, triplet=False
            )
            operator_dipvel.ao_integrals = integral_generator.integrals(integrals.DIPVEL)
            self.driver.add_operator(operator_dipvel)
Ejemplo n.º 3
0
 def add_operator(self, operator: Operator) -> None:
     # First dimension is the number of Cartesian components, next
     # two are the number of AOs.
     assert hasattr(operator, "ao_integrals")
     shape = operator.ao_integrals.shape
     assert len(shape) == 3
     assert shape[0] >= 1
     assert shape[1] == shape[2]
     operator.indices_closed_act = self.indices_closed_act
     operator.indices_closed_secondary = self.indices_closed_secondary
     operator.indices_act_secondary = self.indices_act_secondary
     # Form the property gradient.
     operator.form_rhs(self.mocoeffs, self.occupations)
     self.operators.append(operator)
Ejemplo n.º 4
0
    def form_operators(self) -> None:

        if self.program == Program.PySCF:
            from pyresponse.pyscf import integrals

            integral_generator = integrals.IntegralsPyscf(self.program_obj)
        elif self.program == Program.Psi4:
            from pyresponse.psi4 import integrals

            integral_generator = integrals.IntegralsPsi4(self.program_obj)
        else:
            raise RuntimeError

        # angular momentum
        operator_angmom = Operator(label="angmom",
                                   is_imaginary=True,
                                   is_spin_dependent=False,
                                   triplet=False)
        self.program_obj.set_common_orig(self.gauge_origin)
        operator_angmom.ao_integrals = integral_generator.integrals(
            integrals.ANGMOM_COMMON_GAUGE)
        self.driver.add_operator(operator_angmom)

        # spin-orbit (1-electron, exact nuclear charges)
        operator_spinorb = Operator(label="spinorb",
                                    is_imaginary=True,
                                    is_spin_dependent=False,
                                    triplet=False)
        integrals_spinorb_ao = 0
        for atm_id in range(self.program_obj.natm):
            self.program_obj.set_rinv_orig(self.program_obj.atom_coord(atm_id))
            chg = self.program_obj.atom_charge(atm_id)
            integrals_spinorb_ao += chg * integral_generator.integrals(
                integrals.SO_SPHER_1e)
        operator_spinorb.ao_integrals = integrals_spinorb_ao
        self.driver.add_operator(operator_spinorb)

        # spin-orbit (1-electron, effective nuclear charges)
        operator_spinorb_eff = Operator(label="spinorb_eff",
                                        is_imaginary=True,
                                        is_spin_dependent=False,
                                        triplet=False)
        integrals_spinorb_eff_ao = 0
        for atm_id in range(self.program_obj.natm):
            self.program_obj.set_rinv_orig(self.program_obj.atom_coord(atm_id))
            # chg = self.program_obj.atom_effective_charge[atm_id]
            chg = 0
            integrals_spinorb_eff_ao += chg * integral_generator.integrals(
                integrals.SO_SPHER_1e)
        operator_spinorb_eff.ao_integrals = integrals_spinorb_eff_ao
        self.driver.add_operator(operator_spinorb_eff)
Ejemplo n.º 5
0
    def form_operators(self):

        if self.program == Program.PySCF:
            from pyresponse.pyscf import integrals

            integral_generator = integrals.IntegralsPyscf(self.program_obj)
        elif self.program == Program.Psi4:
            from pyresponse.psi4 import integrals

            integral_generator = integrals.IntegralsPsi4(self.program_obj)
        else:
            raise RuntimeError

        operator_diplen = Operator(label="dipole",
                                   is_imaginary=False,
                                   is_spin_dependent=False,
                                   triplet=False)
        operator_diplen.ao_integrals = integral_generator.integrals(
            integrals.DIPOLE)
        self.driver.add_operator(operator_diplen)
Ejemplo n.º 6
0
def dalton_label_to_operator(label: str) -> Operator:

    label = clean_dalton_label(label)

    coord1_to_slice = {"x": 0, "y": 1, "z": 2}
    coord2_to_slice = {
        "xx": 0,
        "xy": 1,
        "xz": 2,
        "yy": 3,
        "yz": 4,
        "zz": 5,
        "yx": 1,
        "zx": 2,
        "zy": 4,
    }
    slice_to_coord1 = {v: k for (k, v) in coord1_to_slice.items()}

    # dipole length
    if "diplen" in label:
        operator_label = "dipole"
        _coord = label[0]
        slice_idx = coord1_to_slice[_coord]
        is_imaginary = False
        is_spin_dependent = False
    # dipole velocity
    elif "dipvel" in label:
        operator_label = "dipvel"
        _coord = label[0]
        slice_idx = coord1_to_slice[_coord]
        is_imaginary = True
        is_spin_dependent = False
    # angular momentum
    elif "angmom" in label:
        operator_label = "angmom"
        _coord = label[0]
        slice_idx = coord1_to_slice[_coord]
        is_imaginary = True
        is_spin_dependent = False
    # spin-orbit
    elif "spnorb" in label:
        operator_label = "spinorb"
        _coord = label[0]
        slice_idx = coord1_to_slice[_coord]
        is_imaginary = True
        is_spin_dependent = True
        _nelec = label[1]
        if _nelec in ("1", "2"):
            operator_label += _nelec
        # combined one- and two-electron
        elif _nelec in (" ", "_"):
            operator_label += "c"
        else:
            pass
    # Fermi contact
    elif "fc" in label:
        operator_label = "fermi"
        _atomid = label[6 : 6 + 2]
        slice_idx = int(_atomid) - 1
        is_imaginary = False
        is_spin_dependent = True
    # spin-dipole
    elif "sd" in label:
        operator_label = "sd"
        _coord_atom = label[3 : 3 + 3]
        _coord = label[7]
        _atomid = (int(_coord_atom) - 1) // 3
        _coord_1 = (int(_coord_atom) - 1) % 3
        _coord_2 = slice_to_coord1[_coord_1] + _coord
        slice_idx = (6 * _atomid) + coord2_to_slice[_coord_2]
        is_imaginary = False
        is_spin_dependent = True
    # TODO SD+FC?
    # nucleus-orbit
    elif "pso" in label:
        operator_label = "pso"
        # TODO coord manipulation
        is_imaginary = True
        # TODO is this correct?
        is_spin_dependent = False
        # FIXME
        slice_idx = None
    else:
        operator_label = ""
        is_imaginary = None
        is_spin_dependent = None
        slice_idx = None

    operator = Operator(
        label=operator_label,
        is_imaginary=is_imaginary,
        is_spin_dependent=is_spin_dependent,
        slice_idx=slice_idx,
    )

    return operator
def test_atomic_polar_tensor_rhf():
    mol = molecules.molecule_physicists_water_sto3g()
    mol.reset_point_group("c1")
    mol.update_geometry()
    psi4.core.set_active_molecule(mol)

    options = {
        "BASIS": "STO-3G",
        "SCF_TYPE": "PK",
        "E_CONVERGENCE": 1e-10,
        "D_CONVERGENCE": 1e-10,
    }

    psi4.set_options(options)

    _, wfn = psi4.energy("hf", return_wfn=True)
    mints = psi4.core.MintsHelper(wfn)

    C = mocoeffs_from_psi4wfn(wfn)
    E = moenergies_from_psi4wfn(wfn)
    occupations = occupations_from_psi4wfn(wfn)
    nocc, nvir, _, _ = occupations
    norb = nocc + nvir

    # electric perturbation part
    ao2mo = AO2MO(C, occupations, I=np.asarray(mints.ao_eri()))
    ao2mo.perform_rhf_full()
    solver = ExactInv(C, E, occupations)
    solver.tei_mo = ao2mo.tei_mo
    solver.tei_mo_type = "full"
    driver = CPHF(solver)
    operator_diplen = Operator(label="dipole",
                               is_imaginary=False,
                               is_spin_dependent=False,
                               triplet=False)
    # integrals_diplen_ao = self.pyscfmol.intor('cint1e_r_sph', comp=3)
    M = np.stack([np.asarray(Mc) for Mc in mints.ao_dipole()])
    operator_diplen.ao_integrals = M
    driver.add_operator(operator_diplen)

    # geometric perturbation part
    operator_geometric = Operator(label="nuclear",
                                  is_imaginary=False,
                                  is_spin_dependent=False,
                                  triplet=False)
    operator_geometric.form_rhs_geometric(C, occupations, mol.natom(),
                                          solver.tei_mo[0], mints)
    print(operator_geometric.label)
    print(operator_geometric.mo_integrals_ai_alph)
    print(operator_diplen.label)
    print(operator_diplen.mo_integrals_ai_alph)
    # hack for dim check in solver
    operator_geometric.ao_integrals = np.zeros(
        (3 * mol.natom(), M.shape[1], M.shape[2]))
    # bypass driver's call to form_rhs
    driver.solver.operators.append(operator_geometric)

    driver.run()
    print(driver.results[0])
    print(driver.results[0].T)
    print(driver.results[0] - driver.results[0].T)
    print(operator_geometric.rspvecs_alph[0])
    # Nuclear contribution to dipole gradient
    # Electronic contributions to static part of dipole gradient
    # Reorthonormalization part of dipole gradient
    # Static contribution to dipole gradient
    # Relaxation part of dipole gradient
    # Total dipole gradient - TRAROT

    print("Nuclear contribution to dipole gradient")
    natom = mol.natom()
    Z = np.asarray([mol.Z(i) for i in range(natom)])
    nuclear_contrib = np.concatenate(
        [np.diag(Z.take(3 * [i])) for i in range(natom)])
    print(nuclear_contrib)

    return locals()