reaction.py 文件源码

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

项目:crnpy 作者: etonello 项目源码 文件源码
def _fix_denom(self, species):
        """Remove species that are involved in both reactant and product,
        if their concentration divides the denominator of the rate."""
        remainder = self.kinetic_param.as_numer_denom()[1].cancel()

        #if remainder.func.__name__ == 'Mul':
        if remainder != 1:
            mulargs = [remainder] + 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 and s in self.reactant and s in self.product for s in species):
                for s in species:
                    if sp.Symbol(s) in mulargs and s in self.reactant and s in self.product:
                        if self.reactant[s] == 1: del self.reactant[s]
                        else: self.reactant[s] = self.reactant[s] - 1
                        if self.product[s] == 1: del self.product[s]
                        else: self.product[s] = 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:
                            if str(remainder) in species: mulargs = [remainder]
                            else: mulargs = []
        # update the kinetic parameter
        self._kinetic_param = self.rate / self.reactant.ma()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号