copyobj
R2026bCopy SimBiology object and its children
Syntax
Description
makes a copy of a SimBiology model object copiedObj = copyobj(modelObj)modelObj and returns the
copied model object copiedObj. The function also sets the
Parent property of the copied model object to the root object. Use
this function to create a copy of a model that you can then add as a submodel to build a
model hierarchy.
makes a copy of a SimBiology object and returns the copied object. The function also sets
the copiedObj = copyobj(object,parentObj)Parent property of the copied object to
parentObj.
One exception is that if both object and
parentObj are compartments, the Owner property
of the copied object is set to parentObj instead.
specifies how to handle naming conflicts. (since R2024a)copiedObj = copyobj(object,parentObj,conflictOption)
Examples
Create a model object and add a reaction.
m1 = sbiomodel("m1"); c1 = addcompartment(m1,"c1"); r1 = addreaction(m1,"a -> b");
Create a copy of the reaction object and add it to another model.
m2 = sbiomodel("m2");
r1copy = copyobj(r1,m2);Create a copy of species a in the same compartment using the "force" option. The function adds the postfix "_1" to the name of the copied species to resolve the naming conflict.
a = m1.Species(1);
a_copy = copyobj(a,c1,"force")a_copy = SimBiology Species Array Index: Compartment: Name: Value: Units: ParentModel: 1 c1 a_1 0 m1
Build a PBPK model from a generic organ template using submodels, then use sbioselect and addequivalence to connect shared compartments and species across organ submodels.
Create a generic organ model with venous blood, arterial blood, and organ compartments, each containing a Drug species.
genericOrganModel = sbiomodel("Generic Organ"); venousComp = addcompartment(genericOrganModel,"Venous Blood",3000,Units="milliliter"); arterialComp = addcompartment(genericOrganModel,"Arterial Blood",1500,Units="milliliter"); organComp = addcompartment(genericOrganModel,"Organ",0.5e-10,Units="milliliter"); addspecies(venousComp,"Drug",0,Units="milligram/milliliter"); addspecies(arterialComp,"Drug",0,Units="milligram/milliliter"); addspecies(organComp,"Drug",0,Units="milligram/milliliter"); addparameter(genericOrganModel,"DrugBloodPlasmaRatio",0.8,Units="dimensionless"); addparameter(genericOrganModel,"DrugFractionUnbound",0.6,Units="dimensionless");
Build the PBPK model hierarchy by copying the generic organ model into multiple organ submodels using copyobj.
pbpkModel = sbiomodel("PBPK"); for organ = ["Gut","Liver","Lung","Heart","Brain","Kidney"] organModel = copyobj(genericOrganModel,pbpkModel); organModel.Name = organ + " submodel"; organCompartment = sbioselect(organModel.Compartments,Name="Organ"); rename(organCompartment,organ); end
Inspect the submodel hierarchy.
pbpkModel.Models
ans = SimBiology Model Array Index: Name: ParentModel: 1 Gut submodel PBPK 2 Liver submodel PBPK 3 Lung submodel PBPK 4 Heart submodel PBPK 5 Brain submodel PBPK 6 Kidney submodel PBPK
Use sbioselect to find all Venous Blood compartments across submodels.
venousComps = sbioselect(pbpkModel,"Type","compartment","Name","Venous Blood")
venousComps = SimBiology Compartment Array Index: Name: Value: Units: ParentModel: 1 Venous Blood 3000 milliliter Gut submodel 2 Venous Blood 3000 milliliter Liver submodel 3 Venous Blood 3000 milliliter Lung submodel 4 Venous Blood 3000 milliliter Heart submodel 5 Venous Blood 3000 milliliter Brain submodel 6 Venous Blood 3000 milliliter Kidney submodel
Use addequivalence to create an equivalence set grouping all Venous Blood compartments. During simulation, these compartments share a single resolved value.
eqVenous = addequivalence(pbpkModel,venousComps)
eqVenous =
EquivalenceSet with properties:
ModelScope: [1×1 SimBiology.Model]
Quantities: [6×1 SimBiology.Compartment]
ResolvedQuantity: [1×1 SimBiology.Compartment]
SuperSet: []
SubSets: [6×1 SimBiology.EquivalenceSet]
TopLevelSet: [1×1 SimBiology.EquivalenceSet]
Check which compartment is the resolved quantity. This is the quantity used in simulation and analysis workflows.
eqVenous.ResolvedQuantity
ans =
SimBiology Compartment - Venous Blood
Compartment Components:
Value: 3000
Units: milliliter
Compartments: 0
Constant: true
Owner:
Species: 1
ParentModel: Gut submodel
Similarly, create an equivalence set for Arterial Blood compartments.
arterialComps = sbioselect(pbpkModel,"Type","compartment","Name","Arterial Blood"); eqArterial = addequivalence(pbpkModel,arterialComps);
Making compartments equivalent does not automatically make their species equivalent. Create equivalence sets for the Drug species in the Venous Blood and Arterial Blood compartments.
venousDrugSpecies = sbioselect(venousComps,"Type","species","Name","Drug"); eqVenousDrug = addequivalence(pbpkModel,venousDrugSpecies); arterialDrugSpecies = sbioselect(arterialComps,"Type","species","Name","Drug"); eqArterialDrug = addequivalence(pbpkModel,arterialDrugSpecies);
Verify the equivalence sets on the model.
pbpkModel.EquivalenceSets
ans =
4×1 EquivalenceSet array with properties:
ModelScope
Quantities
ResolvedQuantity
SuperSet
SubSets
TopLevelSet
Input Arguments
SimBiology model component, specified as a Model, SimBiology.Configset, Compartment, Species, Parameter, SimBiology.RepeatDose, SimBiology.ScheduleDose, Variant object, Reaction, KineticLaw, SimBiology.Event, Rule, or Observable.
SimBiology model component, specified as a Model, Compartment, Reaction, KineticLaw, or Root object.
If the input object is... | parentObj must be... |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
SimBiology model, specified as a Model object.
Method to resolve naming conflicts, specified as a character vector or string. Valid options are:
"force"— The function copies the model component but renames the copied component if there is a naming conflict by appending"_N", whereNis a positive integer. For example, when you try to make a copy of a species inside the same compartment, the"force"option creates a copied species, which has the same name as the original species with a postfix"_N". For details, see Guidelines for Naming Model Components."strict"— The function throws an error and will not copy the model component if there is a naming conflict.
Note
There are some exceptions for this option, and it works for a subset of model components.
Compartment, dose, event, observable, parameter, rule, species, and variant objects support this option.
Configset and reaction objects do not have this option, but the copied object and any reaction-scoped parameters are always renamed as needed.
KineticLaw objects do not have or need this option.
Version History
Introduced in R2006aYou can now copy a Model object to another Model
object as a submodel. Previously, copying a model was supported only to the
Root object.
The copyobj function has an optional input argument to resolve the
naming conflicts. The new argument has the following values: "strict" and
"force".
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)