示例#1
0
def readTurbomoleBasis(path):
    """Read Turbomole basis set"""
    bss = topParseB.parseFile(path)
    atoms = [xs.atomLabel.lower() for xs in bss]
    names = concat([xs.basisName.upper().split() for xs in bss])
    formats = [xs.format[:] for xs in bss]
    formats_int = map(lambda fss: [[int(x) for x in xs] for xs in fss], formats)
    rss = [rs.coeffs[:] for rs in bss]
    rawData = [[x.contractions[:] for x in rss[i]] for i in range(len(rss))]
    fst = lambda xs: xs[0]
    snd = lambda xs: xs[1]
    expos = list(
        map(
            mapFloat,
            [concatMap(fst, swapCoeff(2, rawData[i])) for i in range(len(rawData))],
        )
    )
    coeffs = list(
        map(
            mapFloat,
            [concatMap(snd, swapCoeff(2, rawData[i])) for i in range(len(rawData))],
        )
    )
    basisData = zipWith(AtomBasisData)(expos)(coeffs)
    basiskey = zipWith3(AtomBasisKey)(atoms)(names)(formats_int)

    return basiskey, basisData
示例#2
0
def createAtoms(xs):
    """
    Create an AtomXYZ tuple from a string.
    """
    ls = [a.label.lower() for a in xs]
    rs = [list(map(float, a.xyz)) for a in xs]
    return zipWith(AtomXYZ)(ls)(rs)
示例#3
0
def test_zipwith():
    """
    zipWith f xs ys ==  map (f) (zip  xs ys)
    """
    @curry
    def f(x, y):
        return x * y

    xs = range(3)
    ys = range(3, 6)

    assert zipWith(f)(xs)(ys) == [f(x, y) for (x, y) in zip(xs, ys)]
示例#4
0
def readCp2KBasis(path):
    """
    Read the Contracted Gauss function primitives format from a text file.

    :param path: Path to the file containing the basis.
    :type path: String
    """
    bss = topParseBasis.parseFile(path)
    atoms = ["".join(xs.atom[:]).lower() for xs in bss]
    names = [" ".join(xs.basisName[:]).upper() for xs in bss]
    formats = [list(map(int, xs.format[:])) for xs in bss]
    # for example 2 0 3 7 3 3 2 1 there are sum(3 3 2 1) =9 Lists
    # of Coefficients + 1 lists of exponents
    nCoeffs = [int(sum(xs[4:]) + 1) for xs in formats]
    rss = zipWith(swapCoeff2)(nCoeffs)(list(map(float, cs.coeffs[:]))
                                       for cs in bss)
    tss = [headTail(xs) for xs in rss]
    basisData = [AtomBasisData(xs[0], xs[1]) for xs in tss]
    basiskey = zipWith3(AtomBasisKey)(atoms)(names)(formats)

    return (basiskey, basisData)
示例#5
0
    def saveMO(self,
               parserFun,
               pathMO,
               nOrbitals=None,
               nOrbFuns=None,
               pathEs=None,
               pathCs=None,
               nOccupied=None,
               nHOMOS=None,
               nLUMOS=None):
        """
        Save Molecular orbital eigenvalues and eigenvectors.

        :parameter parserFun: Function to parse the file containing the MOs.
        :parameter pathMO: Absolute path to the MOs file.
        :type pathMO: String
        :parameter nOrbitals: Number of orbitals
        :type nOrbitals: Int
        :param nOrbFuns: Number of Atomic orbitals function that made up
        each of the molecular orbitals.
        :type nOrbFuns: Int
        :parameter pathEs: Path to the MO eigenvalues in the HDF5 file
                           (default is: <softwareName>/mo/eigenvalues).
        :type pathEs: String
        :parameter pathCs: Path to the MO coefficients in the HDF5 file
                           (default is: <softwareName>/mo/coefficients).
        :type pathCs: String
        :param nOccupied: Number of occupied molecular orbitals.
        :type nOccupied: Int
        :param nHOMOS: number of H**O orbitals to store in HDF5.
        :type nHOMOS: Int
        :param nLUMOS: number of HUMO orbitals to store in HDF5.
        :type nLUMOS: Int
        :returns: **None**
        """

        pathEs = pathEs if pathEs is not None else join(
            self.name, "mo", "eigenvalues")
        pathCs = pathCs if pathCs is not None else join(
            self.name, "mo", "coefficients")

        # Save all the frontier orbitals.
        # NOTE: IT ASSUMES THAT The USER HAVE SELECTED A RANGE OF MO
        # TO PRINT.
        if not (nHOMOS is None and nLUMOS is None):
            infoMO = parserFun(pathMO, nHOMOS + nLUMOS, nOrbFuns)

        elif nOrbitals is not None:
            infoMO = parserFun(pathMO, nOrbitals, nOrbFuns)
            if not (nHOMOS is None and nLUMOS is None) and \
               nOrbitals > nHOMOS + nLUMOS:
                # Drop Coefficients that below and above nHOMOS and nLUMOS,
                # respectively.
                ess, css = infoMO
                css = np.transpose(css)
                eigenVals = ess[nOccupied - nHOMOS:nOccupied + nLUMOS]
                coefficients = css[nOccupied - nHOMOS:nOccupied + nLUMOS]
                infoMO = InfoMO(eigenVals, np.transpose(coefficients))

        zipWith(self.funHDF5)([pathEs,
                               pathCs])([infoMO.eigenVals, infoMO.coeffs])