当前位置: 首页>>代码示例>>Python>>正文


Python Structure.writeStr方法代码示例

本文整理汇总了Python中diffpy.Structure.Structure.writeStr方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.writeStr方法的具体用法?Python Structure.writeStr怎么用?Python Structure.writeStr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在diffpy.Structure.Structure的用法示例。


在下文中一共展示了Structure.writeStr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_write_and_read

# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import writeStr [as 别名]
 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.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
开发者ID:cfarrow,项目名称:diffpy.Structure,代码行数:28,代码来源:TestP_cif.py

示例2: test___copy__

# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import writeStr [as 别名]
 def test___copy__(self):
     """check Structure.__copy__()
     """
     cdse = Structure(filename=cdsefile)
     cdse_str = cdse.writeStr('pdffit')
     cdse2 = copy.copy(cdse)
     self.assertEqual(cdse_str, cdse2.writeStr('pdffit'))
     self.failIf(cdse.lattice is cdse2.lattice)
     sameatoms = set(cdse).intersection(cdse2)
     self.failIf(sameatoms)
     return
开发者ID:benfrandsen,项目名称:diffpy.Structure,代码行数:13,代码来源:TestStructure.py

示例3: outputFormats

# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import writeStr [as 别名]
            print >> sys.stderr, "'%s' is not valid input format" % infmt
            sys.exit(2)
        if outfmt not in outputFormats():
            print >> sys.stderr, "'%s' is not valid output format" % outfmt
            sys.exit(2)
    except ValueError:
        print >> sys.stderr, \
            "invalid format specification '%s' does not contain .." % args[0]
        sys.exit(2)
    # ready to do some real work
    try:
        strufile = args[1]
        stru = Structure()
        if args[1] == "-":
            stru.readStr(sys.stdin.read(), infmt)
        else:
            stru.read(strufile, infmt)
        sys.stdout.write( stru.writeStr(outfmt) )
    except IndexError:
        print >> sys.stderr, "strufile not specified"
        sys.exit(2)
    except IOError, (errno, errmsg):
        print >> sys.stderr, "%s: %s" % (strufile, errmsg)
        sys.exit(1)
    except StructureFormatError, errmsg:
        print >> sys.stderr, "%s: %s" % (strufile, errmsg)
        sys.exit(1)

if __name__ == "__main__":
    main()
开发者ID:benfrandsen,项目名称:diffpy.Structure,代码行数:32,代码来源:transtru.py

示例4: TestP_pdffit

# 需要导入模块: from diffpy.Structure import Structure [as 别名]
# 或者: from diffpy.Structure.Structure import writeStr [as 别名]

#.........这里部分代码省略.........
        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_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


    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


    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


    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')
开发者ID:cfarrow,项目名称:diffpy.Structure,代码行数:70,代码来源:TestP_pdffit.py


注:本文中的diffpy.Structure.Structure.writeStr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。