def load_database(self):
        self.logger.info("Test loading Database")

        user_defined_export_rxns_Sji = {
            'EX_glc': {
                'C00031': -1.0
            },
            'EX_nad': {
                'C00003': -1.0
            },
            'EX_adp': {
                'C00008': -1.0
            },
            'EX_phosphate': {
                'C00009': -1.0
            },
            'EX_pyruvate': {
                'C00022': -1.0
            },
            'EX_nadh': {
                'C00004': -1.0
            },
            'EX_atp': {
                'C00002': -1.0
            },
            'EX_h2o': {
                'C00001': -1.0
            },
            'EX_hplus': {
                'C00080': -1.0
            },
            'EX_nadp': {
                'C00006': -1.0
            },
            'EX_nadph': {
                'C00005': -1.0
            }
        }

        DB = load_db_v3(
            reduce_model_size=True,
            user_defined_export_rxns_Sji=user_defined_export_rxns_Sji)
        DB.validate()
        # assert_equal(len(DB.metabolites), 5969)
        # assert_equal(len(DB.reactions), 7175)
        return DB
    def __init__(self,
                 objective='MinFlux',
                 zlb=10,
                 nATP=1,
                 add_loopless_constraints=True,
                 max_iteration=1,
                 pulp_solver=None,
                 result_filepath=None,
                 M=1000,
                 logger=None):
        """An example of the optStoic model for identifying glycolytic pathways
            generating n ATP.

        Args:
            objective (str, optional): Description
            zlb (int, optional): Description
            nATP (int, optional): nATP (int, optional): The number of ATP
            add_loopless_constraints (bool, optional): Description
            max_iteration (int, optional): Description
            pulp_solver (None, optional): Description
            result_filepath (None, optional): Description
            M (int, optional): Description
            logger (None, optional): Description
        """

        self.DBV3 = database.load_db_v3(
            reduce_model_size=True,
            user_defined_export_rxns_Sji=self.EXPORT_RXNS_SJI
        )

        super(OptStoicGlycolysis, self).__init__(
            database=self.DBV3,
            objective='MinFlux',
            zlb=zlb,
            specific_bounds=self.GLYCOLYSIS_BOUNDS,
            custom_flux_constraints=self.CUSTOM_REDOX_CONSTRAINTS,
            add_loopless_constraints=add_loopless_constraints,
            max_iteration=max_iteration,
            pulp_solver=pulp_solver,
            result_filepath=result_filepath,
            M=1000,
            logger=logger)

        self.nATP = nATP
Exemplo n.º 3
0
def test_optstoic():
    """An alternative to the nosetest due to issue with PULP/SCIP_CMD
    """
    logger = create_logger(name='optstoicpy.script.optstoic.main')

    logger.info("Test generalized optstoic")

    # Set the following reactions as allowable export reactions
    db3 = load_db_v3(reduce_model_size=True,
                     user_defined_export_rxns_Sji={
                         'EX_glc': {
                             'C00031': -1.0
                         },
                         'EX_nad': {
                             'C00003': -1.0
                         },
                         'EX_adp': {
                             'C00008': -1.0
                         },
                         'EX_phosphate': {
                             'C00009': -1.0
                         },
                         'EX_pyruvate': {
                             'C00022': -1.0
                         },
                         'EX_nadh': {
                             'C00004': -1.0
                         },
                         'EX_atp': {
                             'C00002': -1.0
                         },
                         'EX_h2o': {
                             'C00001': -1.0
                         },
                         'EX_hplus': {
                             'C00080': -1.0
                         },
                         'EX_nadp': {
                             'C00006': -1.0
                         },
                         'EX_nadph': {
                             'C00005': -1.0
                         }
                     })

    #logger.debug('Testing optstoic output filepath: %s', res_dir)

    pulp_solver = load_pulp_solver(solver_names=[
        'SCIP_CMD', 'GUROBI', 'GUROBI_CMD', 'CPLEX_CMD', 'GLPK_CMD'
    ],
                                   logger=logger)

    # How to add custom flux constraints:
    # E.g.,
    # v('EX_nadph') + v('EX_nadh') = 2;
    # v('EX_nadp') + v('EX_nad') = -2;
    # v('EX_nadh') + v('EX_nad') = 0;
    # v('EX_nadph') + v('EX_nadp') = 0;
    # became
    # lp_prob += v['EX_nadph'] + v['EX_nadh'] == 2, 'nadphcons1'
    # lp_prob += v['EX_nadp'] + v['EX_nad'] == -2, 'nadphcons2'
    # lp_prob += v['EX_nadh'] + v['EX_nad'] == 0, 'nadphcons3'
    # lp_prob += v['EX_nadph'] + v['EX_nadp'] == 0, 'nadphcons4'

    custom_flux_constraints = [{
        'constraint_name': 'nadphcons1',
        'reactions': ['EX_nadph', 'EX_nadh'],
        'UB': 2,
        'LB': 2
    }, {
        'constraint_name': 'nadphcons2',
        'reactions': ['EX_nadp', 'EX_nad'],
        'UB': -2,
        'LB': -2
    }, {
        'constraint_name': 'nadphcons3',
        'reactions': ['EX_nadh', 'EX_nad'],
        'UB': 0,
        'LB': 0
    }, {
        'constraint_name': 'nadphcons4',
        'reactions': ['EX_nadph', 'EX_nadp'],
        'UB': 0,
        'LB': 0
    }]

    specific_bounds = {
        'EX_glc': {
            'LB': -1,
            'UB': -1
        },
        'EX_pyruvate': {
            'LB': 2,
            'UB': 2
        },
        'EX_nad': {
            'LB': -2,
            'UB': 0
        },
        'EX_nadh': {
            'LB': 0,
            'UB': 2
        },
        'EX_nadp': {
            'LB': -2,
            'UB': 0
        },
        'EX_nadph': {
            'LB': 0,
            'UB': 2
        },
        'EX_adp': {
            'LB': -1,
            'UB': -1
        },
        'EX_phosphate': {
            'LB': -1,
            'UB': -1
        },
        'EX_atp': {
            'LB': 1,
            'UB': 1
        },
        'EX_h2o': {
            'LB': 1,
            'UB': 1
        },
        'EX_hplus': {
            'LB': -10,
            'UB': 10
        }
    }  # pulp/gurobi has issue with "h+"

    test = OptStoic(database=db3,
                    objective='MinFlux',
                    zlb=None,
                    specific_bounds=specific_bounds,
                    custom_flux_constraints=custom_flux_constraints,
                    add_loopless_constraints=True,
                    max_iteration=2,
                    pulp_solver=pulp_solver,
                    result_filepath='./result/',
                    M=1000,
                    logger=logger)

    if sys.platform == 'cygwin':
        lp_prob, pathways = test.solve_gurobi_cl(
            outputfile='test_optstoic_cyg.txt', cleanup=False)
        #test.max_iteration = test.max_iteration + 2
        #lp_prob, pathways = test.solve_gurobi_cl(outputfile='test_optstoic_cyg.txt', exclude_existing_solution=True, cleanup=False)
    else:
        lp_prob, pathways = test.solve(outputfile='test_optstoic.txt')
        #test.max_iteration = test.max_iteration + 1
        #lp_prob, pathways = test.solve(outputfile='test_optstoic.txt', exclude_existing_solution=True)

    return lp_prob, pathways