use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class DiffEquMathMapping method computeBoundaryConditionSource.
// determine membrane inside and outside subvolume
public static Pair<SubVolume, SubVolume> computeBoundaryConditionSource(Model model, SimulationContext simContext, SurfaceClass surfaceClass) {
SubVolume outerSubVolume = null;
SubVolume innerSubVolume = null;
Structure[] mappedStructures = simContext.getGeometryContext().getStructuresFromGeometryClass(surfaceClass);
// inside and outside correspond to structure hierarchy when present
for (Structure s : mappedStructures) {
if (s instanceof Membrane) {
Membrane m = (Membrane) s;
Feature infeature = model.getStructureTopology().getInsideFeature(m);
if (infeature != null) {
FeatureMapping insm = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(infeature);
if (insm.getGeometryClass() instanceof SubVolume) {
innerSubVolume = (SubVolume) insm.getGeometryClass();
}
}
Feature outfeature = model.getStructureTopology().getOutsideFeature(m);
if (outfeature != null) {
FeatureMapping outsm = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(outfeature);
if (outsm.getGeometryClass() instanceof SubVolume) {
outerSubVolume = (SubVolume) outsm.getGeometryClass();
}
}
}
}
// make the choice deterministic
if (innerSubVolume == null || outerSubVolume == null || innerSubVolume == outerSubVolume) {
Set<SubVolume> sv = surfaceClass.getAdjacentSubvolumes();
Iterator<SubVolume> iterator = sv.iterator();
innerSubVolume = iterator.next();
outerSubVolume = iterator.next();
if (innerSubVolume.getName().compareTo(outerSubVolume.getName()) > 0) {
SubVolume temp = innerSubVolume;
innerSubVolume = outerSubVolume;
outerSubVolume = temp;
}
}
Pair<SubVolume, SubVolume> ret = new Pair<>(innerSubVolume, outerSubVolume);
return ret;
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class DiffEquMathMapping method refreshVariables.
/**
* This method was created in VisualAge.
*/
private void refreshVariables() throws MappingException {
// System.out.println("MathMapping.refreshVariables()");
//
// non-constant dependent variables require a function
//
Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (scm.getDependencyExpression() != null && !scs.isConstant()) {
// scm.setVariable(new Function(scm.getSpeciesContext().getName(),scm.getDependencyExpression()));
scm.setVariable(null);
}
if (getSimulationContext().hasEventAssignment(scs.getSpeciesContext())) {
scm.setDependencyExpression(null);
}
}
//
// non-constant independent variables require either a membrane or volume variable
//
enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (scm.getDependencyExpression() == null && (!scs.isConstant() || getSimulationContext().hasEventAssignment(scs.getSpeciesContext()))) {
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(scm.getSpeciesContext().getStructure());
Structure struct = scm.getSpeciesContext().getStructure();
Domain domain = null;
if (sm.getGeometryClass() != null) {
domain = new Domain(sm.getGeometryClass());
}
if (struct instanceof Feature || struct instanceof Membrane) {
if (sm.getGeometryClass() instanceof SurfaceClass) {
if (scs.isWellMixed()) {
scm.setVariable(new MembraneRegionVariable(scm.getSpeciesContext().getName(), domain));
} else if (getSimulationContext().isStoch() && getSimulationContext().getGeometry().getDimension() > 0 && !scs.isForceContinuous()) {
scm.setVariable(new MemVariable(scm.getSpeciesContext().getName() + "_conc", domain));
} else {
scm.setVariable(new MemVariable(scm.getSpeciesContext().getName(), domain));
}
} else {
if (scs.isWellMixed()) {
scm.setVariable(new VolumeRegionVariable(scm.getSpeciesContext().getName(), domain));
} else if (getSimulationContext().isStoch() && getSimulationContext().getGeometry().getDimension() > 0 && !scs.isForceContinuous()) {
scm.setVariable(new VolVariable(scm.getSpeciesContext().getName() + "_conc", domain));
} else {
scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), domain));
}
}
} else {
throw new MappingException("class " + scm.getSpeciesContext().getStructure().getClass() + " not supported");
}
mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
}
}
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class StructureAnalyzer method refreshFastMatrices.
/**
* This method was created in VisualAge.
*/
private void refreshFastMatrices() throws Exception {
// System.out.println("StructureAnalyzer.refreshFastMatrices()");
//
// update scheme matrix for fast system
//
fastSchemeMatrix = new RationalNumberMatrix(fastSpeciesContextMappings.length, fastReactionSteps.length);
for (int i = 0; i < fastSpeciesContextMappings.length; i++) {
for (int j = 0; j < fastReactionSteps.length; j++) {
fastSchemeMatrix.set_elem(i, j, fastReactionSteps[j].getStoichiometry(fastSpeciesContextMappings[i].getSpeciesContext()));
}
}
//
for (int i = 0; i < fastSpeciesContextMappings.length; i++) {
SpeciesContextMapping scm = fastSpeciesContextMappings[i];
SpeciesContext sc = scm.getSpeciesContext();
//
// collect fast rate expression
//
Expression exp = new Expression(0.0);
for (int j = 0; j < fastReactionSteps.length; j++) {
int stoichiometry = fastReactionSteps[j].getStoichiometry(sc);
ReactionSpec reactionSpec = mathMapping_4_8.getSimulationContext().getReactionContext().getReactionSpec(fastReactionSteps[j]);
if (stoichiometry != 0) {
if (!reactionSpec.isFast()) {
throw new Exception("expected only fast rates");
}
if (reactionSpec.isExcluded()) {
throw new Exception("expected only included rates");
}
ReactionParticipant[] rps = fastReactionSteps[j].getReactionParticipants();
ReactionParticipant rp0 = null;
for (ReactionParticipant rp : rps) {
if (rp.getSpeciesContext() == sc) {
rp0 = rp;
break;
}
}
//
if (rp0 != null) {
Structure structure = fastReactionSteps[j].getStructure();
Expression fastRateExpression = getReactionRateExpression(fastReactionSteps[j], rp0).renameBoundSymbols(mathMapping_4_8.getNameScope());
if ((structure instanceof Membrane) && (rp0.getStructure() != structure)) {
Membrane membrane = (Membrane) structure;
MembraneMapping membraneMapping = (MembraneMapping) mathMapping_4_8.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
Expression fluxCorrection = new Expression(mathMapping_4_8.getFluxCorrectionParameter(membraneMapping, (Feature) rp0.getStructure()), mathMapping_4_8.getNameScope());
exp = Expression.add(exp, Expression.mult(fluxCorrection, fastRateExpression));
} else {
exp = Expression.add(exp, new Expression(fastRateExpression));
}
}
}
}
// exp.bindExpression(mathMapping);
scm.setFastRate(exp.flatten());
}
// System.out.println("StructureAnalyzer.refreshFastMatrices(), scheme matrix:");
// fastSchemeMatrix.show();
//
// update null space matrix
//
fastNullSpaceMatrix = fastSchemeMatrix.findNullSpace();
// if (fastNullSpaceMatrix==null){
// System.out.println("fast system has full rank");
// }else{
// System.out.println("StructureAnalyzer.refreshFastMatrices(), nullSpace matrix:");
// fastNullSpaceMatrix.show();
// }
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class StructureAnalyzer method getReactionRateExpression.
public Expression getReactionRateExpression(ReactionStep reactionStep, ReactionParticipant reactionParticipant) throws Exception {
if (reactionParticipant instanceof Catalyst) {
throw new Exception("Catalyst " + reactionParticipant + " doesn't have a rate for this reaction");
// return new Expression(0.0);
}
double stoich = reactionStep.getStoichiometry(reactionParticipant.getSpeciesContext());
if (stoich == 0.0) {
return new Expression(0.0);
}
if (reactionStep.getKinetics() instanceof DistributedKinetics) {
DistributedKinetics distributedKinetics = (DistributedKinetics) reactionStep.getKinetics();
if (stoich != 1) {
Expression exp = Expression.mult(new Expression(stoich), new Expression(distributedKinetics.getReactionRateParameter(), mathMapping_4_8.getNameScope()));
return exp;
} else {
Expression exp = new Expression(distributedKinetics.getReactionRateParameter(), mathMapping_4_8.getNameScope());
return exp;
}
} else if (reactionStep.getKinetics() instanceof LumpedKinetics) {
Structure.StructureSize structureSize = reactionStep.getStructure().getStructureSize();
//
// need to put this into concentration/time with respect to structure for reaction.
//
LumpedKinetics lumpedKinetics = (LumpedKinetics) reactionStep.getKinetics();
Expression factor = null;
ModelUnitSystem unitSystem = mathMapping_4_8.getSimulationContext().getModel().getUnitSystem();
if (reactionStep.getStructure() instanceof Feature || ((reactionStep.getStructure() instanceof Membrane) && reactionStep instanceof FluxReaction)) {
VCUnitDefinition lumpedToVolumeSubstance = unitSystem.getVolumeSubstanceUnit().divideBy(unitSystem.getLumpedReactionSubstanceUnit());
factor = Expression.div(new Expression(lumpedToVolumeSubstance.getDimensionlessScale()), new Expression(structureSize, mathMapping_4_8.getNameScope()));
} else if (reactionStep.getStructure() instanceof Membrane && reactionStep instanceof SimpleReaction) {
VCUnitDefinition lumpedToVolumeSubstance = unitSystem.getMembraneSubstanceUnit().divideBy(unitSystem.getLumpedReactionSubstanceUnit());
factor = Expression.div(new Expression(lumpedToVolumeSubstance.getDimensionlessScale()), new Expression(structureSize, mathMapping_4_8.getNameScope()));
} else {
throw new RuntimeException("failed to create reaction rate expression for reaction " + reactionStep.getName() + ", with kinetic type of " + reactionStep.getKinetics().getClass().getName());
}
if (stoich != 1) {
Expression exp = Expression.mult(new Expression(stoich), Expression.mult(new Expression(lumpedKinetics.getLumpedReactionRateParameter(), mathMapping_4_8.getNameScope()), factor));
return exp;
} else {
Expression exp = Expression.mult(new Expression(lumpedKinetics.getLumpedReactionRateParameter(), mathMapping_4_8.getNameScope()), factor);
return exp;
}
} else {
throw new RuntimeException("unexpected kinetic type " + reactionStep.getKinetics().getClass().getName());
}
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class VolumeStructureAnalyzer method refreshStructures.
/**
* Build list of structures that are mapped to this volume subdomain
*/
protected void refreshStructures() {
//
// get all structures that are mapped to this subvolume (subdomain)
//
Structure[] structs = mathMapping_4_8.getStructures(subVolume);
Vector<Structure> structList = new Vector<Structure>();
if (structs != null) {
for (int i = 0; i < structs.length; i++) {
//
if (structs[i] instanceof Membrane) {
Membrane membrane = (Membrane) structs[i];
MembraneMapping membraneMapping = (MembraneMapping) mathMapping_4_8.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
if (mathMapping_4_8.getResolved(membraneMapping)) {
continue;
}
}
//
// add all others to the structure list
//
structList.addElement(structs[i]);
}
}
//
if (structList.size() > 0) {
structures = new Structure[structList.size()];
structList.copyInto(structures);
} else {
structures = null;
}
}
Aggregations