コード例 #1
0
    def _update_atoms(self, atoms):
        """ Update atoms-object, whether it is ase.Atoms or hotbit.Atoms. """

        if hasattr(atoms, 'container'):
            self.atoms = atoms.copy()
        else:
            container = container_magic(atoms)
            #print 'cc',container
            atoms_cont = Atoms(atoms=atoms, container=container)
            self.atoms = atoms_cont.copy()
コード例 #2
0
ファイル: elements.py プロジェクト: pekkosk/hotbit
    def _update_atoms(self,atoms):
        """ Update atoms-object, whether it is ase.Atoms or hotbit.Atoms. """

        if hasattr(atoms,'container'):
            self.atoms = atoms.copy()
        else:
            container = container_magic(atoms)
            #print 'cc',container
            atoms_cont = Atoms(atoms=atoms,container=container)
            self.atoms = atoms_cont.copy()
コード例 #3
0
ファイル: periodicity.py プロジェクト: nateharms/hotbit
    #    q -= np.sum(q)/len(q)

    r = [[SX / 4, SY / 4, SZ / 4], [3 * SX / 4, SY / 4, SZ / 4],
         [SX / 4, 3 * SY / 4, SZ / 4], [SX / 4, SY / 4, 3 * SZ / 4]]
    q = [1, -1, 1, -1]

    if False:
        # no periodicity, this should simply not fail
        if debug:
            print("0D")
        a = Atoms('%iH' % NAT,
                  positions=r,
                  charges=q,
                  cell=[SX, SY, SZ],
                  pbc=False)
        b = HotbitAtoms(atoms=a, container='Bravais')

        electrostatics_test(b, 3)
        electrostatics_test(b, 5)

    if True:
        # 1D periodicity
        if debug:
            print("1D")
        a = Atoms('%iH' % NAT,
                  positions=r,
                  charges=q,
                  cell=[SX, SY, SZ],
                  pbc=[False, False, True])
        b = HotbitAtoms(atoms=a, container='Bravais')
コード例 #4
0
ファイル: C6H6_wedge.py プロジェクト: molguin-qc/hotbit
from ase import *
from ase import Atoms as ase_Atoms
from hotbit import *
from hotbit.atoms import Atoms
from box.md import check_energy_conservation
from hotbit.test.misc import default_param


# check that C1H1-presentation of C6H6 goes right
SCC=True
cut=3.0
atoms = Atoms('CH',[(1.42,0,0),(2.0,1.0,0.2)],container='Wedge')
atoms.set_container(M=6,height=10)

calc = Hotbit(SCC=SCC,txt='tmp.cal',kpts=(6,1,1),gamma_cut=cut,**default_param)
atoms.set_calculator(calc)
e1 = atoms.get_potential_energy()

atoms6 = ase_Atoms(pbc=False)
atoms6 += atoms.extended_copy([(i-2,0,0) for i in range(6)])
#view(atoms)
calc = Hotbit(SCC=SCC,txt='tmp.cal',gamma_cut=cut,**default_param)
atoms6.set_calculator(calc)
e6 = atoms6.get_potential_energy()

assert abs(6*e1-e6)<1E-5


#
# energy conservation
#
コード例 #5
0
ファイル: C6H6_cell_game.py プロジェクト: molguin-qc/hotbit
from ase import *
from ase import Atoms as ase_Atoms
from hotbit import *
from hotbit.atoms import Atoms
from box.md import check_energy_conservation
from hotbit.test.misc import default_param

SCC=True
cut=3.0
atoms = Atoms('CH',[(1.42,0,0),(2.42,0,0)],container='Wedge')
atoms.set_container(M=6,height=10)

calc = Hotbit(SCC=SCC,txt='tmp.cal',kpts=(6,1,1),gamma_cut=cut,**default_param)
atoms.set_calculator(calc)
e1 = atoms.get_potential_energy()

 
aux = atoms.extended_copy((3,1,1))
atoms2 = Atoms(container='Wedge')
atoms2 += aux[0]
atoms2 += aux[-1]
atoms2.set_container(M=6,height=10)

#view(atoms2)
calc = Hotbit(SCC=SCC,txt='tmp.cal',kpts=(6,1,1),gamma_cut=cut,**default_param)
atoms2.set_calculator(calc)
e2 = atoms.get_potential_energy()

assert abs(e1-e2)<1E-5

コード例 #6
0
ファイル: mulliken.py プロジェクト: pastewka/hotbit
    x3, y3 = calc.get_covalent_energy('atoms', i=1, j=1)
    assert abs((y1 + y2 + y3).sum() - y.sum()) < eps

    sm = 0.0
    for i in range(calc.st.norb):
        for j in range(i, calc.st.norb):
            x1, y1 = calc.get_covalent_energy('orbitals', i=i, j=j)
            sm += y1.sum()
    assert abs(y.sum() - sm) < eps

if True:
    # check that C1H1-presentation of C6H6 goes right
    n1 = 4
    SCC = True
    cut = 1E10
    a1 = Atoms('CH', [(1.42, 0, 0), (2.42, 0.1, 0.1)], container='Wedge')
    a1.set_container(M=6, height=10)
    aux = a1.extended_copy([(1, 0, 0)])
    a1 += aux
    a1.set_container(M=3, height=10)

    n2 = 12
    c1 = Hotbit(SCC=SCC,
                txt='-',
                kpts=(3, 1, 1),
                gamma_cut=cut,
                **default_param)
    a1.set_calculator(c1)
    a1.get_potential_energy()

    a2 = a1.extended_copy((3, 1, 1))
コード例 #7
0
for sol in solvers:
    if debug:
        print("=== %s ===" % sol.__class__)
    for name, target_M, nnd, a in systems:
        syms = a.get_chemical_symbols()
        
        #a.set_charges([ (Q if sym == syms[0] else -Q) for sym in syms ])
        # to work with older versions
        a.set_initial_charges([ (-Q,Q)[sym==syms[0]] for sym in syms ])

        a.translate([0.25*a0,0.25*a0,0.25*a0])
        if debug:
            write("%s.cfg" % name, a)

        ha = HotbitAtoms(a, container='Bravais')

        sol.update(ha, ha.get_initial_charges())

        phi  = sol.get_potential()
        e    = np.sum(a.get_initial_charges()*phi)/2
        M    = -2*e*a0*nnd/(len(a))
        err  = abs(M-target_M)

        if debug:
            print("%20s   %8.6f  %8.6f  (%8.6e)" % ( name, M, target_M, err ))

        assert err < 1e-3

            
コード例 #8
0
ファイル: C6H6_wedge.py プロジェクト: nateharms/hotbit
import ase.units as units
from ase import *
from ase import Atoms as ase_Atoms
from hotbit import *
from hotbit.atoms import Atoms
from box.md import check_energy_conservation
from hotbit.test.misc import default_param

# check that C1H1-presentation of C6H6 goes right
SCC = True
cut = 3.0
atoms = Atoms('CH', [(1.42, 0, 0), (2.0, 1.0, 0.2)], container='Wedge')
atoms.set_container(M=6, height=10)

calc = Hotbit(SCC=SCC,
              txt='tmp.cal',
              kpts=(6, 1, 1),
              gamma_cut=cut,
              **default_param)
atoms.set_calculator(calc)
e1 = atoms.get_potential_energy()

atoms6 = ase_Atoms(pbc=False)
atoms6 += atoms.extended_copy([(i - 2, 0, 0) for i in range(6)])
#view(atoms)
calc = Hotbit(SCC=SCC, txt='tmp.cal', gamma_cut=cut, **default_param)
atoms6.set_calculator(calc)
e6 = atoms6.get_potential_energy()

assert abs(6 * e1 - e6) < 1E-5
コード例 #9
0
ファイル: CNT5_0_SCC.py プロジェクト: molguin-qc/hotbit
straight.set_pbc((False,False,True))
for i in range(len(straight)):
    if straight[i].z<1.0:
        r=sqrt(straight[i].x**2+straight[i].y**2)
        c=(1+r)/r
        x,y,z = c*straight[i].x,c*straight[i].y,straight[i].z
        straight+=Atom('H',(x,y,z))
#view(straight)
calc = Hotbit(SCC=SCC,txt='chiral.cal',kpts=(1,1,nkpts),gamma_cut=cut)
straight.set_calculator(calc)
e1 = straight.get_potential_energy()



# same thing, but calculate by twisting 2*pi/5 while translating
height = straight.get_cell()[2,2]
chiral = Atoms(container='Chiral')
chiral += straight
chiral.set_container(height=height,angle=2*pi/5)
calc = Hotbit(SCC=SCC,txt='chiral.cal',kpts=(1,1,nkpts),gamma_cut=cut)
chiral.set_calculator(calc)
view(chiral)
e2 = chiral.get_potential_energy()
assert abs(e1-e2)<1E-6


# check the energy conservation for the chiral situation
chiral.rattle(0.1)
calc = Hotbit(SCC=SCC,txt='chiral.cal',width=0.1,kpts=(1,1,1),gamma_cut=cut) #,verbose_SCC=True)
chiral.set_calculator(calc)
assert check_energy_conservation(chiral,dt=0.5*fs,steps=50,tol=0.02,plot=True)
コード例 #10
0
from ase import *
from ase import Atoms as ase_Atoms
from hotbit import *
from hotbit.atoms import Atoms
from box.md import check_energy_conservation
from hotbit.test.misc import default_param

SCC = True
cut = 3.0
atoms = Atoms('CH', [(1.42, 0, 0), (2.42, 0, 0)], container='Wedge')
atoms.set_container(M=6, height=10)

calc = Hotbit(SCC=SCC,
              txt='tmp.cal',
              kpts=(6, 1, 1),
              gamma_cut=cut,
              **default_param)
atoms.set_calculator(calc)
e1 = atoms.get_potential_energy()

aux = atoms.extended_copy((3, 1, 1))
atoms2 = Atoms(container='Wedge')
atoms2 += aux[0]
atoms2 += aux[-1]
atoms2.set_container(M=6, height=10)

#view(atoms2)
calc = Hotbit(SCC=SCC,
              txt='tmp.cal',
              kpts=(6, 1, 1),
              gamma_cut=cut,
コード例 #11
0
ファイル: CNT5_0_chiral.py プロジェクト: nateharms/hotbit
from hotbit.atoms import Atoms
from box.systems import nanotube
from box.md import check_energy_conservation

nkpts=10

# energy of normal infinite (5,0) 
straight = nanotube(5,0,1.42)
calc = Hotbit(SCC=False,txt='chiral.cal',kpts=(1,1,nkpts))
straight.set_calculator(calc)
e1 = straight.get_potential_energy()
#view(straight)


# same thing, but calculate by twisting 2*pi/5 while translating
height = straight.get_cell()[2,2]
chiral = Atoms(container='Chiral')
chiral += straight
chiral.set_container(height=height,angle=2*pi/5)
calc = Hotbit(SCC=False,txt='chiral.cal',kpts=(1,1,nkpts))
chiral.set_calculator(calc)
e2 = chiral.get_potential_energy()
assert abs(e1-e2)<1E-6


# check the energy conservation for the chiral situation
#chiral.rattle(0.1)
#calc = Hotbit(SCC=False,txt='chiral.cal',kpts=(1,1,1))
#chiral.set_calculator(calc)
#conv = check_energy_conservation(chiral,dt=0.5*fs,steps=50,tol=0.01,plot=False)
#assert conv
コード例 #12
0
for sol in solvers:
    if debug:
        print "=== %s ===" % sol.__class__
    for name, target_M, nnd, a in systems:
        syms = a.get_chemical_symbols()
        
        #a.set_charges([ (Q if sym == syms[0] else -Q) for sym in syms ])
        # to work with older versions
        a.set_initial_charges([ (-Q,Q)[sym==syms[0]] for sym in syms ])

        a.translate([0.25*a0,0.25*a0,0.25*a0])
        if debug:
            write("%s.cfg" % name, a)

        ha = HotbitAtoms(a, container='Bravais')

        sol.update(ha, ha.get_initial_charges())

        phi  = sol.get_potential()
        e    = np.sum(a.get_initial_charges()*phi)/2
        M    = -2*e*a0*nnd/(len(a))
        err  = abs(M-target_M)

        if debug:
            print "%20s   %8.6f  %8.6f  (%8.6e)" % ( name, M, target_M, err )

        assert err < 1e-3

            
コード例 #13
0
ファイル: mulliken.py プロジェクト: molguin-qc/hotbit
    assert abs((y1+y2+y3).sum()-y.sum())<eps
    
    sm = 0.0
    for i in range(calc.st.norb):
        for j in range(i,calc.st.norb):
            x1,y1 = calc.get_covalent_energy('orbitals',i=i,j=j) 
            sm += y1.sum()
    assert abs(y.sum()-sm)<eps


if True:
    # check that C1H1-presentation of C6H6 goes right
    n1 = 4
    SCC=True
    cut=1E10
    a1 = Atoms('CH',[(1.42,0,0),(2.42,0.1,0.1)],container='Wedge')
    a1.set_container(M=6,height=10)
    aux = a1.extended_copy([(1,0,0)])
    a1 += aux
    a1.set_container(M=3,height=10)
    
    
    n2 = 12
    c1 = Hotbit(SCC=SCC,txt='-',kpts=(3,1,1),gamma_cut=cut,**default_param)
    a1.set_calculator(c1)
    a1.get_potential_energy()
    
    
    a2 = a1.extended_copy((3,1,1))
    c2 = Hotbit(SCC=SCC,txt='-',kpts=(1,1,1),gamma_cut=cut,**default_param)
    a2.set_calculator(c2)
コード例 #14
0
ファイル: periodicity.py プロジェクト: molguin-qc/hotbit
           [   SX/4, 3*SY/4,   SZ/4 ],
           [   SX/4,   SY/4, 3*SZ/4 ] ]
    q  = [ 1, -1, 1, -1 ]

    if False:
        # no periodicity, this should simply not fail
        if debug:
            print "0D"
        a = Atoms('%iH' % NAT,
                  positions  = r,
                  charges    = q,
                  cell       = [ SX, SY, SZ ],
                  pbc        = False
                  )
        b = HotbitAtoms(
            atoms      = a,
            container  = 'Bravais'
            )

        electrostatics_test(b, 3)
        electrostatics_test(b, 5)


    if True:
        # 1D periodicity
        if debug:
            print "1D"
        a = Atoms('%iH' % NAT,
                  positions  = r,
                  charges    = q,
                  cell       = [ SX, SY, SZ ],
                  pbc        = [ False, False, True ]