def test_dsaworm(self):
        'Lattice: dsaw orm'
        lattice = Lattice(a=1, b=2, c=3, alpha=89, beta=91, gamma=92)

        orm = self.orm
        latticerecord = orm(lattice)

        orm.save(lattice)

        lattice_loaded = orm.load(Lattice, latticerecord.id)

        props = [d.name for d in Lattice.Inventory.getDescriptors()]
        for prop in props:
            self.assertEqual(getattr(lattice_loaded, prop),
                             getattr(lattice, prop))
            continue
        return
Esempio n. 2
0
def save(filename, material):
    for geo in material.get_geos():
        atoms = geo.get_atoms()
        from matter import Structure, Lattice
        import matter.Atom as matterAtom
        for atom in atoms:
            x, y, z = atom.get_xyz()
            atno = atom.get_atno()
            atoms.append(matterAtom(symbol[atno], [x, y, z]))
        cell = geo.get_cell()
        a, b, c, alph, bet, gam = cell.abcabg
        lattice = Lattice(a, b, c, alph, bet, gam)
        stru = Structure(atoms, lattice)
    import pickle
    output = open(filename, 'wb')
    from Utilities import assureCorrectFileEnding
    filename = assureCorrectFileEnding(filename, 'pkl')
    pickle.dump(stru, output)
    output.close()

    return
Esempio n. 3
0
def makeMatter():
    from matter import Structure, Atom, Lattice
    atoms = [Atom('Fe', xyz=(0, 0, 0)), Atom('Al', xyz=(0.5, 0.5, 0.5))]
    lattice = Lattice(base=((1., 0, 0), (0, 1., 0), (0, 0, 1.)))
    return Structure(atoms, lattice)
Esempio n. 4
0
    def parseLines(self, lines):
        """Parse list of lines in PDFfit format.

        Return Structure object or raise StructureFormatError.
        """
        p_nl = 0
        rlist = []
        try:
            self.stru = PDFFitStructure()
            stru = self.stru
            cell_line_read = False
            stop = len(lines)
            while stop > 0 and lines[stop - 1].strip() == "":
                stop -= 1
            ilines = iter(lines[:stop])
            # read header of PDFFit file
            for l in ilines:
                p_nl += 1
                words = l.split()
                if len(words) == 0 or words[0][0] == '#':
                    continue
                elif words[0] == 'title':
                    stru.description = l.lstrip()[5:].strip()
                elif words[0] == 'scale':
                    stru.pdffit['scale'] = float(words[1])
                elif words[0] == 'sharp':
                    l1 = l.replace(',', ' ')
                    sharp_pars = [float(w) for w in l1.split()[1:]]
                    if len(sharp_pars) < 4:
                        stru.pdffit['delta2'] = sharp_pars[0]
                        stru.pdffit['sratio'] = sharp_pars[1]
                        stru.pdffit['rcut'] = sharp_pars[2]
                    else:
                        stru.pdffit['delta2'] = sharp_pars[0]
                        stru.pdffit['delta1'] = sharp_pars[1]
                        stru.pdffit['sratio'] = sharp_pars[2]
                        stru.pdffit['rcut'] = sharp_pars[3]
                elif words[0] == 'spcgr':
                    key = 'spcgr'
                    start = l.find(key) + len(key)
                    value = l[start:].strip()
                    stru.pdffit['spcgr'] = value
                elif words[0] == 'shape':
                    self._parse_shape(l)
                elif words[0] == 'cell':
                    cell_line_read = True
                    l1 = l.replace(',', ' ')
                    latpars = [float(w) for w in l1.split()[1:7]]
                    stru.lattice = Lattice(*latpars)
                elif words[0] == 'dcell':
                    l1 = l.replace(',', ' ')
                    stru.pdffit['dcell'] = [float(w) for w in l1.split()[1:7]]
                elif words[0] == 'ncell':
                    l1 = l.replace(',', ' ')
                    stru.pdffit['ncell'] = [int(w) for w in l1.split()[1:5]]
                elif words[0] == 'format':
                    if words[1] != 'pdffit':
                        emsg = "%d: file is not in PDFfit format" % p_nl
                        raise StructureFormatError(emsg)
                elif words[0] == 'atoms' and cell_line_read:
                    break
                else:
                    self.ignored_lines.append(l)
            # Header reading finished, check if required lines were present.
            if not cell_line_read:
                emsg = "%d: file is not in PDFfit format" % p_nl
                raise StructureFormatError(emsg)
            # Load data from atom entries.
            p_natoms = reduce(lambda x, y: x * y, stru.pdffit['ncell'])
            # we are now inside data block
            for l in ilines:
                p_nl += 1
                wl1 = l.split()
                element = wl1[0][0].upper() + wl1[0][1:].lower()
                xyz = [float(w) for w in wl1[1:4]]
                occ = float(wl1[4])
                stru.addNewAtom(element, xyz=xyz, occupancy=occ)
                a = stru.getLastAtom()
                p_nl += 1
                wl2 = ilines.next().split()
                a.sigxyz = [float(w) for w in wl2[0:3]]
                a.sigo = float(wl2[3])
                p_nl += 1
                wl3 = ilines.next().split()
                p_nl += 1
                wl4 = ilines.next().split()
                p_nl += 1
                wl5 = ilines.next().split()
                p_nl += 1
                wl6 = ilines.next().split()
                a.sigU = numpy.zeros((3, 3), dtype=float)
                a.U11 = float(wl3[0])
                a.U22 = float(wl3[1])
                a.U33 = float(wl3[2])
                a.sigU[0, 0] = float(wl4[0])
                a.sigU[1, 1] = float(wl4[1])
                a.sigU[2, 2] = float(wl4[2])
                a.U12 = float(wl5[0])
                a.U13 = float(wl5[1])
                a.U23 = float(wl5[2])
                a.sigU[0, 1] = a.sigU[1, 0] = float(wl6[0])
                a.sigU[0, 2] = a.sigU[2, 0] = float(wl6[1])
                a.sigU[1, 2] = a.sigU[2, 1] = float(wl6[2])
            if len(stru) != p_natoms:
                emsg = "expected %d atoms, read %d" % (p_natoms, len(stru))
                raise StructureFormatError(emsg)
            if stru.pdffit['ncell'][:3] != [1, 1, 1]:
                superlatpars = [
                    latpars[i] * stru.pdffit['ncell'][i] for i in range(3)
                ] + latpars[3:]
                superlattice = Lattice(*superlatpars)
                stru.placeInLattice(superlattice)
                stru.pdffit['ncell'] = [1, 1, 1, p_natoms]
        except (ValueError, IndexError):
            emsg = "%d: file is not in PDFfit format" % p_nl
            exc_type, exc_value, exc_traceback = sys.exc_info()
            raise StructureFormatError, emsg, exc_traceback
        return stru
Esempio n. 5
0
def testMatter():

    pwInput = PWInput(config=testSCFString)

    struct = matter.Structure()
    struct.read('data/graphite.cif', format='cif')
    #struct.read('data/PbTe.cif', format='cif')
    #struct.read('data/Ni.stru', format='pdffit')
    #struct.read('data/CdSe-wurtzite.stru', format='pdffit')

    print struct
    print struct.lattice.base

    #struct = Structure(filename='data/Ni.stru')
    #struct = Structure(filename='data/graphite.cif')
    #struct = Structure(filename='data/PbTe.cif')
    #struct = Structure(filename='data/CdSe-wurtzite.stru')
    #struct = Structure(pbte)

    # does not work well in matter:
    #s = pbte.writeStr(format='cif')

    at1 = Atom('V', [0., 0., 0.])
    at2 = Atom('V', [0.5, 0., 0.])
    at3 = Atom('V', [0., 0.5, 0.])
    at4 = Atom('V', [0., 0., 0.5])
    at5 = Atom('V', [0.5, 0.5, 0.])
    at6 = Atom('V', [0., 0.5, 0.5])
    at7 = Atom('V', [0.5, 0., 0.5])
    at8 = Atom('V', [0.5, 0.5, 0.5])

    at9 = Atom('V', [0.25, 0.25, 0.25])
    at10 = Atom('Fe', [0.75, 0.25, 0.25])
    at11 = Atom('V', [0.75, 0.75, 0.25])
    at12 = Atom('Fe', [0.25, 0.75, 0.25])

    at13 = Atom('Fe', [0.25, 0.25, 0.75])
    at14 = Atom('V', [0.75, 0.25, 0.75])
    at15 = Atom('Fe', [0.75, 0.75, 0.75])
    at16 = Atom('V', [0.25, 0.75, 0.75])
    struct2 = Structure([
        at1, at2, at3, at4, at5, at6, at7, at8, at9, at10, at11, at12, at13,
        at14, at15, at16
    ],
                        lattice=Lattice(2, 2, 2, 90, 90, 90))
    #print struct
    massList = [50., 55.]
    psList = ['ps1', 'ps2']

    #massList = [1, 2, 3, 4, 5, 6,1, 2, 3, 4, 5, 6]
    #psList  = ['ps1', 'ps2', 'ps2', 'ps3', 'ps4','ps1', 'ps2', 'ps2', 'ps3', 'ps4']

    #    pwInput.structure.load(ibrav = 0, structure = struct, \
    #                           massList = massList, psList = psList)

    #pwInput.structure.load(structure = struct )

    #print pwInput.structure.atomLabels()

    pwInput.structure.load(structure = struct, ibrav = 2, \
                           massList = massList, psList = psList)

    #    pwInput.structure.setStructureFromDiffpyStructure(struct, \
    #                                                            massList = massList,\
    #                                                            psList = psList)

    #    pwInput.structure.setReducedStructureFromDiffpyStructure(struct, ibrav = 2, \
    #                                                            massList = massList,\
    #                                                            psList = psList)
    # this will update string s:
    #s = ''
    #s = pwInput.structure.toString(string = s)

    #pwInput.removeNamelist('system')
    #pwInput.removeCard('atomic_species')
    #pwInput.removeCard('atomic_positions')
    #pwInput.removeCard('cell_parameters')
    #pwInput.structure.parseInput()

    s = pwInput.structure.toString()

    #pwInput.structure.atomicPositionsType = 'alat'

    #s = pwInput.structure.toString()

    #pwInput.structure.save('scf.in')

    print s
Esempio n. 6
0
    def parseLines(self, lines):
        """Parse list of lines in XYZ format.

        Return Structure object or raise StructureFormatError.
        """
        linefields = [l.split() for l in lines]
        # prepare output structure
        stru = Structure()
        # find first valid record
        start = 0
        for field in linefields:
            if len(field) == 0 or field[0] == "#":
                start += 1
            else:
                break
        # first valid line gives number of atoms
        try:
            lfs = linefields[start]
            w1 = linefields[start][0]
            if len(lfs) == 1 and str(int(w1)) == w1:
                p_natoms = int(w1)
                #try to get lattice vectors from description line
                try:
                    latticeVecs = map(float, linefields[start + 1])
                    assert len(latticeVecs) == 9
                    from matter.Lattice import Lattice
                    reshaped = [
                        latticeVecs[0:3], latticeVecs[3:6], latticeVecs[6:9]
                    ]
                    stru.lattice = Lattice(base=reshaped)
                    needsDescription = True
                except:
                    needsDescription = False
                    stru.description = lines[start + 1].strip()
                start += 2
            else:
                emsg = ("%d: invalid XYZ format, missing number of atoms" %
                        (start + 1))
                raise StructureFormatError(emsg)
        except (IndexError, ValueError):
            exc_type, exc_value, exc_traceback = sys.exc_info()
            emsg = ("%d: invalid XYZ format, missing number of atoms" %
                    (start + 1))
            raise StructureFormatError, emsg, exc_traceback
        # find the last valid record
        stop = len(lines)
        while stop > start and len(linefields[stop - 1]) == 0:
            stop -= 1
        # get out for empty structure
        if p_natoms == 0 or start >= stop:
            return stru
        # here we have at least one valid record line
        nfields = len(linefields[start])
        if nfields != 4 and nfields != 5:
            emsg = "%d: invalid XYZ format, expected 4 or 5 columns" % (start +
                                                                        1)
            raise StructureFormatError(emsg)
        # now try to read all record lines
        try:
            p_nl = start
            for fields in linefields[start:]:
                p_nl += 1
                if fields == []:
                    continue
                elif len(fields) != 4 and len(fields) != 5:
                    emsg = ('%d: all lines must have ' +
                            'a symbol, position, and optionally charge') % p_nl
                    raise StructureFormatError(emsg)
                symbol = fields[0]
                symbol = symbol[0].upper() + symbol[1:].lower()
                xyz = [float(f) for f in fields[1:4]]
                if len(fields) == 5:
                    charge = float(fields[4])
                else:
                    charge = 0.0
                stru.addNewAtom(symbol, xyz=xyz, charge=charge)
        except ValueError:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            emsg = "%d: invalid number format" % p_nl
            raise StructureFormatError, emsg, exc_traceback
        # finally check if all the atoms have been read
        if p_natoms is not None and len(stru) != p_natoms:
            emsg = "expected %d atoms, read %d" % (p_natoms, len(stru))
            raise StructureFormatError(emsg)
        if needsDescription:
            stru.generateDescription()
        return stru
Esempio n. 7
0
 def setUp(self):
     self.lattice = Lattice()
     self.places = 12
     return
Esempio n. 8
0
class TestLattice(unittest.TestCase):
    """test methods of Lattice class"""
    def setUp(self):
        self.lattice = Lattice()
        self.places = 12
        return

    def assertListAlmostEqual(self, l1, l2, places=None):
        """wrapper for list comparison"""
        if places is None: places = self.places
        self.assertEqual(len(l1), len(l2))
        for i in range(len(l1)):
            self.assertAlmostEqual(l1[i], l2[i], places)

    def test_setLatPar(self):
        """check calculation of standard unit cell vectors"""
        from numpy import dot
        from math import radians, sqrt, cos, sin
        norm = lambda x: sqrt(sum([xi**2 for xi in x]))
        cosd = lambda x: cos(radians(x))
        sind = lambda x: sin(radians(x))
        self.lattice.setLatPar(1.0, 2.0, 3.0, 80, 100, 120)
        base = self.lattice.base
        self.assertAlmostEqual(1.0, norm(base[0]), self.places)
        self.assertAlmostEqual(2.0, norm(base[1]), self.places)
        self.assertAlmostEqual(3.0, norm(base[2]), self.places)
        self.assertAlmostEqual(cosd(80.0),
                               dot(base[1], base[2]) / (2 * 3), self.places)
        self.assertAlmostEqual(cosd(100.0),
                               dot(base[0], base[2]) / (1 * 3), self.places)
        self.assertAlmostEqual(cosd(120.0),
                               dot(base[0], base[1]) / (1 * 2), self.places)

    def test_setLatBase(self):
        """check calculation of unit cell rotation"""
        import numpy
        import numpy.linalg as numalg
        base = numpy.array([[1.0, 1.0, 0.0], [0.0, 1.0, 1.0], [1.0, 0.0, 1.0]])
        self.lattice.setLatBase(base)
        self.assertAlmostEqual(self.lattice.a, numpy.sqrt(2.0), self.places)
        self.assertAlmostEqual(self.lattice.b, numpy.sqrt(2.0), self.places)
        self.assertAlmostEqual(self.lattice.c, numpy.sqrt(2.0), self.places)
        self.assertAlmostEqual(self.lattice.alpha, 60.0, self.places)
        self.assertAlmostEqual(self.lattice.beta, 60.0, self.places)
        self.assertAlmostEqual(self.lattice.gamma, 60.0, self.places)
        detR0 = numalg.det(self.lattice.baserot)
        self.assertAlmostEqual(detR0, 1.0, self.places)
        # try if rotation matrix works
        self.assertEqual(numpy.all(base == self.lattice.base), True)
        self.lattice.setLatPar(alpha=44, beta=66, gamma=88)
        self.assertNotEqual(numpy.all(base == self.lattice.base), True)
        self.lattice.setLatPar(alpha=60, beta=60, gamma=60)
        self.assertListAlmostEqual(base[0], self.lattice.base[0])
        self.assertListAlmostEqual(base[1], self.lattice.base[1])
        self.assertListAlmostEqual(base[2], self.lattice.base[2])
        # try base checking
        self.assertRaises(LatticeError, self.lattice.setLatBase,
                          [[1, 0, 0], [1, 0, 0], [0, 0, 1]])
        self.assertRaises(LatticeError, self.lattice.setLatBase,
                          [[1, 0, 0], [0, 0, 1], [0, 1, 0]])
        return

    def test_repr(self):
        """check string representation of this lattice"""
        r = repr(self.lattice)
        self.assertEqual(r, "Lattice()")
        self.lattice.setLatPar(1, 2, 3, 10, 20, 30)
        r = repr(self.lattice)
        r0 = "Lattice(a=1, b=2, c=3, alpha=10, beta=20, gamma=30)"
        self.assertEqual(r, r0)
        base = [[1.0, 1.0, 0.0], [0.0, 2.0, 2.0], [3.0, 0.0, 3.0]]
        self.lattice.setLatBase(base)
        r = repr(self.lattice)
        self.assertEqual(r, "Lattice(base=%r)" % self.lattice.base)

    def test_monkhorst_pack(self):
        self.lattice.setLatPar(3, 3, 3, 90, 90, 90)
        grid = (2, 2, 2)
        print self.lattice.getMonkhorstPackGrid(grid)
        print self.lattice.getFracMonkhorstPackGrid(grid)
Esempio n. 9
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
# USA

# read and view pickled structure object
from matter import Structure, Lattice, Atom
at1 = Atom('C', [0.333333333333333, 0.666666666666667, 0])
at2 = Atom('C', [0.666666666666667, 0.333333333333333, 0])
a = 2.4612
c = 6.7079
graphite = Structure([at1, at2], lattice=Lattice(a, a, c, 90, 90, 120))
print graphite

import pickle
output = open('graphite.pkl', 'wb')
pickle.dump(graphite, output)
output.close()

pkl_file = open('graphite.pkl', 'rb')
g2 = pickle.load(pkl_file)
print g2

#m2 = create_nanotube(10,10,10)
#save_file("nano.xyz", m2)

#atoms = m1.get_atoms()
Esempio n. 10
0
    def test_load_matter(self):
        from matter import Structure, Atom, Lattice
        at1 = Atom('V', [0., 0., 0.])
        at2 = Atom('V', [0.5, 0., 0.])
        at3 = Atom('V', [0., 0.5, 0.])
        at4 = Atom('V', [0., 0., 0.5])
        at5 = Atom('V', [0.5, 0.5, 0.])
        at6 = Atom('V', [0., 0.5, 0.5])
        at7 = Atom('V', [0.5, 0., 0.5])
        at8 = Atom('V', [0.5, 0.5, 0.5])
        at9 = Atom('V', [0.25, 0.25, 0.25])
        at10 = Atom('Fe', [0.75, 0.25, 0.25])
        at11 = Atom('V', [0.75, 0.75, 0.25])
        at12 = Atom('Fe', [0.25, 0.75, 0.25])
        at13 = Atom('Fe', [0.25, 0.25, 0.75])
        at14 = Atom('V', [0.75, 0.25, 0.75])
        at15 = Atom('Fe', [0.75, 0.75, 0.75])
        at16 = Atom('V', [0.25, 0.75, 0.75])
        a = 2. * 5.663 / 1.889725989  # set a in angstrom
        struct = Structure( [ at1, at2, at3, at4, at5, at6, at7, at8, at9, \
                             at10, at11, at12, at13, at14, at15, at16], \
                             lattice = Lattice(a, a, a, 90, 90, 90))
        #print struct
        massList = [50.9415, 55.847]
        psList = ['V.pbe-n-van.UPF', 'Fe.pbe-nd-rrkjus.UPF']
        #self.input.structure.load(structure = struct, ibrav = 2, massList = massList, psList = psList)
        self.input.structure.load(structure=struct,
                                  ibrav=2,
                                  massList=massList,
                                  psList=psList)
        answer1 = """"Face Centered Cubic" cell:
-5.66300000  0.00000000  5.66300000
 0.00000000  5.66300000  5.66300000
-5.66300000  5.66300000  0.00000000

Atomic positions in units of lattice parametr "a":
V       0.00000000  0.00000000  0.00000000  
V       0.50000000  0.00000000  0.00000000  
V       0.25000000  0.25000000  0.25000000  
Fe      0.75000000  0.25000000  0.25000000  

V   50.9415 V.pbe-n-van.UPF
Fe  55.8470 Fe.pbe-nd-rrkjus.UPF
"""
        #print str(self.input.structure)
        self.assertEqual(str(self.input.structure), answer1)
        at1 = Atom('V', [0., 0., 0.])
        at2 = Atom('V', [0.5, 0., 0.])
        at3 = Atom('V', [0., 0.5, 0.])
        at4 = Atom('V', [0., 0., 0.5])
        at5 = Atom('V', [0.5, 0.5, 0.])
        at6 = Atom('V', [0., 0.5, 0.5])
        at7 = Atom('V', [0.5, 0., 0.5])
        at8 = Atom('V', [0.5, 0.5, 0.5])
        at9 = Atom('V', [0.25, 0.25, 0.25])
        at10 = Atom('Fe', [0.75, 0.25, 0.25])
        at11 = Atom('V', [0.75, 0.75, 0.25])
        at12 = Atom('Fe', [0.25, 0.75, 0.25])
        at13 = Atom('Fe', [0.25, 0.25, 0.75])
        at14 = Atom('V', [0.75, 0.25, 0.75])
        at15 = Atom('Fe', [0.75, 0.75, 0.75])
        at16 = Atom('V', [0.25, 0.75, 0.75])
        a = 2. * 5.663 / 1.889725989  # set a in angstrom
        struct2 = Structure( [ at1, at2, at3, at4, at5, at6, at7, at8, at9, \
                             at10, at11, at12, at13, at14, at15, at16], \
                             lattice = Lattice(a, a, a, 90, 90, 90))
        self.input.structure.load(structure=struct2,
                                  massList=massList,
                                  psList=psList)
        answer2 = """"generic" cell:
 11.32600000  0.00000000  0.00000000
 0.00000000  11.32600000  0.00000000
 0.00000000  0.00000000  11.32600000

Atomic positions in units of lattice parametr "a":
V       0.00000000  0.00000000  0.00000000  
V       2.99673076  0.00000000  0.00000000  
V       0.00000000  2.99673076  0.00000000  
V       0.00000000  0.00000000  2.99673076  
V       2.99673076  2.99673076  0.00000000  
V       0.00000000  2.99673076  2.99673076  
V       2.99673076  0.00000000  2.99673076  
V       2.99673076  2.99673076  2.99673076  
V       1.49836538  1.49836538  1.49836538  
Fe      4.49509614  1.49836538  1.49836538  
V       4.49509614  4.49509614  1.49836538  
Fe      1.49836538  4.49509614  1.49836538  
Fe      1.49836538  1.49836538  4.49509614  
V       4.49509614  1.49836538  4.49509614  
Fe      4.49509614  4.49509614  4.49509614  
V       1.49836538  4.49509614  4.49509614  

V   50.9415 V.pbe-n-van.UPF
Fe  55.8470 Fe.pbe-nd-rrkjus.UPF
"""
        #print str(self.input.structure)
        self.assertEqual(str(self.input.structure), answer2)
Esempio n. 11
0
 def setUp(self):
     self.lattice = Lattice()
     self.places = 12
     return
Esempio n. 12
0
class TestLattice(unittest.TestCase):
    """test methods of Lattice class"""

    def setUp(self):
        self.lattice = Lattice()
        self.places = 12
        return

    def assertListAlmostEqual(self, l1, l2, places=None):
        """wrapper for list comparison"""
        if places is None: places = self.places
        self.assertEqual(len(l1), len(l2))
        for i in range(len(l1)):
            self.assertAlmostEqual(l1[i], l2[i], places)

    def test_setLatPar(self):
        """check calculation of standard unit cell vectors"""
        from numpy import dot
        from math import radians, sqrt, cos, sin
        norm = lambda x : sqrt(sum([xi**2 for xi in x]))
        cosd = lambda x : cos(radians(x))
        sind = lambda x : sin(radians(x))
        self.lattice.setLatPar(1.0, 2.0, 3.0, 80, 100, 120)
        base = self.lattice.base
        self.assertAlmostEqual(1.0, norm(base[0]), self.places)
        self.assertAlmostEqual(2.0, norm(base[1]), self.places)
        self.assertAlmostEqual(3.0, norm(base[2]), self.places)
        self.assertAlmostEqual(cosd(80.0),
                dot(base[1],base[2])/(2*3), self.places)
        self.assertAlmostEqual(cosd(100.0),
                dot(base[0],base[2])/(1*3), self.places)
        self.assertAlmostEqual(cosd(120.0),
                dot(base[0],base[1])/(1*2), self.places)

    def test_setLatBase(self):
        """check calculation of unit cell rotation"""
        import numpy
        import numpy.linalg as numalg
        base = numpy.array([[ 1.0,  1.0,  0.0],
                          [ 0.0,  1.0,  1.0],
                          [ 1.0,  0.0,  1.0]])
        self.lattice.setLatBase(base)
        self.assertAlmostEqual(self.lattice.a, numpy.sqrt(2.0), self.places)
        self.assertAlmostEqual(self.lattice.b, numpy.sqrt(2.0), self.places)
        self.assertAlmostEqual(self.lattice.c, numpy.sqrt(2.0), self.places)
        self.assertAlmostEqual(self.lattice.alpha, 60.0, self.places)
        self.assertAlmostEqual(self.lattice.beta,  60.0, self.places)
        self.assertAlmostEqual(self.lattice.gamma, 60.0, self.places)
        detR0 = numalg.det(self.lattice.baserot)
        self.assertAlmostEqual(detR0, 1.0, self.places)
        # try if rotation matrix works
        self.assertEqual(numpy.all(base == self.lattice.base), True)
        self.lattice.setLatPar(alpha=44, beta=66, gamma=88)
        self.assertNotEqual(numpy.all(base == self.lattice.base), True)
        self.lattice.setLatPar(alpha=60, beta=60, gamma=60)
        self.assertListAlmostEqual(base[0], self.lattice.base[0])
        self.assertListAlmostEqual(base[1], self.lattice.base[1])
        self.assertListAlmostEqual(base[2], self.lattice.base[2])
        # try base checking
        self.assertRaises(LatticeError, self.lattice.setLatBase,
                [[1, 0, 0], [1,0,0], [0,0,1]])
        self.assertRaises(LatticeError, self.lattice.setLatBase,
                [[1, 0, 0], [0,0,1], [0,1,0]])
        return

    def test_repr(self):
        """check string representation of this lattice"""
        r = repr(self.lattice)
        self.assertEqual(r, "Lattice()")
        self.lattice.setLatPar(1, 2, 3, 10, 20, 30)
        r = repr(self.lattice)
        r0 = "Lattice(a=1, b=2, c=3, alpha=10, beta=20, gamma=30)"
        self.assertEqual(r, r0)
        base = [[ 1.0,  1.0,  0.0],
                [ 0.0,  2.0,  2.0],
                [ 3.0,  0.0,  3.0]]
        self.lattice.setLatBase(base)
        r = repr(self.lattice)
        self.assertEqual(r, "Lattice(base=%r)" % self.lattice.base)
        
    def test_monkhorst_pack(self):
        self.lattice.setLatPar(3, 3, 3, 90, 90, 90)
        grid = (2,2,2)
        print self.lattice.getMonkhorstPackGrid(grid)
        print self.lattice.getFracMonkhorstPackGrid(grid)