reaction.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:crnpy 作者: etonello 项目源码 文件源码
def _fix_ma(self, species = None):
        """Check the numerator of the reaction rate, and adds species
        to reactant and product if they divide the numerator but their
        stoichiometry does not match the degree in the rate."""
        remainder = self.kinetic_param.as_numer_denom()[0].cancel()

        if remainder.func.__name__ == 'Mul':
            mulargs = list(remainder.args) + [i.args[0] for i in remainder.args if i.func.__name__ == 'Mul'] \
                                           + [i.args[0] for i in remainder.args if i.func.__name__ == 'Pow']
            while any(sp.Symbol(s) in mulargs for s in species):
                for s in species:
                    if sp.Symbol(s) in mulargs:
                        if s in self.reactant: self.reactant[s] = self.reactant[s] + 1
                        else: self.reactant[s] = 1
                        if s in self.product: self.product[s] = self.product[s] + 1
                        else: self.product[s] = 1
                        remainder = (remainder / sp.Symbol(s)).factor()
                        if remainder.func.__name__ == 'Mul':
                            mulargs = list(remainder.args) + [i.args[0] for i in remainder.args if i.func.__name__ == 'Mul'] \
                                                           + [i.args[0] for i in remainder.args if i.func.__name__ == 'Pow']
                        else: mulargs = []
            # update the kinetic parameter
            self.__kinetic_param = (self.rate / self.reactant.ma()).cancel()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号