use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class ReactionCartoonTool method lineAction.
private void lineAction(SpeciesContext speciesContextStart, ReactionStep reactionEnd) throws Exception {
Structure endStructure = reactionEnd.getStructure();
Structure startStructure = speciesContextStart.getStructure();
if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
int stoichiometry = 1;
Reactant reactant = null;
for (ReactionParticipant participant : reactionEnd.getReactionParticipants()) {
if (participant instanceof Reactant && participant.getSpeciesContext().equals(speciesContextStart)) {
reactant = (Reactant) participant;
}
}
if (reactant != null) {
// only increase stoichiometry if reaction is SimpleReaction
if (reactionEnd instanceof SimpleReaction) {
reactant.setStoichiometry(reactant.getStoichiometry() + 1);
}
Shape shape = getReactionCartoon().getShapeFromModelObject(reactant);
if (shape != null) {
shape.refreshLabel();
}
} else {
// add speciesContextEnd as pdt to reactionStart only if reactionStart is a SimpleRxn or if it is a FluxRxn and doesn't have a pdt.
if (reactionEnd instanceof SimpleReaction || ((reactionEnd instanceof FluxReaction) && !(reactionEnd.hasReactant()))) {
reactionEnd.addReactant(speciesContextStart, stoichiometry);
}
}
if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
// ============ change kinetics to lumped or warn user ?????????
// simpleReactionEnd.setKinetics(new GeneralLumpedKinetics(simpleReactionEnd));
}
getReactionCartoon().notifyChangeEvent();
}
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class ReactionCartoonTool method lineAction.
private void lineAction(Structure startStructure, Structure endStructure, Shape endShape) throws Exception, PropertyVetoException, ExpressionException {
Point startPos = edgeShape.getStart();
Point endPos = edgeShape.getEnd();
if (endStructure.equals(startStructure)) {
SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endStructure);
reaction.addReactant(speciesContext1, 1);
reaction.addProduct(speciesContext2, 1);
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(endStructure, speciesContext1, startPos);
positionShapeForObject(endStructure, speciesContext2, endPos);
positionShapeForObject(endStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
getGraphModel().clearSelection();
getGraphModel().select(reaction);
} else {
if (endStructure instanceof Membrane && startStructure instanceof Feature) {
Membrane endMembrane = (Membrane) endStructure;
Feature startFeature = (Feature) startStructure;
// if(structTopology.getOutsideFeature(endMembrane).equals(startFeature) || structTopology.getInsideFeature(endMembrane).equals(startFeature))
// {
SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startFeature);
SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endMembrane);
SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endMembrane);
reaction.addReactant(speciesContext1, 1);
reaction.addProduct(speciesContext2, 1);
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startFeature, speciesContext1, startPos);
positionShapeForObject(endMembrane, speciesContext2, endPos);
// finding correct insertion point for reaction, statements below should be put into a utility if used often
int memAbsXmin = endShape.getSpaceManager().getAbsLoc().x;
int memAbsXmax = memAbsXmin + endShape.getSpaceManager().getSize().width;
int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
int reactionAbsX = (startPos.x + endPos.x) / 2;
if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
reactionAbsX = memAbsXmin;
} else {
reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
}
positionShapeForObject(endMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
getGraphModel().clearSelection();
getGraphModel().select(reaction);
// }
} else if (endStructure instanceof Feature && startStructure instanceof Membrane) {
Membrane startMembrane = (Membrane) startStructure;
Feature endFeature = (Feature) endStructure;
// if(structTopology.getOutsideFeature(startMembrane).equals(endFeature) || structTopology.getInsideFeature(startMembrane).equals(endFeature))
// {
SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startMembrane);
SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endFeature);
SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startMembrane);
reaction.addReactant(speciesContext1, 1);
reaction.addProduct(speciesContext2, 1);
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startMembrane, speciesContext1, startPos);
positionShapeForObject(endFeature, speciesContext2, endPos);
// finding correct insertion point for reaction, statements below should be put into a utility if used often
int memAbsXmin = startShape.getSpaceManager().getAbsLoc().x;
int memAbsXmax = memAbsXmin + startShape.getSpaceManager().getSize().width;
int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
int reactionAbsX = (startPos.x + endPos.x) / 2;
if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
reactionAbsX = memAbsXmin;
} else {
reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
}
positionShapeForObject(startMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
getGraphModel().clearSelection();
getGraphModel().select(reaction);
// }
} else if (endStructure instanceof Feature && startStructure instanceof Feature) {
Feature startFeature = (Feature) startStructure;
Feature endFeature = (Feature) endStructure;
SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
reaction.addReactant(speciesContext1, 1);
reaction.addProduct(speciesContext2, 1);
reaction.setKinetics(new GeneralLumpedKinetics(reaction));
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startStructure, speciesContext1, startPos);
positionShapeForObject(endStructure, speciesContext2, endPos);
positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
getGraphModel().clearSelection();
getGraphModel().select(reaction);
} else if (endStructure instanceof Membrane && startStructure instanceof Membrane) {
SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
reaction.addReactant(speciesContext1, 1);
reaction.addProduct(speciesContext2, 1);
reaction.setKinetics(new GeneralLumpedKinetics(reaction));
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startStructure, speciesContext1, startPos);
positionShapeForObject(endStructure, speciesContext2, endPos);
positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
getGraphModel().clearSelection();
getGraphModel().select(reaction);
}
}
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class SpeciesContextSpec method convertConcentrationToParticles.
public Expression convertConcentrationToParticles(Expression iniConcentration) throws ExpressionException, MappingException {
Expression iniParticlesExpr = null;
Structure structure = getSpeciesContext().getStructure();
double structSize = computeStructureSize();
if (structure instanceof Membrane) {
// particles = iniConcentration(molecules/um2)*size(um2)
try {
iniParticlesExpr = new Expression((Math.round(iniConcentration.evaluateConstant() * structSize)));
} catch (ExpressionException e) {
iniParticlesExpr = Expression.mult(iniConcentration, new Expression(structSize)).flatten();
}
} else {
// convert concentration(particles/volume) to number of particles
// particles = [iniConcentration(uM)*size(um3)]/KMOLE
// @Note : 'kMole' variable here is used only as a var name, it does not represent the previously known ReservedSymbol KMOLE.
ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
VCUnitDefinition volSubstanceToStochastic = modelUnitSystem.getStochasticSubstanceUnit().divideBy(modelUnitSystem.getVolumeSubstanceUnit());
double volSubstanceToStochasticScale = volSubstanceToStochastic.getDimensionlessScale().doubleValue();
try {
iniParticlesExpr = new Expression((Math.round(iniConcentration.evaluateConstant() * structSize * volSubstanceToStochasticScale)));
} catch (ExpressionException e) {
Expression numeratorExpr = Expression.mult(iniConcentration, new Expression(structSize));
Expression exp = new Expression(volSubstanceToStochasticScale);
iniParticlesExpr = Expression.mult(numeratorExpr, exp).flatten();
}
}
return iniParticlesExpr;
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class CurrentClampElectricalDevice method initializeParameters.
private void initializeParameters() throws ExpressionException {
ElectricalDevice.ElectricalDeviceParameter[] parameters = new ElectricalDevice.ElectricalDeviceParameter[3];
//
// set the transmembrane current (total current, if necessary derive it from the current density).
//
ElectricalDeviceParameter transMembraneCurrent = null;
ModelUnitSystem modelUnitSystem = mathMapping.getSimulationContext().getModel().getUnitSystem();
VCUnitDefinition currentUnit = modelUnitSystem.getCurrentUnit();
if (currentClampStimulus instanceof TotalCurrentClampStimulus) {
TotalCurrentClampStimulus stimulus = (TotalCurrentClampStimulus) currentClampStimulus;
LocalParameter currentParameter = stimulus.getCurrentParameter();
transMembraneCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TransmembraneCurrent], new Expression(currentParameter.getExpression()), ROLE_TransmembraneCurrent, currentUnit);
} else if (currentClampStimulus instanceof CurrentDensityClampStimulus) {
CurrentDensityClampStimulus stimulus = (CurrentDensityClampStimulus) currentClampStimulus;
LocalParameter currentDensityParameter = stimulus.getCurrentDensityParameter();
//
// here we have to determine the expression for current (from current density).
//
Feature feature1 = currentClampStimulus.getElectrode().getFeature();
Feature feature2 = mathMapping.getSimulationContext().getGroundElectrode().getFeature();
Membrane membrane = null;
StructureTopology structTopology = mathMapping.getSimulationContext().getModel().getStructureTopology();
if (structTopology.getParentStructure(feature1) != null && structTopology.getOutsideFeature((Membrane) structTopology.getParentStructure(feature1)) == feature2) {
membrane = ((Membrane) structTopology.getParentStructure(feature1));
} else if (structTopology.getParentStructure(feature2) != null && structTopology.getOutsideFeature((Membrane) structTopology.getParentStructure(feature2)) == feature1) {
membrane = ((Membrane) structTopology.getParentStructure(feature2));
}
if (membrane == null) {
throw new RuntimeException("current clamp based on current density crosses multiple membranes, unable to " + "determine single membrane to convert current density into current in Application '" + mathMapping.getSimulationContext().getName() + "'.");
}
MembraneMapping membraneMapping = (MembraneMapping) mathMapping.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
StructureMappingParameter sizeParameter = membraneMapping.getSizeParameter();
Expression area = null;
if (mathMapping.getSimulationContext().getGeometry().getDimension() == 0 && (sizeParameter.getExpression() == null || sizeParameter.getExpression().isZero())) {
area = membraneMapping.getNullSizeParameterValue();
} else {
area = new Expression(sizeParameter, mathMapping.getNameScope());
}
transMembraneCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TransmembraneCurrent], Expression.mult(new Expression(currentDensityParameter.getExpression()), area), ROLE_TransmembraneCurrent, currentUnit);
} else {
throw new RuntimeException("unexpected current clamp stimulus type : " + currentClampStimulus.getClass().getName());
}
ElectricalDeviceParameter totalCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TotalCurrent], new Expression(transMembraneCurrent, getNameScope()), ROLE_TotalCurrent, currentUnit);
ElectricalDeviceParameter voltage = new ElectricalDeviceParameter(DefaultNames[ROLE_Voltage], null, ROLE_Voltage, modelUnitSystem.getVoltageUnit());
parameters[0] = totalCurrent;
parameters[1] = transMembraneCurrent;
parameters[2] = voltage;
//
// add any user-defined parameters
//
LocalParameter[] stimulusParameters = currentClampStimulus.getLocalParameters();
for (int i = 0; stimulusParameters != null && i < stimulusParameters.length; i++) {
if (stimulusParameters[i].getRole() == ElectricalStimulus.ElectricalStimulusParameterType.UserDefined) {
ElectricalDeviceParameter newParam = new ElectricalDeviceParameter(stimulusParameters[i].getName(), new Expression(stimulusParameters[i].getExpression()), ROLE_UserDefined, stimulusParameters[i].getUnitDefinition());
parameters = (ElectricalDeviceParameter[]) BeanUtils.addElement(parameters, newParam);
}
}
setParameters(parameters);
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class CurrentClampElectricalDevice method initializeParameters.
private void initializeParameters() throws ExpressionException {
ElectricalDevice.ElectricalDeviceParameter[] parameters = new ElectricalDevice.ElectricalDeviceParameter[3];
//
// set the transmembrane current (total current, if necessary derive it from the current density).
//
ElectricalDeviceParameter transMembraneCurrent = null;
ModelUnitSystem modelUnitSystem = mathMapping_4_8.getSimulationContext().getModel().getUnitSystem();
VCUnitDefinition currentUnit = modelUnitSystem.getCurrentUnit();
if (currentClampStimulus instanceof TotalCurrentClampStimulus) {
TotalCurrentClampStimulus stimulus = (TotalCurrentClampStimulus) currentClampStimulus;
LocalParameter currentParameter = stimulus.getCurrentParameter();
transMembraneCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TransmembraneCurrent], new Expression(currentParameter.getExpression()), ROLE_TransmembraneCurrent, currentUnit);
} else if (currentClampStimulus instanceof CurrentDensityClampStimulus) {
CurrentDensityClampStimulus stimulus = (CurrentDensityClampStimulus) currentClampStimulus;
LocalParameter currentDensityParameter = stimulus.getCurrentDensityParameter();
//
// here we have to determine the expression for current (from current density).
//
Feature feature1 = currentClampStimulus.getElectrode().getFeature();
Feature feature2 = mathMapping_4_8.getSimulationContext().getGroundElectrode().getFeature();
Membrane membrane = null;
StructureTopology structTopology = mathMapping_4_8.getSimulationContext().getModel().getStructureTopology();
if (structTopology.getParentStructure(feature1) != null && structTopology.getOutsideFeature((Membrane) structTopology.getParentStructure(feature1)) == feature2) {
membrane = ((Membrane) structTopology.getParentStructure(feature1));
} else if (structTopology.getParentStructure(feature2) != null && structTopology.getOutsideFeature((Membrane) structTopology.getParentStructure(feature2)) == feature1) {
membrane = ((Membrane) structTopology.getParentStructure(feature2));
}
if (membrane == null) {
throw new RuntimeException("current clamp based on current density crosses multiple membranes, unable to " + "determine single membrane to convert current density into current in Application '" + mathMapping_4_8.getSimulationContext().getName() + "'.");
}
MembraneMapping membraneMapping = (MembraneMapping) mathMapping_4_8.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
StructureMappingParameter sizeParameter = membraneMapping.getSizeParameter();
Expression area = null;
if (mathMapping_4_8.getSimulationContext().getGeometry().getDimension() == 0 && (sizeParameter.getExpression() == null || sizeParameter.getExpression().isZero())) {
area = membraneMapping.getNullSizeParameterValue();
} else {
area = new Expression(sizeParameter, mathMapping_4_8.getNameScope());
}
transMembraneCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TransmembraneCurrent], Expression.mult(new Expression(currentDensityParameter.getExpression()), area), ROLE_TransmembraneCurrent, currentUnit);
} else {
throw new RuntimeException("unexpected current clamp stimulus type : " + currentClampStimulus.getClass().getName());
}
ElectricalDeviceParameter totalCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TotalCurrent], new Expression(transMembraneCurrent, getNameScope()), ROLE_TotalCurrent, currentUnit);
ElectricalDeviceParameter voltage = new ElectricalDeviceParameter(DefaultNames[ROLE_Voltage], null, ROLE_Voltage, modelUnitSystem.getVoltageUnit());
parameters[0] = totalCurrent;
parameters[1] = transMembraneCurrent;
parameters[2] = voltage;
//
// add any user-defined parameters
//
LocalParameter[] stimulusParameters = currentClampStimulus.getLocalParameters();
for (int i = 0; stimulusParameters != null && i < stimulusParameters.length; i++) {
if (stimulusParameters[i].getRole() == ElectricalStimulus.ElectricalStimulusParameterType.UserDefined) {
ElectricalDeviceParameter newParam = new ElectricalDeviceParameter(stimulusParameters[i].getName(), new Expression(stimulusParameters[i].getExpression()), ROLE_UserDefined, stimulusParameters[i].getUnitDefinition());
parameters = (ElectricalDeviceParameter[]) BeanUtils.addElement(parameters, newParam);
}
}
setParameters(parameters);
}
Aggregations