Esempio n. 1
0
 def test_read_rawxyz_bad(self):
     """check exceptions when reading unsupported xy file"""
     stru = self.stru
     self.assertRaises(StructureFormatError, stru.read,
                       datafile('hexagon-raw-bad.xyz'), self.format)
     self.assertRaises(StructureFormatError, stru.read,
                       datafile('hexagon-raw.xy'), self.format)
 def test_read_xyz_bad(self):
     """check exceptions when reading invalid xyz file"""
     stru = self.stru
     self.assertRaises(StructureFormatError, stru.read, datafile("bucky-bad1.xyz"), self.format)
     self.assertRaises(StructureFormatError, stru.read, datafile("bucky-bad2.xyz"), self.format)
     self.assertRaises(StructureFormatError, stru.read, datafile("bucky-plain.xyz"), self.format)
     self.assertRaises(StructureFormatError, stru.read, datafile("hexagon-raw.xy"), self.format)
Esempio n. 3
0
 def test_read_rawxyz_bad(self):
     """check exceptions when reading unsupported xy file"""
     stru = self.stru
     self.assertRaises(StructureFormatError, stru.read,
             datafile('hexagon-raw-bad.xyz'), self.format)
     self.assertRaises(StructureFormatError, stru.read,
             datafile('hexagon-raw.xy'), self.format)
Esempio n. 4
0
 def test_read_pdffit_bad(self):
     """check exceptions when reading invalid pdffit file"""
     stru = self.stru
     self.assertRaises(StructureFormatError, stru.read,
                       datafile('Ni-bad.stru'), self.format)
     self.assertRaises(StructureFormatError, stru.read,
                       datafile('bucky.xyz'), self.format)
     return
Esempio n. 5
0
 def test_read_pdffit_bad(self):
     """check exceptions when reading invalid pdffit file"""
     stru = self.stru
     self.assertRaises(StructureFormatError, stru.read,
             datafile('Ni-bad.stru'), self.format)
     self.assertRaises(StructureFormatError, stru.read,
             datafile('bucky.xyz'), self.format)
     return
Esempio n. 6
0
 def test_read_rawxyz(self):
     """check reading of raw xyz file"""
     stru = self.stru
     stru.read(datafile('bucky-raw.xyz'), self.format)
     s_els = [a.element for a in stru]
     self.assertEqual(stru.title, 'bucky-raw')
     self.assertEqual(s_els, 60*[''])
     stru.read(datafile('hexagon-raw.xyz'), self.format)
     zs = [a.xyz[-1] for a in stru]
     self.assertEqual(zs, 6*[0.0])
Esempio n. 7
0
 def test_read_rawxyz(self):
     """check reading of raw xyz file"""
     stru = self.stru
     stru.read(datafile('bucky-raw.xyz'), self.format)
     s_els = [a.element for a in stru]
     self.assertEqual(stru.title, 'bucky-raw')
     self.assertEqual(s_els, 60 * [''])
     stru.read(datafile('hexagon-raw.xyz'), self.format)
     zs = [a.xyz[-1] for a in stru]
     self.assertEqual(zs, 6 * [0.0])
Esempio n. 8
0
 def test_read_xyz_bad(self):
     """check exceptions when reading invalid xyz file"""
     stru = self.stru
     self.assertRaises(StructureFormatError, stru.read,
                       datafile('bucky-bad1.xyz'), self.format)
     self.assertRaises(StructureFormatError, stru.read,
                       datafile('bucky-bad2.xyz'), self.format)
     self.assertRaises(StructureFormatError, stru.read,
                       datafile('bucky-plain.xyz'), self.format)
     self.assertRaises(StructureFormatError, stru.read,
                       datafile('hexagon-raw.xy'), self.format)
Esempio n. 9
0
 def test_writeStr_pdffit(self):
     """check writing of normal xyz file"""
     stru = self.stru
     stru.read(datafile('Ni.stru'), self.format)
     f_s = open(datafile('Ni.stru')).read()
     f_s = re.sub('[ \t]+', ' ', f_s)
     f_s = re.sub('[ \t]+\n', '\n', f_s)
     s_s = stru.writeStr(self.format)
     s_s = re.sub('[ \t]+', ' ', s_s)
     self.assertEqual(f_s, s_s)
     return
Esempio n. 10
0
 def test_writeStr_pdffit(self):
     """check writing of normal xyz file"""
     stru = self.stru
     stru.read(datafile('Ni.stru'), self.format)
     f_s = open(datafile('Ni.stru')).read()
     f_s = re.sub('[ \t]+', ' ', f_s)
     f_s = re.sub('[ \t]+\n', '\n', f_s)
     s_s = stru.writeStr(self.format)
     s_s = re.sub('[ \t]+', ' ', s_s)
     self.assertEqual(f_s, s_s)
     return
Esempio n. 11
0
 def test_writeStr_pdffit(self):
     """check writing of normal xyz file"""
     stru = self.stru
     stru.read(datafile("Ni.stru"), self.format)
     f_s = open(datafile("Ni.stru")).read()
     f_s = re.sub("[ \t]+", " ", f_s)
     f_s = re.sub("[ \t]+\n", "\n", f_s)
     s_s = stru.writeStr(self.format)
     s_s = re.sub("[ \t]+", " ", s_s)
     self.assertEqual(f_s, s_s)
     return
Esempio n. 12
0
 def setUp(self):
     # load test structures once
     if TestSuperCell.stru_cdse is None:
         cdsefile = datafile("CdSe_bulk.stru")
         TestSuperCell.stru_cdse = Structure(filename=cdsefile)
     if TestSuperCell.stru_ni is None:
         nifile = datafile("Ni.stru")
         TestSuperCell.stru_ni = Structure(filename=nifile)
     # bring them to the instance
     self.stru_cdse = TestSuperCell.stru_cdse
     self.stru_ni = TestSuperCell.stru_ni
     return
Esempio n. 13
0
 def test_badspacegroup_cif(self):
     """Test reading of CIF file with unrecognized space group.
     """
     ptest = self.ptest
     filename = datafile('badspacegroup.cif')
     self.assertRaises(StructureFormatError, ptest.parseFile, filename)
     return
Esempio n. 14
0
 def test_read_plainxyz(self):
     """check reading of a plain xyz file"""
     stru = self.stru
     stru.read(datafile("bucky-plain.xyz"), self.format)
     s_els = [a.element for a in stru]
     self.assertEqual(stru.title, "bucky-plain")
     self.assertEqual(s_els, 60 * ["C"])
Esempio n. 15
0
 def test_read_pdffit_Ni(self):
     """check reading of Ni pdffit structure file"""
     stru = self.stru
     stru.read(datafile('Ni.stru'), self.format)
     f_title = "structure Ni  FCC"
     self.assertEqual(stru.title, f_title)
     self.assertEqual(stru.pdffit['spcgr'], 'Fm-3m')
     s_lat = [
         stru.lattice.a, stru.lattice.b, stru.lattice.c, stru.lattice.alpha,
         stru.lattice.beta, stru.lattice.gamma
     ]
     f_lat = [3.52, 3.52, 3.52, 90.0, 90.0, 90.0]
     for i in range(len(s_lat)):
         self.assertAlmostEqual(s_lat[i], f_lat[i])
     self.assertEqual(stru.pdffit['ncell'], [1, 1, 1, 4])
     s_els = [a.element for a in stru]
     self.assertEqual(s_els, 4 * ['Ni'])
     a0 = stru[0]
     s_xyz = a0.xyz
     f_xyz = [0.0, 0.0, 0.0]
     s_o = a0.occupancy
     f_o = 1.0
     s_U = [a0.U[i][i] for i in range(3)]
     f_U = 3 * [0.00126651]
     for i in range(3):
         self.assertAlmostEqual(s_xyz[i], f_xyz[i])
         self.assertAlmostEqual(s_U[i], f_U[i])
     self.assertAlmostEqual(s_o, f_o)
Esempio n. 16
0
 def test_rwStr_pdb_CdSe(self):
     """check conversion to PDB file format"""
     stru = self.stru
     stru.read(datafile('CdSe_bulk.stru'), 'pdffit')
     s = stru.writeStr(self.format)
     # all lines should be 80 characters long
     linelens = [len(l) for l in s.split('\n') if l != ""]
     self.assertEqual(linelens, len(linelens) * [80])
     # now clean and re-read structure
     stru = Structure()
     stru.readStr(s, self.format)
     s_els = [a.element for a in stru]
     f_els = ['Cd', 'Cd', 'Se', 'Se']
     self.assertEqual(s_els, f_els)
     s_lat = [
         stru.lattice.a, stru.lattice.b, stru.lattice.c, stru.lattice.alpha,
         stru.lattice.beta, stru.lattice.gamma
     ]
     f_lat = [4.235204, 4.235204, 6.906027, 90.0, 90.0, 120.0]
     self.assertListAlmostEqual(s_lat, f_lat)
     a0 = stru[0]
     s_Uii = [a0.U[i, i] for i in range(3)]
     f_Uii = [0.01303035, 0.01303035, 0.01401959]
     self.assertListAlmostEqual(s_Uii, f_Uii)
     s_sigUii = [a0.sigU[i, i] for i in range(3)]
     f_sigUii = [0.00011127, 0.00011127, 0.00019575]
     self.assertListAlmostEqual(s_sigUii, f_sigUii)
     s_title = stru.title
     f_title = "Cell structure file of CdSe #186"
     self.assertEqual(s_title, f_title)
 def test_goodkwarg(self):
     """check loading of CIF file and passing of parser keyword argument.
     """
     f = datafile('graphite.cif')
     stru = loadStructure(f, eps=1e-10)
     self.assertEqual(8, len(stru))
     return
Esempio n. 18
0
 def test_rwStr_pdb_CdSe(self):
     """check conversion to PDB file format"""
     stru = self.stru
     stru.read(datafile('CdSe_bulk.stru'), 'pdffit')
     s = stru.writeStr(self.format)
     # all lines should be 80 characters long
     linelens = [ len(l) for l in s.split('\n') if l != "" ]
     self.assertEqual(linelens, len(linelens)*[80])
     # now clean and re-read structure
     stru = Structure()
     stru.readStr(s, self.format)
     s_els = [a.element for a in stru]
     f_els = ['Cd', 'Cd', 'Se', 'Se']
     self.assertEqual(s_els, f_els)
     s_lat = [ stru.lattice.a, stru.lattice.b, stru.lattice.c,
         stru.lattice.alpha, stru.lattice.beta, stru.lattice.gamma ]
     f_lat = [ 4.235204,  4.235204,  6.906027, 90.0, 90.0, 120.0 ]
     self.assertListAlmostEqual(s_lat, f_lat)
     a0 = stru[0]
     s_Uii = [ a0.U[i,i] for i in range(3) ]
     f_Uii = [ 0.01303035, 0.01303035, 0.01401959 ]
     self.assertListAlmostEqual(s_Uii, f_Uii)
     s_sigUii = [ a0.sigU[i,i] for i in range(3) ]
     f_sigUii = [ 0.00011127, 0.00011127, 0.00019575 ]
     self.assertListAlmostEqual(s_sigUii, f_sigUii)
     s_title = stru.title
     f_title = "Cell structure file of CdSe #186"
     self.assertEqual(s_title, f_title)
 def test_discus(self):
     """check loading of discus file format
     """
     f = datafile('Ni-discus.stru')
     stru = loadStructure(f)
     self.failUnless(type(stru) is PDFFitStructure)
     return
Esempio n. 20
0
 def test_read_bratoms_bad(self):
     """check exceptions when reading invalid bratoms file"""
     badfiles = [
             'LiCl-bad.cif',
             'PbTe.cif',
             'arginine.pdb',
             'ZnSb_RT_Q28X_VM_20_fxiso.rstr',
             'Ni-bad.stru',
             'Ni-discus.stru',
             'Ni.stru',
             'BubbleRaftShort.xcfg',
             'bucky-bad1.xyz',
             'bucky-bad2.xyz',
             'bucky-plain-bad.xyz',
             'bucky-plain.xyz',
             'bucky-raw.xyz',
             'bucky.xyz',
             'hexagon-raw-bad.xyz',
             'hexagon-raw.xyz',
     ]
     for ft in badfiles:
         ff = datafile(ft)
         self.assertRaises(StructureFormatError,
                 self.stru.read, ff, format=self.format)
     return
Esempio n. 21
0
 def test_read_xyz(self):
     """check reading of normal xyz file"""
     stru = self.stru
     stru.read(datafile('bucky.xyz'), self.format)
     s_els = [a.element for a in stru]
     self.assertEqual(stru.title, 'bucky-ball')
     self.assertEqual(s_els, 60*['C'])
 def test_discus(self):
     """check loading of discus file format
     """
     f = datafile('Ni-discus.stru')
     stru = loadStructure(f)
     self.failUnless(type(stru) is PDFFitStructure)
     return
Esempio n. 23
0
 def test_read_pdffit_Ni(self):
     """check reading of Ni pdffit structure file"""
     stru = self.stru
     stru.read(datafile('Ni.stru'), self.format)
     f_title = "structure Ni  FCC"
     self.assertEqual(stru.title, f_title)
     self.assertEqual(stru.pdffit['spcgr'], 'Fm-3m')
     s_lat = [ stru.lattice.a, stru.lattice.b, stru.lattice.c,
         stru.lattice.alpha, stru.lattice.beta, stru.lattice.gamma ]
     f_lat = [3.52, 3.52, 3.52, 90.0, 90.0, 90.0]
     for i in range(len(s_lat)):
         self.assertAlmostEqual(s_lat[i], f_lat[i])
     self.assertEqual(stru.pdffit['ncell'], [1,1,1,4])
     s_els = [a.element for a in stru]
     self.assertEqual(s_els, 4*['Ni'])
     a0 = stru[0]
     s_xyz = a0.xyz
     f_xyz = [0.0, 0.0, 0.0];
     s_o = a0.occupancy
     f_o = 1.0
     s_U = [ a0.U[i][i] for i in range(3) ]
     f_U = 3*[0.00126651]
     for i in range(3):
         self.assertAlmostEqual(s_xyz[i], f_xyz[i])
         self.assertAlmostEqual(s_U[i], f_U[i])
     self.assertAlmostEqual(s_o, f_o)
Esempio n. 24
0
 def test_read_pdffit_Ni_prim123(self):
     """check reading of Ni_prim supercell 1x2x3"""
     stru = self.stru
     stru.read(datafile('Ni_prim123.stru'), self.format)
     s_lat = [
         stru.lattice.a, stru.lattice.b, stru.lattice.c, stru.lattice.alpha,
         stru.lattice.beta, stru.lattice.gamma
     ]
     f_lat = [2.489016, 2 * 2.489016, 3 * 2.489016, 60.0, 60.0, 60.0]
     for i in range(len(s_lat)):
         self.assertAlmostEqual(s_lat[i], f_lat[i])
     s_els = [a.element for a in stru]
     self.assertEqual(s_els, 6 * ['Ni'])
     a5 = stru[5]
     s_xyz = a5.xyz
     f_xyz = [0.0, 1.0 / 2.0, 2.0 / 3.0]
     for i in range(3):
         self.assertAlmostEqual(s_xyz[i], f_xyz[i])
     s_o = a5.occupancy
     f_o = 1.0
     self.assertAlmostEqual(s_o, f_o)
     s_U = [
         a5.U[ij[0], ij[1]]
         for ij in [(0, 0), (1, 1), (2, 2), (0, 1), (0, 2), (1, 2)]
     ]
     f_U = 3 * [0.00126651] + 3 * [-0.00042217]
     for i in range(len(s_U)):
         self.assertAlmostEqual(s_U[i], f_U[i])
     return
 def test_goodkwarg(self):
     """check loading of CIF file and passing of parser keyword argument.
     """
     f = datafile('graphite.cif')
     stru = loadStructure(f, eps=1e-10)
     self.assertEqual(8, len(stru))
     return
Esempio n. 26
0
 def test_read_xyz(self):
     """check reading of normal xyz file"""
     stru = self.stru
     stru.read(datafile('bucky.xyz'), self.format)
     s_els = [a.element for a in stru]
     self.assertEqual(stru.title, 'bucky-ball')
     self.assertEqual(s_els, 60 * ['C'])
Esempio n. 27
0
 def test_read_bratoms_bad(self):
     """check exceptions when reading invalid bratoms file"""
     badfiles = [
         'LiCl-bad.cif',
         'PbTe.cif',
         'arginine.pdb',
         'ZnSb_RT_Q28X_VM_20_fxiso.rstr',
         'Ni-bad.stru',
         'Ni-discus.stru',
         'Ni.stru',
         'BubbleRaftShort.xcfg',
         'bucky-bad1.xyz',
         'bucky-bad2.xyz',
         'bucky-plain-bad.xyz',
         'bucky-plain.xyz',
         'bucky-raw.xyz',
         'bucky.xyz',
         'hexagon-raw-bad.xyz',
         'hexagon-raw.xyz',
     ]
     for ft in badfiles:
         ff = datafile(ft)
         self.assertRaises(StructureFormatError,
                           self.stru.read,
                           ff,
                           format=self.format)
     return
Esempio n. 28
0
 def test_read_pdffit_Ni_prim123(self):
     """check reading of Ni_prim supercell 1x2x3"""
     stru = self.stru
     stru.read(datafile('Ni_prim123.stru'), self.format)
     s_lat = [ stru.lattice.a, stru.lattice.b, stru.lattice.c,
         stru.lattice.alpha, stru.lattice.beta, stru.lattice.gamma ]
     f_lat = [2.489016,  2*2.489016,  3*2.489016, 60.0, 60.0, 60.0]
     for i in range(len(s_lat)):
         self.assertAlmostEqual(s_lat[i], f_lat[i])
     s_els = [a.element for a in stru]
     self.assertEqual(s_els, 6*['Ni'])
     a5 = stru[5]
     s_xyz = a5.xyz
     f_xyz = [0.0, 1.0/2.0, 2.0/3.0];
     for i in range(3):
         self.assertAlmostEqual(s_xyz[i], f_xyz[i])
     s_o = a5.occupancy
     f_o = 1.0
     self.assertAlmostEqual(s_o, f_o)
     s_U = [ a5.U[ij[0],ij[1]]
             for ij in [(0,0), (1,1), (2,2), (0,1), (0,2), (1,2)] ]
     f_U = 3*[0.00126651] + 3*[-0.00042217]
     for i in range(len(s_U)):
         self.assertAlmostEqual(s_U[i], f_U[i])
     return
 def test_cif(self):
     """check loading of CIF file format
     """
     f = datafile('PbTe.cif')
     stru = loadStructure(f)
     self.assertTrue(isinstance(stru, Structure))
     self.assertFalse(isinstance(stru, PDFFitStructure))
     return
 def test_xcfg(self):
     """check loading of atomeye xcfg format
     """
     f = datafile('BubbleRaftShort.xcfg')
     stru = loadStructure(f)
     self.failUnless(type(stru) is Structure)
     self.assertRaises(StructureFormatError, loadStructure, f, 'xyz')
     return
Esempio n. 31
0
 def test_cif(self):
     """check loading of CIF file format
     """
     f = datafile('PbTe.cif')
     stru = loadStructure(f)
     self.assertTrue(isinstance(stru, Structure))
     self.assertFalse(isinstance(stru, PDFFitStructure))
     return
 def test_cif(self):
     """check loading of CIF file format
     """
     f = datafile('PbTe.cif')
     stru = loadStructure(f)
     self.failUnless(isinstance(stru, Structure))
     self.failIf(isinstance(stru, PDFFitStructure))
     return
 def test_cif(self):
     """check loading of CIF file format
     """
     f = datafile('PbTe.cif')
     stru = loadStructure(f)
     self.failUnless(isinstance(stru, Structure))
     self.failIf(isinstance(stru, PDFFitStructure))
     return
 def test_xcfg(self):
     """check loading of atomeye xcfg format
     """
     f = datafile('BubbleRaftShort.xcfg')
     stru = loadStructure(f)
     self.failUnless(type(stru) is Structure)
     self.assertRaises(StructureFormatError,
             loadStructure, f, 'xyz')
     return
Esempio n. 35
0
 def test_huge_occupancy(self):
     """check structure with huge occupancy can be read.
     """
     self.stru.read(datafile('Ni.stru'), self.format)
     self.stru[0].occupancy = 16e16
     s_s = self.stru.writeStr(self.format)
     stru1 = Structure()
     stru1.readStr(s_s, self.format)
     self.assertEqual(16e16, stru1[0].occupancy)
     return
Esempio n. 36
0
 def test_nosites_cif(self):
     """Test reading of CIF file with no valid sites.
     """
     ptest = self.ptest
     stru = ptest.parseFile(datafile('nosites.cif'))
     self.assertEqual(0, len(stru))
     self.assertEqual(10.413, stru.lattice.a)
     self.assertEqual(10.413, stru.lattice.b)
     self.assertEqual(10.413, stru.lattice.c)
     return
Esempio n. 37
0
 def test_huge_occupancy(self):
     """check structure with huge occupancy can be read.
     """
     self.stru.read(datafile('Ni.stru'), self.format)
     self.stru[0].occupancy = 16e16
     s_s = self.stru.writeStr(self.format)
     stru1 = Structure()
     stru1.readStr(s_s, self.format)
     self.assertEqual(16e16, stru1[0].occupancy)
     return
Esempio n. 38
0
 def test_stepcut_parsing(self):
     """check parsing of stepcut record from a file.
     """
     stru = self.stru
     stru.read(datafile("Ni.stru"), self.format)
     self.assertEqual(0, stru.pdffit["stepcut"])
     snoshape = stru.writeStr(format=self.format)
     self.failUnless(not re.search("(?m)^shape", snoshape))
     # produce a string with non-zero stepcut
     stru.pdffit["stepcut"] = 13
     s13 = stru.writeStr(format=self.format)
     self.failUnless(re.search("(?m)^shape +stepcut, ", s13))
     stru13 = Structure()
     stru13.readStr(s13)
     self.assertEqual(13, stru13.pdffit["stepcut"])
     ni_lines = open(datafile("Ni.stru")).readlines()
     ni_lines.insert(3, "shape invalid, 7\n")
     sbad = "".join(ni_lines)
     self.assertRaises(StructureFormatError, self.stru.readStr, sbad, format=self.format)
     return
Esempio n. 39
0
 def test_spdiameter_parsing(self):
     """check parsing of spdiameter record from a file.
     """
     stru = self.stru
     stru.read(datafile('Ni.stru'), self.format)
     self.assertEqual(0, stru.pdffit['spdiameter'])
     snoshape = stru.writeStr(format=self.format)
     self.failUnless(not re.search('(?m)^shape', snoshape))
     # produce a string with non-zero spdiameter
     stru.pdffit['spdiameter'] = 13
     s13 = stru.writeStr(format=self.format)
     self.failUnless(re.search('(?m)^shape +sphere, ', s13))
     stru13 = Structure()
     stru13.readStr(s13)
     self.assertEqual(13, stru13.pdffit['spdiameter'])
     ni_lines = open(datafile('Ni.stru')).readlines()
     ni_lines.insert(3, 'shape invalid, 7\n')
     sbad = ''.join(ni_lines)
     self.assertRaises(StructureFormatError, self.stru.readStr,
             sbad, format=self.format)
     return
Esempio n. 40
0
 def test_stepcut_parsing(self):
     """check parsing of stepcut record from a file.
     """
     stru = self.stru
     stru.read(datafile('Ni-discus.stru'), self.format)
     self.assertEqual(0, stru.pdffit['stepcut'])
     snoshape = stru.writeStr(format=self.format)
     self.assertTrue(not re.search('(?m)^shape', snoshape))
     # produce a string with non-zero stepcut
     stru.pdffit['stepcut'] = 13
     s13 = stru.writeStr(format=self.format)
     self.assertTrue(re.search('(?m)^shape +stepcut, ', s13))
     stru13 = Structure()
     stru13.readStr(s13)
     self.assertEqual(13, stru13.pdffit['stepcut'])
     ni_lines = open(datafile('Ni.stru')).readlines()
     ni_lines.insert(3, 'shape invalid, 7\n')
     sbad = ''.join(ni_lines)
     self.assertRaises(StructureFormatError, self.stru.readStr,
             sbad, format=self.format)
     return
Esempio n. 41
0
 def test_read_xcfg(self):
     """check reading of BubbleRaft XCFG file"""
     stru = self.stru
     stru.read(datafile('BubbleRaftShort.xcfg'), self.format)
     f_els = 500* [ "Ar" ]
     s_els = [a.element for a in stru]
     self.assertEqual(s_els, f_els)
     self.assertAlmostEqual(stru.distance(82, 357), 47.5627, 3)
     s_lat = [ stru.lattice.a, stru.lattice.b, stru.lattice.c,
         stru.lattice.alpha, stru.lattice.beta, stru.lattice.gamma ]
     f_lat = [127.5, 119.5, 3.0, 90.0, 90.0, 90.0]
     self.assertListAlmostEqual(s_lat, f_lat)
Esempio n. 42
0
 def test_read_xcfg(self):
     """check reading of BubbleRaft XCFG file"""
     stru = self.stru
     stru.read(datafile('BubbleRaftShort.xcfg'), self.format)
     f_els = 500 * ["Ar"]
     s_els = [a.element for a in stru]
     self.assertEqual(s_els, f_els)
     self.assertAlmostEqual(stru.distance(82, 357), 47.5627, 3)
     s_lat = [
         stru.lattice.a, stru.lattice.b, stru.lattice.c, stru.lattice.alpha,
         stru.lattice.beta, stru.lattice.gamma
     ]
     f_lat = [127.5, 119.5, 3.0, 90.0, 90.0, 90.0]
     self.assertListAlmostEqual(s_lat, f_lat)
Esempio n. 43
0
 def test_ignored_lines(self):
     """check skipping of ignored lines in the header
     """
     r1 = "ignored record 1"
     r2 = "ignored record 2"
     ni_lines = open(datafile("Ni.stru")).readlines()
     ni_lines.insert(2, r1 + "\n")
     ni_lines.insert(4, r2 + "\n")
     s_s1 = "".join(ni_lines)
     p = self.stru.readStr(s_s1, self.format)
     self.assertEqual([r1, r2], p.ignored_lines)
     ni_lines.insert(-3, r1 + "\n")
     s_s2 = "".join(ni_lines)
     self.assertRaises(StructureFormatError, self.stru.readStr, s_s2, self.format)
     return
Esempio n. 44
0
 def test_read_pdb_arginine(self):
     """check reading of arginine PDB file"""
     stru = self.stru
     stru.read(datafile('arginine.pdb'), self.format)
     f_els = [ "N", "C", "C", "O", "C", "C", "C", "N", "C", "N", "N", "H",
         "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H",
         "O", "H" ]
     s_els = [a.element for a in stru]
     self.assertEqual(s_els, f_els)
     s_lat = [ stru.lattice.a, stru.lattice.b, stru.lattice.c,
         stru.lattice.alpha, stru.lattice.beta, stru.lattice.gamma ]
     f_lat = [1.0, 1.0, 1.0, 90.0, 90.0, 90.0]
     self.assertEqual(s_lat, f_lat)
     a0 = stru[0]
     self.assertListAlmostEqual(a0.xyz, [0.735, 2.219, 1.389])
Esempio n. 45
0
 def test_ignored_lines(self):
     """check skipping of ignored lines in the header
     """
     r1 = 'ignored record 1'
     r2 = 'ignored record 2'
     ni_lines = open(datafile('Ni.stru')).readlines()
     ni_lines.insert(2, r1 + '\n')
     ni_lines.insert(4, r2 + '\n')
     s_s1 = "".join(ni_lines)
     p = self.stru.readStr(s_s1, self.format)
     self.assertEqual([r1, r2], p.ignored_lines)
     ni_lines.insert(-3, r1 + '\n')
     s_s2 = "".join(ni_lines)
     self.assertRaises(StructureFormatError, self.stru.readStr, s_s2,
                       self.format)
     return
Esempio n. 46
0
 def test_ignored_lines(self):
     """check skipping of ignored lines in the header
     """
     r1 = 'ignored record 1\n'
     r2 = 'ignored record 2\n'
     ni_lines = open(datafile('Ni-discus.stru')).readlines()
     ni_lines.insert(2, r1)
     ni_lines.insert(4, r2)
     s_s1 = "".join(ni_lines)
     p = self.stru.readStr(s_s1, self.format)
     self.assertEqual([r1.rstrip(), r2.rstrip()], p.ignored_lines)
     ni_lines.append(r1)
     s_s2 = "".join(ni_lines)
     self.assertRaises(StructureFormatError, self.stru.readStr,
             s_s2, self.format)
     return
Esempio n. 47
0
 def test_ignored_lines(self):
     """check skipping of ignored lines in the header
     """
     r1 = 'ignored record 1\n'
     r2 = 'ignored record 2\n'
     ni_lines = open(datafile('Ni-discus.stru')).readlines()
     ni_lines.insert(2, r1)
     ni_lines.insert(4, r2)
     s_s1 = "".join(ni_lines)
     p = self.stru.readStr(s_s1, self.format)
     self.assertEqual([r1.rstrip(), r2.rstrip()], p.ignored_lines)
     ni_lines.append(r1)
     s_s2 = "".join(ni_lines)
     self.assertRaises(StructureFormatError, self.stru.readStr,
             s_s2, self.format)
     return
Esempio n. 48
0
 def test_rwStr_xcfg_CdSe(self):
     """check conversion to XCFG file format"""
     stru = self.stru
     stru.read(datafile('CdSe_bulk.stru'), 'pdffit')
     s = stru.writeStr(self.format)
     stru = Structure()
     stru.readStr(s, self.format)
     s_els = [a.element for a in stru]
     f_els = ['Cd', 'Cd', 'Se', 'Se']
     self.assertEqual(s_els, f_els)
     s_lat = [ stru.lattice.a, stru.lattice.b, stru.lattice.c,
         stru.lattice.alpha, stru.lattice.beta, stru.lattice.gamma ]
     f_lat = [ 4.235204,  4.235204,  6.906027, 90.0, 90.0, 120.0 ]
     self.assertListAlmostEqual(s_lat, f_lat)
     a0 = stru[0]
     s_Uii = [ a0.U[i,i] for i in range(3) ]
     f_Uii = [ 0.01303035, 0.01303035, 0.01401959 ]
     self.assertListAlmostEqual(s_Uii, f_Uii)
Esempio n. 49
0
 def test_read_pdffit_ZnSb(self):
     """check reading of ZnSb pdffit structure file"""
     stru = self.stru
     stru.read(datafile("ZnSb_RT_Q28X_VM_20_fxiso.rstr"), self.format)
     f_title = "Cell structure file of Zn4Sb3 #167 interstitial"
     self.assertEqual(stru.title, f_title)
     self.assertAlmostEqual(stru.pdffit["scale"], 0.826145)
     self.assertAlmostEqual(stru.pdffit["delta2"], 4.687951)
     self.assertAlmostEqual(stru.pdffit["delta1"], 0.01)
     self.assertAlmostEqual(stru.pdffit["sratio"], 1.02)
     self.assertAlmostEqual(stru.pdffit["rcut"], 0.03)
     self.assertEqual(stru.pdffit["spcgr"], "R-3c")
     s_lat = [
         stru.lattice.a,
         stru.lattice.b,
         stru.lattice.c,
         stru.lattice.alpha,
         stru.lattice.beta,
         stru.lattice.gamma,
     ]
     f_lat = [12.309436, 12.309436, 12.392839, 90.0, 90.0, 120.0]
     self.assertListAlmostEqual(s_lat, f_lat)
     s_dcell = stru.pdffit["dcell"]
     f_dcell = [0.000008, 0.000008, 0.000013, 0.0, 0.0, 0.0]
     self.assertListAlmostEqual(s_dcell, f_dcell)
     self.assertEqual(stru.pdffit["ncell"], [1, 1, 1, 66])
     s_els = [a.element for a in stru]
     self.assertEqual(s_els, 36 * ["Zn"] + 30 * ["Sb"])
     a0 = stru[0]
     s_xyz = a0.xyz
     f_xyz = [0.09094387, 0.24639539, 0.40080261]
     s_o = a0.occupancy
     f_o = 0.9
     s_sigxyz = a0.sigxyz
     f_sigxyz = [0.00000079, 0.00000076, 0.00000064]
     s_sigo = a0.sigo
     f_sigo = 0.0
     s_U = [a0.U[i][i] for i in range(3)]
     f_U = 3 * [0.01]
     self.assertListAlmostEqual(s_xyz, f_xyz)
     self.assertListAlmostEqual(s_sigxyz, f_sigxyz)
     self.assertListAlmostEqual(s_U, f_U)
     self.assertAlmostEqual(s_o, f_o)
     self.assertAlmostEqual(s_sigo, f_sigo)
Esempio n. 50
0
 def test_read_pdb_arginine(self):
     """check reading of arginine PDB file"""
     stru = self.stru
     stru.read(datafile('arginine.pdb'), self.format)
     f_els = [
         "N", "C", "C", "O", "C", "C", "C", "N", "C", "N", "N", "H", "H",
         "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "O",
         "H"
     ]
     s_els = [a.element for a in stru]
     self.assertEqual(s_els, f_els)
     s_lat = [
         stru.lattice.a, stru.lattice.b, stru.lattice.c, stru.lattice.alpha,
         stru.lattice.beta, stru.lattice.gamma
     ]
     f_lat = [1.0, 1.0, 1.0, 90.0, 90.0, 90.0]
     self.assertEqual(s_lat, f_lat)
     a0 = stru[0]
     self.assertListAlmostEqual(a0.xyz, [0.735, 2.219, 1.389])
Esempio n. 51
0
 def test_rwStr_xcfg_CdSe(self):
     """check conversion to XCFG file format"""
     stru = self.stru
     stru.read(datafile('CdSe_bulk.stru'), 'pdffit')
     s = stru.writeStr(self.format)
     stru = Structure()
     stru.readStr(s, self.format)
     s_els = [a.element for a in stru]
     f_els = ['Cd', 'Cd', 'Se', 'Se']
     self.assertEqual(s_els, f_els)
     s_lat = [
         stru.lattice.a, stru.lattice.b, stru.lattice.c, stru.lattice.alpha,
         stru.lattice.beta, stru.lattice.gamma
     ]
     f_lat = [4.235204, 4.235204, 6.906027, 90.0, 90.0, 120.0]
     self.assertListAlmostEqual(s_lat, f_lat)
     a0 = stru[0]
     s_Uii = [a0.U[i, i] for i in range(3)]
     f_Uii = [0.01303035, 0.01303035, 0.01401959]
     self.assertListAlmostEqual(s_Uii, f_Uii)
Esempio n. 52
0
 def test_read_discus_Ni(self):
     """check reading of Ni structure in discus format"""
     stru = self.stru
     stru.read(datafile('Ni-discus.stru'), self.format)
     f_title = 'structure Ni  FCC'
     self.assertEqual(f_title, stru.title)
     self.assertEqual('Fm-3m', stru.pdffit['spcgr'])
     # cell record
     abcABG = (3.52, 3.52, 3.52, 90.0, 90.0, 90.0)
     self.assertEqual(abcABG, stru.lattice.abcABG())
     # ncell
     self.assertEqual([1, 1, 1, 4], stru.pdffit['ncell'])
     self.assertEqual(4, len(stru))
     # first atom
     a0 = stru[0]
     self.assertEqual((0.0, 0.0, 0.0), tuple(a0.xyz))
     self.failUnless(not a0.anisotropy)
     Biso0 = 0.1
     self.assertAlmostEqual(Biso0, a0.Bisoequiv, self.places)
     return
Esempio n. 53
0
 def test_read_discus_Ni(self):
     """check reading of Ni structure in discus format"""
     stru = self.stru
     stru.read(datafile('Ni-discus.stru'), self.format)
     f_title = 'structure Ni  FCC'
     self.assertEqual(f_title, stru.title)
     self.assertEqual('Fm-3m', stru.pdffit['spcgr'])
     # cell record
     abcABG = (3.52, 3.52, 3.52, 90.0, 90.0, 90.0)
     self.assertEqual(abcABG, stru.lattice.abcABG())
     # ncell
     self.assertEqual([1, 1, 1, 4], stru.pdffit['ncell'])
     self.assertEqual(4, len(stru))
     # first atom
     a0 = stru[0]
     self.assertEqual((0.0, 0.0, 0.0), tuple(a0.xyz))
     self.assertTrue(not a0.anisotropy)
     Biso0 = 0.1
     self.assertAlmostEqual(Biso0, a0.Bisoequiv, self.places)
     return
Esempio n. 54
0
 def test_read_pdffit_ZnSb(self):
     """check reading of ZnSb pdffit structure file"""
     stru = self.stru
     stru.read(datafile('ZnSb_RT_Q28X_VM_20_fxiso.rstr'), self.format)
     f_title = "Cell structure file of Zn4Sb3 #167 interstitial"
     self.assertEqual(stru.title, f_title)
     self.assertAlmostEqual(stru.pdffit['scale'], 0.826145)
     self.assertAlmostEqual(stru.pdffit['delta2'], 4.687951)
     self.assertAlmostEqual(stru.pdffit['delta1'], 0.01)
     self.assertAlmostEqual(stru.pdffit['sratio'], 1.02)
     self.assertAlmostEqual(stru.pdffit['rcut'], 0.03)
     self.assertEqual(stru.pdffit['spcgr'], 'R-3c')
     s_lat = [
         stru.lattice.a, stru.lattice.b, stru.lattice.c, stru.lattice.alpha,
         stru.lattice.beta, stru.lattice.gamma
     ]
     f_lat = [12.309436, 12.309436, 12.392839, 90.0, 90.0, 120.0]
     self.assertListAlmostEqual(s_lat, f_lat)
     s_dcell = stru.pdffit['dcell']
     f_dcell = [0.000008, 0.000008, 0.000013, 0.0, 0.0, 0.0]
     self.assertListAlmostEqual(s_dcell, f_dcell)
     self.assertEqual(stru.pdffit['ncell'], [1, 1, 1, 66])
     s_els = [a.element for a in stru]
     self.assertEqual(s_els, 36 * ['Zn'] + 30 * ['Sb'])
     a0 = stru[0]
     s_xyz = a0.xyz
     f_xyz = [0.09094387, 0.24639539, 0.40080261]
     s_o = a0.occupancy
     f_o = 0.9
     s_sigxyz = a0.sigxyz
     f_sigxyz = [0.00000079, 0.00000076, 0.00000064]
     s_sigo = a0.sigo
     f_sigo = 0.0
     s_U = [a0.U[i][i] for i in range(3)]
     f_U = 3 * [0.01]
     self.assertListAlmostEqual(s_xyz, f_xyz)
     self.assertListAlmostEqual(s_sigxyz, f_sigxyz)
     self.assertListAlmostEqual(s_U, f_U)
     self.assertAlmostEqual(s_o, f_o)
     self.assertAlmostEqual(s_sigo, f_sigo)
Esempio n. 55
0
"""Unit tests for Structure class.
"""


import copy
import unittest
import numpy

from diffpy.Structure.tests.testutils import datafile
from diffpy.Structure import Structure
from diffpy.Structure import Lattice
from diffpy.Structure import Atom

# useful variables
cdsefile = datafile('CdSe_bulk.stru')
teifile = datafile('TeI.cif')
pbtefile = datafile('PbTe.cif')

##############################################################################
class TestStructure(unittest.TestCase):
    """test methods of Structure class"""

    _loaded_structures = {}

    def setUp(self):
        self.stru = Structure( [ Atom('C', [0,0,0]), Atom('C', [1,1,1]) ],
                lattice=Lattice(1, 1, 1, 90, 90, 120) )
        if not self._loaded_structures:
            self._loaded_structures.update([
                ('cdse', Structure(filename=cdsefile)),
Esempio n. 56
0
 def test_writeStr_cif(self):
     """check conversion to CIF string"""
     stru = self.stru
     stru.read(datafile('GaAs.inp'), 'bratoms')
     s_s = stru.writeStr(self.format)
 def test_badkwarg(self):
     """check loading of xyz file format with invalid keyword argument
     """
     f = datafile('bucky.xyz')
     self.assertRaises(TypeError, loadStructure, f, eps=1e-10)
     return
Esempio n. 58
0
class TestP_cif(unittest.TestCase):

    goodciffile = datafile('PbTe.cif')
    badciffile = datafile('LiCl-bad.cif')
    graphiteciffile = datafile('graphite.cif')
    cdsebulkpdffitfile = datafile('CdSe_bulk.stru')
    teiciffile = datafile('TeI.cif')
    places = 6

    def setUp(self):
        self.ptest = P_cif()
        self.pfile = P_cif()
        return

    def tearDown(self):
        return

    def test_parse(self):
        """check P_cif.parse()
        """
        sgood = open(self.goodciffile).read()
        sbad = open(self.badciffile).read()
        pfile, ptest = self.pfile, self.ptest
        stru_check = pfile.parseFile(self.goodciffile)
        stru = ptest.parse(sgood)
        self.assertEqual(str(stru_check), str(stru))
        self.assertEqual(str(stru_check.lattice), str(stru.lattice))
        self.assertEqual(pfile.spacegroup.short_name,
            ptest.spacegroup.short_name)
        ptestb = P_cif()
        self.assertRaises(StructureFormatError,
            ptestb.parse, sbad)
        return

    def test_parseLines(self):
        """check P_cif.parseLines()
        """
        goodlines = open(self.goodciffile).readlines()
        badlines = open(self.badciffile).readlines()
        pfile, ptest = self.pfile, self.ptest
        stru_check = pfile.parseFile(self.goodciffile)
        stru = ptest.parseLines(goodlines)
        self.assertEqual(str(stru_check), str(stru))
        self.assertEqual(str(stru_check.lattice), str(stru.lattice))
        self.assertEqual(pfile.spacegroup.short_name,
            ptest.spacegroup.short_name)
        ptest2 = P_cif()
        self.assertRaises(StructureFormatError,
                ptest2.parseLines, badlines)
        return

    def test_parseFile(self):
        """check P_cif.parseFile()
        """
        # goodciffile
        stru = self.pfile.parseFile(self.goodciffile)
        self.assertEqual(8, len(stru))
        self.assertEqual(6.461, stru.lattice.a)
        self.assertEqual(6.461, stru.lattice.b)
        self.assertEqual(6.461, stru.lattice.c)
        self.assertEqual(90.0, stru.lattice.alpha)
        self.assertEqual(90.0, stru.lattice.beta)
        self.assertEqual(90.0, stru.lattice.gamma)
        self.assertEqual('Fm-3m', self.pfile.spacegroup.short_name)
        a0 = stru[0]
        self.assertEqual(0.5, a0.x)
        self.assertEqual(0.5, a0.y)
        self.assertEqual(0.5, a0.z)
        self.assertEqual(False, a0.anisotropy)
        self.assertEqual(1.0, a0.occupancy)
        self.assertEqual(0.0225566, a0.Uisoequiv)
        # badciffile
        pfile2 = P_cif()
        self.assertRaises(StructureFormatError,
                pfile2.parseFile, self.badciffile)
        # graphite
        pgraphite = P_cif()
        graphite = pgraphite.parseFile(self.graphiteciffile)
        self.assertEqual(4, len(graphite))
        c1 = graphite[0]
        self.assertEqual(str, type(c1.element))
        self.assertEqual('C', c1.element)
        self.assertEqual(str, type(c1.label))
        self.assertEqual('C1', c1.label)
        # filename with unicode encoding
        ugraphite = P_cif().parseFile(unicode(self.graphiteciffile))
        self.assertEqual(4, len(ugraphite))
        # File with full space group name
        ptei = P_cif().parseFile(self.teiciffile)
        self.assertEqual(16 , len(ptei))
        return

#   def test__parseCifBlock(self):
#       """check P_cif._parseCifBlock()
#       """
#       return
#
#   def test__parse_lattice(self):
#       """check P_cif._parse_lattice()
#       """
#       return
#
#   def test__parse_atom_site_label(self):
#       """check P_cif._parse_atom_site_label()
#       """
#       return
#
#   def test__parse_atom_site_aniso_label(self):
#       """check P_cif._parse_atom_site_aniso_label()
#       """
#       return
#
#   def test__parse_space_group_symop_operation_xyz(self):
#       """check P_cif._parse_space_group_symop_operation_xyz()
#       """
#       return
#
#   def test__expandAsymmetricUnit(self):
#       """check P_cif._expandAsymmetricUnit()
#       """
#       return
#
#   def test_toLines(self):
#       """check P_cif.toLines()
#       """
#       return
#
#   def test_tostring(self):
#       """check P_cif.tostring()
#       """
#       return

    def test_write_and_read(self):
        """high-level check of P_cif.tostring()
        """
        # high-level check
        stru_check = Structure()
        stru_check.read(self.cdsebulkpdffitfile)
        s_s = stru_check.writeStr('cif')
        stru = Structure()
        stru.readStr(s_s, 'cif')
        self.assertAlmostEqual(4.2352, stru.lattice.a, self.places)
        self.assertAlmostEqual(4.2352, stru.lattice.b, self.places)
        self.assertAlmostEqual(6.90603, stru.lattice.c, self.places)
        self.assertEqual(4, len(stru))
        a0 = stru[0]
        self.assertEqual('Cd', a0.element)
        self.assertListAlmostEqual([0.3334, 0.6667, 0.0], a0.xyz)
        self.failUnless(a0.anisotropy)
        self.assertAlmostEqual(0.01303, a0.U[0,0])
        self.assertAlmostEqual(0.01303, a0.U[1,1])
        self.assertAlmostEqual(0.01402, a0.U[2,2])
        a3 = stru[3]
        self.assertEqual('Se', a3.element)
        self.assertListAlmostEqual([0.6666, 0.333300, 0.87667], a3.xyz)
        self.assertAlmostEqual(0.015673, a3.U[0,0])
        self.assertAlmostEqual(0.015673, a3.U[1,1])
        self.assertAlmostEqual(0.046164, a3.U[2,2])
        return

    def test_eps(self):
        """Test the P_cif.eps coordinates resolution.
        """
        pcif = P_cif()
        pcif.eps = 1e-8
        grph = pcif.parseFile(self.graphiteciffile)
        self.assertEqual(8, len(grph))
        self.assertTrue(all(a.label.startswith('C1') for a in grph[:2]))
        self.assertTrue(all(a.label.startswith('C2') for a in grph[2:]))
        pcif2 = P_cif()
        pcif2.eps = 1e-3
        grph2 = pcif2.parseFile(self.graphiteciffile)
        self.assertEqual(4, len(grph2))
        return

    def test_getParser(self):
        """Test passing of eps keyword argument by getParser function.
        """
        pcif = getParser('cif', eps=1e-6)
        grph = pcif.parseFile(self.graphiteciffile)
        self.assertEqual(8, len(grph))
        self.assertTrue(all(a.label.startswith('C1') for a in grph[:2]))
        self.assertTrue(all(a.label.startswith('C2') for a in grph[2:]))
        pcif2 = getParser('cif')
        grph2 = pcif2.parseFile(self.graphiteciffile)
        self.assertEqual(4, len(grph2))
        return

    ########################################################################
    # helpers
    ########################################################################

    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)
        return