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


Python formula.Formula类代码示例

本文整理汇总了Python中psamm.formula.Formula的典型用法代码示例。如果您正苦于以下问题:Python Formula类的具体用法?Python Formula怎么用?Python Formula使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_predict_with_multiple_solutions

    def test_predict_with_multiple_solutions(self):
        """Test prediction where multiple solutions exist (TALA)."""
        reaction = parse_reaction(
            'r5p[c] + xu5p-D[c] <=> g3p[c] + s7p[c]')
        formulas = {
            'r5p': Formula.parse('C5H9O8P'),
            'xu5p-D': Formula.parse('C5H9O8P'),
            'g3p': Formula.parse('C3H5O6P'),
            's7p': Formula.parse('C7H13O10P'),
        }

        solutions = list(
            mapmaker.predict_compound_pairs(reaction, formulas, self.solver))
        self.assertEqual(len(solutions), 2)

        # Solution A
        self.assertIn({
            (Compound('r5p', 'c'), Compound('s7p', 'c')):
                Formula.parse('C5O8P'),
            (Compound('xu5p-D', 'c'), Compound('g3p', 'c')):
                Formula.parse('C3O6P'),
            (Compound('xu5p-D', 'c'), Compound('s7p', 'c')):
                Formula.parse('C2O2'),
        }, solutions)

        # Solution B
        self.assertIn({
            (Compound('xu5p-D', 'c'), Compound('s7p', 'c')):
                Formula.parse('C5O8P'),
            (Compound('r5p', 'c'), Compound('g3p', 'c')):
                Formula.parse('C3O6P'),
            (Compound('r5p', 'c'), Compound('s7p', 'c')):
                Formula.parse('C2O2'),
        }, solutions)
开发者ID:keitht547,项目名称:psamm,代码行数:34,代码来源:test_mapmaker.py

示例2: test_formula_items

 def test_formula_items(self):
     f = Formula({Atom('H'): 12, Atom('C'): 6, Atom('O'): 6})
     self.assertEqual(dict(f.items()), {
         Atom('C'): 6,
         Atom('H'): 12,
         Atom('O'): 6
     })
开发者ID:ForkBackups,项目名称:psamm,代码行数:7,代码来源:test_formula.py

示例3: test_formula_items

 def test_formula_items(self):
     f = Formula({Atom.H: 12, Atom.C: 6, Atom.O: 6})
     self.assertEqual(dict(f.items()), {
         Atom.C: 6,
         Atom.H: 12,
         Atom.O: 6
     })
开发者ID:spikeliu,项目名称:psamm,代码行数:7,代码来源:test_formula.py

示例4: test_reaction_formula_none_return

 def test_reaction_formula_none_return(self):
     reaction = parse_reaction('A[e] + (6) B[c] <=> (6) C[e] + (6) D[c]')
     compound_formula = {
         'A': Formula.parse('C6H12O6'),
         'B': Formula.parse('O2'),
         'C': Formula.parse('CO2'),
     }
     result = balancecheck.reaction_formula(reaction, compound_formula)
     self.assertIsNone(result)
开发者ID:keitht547,项目名称:psamm,代码行数:9,代码来源:test_balancecheck.py

示例5: test_predict_compound_pairs

    def test_predict_compound_pairs(self):
        """Test prediction of HEX1 reaction."""
        reaction = parse_reaction(
            'atp[c] + glc-D[c] => adp[c] + g6p[c] + h[c]')
        formulas = {
            'atp': Formula.parse('C10H12N5O13P3'),
            'adp': Formula.parse('C10H12N5O10P2'),
            'glc-D': Formula.parse('C6H12O6'),
            'g6p': Formula.parse('C6H11O9P'),
            'h': Formula.parse('H'),
        }
        transfer, balance = findprimarypairs.predict_compound_pairs(
            reaction, formulas)

        self.assertEqual(balance, {})
        self.assertEqual(transfer, {
            ((Compound('atp', 'c'), 1), (Compound('adp', 'c'), 1)):
                Formula.parse('C10H12N5O10P2'),
            ((Compound('glc-D', 'c'), 1), (Compound('g6p', 'c'), 1)):
                Formula.parse('C6H11O6'),
            ((Compound('atp', 'c'), 1), (Compound('g6p', 'c'), 1)):
                Formula.parse('O3P'),
            ((Compound('glc-D', 'c'), 1), (Compound('h', 'c'), 1)):
                Formula.parse('H'),
        })
开发者ID:keitht547,项目名称:psamm,代码行数:25,代码来源:test_findprimarypairs.py

示例6: test_predict_compound_pairs_unbalanced

    def test_predict_compound_pairs_unbalanced(self):
        """Test prediction of (non-sense) unbalanced reaction."""
        reaction = parse_reaction(
            'a[c] <=> b[c] + c[c]')
        formulas = {
            'a': Formula.parse('C10H12'),
            'b': Formula.parse('C9H11'),
            'c': Formula.parse('CO2'),
        }

        with self.assertRaises(mapmaker.UnbalancedReactionError):
            list(mapmaker.predict_compound_pairs(
                reaction, formulas, self.solver))
开发者ID:keitht547,项目名称:psamm,代码行数:13,代码来源:test_mapmaker.py

示例7: test_formula_flattened

 def test_formula_flattened(self):
     f = Formula({
         Atom('C'): 1,
         Atom('H'): 3,
         Formula({Atom('C'): 1, Atom('H'): 2}): 14,
         Formula({
             Atom('C'): 1, Atom('O'): 1,
             Formula({Atom('H'): 1, Atom('O'): 1}): 1
         }): 1
     })
     self.assertEqual(f.flattened(), Formula({
         Atom('C'): 16,
         Atom('H'): 32,
         Atom('O'): 2
     }))
开发者ID:ForkBackups,项目名称:psamm,代码行数:15,代码来源:test_formula.py

示例8: test_formula_flattened

 def test_formula_flattened(self):
     f = Formula({
         Atom.C: 1,
         Atom.H: 3,
         Formula({Atom.C: 1, Atom.H: 2}): 14,
         Formula({
             Atom.C: 1, Atom.O: 1,
             Formula({Atom.H: 1, Atom.O: 1}): 1
         }): 1
     })
     self.assertEqual(f.flattened(), Formula({
         Atom.C: 16,
         Atom.H: 32,
         Atom.O: 2
     }))
开发者ID:spikeliu,项目名称:psamm,代码行数:15,代码来源:test_formula.py

示例9: test_predict_compound_pairs_multiple

    def test_predict_compound_pairs_multiple(self):
        """Test prediction of reaction with multiple instances."""
        reaction = parse_reaction(
            'a[c] <=> (2) b[c] + c[c]')
        formulas = {
            'a': Formula.parse('C10H13O6'),
            'b': Formula.parse('C5H6O3'),
            'c': Formula.parse('H'),
        }
        solutions = list(
            mapmaker.predict_compound_pairs(reaction, formulas, self.solver))

        self.assertEqual(len(solutions), 1)
        self.assertEqual(solutions[0], {
            (Compound('a', 'c'), Compound('b', 'c')): Formula.parse('C10O6'),
        })
开发者ID:keitht547,项目名称:psamm,代码行数:16,代码来源:test_mapmaker.py

示例10: test_write_compounds

    def test_write_compounds(self):
        stream = StringIO()
        compounds = [
            entry.DictCompoundEntry({
                'id': 'c1',
                'name': 'Compound 1',
                'charge': 2,
                'custom': 34.5
            }),
            entry.DictCompoundEntry({
                'id': 'c2',
                'name': 'Compound 2',
                'formula': Formula.parse('H2O')
            })
        ]
        self.writer.write_compounds(stream, compounds)

        self.assertEqual(yaml.safe_load(stream.getvalue()), [
            {
                'id': 'c1',
                'name': 'Compound 1',
                'charge': 2,
                'custom': 34.5
            },
            {
                'id': 'c2',
                'name': 'Compound 2',
                'formula': 'H2O'
            }
        ])
开发者ID:keitht547,项目名称:psamm,代码行数:30,代码来源:test_datasource_native.py

示例11: test_formula_substitute_non_positive

    def test_formula_substitute_non_positive(self):
        f = Formula.parse('CH3(CH2)nCOOH')

        with self.assertRaises(ValueError):
            f.substitute(lambda v: {'n': -5}.get(v.symbol, v))

        with self.assertRaises(ValueError):
            f.substitute(lambda v: {'n': 0}.get(v.symbol, v))
开发者ID:ForkBackups,项目名称:psamm,代码行数:8,代码来源:test_formula.py

示例12: test_weighted_formula

 def test_weighted_formula(self):
     weighted = mapmaker._weighted_formula(
         Formula.parse('C1H2N3S4R'), mapmaker.default_weight)
     self.assertEqual(set(weighted), {
         (Atom.C, 1, 1),
         # H is discarded
         (Atom.N, 3, 0.4),
         (Atom.S, 4, 1),
         (Radical('R'), 1, 40.0)
     })
开发者ID:keitht547,项目名称:psamm,代码行数:10,代码来源:test_mapmaker.py

示例13: test_formula_balance

    def test_formula_balance(self):
        d = {reaction.id: value for reaction, value in
             balancecheck.formula_balance(self._model)}
        self.assertEqual(d['rxn_1'][0], Formula.parse('C6H12O6'))
        self.assertEqual(d['rxn_1'][1], Formula.parse('O2'))

        self.assertEqual(d['rxn_2'][0], Formula.parse('O2'))
        self.assertEqual(d['rxn_2'][1], Formula.parse('CO2'))

        self.assertEqual(d['rxn_3'][0], Formula.parse('C6H12O18'))
        self.assertEqual(d['rxn_3'][1], Formula.parse('C6H12O18'))
开发者ID:keitht547,项目名称:psamm,代码行数:11,代码来源:test_balancecheck.py

示例14: setUp

    def setUp(self):
        self.dest = tempfile.mkdtemp()

        self.model = NativeModel({
            'id': 'test_mode',
            'name': 'Test model',
        })

        # Compounds
        self.model.compounds.add_entry(CompoundEntry({
            'id': 'cpd_1',
            'formula': Formula.parse('CO2')
        }))
        self.model.compounds.add_entry(CompoundEntry({
            'id': 'cpd_2',
        }))
        self.model.compounds.add_entry(CompoundEntry({
            'id': 'cpd_3',
        }))

        # Compartments
        self.model.compartments.add_entry(CompartmentEntry({
            'id': 'c'
        }))
        self.model.compartments.add_entry(CompartmentEntry({
            'id': 'e'
        }))

        # Reactions
        self.model.reactions.add_entry(ReactionEntry({
            'id': 'rxn_1',
            'equation': parse_reaction('(2) cpd_1[c] <=> cpd_2[e] + cpd_3[c]'),
            'genes': boolean.Expression('g_1 and (g_2 or g_3)'),
            'subsystem': 'Some subsystem'
        }))
        self.model.reactions.add_entry(ReactionEntry({
            'id': 'rxn_2',
            'equation': parse_reaction(
                '(0.234) cpd_1[c] + (1.34) cpd_2[c] => cpd_3[c]'),
            'subsystem': 'Biomass'
        }))

        self.model.biomass_reaction = 'rxn_2'
        self.model.limits['rxn_1'] = 'rxn_1', Decimal(-42), Decimal(1000)
        self.model.exchange[Compound('cpd_2', 'e')] = (
            Compound('cpd_2', 'e'), 'EX_cpd_2', -10, 0)
开发者ID:keitht547,项目名称:psamm,代码行数:46,代码来源:test_importer.py

示例15: test_reaction_formula_normal_return

 def test_reaction_formula_normal_return(self):
     reaction = parse_reaction('A[e] + (6) B[c] <=> (6) C[e] + (6) D[c]')
     compound_formula = {
         'A': Formula.parse('C6H12O6'),
         'B': Formula.parse('O2'),
         'C': Formula.parse('CO2'),
         'D': Formula.parse('H2O')
     }
     left_form, right_form = balancecheck.reaction_formula(
         reaction, compound_formula)
     self.assertEqual(left_form, Formula.parse('C6H12O18'))
     self.assertEqual(right_form, Formula.parse('C6H12O18'))
开发者ID:keitht547,项目名称:psamm,代码行数:12,代码来源:test_balancecheck.py


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