示例#1
0
    def __init__(self):
        self.simulation = oc.simulation()
        self.simulation.data().setStartingPoint(0)
        self.simulation.data().setEndingPoint(3900)
        self.simulation.data().setPointInterval(1)
        self.constants = self.simulation.data().constants()
        self.constant_parameter_names = sorted(list(self.constants.keys()))

        for i in range(0, len(fit_parameters_exclude)):
            self.constant_parameter_names.remove(fit_parameters_exclude[i])

        self.model_constants = OrderedDict(
            {k: self.constants[k]
             for k in self.constant_parameter_names})

        # default the parameter bounds to something sensible, needs to be set directly
        bounds = []
        for c in self.constant_parameter_names:
            v = self.constants[c]
            bounds.append([bounds_dictionary[c][0], bounds_dictionary[c][1]])
        # define our sensitivity analysis problem
        self.problem = {
            'num_vars': len(self.constant_parameter_names),
            'names': self.constant_parameter_names,
            'bounds': bounds
        }
        self.samples = saltelli.sample(self.problem, num_samples)
        #print(self.samples)
        np.savetxt("self.samples.txt", self.samples)
示例#2
0
 def __init__(self):
     self.simulation = oc.simulation()
     self.simulation.data().setStartingPoint(0)
     self.simulation.data().setEndingPoint(3600)
     self.simulation.data().setPointInterval(1)
     self.constants = self.simulation.data().constants()
     self.model_constants = OrderedDict({k: self.constants[k]
                                         for k in self.constants.keys()})
示例#3
0
 def __init__(self):
     self.simulation = oc.simulation()
     self.simulation.data().setStartingPoint(0)
     self.simulation.data().setEndingPoint(3600)
     self.simulation.data().setPointInterval(1)
     self.constants = self.simulation.data().constants()
     self.simulation.resetParameters()
     self.simulation.clearResults()
     for k, v in dict.items():
         self.constants[k] = v
     self.model_constants = OrderedDict(
         {k: self.constants[k]
          for k in self.constants.keys()})
示例#4
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()))
示例#5
0
    def __init__(self):
        self.simulation = oc.simulation()
        self.simulation.data().setStartingPoint(0)
        self.simulation.data().setEndingPoint(3900)
        self.simulation.data().setPointInterval(1)
        self.constants = self.simulation.data().constants()
        self.model_constants = OrderedDict(
            {k: self.constants[k]
             for k in self.constants.keys()})

        #print(self.model_constants)

        # default the parameter bounds to something sensible, needs to be set directly
        bounds = []
        #print(self.constants)
        for c in self.constants:
            v = self.constants[c]
            print(c)
            #print(bounds_dictionary[c][1])
            print(v)
            bounds.append([bounds_dictionary[c][0], bounds_dictionary[c][1]])
        # Define sensitivity analysis problem
        self.problem = {
            'num_vars': len(self.constants),
            'names': self.constants.keys(),
            'bounds': bounds
        }
        self.problem = {
            'num_vars':
            12,
            'names': [
                'FCepsilonRI/k_f1', 'FCepsilonRI/k_f2', 'FCepsilonRI/k_f3',
                'FCepsilonRI/k_f4', 'FCepsilonRI/k_f5', 'FCepsilonRI/k_f6',
                'FCepsilonRI/k_f7', 'FCepsilonRI/k_r1', 'FCepsilonRI/k_r3',
                'FCepsilonRI/k_r5', 'FCepsilonRI/k_r7', 'FCepsilonRI/k_f8'
            ],
            'bounds': [[-5, 2], [-5, 2], [-5, 2], [-5, 2], [-5, 2], [-5, 2],
                       [-5, 2], [-10, -9], [-10, -9], [-10, -9], [-10, -9],
                       [-0.03, -0.027]]
        }

        # Generate Samples
        self.samples = saltelli.sample(
            self.problem, 50
        )  #Generate no of sample using N*(2D+2) where N is the supplied argument and D is no of constant
示例#6
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
示例#7
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()
示例#8
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)
示例#9
0
def main(file, geojson=False, classes=None):
    (root, extension) = os.path.splitext(file)
    if not extension:
        extension = '.xml'

    diagram = parse(root + extension)

    if classes:
        utils.mkdir(root)
        utils.mkdir('{}/images'.format(root))
        utils.mkdir('{}/features'.format(root))
        defines_top = DefinesStore.top()
        export_diagram_layer(diagram, 'background', root, geojson, excludes=frozenset(classes))
        for cls in classes:
            DefinesStore.reset(defines_top)
            export_diagram_layer(diagram, cls, root, geojson)
    else:
        try:
            import OpenCOR as oc
            svg = diagram.svg()
            browser = oc.browserWebView()
            browser.setContent(svg, "image/svg+xml")
        except ModuleNotFoundError:
            export_diagram_layer(diagram, None, root, geojson)
示例#10
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:
示例#11
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)
示例#12
0
def figure(**kwds):
    return plt.figure(FigureClass=Figure, tight_layout=True, **kwds)


if __name__ == '__main__':

    import OpenCOR as oc
    '''
    s = oc.openSimulation('noble_1962.cellml')
    s.data().setEndingPoint(0.6)
    s.data().setPointInterval(0.005)
    s.reset()
    s.run()
'''
    s = oc.simulation()

    diagram = Diagram('noble_1962.svg', s, 0.04, 0.60, 's')

    diagram.add_channel('sodium_channel/i_Na', 'i_Na', (183.849, 49.756), 'V', 'red')
    diagram.add_channel('potassium_channel/i_K', 'i_K', (80.867, 49.756), 'V-', '#b666d2')
    diagram.add_channel('leakage_current/i_Leak', 'i_Leak', (133.551, 167.485), 'V', 'orange')

    svg = diagram.generate_svg(speed=0.5, period=25)

    browser = oc.browserWebView()
    browser.setContent(svg, "image/svg+xml")

    f = open('noble_1962_animated.svg', 'w')
    f.write(svg)
    f.close()
示例#13
0
 def __init__(self):
     print("Hello World")
     self.simulation = oc.simulation()
     print(filename)
     print('oh year')
示例#14
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)
示例#16
0
import OpenCOR as oc

s = oc.simulation()
d = s.data()
r = s.results()

d.setEndingPoint(600)
s.run()

t = r.points().values()
v = r.states()['membrane/V'].values()
na = r.states()['sodium_dynamics/Na_i'].values()


from matplotlib import pyplot as plt

na_axis = plt.subplot(2, 1, 1)
na_plot = plt.plot(t, na, lw=1)
na_plot[0].set_gid('Na')
plt.ylabel('Na_i (millimolar)')

v_axis = plt.subplot(2, 1, 2)
v_plot = plt.plot(t, v, lw=1)
v_plot[0].set_gid('V')
plt.ylabel('Membrane voltage (mV)')
plt.xlabel('Time (ms)')

#plt.show()

#plt.savefig('sodium.svg')