예제 #1
0
def HCPoutputYAML(a0, c_a, z=1./8.):
    """
    Generates YAML file corresponding to our HCP lattice with octahedral and tetrahedrals.
    :param a0: lattice constant
    :param c_a: c/a ratio
    :param z: distance of tetrahedral from basal plane (unit cell coordinates)
    :return: YAML string containing the *short* version, along with jump networks
    """
    # Note: alternatively, we could construct our HCP crystal *then* generate Wyckoff positions
    hexlatt = a0*np.array([[0.5, 0.5, 0],
                           [-np.sqrt(0.75), np.sqrt(0.75), 0],
                           [0, 0, c_a]])
    hcpbasis = [[np.array([1./3.,2./3.,1./4.]),np.array([2./3.,1./3.,3./4.])],
                [np.array([0.,0.,0.]), np.array([0.,0.,0.5]),
                 np.array([1./3.,2./3.,3./4.-z]), np.array([1./3.,2./3.,3./4.+z]),
                 np.array([2./3.,1./3.,1./4.-z]), np.array([2./3.,1./3.,1./4.+z])]]
    HCP = crystal.Crystal(hexlatt, hcpbasis)
    # these cutoffs are for: o->t, t->t, o->o along c
    # (preferably all below a). The t->t should be shortest, and o->o the longest
    cutoff = 1.01*a0*max(np.sqrt(1./3.+c_a**2/64), 2*z*c_a, 0.5*c_a)
    if __debug__:
        if cutoff > a0: raise AssertionError('Geometry such that we will include basal jumps')
        if np.abs(z) > 0.25: raise AssertionError('Tetrahedral parameter out of range (>1/4)')
        if np.abs(z) < 1e-2: raise AssertionError('Tetrahedral parameter out of range (approx. 0)')
    return HeaderString + \
           HCP.simpleYAML(a0) + \
           OnsagerCalc.Interstitial.sitelistYAML(HCP.sitelist(1)) + \
           OnsagerCalc.Interstitial.jumpnetworkYAML(HCP.jumpnetwork(1, cutoff))
예제 #2
0
    def setUp(self):
        latt = np.array([[0., 0.1, 0.5], [0.3, 0., 0.5], [0.5, 0.5, 0.]]) * 0.55
        self.DC_Si = crystal.Crystal(latt, [[np.array([0., 0., 0.]), np.array([0.25, 0.25, 0.25])]], ["Si"])
        # keep it simple with [1.,0.,0.] type orientations for now
        o = np.array([1., 0., 0.]) / np.linalg.norm(np.array([1., 0., 0.])) * 0.126
        famp0 = [o.copy()]
        family = [famp0]

        self.pdbcontainer_si = dbStates(self.DC_Si, 0, family)
        self.mdbcontainer_si = mStates(self.DC_Si, 0, family)

        self.jset0, self.jset2 = self.pdbcontainer_si.jumpnetwork(0.3, 0.01, 0.01), self.mdbcontainer_si.jumpnetwork(
            0.3, 0.01, 0.01)

        self.crys_stars = StarSet(self.pdbcontainer_si, self.mdbcontainer_si, self.jset0, self.jset2, Nshells=1)
        self.vec_stars = vectorStars(self.crys_stars)

        self.om2tags = self.vec_stars.starset.jtags2
        # generate 1, 3 and 4 jumpnetworks
        (self.jnet_1, self.jnet_1_indexed, self.om1tags), self.jtype = self.crys_stars.jumpnetwork_omega1()
        (self.symjumplist_omega43_all, self.symjumplist_omega43_all_indexed), (
            self.symjumplist_omega4, self.symjumplist_omega4_indexed, self.om4tags), (
            self.symjumplist_omega3, self.symjumplist_omega3_indexed,
            self.om3tags) = self.crys_stars.jumpnetwork_omega34(
            0.3, 0.01, 0.01, 0.01)

        self.W0list = np.random.rand(len(self.vec_stars.starset.jnet0))
        self.W1list = np.random.rand(len(self.jnet_1))
        self.W2list = np.random.rand(len(self.jset2[0]))
        self.W3list = np.random.rand(len(self.symjumplist_omega3))
        self.W4list = np.random.rand(len(self.symjumplist_omega4))

        # generate all the bias expansions - will separate out later
        self.biases = self.vec_stars.biasexpansion(self.jnet_1, self.jset2[0], self.jtype, self.symjumplist_omega43_all)
        self.rateExps = self.vec_stars.rateexpansion(self.jnet_1, self.jtype, self.symjumplist_omega43_all)
예제 #3
0
    def setUp(self):
        self.crys2d = crystal.Crystal(np.array([[1., 0.], [0., 1.5]]), [[np.array([0, 0]), np.array([0.5, 0.5])]], ["A"])
        print("Crystal dimension: {}".format(self.crys2d.dim))
        o = np.array([0., 0.1])
        famp02d = [o.copy()]
        family2d = [famp02d]

        self.pdbcontainer_si = dbStates(self.crys2d, 0, family2d)
        self.mdbcontainer_si = mStates(self.crys2d, 0, family2d)

        jset02d, jset22d = self.pdbcontainer_si.jumpnetwork(1.51, 0.01, 0.01), self.mdbcontainer_si.jumpnetwork(1.51, 0.01, 0.01)

        self.crys_stars = StarSet(self.pdbcontainer_si, self.mdbcontainer_si, jset02d, jset22d, Nshells=1)
        self.vec_stars = vectorStars(self.crys_stars)

        self.om2tags = self.vec_stars.starset.jtags2
        # generate 1, 3 and 4 jumpnetworks
        (self.jnet_1, self.jnet_1_indexed, self.om1tags), self.jtype = self.crys_stars.jumpnetwork_omega1()
        (self.symjumplist_omega43_all, self.symjumplist_omega43_all_indexed), (
            self.symjumplist_omega4, self.symjumplist_omega4_indexed, self.om4tags), (
            self.symjumplist_omega3, self.symjumplist_omega3_indexed,
            self.om3tags) = self.crys_stars.jumpnetwork_omega34(1.51, 0.01, 0.01, 0.01)

        self.jset2 = jset22d

        self.W0list = np.random.rand(len(self.vec_stars.starset.jnet0))
        self.W1list = np.random.rand(len(self.jnet_1))
        self.W2list = np.random.rand(len(self.jset2[0]))
        self.W3list = np.random.rand(len(self.symjumplist_omega3))
        self.W4list = np.random.rand(len(self.symjumplist_omega4))

        # generate all the bias expansions - will separate out later
        self.biases = self.vec_stars.biasexpansion(self.jnet_1, self.jset2[0], self.jtype, self.symjumplist_omega43_all)
        self.rateExps = self.vec_stars.rateexpansion(self.jnet_1, self.jtype, self.symjumplist_omega43_all)
        print("Instantiated")
예제 #4
0
    def setUp(self):
        o = np.array([0.1, 0.])
        famp0 = [o.copy()]
        self.family = [famp0]

        latt = np.array([[1., 0.], [0., 1.]])
        self.crys = crystal.Crystal(latt, [np.array([0, 0])], ["A"])
예제 #5
0
    def testBCC_B2(self):
        """Test that BCC and B2 produce the same GF"""
        a0 = 1.
        chem = 0
        BCC = crystal.Crystal.BCC(a0)
        BCC_sitelist = BCC.sitelist(chem)
        BCC_jumpnetwork = BCC.jumpnetwork(chem, 0.87 * a0)
        BCC_GF = GFcalc.GFCrystalcalc(BCC,
                                      chem,
                                      BCC_sitelist,
                                      BCC_jumpnetwork,
                                      Nmax=6)
        BCC_GF.SetRates(np.ones(len(BCC_sitelist)),
                        np.zeros(len(BCC_sitelist)),
                        2. * np.ones(len(BCC_jumpnetwork)),
                        np.zeros(len(BCC_jumpnetwork)))

        B2 = crystal.Crystal(
            a0 * np.eye(3),
            [np.zeros(3), np.array([0.45, 0.45, 0.45])])
        B2_sitelist = B2.sitelist(chem)
        B2_jumpnetwork = B2.jumpnetwork(chem, 0.99 * a0)
        B2_GF = GFcalc.GFCrystalcalc(B2,
                                     chem,
                                     B2_sitelist,
                                     B2_jumpnetwork,
                                     Nmax=6)
        B2_GF.SetRates(np.ones(len(B2_sitelist)), np.zeros(len(B2_sitelist)),
                       2. * np.ones(len(B2_jumpnetwork)),
                       np.zeros(len(B2_jumpnetwork)))
        veclist = [
            np.array([a0, 0, 0]),
            np.array([0, a0, 0]),
            np.array([0, 0, a0]),
            np.array([-a0, 0, 0]),
            np.array([0, -a0, 0]),
            np.array([0, 0, -a0])
        ]
        for v1 in veclist:
            for v2 in veclist:
                # print('{}: '.format(v1+v2) + '{} vs {} vs {}'.format(B2_GF(0,0,v1+v2),B2_GF(1,1,v1+v2),BCC_GF(0,0,v1+v2)))
                self.assertAlmostEqual(BCC_GF(0, 0, v1 + v2),
                                       B2_GF(0, 0, v1 + v2),
                                       places=5)
                self.assertAlmostEqual(BCC_GF(0, 0, v1 + v2),
                                       B2_GF(1, 1, v1 + v2),
                                       places=5)
        for jlist in B2_jumpnetwork:
            for (i, j), dx in jlist:
                # convert our B2 dx into a corresponding BCC dx:
                BCCdx = (0.5 * a0) * np.round(dx / (0.5 * a0))
                # print('({},{}), {} / {}: '.format(i,j,dx,BCCdx) + '{} vs {}'.format(B2_GF(i,j,dx), BCC_GF(0,0,BCCdx)))
                self.assertAlmostEqual(BCC_GF(0, 0, BCCdx),
                                       B2_GF(i, j, dx),
                                       places=5)
예제 #6
0
 def testtria(self):
     """Test on triagonal"""
     tria = crystal.Crystal(
         np.array([[1 / 2, 1 / 2], [-np.sqrt(3 / 4),
                                    np.sqrt(3 / 4)]]), [np.zeros(2)])
     tria_sitelist = tria.sitelist(0)
     tria_jumpnetwork = tria.jumpnetwork(0, 1.01)
     tria_GF = GFcalc.GFCrystalcalc(tria,
                                    0,
                                    tria_sitelist,
                                    tria_jumpnetwork,
                                    Nmax=4)
     tria_GF.SetRates([1], [0], [1], [0])
     tria_zero = np.zeros(2)
     tria_1nn = np.array([1., 0.])
     g0 = tria_GF(0, 0, tria_zero)
     g1 = tria_GF(0, 0, tria_1nn)
     self.assertAlmostEqual(-6 * g0 + 6 * g1, 1, places=6)
예제 #7
0
 def testhoneycomb(self):
     """Test on honeycomb"""
     honey = crystal.Crystal(
         np.array([[1 / 2, 1 / 2], [-np.sqrt(3 / 4),
                                    np.sqrt(3 / 4)]]),
         [np.array([2 / 3, 1 / 3]),
          np.array([1 / 3, 2 / 3])])
     honey_sitelist = honey.sitelist(0)
     honey_jumpnetwork = honey.jumpnetwork(0, 0.6)
     honey_GF = GFcalc.GFCrystalcalc(honey,
                                     0,
                                     honey_sitelist,
                                     honey_jumpnetwork,
                                     Nmax=4)
     honey_GF.SetRates([1], [0], [1], [0])
     honey_zero = np.zeros(2)
     honey_1nn = honey.pos2cart(np.zeros(2), (0, 1)) - honey.pos2cart(
         np.zeros(2), (0, 0))
     g0 = honey_GF(0, 0, honey_zero)
     g1 = honey_GF(0, 1, honey_1nn)
     self.assertAlmostEqual(-3 * g0 + 3 * g1, 1, places=6)
예제 #8
0
 def testsquare(self):
     """Test on square"""
     square = crystal.Crystal(np.eye(2), [np.zeros(2)])
     square_sitelist = square.sitelist(0)
     square_jumpnetwork = square.jumpnetwork(0, 1.01)
     square_GF = GFcalc.GFCrystalcalc(square,
                                      0,
                                      square_sitelist,
                                      square_jumpnetwork,
                                      Nmax=4)
     square_GF.SetRates([1], [0], [1], [0])
     square_zero = np.zeros(2)
     square_1nn = np.array([1., 0.])
     square_2nn = np.array([1., 1.])
     square_3nn = np.array([2., 0.])
     g0 = square_GF(0, 0, square_zero)
     g1 = square_GF(0, 0, square_1nn)
     g2 = square_GF(0, 0, square_2nn)
     g3 = square_GF(0, 0, square_3nn)
     self.assertAlmostEqual(-4 * g0 + 4 * g1, 1, places=6)
     self.assertAlmostEqual(-4 * g1 + g0 + 2 * g2 + g3, 0, places=6)
예제 #9
0
import numpy as np
import onsager.crystal as crystal
#This will be used to store crystal structures needed to create tests
#omega_Ti crystal structure
a0 = 4.576855
c_a = 2.828683 / a0
alatt = np.array([[0.5, 0.5, 0.], [-np.sqrt(0.75),
                                   np.sqrt(0.75), 0.], [0., 0., c_a]]) * a0
u1 = np.array([0., 0., 0.])
u2 = np.array([1. / 3., 2. / 3., 1. / 2.])
u3 = np.array([2. / 3., 1. / 3., 1. / 2.])
omega_Ti = crystal.Crystal(alatt, [[u1, u2, u3]], ["Ti"])
#simple tetragonal crystal structure
# tet = crystal.Crystal(np.array([[1.2,0.,0.],[0.,1.2,0.],[0.,0.,1.5]]),[[np.zeros(3)]])
# tet2 = crystal.Crystal(np.array([[0.32,0.,0.],[0.,0.32,0.],[0.,0.,0.45]]),[[np.zeros(3),np.array([0.5,0.,0.]),np.array([0.,0.5,0.])]])
# tet3 = crystal.Crystal(np.array([[0.32,0.,0.],[0.,0.32,0.],[0.,0.,0.45]]),[[np.zeros(3),np.array([0.0,0.5,0.])],[np.array([0.5,0.,0.])]],["A","B"])
# print (tet3)
tet = crystal.Crystal(
    np.array([[0.28, 0., 0.], [0., 0.28, 0.], [0., 0., 0.32]]),
    [[np.zeros(3)]])
tet2 = crystal.Crystal(
    np.array([[0.28, 0., 0.], [0., 0.28, 0.], [0., 0., 0.32]]),
    [[np.zeros(3),
      np.array([0.5, 0., 0.]),
      np.array([0., 0.5, 0.])]])
tet3 = crystal.Crystal(
    np.array([[0.32, 0., 0.], [0., 0.32, 0.], [0., 0., 0.45]]),
    [[np.zeros(3), np.array([0.0, 0.5, 0.])], [np.array([0.5, 0., 0.])]],
    ["A", "B"])
tet4 = crystal.Crystal(
    np.array([[0.28, 0., 0.], [0., 0.28, 0.], [0., 0., 0.32]]),
예제 #10
0
    def test_jnet0(self):
        # cube
        famp0 = [
            np.array([1., 0., 0.]) / np.linalg.norm(np.array([1., 0., 0.])) *
            0.126
        ]
        family = [famp0]
        pdbcontainer_cube = dbStates(cube, 0, family)
        jset_cube, jind_cube = pdbcontainer_cube.jumpnetwork(0.3, 0.01, 0.01)
        test_dbi = dumbbell(
            pdbcontainer_cube.getIndex((0, np.array([0.126, 0., 0.]))),
            np.array([0, 0, 0]))
        test_dbf = dumbbell(
            pdbcontainer_cube.getIndex((0, np.array([0.126, 0., 0.]))),
            np.array([0, 1, 0]))
        count = 0
        indices = []
        for i, jlist in enumerate(jset_cube):
            for q, j in enumerate(jlist):
                if j.state1 == test_dbi:
                    if j.state2 == test_dbf:
                        if j.c1 == j.c2 == -1:
                            count += 1
                            indices.append((i, q))
                            jtest = jlist
        # print (indices)
        self.assertEqual(
            count,
            1)  # see that this jump has been taken only once into account
        self.assertEqual(len(jtest), 24)

        # Next FCC
        # test this out with FCC
        fcc = crystal.Crystal.FCC(0.55)
        famp0 = [np.array([1., 1., 0.]) / np.sqrt(2) * 0.2]
        family = [famp0]
        pdbcontainer_fcc = dbStates(fcc, 0, family)
        jset_fcc, jind_fcc = pdbcontainer_fcc.jumpnetwork(0.4, 0.01, 0.01)
        o1 = np.array([1., -1., 0.]) * 0.2 / np.sqrt(2)
        if any(np.allclose(-o1, o) for i, o in pdbcontainer_fcc.iorlist):
            o1 = -o1.copy()
        db1 = dumbbell(pdbcontainer_fcc.getIndex((0, o1)), np.array([0, 0, 0]))
        db2 = dumbbell(pdbcontainer_fcc.getIndex((0, o1)), np.array([0, 0, 1]))
        jmp = jump(db1, db2, 1, 1)
        jtest = []
        for jl in jset_fcc:
            for j in jl:
                if j == jmp:
                    jtest.append(jl)
        # see that the jump has been accounted just once.
        self.assertEqual(len(jtest), 1)
        # See that there 24 jumps. 24 0->0.
        self.assertEqual(len(jtest[0]), 24)

        # DC_Si - same symmetry as FCC, except twice the number of jumps, since we have two basis
        # atoms belonging to the same Wyckoff site, in a crystal with the same lattice vectors.
        latt = np.array([[0., 0.5, 0.5], [0.5, 0., 0.5], [0.5, 0.5, 0.]
                         ]) * 0.55
        DC_Si = crystal.Crystal(
            latt, [[np.array([0., 0., 0.]),
                    np.array([0.25, 0.25, 0.25])]], ["Si"])
        famp0 = [np.array([1., 1., 0.]) / np.sqrt(2) * 0.2]
        family = [famp0]
        pdbcontainer_si = dbStates(DC_Si, 0, family)
        jset_si, jind_si = pdbcontainer_si.jumpnetwork(0.4, 0.01, 0.01)
        o1 = np.array([1., -1., 0.]) * 0.2 / np.sqrt(2)
        if any(np.allclose(-o1, o) for i, o in pdbcontainer_si.iorlist):
            o1 = -o1.copy()
        db1 = dumbbell(pdbcontainer_si.getIndex((0, o1)), np.array([0, 0, 0]))
        db2 = dumbbell(pdbcontainer_si.getIndex((0, o1)), np.array([0, 0, 1]))
        jmp = jump(db1, db2, 1, 1)
        jtest = []
        for jl in jset_si:
            for j in jl:
                if j == jmp:
                    jtest.append(jl)
        # see that the jump has been accounted just once.
        self.assertEqual(len(jtest), 1)
        # See that there 48 jumps. 24 0->0 and 24 1->1.
        self.assertEqual(len(jtest[0]), 48)

        # HCP
        Mg = crystal.Crystal.HCP(0.3294, chemistry=["Mg"])
        famp0 = [np.array([1., 0., 0.]) * 0.145]
        family = [famp0]
        pdbcontainer_hcp = dbStates(Mg, 0, family)
        jset_hcp, jind_hcp = pdbcontainer_hcp.jumpnetwork(0.45, 0.01, 0.01)
        o = np.array([0.145, 0., 0.])
        if any(np.allclose(-o, o1) for i, o1 in pdbcontainer_hcp.iorlist):
            o = -o + 0.
        db1 = dumbbell(pdbcontainer_hcp.getIndex((0, o)),
                       np.array([0, 0, 0], dtype=int))
        db2 = dumbbell(pdbcontainer_hcp.getIndex((1, o)),
                       np.array([0, 0, 0], dtype=int))
        testjump = jump(db1, db2, 1, 1)
        count = 0
        testlist = []
        for jl in jset_hcp:
            for j in jl:
                if j == testjump:
                    count += 1
                    testlist = jl
        self.assertEqual(len(testlist), 24)
        self.assertEqual(count, 1)

        # test_indices
        # First check if they have the same number of lists and elements
        jindlist = [jind_cube, jind_fcc, jind_si, jind_hcp]
        jsetlist = [jset_cube, jset_fcc, jset_si, jset_hcp]
        pdbcontainerlist = [
            pdbcontainer_cube, pdbcontainer_fcc, pdbcontainer_si,
            pdbcontainer_hcp
        ]
        for pdbcontainer, jset, jind in zip(pdbcontainerlist, jsetlist,
                                            jindlist):
            self.assertEqual(len(jind), len(jset))
            # now check if all the elements are correctly correspondent
            for lindex in range(len(jind)):
                self.assertEqual(len(jind[lindex]), len(jset[lindex]))
                for jindex in range(len(jind[lindex])):
                    (i1, o1) = pdbcontainer.iorlist[jind[lindex][jindex][0][0]]
                    (i2, o2) = pdbcontainer.iorlist[jind[lindex][jindex][0][1]]
                    self.assertEqual(
                        pdbcontainer.iorlist[jset[lindex]
                                             [jindex].state1.iorind][0], i1)
                    self.assertEqual(
                        pdbcontainer.iorlist[jset[lindex]
                                             [jindex].state2.iorind][0], i2)
                    self.assertTrue(
                        np.allclose(
                            pdbcontainer.iorlist[
                                jset[lindex][jindex].state1.iorind][1], o1))
                    self.assertTrue(
                        np.allclose(
                            pdbcontainer.iorlist[
                                jset[lindex][jindex].state2.iorind][1], o2))
                    dx = disp(pdbcontainer, jset[lindex][jindex].state1,
                              jset[lindex][jindex].state2)
                    self.assertTrue(np.allclose(dx, jind[lindex][jindex][1]))
예제 #11
0
    def test_mixedjumps(self):
        latt = np.array([[0., 0.5, 0.5], [0.5, 0., 0.5], [0.5, 0.5, 0.]
                         ]) * 0.55
        DC_Si = crystal.Crystal(
            latt, [[np.array([0., 0., 0.]),
                    np.array([0.25, 0.25, 0.25])]], ["Si"])
        famp0 = [np.array([1., 1., 0.]) / np.sqrt(2) * 0.2]
        family = [famp0]
        mdbcontainer = mStates(DC_Si, 0, family)
        jset, jind = mdbcontainer.jumpnetwork(0.4, 0.01, 0.01)
        o1 = np.array([1., 1., 0.]) * 0.2 / np.sqrt(2)
        # if any(np.allclose(-o1, o) for i, o in pdbcontainer.iorlist):
        #     o1 = -o1.copy()
        # db1 = dumbbell(pdbcontainer_si.getIndex((0, o1)), np.array([0, 0, 0]))
        # db2 = dumbbell(pdbcontainer_si.getIndex((0, o1)), np.array([0, 0, 1]))
        test_dbi = dumbbell(mdbcontainer.getIndex((0, o1)), np.array([0, 0,
                                                                      0]))
        test_dbf = dumbbell(mdbcontainer.getIndex((1, o1)), np.array([0, 0,
                                                                      0]))
        count = 0
        jtest = None
        for i, jlist in enumerate(jset):
            for q, j in enumerate(jlist):
                if j.state1.db == test_dbi:
                    if j.state2.db == test_dbf:
                        if j.c1 == j.c2 == 1:
                            count += 1
                            jtest = jlist
        self.assertEqual(
            count,
            1)  # see that this jump has been taken only once into account
        self.assertEqual(len(jtest), 48)

        # check if conditions for mixed dumbbell transitions are satisfied
        count = 0
        for jl in jset:
            for j in jl:
                if j.c1 == -1 or j.c2 == -1:
                    count += 1
                    break
                if not (j.state1.i_s
                        == mdbcontainer.iorlist[j.state1.db.iorind][0]
                        and j.state2.i_s
                        == mdbcontainer.iorlist[j.state2.db.iorind][0]
                        and np.allclose(j.state1.R_s, j.state1.db.R)
                        and np.allclose(j.state2.R_s, j.state2.db.R)):
                    count += 1
                    break
            if count == 1:
                break
        self.assertEqual(count, 0)

        # test_indices
        # First check if they have the same number of lists and elements
        self.assertEqual(len(jind), len(jset))
        # now check if all the elements are correctly correspondent
        for lindex in range(len(jind)):
            self.assertEqual(len(jind[lindex]), len(jset[lindex]))
            for jindex in range(len(jind[lindex])):
                (i1, o1) = mdbcontainer.iorlist[jind[lindex][jindex][0][0]]
                (i2, o2) = mdbcontainer.iorlist[jind[lindex][jindex][0][1]]
                self.assertEqual(
                    mdbcontainer.iorlist[jset[lindex][jindex].state1.db.iorind]
                    [0], i1)
                self.assertEqual(
                    mdbcontainer.iorlist[jset[lindex][jindex].state2.db.iorind]
                    [0], i2)
                self.assertTrue(
                    np.allclose(
                        mdbcontainer.iorlist[
                            jset[lindex][jindex].state1.db.iorind][1], o1))
                self.assertTrue(
                    np.allclose(
                        mdbcontainer.iorlist[
                            jset[lindex][jindex].state2.db.iorind][1], o2))
예제 #12
0
 def testPyrope(self):
     """Test using the pyrope structure: two disconnected symmetry-related networks"""
     a0 = 1.
     chem = 0
     cutoff = 0.31 * a0
     alatt = a0 * np.array([[-0.5, 0.5, 0.5], [0.5, -0.5, 0.5],
                            [0.5, 0.5, -0.5]])
     invlatt = np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]])
     uMg = ((1 / 8, 0, 1 / 4), (3 / 8, 0, 3 / 4), (1 / 4, 1 / 8, 0),
            (3 / 4, 3 / 8, 0), (0, 1 / 4, 1 / 8), (0, 3 / 4, 3 / 8),
            (7 / 8, 0, 3 / 4), (5 / 8, 0, 1 / 4), (3 / 4, 7 / 8, 0),
            (1 / 4, 5 / 8, 0), (0, 3 / 4, 7 / 8), (0, 1 / 4, 5 / 8))
     tovec = lambda x: np.dot(invlatt, x)
     # this is a reduced version of pyrope: just the Mg (24c sites in 230)
     # pyrope2 = half of the sites; makes for a single, connected network
     pyropeMg = crystal.Crystal(alatt,
                                [[vec(w) for w in uMg
                                  for vec in (tovec, )]], ['Mg'])
     pyropeMg2 = crystal.Crystal(
         alatt, [[vec(w) for w in uMg[:6] for vec in (tovec, )]], ['Mg'])
     sitelist = pyropeMg.sitelist(chem)
     sitelist2 = pyropeMg2.sitelist(chem)
     jumpnetwork = pyropeMg.jumpnetwork(chem, cutoff)
     jumpnetwork2 = pyropeMg2.jumpnetwork(chem, cutoff)
     self.assertEqual(len(jumpnetwork), 1)
     self.assertEqual(len(jumpnetwork2), 1)
     GF = GFcalc.GFCrystalcalc(pyropeMg, chem, sitelist, jumpnetwork)
     GF2 = GFcalc.GFCrystalcalc(pyropeMg2, chem, sitelist2, jumpnetwork2)
     GF.SetRates(np.ones(1), np.zeros(1), 0.25 * np.ones(1),
                 np.zeros(1))  # simple tracer
     GF2.SetRates(np.ones(1), np.zeros(1), 0.25 * np.ones(1),
                  np.zeros(1))  # simple tracer
     D0 = np.eye(3) * (1 / 64)
     for D in (GF.D, GF2.D):
         self.assertTrue(
             np.allclose(D0, D),
             msg='Diffusivity does not match?\n{}\n!=\n{}'.format(D0, D))
     basis = pyropeMg.basis[chem]
     # order of testing: 000, 211
     ijlist = ((0, 0), (0, 2))
     dxlist = [np.dot(alatt, basis[j] - basis[i]) for (i, j) in ijlist]
     glist = np.array([GF(i, j, dx) for (i, j), dx in zip(ijlist, dxlist)])
     g2list = np.array(
         [GF2(i, j, dx) for (i, j), dx in zip(ijlist, dxlist)])
     Gref = np.array([2.30796022, 1.30807261])
     self.assertTrue(
         np.allclose(glist, -Gref, rtol=1e-4),
         msg='Does not match Carlson and Wilson values?\n{} !=\n{}'.format(
             glist, Gref))
     # with the nearly disconnected, the rate anisotropy makes comparison of differences
     # much more stable
     self.assertTrue(
         np.allclose(glist, g2list, rtol=1e-12),
         msg='Does not match single network GF values?\n{} !=\n{}'.format(
             glist, g2list))
     for i in range(12):
         for j in range(12):
             dx = np.dot(alatt, basis[j] - basis[i])
             if i // 6 != j // 6:
                 self.assertAlmostEqual(
                     GF(i, j, dx),
                     0,
                     msg='Does not give disconnected networks? {},{}'.
                     format(i, j))
             else:
                 if i >= 6: dxmap = -dx  # inversion
                 else: dxmap = dx
                 self.assertAlmostEqual(
                     GF(i, j, dx),
                     GF2(i % 6, j % 6, dxmap),
                     msg='Does not match single network? {},{}'.format(
                         i, j))
예제 #13
0
 def testOnsagerVacancyMediated(self):
     """Test whether we can write and read an HDF5 group containing a VacancyMediated Onsager Calculator"""
     HCP = crystal.Crystal.HCP(1., np.sqrt(8 / 3))
     HCP_sitelist = HCP.sitelist(0)
     HCP_jumpnetwork = HCP.jumpnetwork(0, 1.01)
     HCP_diffuser = OnsagerCalc.VacancyMediated(HCP, 0, HCP_sitelist,
                                                HCP_jumpnetwork, 1)
     HCP_diffuser.addhdf5(self.f)  # we'll usually dump it in main
     HCP_diffuser_copy = OnsagerCalc.VacancyMediated.loadhdf5(
         self.f)  # should be fully self-contained
     thermaldef = {
         'preV': np.array([1.]),
         'eneV': np.array([0.]),
         'preT0': np.array([1., 1.5]),
         'eneT0': np.array([0.25, 0.35])
     }
     thermaldef.update(HCP_diffuser.maketracerpreene(**thermaldef))
     for L0, Lcopy in zip(
             HCP_diffuser.Lij(
                 *HCP_diffuser.preene2betafree(1.0, **thermaldef)),
             HCP_diffuser_copy.Lij(
                 *HCP_diffuser_copy.preene2betafree(1.0, **thermaldef))):
         self.assertTrue(np.allclose(L0, Lcopy),
                         msg='{}\n!=\n{}'.format(L0, Lcopy))
     # compare tags
     for k in HCP_diffuser.tags.keys():
         self.assertEqual(HCP_diffuser.tags[k], HCP_diffuser_copy.tags[k])
     # do a dictionary check (dictionaries are only added *after* a minimum of one call
     HCP_diffuser.addhdf5(self.f.create_group('new'))
     HCP_diffuser_copy = OnsagerCalc.VacancyMediated.loadhdf5(
         self.f['new'])  # should be fully self-contained
     for L0, Lcopy in zip(
             HCP_diffuser.Lij(
                 *HCP_diffuser.preene2betafree(1.0, **thermaldef)),
             HCP_diffuser_copy.Lij(
                 *HCP_diffuser_copy.preene2betafree(1.0, **thermaldef))):
         self.assertTrue(np.allclose(L0, Lcopy),
                         msg='{}\n!=\n{}'.format(L0, Lcopy))
     # Test with B2 (there are additional terms that get used when we have origin states)
     B2 = crystal.Crystal(
         np.eye(3), [np.zeros(3), np.array([0.45, 0.45, 0.45])])
     B2diffuser = OnsagerCalc.VacancyMediated(B2, 0, B2.sitelist(0),
                                              B2.jumpnetwork(0, 0.99), 1)
     B2diffuser.addhdf5(self.f.create_group('B2'))
     B2diffuser_copy = OnsagerCalc.VacancyMediated.loadhdf5(self.f['B2'])
     Nsites, Njumps = len(B2diffuser.sitelist), len(B2diffuser.om0_jn)
     tdef = {
         'preV': np.ones(Nsites),
         'eneV': np.zeros(Njumps),
         'preT0': np.ones(Njumps),
         'eneT0': np.zeros(Njumps)
     }
     tdef.update(B2diffuser.maketracerpreene(**tdef))
     for L0, Lcopy in zip(
             B2diffuser.Lij(*B2diffuser.preene2betafree(1.0, **tdef)),
             B2diffuser_copy.Lij(
                 *B2diffuser_copy.preene2betafree(1.0, **tdef))):
         self.assertTrue(np.allclose(L0, Lcopy),
                         msg='{}\n!=\n{}'.format(L0, Lcopy))
     # Test with displaced triangle (2D "B2" example):
     tria2 = crystal.Crystal(
         np.array([[1., 0.], [0., np.sqrt(3.)]]),
         [np.zeros(2), np.array([0.5, 0.4])])
     tria2diffuser = OnsagerCalc.VacancyMediated(tria2, 0,
                                                 tria2.sitelist(0),
                                                 tria2.jumpnetwork(0,
                                                                   1.2), 1)
     tria2diffuser.addhdf5(self.f.create_group('tria'))
     tria2diffuser_copy = OnsagerCalc.VacancyMediated.loadhdf5(
         self.f['tria'])
     Nsites, Njumps = len(tria2diffuser.sitelist), len(tria2diffuser.om0_jn)
     tdef2 = {
         'preV': np.ones(Nsites),
         'eneV': np.zeros(Njumps),
         'preT0': np.ones(Njumps),
         'eneT0': np.zeros(Njumps)
     }
     tdef2.update(tria2diffuser.maketracerpreene(**tdef2))
     for L0, Lcopy in zip(
             tria2diffuser.Lij(
                 *tria2diffuser.preene2betafree(1.0, **tdef2)),
             tria2diffuser_copy.Lij(
                 *tria2diffuser_copy.preene2betafree(1.0, **tdef2))):
         self.assertTrue(np.allclose(L0, Lcopy),
                         msg='{}\n!=\n{}'.format(L0, Lcopy))
     # compare tags
     for k in tria2diffuser.tags.keys():
         self.assertEqual(tria2diffuser.tags[k], tria2diffuser_copy.tags[k])