Esempio n. 1
0
def backtransform(chgeMol, permMol, chgeGrad=None, chgeDip=None):
    """Here, *chgeMol* and *chgeGrd* need to be turned into the native Cfour
    orientation embodied by *permMol*. Currently for vpt2.

    """
    # Set up array reorientation object
    p4c4 = OrientMols(permMol, chgeMol)  # opposite than usual
    oriCoord = p4c4.transform_coordinates2(chgeMol)
    p4Elem = []
    for at in range(chgeMol.natom()):
        p4Elem.append(chgeMol.Z(at))
    oriElem = p4c4.transform_elementlist(p4Elem)
    oriElemMap = p4c4.Catommap

    oriGrad = None if chgeGrad is None else p4c4.transform_gradient(chgeGrad)
    oriDip = None if chgeDip is None else p4c4.transform_vector(chgeDip)

    if chgeGrad and chgeDip:
        return oriElemMap, oriElem, oriCoord, oriGrad, oriDip
    else:
        return oriElemMap, oriElem, oriCoord
Esempio n. 2
0
def harvest(p4Mol, c4out, **largs):
    """Parses all the pieces of output from Cfour: the stdout in
    *c4out* and the contents of various scratch files like GRD stored
    in their namesake keys in *largs*. Since all Cfour output uses
    its own orientation and atom ordering for the given molecule,
    a qcdb.Molecule *p4Mol*, if supplied, is used to transform the
    Cfour output back into consistency with *p4Mol*.

    """
    # Collect results from output file and subsidiary files
    outPsivar, outMol, outGrad = harvest_output(c4out)

    if 'GRD' in largs:
        grdMol, grdGrad = harvest_GRD(largs['GRD'])
    else:
        grdMol, grdGrad = None, None

    if 'FCMFINAL' in largs:
        fcmHess = harvest_FCM(largs['FCMFINAL'])
    else:
        fcmHess = None

    if 'DIPOL' in largs:
        dipolDip = harvest_DIPOL(largs['DIPOL'])
    else:
        dipolDip = None

    # Reconcile the coordinate information: several cases
    #   Case                            p4Mol   GRD      Check consistency           Apply orientation?     ReturnMol (1-19-2014)
    #   sp with mol thru cfour {}       None    None              outMol             N.C.                   outMol
    #   opt with mol thru cfour {}      None    grdMol            outMol && grdMol   N.C.                   grdMol
    #   sp with mol thru molecule {}    p4Mol   None     p4Mol && outMol             p4Mol <-- outMol       p4Mol (same as input arg)
    #   opt with mol thru molecule {}   p4Mol   grdMol   p4Mol && outMol && grdMol   p4Mol <-- grdMol       p4Mol (same as input arg)

    if outMol:
        if grdMol:
            if abs(outMol.nuclear_repulsion_energy() - grdMol.nuclear_repulsion_energy()) > 1.0e-3:
                raise ValidationError("""Cfour outfile (NRE: %f) inconsistent with Cfour GRD (NRE: %f).""" % \
                        (outMol.nuclear_repulsion_energy(), grdMol.nuclear_repulsion_energy()))
        if p4Mol:
            if abs(outMol.nuclear_repulsion_energy() - p4Mol.nuclear_repulsion_energy()) > 1.0e-3:
                raise ValidationError("""Cfour outfile (NRE: %f) inconsistent with Psi4 input (NRE: %f).""" % \
                    (outMol.nuclear_repulsion_energy(), p4Mol.nuclear_repulsion_energy()))
    else:
        raise ValidationError("""No coordinate information extracted from Cfour output.""")

#    print '    <<<   [1] P4-MOL   >>>'
#    if p4Mol:
#        p4Mol.print_out_in_bohr()
#    print '    <<<   [2] C4-OUT-MOL   >>>'
#    if outMol:
#        outMol.print_out_in_bohr()
#    print '    <<<   [3] C4-GRD-MOL   >>>'
#    if grdMol:
#        grdMol.print_out_in_bohr()

    # Set up array reorientation object
    if p4Mol and grdMol:
        p4c4 = OrientMols(p4Mol, grdMol)
        oriCoord = p4c4.transform_coordinates2(grdMol)
        oriGrad = p4c4.transform_gradient(grdGrad)
        oriDip = None if dipolDip is None else p4c4.transform_vector(dipolDip)
    elif p4Mol and outMol:
        p4c4 = OrientMols(p4Mol, outMol)
        oriCoord = p4c4.transform_coordinates2(outMol)
        oriGrad = None
        oriDip = None if dipolDip is None else p4c4.transform_vector(dipolDip)
    elif outMol:
        oriCoord = None
        oriGrad = None
        oriDip = None if dipolDip is None else dipolDip

#    print p4c4
#    print '    <<<   [4] C4-ORI-MOL   >>>'
#    if oriCoord is not None:
#        for item in oriCoord:
#            print('       %16.8f %16.8f %16.8f' % (item[0], item[1], item[2]))
#
#    print '    <<<   [1] C4-GRD-GRAD   >>>'
#    if grdGrad is not None:
#        for item in grdGrad:
#            print('       %16.8f %16.8f %16.8f' % (item[0], item[1], item[2]))
#    print '    <<<   [2] C4-ORI-GRAD   >>>'
#    if oriGrad is not None:
#        for item in oriGrad:
#            print('       %16.8f %16.8f %16.8f' % (item[0], item[1], item[2]))


    retMol = None if p4Mol else grdMol

    if oriDip:
        outPsivar['CURRENT DIPOLE X'] = str(oriDip[0] * psi_dipmom_au2debye)
        outPsivar['CURRENT DIPOLE Y'] = str(oriDip[1] * psi_dipmom_au2debye)
        outPsivar['CURRENT DIPOLE Z'] = str(oriDip[2] * psi_dipmom_au2debye)

    if oriGrad:
        retGrad = oriGrad
    elif grdGrad:
        retGrad = grdGrad
    else:
        retGrad = None

    return outPsivar, retGrad, retMol