def test_rwStr_pdb_CdSe(self): """check conversion to PDB file format""" stru = self.stru stru.read(datafile('CdSe_bulk.stru'), 'pdffit') #print stru.description 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) #print stru.description s_els = [a.symbol 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.description f_title = "Cell structure file of CdSe #186" self.assertEqual(s_title, f_title)
def test_rwStr_pdb_CdSe(self): """check conversion to PDB file format""" stru = self.stru stru.read(datafile('CdSe_bulk.stru'), 'pdffit') #print stru.description 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) #print stru.description s_els = [a.symbol 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.description f_title = "Cell structure file of CdSe #186" self.assertEqual(s_title, f_title)
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.symbol 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)
def readStr(self, s, format='auto'): """Same as Structure.readStr, but update spcgr value in self.pdffit when parser can get spacegroup. Return instance of StructureParser used to load the data. See Structure.readStr() for more info. """ p = Structure.readStr(self, s, format) sg = getattr(p, 'spacegroup', None) if sg: self.pdffit['spcgr'] = sg.short_name return p