pycotools3.model.Model¶
-
class
pycotools3.model.
Model
(copasi_file, quantity_type='concentration', new=False, **kwargs)[source]¶ Construct a pycotools3 model from a copasi file
The Model object is of central importance in pycotools as it extracts relevant information from a copasi file file into python.
These are
Model
attributes and properties:Examples
>>> from pycotools3.model import Model >>> model_path = r'/full/path/to/model.cps' >>> model = Model(model_path) ##work in concentration units >>> model = Model(model_path, quantity_type='particle_numbers') ## work in particle numbers
Property Description copasi_file Full path to model root Full path directory containing model reference Copasi model reference time_unit Time unit name Model name volume_unit Volume unit quantity_unit Quantity unit area_unit Area Unit length_unit Length unit avagadro Avagadro’s number key Model key states List of states in correct order defined by copasi StateTemplate element. fit_item_order Order in which fit items appear all_variable_names List of reactions, metabolites, global_quantities local_parameters, compartment names as string number_of_reactions Number of reactions in model.Model
Methods
__init__
(copasi_file[, quantity_type, new])param copasi_file: full path to a copasi file add
(component_name, **kwargs)add a model component to the model add_compartment
(compartment)Add compartment to model add_component
(component_name, component[, …])add a model component to the model add_function
(function)Add function to model add_global_quantity
(global_quantity)Add global quantity to model add_local_parameter
(local_parameter)Add a local parameter to the model, specifically into the String=’kinetic Parameters’ section of parameter sets add_metabolite
(metab)Add a metabolite to the model xml add_reaction
(reaction[, expression, rate_law])param reaction: py:class:Reaction or str. If str then add_state
(state, value)Append state on to end of state template. convert_molar_to_particles
(moles, mol_unit, …)Convert molarity to particle numbers convert_particles_to_molar
(particles, …)Converts particle numbers to Molarity. get
(component, value[, by])Factory method for getting a model component by a value of a certain type get_variable_names
([which, …])Get the names of variables in the model. insert_parameters
(**kwargs)Wrapper around the InsetParameters class open
([copasi_file, as_temp])Open model with the gui. refresh
()Save the file then reload the Model. remove
(component, name)General factor method for removing model components remove_compartment
(value[, by])Remove a compartment with the attribute given as the ‘by’ and value arguments remove_function
(value[, by])remove a function from model remove_global_quantity
(value[, by])Remove a global quantity from your model remove_metabolite
(value[, by])Remove metabolite from model. remove_reaction
(value[, by])Remove reaction remove_state
(state)Remove state from StateTemplate and InitialState fields. reset_cache
(prop)Delete property from cache then reset it save
([copasi_file])Save copasiML to copasi_filename. scan
([inplace])Perform a parameter scan on model set
(component, match_value, new_value[, …])Set a model components attribute to a new value simulate
(start, stop, by[, variables])to_antimony
()Returns antimony string of model. to_df
()Convert kwargs to 1D df :return: pandas.DataFrame to_dict
()get kwargs as dictionary :return: dict to_sbml
([sbml_file])convert model to sbml to_string
()Produce kwargs as string format for using in __str__ methods in subclasses. Attributes
active_parameter_set
get active parameter set all_variable_names
The names of all compartments, metabolites, global quantities, reactions and local parameters in the model. area_unit
str. The currently defined area unit. avagadro
Not really needed but good to check the consistancy of avagadros number. compartments
Get list of model compartments constants
Get list of constants from xml attribute `cn=”String=Kinetic Parameters” copasi_file
Model
fit_item_order
Get names of parameters being fitted in the order they appear functions
get model functions global_quantities
list each element is GlobalQuantity
key
Get the model reference - the ‘key’ from self.get_model_units length_unit
str local_parameters
Get local parameters in model. metabolites
list. Each element is Metabolite
name
str. The model name number_of_reactions
int number of reactions parameter_descriptions
list. Each element a ParameterDescription
parameter_sets
Here for potential future implementation of easy switching between parameter sets :return: parameters
get all locals, globals and metabs as pandas dataframe quantity_unit
str. The currently defined quantity unit reactions
assemble a list of reactions reference
Get model reference from xml root
Root directory for model. states
The states (metabolites, globals, compartments) in the order they are read by Copasi from the StateTemplate element. time_unit
str current time unit defined by copasi volume_unit
str. The currently defined volume unit -
active_parameter_set
¶ get active parameter set
Not really in use
Returns: etree.Element
Args:
Returns:
-
add
(component_name, **kwargs)[source]¶ add a model component to the model
Parameters: - component_name – str`. i.e. ‘reaction’, ‘function’, ‘metabolite
- component – py:class:model.<component>. The component class to add i.e. Metabolite
- reaction_expression – When adding reaction using string as first arg, this argument takes the reaction expression (i.e. A -> B)
- reaction_rate_law – When adding reaction using string as first argument this argument takes the reaction rate law (i.e. k*A)
- **kwargs –
Returns: py:class:`Model
-
add_compartment
(compartment)[source]¶ Add compartment to model
Parameters: compartment – py:class:Compartment Returns: py:class:Model
-
add_component
(component_name, component, reaction_expression=None, reaction_rate_law=None)[source]¶ add a model component to the model
Parameters: - component_name – str`. i.e. ‘reaction’, ‘function’, ‘metabolite
- component – py:class:model.<component>. The component class to add i.e. Metabolite
- reaction_expression – When adding reaction using string as first arg, this argument takes the reaction expression (i.e. A -> B) (Default value = None)
- reaction_rate_law – When adding reaction using string as first argument this argument takes the reaction rate law (i.e. k*A) (Default value = None)
Returns: class:`Model
Return type: py
-
add_function
(function)[source]¶ Add function to model
Parameters: function – py:class:Function. Returns: py:class:Model
-
add_global_quantity
(global_quantity)[source]¶ Add global quantity to model
Parameters: global_quantity – str` or GlobalQuantity
. If stris the name of global_quantity to add and default
GlobalQuantity
properties are adopted. IfGlobalQuantity
, aGlobalQuantity
instance must be prebuilt and passes as arg.Returns: py:class:Model
-
add_local_parameter
(local_parameter)[source]¶ Add a local parameter to the model, specifically into the String=’kinetic Parameters’ section of parameter sets
Parameters: local_parameter – py:class:LocalParameter Returns: py:class:Model
-
add_metabolite
(metab)[source]¶ Add a metabolite to the model xml
Parameters: metab – str` or Metabolite
. If stris the name of metabolite to add and default
Metabolite
properties are adopted. IfMetabolite
, aMetabolite
instance must be prebuilt and passes as arg.Returns: py:class:Model
-
add_reaction
(reaction, expression=None, rate_law=None)[source]¶ Parameters: reaction – py:class:Reaction or str. If str then - must be the name of the reaction.
- expression: (Default value = None) rate_law: (Default value = None)
Returns: py:class:Model
-
add_state
(state, value)[source]¶ Append state on to end of state template. Used within add_metabolite and add_global_quantity. Shouldn’t need to use manually
Parameters: - state – str`. A valid key
- value – int`, float. Value for state
Returns:
-
all_variable_names
¶ The names of all compartments, metabolites, global quantities, reactions and local parameters in the model.
Returns: list. Each element is str Args:
Returns:
-
area_unit
¶ - str. The currently defined area unit.
Args:
Returns:
Type: return
-
avagadro
¶ Not really needed but good to check the consistancy of avagadros number.
This number was changed between version 16 and 19 and caused a bugArgs:
Returns:
-
compartments
¶ Get list of model compartments
Returns: list. Each element is Compartment
Args:
Returns:
-
constants
¶ Get list of constants from xml attribute `cn=”String=Kinetic Parameters”
Returns: list each element LocalParameter
-
static
convert_molar_to_particles
(moles, mol_unit, compartment_volume)[source]¶ Convert molarity to particle numbers
Parameters: - moles – int` or float. Number of moles in mol_unit to convert
- mol_unit – str`. Mole unit to convert from.
- suppoerted: fmol, pmol, nmol, umol, mmol or mol
- compartment_volume: int` or float. Volume of compartment containing specie to convert
Returns: int`. number of particles
-
static
convert_particles_to_molar
(particles, mol_unit, compartment_volume)[source]¶ Converts particle numbers to Molarity.
##TODO build support for copasi’s newest units
Parameters: - particles – int` Number of particles to convert
- mol_unit – str`. The quantity unit, i.e:
- fmol, pmol, nmol, umol, mmol or mol
- compartment_volume: int`, float. Volume of compartment containing specie to convert
Returns: float`. Molarity
-
fit_item_order
¶ Get names of parameters being fitted in the order they appear
Returns: list Args:
Returns:
-
functions
¶ get model functions
Returns: list each element a py:class:`Function
-
get
(component, value, by='name')[source]¶ Factory method for getting a model component by a value of a certain type
Parameters: - component – str`. The component i.e. metabolite or local_parameter
- value – str`. Value of the attribute to match by i.e. metabolite called A
- by – str`. Which attribute to search by. i.e. name or key or value (Default value = ‘name’)
Returns: py:class:Model.<component>`
Get reaction called A2B:
Get metabolite called A:
Get all reactions which have a fixed simulation_type:
Get all compartments with an initial value of 15 (concentration or particles depending on quantity_type):
Get metabolites in the nucleus compartment:
Return type: Instance of `
>>> model.get('reaction', 'A2B', by='name')
>>> model.get('metabolite', 'A', by='name')
>>> model.get('global_quantity', 'fixed', by='simulation_type')
>>> model.get('compartment', 15, by='initial_value')
>>> model.get('metabolite', 'nuc', by='compartment')
-
get_model_object
(string)[source]¶ Retrieve a model object, such as a parameter or metabolite :param string: name of parameter :type string: str
Returns: correct model object
-
get_variable_names
(which='a', include_assignments=True, prefix=None)[source]¶ Get the names of variables in the model. If include_assignments is off these are ommited from the results (this is useful for ParameterEstimation) as they are not generally estimated. Prefix provides a way of filtering the returned list
Parameters: - which – string. Default=’a’. A string containing any or all of characters ‘a’, ‘m’, ‘g’, ‘l’, ‘c’ for all, metabolites, global_quantities, local_parameters and compartments respectively
- include_assignments – Boolean. Default=True. If True, return global variables with assignments
- prefix – str. Default=None. If given, returned parameter names are filtered to only include parameter with prerfix at the begining.
Returns: ‘list’ of variable names
-
global_quantities
¶ - list each element is
GlobalQuantity
Args:
Returns:
Type: return
-
insert_parameters
(**kwargs)[source]¶ Wrapper around the InsetParameters class
Parameters: - kwargs – Arguments for InsertParameters
- **kwargs –
Returns: py:class:Model
-
key
¶ Get the model reference - the ‘key’ from self.get_model_units
Returns: str Args:
Returns:
-
length_unit
¶ - str
Args:
Returns:
Type: return
-
local_parameters
¶ Get local parameters in model. local_parameters are those which are actively used in reactions and do not have a global variable assigned to them. The constant property returns all local parameters regardless of simulation type (fixed or assignment)
Returns: list. Each element is LocalParameter
Args:
Returns:
-
metabolites
¶ - list. Each element is
Metabolite
Args:
Returns:
Type: return
-
name
¶ - str. The model name
Args:
Returns:
Type: return
-
number_of_reactions
¶ - int number of reactions
Args:
Returns:
Type: return
-
open
(copasi_file=None, as_temp=False)[source]¶ Open model with the gui. In order to work the environment variables must be properly set so that the command CopasiUI in the terminal or command prompt opens the model.
First
Model.save()
the model to copasi_file then open with CopasiUI. Optionally open with a temporary filename.Parameters: - copasi_file – str` or None. Same as
model.Save()
(Default value = None) - as_temp – bool`. Use temp file to open the model and remove
afterwards (Default value = False)
Returns: None` - copasi_file – str` or None. Same as
-
parameter_descriptions
¶ - list. Each element a
ParameterDescription
Args:
Returns:
Type: return
-
parameter_sets
¶ Here for potential future implementation of easy switching between parameter sets :return:
Args:
Returns:
-
parameters
¶ get all locals, globals and metabs as pandas dataframe
Returns: pandas.DataFrame
Args:
Returns:
-
quantity_unit
¶ - str. The currently defined quantity unit
Args:
Returns:
Type: return
-
reactions
¶ assemble a list of reactions
Returns: list each element a Reaction
-
reference
¶ Get model reference from xml
Returns: str Args:
Returns:
-
refresh
()[source]¶ Save the file then reload the Model. Can’t use the save method though because the save method uses the refresh method. :return:
Args:
Returns:
-
remove
(component, name)[source]¶ General factor method for removing model components
Parameters: - component – str` which component to remove (i.e. metabolite)
- name – str` name of component to remove
Returns: py:class:Model
-
remove_compartment
(value, by='name')[source]¶ Remove a compartment with the attribute given as the ‘by’ and value arguments
Parameters: - value – str`. Value of attribute to match i.e. ‘Nucleus’
- by – str` which attribute to match i.e. ‘name’ or ‘key’ (Default value = ‘name’)
Returns: py:class:Model
-
remove_function
(value, by='name')[source]¶ remove a function from model
Parameters: - value – str` value of attribute to match (i.e the functions name)
- by – str` which attribute to match by. default=’name’
Returns: py:class:model.Model
-
remove_global_quantity
(value, by='name')[source]¶ Remove a global quantity from your model
Parameters: - value – value to match by (i.e. ProteinA or ProteinB)
- by – attribute to match (i.e. name or key) (Default value = ‘name’)
Returns: py:class:model.Model
-
remove_metabolite
(value, by='name')[source]¶ Remove metabolite from model.
Parameters: - value – str`. Attribute value to remove
- by – str` Any metabolite attribute type to match (Default value = ‘name’)
Returns: py:class:Model
Usage: ## Remove attribute called ‘A’
## Remove metabolites with initial concentration of 0
>>> model.remove_metabolite('A', by='name')
>>> model.remove_metabolite(0, by='concentration')
-
remove_reaction
(value, by='name')[source]¶ Remove reaction
Parameters: - value – str`. Value of attibute
- by – attribute of reaction to match default=’name
str which :py:class`Reaction` atrribute to match
Returns: py:class:Model
-
remove_state
(state)[source]¶ Remove state from StateTemplate and InitialState fields. USed for deleting metabolites and global quantities.
Parameters: state – str`. key of state to remove (i.e. Metabolite_1) Returns: py:class:Model
-
reset_cache
(prop)[source]¶ Delete property from cache then reset it
Parameters: prop – str`. property to reset Returns: py:class:Model
-
root
¶ Root directory for model. The directory where copasi_file is saved.
Does not need a setter since root is derived from copasi_file property
Returns: str Args:
Returns:
-
save
(copasi_file=None)[source]¶ Save copasiML to copasi_filename.
Parameters: copasi_filename – str` or None. Deafult is None. When None defaults to same filepath the model came from. If another path, saves to that path. copasi_file: (Default value = None) Returns: py:class:Model
-
scan
(inplace=False, **kwargs)[source]¶ Perform a parameter scan on model
This is a wrapper around
tasks.Scan
and accepts all of the same arguments, except the model which is already provided.Parameters: **kwargs – Returns:
-
sensitivities
(inplace=False, **kwargs)[source]¶ Perform a sensitivity analysis on model
This is a wrapper around
tasks.Sensitivities
and accepts all of the same arguments, except the model which is already provided.Parameters: **kwargs – Returns:
-
set
(component, match_value, new_value, match_field='name', change_field='name')[source]¶ Set a model components attribute to a new value
Parameters: - component – str` type of component to change (i.e. metbaolite)
- match_value – str`, int, float depending on value of match_field.
- The value to match.
- new_value: str`, int or float depending on value of match_field
- new value for component attribute
- match_field: str`. The attribute of component to match by. (Default value = ‘name’) change_field: str` The attribute of the component matched that you want to change? (Default value = ‘name’)
Returns: py:class:Model Set initial concentration of metabolite called ‘X’ to 50:
Set name of global quantity called ‘G’ to ‘H’:
>>> model.set('metabolite', 'X', 50, match_field='name', change_field='concentration')
>>> model.set('global_quantity', 'G', 'H', match_field='name', change_field='name')
-
states
¶ The states (metabolites, globals, compartments) in the order they are read by Copasi from the StateTemplate element.
Returns: OrderedDict Args:
Returns:
-
time_unit
¶ - str current time unit defined by copasi
Args:
Returns:
Type: return
-
to_antimony
()[source]¶ Returns antimony string of model. Wrapper around tellurium functions :return:
Args:
Returns:
-
to_sbml
(sbml_file=None)[source]¶ convert model to sbml
Parameters: sbml_file – str`. Path for SBML. Defaults to same as copasi filename Returns: str`. Path to smbl file
-
volume_unit
¶ - str. The currently defined volume unit
Args:
Returns:
Type: return
-