biocrnpyler.core.species

Classes

Complex(*args, **keywords)

Metaclass for creating chemical complexes.

ComplexSpecies(species[, name, ...])

!!!ComplexSpecies and OrderedComplexSpecies should ALWAYS be created with the Complex function!!!

OrderedComplexSpecies(species[, name, ...])

!!!ComplexSpecies and OrderedComplexSpecies should ALWAYS be created with the Complex function!!!

OrderedPolymerSpecies(species[, name, ...])

A class to represent OrderedPolymers which can also participate in chemical reactions.

PolymerConformation([complexes, polymer, ...])

This class stores a set of PolymerSpecies and a set of connections between them in the form of ComplexSpecies containing Monomers inside the PolymerSpecies.

Species(name[, material_type, attributes, ...])

A formal species object for a chemical reaction network (CRN).

WeightedSpecies(species[, stoichiometry])

Container object for a all types of species and its stoichiometry

class biocrnpyler.core.species.Complex(*args, **keywords)[source]

Metaclass for creating chemical complexes.

Complex is not a class that gets instantiated - it creates ComplexSpecies and OrderedComplexSpecies. The Logic encoded in the __new__ function is used to insert these classes into the binding sites of OrderedPolymerSpecies.

arguments: species: a list of species to put into ComplexSpecies or OrderedComplexSpecies

keywords: ordered: whether to produce an OrderedComplexSpecies (default = False)

This function effectively produces the instance of the correct Species Class based upon the arguments passed in.

Cases: Here species refer to the Species in the Species list passed into the construct. 1. No Species have parents.

Produces: an ComplexSpecies or an OrderedComplexSepcies

  1. A single Species S has a parent which is an OrderedPolymerSpecies with no parent. Produces: an OrderedPolymerSpecies with a ComplexSpecies or OrderedComplexSpecies containing S in S’s location in the OrderedPolymerSpecies.

  2. [Error Case] Multiple Species S have parents which are OrderedPolymerSpecies without parents.

  3. [Error Case] Entire OrderedPolymerSpecies inside PolymerConformations are being Complexed Together

  4. One or More Species S have parents which are OrderedPolymerSpecies with parents and/or PolymerConformations Produces: a (Ordered)ComplexSpecies containing all S inside a PolymerConformation which merges all PolymerComformation Complexes.

class biocrnpyler.core.species.ComplexSpecies(species: List[Species | str], name: str | None = None, material_type='complex', attributes=None, compartment=None, **keywords)[source]

!!!ComplexSpecies and OrderedComplexSpecies should ALWAYS be created with the Complex function!!!

A special kind of species which is formed as a complex of two or more species. Used for attribute inheritance and storing groups of bounds Species. Note taht in a ComplexSpecies, the order of the species list does not matter. This means that ComplexSpecies([s1, s2]) = ComplexSpecies([s2, s1]). This is good for modelling order-indpendent binding complexes. For a case where species order matters (e.g. polymers) use OrderedComplexSpecies

the default is that the monomer is not part of a polymer

add_attribute(attribute: str)[source]

Adds attributes to a Species

contains_species_monomer(s)[source]

Checks if the Species has a monomer (Species) inside of it, but without checking Species.parent, Species.position, or direction. In effect, a less stringent version of __contains__.

static flatten_list(in_list) List[source]

Helper function to flatten lists

get_orphan()[source]

returns a copy of this monomer, except with no parent. But it still has a position and direction

get_species(recursive=False)[source]

Returns all species in the ComplexSpecies. If recursive = True, returns species inside internal ComplexSpecies recursively as well.

monomer_count(m)[source]

Effectively self.species.count(m) using monomer_eq for equality

monomer_eq(other)[source]

Same as normal equality, but does not check for parents or positions.

pretty_print(show_material=True, show_compartment=False, show_attributes=True, show_initial_condition=False, **kwargs)[source]

A more powerful printing function. Useful for understanding CRNs but does not return string identifiers. show_material toggles whether species.material is printed. show_attributes toggles whether species.attributes is printed

remove()[source]

Added functionality to remove direction as an attribute.

remove_attribute(attribute: str)[source]

removes an attribute from a Species

replace_species(species: Species, new_species: Species)[source]

Replaces species with new_species in the entire Complex Species. Acts recursively on nested ComplexSpecies Does not act in place - returns a new ComplexSpecies.

class biocrnpyler.core.species.OrderedComplexSpecies(species, name=None, material_type='ordered_complex', attributes=None, compartment=None, **keywords)[source]

!!!ComplexSpecies and OrderedComplexSpecies should ALWAYS be created with the Complex function!!!

A special kind of species which is formed as a complex of two or more species. In OrderedComplexSpecies the order in which the complex subspecies are is defined denote different species, eg [s1, s2, s3] != [s1, s3, s2]. Used for attribute inheritance and storing groups of bounds Species.

the default is that the monomer is not part of a polymer

add_attribute(attribute: str)[source]

Adds attributes to a Species

contains_species_monomer(s)[source]

Checks if the Species has a monomer (Species) inside of it, but without checking Species.parent, Species.position, or direction. In effect, a less stringent version of __contains__.

static flatten_list(in_list) List[source]

Helper function to flatten lists

get_orphan()[source]

returns a copy of this monomer, except with no parent. But it still has a position and direction

get_species(recursive=False)[source]

Returns all species in the ComplexSpecies. If recursive = True, returns species inside internal ComplexSpecies recursively as well.

monomer_count(m)[source]

Effectively self.species.count(m) using monomer_eq for equality

monomer_eq(other)[source]

Same as normal equality, but does not check for parents or positions.

pretty_print(show_material=True, show_compartment=False, show_attributes=True, show_initial_condition=False, **kwargs)[source]

A more powerful printing function. Useful for understanding CRNs but does not return string identifiers. show_material toggles whether species.material is printed. show_attributes toggles whether species.attributes is printed

remove()[source]

Added functionality to remove direction as an attribute.

remove_attribute(attribute: str)[source]

removes an attribute from a Species

replace_species(species: Species, new_species: Species)[source]

Replaces species with new_species in the entire Complex Species. Acts recursively on nested ComplexSpecies

class biocrnpyler.core.species.OrderedPolymerSpecies(species, name=None, material_type='ordered_polymer', compartment=None, attributes=None, circular=False)[source]

A class to represent OrderedPolymers which can also participate in chemical reactions. OrderedPolymerSpecies is made up of Species (which are also OrderedMonomers).

The Species inside an OrderedPolymerSpecies are meant to model multiple binding sites and/or functional regions. ComplexSpecies can be formed inside an OrderedPolymer by passing the internal Species at a specific location.

When used as an input to a reaction, OrderedPolymerSpecies can be passed or one if its internal Species (eg a Species with Species.parent = OrderedPolymerSpecies) can also be used to produce the same reaction. This allows flexibility in the arguments to different Mechanisms. Sometimes, it is convenient to pass in the OrderedPolymerSpecies, sometimes it is convenient to pass an internal Species. Both will work from the point of view of any Mechanism.

the default is that the monomer is not part of a polymer

add_attribute(attribute: str)[source]

Adds attributes to a Species

contains_species_monomer(s)[source]

Checks if the Species has a monomer (Species) inside of it, but without checking Species.parent, Species.position, or direction. In effect, a less stringent version of __contains__.

static flatten_list(in_list) List[source]

Helper function to flatten lists

classmethod from_polymer_species(ops, replace_dict, **keywords)[source]

Created a new OrderedPolymerSpecies with certain monomers replaced based upon replace_dict:

inputs: replace_dict {monomer index –> new Species} outputs: OrderedPolymerSpecies

get_orphan()[source]

returns a copy of this monomer, except with no parent. But it still has a position and direction

get_species(recursive=False)[source]

Returns all species in the ComplexSpecies. If recursive = True, returns species inside internal ComplexSpecies recursively as well.

monomer_count(m)[source]

Effectively self.species.count(m) using monomer_eq for equality

monomer_eq(other)[source]

Same as normal equality, but does not check for parents or positions.

pretty_print(show_material=True, show_compartment=False, show_attributes=True, show_initial_condition=False, **kwargs)[source]

A more powerful printing function. Useful for understanding CRNs but does not return string identifiers. show_material toggles whether species.material is printed. show_attributes toggles whether species.attributes is printed

remove()[source]

Added functionality to remove direction as an attribute.

remove_attribute(attribute: str)[source]

removes an attribute from a Species

replace_species(species: Species, new_species: Species)[source]

Replaces species with new_species in the entire Complex Species. Acts recursively on nested ComplexSpecies

class biocrnpyler.core.species.PolymerConformation(complexes=None, polymer=None, material_type='conformation', name=None, **keywords)[source]

This class stores a set of PolymerSpecies and a set of connections between them in the form of ComplexSpecies containing Monomers inside the PolymerSpecies.

The main function of this class is to provide a unique name to each conformation. The name is given by:

conformation__[PolymerSpecies 1]_…_[PolymerSpecies N]_[ComplexSpecies_1 parent Polymer indices]_[ComplexSpecies_1]…_[ComplexSpecies_M]__

where the list of PolymerSpecies and ComplexSpecies are in alphabetical order. The ComplexSpecies parent Polymer indices notes which Polymers each Species in the ComplexSpecies comes from, with ‘n’ used for None.

In general, users should not produce PolymerConformations directly. The Complex function will automatically produce these when a complex is formed involving Multiple OrderedMonomers contained within one or more PolymerSpecies.

In effect, this can be thought of as a data structure for a hypergraph. The monomers of the PolymerSpecies are vertices and ComplexSpecies form edges that connect an arbitrary number of vertices (potentially including other Species as well). Note that this class allows for multiple edges between the same sets of vertices.

complexes: a list of ComplexSpecies each of which must contain Monomers from the OrderedPolymerSpecies in the conformation

add_attribute(attribute: str)[source]

Adds attributes to a Species

contains_species_monomer(s)[source]

Checks if the Species has a monomer (Species) inside of it, but without checking Species.parent, Species.position, or direction. In effect, a less stringent version of __contains__.

copy_remove_complexes(complexes)[source]

Returns a new PolymerConformation without these complexes

static flatten_list(in_list) List[source]

Helper function to flatten lists

classmethod from_polymer_conformation(pcs, complexes=None, complexes_to_remove=None, **keywords)[source]

This function produces a new PolymerConformation from previously existing PolymerConformations and new Complexes.

pcs: a list of PolymerConformations complexes: a list of complexes to add to the polymer conformation

classmethod from_polymer_replacement(pc, old_polymers, new_polymers, **keywords)[source]

This function produces a PolymerConformation from a previously existing PolymerConformation by replacing old_polymers with new_polymers

pc: the PolymerConformation to replace polymers from. old_polymers: a list of PolymerSpecies instances. These must be the same instances stored inside pc or an error is thrown. new_polymers: a list of new PolymerSpecies instances to replace each of the old_polymers. Must be the same length as old_polymers.

get_orphan()[source]

returns a copy of this monomer, except with no parent. But it still has a position and direction

get_species(**kwargs)[source]

Used in some recursive calls where ComplexSpecies returns a list and Species will return just themselves (in a list)

monomer_eq(other)[source]

Same as normal equality, but does not check for parents or positions.

pretty_print(show_material=True, show_compartment=False, show_attributes=True, show_initial_condition=False, **kwargs)[source]

#A more powerful printing function. Useful for understanding CRNs but does not return string identifiers. show_material toggles whether species.material is printed. show_attributes toggles whether species.attributes is printed

remove()[source]

Added functionality to remove direction as an attribute.

remove_attribute(attribute: str)[source]

removes an attribute from a Species

class biocrnpyler.core.species.Species(name: str, material_type='', attributes: List | None = None, compartment=None, **keywords)[source]

A formal species object for a chemical reaction network (CRN).

A Species must have a name. They may also have a material_type (such as DNA, RNA, Protein), and a list of attributes.

the default is that the monomer is not part of a polymer

add_attribute(attribute: str)[source]

Adds attributes to a Species

contains_species_monomer(s)[source]

Checks if the Species has a monomer (Species) inside of it, but without checking Species.parent, Species.position, or direction. In effect, a less stringent version of __contains__.

static flatten_list(in_list) List[source]

Helper function to flatten lists

get_orphan()[source]

returns a copy of this monomer, except with no parent. But it still has a position and direction

get_species(**kwargs)[source]

Used in some recursive calls where ComplexSpecies returns a list and Species will return just themselves (in a list)

monomer_eq(other)[source]

Same as normal equality, but does not check for parents or positions.

pretty_print(show_material=True, show_compartment=False, show_attributes=True, show_initial_condition=False, **kwargs)[source]

#A more powerful printing function. Useful for understanding CRNs but does not return string identifiers. show_material toggles whether species.material is printed. show_attributes toggles whether species.attributes is printed

remove()[source]

Added functionality to remove direction as an attribute.

remove_attribute(attribute: str)[source]

removes an attribute from a Species