BioSIMI-Python/modules/Subsystem.py
def simulateVariableInputs(self, ListOfInputs, ListOfListOfAmounts, ListOfSpeciesToPlot, timepoints, mode = 'continue', xlabel = 'Time', ylabel = 'Concentration (AU)', sizeOfXLabels = 14, sizeOfYLabels = 14):
        ''''
        Simulates the Subsystem model with the input species amounts varying 
        Uses bioscrape to simulate and plots the result
        '''
        mpl.rc('axes', prop_cycle=(mpl.cycler('color', ['r', 'k', 'b','g','y','m','c']) ))
        model = self.getSubsystemDoc().getModel()
        simpleModel = SimpleModel(model)
        species_list = []
        final_result = {}
        total_time = {}
        SpeciesToPlot = ListOfSpeciesToPlot[:]
        for species_name in ListOfSpeciesToPlot:
            species = simpleModel.getSpeciesByName(species_name)
            if type(species) is list:
                print('BioSIMI-Python WARNING -- There are multiple species with the name ' + species_name + 'Suffixed species will be plotted ')
                for species_i in species:
                    species_list.append(species_i.getId())
                    final_result[species_i.getId()] = []
                    total_time[species_i.getId()] = []
                key_ind = ListOfSpeciesToPlot.index(species_name)
                insert_new = []
                for j in range(len(species)-1):
                    insert_new.append(species_name + str(j+1))
                SpeciesToPlot[key_ind+1:key_ind+1] = insert_new 
            else:
                species_list.append(species.getId())
                final_result[species.getId()] = []
                total_time[species.getId()] = []
        initialTime = timepoints[0]
        t_end = timepoints[-1]
        points = len(timepoints)
        if (len(ListOfInputs) == 1) or (type(ListOfInputs) is str):
            t = initialTime
            if type(ListOfInputs) is list:
                input = ListOfInputs[0]
            elif type(ListOfInputs) is str:
                input = ListOfInputs
            else:
                print('BioSIMI-Python ERROR -- The input species argument should either be a list or a string')
                return

            species_inp = simpleModel.getSpeciesByName(input)
            if type(species_inp) is list:
                print('BioSIMI-Python ERROR -- Multiple input species found in the model for the input name given.')
                return 
            for amount in ListOfListOfAmounts:
                if type(amount) is list:
                    print('BioSIMI-Python ERROR -- For single input, the amounts should not be a list of list type')
                    return
            for j in range(len(ListOfListOfAmounts)):
                # Start simulating and create data
                amount = ListOfListOfAmounts[j]
                check(species_inp.setInitialAmount(amount), 'setting initial amount to input species')
                time = np.linspace(t,t+t_end,points)
                data, m = self.simulateSbmlWithBioscrape(t, time)
                for species_id in species_list:
                    sp_data = data[:,m.get_species_index(species_id)]
                    t = time[-1]
                    final_result[species_id].extend(sp_data)
                    total_time[species_id].extend(time)
                if mode == 'continue':
                    for species in model.getListOfSpecies():
                        species.setInitialAmount(data[:,m.get_species_index(species.getId())][-1])




        else:
            t = initialTime
            ListOfSpecies = []
            for i in range(len(ListOfInputs)):
                input = ListOfInputs[i]
                species_inp = simpleModel.getSpeciesByName(input)
                if type(species_inp) is list:
                    print('BioSIMI-Python ERROR -- Multiple input species found in the model.')
                    return 
                ListOfSpecies.append(species_inp)
            for i in range(len(ListOfListOfAmounts)):
                if (type(ListOfListOfAmounts[i]) is not list) or (len(ListOfListOfAmounts[i]) != len(ListOfInputs)) :
                    print('BioSIMI-Python ERROR -- For multiple inputs, all items of ListOfListOfAmounts attribute should be lists of length same as the number of inputs')
                    return
            for j in range(len(ListOfListOfAmounts)):
                for amount, species in zip(ListOfListOfAmounts[j], ListOfSpecies):
                # Start simulating and create data
                    check(species.setInitialAmount(amount), 'setting initial amount to input species')
                time = np.linspace(t,t+t_end,points)
                data, m = self.simulateSbmlWithBioscrape(t, time)
                for species_id in species_list:
                    sp_data = data[:,m.get_species_index(species_id)]
                    t = time[-1]
                    final_result[species_id].extend(sp_data)
                    total_time[species_id].extend(time)

                if mode == 'continue':
                    for species in model.getListOfSpecies():
                        species.setInitialAmount(data[:,m.get_species_index(species.getId())][-1])

        for species_id in species_list:
            plt.plot(total_time[species_id], final_result[species_id])

        plt.legend(SpeciesToPlot)
        mpl.rc('xtick', labelsize= sizeOfXLabels) 
        mpl.rc('ytick', labelsize=sizeOfYLabels)
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
        plt.show()
        return final_result, total_time

        Simulates the Subsystem model with the input species amounts varying 
        Uses bioscrape to simulate and plots the result
        
Simulates the Subsystem model with the input species amounts varying
Uses bioscrape to simulate and plots the result
Simulates the Subsystem model with the input species amounts varying Uses bioscrape to simulate and plots the result
def simulateVariableInputs(self, ListOfInputs, ListOfListOfAmounts, ListOfSpeciesToPlot, timepoints, mode = 'continue', xlabel = 'Time', ylabel = 'Concentration (AU)', sizeOfXLabels = 14, sizeOfYLabels = 14):
        mpl.rc('axes', prop_cycle=(mpl.cycler('color', ['r', 'k', 'b','g','y','m','c']) ))
        model = self.getSubsystemDoc().getModel()
        simpleModel = SimpleModel(model)
        species_list = []
        final_result = {}
        total_time = {}
        SpeciesToPlot = ListOfSpeciesToPlot[:]
        for species_name in ListOfSpeciesToPlot:
            species = simpleModel.getSpeciesByName(species_name)
            if type(species) is list:
                print('BioSIMI-Python WARNING -- There are multiple species with the name ' + species_name + 'Suffixed species will be plotted ')
                for species_i in species:
                    species_list.append(species_i.getId())
                    final_result[species_i.getId()] = []
                    total_time[species_i.getId()] = []
                key_ind = ListOfSpeciesToPlot.index(species_name)
                insert_new = []
                for j in range(len(species)-1):
                    insert_new.append(species_name + str(j+1))
                SpeciesToPlot[key_ind+1:key_ind+1] = insert_new 
            else:
                species_list.append(species.getId())
                final_result[species.getId()] = []
                total_time[species.getId()] = []
        initialTime = timepoints[0]
        t_end = timepoints[-1]
        points = len(timepoints)
        if (len(ListOfInputs) == 1) or (type(ListOfInputs) is str):
            t = initialTime
            if type(ListOfInputs) is list:
                input = ListOfInputs[0]
            elif type(ListOfInputs) is str:
                input = ListOfInputs
            else:
                print('BioSIMI-Python ERROR -- The input species argument should either be a list or a string')
                return
            species_inp = simpleModel.getSpeciesByName(input)
            if type(species_inp) is list:
                print('BioSIMI-Python ERROR -- Multiple input species found in the model for the input name given.')
                return 
            for amount in ListOfListOfAmounts:
                if type(amount) is list:
                    print('BioSIMI-Python ERROR -- For single input, the amounts should not be a list of list type')
                    return
            for j in range(len(ListOfListOfAmounts)):
                amount = ListOfListOfAmounts[j]
                check(species_inp.setInitialAmount(amount), 'setting initial amount to input species')
                time = np.linspace(t,t+t_end,points)
                data, m = self.simulateSbmlWithBioscrape(t, time)
                for species_id in species_list:
                    sp_data = data[:,m.get_species_index(species_id)]
                    t = time[-1]
                    final_result[species_id].extend(sp_data)
                    total_time[species_id].extend(time)
                if mode == 'continue':
                    for species in model.getListOfSpecies():
                        species.setInitialAmount(data[:,m.get_species_index(species.getId())][-1])
        else:
            t = initialTime
            ListOfSpecies = []
            for i in range(len(ListOfInputs)):
                input = ListOfInputs[i]
                species_inp = simpleModel.getSpeciesByName(input)
                if type(species_inp) is list:
                    print('BioSIMI-Python ERROR -- Multiple input species found in the model.')
                    return 
                ListOfSpecies.append(species_inp)
            for i in range(len(ListOfListOfAmounts)):
                if (type(ListOfListOfAmounts[i]) is not list) or (len(ListOfListOfAmounts[i]) != len(ListOfInputs)) :
                    print('BioSIMI-Python ERROR -- For multiple inputs, all items of ListOfListOfAmounts attribute should be lists of length same as the number of inputs')
                    return
            for j in range(len(ListOfListOfAmounts)):
                for amount, species in zip(ListOfListOfAmounts[j], ListOfSpecies):
                    check(species.setInitialAmount(amount), 'setting initial amount to input species')
                time = np.linspace(t,t+t_end,points)
                data, m = self.simulateSbmlWithBioscrape(t, time)
                for species_id in species_list:
                    sp_data = data[:,m.get_species_index(species_id)]
                    t = time[-1]
                    final_result[species_id].extend(sp_data)
                    total_time[species_id].extend(time)
                if mode == 'continue':
                    for species in model.getListOfSpecies():
                        species.setInitialAmount(data[:,m.get_species_index(species.getId())][-1])
        for species_id in species_list:
            plt.plot(total_time[species_id], final_result[species_id])
        plt.legend(SpeciesToPlot)
        mpl.rc('xtick', labelsize= sizeOfXLabels) 
        mpl.rc('ytick', labelsize=sizeOfYLabels)
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
        plt.show()
        return final_result, total_time
def simulateVariableInputs ( self , ListOfInputs , ListOfListOfAmounts , ListOfSpeciesToPlot , timepoints , mode = 'continue' , xlabel = 'Time' , ylabel = 'Concentration (AU)' , sizeOfXLabels = 14 , sizeOfYLabels = 14 ) : mpl . rc ( 'axes' , prop_cycle = ( mpl . cycler ( 'color' , [ 'r' , 'k' , 'b' , 'g' , 'y' , 'm' , 'c' ] ) ) ) model = self . getSubsystemDoc ( ) . getModel ( ) simpleModel = SimpleModel ( model ) species_list = [ ] final_result = { } total_time = { } SpeciesToPlot = ListOfSpeciesToPlot [ : ] for species_name in ListOfSpeciesToPlot : species = simpleModel . getSpeciesByName ( species_name ) if type ( species ) is list : print ( 'BioSIMI-Python WARNING -- There are multiple species with the name ' + species_name + 'Suffixed species will be plotted ' ) for species_i in species : species_list . append ( species_i . getId ( ) ) final_result [ species_i . getId ( ) ] = [ ] total_time [ species_i . getId ( ) ] = [ ] key_ind = ListOfSpeciesToPlot . index ( species_name ) insert_new = [ ] for j in range ( len ( species ) - 1 ) : insert_new . append ( species_name + str ( j + 1 ) ) SpeciesToPlot [ key_ind + 1 : key_ind + 1 ] = insert_new else : species_list . append ( species . getId ( ) ) final_result [ species . getId ( ) ] = [ ] total_time [ species . getId ( ) ] = [ ] initialTime = timepoints [ 0 ] t_end = timepoints [ - 1 ] points = len ( timepoints ) if ( len ( ListOfInputs ) == 1 ) or ( type ( ListOfInputs ) is str ) : t = initialTime if type ( ListOfInputs ) is list : input = ListOfInputs [ 0 ] elif type ( ListOfInputs ) is str : input = ListOfInputs else : print ( 'BioSIMI-Python ERROR -- The input species argument should either be a list or a string' ) return species_inp = simpleModel . getSpeciesByName ( input ) if type ( species_inp ) is list : print ( 'BioSIMI-Python ERROR -- Multiple input species found in the model for the input name given.' ) return for amount in ListOfListOfAmounts : if type ( amount ) is list : print ( 'BioSIMI-Python ERROR -- For single input, the amounts should not be a list of list type' ) return for j in range ( len ( ListOfListOfAmounts ) ) : amount = ListOfListOfAmounts [ j ] check ( species_inp . setInitialAmount ( amount ) , 'setting initial amount to input species' ) time = np . linspace ( t , t + t_end , points ) data , m = self . simulateSbmlWithBioscrape ( t , time ) for species_id in species_list : sp_data = data [ : , m . get_species_index ( species_id ) ] t = time [ - 1 ] final_result [ species_id ] . extend ( sp_data ) total_time [ species_id ] . extend ( time ) if mode == 'continue' : for species in model . getListOfSpecies ( ) : species . setInitialAmount ( data [ : , m . get_species_index ( species . getId ( ) ) ] [ - 1 ] ) else : t = initialTime ListOfSpecies = [ ] for i in range ( len ( ListOfInputs ) ) : input = ListOfInputs [ i ] species_inp = simpleModel . getSpeciesByName ( input ) if type ( species_inp ) is list : print ( 'BioSIMI-Python ERROR -- Multiple input species found in the model.' ) return ListOfSpecies . append ( species_inp ) for i in range ( len ( ListOfListOfAmounts ) ) : if ( type ( ListOfListOfAmounts [ i ] ) is not list ) or ( len ( ListOfListOfAmounts [ i ] ) != len ( ListOfInputs ) ) : print ( 'BioSIMI-Python ERROR -- For multiple inputs, all items of ListOfListOfAmounts attribute should be lists of length same as the number of inputs' ) return for j in range ( len ( ListOfListOfAmounts ) ) : for amount , species in zip ( ListOfListOfAmounts [ j ] , ListOfSpecies ) : check ( species . setInitialAmount ( amount ) , 'setting initial amount to input species' ) time = np . linspace ( t , t + t_end , points ) data , m = self . simulateSbmlWithBioscrape ( t , time ) for species_id in species_list : sp_data = data [ : , m . get_species_index ( species_id ) ] t = time [ - 1 ] final_result [ species_id ] . extend ( sp_data ) total_time [ species_id ] . extend ( time ) if mode == 'continue' : for species in model . getListOfSpecies ( ) : species . setInitialAmount ( data [ : , m . get_species_index ( species . getId ( ) ) ] [ - 1 ] ) for species_id in species_list : plt . plot ( total_time [ species_id ] , final_result [ species_id ] ) plt . legend ( SpeciesToPlot ) mpl . rc ( 'xtick' , labelsize = sizeOfXLabels ) mpl . rc ( 'ytick' , labelsize = sizeOfYLabels ) plt . xlabel ( xlabel ) plt . ylabel ( ylabel ) plt . show ( ) return final_result , total_time
Simulates the Subsystem model with the input species amounts varying
Uses bioscrape to simulate and plots the result
Simulates the Subsystem model with the input species amounts varying Uses bioscrape to simulate and plots the result
''''
        Simulates the Subsystem model with the input species amounts varying 
        Uses bioscrape to simulate and plots the result
        ''' # Start simulating and create data # Start simulating and create data
self
ListOfInputs
ListOfListOfAmounts
ListOfSpeciesToPlot
timepoints
mode
xlabel
ylabel
sizeOfXLabels
sizeOfYLabels