def synthesize_with_isat(crn):
    #derivatives = []
    derivatives = [{"variable": 'PThree', "order": 1, "is_variance": False, "name": "PThree_dot"}]
    flow = crn.flow(False, derivatives)

    # specification = [('', 'PThree_dot >= 0', '((PThree > 0.1) and (PThree_dot < 0.001))'), ('', 'PThree_dot <= 0', '')]
    # specification = [('', '(K > 0.3) and (PThree_dot >= 0)', '(PThree_dot = 0)' ), ('', '(PThree_dot < 0)', '(K < 0.1) and (PThree_dot < 0)')]
    # specification = [('', '', 'PThree > 0.4 '), ('', '', 'PThree < 0.3')]
    #specification = [('','PThree_dot >= 0','PThree_dot = 0'),('','PThree_dot < 0','')]
    # specification = [('','PThree_dot >= 0',' (PThree_dot = 0) and (PThree > 0.4) '),('','PThree_dot <= 0','(PThree < 0.3)')]
    #
    hys = iSATParser.constructISAT(crn, specification, flow, other_constraints='PThree < 0.4;',scale_factor=1)
    with open('sixreactionnetwork.hys', 'w') as file:
        file.write(hys)

    sc = SolverCallerISAT("./sixreactionnetwork.hys", isat_path="../isat-ode-r2806-static-x86_64-generic-noSSE-stripped.txt")

    result_files = sc.single_synthesis(cost=0, precision=0.1, msw=0.5)

    for file_name in result_files:
        print("\n\n")
        # print(sc.getCRNValues(file_name))

        vals, all_vals = sc.getCRNValues(file_name)
        initial_conditions, parametrised_flow = sc.get_full_solution(crn, flow, all_vals)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)

        t, sol, variable_names = sc.simulate_solutions(initial_conditions, parametrised_flow,
                                                       plot_name=file_name + "-simulation.png", t = linspace(0, 10, 1000))
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulation.csv", sol, delimiter=",")
def exampleLotkaOscillator(solver='iSAT'):
    A = Species('A')
    B = Species('B')

    k1 = RateConstant('k_1', 0.01, 2)
    k2 = RateConstant('k_2', 0.01, 2)
    k3 = RateConstant('k_3', 0.01, 2)

    reaction1 = Reaction([Term(A, 1)], [Term(A, 2)], k1)
    reaction2 = Reaction([Term(A, 1), Term(B, 1)], [Term(B, 2)], k2)
    reaction3 = Reaction([Term(B, 1)], [], k3)

    crn = CRNSketch([reaction1, reaction2, reaction3], [], [])

    isLNA = False
    derivatives = [{
        "variable": 'A',
        "order": 1,
        "is_variance": False,
        "name": "A_dot"
    }, {
        "variable": 'B',
        "order": 1,
        "is_variance": False,
        "name": "B_dot"
    }]

    specification = [(0.1, 'A_dot = 0'), (0.2, 'A_dot < 0 or A_dot > 0'),
                     (0.3, 'A_dot = 0')]

    flow = crn.flow(isLNA, derivatives)
    if solver is 'iSAT':
        return iSATParser.constructISAT(crn, specification, flow)
    elif solver is 'dReal':
        return iSATParser.constructdReal(crn, specification, flow)
Exemplo n.º 3
0
def synthesize_with_isat(crn):
    derivatives = []
    flow = crn.flow(False, derivatives)

    specification = [('', '', '(X < 0.1)')]

    hys = iSATParser.constructISAT(crn, specification, flow)
    with open('simple.hys', 'w') as file:
        file.write(hys)

    sc = SolverCallerISAT("./simple.hys", isat_path="../isat-ode-r2806-static-x86_64-generic-noSSE-stripped.txt")

    result_files = sc.single_synthesis(cost=0)

    for file_name in result_files:
        vals, all_vals = sc.getCRNValues(file_name)
        initial_conditions, parametrised_flow = sc.get_full_solution(crn, flow, all_vals)

        print("\n\nInitial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)

        t, sol, variable_names = sc.simulate_solutions(initial_conditions, parametrised_flow,
                                                       plot_name=file_name + "-simulation.png")
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulation.csv", sol, delimiter=",")
def getProblem(crn_sketch_string, crn_code, specification_string):

    if specification_string:
        input_species = get_input_species(specification_string)
        isLNA, requiredDerivatives, specification = construct_specification(
            specification_string)
    else:
        input_species = []
        isLNA = False
        requiredDerivatives = []
        specification = []

    crn = {}
    constraints = []
    if crn_code:
        exec(crn_code)
    else:
        crn_details = CRNbuilder(crn_sketch_string, input_species)
        crn = CRNSketch(crn_details.required_reactions,
                        crn_details.optional_reactions, input_species)
        constraints = crn_details.constraints

    flow = crn.flow(isLNA, requiredDerivatives)
    isat_problem, modes = iSATParser.constructISAT(crn, specification, flow,
                                                   constraints), specification
    dreal_problem, modes = iSATParser.constructdReal(
        crn, specification, flow, constraints), specification

    return isat_problem, dreal_problem, flow, crn
def AMExample():
    X = Species('X')
    Y = Species('Y')
    B = Species('B')

    reaction1 = Reaction([Term(X, 1), Term(Y, 1)],
                         [Term(X, 1), Term(B, 1)],
                         RateConstant('k_1', 0.1, 10))
    reaction2 = Reaction([Term(Y, 1), Term(X, 1)],
                         [Term(Y, 1), Term(B, 1)],
                         RateConstant('k_2', 0.1, 10))
    reaction3 = Reaction([Term(X, 1), Term(B, 1)],
                         [Term(X, 1), Term(X, 1)],
                         RateConstant('k_3', 0.1, 10))
    reaction4 = Reaction([Term(Y, 1), Term(B, 1)],
                         [Term(Y, 1), Term(Y, 1)],
                         RateConstant('k_4', 0.1, 10))

    crn = CRNSketch([reaction1, reaction2, reaction3, reaction4], [], [])
    isLNA = False
    derivatives = []
    specification = []

    flow = crn.flow(isLNA, derivatives)
    return iSATParser.constructISAT(crn, specification, flow, costFunction='')
Exemplo n.º 6
0
def synthesize_with_isat(crn):
    derivatives = [{
        "variable": 'L3p',
        "order": 1,
        "is_variance": False,
        "name": "L3p_dot"
    }, {
        "variable": 'L3p',
        "order": 2,
        "is_variance": False,
        "name": "L3p_dot_dot"
    }]
    flow = crn.flow(False, derivatives)

    #specification = [('', '(L3p_dot >= 0) and (L3p_dot_dot >= 0)', '(L3p_dot_dot < 0.001)'),
    #                 ('', '(L3p_dot >= 0) and (L3p_dot_dot <= 0)', '(L3p > 100)')]
    #ok

    specification = [('', '', '')]

    flow = crn.flow(False, derivatives)
    hys = iSATParser.constructISAT(crn, specification, flow, max_time=100)
    with open('phosphorelay.hys', 'w') as file:
        file.write(hys)

    sc = SolverCallerISAT(
        "./phosphorelay.hys",
        isat_path="../isat-ode-r2806-static-x86_64-generic-noSSE-stripped.txt")

    result_files = sc.single_synthesis(cost=0, precision=0.01, msw=0.05)
    # result_files = ["./results/sixreactionstar_0_0.01-isat.txt"]

    for file_name in result_files:
        print("\n\n")
        # print(sc.getCRNValues(file_name))

        vals, all_vals = sc.getCRNValues(file_name)
        initial_conditions, parametrised_flow = sc.get_full_solution(
            crn, flow, all_vals)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)

        t, sol, variable_names = sc.simulate_solutions(
            initial_conditions,
            parametrised_flow,
            plot_name=file_name + "-simulation.png",
            t=linspace(0, 100, 1000),
            mode_times=all_vals["time"])
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulation.csv", sol, delimiter=",")
def synthesize_with_isat(crn):
    # derivatives = []
    derivatives = [{
        "variable": 'PThreeStar',
        "order": 1,
        "is_variance": False,
        "name": "PThreeStar_dot"
    }]
    flow = crn.flow(False, derivatives)
    specification = [('', '', '')]

    specification = [('', '', '(inputTime > 100) and (PThreeStar < 0.75)'),
                     ('', '', '(PThreeStar > 0.9)')
                     ]  # try to capture an inverted-bellshape response

    hys = iSATParser.constructISAT(crn,
                                   specification,
                                   flow,
                                   max_time=350,
                                   other_constraints='',
                                   scale_factor=1)
    # with open('sixreactionstar.hys', 'w') as file:
    #    file.write(hys)

    sc = SolverCallerISAT(
        "./sixreactionstar.hys",
        isat_path="../isat-ode-r2806-static-x86_64-generic-noSSE-stripped.txt")

    result_files = sc.single_synthesis(cost=0, precision=0.01, msw=0.05)
    # result_files = ["./results/sixreactionstar_0_0.01-isat.txt"]

    for file_name in result_files:
        print("\n\n")
        # print(sc.getCRNValues(file_name))

        vals, all_vals = sc.getCRNValues(file_name)
        initial_conditions, parametrised_flow = sc.get_full_solution(
            crn, flow, all_vals)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)

        t, sol, variable_names = sc.simulate_solutions(
            initial_conditions,
            parametrised_flow,
            plot_name=file_name + "-simulation.png",
            t=linspace(0, 350, 1000),
            hidden_variables="POne,POneStar,PTwo,PTwoStar,PThree")
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulation.csv", sol, delimiter=",")
def michaelis_menten_example():
    X = Species('X')
    Y = Species('Y')

    vmax = RateConstant('V_max', 0.1, 10)
    km = RateConstant('K_m', 0.1, 10)

    reaction = MichaelisMentenReaction([(X, 2)], [(Y, 3)], vmax, km)

    derivatives = []

    crn = CRNSketch([reaction], [], [])
    flow = crn.flow(False, derivatives)
    crn.get_cost()

    return iSATParser.constructISAT(crn, [], flow, costFunction='')
def exampleJointAlternative():

    X = Species('X', initial_max=5)
    Y = Species('Y', initial_value=12)
    B = Species('B')

    reaction1 = Reaction([TermChoice(0, [(X, 2), (Y, 3)])], [(B, 1)],
                         RateConstant('k_1', 1, 2))

    isLNA = False
    derivatives = []
    specification = [(0, 'X = 0'), (0.5, 'X = 0.5'), (1, 'X = 0')]

    crn = CRNSketch([reaction1], [], [])
    flow = crn.flow(isLNA, derivatives)
    return flow, iSATParser.constructISAT(crn,
                                          specification,
                                          flow,
                                          costFunction='')
def exampleCRN():
    A = Species('A')
    B = Species('B')
    x1 = Species('x_1')
    x2 = Species('x_2')

    reaction1 = Reaction([Term(A, 1), Term(x1, 1)],
                         [Term(x1, 1), Term(x1, 1)], RateConstant('k_1', 1, 2))
    reaction2 = Reaction([Term(x1, 1), Term(x2, 1)], [Term(x2, 2)],
                         RateConstant('k_2', 1, 2))
    reaction3 = Reaction([Term(x2, 1)], [Term(B, 1)],
                         RateConstant('k_3', 1, 2))

    crn = CRNSketch([reaction1, reaction2, reaction3], [], [])
    isLNA = False
    derivatives = []
    specification = []

    flow = crn.flow(isLNA, derivatives)
    return iSATParser.constructISAT(crn, specification, flow, costFunction='')
def synthesize_with_isat(crn):
    derivatives = []
    flow = crn.flow(True, derivatives)

    # specification_dreal = [('','cA > A','')]
    specification = [('', '', '')]

    flow = crn.flow(False, derivatives)
    hys = iSATParser.constructISAT(crn, specification, flow, max_time=100)
    with open('superpoisson.hys', 'w') as file:
        file.write(hys)

    sc = SolverCallerISAT(
        "./superpoisson.hys",
        isat_path="../isat-ode-r2806-static-x86_64-generic-noSSE-stripped.txt")

    result_files = sc.single_synthesis(cost=0, precision=0.01, msw=0.05)
    # result_files = ["./results/sixreactionstar_0_0.01-isat.txt"]

    for file_name in result_files:
        print("\n\n")
        # print(sc.getCRNValues(file_name))

        vals, all_vals = sc.getCRNValues(file_name)
        initial_conditions, parametrised_flow = sc.get_full_solution(
            crn, flow, all_vals)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)

        t, sol, variable_names = sc.simulate_solutions(
            initial_conditions,
            parametrised_flow,
            plot_name=file_name + "-simulation.png",
            t=linspace(0, 100, 1000))
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulation.csv", sol, delimiter=",")
def hill_function_example():
    X = Species('X')
    Y = Species('Y')

    vmax = RateConstant('V_max', 0.1, 10)
    km = RateConstant('Km', 0.1, 10)
    n = RateConstant('n', 0.1, 10)

    #reaction = HillReaction([(X, 2)], [(Y,3)], vmax, km, n)
    #reaction = HillReaction([ TermChoice(0, [(X, 2), (Y, 2)])], [(Y,4)], vmax, km, n)

    reaction = HillReaction(
        [TermChoice(0, [(LambdaChoice([X, Y], 1), 2),
                        (Y, 4)])], [(Y, 5)], vmax, km, n)
    reaction = HillReaction([(LambdaChoice([X, Y], 1), 2), (Y, 4)], [(Y, 5)],
                            vmax, km, n)

    derivatives = []

    crn = CRNSketch([reaction], [], [])
    flow = crn.flow(False, derivatives)
    crn.get_cost()

    return iSATParser.constructISAT(crn, [], flow, costFunction='')