Exemplo n.º 1
0
 def __init__(self, *args):
     self.args = dict(args)
     self.simulation = oc.openSimulation(self.args.get('Sim_file'))
     self.simulation.data().setStartingPoint(self.args.get('start_time'))
     self.simulation.data().setEndingPoint(self.args.get('end_time'))
     self.simulation.data().setPointInterval(self.args.get('time_step'))
     self.simulation.resetParameters()
     self.constants = self.simulation.data().constants()
     self.variables = self.simulation.data().states()
     self.all_variable_names = sorted(list(self.variables.keys()))
     self.fitted_variable_names = sorted(list(self.variables.keys()))
     self.fitted_parameter_names = sorted(list(self.constants.keys()))
     self.all_parameter_names = sorted(list(self.constants.keys()))
Exemplo n.º 2
0
def main(stimulation_mode_parameter, stimulation_level_parameter):
    return_code = 0

    s = OpenCOR.openSimulation(
        '/home/opencor/models/HumanSAN_Fabbri_Fantini_Wilders_Severi_2017.sedml'
    )
    d = s.data()
    c = d.constants()
    stimulation_level_parameter = max(0.0, min(1.0,
                                               stimulation_level_parameter))

    c['Rate_modulation_experiments/Iso_1_uM'] = 1.0  # dimensionless
    if stimulation_mode_parameter == 1:
        # Stellate stimulation 0 - 1 :: 22 - 0
        c['Rate_modulation_experiments/ACh'] = (
            1.0 - stimulation_level_parameter) * 22.0e-6
    elif stimulation_mode_parameter == 2:
        # Vagus stimulation 0 - 1 :: 22 - 38
        c['Rate_modulation_experiments/ACh'] = 22.0e-6 + stimulation_level_parameter * (
            38.0e-6 - 22.0e-6)
    else:
        return_code = 4

    # Run the simulation
    try:
        if return_code == 0 and s.run():
            r = s.results()
            output_data = {
                'membrane': {
                    'v': r.algebraic()['Membrane/V'].values().tolist()
                }
            }
            peaks = find_peaks(output_data['membrane']['v'])[0]
            output_data['heart_rate'] = len(peaks)
            json_format = json.dumps(output_data)
            print(json_format)
        else:
            return_code = 5
    except RuntimeError:
        return_code = 6

    return return_code
Exemplo n.º 3
0
def simulate_cellml(filename, start_time, end_time, time_interval):
    # Load and initialise the simulation
    simulation = oc.openSimulation(filename)
    # In case we have reloaded an open simulation
    simulation.resetParameters()
    simulation.clearResults()

    # Reference some simulation objects
    initial_data = simulation.data()
    constants = initial_data.constants()
    results = simulation.results()
    # Simulation time points must match experiment data points
    initial_data.setStartingPoint(start_time)
    initial_data.setEndingPoint(end_time)
    initial_data.setPointInterval(time_interval)

    try:
        simulation.run()
    except RuntimeError:
        print("Runtime error:")
        print(simulation_cellml + " did not run sucessfully")
        raise
    return simulation.results()
Exemplo n.º 4
0
def main(stimulus_period):
    s = OpenCOR.openSimulation('/home/opencor/models/action-potential.xml')

    d = s.data()

    # Set integration range
    d.setPointInterval(10)  # ms
    d.setEndingPoint(100000)  # ms

    # print('Setting stimulus period to:', stimulus_period)
    c = d.constants()
    c['membrane/period'] = stimulus_period  # ms

    # Run the simulation
    s.run()

    r = s.results()

    json_format = json.dumps(
        {'membrane': {
            'v': r.states()['membrane/v'].values().tolist()
        }})
    print(json_format)
Exemplo n.º 5
0
mapfilepath = Path(mapfile)
with mapfilepath.open("r") as fp:
    inputkeymap = json.load(fp)
inputdata = {
    newkey: inputdata_unmapped[oldkey]
    for (oldkey, newkey) in inputkeymap.items()
}
print(inputdata)

starttime = float(inputdata["starttime"])
endtime = float(inputdata["endtime"])
timeincr = float(inputdata["timeincr"])

# some basic verification
if modelpath.endswith('cellml') or modelpath.endswith('sedml'):
    model = OpenCOR.openSimulation(modelpath)
else:
    sys.exit('Invalid file type: only .cellml and .sedml accepted')

if endtime < starttime:
    print(
        'ending time must be greater than starting time, using 1000s after start instead'
    )
    endtime = starttime + 1000
if timeincr <= 0:
    print('time increment should be greater than 0s. Setting to 1s')
    timeincr = 1
else:
    print('inputs are valid.')

try:
Exemplo n.º 6
0
from scipy.optimize import curve_fit, minimize,least_squares

import OpenCOR as oc

# Experiment data -- has to be regularly sampled
expt_data = np.loadtxt('FCepsilonRI_trial_FullResolution.csv', delimiter=',')
expt_time = expt_data[...,0]
expt_pGRB2 = expt_data[...,1]
expt_pSyk = expt_data[...,2]

# The state variable in the model that the data represents
expt_state_uri_pGrb2 = 'FCepsilonRI/pGrb2'
expt_state_uri_pSyk = 'FCepsilonRI/pSyk'

# Load and initialise the simulation
simulation = oc.openSimulation('FCepsilonRI_trial.cellml')

# In case we have reloaded an open simulation
simulation.resetParameters()
simulation.clearResults()

# Reference some simulation objects
initial_data = simulation.data()
constants = initial_data.constants()
results = simulation.results()

# Simulation time points must match experiment data points
initial_data.setStartingPoint(0.0)
initial_data.setEndingPoint(3600)
initial_data.setPointInterval(1)
Exemplo n.º 7
0
import OpenCOR as oc

# Experiment data -- has to be regularly sampled
expt_data = np.loadtxt('Exp_pSyk_pFC.csv', delimiter=',')
expt_time = expt_data[..., 0]
expt_time = np.array([0, 240, 480, 960, 1920, 3840])
expt_pSyk = expt_data[..., 1]
expt_pFC = expt_data[..., 2]

# The state variable in the model that the data represents
expt_state_uri_pSyk = 'FCepsilonRI/pSyk'
expt_state_uri_pFC = 'FCepsilonRI/pFC'

# Load and initialise the simulation
simulation = oc.openSimulation('FCepsilonRI_Faeder_model2.cellml')

# In case we have reloaded an open simulation
simulation.resetParameters()
simulation.clearResults()

# Reference some simulation objects
initial_data = simulation.data()
constants = initial_data.constants()
states = initial_data.states()
results = simulation.results()

# Simulation time points must match experiment data points
initial_data.setStartingPoint(0.0)
initial_data.setEndingPoint(4000)
initial_data.setPointInterval(1)
    'FCepsilonRI/K_6': [-5, 2],
    'FCepsilonRI/K_7': [-5, 2],
    'FCepsilonRI/K_8': [-5, 2],
    'FCepsilonRI/K_9': [-5, 2],
    'FCepsilonRI/K_10': [-5, 2],
    'FCepsilonRI/K_11': [-5, 2],
    'FCepsilonRI/K_12': [-5, 2],
    'FCepsilonRI/V_1': [-5, 2],
    'FCepsilonRI/V_2': [-5, 2],
    'FCepsilonRI/V_3': [-5, 2],
    'FCepsilonRI/V_4': [-5, 2],
    'FCepsilonRI/pLyn': [-1.32640456, -1.32640455]
}

# Load and initialise the simulation
simulation = oc.openSimulation('FCepsilonRI.cellml')

# In case we have reloaded an open simulation
simulation.resetParameters()
simulation.clearResults()

# Reference some simulation objects
initial_data = simulation.data()
constants = initial_data.constants()
states = initial_data.states()
results = simulation.results()

# Simulation time points must match experiment data points
initial_data.setStartingPoint(0.0)
initial_data.setEndingPoint(3900)
initial_data.setPointInterval(1)