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


Python Formula.parse方法代码示例

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


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

示例1: test_predict_with_multiple_solutions

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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,代码行数:36,代码来源:test_mapmaker.py

示例2: test_reaction_formula_none_return

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
 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,代码行数:11,代码来源:test_balancecheck.py

示例3: test_predict_compound_pairs

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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,代码行数:27,代码来源:test_findprimarypairs.py

示例4: test_predict_compound_pairs_unbalanced

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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,代码行数:15,代码来源:test_mapmaker.py

示例5: test_predict_compound_pairs_multiple

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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,代码行数:18,代码来源:test_mapmaker.py

示例6: test_write_compounds

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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,代码行数:32,代码来源:test_datasource_native.py

示例7: test_formula_substitute_non_positive

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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,代码行数:10,代码来源:test_formula.py

示例8: test_weighted_formula

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
 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,代码行数:12,代码来源:test_mapmaker.py

示例9: test_formula_balance

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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,代码行数:13,代码来源:test_balancecheck.py

示例10: setUp

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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,代码行数:48,代码来源:test_importer.py

示例11: test_reaction_formula_normal_return

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
 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,代码行数:14,代码来源:test_balancecheck.py

示例12: test_predict_compound_pairs

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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')
        }

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

        self.assertEqual(len(solutions), 1)
        self.assertEqual(solutions[0], {
            (Compound('atp', 'c'), Compound('adp', 'c')):
                Formula.parse('C10N5O10P2'),
            (Compound('glc-D', 'c'), Compound('g6p', 'c')):
                Formula.parse('C6O6'),
            (Compound('atp', 'c'), Compound('g6p', 'c')):
                Formula.parse('O3P'),
        })
开发者ID:keitht547,项目名称:psamm,代码行数:26,代码来源:test_mapmaker.py

示例13: test_predict_compound_pairs_unbalanced

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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'),
        }
        transfer, balance = findprimarypairs.predict_compound_pairs(
            reaction, formulas)

        self.assertEqual(balance, {
            (Compound('a', 'c'), 1): Formula.parse('H'),
            (Compound('c', 'c'), 1): Formula.parse('O2'),
        })
        self.assertEqual(transfer, {
            ((Compound('a', 'c'), 1), (Compound('b', 'c'), 1)):
                Formula.parse('C9H11'),
            ((Compound('a', 'c'), 1), (Compound('c', 'c'), 1)):
                Formula.parse('C'),
        })
开发者ID:keitht547,项目名称:psamm,代码行数:24,代码来源:test_findprimarypairs.py

示例14: test_predict_compound_pairs_multiple

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
    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'),
        }
        transfer, balance = findprimarypairs.predict_compound_pairs(
            reaction, formulas)

        self.assertEqual(balance, {})
        self.assertEqual(transfer, {
            ((Compound('a', 'c'), 1), (Compound('b', 'c'), 1)):
                Formula.parse('C5H6O3'),
            ((Compound('a', 'c'), 1), (Compound('b', 'c'), 2)):
                Formula.parse('C5H6O3'),
            ((Compound('a', 'c'), 1), (Compound('c', 'c'), 1)):
                Formula.parse('H'),
        })
开发者ID:keitht547,项目名称:psamm,代码行数:23,代码来源:test_findprimarypairs.py

示例15: test_formula_parse_with_radical

# 需要导入模块: from psamm.formula import Formula [as 别名]
# 或者: from psamm.formula.Formula import parse [as 别名]
 def test_formula_parse_with_radical(self):
     f = Formula.parse('C2H4NO2R')
     self.assertEqual(f, Formula({
         Atom.C: 2, Atom.H: 4, Atom.N: 1, Atom.O: 2, Radical('R'): 1}))
开发者ID:spikeliu,项目名称:psamm,代码行数:6,代码来源:test_formula.py


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