BioSIMI-Python/modules/Subsystem.py
def connectSubsystems(self, ListOfSubsystems, connectionLogic, mode = 'volume', combineNames = False, inputSpecies = None):
        '''
        The ListOfSubsystems are combined together as in combineSubsystems 
        method (depending on combineNames). Additionally, species interaction specified 
        In the connectionLogic is modeled for the concerned Species. The inputSpecies is 
        An optional argument that may be used to specify a list of Species which are desired
        inactive in the connected Subsystem
        '''
        self.combineSubsystems(ListOfSubsystems, combineNames, mode)
        model = self.getSubsystemDoc().getModel()
        check(model,'retreiving self model in connectSubsystem')
        # The connection logic given by user species two or more different species
        # but that are bound to each other.
        # Set the initial amount of the input in the output subsystem to zero since it's not
        # isolated anymore.
        model_obj = SimpleModel(model)
        if inputSpecies:
            if type(inputSpecies) is list:
                for inp_sp in inputSpecies:
                    check(model_obj.getSpeciesByName(inp_sp).setInitialAmount(0.0),'setting initial amount to 0 in connectSubsystem')
            else:
                check(model_obj.getSpeciesByName(inputSpecies).setInitialAmount(0.0),'setting initial amount to 0 in connectSubsystem')
        for species_name in connectionLogic.keys():
            # Get the ids of the concerned species from the
            # connection logic given by the user
            x = model_obj.getSpeciesByName(species_name)
            y = model_obj.getSpeciesByName(connectionLogic[species_name])
            if type(x) is list or type(y) is list:
                print('Error : Multiple species exist in the model which have the same name to what is given in the connection map. Make sure that connecting species are unique. Use the renameSName function to rename the species before trying to connect')
                return

            if x.getCompartment() == y.getCompartment():
                s = sum([x.getInitialAmount(), y.getInitialAmount()])
                # x and y should also have the same id so that they go into reactions as one.
                # Also, set the initial amount of the species to be equal to the
                # sum of their individual amounts
                check(x.setInitialAmount(s),'setting initial amount of x in connectSubsystem')
                check(y.setInitialAmount(s),'setting initial amount of y in connectSubsystem')
                # Rename ID of x by that of y
                oldid_x = x.getId()
                oldid_y = y.getId()
                check(oldid_x,'retreiving oldid of x in connectSubsystem')
                check(oldid_y,'retreiving oldid of x in connectSubsystem')
                newid = x.getId() +'_with_' +  y.getId()
                check(newid,'retreiving newid of y in connectSubsystem')
                self.renameSId(oldid_x, newid)
                self.renameSId(oldid_y, newid)
                # Remove x from species in the model to avoid duplication
                sp_remove = model_obj.getSpeciesByName(x.getName())
                if type(sp_remove) is list:
                    print('BioSIMI-Python WARNING -- Multiple species exist in the model with the same name as given in connection logic. Ensure that connection logic deals with unique species. Simulation may lead to wrong result in this case')
                    return
                else:
                    id_to_remove = sp_remove.getId()
                    model.removeSpecies(id_to_remove)

        The ListOfSubsystems are combined together as in combineSubsystems 
        method (depending on combineNames). Additionally, species interaction specified 
        In the connectionLogic is modeled for the concerned Species. The inputSpecies is 
        An optional argument that may be used to specify a list of Species which are desired
        inactive in the connected Subsystem
        
The ListOfSubsystems are combined together as in combineSubsystems
method (depending on combineNames). Additionally, species interaction specified
In the connectionLogic is modeled for the concerned Species. The inputSpecies is
An optional argument that may be used to specify a list of Species which are desired
inactive in the connected Subsystem
The ListOfSubsystems are combined together as in combineSubsystems method ( depending on combineNames ) . Additionally species interaction specified In the connectionLogic is modeled for the concerned Species . The inputSpecies is An optional argument that may be used to specify a list of Species which are desired inactive in the connected Subsystem
def connectSubsystems(self, ListOfSubsystems, connectionLogic, mode = 'volume', combineNames = False, inputSpecies = None):
        self.combineSubsystems(ListOfSubsystems, combineNames, mode)
        model = self.getSubsystemDoc().getModel()
        check(model,'retreiving self model in connectSubsystem')
        model_obj = SimpleModel(model)
        if inputSpecies:
            if type(inputSpecies) is list:
                for inp_sp in inputSpecies:
                    check(model_obj.getSpeciesByName(inp_sp).setInitialAmount(0.0),'setting initial amount to 0 in connectSubsystem')
            else:
                check(model_obj.getSpeciesByName(inputSpecies).setInitialAmount(0.0),'setting initial amount to 0 in connectSubsystem')
        for species_name in connectionLogic.keys():
            x = model_obj.getSpeciesByName(species_name)
            y = model_obj.getSpeciesByName(connectionLogic[species_name])
            if type(x) is list or type(y) is list:
                print('Error : Multiple species exist in the model which have the same name to what is given in the connection map. Make sure that connecting species are unique. Use the renameSName function to rename the species before trying to connect')
                return
            if x.getCompartment() == y.getCompartment():
                s = sum([x.getInitialAmount(), y.getInitialAmount()])
                check(x.setInitialAmount(s),'setting initial amount of x in connectSubsystem')
                check(y.setInitialAmount(s),'setting initial amount of y in connectSubsystem')
                oldid_x = x.getId()
                oldid_y = y.getId()
                check(oldid_x,'retreiving oldid of x in connectSubsystem')
                check(oldid_y,'retreiving oldid of x in connectSubsystem')
                newid = x.getId() +'_with_' +  y.getId()
                check(newid,'retreiving newid of y in connectSubsystem')
                self.renameSId(oldid_x, newid)
                self.renameSId(oldid_y, newid)
                sp_remove = model_obj.getSpeciesByName(x.getName())
                if type(sp_remove) is list:
                    print('BioSIMI-Python WARNING -- Multiple species exist in the model with the same name as given in connection logic. Ensure that connection logic deals with unique species. Simulation may lead to wrong result in this case')
                    return
                else:
                    id_to_remove = sp_remove.getId()
                    model.removeSpecies(id_to_remove)
def connectSubsystems ( self , ListOfSubsystems , connectionLogic , mode = 'volume' , combineNames = False , inputSpecies = None ) : self . combineSubsystems ( ListOfSubsystems , combineNames , mode ) model = self . getSubsystemDoc ( ) . getModel ( ) check ( model , 'retreiving self model in connectSubsystem' ) model_obj = SimpleModel ( model ) if inputSpecies : if type ( inputSpecies ) is list : for inp_sp in inputSpecies : check ( model_obj . getSpeciesByName ( inp_sp ) . setInitialAmount ( 0.0 ) , 'setting initial amount to 0 in connectSubsystem' ) else : check ( model_obj . getSpeciesByName ( inputSpecies ) . setInitialAmount ( 0.0 ) , 'setting initial amount to 0 in connectSubsystem' ) for species_name in connectionLogic . keys ( ) : x = model_obj . getSpeciesByName ( species_name ) y = model_obj . getSpeciesByName ( connectionLogic [ species_name ] ) if type ( x ) is list or type ( y ) is list : print ( 'Error : Multiple species exist in the model which have the same name to what is given in the connection map. Make sure that connecting species are unique. Use the renameSName function to rename the species before trying to connect' ) return if x . getCompartment ( ) == y . getCompartment ( ) : s = sum ( [ x . getInitialAmount ( ) , y . getInitialAmount ( ) ] ) check ( x . setInitialAmount ( s ) , 'setting initial amount of x in connectSubsystem' ) check ( y . setInitialAmount ( s ) , 'setting initial amount of y in connectSubsystem' ) oldid_x = x . getId ( ) oldid_y = y . getId ( ) check ( oldid_x , 'retreiving oldid of x in connectSubsystem' ) check ( oldid_y , 'retreiving oldid of x in connectSubsystem' ) newid = x . getId ( ) + '_with_' + y . getId ( ) check ( newid , 'retreiving newid of y in connectSubsystem' ) self . renameSId ( oldid_x , newid ) self . renameSId ( oldid_y , newid ) sp_remove = model_obj . getSpeciesByName ( x . getName ( ) ) if type ( sp_remove ) is list : print ( 'BioSIMI-Python WARNING -- Multiple species exist in the model with the same name as given in connection logic. Ensure that connection logic deals with unique species. Simulation may lead to wrong result in this case' ) return else : id_to_remove = sp_remove . getId ( ) model . removeSpecies ( id_to_remove )
The ListOfSubsystems are combined together as in combineSubsystems
method (depending on combineNames).
The ListOfSubsystems are combined together as in combineSubsystems method ( depending on combineNames ) .
'''
        The ListOfSubsystems are combined together as in combineSubsystems 
        method (depending on combineNames). Additionally, species interaction specified 
        In the connectionLogic is modeled for the concerned Species. The inputSpecies is 
        An optional argument that may be used to specify a list of Species which are desired
        inactive in the connected Subsystem
        ''' # The connection logic given by user species two or more different species # but that are bound to each other. # Set the initial amount of the input in the output subsystem to zero since it's not # isolated anymore. # Get the ids of the concerned species from the # connection logic given by the user # x and y should also have the same id so that they go into reactions as one. # Also, set the initial amount of the species to be equal to the # sum of their individual amounts # Rename ID of x by that of y # Remove x from species in the model to avoid duplication
self
ListOfSubsystems
connectionLogic
mode
combineNames
inputSpecies