def ifc(filename="SIRIFC", ifc_=None): """ Return inactive/active densities from orbitals on interface file SIRIFC """ if ifc_ is None: ifc_ = sirifc.sirifc(filename) Di = blocked.BlockDiagonalMatrix(ifc_.nbas, ifc_.nbas) for isym in range(ifc_.nsym): if ifc_.nish[isym]: Ci = ifc_.cmo.subblock[isym] Cocci = Ci[:, : ifc_.nish[isym]] Di.subblock[isym] = 2 * Cocci @ Cocci.T Di = Di.unblock() if ifc_.nasht: cmoa = blocked.BlockDiagonalMatrix(ifc_.nbas, ifc_.nash) for isym in range(ifc_.nsym): if ifc_.nash[isym]: nishi = ifc_.nish[isym] nocci = ifc_.nish[isym] + ifc_.nash[isym] cmoa.subblock[isym] = ifc_.cmo.subblock[isym][:, nishi:nocci] cmoa = cmoa.unblock() Dv = cmoa @ ifc_.dv.unpack() @ cmoa.T else: Dv = full.matrix((ifc_.nbast, ifc_.nbast)) return Di, Dv
def get_occ_density(self, occnum): densities = blocked.BlockDiagonalMatrix(self.basinfo.nbas, self.basinfo.nbas) for dens, occ, cmo in zip(densities, occnum, self.cmo): for i, ni in enumerate(occ): dens += ni * numpy.outer(cmo[:, i], cmo[:, i]) return densities.unblock()
def cmo(self): if self._cmo is None: with FortranBinary(self.name) as fb: fb.find("NEWORB") cmo_rec = next(fb) nbas = self.basinfo.nbas norb = self.basinfo.norb assert len(cmo_rec) // 8 == numpy.dot(nbas, norb) cmo = blocked.BlockDiagonalMatrix(self.basinfo.nbas, self.basinfo.norb) for nbasi, norbi, cmoi in zip(nbas, norb, cmo.subblock): cmoi[:, :] = (numpy.array(cmo_rec.read( nbasi * norbi, "d")).reshape( (nbasi, norbi), order="F").view(full.matrix)) self._cmo = cmo return self._cmo
def getcmo(self): self.find("NEWORB") ncmot4 = max(self.basinfo.ncmot, 4) cmo_rec = self.next() assert cmo_rec.reclen / 8 == numpy.dot(self.basinfo.nbas, self.basinfo.norb) n = 0 cmo = blocked.BlockDiagonalMatrix(self.basinfo.nbas, self.basinfo.norb) for isym in range(self.basinfo.nsym): cmoi = numpy.array( cmo_rec.read( self.basinfo.nbas[isym] * self.basinfo.norb[isym], 'd')).reshape( (self.basinfo.nbas[isym], self.basinfo.norb[isym]), order='F') cmo.subblock[isym] = cmoi.view(full.matrix) return cmo
def cmo(self): """Read MO coefficients""" if self._cmo is None: with FortranBinary(self.name) as fb: fb.find(self.ifclabel) for _ in range(3): fb.next() ncmot4 = max(self.ncmot, 4) dbl = fb.readbuf(ncmot4, self.FLOAT) n = 0 self._cmo = blocked.BlockDiagonalMatrix(self.nbas, self.norb) for isym in range(8): for mo in range(self.norb[isym]): for ao in range(self.nbas[isym]): self._cmo.subblock[isym][ao, mo] = dbl[n] n += 1 assert n == self.ncmot return self._cmo
def fock(self): """Read Fock matrix (MO)""" if self._fock is None: with FortranBinary(self.name) as fb: fb.find(self.ifclabel) for i in range(6): fb.next() m2orbt = max(self.n2orbt, 4) dbl = fb.readbuf(m2orbt, self.FLOAT) self._fock = blocked.BlockDiagonalMatrix(self.norb, self.norb) n = 0 for isym in range(8): for i in range(self.norb[isym]): for j in range(self.norb[isym]): self._fock.subblock[isym][j, i] = dbl[n] n += 1 assert n == self.n2orbt return self._fock
def get_rhf_density(self): densities = blocked.BlockDiagonalMatrix(self.basinfo.nbas, self.basinfo.nbas) for dens, occ, cmo in zip(densities, self.basinfo.nrhf, self.cmo): dens += 2 * cmo[:, :occ] @ cmo[:, :occ].T return densities.unblock()