geometric/ic_tools.py
def check_internal_grad(coords, molecule, IC, engine, dirname, verbose=0):
    """ Check the internal coordinate gradient using finite difference. """
    # Initial energy and gradient
    spcalc = engine.calc(coords, dirname)
    E = spcalc['energy']
    gradx = spcalc['gradient']
    # Initial internal coordinates
    q0 = IC.calculate(coords)
    Gq = IC.calcGrad(coords, gradx)
    logger.info("-=# Now checking gradient of the energy in internal coordinates vs. finite difference #=-\n")
    logger.info("%20s : %14s %14s %14s\n" % ('IC Name', 'Analytic', 'Numerical', 'Abs-Diff'))
    h = 1e-3
    Gq_f = np.zeros_like(Gq)
    for i in range(len(q0)):
        dq = np.zeros_like(q0)
        dq[i] += h
        x1 = IC.newCartesian(coords, dq, verbose)
        EPlus = engine.calc(x1, dirname)['energy']
        dq[i] -= 2*h
        x1 = IC.newCartesian(coords, dq, verbose)
        EMinus = engine.calc(x1, dirname)['energy']
        fdiff = (EPlus-EMinus)/(2*h)
        logger.info("%20s : % 14.6f % 14.6f % 14.6f\n" % (IC.Internals[i], Gq[i], fdiff, Gq[i]-fdiff))
        Gq_f[i] = fdiff
    return Gq, Gq_f
 Check the internal coordinate gradient using finite difference. 
Check the internal coordinate gradient using finite difference.
Check the internal coordinate gradient using finite difference .
def check_internal_grad(coords, molecule, IC, engine, dirname, verbose=0):
    spcalc = engine.calc(coords, dirname)
    E = spcalc['energy']
    gradx = spcalc['gradient']
    q0 = IC.calculate(coords)
    Gq = IC.calcGrad(coords, gradx)
    logger.info("-=# Now checking gradient of the energy in internal coordinates vs. finite difference #=-\n")
    logger.info("%20s : %14s %14s %14s\n" % ('IC Name', 'Analytic', 'Numerical', 'Abs-Diff'))
    h = 1e-3
    Gq_f = np.zeros_like(Gq)
    for i in range(len(q0)):
        dq = np.zeros_like(q0)
        dq[i] += h
        x1 = IC.newCartesian(coords, dq, verbose)
        EPlus = engine.calc(x1, dirname)['energy']
        dq[i] -= 2*h
        x1 = IC.newCartesian(coords, dq, verbose)
        EMinus = engine.calc(x1, dirname)['energy']
        fdiff = (EPlus-EMinus)/(2*h)
        logger.info("%20s : % 14.6f % 14.6f % 14.6f\n" % (IC.Internals[i], Gq[i], fdiff, Gq[i]-fdiff))
        Gq_f[i] = fdiff
    return Gq, Gq_f
def check_internal_grad ( coords , molecule , IC , engine , dirname , verbose = 0 ) : spcalc = engine . calc ( coords , dirname ) E = spcalc [ 'energy' ] gradx = spcalc [ 'gradient' ] q0 = IC . calculate ( coords ) Gq = IC . calcGrad ( coords , gradx ) logger . info ( "-=# Now checking gradient of the energy in internal coordinates vs. finite difference #=-\n" ) logger . info ( "%20s : %14s %14s %14s\n" % ( 'IC Name' , 'Analytic' , 'Numerical' , 'Abs-Diff' ) ) h = 1e-3 Gq_f = np . zeros_like ( Gq ) for i in range ( len ( q0 ) ) : dq = np . zeros_like ( q0 ) dq [ i ] += h x1 = IC . newCartesian ( coords , dq , verbose ) EPlus = engine . calc ( x1 , dirname ) [ 'energy' ] dq [ i ] -= 2 * h x1 = IC . newCartesian ( coords , dq , verbose ) EMinus = engine . calc ( x1 , dirname ) [ 'energy' ] fdiff = ( EPlus - EMinus ) / ( 2 * h ) logger . info ( "%20s : % 14.6f % 14.6f % 14.6f\n" % ( IC . Internals [ i ] , Gq [ i ] , fdiff , Gq [ i ] - fdiff ) ) Gq_f [ i ] = fdiff return Gq , Gq_f
Check the internal coordinate gradient using finite difference.
Check the internal coordinate gradient using finite difference .
""" Check the internal coordinate gradient using finite difference. """ # Initial energy and gradient # Initial internal coordinates
coords
molecule
IC
engine
dirname
verbose