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


Python Options.toelement方法代码示例

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


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

示例1: TestOptions

# 需要导入模块: from pymontecarlo.options.options import Options [as 别名]
# 或者: from pymontecarlo.options.options.Options import toelement [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(1, len(models))
        self.assertEqual(ELASTIC_CROSS_SECTION.rutherford, models[0])

    def testcopy(self):
        uuid = self.ops.uuid
        ops = copy.copy(self.ops)

        self.assertEqual(1, len(ops.programs))

        self.assertAlmostEqual(1234, self.ops.beam.energy_eV, 4)
        self.assertAlmostEqual(1234, ops.beam.energy_eV, 4)
        self.assertEqual(self.ops.beam, ops.beam)

        self.assertNotEqual(uuid, ops.uuid)
        self.assertEqual(uuid, self.ops.uuid)

        ops.beam.energy_eV = 5678
        self.assertAlmostEqual(5678, self.ops.beam.energy_eV, 4)
        self.assertAlmostEqual(5678, ops.beam.energy_eV, 4)

    def testdeepcopy(self):
        uuid = self.ops.uuid
        ops = copy.deepcopy(self.ops)

        self.assertEqual(1, len(ops.programs))

        self.assertAlmostEqual(1234, self.ops.beam.energy_eV, 4)
        self.assertAlmostEqual(1234, ops.beam.energy_eV, 4)
        self.assertNotEqual(self.ops.beam, ops.beam)

        self.assertNotEqual(uuid, ops.uuid)
        self.assertEqual(uuid, self.ops.uuid)

        ops.beam.energy_eV = 5678
        self.assertAlmostEqual(1234, self.ops.beam.energy_eV, 4)
        self.assertAlmostEqual(5678, ops.beam.energy_eV, 4)

        self.assertIsNot(list(self.ops.limits)[0], list(ops.limits)[0])

    def testuuid(self):
        uuid = self.ops.uuid
        self.assertEqual(uuid, self.ops.uuid)

    def testdetectors(self):
        dets = list(self.ops.detectors.iterclass(BackscatteredElectronEnergyDetector))
        self.assertEqual(1, len(dets))
        self.assertEqual('bse', dets[0][0])

        dets = list(self.ops.detectors.iterclass(ShowersLimit))
        self.assertEqual(0, len(dets))

    def testdetectors_multiple(self):
        self.ops.detectors['bse'] = \
            [BackscatteredElectronEnergyDetector(1000, (0, 1234)),
             BackscatteredElectronEnergyDetector(2000, (1234, 5678))]

        dets = list(self.ops.detectors.iterclass(BackscatteredElectronEnergyDetector))
        self.assertEqual(2, len(dets))
        self.assertEqual('bse', dets[0][0])
        self.assertEqual('bse', dets[1][0])

    def testlimits(self):
        self.ops.limits.add(ShowersLimit(1234))
        self.assertEqual(1, len(self.ops.limits))

        limits = list(self.ops.limits.iterclass(ShowersLimit))
        self.assertEqual(1, len(limits))

    def testmodels(self):
        self.ops.models.add(ELASTIC_CROSS_SECTION.mott_drouin1993)
        self.assertEqual(2, len(self.ops.models))
        models = list(self.ops.models.iterclass(ELASTIC_CROSS_SECTION))
        self.assertEqual(2, len(models))
        
        self.ops.models.add(ELASTIC_CROSS_SECTION.mott_drouin1993)
        self.assertEqual(2, len(self.ops.models))

    def testto_from_element(self):
        element = self.ops.toelement()
        obj = Options.fromelement(element)

        self.assertEqual(1, len(obj.programs))

        self.assertAlmostEqual(1234, obj.beam.energy_eV, 4)

        self.assertEqual(1, len(obj.detectors))
        det = obj.detectors['bse']
        self.assertAlmostEqual(0, det.limits_eV[0], 4)
        self.assertAlmostEqual(1234, det.limits_eV[1], 4)
        self.assertEqual(1000, det.channels)

        self.assertEqual(1, len(obj.limits))
        limits = list(obj.limits.iterclass(ShowersLimit))
        self.assertEqual(1, len(limits))
        self.assertEqual(5678, limits[0].showers)

        self.assertEqual(1, len(obj.models))
        models = list(obj.models.iterclass(ELASTIC_CROSS_SECTION))
        self.assertEqual(1, len(models))
        self.assertEqual(ELASTIC_CROSS_SECTION.rutherford, models[0])
开发者ID:pymontecarlo,项目名称:pymontecarlo,代码行数:104,代码来源:test_options.py


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