예제 #1
0
def optimize(atoms, fmax=0.01):
    atoms.center(vacuum=6)
    atoms.rattle()
    if atoms.get_calculator() == None:
        atoms.set_calculator(Hotbit())
    dyn = QuasiNewton(atoms, maxstep=0.01)
    dyn.run(fmax=fmax)
예제 #2
0
파일: fitting.py 프로젝트: pekkosk/hotbit
 def __init__(self, rf, pars):
     from copy import copy
     from hotbit import Hotbit
     self.pars = pars
     self.trajectories = []
     self.calculators = []
     for data in rf._get_trajs_for_fitting():
         filename = data['filename']
         del data['filename']
         c = Hotbit()
         for key, value in data.iteritems():
             c.__dict__[key] = data[key]
         self.trajectories.append(filename)
         self.calculators.append(c)
     self.points = []
     self.ref_points = []
     self.colors = ['cyan','red','orange','#8DEE1E','magenta','green','black']
예제 #3
0
파일: fitting.py 프로젝트: sh-pan/hotbit
 def __init__(self, rf, pars):
     from copy import copy
     from hotbit import Hotbit
     self.pars = pars
     self.trajectories = []
     self.calculators = []
     for data in rf._get_trajs_for_fitting():
         filename = data['filename']
         del data['filename']
         c = Hotbit()
         for key, value in data.items():
             c.__dict__[key] = data[key]
         self.trajectories.append(filename)
         self.calculators.append(c)
     self.points = []
     self.ref_points = []
     self.colors = ['cyan','red','orange','#8DEE1E','magenta','green','black']
예제 #4
0
파일: fitting.py 프로젝트: sh-pan/hotbit
 def get_isolated_energies(self, trajs, par):
     """
     Return the energies of an isolated atoms.
     """
     elements = []
     energies = {}
     for t in trajs:
         traj = PickleTrajectory(t)
         for atom in traj[0]:
             if not atom.symbol in elements:
                 elements.append(atom.symbol)
     el1, el2 = par.split("_")[0:2]
     for el in elements:
         ss = "%s%s" % (el, el)
         if el1 == el2 and el1 == el:
             tables = {ss:par, 'rest':'default'}
             calc = Hotbit(SCC=True, tables=tables)
         else:
             calc = Hotbit(SCC=True)
         atoms = Atoms(ss, ((0,0,0),(200,0,0)))
         atoms.center(vacuum=100)
         atoms.set_calculator(calc)
         energies[el] = atoms.get_potential_energy() / 2
     return energies
예제 #5
0
파일: mio.py 프로젝트: pastewka/hotbit
def check_db(db, params):
    if debug:
        print "%10s %10s %10s ( %10s )" \
            % ( "bond", "value", "reference", "error" )
    for mol, values in db.iteritems():
        #if mol == 'H2O':
        if 1:
            if debug:
                print mol

            a = molecule(mol)
            a.center(vacuum=10.0)
            a.set_pbc(False)

            #print a.get_chemical_symbols()

            calc = Hotbit(
                charge_density = 'Slater',
                SCC = True,
                width = 1e-6,
                txt = 'mio.out',
                **params)
            a.set_calculator(calc)

            #calc.ia.plot_table('H', 'H')
            #calc.rep.get_repulsion('H', 'H').plot()

            OPT(a, logfile='opt.log').run(fmax=FMAX)

            #print a.get_charges()
            
            for name, ( ( i1, i2 ), refvalue ) in values.iteritems():
                value = a.get_distance(i1, i2)
                if debug:
                    print '%10s %10.3f %10.3f ( %10.3f )' % \
                        ( name, value, refvalue, abs(value-refvalue) )
                assert abs(value-refvalue) < 0.01
예제 #6
0
from hotbit import Hotbit
from ase import *
from box import Atoms
from box.md import quench
from hotbit.test.misc import default_param
#import cgitb; cgitb.enable()

h2o = read('H2O.xyz')
h2o.center(vacuum=5)

calc = Hotbit(verbose=True,
              SCC=True,
              verbose_SCC=False,
              txt='h2o.cal',
              **default_param)
h2o.set_calculator(calc)
print h2o.get_potential_energy()
#print h2o.get_forces()

calc.timer.summary()
print calc.timer.get_timings()
예제 #7
0
except:
    plot = False

import numpy as np
from box import mix

from ase.units import Hartree

Na3 = Atoms('Na3',
            positions=[(1.69649997, 0, 0), (-1.69649997, 0, 0),
                       (0, 2.9384241, 0)],
            cell=(50, 50, 50),
            pbc=False)
tm = mix.Timer()

calc = Hotbit(charge=1, SCC=True, txt='test_lr.cal', **default_param)
Na3.set_calculator(calc)
calc.solve_ground_state(Na3)
lr = LinearResponse(calc)
omega, F = lr.get_linear_response()
e, f = mix.broaden(omega, F, width=0.1)

if plot:
    pl.scatter(e2, f2)
    pl.plot(e, f, label='python')
    pl.legend()
    pl.show()

calc = Hotbit(SCC=True, txt='test_lr.cal', **default_param)
C60 = Atoms(read('C60.xyz'))
C60.set_calculator(calc)
예제 #8
0
파일: size.py 프로젝트: pekkosk/hotbit
atoms.set_cell((4 * 2.45951, 1000, 3000))
atoms.center()
# view(atoms)
# assert False

default_param["Anderson_memory"] = 0
default_param["convergence"] = 1e-2
default_param["mixing_constant"] = 0.1
default_param["width"] = 0.1
# calc0=Calculator0(verbose=True,SCC=True,gamma_cut=3,txt='sizef.cal',**default_param)
# atoms.set_calculator(calc0)
##atoms.get_forces()
# t()
# calc0.finalize()

calc = Hotbit(verbose=True, SCC=True, gamma_cut=3, verbose_SCC=True, txt="size.cal", **default_param)
atoms.set_calculator(calc)
atoms.get_forces()

calc.__del__()
# print calc.st.solver.get_iteration_info()
t()


# systems=['H2COH','AuC']

# default_param['convergence']=1E-5
# default_param['Anderson_memory']=3
# default_param['width']=0.01

예제 #9
0
import sys

from box.fd_forces import check_forces

systems = ['AuC', 'H2COH']

#default_param['convergence']=1E-5
#default_param['Anderson_memory']=3
default_param['width'] = 0.1

for charge_density in [None, 'Gaussian', 'Slater']:
    for system in systems:
        if charge_density is None:
            print('    ... forces for %s, no SCC' % system)
            calc = Hotbit(verbose=True,
                          SCC=False,
                          txt='forces.cal',
                          **default_param)
        else:
            print('    ... forces for %s, SCC, charge density = %s' % \
                ( system, charge_density ))
            calc = Hotbit(verbose=True,
                          SCC=True,
                          charge_density=charge_density,
                          txt='forces.cal',
                          **default_param)
        atoms = molecule(system)
        #view(atoms)
        atoms.center(vacuum=5)
        atoms[0].x += 0.1
        atoms = Atoms(atoms)
        atoms.set_calculator(calc)
예제 #10
0
파일: Au2.py 프로젝트: pastewka/hotbit
from ase import *
from hotbit import Hotbit
from hotbit.test.misc import default_param

calc = Hotbit(SCC=True, txt='test.cal', **default_param)
Au2 = Atoms('Au2',
            positions=[(0, 0, 0), (1.6, 1.2, 0.2)],
            cell=(10, 10, 10),
            pbc=False)
Au2.center(vacuum=10)
Au2.set_calculator(calc)
print Au2.get_potential_energy()
예제 #11
0
# calculate Au dimer
from ase import *
from hotbit import Hotbit

calc = Hotbit(SCC=True, width=0.05, txt='test.cal')
Au2 = Atoms('Au2',
            positions=[(0, 0, 0), (2.6, 0, 0)],
            cell=(10, 10, 10),
            pbc=False)
Au2.center(vacuum=10)
Au2.set_calculator(calc)
print Au2.get_potential_energy()
예제 #12
0
파일: mio.py 프로젝트: pastewka/hotbit
###

if debug:
    for SCC in [ False, True ]:
        if SCC:
            print "--- SCC ---"
        else:
            print "--- no SCC ---"
            
        calc = Hotbit(
            charge_density = 'Slater',
            SCC = SCC,
            verbose = True,
            verbose_SCC = True,
            mixer = {
                'name': 'anderson',
                'convergence': 1e-6,
                'mixing_constant': 0.01 },
            maxiter = 1000,
            txt = 'mio.out',
            **params)

        a = read('formamide.xyz')
        a.center(vacuum=10.0)
        a.set_pbc(False)
        a.set_calculator(calc)

        OPT(a, logfile='opt.log').run(fmax=FMAX)

        iO = 0 
        iC = 1
예제 #13
0
from ase import *
from hotbit import Hotbit
from hotbit.analysis import LinearResponse
from ase.data.molecules import molecule
from hotbit.test.misc import default_param

atoms = Atoms('Na3', [(1.6964999745231999, 0, 0), (-1.6964999745231999, 0, 0),
                      (0, 2.9384240999630005, 0)])
atoms.center(vacuum=5)

default_param['width'] = 0.0136

calc = Hotbit(SCC=True, charge=1, txt='linear_response.cal', **default_param)
atoms.set_calculator()
calc.solve_ground_state(atoms)

lr = LinearResponse(calc, energy_cut=2000, txt='linear_response.txt')
lr.run()
lr.plot_spectrum('Na3+_lr.png', width=0.08)

el = [1.81951, 1.81951, 7.43599, 7.43599]
fl = [0.43036, 0.43036, 4.27744, 4.27744]

for i in range(4):
    e, f = lr.get_excitation(i)
    assert abs(e - el[i]) < 1E-4 and abs(f - fl[i]) < 1E-4
예제 #14
0
 # calculate CO dimer
from ase import *
from hotbit import Hotbit

for SCC in [False,True]:
    calc=Hotbit(SCC=SCC,width=0.05,txt='test.cal')
    atoms=Atoms('CO',positions=[(0,0,0),(1.13,0,0)],cell=(10,10,10),pbc=False)
    atoms.center(vacuum=10) #not necessary
    atoms.set_calculator(calc)
    print(atoms.get_potential_energy())
예제 #15
0
energies0 = [
    -153.471502365, -232.206844117, -166.801950557, -19.356876265,
    -313.487801685, -287.534640343
]
free = [
    -113.81982575044, -191.66618644170001, -141.09652875422,
    -12.680510375480001, -248.57609931692002, -214.95914112540004
]
energies = [e - ef for e, ef in zip(energies0, free)]

eps = 1E-3
for system, e in zip(systems, energies):
    atoms = molecule(system)
    atoms.center(vacuum=10)
    atoms.set_pbc(False)
    if e == 0:
        calc = Calculator0(verbose=True,
                           SCC=False,
                           txt='standard.cal',
                           **default_param)
        atoms.set_calculator(calc)
        print('new system', system, atoms.get_potential_energy())
        sys.exit(0)

    calc = Hotbit(verbose=True, SCC=True, txt='standard.cal', **default_param)
    atoms.set_calculator(calc)
    e1 = atoms.get_potential_energy()
    if abs(e1 - e) > eps:
        raise AssertionError('Energy for %s is %.7f, while should be %.7f' %
                             (system, e1, e))
예제 #16
0
파일: dftb_io.py 프로젝트: pastewka/hotbit
###

dir1 = '/Users/pas/Sourcen/hotbit/param/'
#dir2 = '/Users/pas/Sourcen/hotbit/param/'
dir2 = '/Users/pas/Sourcen/mdcore/data/slater_koster_tables/Frauenheim/download-2009-10-23/mio-0-1/'

###

a = ase.molecule('C6H6')
a.center(vacuum=6.0)

c = Hotbit(elements={
    'H': dir2 + 'H-H.skf',
    'C': dir2 + 'C-C.skf'
},
           tables={
               'HH': dir2 + 'H-H.skf',
               'CH': dir2 + 'C-H.skf',
               'CC': dir2 + 'C-C.skf'
           },
           SCC=False)
a.set_calculator(c)

ase.FIRE(a).run(fmax=0.01)

ase.write('C6H6.cfg', a)

###

for i in c.el.get_present():
    el = c.el.get_element(i)
    sym = el.get_symbol()
예제 #17
0
plot=True
try:
    import pylab as pl
except:
    plot=False
    
import numpy as np
from box import mix

    
from ase.units import Hartree
 
Na3=Atoms('Na3',positions=[(1.69649997,0,0),(-1.69649997,0,0),(0,2.9384241,0)],cell=(50,50,50),pbc=False)  
tm=mix.Timer()

calc=Hotbit(charge=1,SCC=True,txt='test_lr.cal',**default_param)
Na3.set_calculator(calc)
calc.solve_ground_state(Na3)
lr=LinearResponse(calc)
omega,F=lr.get_linear_response()
e,f=mix.broaden(omega,F,width=0.1)

if plot:
    pl.scatter(e2,f2)
    pl.plot(e,f,label='python')
    pl.legend()
    pl.show()
       
calc=Hotbit(SCC=True,txt='test_lr.cal',**default_param)
C60=Atoms(read('C60.xyz'))
C60.set_calculator(calc)
예제 #18
0
파일: size2.py 프로젝트: nateharms/hotbit
import pylab as pl
from box import Atoms

for SCC in [True, False]:
    timings = []
    norbs = []
    sccs = ['non-SCC', 'SCC'][SCC]
    for nx in [1, 2, 3, 4, 5]:
        for ny in [1, 2, 3, 4, 5]:
            print('nx', nx, ny)
            atoms = FaceCenteredCubic(directions=[[1,-1,0], [1,1,-2], [1,1,1]],\
                                    size=(nx,ny,1), symbol='Au', pbc=(0,0,0))

            calc = Hotbit(verbose=True,
                          SCC=SCC,
                          gamma_cut=3,
                          txt='size2.cal',
                          **default_param)
            atoms.set_calculator(calc)
            try:
                atoms.get_forces()
            except:
                continue
            calc.timer.summary()
            timings.append(calc.timer.get_timings())
            norbs.append(calc.el.get_nr_orbitals())
            calc.__del__()

    order = argsort(norbs)
    norbs = sort(norbs)
    timings2 = []
예제 #19
0
from ase import *
from hotbit import Hotbit
from hotbit.analysis import LinearResponse
from ase.data.molecules import molecule
from hotbit.test.misc import default_param

atoms=Atoms('Na3',[(1.6964999745231999,0,0),(-1.6964999745231999,0,0),(0,2.9384240999630005,0)])
atoms.center(vacuum=5)

default_param['width'] = 0.0136

calc=Hotbit(SCC=True,charge=1,txt='linear_response.cal',**default_param)
atoms.set_calculator()
calc.solve_ground_state(atoms)

lr=LinearResponse(calc,energy_cut=2000,txt='linear_response.txt')
lr.run()
lr.plot_spectrum('Na3+_lr.png',width=0.08)

el = [1.81951,1.81951,7.43599,7.43599]
fl = [0.43036,0.43036,4.27744,4.27744]

for i in range(4):
    e,f = lr.get_excitation(i)
    assert abs(e-el[i])<1E-4 and abs(f-fl[i])<1E-4