def create_dpsim_objects(self):
    self.process_mpc()
    dpsimpy_busses_dict = {}
    dpsimpy_comp_dict = {}
    mw_w = 1000000.0
    kv_v = 1000.0
    bus = 0
    load = 0
    generator = 0
    inj = 0
    for (index, bus) in self.mpc_bus_data.iterrows():
        bus = (bus + 1)
        bus_index = str(self.mpc_bus_data.at[(index, 'bus_i')])
        bus_name = bus_index
        dpsimpy_busses_dict[bus_name] = dpsimpy.sp.SimNode(bus_name, dpsimpy.PhaseType.Single)
        bus_type = self.mpc_bus_data.at[(index, 'type')]
        if (bus_type == 1):
            load = (load + 1)
            load_name = ('load%s' % load)
            load_p = (self.mpc_bus_data.at[(index, 'Pd')] * mw_w)
            load_q = (self.mpc_bus_data.at[(index, 'Qd')] * mw_w)
            load_baseV = (self.mpc_bus_data.at[(index, 'baseKV')] * kv_v)
            dpsimpy_comp_dict[load_name] = [dpsimpy.sp.ph1.Load(load_name, dpsimpy.LogLevel.info)]
            dpsimpy_comp_dict[load_name][0].set_parameters(load_p, load_q, load_baseV)
            dpsimpy_comp_dict[load_name][0].modify_power_flow_bus_type(dpsimpy.PowerflowBusType.PQ)
            dpsimpy_comp_dict[load_name].append([dpsimpy_busses_dict[bus_index]])
        elif (bus_type == 2):
            generator = (generator + 1)
            gen_name = ('gen%s' % generator)
            gen = self.mpc_gen_data.loc[(self.mpc_gen_data['bus'] == self.mpc_bus_data.at[(index, 'bus_i')])]
            gen_baseS = (gen['mBase'] * mw_w)
            gen_baseV = (self.mpc_bus_data.at[(index, 'baseKV')] * kv_v)
            gen_v = (gen['Vg'] * gen_baseV)
            gen_p = (gen['Pg'] * mw_w)
            gen_nom_s = abs(complex(gen['Pmax'], gen['Qmax']))
            dpsimpy_comp_dict[gen_name] = [dpsimpy.sp.ph1.SynchronGenerator(gen_name, dpsimpy.LogLevel.info)]
            dpsimpy_comp_dict[gen_name][0].set_parameters(gen_nom_s, gen_baseV, gen_p, gen_v, dpsimpy.PowerflowBusType.PV)
            dpsimpy_comp_dict[gen_name][0].set_base_voltage(gen_baseV)
            dpsimpy_comp_dict[gen_name].append([dpsimpy_busses_dict[bus_index]])
        elif (bus_type == 3):
            inj = (inj + 1)
            extnet_name = ('extnet%s' % inj)
            extnet = self.mpc_gen_data.loc[(self.mpc_gen_data['bus'] == self.mpc_bus_data.at[(index, 'bus_i')])]
            extnet_baseV = (self.mpc_bus_data.at[(index, 'baseKV')] * kv_v)
            extnet_v = (extnet['Vg'] * extnet_baseV)
            dpsimpy_comp_dict[extnet_name] = [dpsimpy.sp.ph1.NetworkInjection(extnet_name, dpsimpy.LogLevel.info)]
            dpsimpy_comp_dict[extnet_name][0].set_parameters(extnet_v)
            dpsimpy_comp_dict[extnet_name][0].set_base_voltage(extnet_baseV)
            dpsimpy_comp_dict[extnet_name][0].modify_power_flow_bus_type(dpsimpy.PowerflowBusType.VD)
            dpsimpy_comp_dict[extnet_name].append([dpsimpy_busses_dict[bus_index]])
        elif (bus_type == 4):
            print('isolated bus type')
        else:
            print('bus type error')
    line = 0
    trafo = 0
    for (index, branch) in self.mpc_branch_data.iterrows():
        branch_ratio = self.mpc_branch_data.at[(index, 'ratio')]
        if (branch_ratio == 0):
            line = (line + 1)
            line_name = ('line%s_%s-%s' % (line, self.mpc_branch_data.at[(index, 'fbus')], self.mpc_branch_data.at[(index, 'tbus')]))
            line_fbus = self.mpc_branch_data.at[(index, 'fbus')]
            line_tbus = self.mpc_branch_data.at[(index, 'tbus')]
            tmp_fbus = self.mpc_bus_data.loc[(self.mpc_bus_data['bus_i'] == line_fbus)]
            tmp_tbus = self.mpc_bus_data.loc[(self.mpc_bus_data['bus_i'] == line_tbus)]
            line_fbus_baseV = (self.mpc_bus_data.at[(tmp_fbus.first_valid_index(), 'baseKV')] * kv_v)
            line_tbus_baseV = (self.mpc_bus_data.at[(tmp_tbus.first_valid_index(), 'baseKV')] * kv_v)
            line_baseZ = ((line_tbus_baseV * line_tbus_baseV) / (self.mpc_base_power_MVA * mw_w))
            line_r = (self.mpc_branch_data.at[(index, 'r')] * line_baseZ)
            line_x = (self.mpc_branch_data.at[(index, 'x')] * line_baseZ)
            line_b = (self.mpc_branch_data.at[(index, 'b')] / line_baseZ)
            line_l = (line_x / self.mpc_omega)
            line_c = (line_b / self.mpc_omega)
            line_g = 0
            dpsimpy_comp_dict[line_name] = [dpsimpy.sp.ph1.PiLine(line_name, dpsimpy.LogLevel.info)]
            dpsimpy_comp_dict[line_name][0].set_parameters(line_r, line_l, line_c, line_g)
            dpsimpy_comp_dict[line_name][0].set_base_voltage(line_tbus_baseV)
            dpsimpy_comp_dict[line_name].append([dpsimpy_busses_dict[str(line_fbus)], dpsimpy_busses_dict[str(line_tbus)]])
        else:
            trafo = (trafo + 1)
            transf_name = ('transformer%s_%s-%s' % (trafo, self.mpc_branch_data.at[(index, 'fbus')], self.mpc_branch_data.at[(index, 'tbus')]))
            transf_s = (self.mpc_branch_data.at[(index, 'rateA')] * mw_w)
            transf_fbus = self.mpc_branch_data.at[(index, 'fbus')]
            transf_tbus = self.mpc_branch_data.at[(index, 'tbus')]
            tmp_fbus = self.mpc_bus_data.loc[(self.mpc_bus_data['bus_i'] == transf_fbus)]
            tmp_tbus = self.mpc_bus_data.loc[(self.mpc_bus_data['bus_i'] == transf_tbus)]
            transf_fbus_baseV = (self.mpc_bus_data.at[(tmp_fbus.first_valid_index(), 'baseKV')] * kv_v)
            transf_tbus_baseV = (self.mpc_bus_data.at[(tmp_tbus.first_valid_index(), 'baseKV')] * kv_v)
            transf_primary_v = (self.mpc_bus_data.at[(tmp_fbus.first_valid_index(), 'Vm')] * transf_fbus_baseV)
            transf_secondary_v = (self.mpc_bus_data.at[(tmp_tbus.first_valid_index(), 'Vm')] * transf_tbus_baseV)
            transf_offNom_ratio = self.mpc_branch_data.at[(index, 'ratio')]
            transf_primary_v = (transf_primary_v / transf_offNom_ratio)
            transf_ratio = (transf_primary_v / transf_secondary_v)
            transf_baseZ = ((transf_tbus_baseV * transf_tbus_baseV) / (self.mpc_base_power_MVA * mw_w))
            transf_r = (self.mpc_branch_data.at[(index, 'r')] * transf_baseZ)
            transf_x = (self.mpc_branch_data.at[(index, 'x')] * transf_baseZ)
            transf_l = (transf_x / self.mpc_omega)
            dpsimpy_comp_dict[transf_name] = [dpsimpy.sp.ph1.Transformer(transf_name, dpsimpy.LogLevel.info)]
            dpsimpy_comp_dict[transf_name][0].set_parameters(transf_primary_v, transf_secondary_v, np.abs(transf_ratio), np.angle(transf_ratio), transf_r, transf_l)
            dpsimpy_comp_dict[transf_name][0].set_base_voltage(transf_tbus_baseV)
            print(transf_primary_v, transf_secondary_v, np.abs(transf_ratio), np.angle(transf_ratio), transf_r, transf_l)
            print(transf_tbus_baseV)
            dpsimpy_comp_dict[transf_name].append([dpsimpy_busses_dict[str(transf_fbus)], dpsimpy_busses_dict[str(transf_tbus)]])
    return (dpsimpy_busses_dict, dpsimpy_comp_dict)
def create_dpsim_objects(self):
    self.process_mpc()
    dpsimpy_busses_dict = {}
    dpsimpy_comp_dict = {}
    mw_w = 1000000.0
    kv_v = 1000.0
    bus = 0
    load = 0
    generator = 0
    inj = 0
    for (index, bus) in self.mpc_bus_data.iterrows():
        bus = (bus + 1)
        bus_index = str(self.mpc_bus_data.at[(index, 'bus_i')])
        bus_name = bus_index
        dpsimpy_busses_dict[bus_name] = dpsimpy.sp.SimNode(bus_name, dpsimpy.PhaseType.Single)
        bus_type = self.mpc_bus_data.at[(index, 'type')]
        if (bus_type == 1):
            load = (load + 1)
            load_name = ('load%s' % load)
            load_p = (self.mpc_bus_data.at[(index, 'Pd')] * mw_w)
            load_q = (self.mpc_bus_data.at[(index, 'Qd')] * mw_w)
            load_baseV = (self.mpc_bus_data.at[(index, 'baseKV')] * kv_v)
            dpsimpy_comp_dict[load_name] = [dpsimpy.sp.ph1.Load(load_name, dpsimpy.LogLevel.info)]
            dpsimpy_comp_dict[load_name][0].set_parameters(load_p, load_q, load_baseV)
            dpsimpy_comp_dict[load_name][0].modify_power_flow_bus_type(dpsimpy.PowerflowBusType.PQ)
            dpsimpy_comp_dict[load_name].append([dpsimpy_busses_dict[bus_index]])
        elif (bus_type == 2):
            generator = (generator + 1)
            gen_name = ('gen%s' % generator)
            gen = self.mpc_gen_data.loc[(self.mpc_gen_data['bus'] == self.mpc_bus_data.at[(index, 'bus_i')])]
            gen_baseS = (gen['mBase'] * mw_w)
            gen_baseV = (self.mpc_bus_data.at[(index, 'baseKV')] * kv_v)
            gen_v = (gen['Vg'] * gen_baseV)
            gen_p = (gen['Pg'] * mw_w)
            gen_nom_s = abs(complex(gen['Pmax'], gen['Qmax']))
            dpsimpy_comp_dict[gen_name] = [dpsimpy.sp.ph1.SynchronGenerator(gen_name, dpsimpy.LogLevel.info)]
            dpsimpy_comp_dict[gen_name][0].set_parameters(gen_nom_s, gen_baseV, gen_p, gen_v, dpsimpy.PowerflowBusType.PV)
            dpsimpy_comp_dict[gen_name][0].set_base_voltage(gen_baseV)
            dpsimpy_comp_dict[gen_name].append([dpsimpy_busses_dict[bus_index]])
        elif (bus_type == 3):
            inj = (inj + 1)
            extnet_name = ('extnet%s' % inj)
            extnet = self.mpc_gen_data.loc[(self.mpc_gen_data['bus'] == self.mpc_bus_data.at[(index, 'bus_i')])]
            extnet_baseV = (self.mpc_bus_data.at[(index, 'baseKV')] * kv_v)
            extnet_v = (extnet['Vg'] * extnet_baseV)
            dpsimpy_comp_dict[extnet_name] = [dpsimpy.sp.ph1.NetworkInjection(extnet_name, dpsimpy.LogLevel.info)]
            dpsimpy_comp_dict[extnet_name][0].set_parameters(extnet_v)
            dpsimpy_comp_dict[extnet_name][0].set_base_voltage(extnet_baseV)
            dpsimpy_comp_dict[extnet_name][0].modify_power_flow_bus_type(dpsimpy.PowerflowBusType.VD)
            dpsimpy_comp_dict[extnet_name].append([dpsimpy_busses_dict[bus_index]])
        elif (bus_type == 4):
            print('isolated bus type')
        else:
            print('bus type error')
    line = 0
    trafo = 0
    for (index, branch) in self.mpc_branch_data.iterrows():
        branch_ratio = self.mpc_branch_data.at[(index, 'ratio')]
        if (branch_ratio == 0):
            line = (line + 1)
            line_name = ('line%s_%s-%s' % (line, self.mpc_branch_data.at[(index, 'fbus')], self.mpc_branch_data.at[(index, 'tbus')]))
            line_fbus = self.mpc_branch_data.at[(index, 'fbus')]
            line_tbus = self.mpc_branch_data.at[(index, 'tbus')]
            tmp_fbus = self.mpc_bus_data.loc[(self.mpc_bus_data['bus_i'] == line_fbus)]
            tmp_tbus = self.mpc_bus_data.loc[(self.mpc_bus_data['bus_i'] == line_tbus)]
            line_fbus_baseV = (self.mpc_bus_data.at[(tmp_fbus.first_valid_index(), 'baseKV')] * kv_v)
            line_tbus_baseV = (self.mpc_bus_data.at[(tmp_tbus.first_valid_index(), 'baseKV')] * kv_v)
            line_baseZ = ((line_tbus_baseV * line_tbus_baseV) / (self.mpc_base_power_MVA * mw_w))
            line_r = (self.mpc_branch_data.at[(index, 'r')] * line_baseZ)
            line_x = (self.mpc_branch_data.at[(index, 'x')] * line_baseZ)
            line_b = (self.mpc_branch_data.at[(index, 'b')] / line_baseZ)
            line_l = (line_x / self.mpc_omega)
            line_c = (line_b / self.mpc_omega)
            line_g = 0
            dpsimpy_comp_dict[line_name] = [dpsimpy.sp.ph1.PiLine(line_name, dpsimpy.LogLevel.info)]
            dpsimpy_comp_dict[line_name][0].set_parameters(line_r, line_l, line_c, line_g)
            dpsimpy_comp_dict[line_name][0].set_base_voltage(line_tbus_baseV)
            dpsimpy_comp_dict[line_name].append([dpsimpy_busses_dict[str(line_fbus)], dpsimpy_busses_dict[str(line_tbus)]])
        else:
            trafo = (trafo + 1)
            transf_name = ('transformer%s_%s-%s' % (trafo, self.mpc_branch_data.at[(index, 'fbus')], self.mpc_branch_data.at[(index, 'tbus')]))
            transf_s = (self.mpc_branch_data.at[(index, 'rateA')] * mw_w)
            transf_fbus = self.mpc_branch_data.at[(index, 'fbus')]
            transf_tbus = self.mpc_branch_data.at[(index, 'tbus')]
            tmp_fbus = self.mpc_bus_data.loc[(self.mpc_bus_data['bus_i'] == transf_fbus)]
            tmp_tbus = self.mpc_bus_data.loc[(self.mpc_bus_data['bus_i'] == transf_tbus)]
            transf_fbus_baseV = (self.mpc_bus_data.at[(tmp_fbus.first_valid_index(), 'baseKV')] * kv_v)
            transf_tbus_baseV = (self.mpc_bus_data.at[(tmp_tbus.first_valid_index(), 'baseKV')] * kv_v)
            transf_primary_v = (self.mpc_bus_data.at[(tmp_fbus.first_valid_index(), 'Vm')] * transf_fbus_baseV)
            transf_secondary_v = (self.mpc_bus_data.at[(tmp_tbus.first_valid_index(), 'Vm')] * transf_tbus_baseV)
            transf_offNom_ratio = self.mpc_branch_data.at[(index, 'ratio')]
            transf_primary_v = (transf_primary_v / transf_offNom_ratio)
            transf_ratio = (transf_primary_v / transf_secondary_v)
            transf_baseZ = ((transf_tbus_baseV * transf_tbus_baseV) / (self.mpc_base_power_MVA * mw_w))
            transf_r = (self.mpc_branch_data.at[(index, 'r')] * transf_baseZ)
            transf_x = (self.mpc_branch_data.at[(index, 'x')] * transf_baseZ)
            transf_l = (transf_x / self.mpc_omega)
            dpsimpy_comp_dict[transf_name] = [dpsimpy.sp.ph1.Transformer(transf_name, dpsimpy.LogLevel.info)]
            dpsimpy_comp_dict[transf_name][0].set_parameters(transf_primary_v, transf_secondary_v, np.abs(transf_ratio), np.angle(transf_ratio), transf_r, transf_l)
            dpsimpy_comp_dict[transf_name][0].set_base_voltage(transf_tbus_baseV)
            print(transf_primary_v, transf_secondary_v, np.abs(transf_ratio), np.angle(transf_ratio), transf_r, transf_l)
            print(transf_tbus_baseV)
            dpsimpy_comp_dict[transf_name].append([dpsimpy_busses_dict[str(transf_fbus)], dpsimpy_busses_dict[str(transf_tbus)]])
    return (dpsimpy_busses_dict, dpsimpy_comp_dict)