Beispiel #1
0
def test_optimize(tmpdir):

    tmpdir.chdir()

    be = Molecule(name="Be", atoms=[('Be', )], charge=0, multiplicity=1)

    template = '''***,be ccpvdz tight fs test
memory,100,m

%geometry

%basis

%core

{rhf; wf,4,1,0}
cisd
'''

    mp = Molpro(exevar="MOLPRO_EXE", runopts=["-s", "-n", "1", "-d", "."])

    corefs = {'Be': [('s', 'exp', 1, (1.1, )), ('p', 'exp', 1, (4.2, ))]}

    ccpvdz_str = '''basis={
!BAZA Petersona
s,Be,2.940000E+03,4.412000E+02,1.005000E+02,2.843000E+01,9.169000E+00,3.196000E+00,1.159000E+00,1.811000E-01,5.890000E-02;
c,1.9,6.800000E-04,5.236000E-03,2.660600E-02,9.999300E-02,2.697020E-01,4.514690E-01,2.950740E-01,1.258700E-02,-3.756000E-03;
c,1.9,-1.230000E-04,-9.660000E-04,-4.831000E-03,-1.931400E-02,-5.328000E-02,-1.207230E-01,-1.334350E-01,5.307670E-01,5.801170E-01;
c,9.9,1.000000E+00;

p,Be,3.619000E+00,7.110000E-01,1.951000E-01,6.018000E-02;
c,1.4,2.911100E-02,1.693650E-01,5.134580E-01,4.793380E-01;
c,4.4,1.000000E+00;
!
!d,Be,2.354000E-01;
!c,1.1,1.000000E+00;
}
'''
    ccpvdz = BasisSet.from_str(ccpvdz_str, fmt='molpro')

    bso = BSOptimizer(objective='cisd total energy',
                      core=[[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0,
                                                       0]],
                      template=template,
                      verbose=True,
                      code=mp,
                      mol=be,
                      fsopt=corefs,
                      staticbs={'Be': ccpvdz},
                      uselogs=True,
                      runcore=True,
                      fname='be_tight.inp')

    bso.run()
    coreenergy = -0.031510764610001019
    assert abs(bso.result.fun - coreenergy) < 1.0e-8, 'wrong objective'
Beispiel #2
0
def test_to_json():

    bs = BasisSet.from_str(VTZGAUSSIAN, fmt='gaussian', name='VTZ')

    bsdumped = bs.to_json(indent=4)
    bsloaded = BasisSet.from_json(bsdumped)

    assert bs.name == bsloaded.name, 'inconsistent name'
    assert bs.element == bsloaded.element, 'inconsistent element'

    for shell, funs in bs.functions.items():

        assert shell in bsloaded.functions.keys(), 'missing shell {}'.format(shell)

        assert np.allclose(funs['e'], bsloaded.functions[shell]['e'])

        for f1, f2 in zip(funs['cf'], bsloaded.functions[shell]['cf']):
            assert np.allclose(f1['idx'], f2['idx']), 'inconsistent idx'
            assert np.allclose(f1['cc'], f2['cc']), 'inconsistent cc'
Beispiel #3
0
def test_optimize(tmpdir):

    tmpdir.chdir()

    dalton = Dalton(exevar='DALTON_EXE',
                    runopts=['-nobackup', '-noarch', '-d'])

    beh = Molecule(name="BeH-", atoms=[('Be',), ('H', (0.0, 0.0, 2.724985))],
                   sym="cnv 2", charge=-1, multiplicity=1)

    moltemplate = '''INTGRL
basis set optimization
test dalton calculator
Atomtypes=2 Charge=-1 Integrals=1.0D-20
%basis
'''

    hftemplate = '''**DALTON INPUT
.RUN WAVE FUNCTIONS
**WAVE FUNCTION
.HF
**END OF DALTON INPUT
'''

    fname = {'dal': 'hf.dal', 'mol': 'BeH-.mol'}
    template = {'mol': moltemplate, 'dal': hftemplate}

    optimization = {"method": "Nelder-Mead",
                    "tol": 1.0e-4,
                    "options": {"maxiter": 100,
                                "disp": True}
                    }

    ccpvdz_str = '''basis={
s,Be,2.940000E+03,4.412000E+02,1.005000E+02,2.843000E+01,9.169000E+00,3.196000E+00,1.159000E+00,1.811000E-01,5.890000E-02;
c,1.9,6.800000E-04,5.236000E-03,2.660600E-02,9.999300E-02,2.697020E-01,4.514690E-01,2.950740E-01,1.258700E-02,-3.756000E-03;
c,1.9,-1.230000E-04,-9.660000E-04,-4.831000E-03,-1.931400E-02,-5.328000E-02,-1.207230E-01,-1.334350E-01,5.307670E-01,5.801170E-01;
c,9.9,1.000000E+00;

p,Be,3.619000E+00,7.110000E-01,1.951000E-01,6.018000E-02;
c,1.4,2.911100E-02,1.693650E-01,5.134580E-01,4.793380E-01;
c,4.4,1.000000E+00;

d,Be,2.354000E-01;
c,1.1,1.000000E+00;

s, H , 13.0100000, 1.9620000, 0.4446000, 0.1220000, 0.0297400
c, 1.3, 0.0196850, 0.1379770, 0.4781480
c, 4.4, 1
c, 5.5, 1
p, H , 0.7270000, 0.1410000
c, 1.1, 1
c, 2.2, 1
}
'''

    ccpvdz = BasisSet.from_str(ccpvdz_str, fmt='molpro')

    augfs = {'Be': [('s', 'exp', 1, (0.02,)),
                    ('p', 'exp', 1, (0.01,)),
                    ('d', 'exp', 1, (0.07,))]}

    bso = BSOptimizer(objective='hf total energy', template=template,
                      code=dalton, mol=beh,
                      fsopt=augfs, staticbs=ccpvdz, verbose=True,
                      optalg=optimization, fname=fname)

    bso.run()

    energy = -15.131589405116999
    assert abs(bso.result.fun - energy) < 1.0e-8, 'wrong objective'
def test_optimize(tmpdir):

    tmpdir.chdir()

    psi = Psi4(exevar="PSI4_EXE", runopts=["-n", "4"])

    beh = Molecule(name="BeH-",
                   atoms=[('Be', ), ('H', (0.0, 0.0, 2.724985))],
                   sym="cnv 2",
                   charge=-1,
                   multiplicity=1)

    psitemp = '''#! test BeH-

memory 100 mb

molecule beh {
    Be  0.0000  0.0000  0.0000
    H   0.0000  0.0000  1.4420
    units angstrom
}

beh.set_molecular_charge(-1)
beh.set_multiplicity(1)


basis = {

assign mybasis

[ mybasis ]
spherical

%basisset

}

set {
freeze_core True
e_convergence 13
d_convergence 10
}

energy('cisd')
'''

    optimization = {
        "method": "Nelder-Mead",
        "tol": 1.0e-4,
        "options": {
            "maxiter": 100,
            "disp": True,
        }
    }

    ccpvdz_str = '''basis={
s,Be,2.940000E+03,4.412000E+02,1.005000E+02,2.843000E+01,9.169000E+00,3.196000E+00,1.159000E+00,1.811000E-01,5.890000E-02;
c,1.9,6.800000E-04,5.236000E-03,2.660600E-02,9.999300E-02,2.697020E-01,4.514690E-01,2.950740E-01,1.258700E-02,-3.756000E-03;
c,1.9,-1.230000E-04,-9.660000E-04,-4.831000E-03,-1.931400E-02,-5.328000E-02,-1.207230E-01,-1.334350E-01,5.307670E-01,5.801170E-01;
c,9.9,1.000000E+00;

p,Be,3.619000E+00,7.110000E-01,1.951000E-01,6.018000E-02;
c,1.4,2.911100E-02,1.693650E-01,5.134580E-01,4.793380E-01;
c,4.4,1.000000E+00;

d,Be,2.354000E-01;
c,1.1,1.000000E+00;

s, H , 13.0100000, 1.9620000, 0.4446000, 0.1220000, 0.0297400
c, 1.3, 0.0196850, 0.1379770, 0.4781480
c, 4.4, 1
c, 5.5, 1
p, H , 0.7270000, 0.1410000
c, 1.1, 1
c, 2.2, 1
}
'''

    ccpvdz = BasisSet.from_str(ccpvdz_str, fmt='molpro')

    augfs = {
        'Be': [('s', 'exp', 1, (0.02, )), ('p', 'exp', 1, (0.01, )),
               ('d', 'exp', 1, (0.07, ))]
    }

    bso = BSOptimizer(objective='cisd total energy',
                      template=psitemp,
                      code=psi,
                      mol=beh,
                      fsopt=augfs,
                      staticbs=ccpvdz,
                      core=[1, 0, 0, 0, 0, 0, 0, 0],
                      verbose=True,
                      optalg=optimization,
                      fname='beh_aug.dat')

    bso.run()

    energy = -15.204232302468
    assert abs(bso.result.fun - energy) < 1.0e-8, 'wrong objective'
def test_optimize(tmpdir):

    tmpdir.chdir()

    gamesstemp = ''' $CONTRL
    scftyp=rhf
    cityp=guga
    runtyp=energy
    maxit=30
    mult=1
    ispher=1
    units=bohr
    exetyp=run
 $END
 $SYSTEM
    timlim=525600
    mwords=100
 $END
 $CIDRT
   iexcit=2
   nfzc=2
   ndoc=2
   nval=40
   group=d2h
 $END

%basis
'''

    be2X = Molecule(name="Be2",
                    atoms=[('Be', (0.0, 0.0, -1.5)),
                           ('H', (0.0, 0.0, 0.0), True),
                           ('Be', (0.0, 0.0, 1.5))],
                    sym="dnh 2",
                    charge=0,
                    multiplicity=1,
                    unique=[0, 1])

    bsstr = '''basis={
s,Be,2.940000E+03,4.412000E+02,1.005000E+02,2.843000E+01,9.169000E+00,3.196000E+00,1.159000E+00,1.811000E-01,5.890000E-02;
c,1.9,6.800000E-04,5.236000E-03,2.660600E-02,9.999300E-02,2.697020E-01,4.514690E-01,2.950740E-01,1.258700E-02,-3.756000E-03;
c,1.9,-1.230000E-04,-9.660000E-04,-4.831000E-03,-1.931400E-02,-5.328000E-02,-1.207230E-01,-1.334350E-01,5.307670E-01,5.801170E-01;
c,9.9,1.000000E+00;

p,Be,3.619000E+00,7.110000E-01,1.951000E-01,6.018000E-02;
c,1.4,2.911100E-02,1.693650E-01,5.134580E-01,4.793380E-01;
c,4.4,1.000000E+00;

d,Be,2.354000E-01;
c,1.1,1.000000E+00;
}
'''

    vdz = BasisSet.from_str(bsstr, fmt='molpro')

    optimization = {
        "method": "CG",
        "tol": 1.0e-4,
        "jacob": False,
        "options": {
            "maxiter": 100,
            "disp": True,
            'eps': 1.0e-3
        }
    }

    gams = GamessUS(exevar="GAMESS_EXE", runopts=['1'])

    midbond = {'H': [('s', 'et', 4, (0.05, 2.0)), ('p', 'et', 4, (0.04, 2.0))]}

    bso = BSOptimizer(objective='cisd total energy',
                      template=gamesstemp,
                      code=gams,
                      mol=be2X,
                      fsopt=midbond,
                      staticbs={'Be': vdz},
                      core=2,
                      fname='midbond.inp',
                      verbose=True,
                      optalg=optimization)

    bso.run()
    energy = -29.1326831928
    assert abs(bso.result.fun - energy) < 1.0e-8, 'wrong objective'