def run_model(path, params):
    soma_params = {
        "V0": 0.0,
        "C": 3.0,
        "Iextmean": -1.0,
        "Iextvarience": 0.5,
        "ENa": 120.0,
        "EK": -15.0,
        "El": 0.0,
        "ECa": 140.0,
        "CCa": 0.05,
        "sfica": 0.13,
        "sbetaca": 0.075,
        "gbarNa": 30.0,
        "gbarK_DR": 17.0,
        "gbarK_AHP": 0.8,
        "gbarK_C ": 15.0,
        "gl": 0.1,
        "gbarCa": 6.0,
    }

    dendrite_params = {
        "V0": 0.0,
        "C": 3.0,
        "Iextmean": -1.0,
        "Iextvarience": 0.5,
        "ENa": 120.0,
        "EK": -15.0,
        "El": 0.0,
        "ECa": 140.0,
        "CCa": 0.05,
        "sfica": 0.13,
        "sbetaca": 0.075,
        "gbarNa": 0.0,
        "gbarK_DR": 0.0,
        "gbarK_AHP": 0.8,
        "gbarK_C ": 5.0,
        "gl": 0.1,
        "gbarCa": 5.0,
    }

    connection_params = {
        "compartment1": "soma",
        "compartment2": "dendrite",
        "p": 0.5,
        "g": 1.5,
    }

    basket_fs_neuron = {
        "V0": -65.0,
        "Iextmean": -0.5,
        "Iextvarience": 0.5,
        "ENa": 50.0,
        "EK": -90.0,
        "El": -65.0,
        "gbarNa": 55.0,
        "gbarK": 8.0,
        "gl": 0.1,
        "fi": 10,
    }

    olm_params = {
        "V0": -70,
        "gl": 0.05,
        "El": -70,
        "gbarNa": 10.7,
        "ENa": 90,
        "gbarK": 31.9,
        "EK": -100,
        "gbarKa": 16.5,
        "gbarH": 0.05,
        "EH": -32.9,
        "Iextmean": 0.0,
        "Iextvarience": 0.5,
    }

    CosSpikeGeneratorParams = {
        "freq": 5.0,  # frequency in Hz
        "phase": 0.0,  # phase in rad
        "latency": 10.0,  # in ms
        "probability": 0.01,
        "threshold": 0.3,
    }

    PoisonSpikeGenerator = {
        "latency": 10.0,  # in ms
        "probability": 0.00001,
    }

    simple_ext_synapse_params = {
        "Erev": 60.0,
        "gbarS": 0.005,
        "tau": 0.5,  # 0.2, # 1.3–2
        "w": 20.0,
        "delay": 0,
    }

    simple_inh_synapse_params = {
        "Erev": -15.0,
        "gbarS": 0.005,
        "tau": 0.2,  # 4.2-7.2 ms
        "w": 100.0,
        "delay": 0,
    }

    ext_synapse_params = {
        "Erev": 60.0,
        "gbarS": 0.005,
        "alpha_s": 1.1,
        "beta_s": 0.19,
        "K": 5.0,
        "teta": 2.0,
        "w": 10.0,
        "delay": 0,
    }

    inh_synapse_params = {
        "Erev": -15.0,
        "gbarS": 0.005,
        "alpha_s": 14.0,
        "beta_s": 0.07,
        "K": 2.0,
        "teta": 0.0,
        "w": 10.0,
        "delay": 0,
    }

    neurons = []
    synapses = []
    Np = 400  # number of pyramide neurons
    Nb = 50  # number of basket cells
    Nolm = 50  # 50 # number of olm cells

    Npv1 = params["n_pv1"]  # number of septum spike generators
    Npv2 = params["n_pv2"]

    Nec = params["n_ec"]  # number of EC inputs
    Ncs = params["n_cs"]  # 100 # number of Shaffer collateral iunput

    Ns = 600  # number synapses between pyramide cells
    Nbasket2pyr = 10  # 100 4 # number synapses from basket interneuron to one pyramide neuron
    Nolm2pyr = 10  # 4 # number synapses from basket interneuron to one pyramide neuron
    Nspyr2basket = 10  # number synapses from one pyramide to interneurons
    Nspyr2OLM = 20

    # number synapses from septal generators to hippocampal interneurons
    Nspv12bas = params["Nspv12bas"]
    Nspv22olm = params["Nspv22olm"]
    NsEc2pyr = params["NsEc2pyr"]
    NsCs2pyr = params["NsCs2pyr"]
    NsCs2bas = params["NsCs2bas"]

    indexes = {
        "pyr": [],
        "bas": [],
        "olm": [],
        "pv1": [],
        "pv2": [],
        "mec": [],
        "cs": [],
    }

    for idx in range(Np):
        soma = {"soma": soma_params.copy()}
        soma["soma"]["V0"] = 0.5 * np.random.randn()
        soma["soma"]["Iextmean"] += 0.5 * np.random.randn()

        dendrite = {"dendrite": dendrite_params.copy()}
        dendrite["dendrite"]["V0"] = soma["soma"]["V0"]
        dendrite["dendrite"]["Iextmean"] += 0.5 * np.random.randn()

        connection = connection_params.copy()
        neuron = {
            "type": "pyramide",
            "compartments": [soma, dendrite],
            "connections": [connection]
        }
        indexes["pyr"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Nb):
        neuron = {"type": "FS_Neuron", "compartments": basket_fs_neuron.copy()}
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] += 0.5 * np.random.randn()
        indexes["bas"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Nolm):
        neuron = {"type": "olm_cell", "compartments": olm_params.copy()}
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] += 0.5 * np.random.randn()
        indexes["olm"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Npv1):

        if (params["pv1_type"] == "rhythm"):
            neuron = {
                "type": "CosSpikeGenerator",
                "compartments": CosSpikeGeneratorParams.copy()
            }
            # neuron["compartments"]["threshold"] = 0.6
            neuron["compartments"]["phase"] = params[
                "ms_pv1_pv2_phase_shift"] + params["ms_cs_pp_phase_shift"]

        elif (params["pv1_type"] == "random"):
            neuron = {
                "type": "PoisonSpikeGenerator",
                "compartments": PoisonSpikeGenerator.copy()
            }
        else:
            raise ValueError("undefined type of ms pv1 neuron")

        indexes["pv1"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Npv2):

        if (params["pv2_type"] == "rhythm"):
            neuron = {
                "type": "CosSpikeGenerator",
                "compartments": CosSpikeGeneratorParams.copy()
            }

            neuron["compartments"]["phase"] = params["ms_cs_pp_phase_shift"]

        elif (params["pv2_type"] == "random"):
            neuron = {
                "type": "PoisonSpikeGenerator",
                "compartments": PoisonSpikeGenerator.copy()
            }
        else:
            raise ValueError("undefined type of ms pv2 neuron")

        indexes["pv2"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Nec):

        if (params["pp_type"] == "rhythm"):
            neuron = {
                "type": "CosSpikeGenerator",
                "compartments": CosSpikeGeneratorParams.copy()
            }
            neuron["compartments"]["threshold"] = 0.3
            neuron["compartments"]["phase"] = -2.79  # !!!!!!!!

        elif (params["pp_type"] == "random"):
            neuron = {
                "type": "PoisonSpikeGenerator",
                "compartments": PoisonSpikeGenerator.copy()
            }
        else:
            raise ValueError("undefined type of ec neuron")

        indexes["mec"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Ncs):

        if (params["cs_type"] == "rhythm"):
            neuron = {
                "type": "CosSpikeGenerator",
                "compartments": CosSpikeGeneratorParams.copy()
            }
            neuron["compartments"]["threshold"] = 0.3
            neuron["compartments"]["phase"] = 0  # !!!!!!!!

        elif (params["cs_type"] == "random"):
            neuron = {
                "type": "PoisonSpikeGenerator",
                "compartments": PoisonSpikeGenerator.copy()
            }
        else:
            raise ValueError("undefined type of ec neuron")

        indexes["cs"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Ns):
        #synapse beteween pyramides

        pre_ind = np.random.choice(indexes["pyr"])
        post_ind = np.random.choice(indexes["pyr"])

        if (pre_ind == post_ind):
            post_ind = np.random.randint(0, Np)
        synapse = {
            "type": "ComplexSynapse",  # "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "soma",
            "params": ext_synapse_params.copy(),
        }
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)

    for _ in range(Nbasket2pyr):
        for idx in indexes["pyr"]:
            # synapses from basket cells to pyramides

            pre_ind = np.random.choice(indexes["bas"])
            synapse = {
                "type": "ComplexSynapse",  # "SimpleSynapseWithDelay",
                "pre_ind": pre_ind,
                "post_ind": idx,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)

    for _ in range(Nolm2pyr):
        for idx in indexes["pyr"]:
            # synapses from OLM cells to pyramides
            pre_ind = np.random.choice(indexes["olm"])

            synapse = {
                "type": "ComplexSynapse",  # "SimpleSynapseWithDelay",
                "pre_ind": pre_ind,
                "post_ind": idx,
                "pre_compartment_name": "soma",
                "post_compartment_name": "dendrite",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)

    for _ in range(Nspyr2OLM):
        for idx in indexes["pyr"]:
            pre_ind = idx

            # set synapse from pyramide to OLM neuron
            post_ind = np.random.choice(indexes["olm"])
            synapse = {
                "type": "ComplexSynapse",  # "SimpleSynapseWithDelay",
                "pre_ind": pre_ind,
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": ext_synapse_params.copy(),
            }
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)

    for _ in range(Nspyr2basket):
        for idx in indexes["pyr"]:
            # set synapse from pyramide to basket neuron
            pre_ind = idx
            post_ind = np.random.choice(indexes["bas"])
            synapse = {
                "type": "ComplexSynapse",  # "SimpleSynapseWithDelay",
                "pre_ind": pre_ind,
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": ext_synapse_params.copy(),
            }
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)

    for idx in range(Nspv12bas):
        # set synapses from pv1 to basket
        pre_ind = np.random.choice(indexes["pv1"])
        post_ind = np.random.choice(indexes["bas"])
        synapse = {
            "type": "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "soma",
            "params": simple_inh_synapse_params.copy(),
        }
        # synapse["params"]["Erev"] = -75
        # synapse["params"]["w"] = 100
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)

    for idx in range(Nspv22olm):
        # set synapses from pv1 to olm
        pre_ind = np.random.choice(indexes["pv2"])
        post_ind = np.random.choice(indexes["olm"])
        synapse = {
            "type": "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "soma",
            "params": simple_inh_synapse_params.copy()
        }
        # synapse["params"]["Erev"] = -75
        # synapse["params"]["w"] = 100
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)

    for idx in range(NsCs2pyr):
        # synapses from shaffer colletarel to pyramodes
        pre_ind = np.random.choice(indexes["cs"])
        post_ind = np.random.choice(indexes["pyr"])
        synapse = {
            "type": "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "soma",
            "params": simple_ext_synapse_params.copy()
        }

        # synapse["params"]["w"] = 20
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)

    for idx in range(NsCs2bas):
        # synapses from shaffer colletarel to basket
        pre_ind = np.random.choice(indexes["cs"])
        post_ind = np.random.choice(indexes["bas"])
        synapse = {
            "type": "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "soma",
            "params": simple_ext_synapse_params.copy()
        }

        #synapse["params"]["w"] = 100
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)

    for idx in range(NsEc2pyr):
        # synapses from perforant pathway to pyramodes
        pre_ind = np.random.choice(indexes["mec"])
        post_ind = np.random.choice(indexes["pyr"])
        synapse = {
            "type": "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "dendrite",
            "params": simple_ext_synapse_params.copy()
        }

        #synapse["params"]["w"] = 100
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)
    """
    for syn in synapses:
        print (neurons[syn["pre_ind"]]["type"] + " -> " + neurons[syn["post_ind"]]["type"])
        print ( str(syn["pre_ind"]) + " -> " + str(syn["post_ind"]) )
    return 
    """

    dt = 0.1
    duration = 500
    net = lib.Network(neurons, synapses)

    for _ in range(4):

        net.integrate(dt, duration)
        net.save_results(path + "_all_results")

        print("Что-то посчиталось!!!")
    return indexes
def run_model(path, experiment):

    cluster_pacemaker = {
        "V0": -50.0,
        "Iextmean": 1.2,        
        "Iextvarience": 0.5,
        "ENa": 50.0,
        "EK": -90.0,
        "El": -50.0,
        "Eh": -40.0,
        "gbarNa": 55.0,
        "gbarK": 8.0,
        "gbarKS": 12.0,
        "gbarH": 1.0,
        "gl": 0.1,
        "fi": 5,
    }
    
    fs_neuron = {
        "V0": -65.0,
        "Iextmean": 0.5,        
        "Iextvarience": 0.5,
        "ENa": 50.0,
        "EK": -90.0,
        "El": -65.0,
        "gbarNa": 55.0,
        "gbarK": 8.0,
        "gl": 0.1,   
        "fi": 10,
    }
    
    ext_synapse_params = {
        "Erev" : 60.0,
        "gbarS": 0.005,
        "alpha_s" : 1.1,
        "beta_s": 0.19,
        "K": 5.0,
        "teta": 2.0,
        "w" : 1.0,
        "delay" : 0,
    }
    
    inh_synapse_params = {
        "Erev" : -15.0,
        "gbarS": 0.005,
        "alpha_s" : 14.0,
        "beta_s": 0.07,
        "K": 2.0,
        "teta": 0.0,
        "w" : 1.0,
        "delay" : 0,
    }
    
    soma_params = {
        "V0": 0.0,
        "C" : 3.0,
        "Iextmean": -0.5,        
        "Iextvarience": 0.2,
        "ENa": 120.0,
        "EK": -15.0,
        "El": 0.0,
        "ECa": 140.0,
        "CCa": 0.05,
        "sfica": 0.13,
        "sbetaca": 0.075, 
        "gbarNa": 30.0,
        "gbarK_DR": 17.0,
        "gbarK_AHP": 0.8,        
        "gbarK_C " : 15.0,
        "gl": 0.1,
        "gbarCa": 6.0,
    }
        
    dendrite_params = {
        "V0": 0.0,
        "C" : 3.0,
        "Iextmean": -0.5,        
        "Iextvarience": 0.2,
        "ENa": 120.0,
        "EK": -15.0,
        "El": 0.0,
        "ECa": 140.0,
        "CCa": 0.05,
        "sfica": 0.13, 
        "sbetaca": 0.075, 
        "gbarNa": 0.0,
        "gbarK_DR": 0.0,
        "gbarK_AHP": 0.8,        
        "gbarK_C " : 5.0,
        "gl": 0.1,
        "gbarCa": 5.0,
    }
        
    connection_params = {
        "compartment1": "soma",
        "compartment2": "dendrite",
        "p": 0.5,
        "g": 1.5,
    }
        
    basket_fs_neuron = {
        "V0": -65.0,
        "Iextmean": 0.2,        
        "Iextvarience": 0.2,
        "ENa": 50.0,
        "EK": -90.0,
        "El": -65.0,
        "gbarNa": 55.0,
        "gbarK": 8.0,
        "gl": 0.1,   
        "fi": 10,
    }
        
    olm_params = {
        "V0" : -70,
        "gl" : 0.05,
        "El" : -70,
        "gbarNa" : 10.7, 
        "ENa" : 90,
        "gbarK" : 31.9,
        "EK" : -100,
        "gbarKa" : 16.5,
        "gbarH" : 0.05,
        "EH" : -32.9,
        "Iextmean" : 0.2,        
        "Iextvarience": 0.2,
    }
    
    
    ########## set model of septum ################
    # number of neurons
    Nglu = 40
    NgabaCR = 40
    NgabaPV1 = 40 
    NgabaPV2 = 40
    NgabaPacPV1 = 10
    NgabaPacPV2 = 10
    
    
    NNseptum = Nglu + NgabaCR + NgabaPV1 + NgabaPV2 + NgabaPacPV1 + NgabaPacPV2
    
    Sparsness = 0.5 # sparsness in septal network
    
    
    neurons = []
    for idx in range(Nglu):
        neuron = {
            "type" : "FS_Neuron",
            "compartments" : fs_neuron.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0.5 # 0.5*np.random.randn()
        neurons.append(neuron)
    
    for idx in range(NgabaCR):
        neuron = {
            "type" : "FS_Neuron",
            "compartments" : fs_neuron.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0 # 0.1*np.random.randn()
        neurons.append(neuron)
    
    for idx in range(NgabaPV1):
        neuron = {
            "type" : "FS_Neuron",
            "compartments" : fs_neuron.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0.1 #0.5*np.random.randn()
        neurons.append(neuron)
    
    for idx in range(NgabaPacPV1):
        neuron = {
            "type" : "ClusterNeuron",
            "compartments" : cluster_pacemaker.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0.1 # 0.5*np.random.randn()
        neurons.append(neuron)
    
    for idx in range(NgabaPV2):
        neuron = {
            "type" : "FS_Neuron",
            "compartments" : fs_neuron.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0.7 #0.5*np.random.randn()
        neurons.append(neuron)
    
    for idx in range(NgabaPacPV2):
        neuron = {
            "type" : "ClusterNeuron",
            "compartments" : cluster_pacemaker.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0.7 #0.5*np.random.randn()
        neurons.append(neuron)
    
    
    synapses = []
    # synapse from Glu to Glu neurons
    
    for idx1 in range(Nglu):
        for idx2 in range(Nglu):
            if (Sparsness < np.random.rand() or idx1 == idx2):
                continue
            pre_ind = idx1
            post_ind = idx2
            synapse = {
                "type" : "ComplexSynapse",
                "pre_ind": pre_ind, 
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name" : "soma",
                "params": ext_synapse_params.copy(),
            }
            synapse["params"]["w"] = 1
            synapses.append(synapse)
    
    # synapses from Glu naurons to GABA(CR) neurons
    for idx1 in range(Nglu):
        for idx2 in range(Nglu, Nglu+NgabaCR):
            if (Sparsness < np.random.rand() or idx1 == idx2):
                continue
            pre_ind = idx1
            post_ind = idx2
            synapse = {
                "type" : "ComplexSynapse",
                "pre_ind": pre_ind, 
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name" : "soma",
                "params": ext_synapse_params.copy(),
            }
            synapse["params"]["w"] = 0.2
            synapses.append(synapse)
    
    # synapses from GABA(CR) neurons to Glu naurons
    for idx1 in range(Nglu, Nglu+NgabaCR):
        for idx2 in range(Nglu):
            if (idx1 == idx2):
                continue
    
            pre_ind = idx1
            post_ind = idx2
            synapse = {
                "type" : "ComplexSynapse",
                "pre_ind": pre_ind, 
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name" : "soma",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["w"] = 1.5
            synapses.append(synapse)
            
           
    # synapses from Glu neurons to PV1 and pac-PV1 naurons  
    for idx1 in range(0, Nglu):
        for idx2 in range(Nglu+NgabaCR, Nglu+NgabaCR+NgabaPV1+NgabaPacPV1):
            if (Sparsness < np.random.rand() or idx1 == idx2):
                continue
            pre_ind = idx1
            post_ind = idx2
            synapse = {
                "type" : "ComplexSynapse",
                "pre_ind": pre_ind, 
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name" : "soma",
                "params": ext_synapse_params.copy(),
            }
            synapse["params"]["w"] = 1
            synapses.append(synapse)
    
    # synapses from PV1 and pac-PV1 naurons to PV2 and pac-PV2
    for idx1 in range(Nglu+NgabaCR, Nglu+NgabaCR+NgabaPV1+NgabaPacPV1):
        for idx2 in range(Nglu+NgabaCR+NgabaPV1+NgabaPacPV1, Nglu+NgabaCR+NgabaPV1+NgabaPacPV1+NgabaPV2+NgabaPacPV2):
            if (Sparsness < np.random.rand() or idx1 == idx2):
                continue
            pre_ind = idx1
            post_ind = idx2
            synapse = {
                "type" : "ComplexSynapse",
                "pre_ind": pre_ind, 
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name" : "soma",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["w"] = 0.5
            synapses.append(synapse) 
        
    # synapses from PV2 and pac-PV2 naurons to PV1 and pac-PV1  
    for pre_ind in range(Nglu+NgabaCR+NgabaPV1+NgabaPacPV1, Nglu+NgabaCR+NgabaPV1+NgabaPacPV1+NgabaPV2+NgabaPacPV2):
        for post_ind in range(Nglu+NgabaCR, Nglu+NgabaCR+NgabaPV1+NgabaPacPV1):
            if (Sparsness < np.random.rand() or idx1 == idx2):
                continue
            synapse = {
                "type" : "ComplexSynapse",
                "pre_ind": pre_ind, 
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name" : "soma",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["w"] = 0.1
            synapses.append(synapse) 
    
    
    for s in synapses:
        s["params"]["w"] *= 2
        
    ###### set model of hippocampus ####################
    # number of neurons
    Np = 400 # number of pyramide neurons
    Nb = 50   # number of basket cells
    Nolm = 50 # number of olm cells
    
    # Number synapses
    Ns = 400 # number synapses between pyramide cells
    Nint2pyr = 50 # 4 # number synapses from one interneuron to one pyramide neuron 
    
    # NSG = 20 # number of spike generators
    Ns2in = 200 # number synapses from septal generators to hippocampal interneurons 
    NsOLM2PV = 400 # number synapses from OLM cell to MSDB PV1 cells 
        
    for idx in range(Np):
        soma = {"soma" : soma_params.copy()}
        soma["soma"]["V0"] = 0.5 * np.random.randn()
        soma["soma"]["Iextmean"] += 0.5*np.random.randn()
            
        dendrite = {"dendrite" : dendrite_params.copy()}
        dendrite["dendrite"]["V0"] = soma["soma"]["V0"]
        dendrite["dendrite"]["Iextmean"] += 0.5*np.random.randn()
           
        connection = connection_params.copy()
        neuron = {
            "type" : "pyramide",
            "compartments" : [soma, dendrite],
            "connections" : [connection]
        }
        neurons.append(neuron)
        
    for idx in range(Nb):
        neuron = {
            "type" : "FS_Neuron",
            "compartments" : basket_fs_neuron.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] += 0.5*np.random.randn()
        neurons.append(neuron)
             
    for idx in range(Nolm):
        neuron = {
            "type" : "olm_cell",
            "compartments" : olm_params.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] += 0.5*np.random.randn()
        neurons.append(neuron)
    
    # set synapses intro hippocampal model
    for idx in range(Ns):
        pre_ind = np.random.randint(0, Np) + NNseptum
        post_ind = np.random.randint(0, Np) + NNseptum
        if (pre_ind == post_ind):
            post_ind = np.random.randint(0, Np) + NNseptum
        synapse = {
            "type" : "ComplexSynapse",
            "pre_ind": pre_ind, 
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name" : "soma",
            "params" : ext_synapse_params.copy(),
        }
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)
        
    for _ in range(Nint2pyr):
        for idx in range(Np):
            pre_ind = np.random.randint(Np, Np + Nb) + NNseptum
            synapse = {
                "type" : "ComplexSynapse",
                "pre_ind": pre_ind, 
                "post_ind": idx + NNseptum,
                "pre_compartment_name": "soma",
                "post_compartment_name" : "soma",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)
        
    for _ in range(Nint2pyr):
        for idx in range(Np):
            pre_ind = np.random.randint(Np + Nb, Np + Nb + Nolm) + NNseptum
            synapse = {
                "type" : "ComplexSynapse",
                "pre_ind": pre_ind, 
                "post_ind": idx + NNseptum,
                "pre_compartment_name": "soma",
                "post_compartment_name" : "dendrite",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)
        
        
    for idx in range(Np):
        pre_ind = idx + NNseptum
        # set synapse from pyramide to OLM neuron
        post_ind = np.random.randint(Np + Nb, Np + Nb + Nolm) + NNseptum
        synapse = {
            "type" : "ComplexSynapse",
            "pre_ind": pre_ind, 
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name" : "soma",
            "params": ext_synapse_params.copy(),
        }
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)
            
         # set synapse from pyramide to basket neuron
        post_ind = np.random.randint(Np, Np + Nb) + NNseptum
        synapse = {
            "type" : "ComplexSynapse",
            "pre_ind": pre_ind, 
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name" : "soma",
            "params": ext_synapse_params.copy(),
        }
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)
    
    # set synapses from MSDB PV-neurons to hippocampal interneurons
    # from PV1-neurons to basketcells   
    for idx in range(Ns2in):
        pre_ind = np.random.randint(Nglu+NgabaCR, Nglu+NgabaCR+NgabaPV1+NgabaPacPV1)
        
        post_ind = np.random.randint(Np, Np + Nb) + NNseptum
        
        
    
        synapse = {
            "type" : "ComplexSynapse",
            "pre_ind": pre_ind, 
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name" : "soma",
            "params": inh_synapse_params.copy(),
        }
        # synapse["params"]["Erev"] = -75
        synapse["params"]["w"] = 50
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)
        
    # from PV2-neurons to OLM neurons    
    for idx in range(Ns2in):
        pre_ind = np.random.randint(Nglu+NgabaCR+NgabaPV1+NgabaPacPV1, Nglu+NgabaCR+NgabaPV1+NgabaPacPV1+NgabaPV2+NgabaPacPV2)
        
        
        post_ind = np.random.randint(Np + Nb, Np + Nb + Nolm) + NNseptum
        synapse = {
            "type" : "ComplexSynapse",
            "pre_ind": pre_ind, 
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name" : "soma",
            "params": inh_synapse_params.copy()
         }
         # synapse["params"]["Erev"] = -75
        synapse["params"]["w"] = 50
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)
    
    # set hippocampal synapses to MSBD PV-neurons
    # from OLM cells to PV1-neurons
    
    if (experiment == "OLM2PV1" or experiment == "OLM2PV1andPV2"):
        for idx in range(NsOLM2PV):
            post_ind = np.random.randint(Nglu+NgabaCR, Nglu+NgabaCR+NgabaPV1+NgabaPacPV1)
            pre_ind = np.random.randint(Np + Nb, Np + Nb + Nolm) + NNseptum
        
            synapse = {
                "type" : "ComplexSynapse",
                "pre_ind": pre_ind, 
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name" : "soma",
                "params": inh_synapse_params.copy(),
            }
            # synapse["params"]["Erev"] = -75
            synapse["params"]["w"] = 50
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)

    if (experiment == "OLM2PV2" or experiment == "OLM2PV1andPV2"):
        for idx in range(NsOLM2PV):
            post_ind = np.random.randint(Nglu+NgabaCR+NgabaPV1+NgabaPacPV1, Nglu+NgabaCR+NgabaPV1+NgabaPacPV1+NgabaPV2+NgabaPacPV2)
            pre_ind = np.random.randint(Np + Nb, Np + Nb + Nolm) + NNseptum
        
            synapse = {
                "type" : "ComplexSynapse",
                "pre_ind": pre_ind, 
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name" : "soma",
                "params": inh_synapse_params.copy(),
            }
            # synapse["params"]["Erev"] = -75
            synapse["params"]["w"] = 50
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)
            
            
            
    duration = 500
    dt = 0.1
    sim = SimmulationParams()
    net = lib.Network(neurons, synapses)
    for _ in range(4):
        curent_time = time.time()
        net.integrate(dt, duration, sim.iext_function)
        print ("Calculation time is %0.3f sec" % (time.time() - curent_time) )
        net.save_results(path+"all_results")
        """
def run_model(sim, path):
    soma_params = {
        "V0": 0.0,
        "C": 3.0,
        "Iextmean": -1.0,
        "Iextvarience": 0.5,
        "ENa": 120.0,
        "EK": -15.0,
        "El": 0.0,
        "ECa": 140.0,
        "CCa": 0.05,
        "sfica": 0.13,
        "sbetaca": 0.075,
        "gbarNa": 30.0,
        "gbarK_DR": 17.0,
        "gbarK_AHP": 0.8,
        "gbarK_C ": 15.0,
        "gl": 0.1,
        "gbarCa": 6.0,
    }

    dendrite_params = {
        "V0": 0.0,
        "C": 3.0,
        "Iextmean": -1.0,
        "Iextvarience": 0.5,
        "ENa": 120.0,
        "EK": -15.0,
        "El": 0.0,
        "ECa": 140.0,
        "CCa": 0.05,
        "sfica": 0.13,
        "sbetaca": 0.075,
        "gbarNa": 0.0,
        "gbarK_DR": 0.0,
        "gbarK_AHP": 0.8,
        "gbarK_C ": 5.0,
        "gl": 0.1,
        "gbarCa": 5.0,
    }

    connection_params = {
        "compartment1": "soma",
        "compartment2": "dendrite",
        "p": 0.5,
        "g": 1.5,
    }

    basket_fs_neuron = {
        "V0": -65.0,
        "Iextmean": -0.5,
        "Iextvarience": 0.5,
        "ENa": 50.0,
        "EK": -90.0,
        "El": -65.0,
        "gbarNa": 55.0,
        "gbarK": 8.0,
        "gl": 0.1,
        "fi": 10,
    }

    olm_params = {
        "V0": -70,
        "gl": 0.05,
        "El": -70,
        "gbarNa": 10.7,
        "ENa": 90,
        "gbarK": 31.9,
        "EK": -100,
        "gbarKa": 16.5,
        "gbarH": 0.05,
        "EH": -32.9,
        "Iextmean": 0.0,
        "Iextvarience": 0.5,
    }

    CosSpikeGeneratorParams = {
        "freq": 5.0,  # frequency in Hz
        "phase": 0.0,  # phase in rad
        "latency": 10.0,  # in ms
        "probability": 0.01,
        "threshold": 0.3,
    }

    PoisonSpikeGenerator = {
        "latency": 10.0,  # in ms
        "probability": 0.00001,
    }

    simple_ext_synapse_params = {
        "Erev": 60.0,
        "gbarS": 0.005,
        "tau": 0.5,  # 0.2, # 1.3–2
        "w": 20.0,
        "delay": 0,
    }

    simple_inh_synapse_params = {
        "Erev": -15.0,
        "gbarS": 0.005,
        "tau": 0.2,  # 4.2-7.2 ms
        "w": 100.0,
        "delay": 0,
    }

    ext_synapse_params = {
        "Erev": 60.0,
        "gbarS": 0.005,
        "alpha_s": 1.1,
        "beta_s": 0.19,
        "K": 5.0,
        "teta": 2.0,
        "w": 10.0,
        "delay": 0,
    }

    inh_synapse_params = {
        "Erev": -15.0,
        "gbarS": 0.005,
        "alpha_s": 14.0,
        "beta_s": 0.07,
        "K": 2.0,
        "teta": 0.0,
        "w": 10.0,
        "delay": 0,
    }

    if (sim.get_mode() == "variate_frequency"):
        CosSpikeGeneratorParams["freq"] = sim.p

    neurons = []
    synapses = []
    Np = 400  # number of pyramide neurons
    Nb = 50  # number of basket cells
    Nolm = 50  # 50 # number of olm cells
    NSG = 100  # 100 # number of septum spike generators
    Nec = 100  # number of EC inputs
    Ncs = 100  # 100 # number of Shaffer collateral iunput

    Ns = 600  # number synapses between pyramide cells
    Nbasket2pyr = 3  # 100 4 # number synapses from basket interneuron to one pyramide neuron
    Nolm2pyr = 10  # 4 # number synapses from olm interneuron to one pyramide neuron
    Nspyr2basket = 10  # number synapses from one pyramide to interneurons
    Nspyr2OLM = 20
    # number synapses from septal generators to hippocampal interneurons
    Nspv12bas = 400
    Nspv22olm = 400
    NsEc2pyr = 150  # 40
    NsCs2pyr = 150
    NsCs2bas = 25

    indexes = {
        "pyr": [],
        "bas": [],
        "olm": [],
        "pv1": [],
        "pv2": [],
        "mec": [],
        "cs": [],
    }

    for idx in range(Np):
        soma = {"soma": soma_params.copy()}
        soma["soma"]["V0"] = 0.5 * np.random.randn()
        soma["soma"]["Iextmean"] += 0.5 * np.random.randn()

        dendrite = {"dendrite": dendrite_params.copy()}
        dendrite["dendrite"]["V0"] = soma["soma"]["V0"]
        dendrite["dendrite"]["Iextmean"] += 0.5 * np.random.randn()

        connection = connection_params.copy()
        neuron = {
            "type": "pyramide",
            "compartments": [soma, dendrite],
            "connections": [connection]
        }
        indexes["pyr"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Nb):
        neuron = {"type": "FS_Neuron", "compartments": basket_fs_neuron.copy()}
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] += 0.5 * np.random.randn()
        indexes["bas"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Nolm):
        neuron = {"type": "olm_cell", "compartments": olm_params.copy()}
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] += 0.5 * np.random.randn()
        indexes["olm"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(NSG):
        """
        if (sim.get_mode() == "only_one_rhytm" and sim.p[1] == 0 and idx >= NSG//2):
            
            neuron = {
                "type" : "PoisonSpikeGenerator", 
                "compartments" : PoisonSpikeGenerator.copy()
            }
            indexes["pv2"].append(len(neurons))
            neurons.append(neuron)
            continue  
        
        if (sim.get_mode() == "only_one_rhytm" and sim.p[0] == 0 and idx < NSG//2):
            
            neuron = {
                "type" : "PoisonSpikeGenerator", 
                "compartments" : PoisonSpikeGenerator.copy()
            }
            indexes["pv1"].append(len(neurons))
            neurons.append(neuron)
            continue
        """

        neuron = {
            "type": "CosSpikeGenerator",
            "compartments": CosSpikeGeneratorParams.copy()
        }

        neuron["compartments"]["phase"] = -2.15 + 1.5  # np.pi # 0.5 - 2.15
        if (idx >= NSG // 2):
            """
            if (sim.get_mode() == "different_phase_shift"):
                neuron["compartments"]["phase"] = sim.p
                indexes["pv1"].append(len(neurons))
            else:
                neuron["compartments"]["phase"] = 0.5 * np.pi + 2.15 # !!!!
                indexes["pv2"].append(len(neurons))
            """
            neuron["compartments"]["phase"] = 1.5  # 0.2 #np.pi + 2.15 # !!!!
            indexes["pv2"].append(len(neurons))
        else:
            indexes["pv1"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Nec):
        neuron = {
            "type": "CosSpikeGenerator",
            "compartments": CosSpikeGeneratorParams.copy()
        }
        neuron["compartments"]["threshold"] = 0.3
        neuron["compartments"]["phase"] = -2.79  # !!!!!!!!
        indexes["mec"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Ncs):
        neuron = {
            "type": "CosSpikeGenerator",
            "compartments": CosSpikeGeneratorParams.copy()
        }
        neuron["compartments"]["threshold"] = 0.3
        neuron["compartments"]["phase"] = 0  # !!!!!!!!
        indexes["cs"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(Ns):
        #synapse beteween pyramides

        pre_ind = np.random.choice(indexes["pyr"])
        post_ind = np.random.choice(indexes["pyr"])

        if (pre_ind == post_ind):
            post_ind = np.random.randint(0, Np)
        synapse = {
            "type": "ComplexSynapse",  # "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "soma",
            "params": ext_synapse_params.copy(),
        }
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)

    for _ in range(Nbasket2pyr):
        for idx in indexes["pyr"]:
            # synapses from basket cells to pyramides

            pre_ind = np.random.choice(indexes["bas"])
            synapse = {
                "type": "ComplexSynapse",  # "SimpleSynapseWithDelay",
                "pre_ind": pre_ind,
                "post_ind": idx,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)

    for _ in range(Nolm2pyr):
        for idx in indexes["pyr"]:
            # synapses from OLM cells to pyramides
            pre_ind = np.random.choice(indexes["olm"])

            synapse = {
                "type": "ComplexSynapse",  # "SimpleSynapseWithDelay",
                "pre_ind": pre_ind,
                "post_ind": idx,
                "pre_compartment_name": "soma",
                "post_compartment_name": "dendrite",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)

    for _ in range(Nspyr2OLM):
        for idx in indexes["pyr"]:
            pre_ind = idx

            # set synapse from pyramide to OLM neuron
            post_ind = np.random.choice(indexes["olm"])
            synapse = {
                "type": "ComplexSynapse",  # "SimpleSynapseWithDelay",
                "pre_ind": pre_ind,
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": ext_synapse_params.copy(),
            }
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)

    for _ in range(Nspyr2basket):
        for idx in indexes["pyr"]:
            # set synapse from pyramide to basket neuron
            pre_ind = idx
            post_ind = np.random.choice(indexes["bas"])
            synapse = {
                "type": "ComplexSynapse",  # "SimpleSynapseWithDelay",
                "pre_ind": pre_ind,
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": ext_synapse_params.copy(),
            }
            synapse["params"]["delay"] = np.random.randint(20, 50)
            synapses.append(synapse)

    for idx in range(Nspv12bas):
        # set synapses from pv1 to basket
        pre_ind = np.random.choice(indexes["pv1"])
        post_ind = np.random.choice(indexes["bas"])
        synapse = {
            "type": "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "soma",
            "params": simple_inh_synapse_params.copy(),
        }
        # synapse["params"]["Erev"] = -75
        # synapse["params"]["w"] = 100
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)

    for idx in range(Nspv22olm):
        # set synapses from pv1 to olm
        pre_ind = np.random.choice(indexes["pv2"])
        post_ind = np.random.choice(indexes["olm"])
        synapse = {
            "type": "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "soma",
            "params": simple_inh_synapse_params.copy()
        }
        # synapse["params"]["Erev"] = -75
        # synapse["params"]["w"] = 100
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)

    for idx in range(NsCs2pyr):
        # synapses from shaffer colletarel to pyramodes
        pre_ind = np.random.choice(indexes["cs"])
        post_ind = np.random.choice(indexes["pyr"])
        synapse = {
            "type": "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "soma",
            "params": simple_ext_synapse_params.copy()
        }

        # synapse["params"]["w"] = 20
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)

    for idx in range(NsCs2bas):
        # synapses from shaffer colletarel to basket
        pre_ind = np.random.choice(indexes["cs"])
        post_ind = np.random.choice(indexes["bas"])
        synapse = {
            "type": "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "soma",
            "params": simple_ext_synapse_params.copy()
        }

        #synapse["params"]["w"] = 100
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)

    for idx in range(NsEc2pyr):
        # synapses from perforant pathway to pyramodes

        pre_ind = np.random.choice(indexes["mec"])
        post_ind = np.random.choice(indexes["pyr"])
        synapse = {
            "type": "SimpleSynapseWithDelay",
            "pre_ind": pre_ind,
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name": "dendrite",
            "params": simple_ext_synapse_params.copy()
        }

        #synapse["params"]["w"] = 1
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)
    """
    for syn in synapses:
        print (neurons[syn["pre_ind"]]["type"] + " -> " + neurons[syn["post_ind"]]["type"])
        print ( str(syn["pre_ind"]) + " -> " + str(syn["post_ind"]) )
    return
    """

    dt = 0.1
    duration = 500
    net = lib.Network(neurons, synapses)

    for _ in range(4):

        net.integrate(dt, duration)
        net.save_results(path + "_all_results")
        """
        V = net.getVhist()
        VmeanSoma = 0
        VmeanDendrite = 0
        np.save(path + "V", V)
        for v in V:
            try:
                VmeanSoma += v["soma"]
                VmeanDendrite += v["dendrite"]
            except KeyError:
                continue
            
        VmeanSoma /= Np
        VmeanDendrite /= Np
        t = np.linspace(duration-500, duration, VmeanSoma.size)
        plt.figure()
        plt.subplot(211)
        plt.plot(t, VmeanSoma, "b")
        plt.subplot(212)
        plt.plot(t, VmeanDendrite, "r")
        
        plt.savefig(path + "mean_V", dpi=300)
        lfp = net.getLFP()
    
        lfp = plib.butter_bandpass_filter(lfp, 1, 80, 1000/dt, 3)
        np.save(path + "lfp", lfp)
        
        currents = net.getfullLFP()
        np.save(path + "  currents", currents)
       
        plt.figure()
        plt.plot(t, lfp)
        #plt.xlim(1000, 1500)
        # lfp_half = lfp[t > duration/2]
        plt.savefig(path + "lfp", dpi=300)
        
        fft_y = np.abs(np.fft.rfft(lfp))/lfp.size
        fft_x = np.fft.rfftfreq(lfp.size, 0.001*dt)
        plt.figure()
        plt.plot(fft_x[1:], fft_y[1:])
        plt.xlim(2, 50)
        
        theta_power = np.sum(fft_y[(fft_x>4)&(fft_x<12)])/np.sum(fft_y)
        plt.savefig(path + "spectra_of_lfp", dpi=300)
        firing = net.getFiring()
        np.save(path + "firing", firing)
        
        
        plt.figure()
        
        cum_it = Np
        sl = firing[1, :] <= cum_it
        pyr_line, = plt.plot(firing[0, sl], firing[1, sl], '.b', label='Pyramide')
        
        sl = (firing[1, :] > cum_it) & (firing[1, :] <= cum_it + Nb)
    
        basket_line, = plt.plot(firing[0, sl], firing[1, sl], '.g', label='Basket')
        cum_it += Nb
        sl = (firing[1, :] > cum_it) & (firing[1, :] <= cum_it + Nolm)
        
        olm_line, = plt.plot(firing[0, sl], firing[1, sl], '.m', label='OLM')
        cum_it += Nolm
        sl = (firing[1, :] > cum_it)
        
        septal_line, = plt.plot(firing[0, sl], firing[1, sl], '.r', label='Septum')
        
        plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
        plt.savefig(path + "raster", dpi=300)
        plt.show()
        
        
        
        """
        print("Что-то посчиталось!!!")
    return indexes
示例#4
0
    for idx in range(Ns2in):
        pre_ind = np.random.randint(Np + Nb + Nolm + NSG//2, Np + Nb + Nolm + NSG)
        post_ind = np.random.randint(Np + Nb, Np + Nb + Nolm)
        synapse = {
            "type" : "ComplexSynapse",
            "pre_ind": pre_ind, 
            "post_ind": post_ind,
            "pre_compartment_name": "soma",
            "post_compartment_name" : "soma",
            "params": inh_synapse_params.copy()
        }
        # synapse["params"]["Erev"] = -75
        synapse["params"]["w"] = 100
        synapse["params"]["delay"] = np.random.randint(20, 50)
        synapses.append(synapse)
    """
    for syn in synapses:
        if (syn["params"]["Erev"] == 60):
            syn["params"]["w"] *= 2

        if (syn["params"]["Erev"] == -15):
            syn["params"]["w"] /= 2

    dt = 0.1
    duration = 500
    net = lib.Network(neurons, synapses)

    for _ in range(4):

        net.integrate(dt, duration, sim.iext_function)
        net.save_results(path + "_all_results")
def run_model(path, params):

    cluster_pacemaker = {
        "V0": -50.0,
        "Iextmean": 1.2,
        "Iextvarience": 0.5,
        "ENa": 50.0,
        "EK": -90.0,
        "El": -50.0,
        "Eh": -40.0,
        "gbarNa": 55.0,
        "gbarK": 8.0,
        "gbarKS": 12.0,
        "gbarH": 1.0,
        "gl": 0.1,
        "fi": 5,
    }

    fs_neuron = {
        "V0": -65.0,
        "Iextmean": 0.5,
        "Iextvarience": 0.5,
        "ENa": 50.0,
        "EK": -90.0,
        "El": -65.0,
        "gbarNa": 55.0,
        "gbarK": 8.0,
        "gl": 0.1,
        "fi": 10,
    }

    ext_synapse_params = {
        "Erev": 60.0,
        "gbarS": 0.005,
        "alpha_s": 1.1,
        "beta_s": 0.19,
        "K": 5.0,
        "teta": 2.0,
        "w": 1.0,
        "delay": 0,
    }

    inh_synapse_params = {
        "Erev": -15.0,
        "gbarS": 0.005,
        "alpha_s": 14.0,
        "beta_s": 0.07,
        "K": 2.0,
        "teta": 0.0,
        "w": 1.0,
        "delay": 0,
    }

    HS_neuron_params = {
        "V0": -63.0,
        "Iextmean": 0.5,
        "Iextvarience": 0.0,
        "ENa": 55.0,
        "EK": -90.0,
        "El": -65.0,
        "EH": -40.0,
        "ECa": 120.0,
        "Ca": 0.0,
        "KD": 30.0,
        "gbarNa": 35.0,
        "gbarK": 9.0,
        "gl": 0.1,
        "gbarK_Ca": 10,
        "gbarCa": 1.0,
        "gbarH": 0.15,
        "alpha_Ca": 0.002,
        "tau_Ca": 80,
    }

    ########## set model of septum ################
    # number of neurons
    Nglu = params["Nglu"]
    NgabaCR = params["NgabaCR"]
    NgabaPV1 = params["NgabaPV1"]
    NgabaPV2 = params["NgabaPV2"]
    NgabaPacPV1 = params["NgabaPacPV1"]
    NgabaPacPV2 = params["NgabaPacPV2"]
    NgabaHS = params["NgabaHS"]

    NN = Nglu + NgabaCR + NgabaPV1 + NgabaPV2 + NgabaPacPV1 + NgabaPacPV2

    Sparsness = params["sparsness"]  # sparsness in septal network

    indexes = {
        "glu": [],
        "pv1": [],
        "pv2": [],
        "pv1_pac": [],
        "pv2_pac": [],
        "cr": [],
        "hs": [],
    }

    neurons = []
    for idx in range(Nglu):
        neuron = {"type": "FS_Neuron", "compartments": fs_neuron.copy()}
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0.5  # 0.5*np.random.randn()

        indexes["glu"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(NgabaCR):
        neuron = {"type": "FS_Neuron", "compartments": fs_neuron.copy()}
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0  # 0.1*np.random.randn()
        indexes["cr"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(NgabaPV1):
        neuron = {"type": "FS_Neuron", "compartments": fs_neuron.copy()}
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0.1  #0.5*np.random.randn()
        indexes["pv1"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(NgabaPacPV1):
        neuron = {
            "type": "ClusterNeuron",
            "compartments": cluster_pacemaker.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0.1  # 0.5*np.random.randn()
        indexes["pv1"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(NgabaPV2):
        neuron = {"type": "FS_Neuron", "compartments": fs_neuron.copy()}
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0.7  #0.5*np.random.randn()
        indexes["pv2"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(NgabaPacPV2):
        neuron = {
            "type": "ClusterNeuron",
            "compartments": cluster_pacemaker.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        neuron["compartments"]["Iextmean"] = 0.7  #0.5*np.random.randn()
        indexes["pv2"].append(len(neurons))
        neurons.append(neuron)

    for idx in range(NgabaHS):
        neuron = {
            "type": "HS_projective_neuron",
            "compartments": HS_neuron_params.copy()
        }
        neuron["compartments"]["V0"] += 10 * np.random.rand()
        # neuron["compartments"]["Iextmean"] = 0.7 #0.5*np.random.randn()
        indexes["hs"].append(len(neurons))
        neurons.append(neuron)

    synapses = []
    # synapse from Glu to Glu neurons

    for idx1 in indexes["glu"]:
        for idx2 in indexes["glu"]:
            if (Sparsness < np.random.rand() or idx1 == idx2):
                continue
            pre_ind = idx1
            post_ind = idx2
            synapse = {
                "type": "ComplexSynapse",
                "pre_ind": pre_ind,
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": ext_synapse_params.copy(),
            }
            synapse["params"]["w"] = 1
            synapses.append(synapse)

    # synapses from Glu naurons to GABA(CR) neurons
    for idx1 in indexes["glu"]:
        for idx2 in indexes["cr"]:
            if (Sparsness < np.random.rand() or idx1 == idx2):
                continue
            pre_ind = idx1
            post_ind = idx2
            synapse = {
                "type": "ComplexSynapse",
                "pre_ind": pre_ind,
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": ext_synapse_params.copy(),
            }
            synapse["params"]["w"] = 0.2
            synapses.append(synapse)

    # synapses from GABA(CR) neurons to Glu naurons
    for idx1 in indexes["cr"]:
        for idx2 in indexes["glu"]:
            if (idx1 == idx2):
                continue

            pre_ind = idx1
            post_ind = idx2
            synapse = {
                "type": "ComplexSynapse",
                "pre_ind": pre_ind,
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["w"] = 1.5
            synapses.append(synapse)

    # synapses from Glu neurons to PV1 and pac-PV1 naurons
    for idx1 in indexes["glu"]:
        for idx2 in indexes["pv1"]:
            if (Sparsness < np.random.rand() or idx1 == idx2):
                continue
            pre_ind = idx1
            post_ind = idx2
            synapse = {
                "type": "ComplexSynapse",
                "pre_ind": pre_ind,
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": ext_synapse_params.copy(),
            }
            synapse["params"]["w"] = 1
            synapses.append(synapse)

    # synapses from PV1 and pac-PV1 naurons to PV2 and pac-PV2
    for idx1 in indexes["pv1"]:
        for idx2 in indexes["pv2"]:
            if (Sparsness < np.random.rand() or idx1 == idx2):
                continue
            pre_ind = idx1
            post_ind = idx2
            synapse = {
                "type": "ComplexSynapse",
                "pre_ind": pre_ind,
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["w"] = 0.5
            synapses.append(synapse)

    # synapses from PV2 and pac-PV2 naurons to PV1 and pac-PV1
    for pre_ind in indexes["pv2"]:
        for post_ind in indexes["pv1"]:
            if (Sparsness < np.random.rand() or idx1 == idx2):
                continue
            synapse = {
                "type": "ComplexSynapse",
                "pre_ind": pre_ind,
                "post_ind": post_ind,
                "pre_compartment_name": "soma",
                "post_compartment_name": "soma",
                "params": inh_synapse_params.copy(),
            }
            synapse["params"]["w"] = 0.1
            synapses.append(synapse)

    for s in synapses:
        s["params"]["w"] /= params["sparsness"]

    duration = params["duration"]
    dt = 0.1

    net = lib.Network(neurons, synapses)
    for _ in range(1):
        curent_time = time.time()
        net.integrate(dt, duration)
        print("Calculation time is %0.3f sec" % (time.time() - curent_time))
        net.save_results(path + "all_results")