use of cbit.vcell.model.SimpleReaction 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.SimpleReaction in project vcell by virtualcell.
the class KineticsTypeTemplatePanel method initKineticChoices.
private void initKineticChoices() {
KineticsDescription[] kineticTypes = reactionStep == null || reactionStep instanceof SimpleReaction ? Simple_Reaction_Kinetic_Types : Flux_Reaction_KineticTypes;
javax.swing.DefaultComboBoxModel model = new DefaultComboBoxModel();
for (int i = 0; i < kineticTypes.length; i++) {
model.addElement(kineticTypes[i]);
}
getKineticsTypeComboBox().setModel(model);
return;
}
use of cbit.vcell.model.SimpleReaction in project vcell by virtualcell.
the class SimpleReactionPanel method setTornOffSimpleReaction.
/**
* Set the TornOffSimpleReaction to a new value.
* @param newValue cbit.vcell.model.SimpleReaction
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void setTornOffSimpleReaction(SimpleReaction newValue) {
if (ivjTornOffSimpleReaction != newValue) {
try {
SimpleReaction oldValue = getTornOffSimpleReaction();
/* Stop listening for events from the current object */
if (ivjTornOffSimpleReaction != null) {
ivjTornOffSimpleReaction.removePropertyChangeListener(ivjEventHandler);
}
ivjTornOffSimpleReaction = newValue;
/* Listen for events from the new object */
if (ivjTornOffSimpleReaction != null) {
ivjTornOffSimpleReaction.addPropertyChangeListener(ivjEventHandler);
}
connPtoP1SetSource();
getReactionCanvas().setReactionStep(ivjTornOffSimpleReaction);
if (ivjTornOffSimpleReaction != null) {
getSimpleReactionNameTextField().setText(getTornOffSimpleReaction().getName());
}
getReactionElectricalPropertiesPanel1().setKinetics(ivjTornOffSimpleReaction.getKinetics());
boolean electricalPropertiesVisible = ivjTornOffSimpleReaction != null && ivjTornOffSimpleReaction.getStructure() instanceof Membrane;
getReactionElectricalPropertiesPanel1().setVisible(electricalPropertiesVisible);
getKineticsTypeTemplatePanel().setReactionStep(getSimpleReaction());
firePropertyChange("simpleReaction", oldValue, newValue);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
;
// user code begin {3}
// user code end
}
use of cbit.vcell.model.SimpleReaction in project vcell by virtualcell.
the class TransformMassActionTableModel method saveTransformedReactions.
public void saveTransformedReactions() throws Exception {
// isTransformable and TransformedREactions are stored according to the indexes in model reaction steps.
boolean[] isTransformable = getTransformMassActions().getIsTransformable();
TransformMassActions.TransformedReaction[] trs = getTransformMassActions().getTransformedReactionSteps();
ReactionStep[] origReactions = getModel().getReactionSteps();
// names of those who can be transformed and will be transformed
String okTransReacNames = "";
// names of those who can be transformed and will not be transformed
String noTransReacNames = "";
// names of those who can not be transformed
String errReacNames = "";
for (int i = 0; i < isTransformable.length; i++) {
if (trs[i].getTransformType() == TransformMassActions.TransformedReaction.TRANSFORMABLE && getIsSelected(i)) {
okTransReacNames = okTransReacNames + origReactions[i].getName() + ",";
} else if (trs[i].getTransformType() == TransformMassActions.TransformedReaction.TRANSFORMABLE && !getIsSelected(i)) {
noTransReacNames = noTransReacNames + origReactions[i].getName() + ",";
} else if (!isTransformable[i]) {
errReacNames = errReacNames + origReactions[i].getName() + ",";
}
}
// set transformed Mass Action kinetics to model reactions
for (int i = 0; i < origReactions.length; i++) {
if (getIsSelected(i)) {
// for simple reaction, we replace the original kinetics with MassActionKinetics if it wasn't MassActionKinetics
if (origReactions[i] instanceof SimpleReaction) {
if (!(origReactions[i].getKinetics() instanceof MassActionKinetics)) {
// ***Below we will physically change the simple reaction***
// put all kinetic parameters together into array newKps
Vector<Kinetics.KineticsParameter> newKps = new Vector<Kinetics.KineticsParameter>();
// get original kinetic parameters which are not current density and reaction rate.
// those parameters are basically the symbols in rate expression.
Vector<Kinetics.KineticsParameter> origKps = new Vector<Kinetics.KineticsParameter>();
Kinetics.KineticsParameter[] Kps = origReactions[i].getKinetics().getKineticsParameters();
for (int j = 0; j < Kps.length; j++) {
if (!(Kps[j].getRole() == Kinetics.ROLE_CurrentDensity || Kps[j].getRole() == Kinetics.ROLE_ReactionRate)) {
origKps.add(Kps[j]);
}
}
// create mass action kinetics for the original reaction step
MassActionKinetics maKinetics = new MassActionKinetics(origReactions[i]);
maKinetics.getKineticsParameterFromRole(Kinetics.ROLE_KForward).setExpression(trs[i].getMassActionFunction().getForwardRate());
maKinetics.getKineticsParameterFromRole(Kinetics.ROLE_KReverse).setExpression(trs[i].getMassActionFunction().getReverseRate());
// Kinetics)
for (int j = 0; j < maKinetics.getKineticsParameters().length; j++) {
newKps.add(maKinetics.getKineticsParameters(j));
}
// copy other kinetic parameters from original kinetics
for (int j = 0; j < origKps.size(); j++) {
newKps.add(origKps.elementAt(j));
}
// add parameters to mass action kinetics
KineticsParameter[] newParameters = new KineticsParameter[newKps.size()];
newParameters = (KineticsParameter[]) newKps.toArray(newParameters);
maKinetics.addKineticsParameters(newParameters);
// after adding all the parameters, we bind the forward/reverse rate expression with symbol table (the reaction step itself)
origReactions[i].getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_KForward).getExpression().bindExpression(origReactions[i]);
origReactions[i].getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_KReverse).getExpression().bindExpression(origReactions[i]);
}
}
// for flux, we set the flux reaction back, coz we will parse it to mass action form in stochastic math mapping.
// However, we don't physically change it.
}
}
String msg = "";
if (!okTransReacNames.equals("")) {
msg = msg + okTransReacNames + " have been transformed.\n";
}
// message to be displayed in popupdialog of DocumentWindow
if (!msg.equals("")) {
throw new Exception(msg);
}
}
use of cbit.vcell.model.SimpleReaction in project vcell by virtualcell.
the class ReactionCartoonFull method applyDefaults.
public void applyDefaults(Diagram diagram) {
List<NodeReference> nodeList = diagram.getNodeFullList();
List<NodeReference> orphansList = new ArrayList<NodeReference>();
for (int i = 0; i < nodeList.size(); i++) {
NodeReference node = nodeList.get(i);
Object obj = null;
Structure struct = diagram.getStructure();
boolean found = false;
switch(node.nodeType) {
case NodeReference.SIMPLE_REACTION_NODE:
obj = getModel().getReactionStep(node.name);
if (!(obj instanceof SimpleReaction)) {
System.out.println("ReactionCartoon.applyDefaults(), diagram reaction " + node.name + " type mismatch in model, using location anyway");
}
break;
case NodeReference.FLUX_REACTION_NODE:
obj = getModel().getReactionStep(node.name);
if (!(obj instanceof FluxReaction)) {
System.out.println("ReactionCartoon.applyDefaults(), diagram flux " + node.name + " type mismatch in model, using location anyway");
}
break;
case NodeReference.SPECIES_CONTEXT_NODE:
obj = getModel().getSpeciesContext(node.name);
break;
case NodeReference.REACTION_RULE_NODE:
obj = getModel().getRbmModelContainer().getReactionRule(node.name);
break;
case // obj is a RuleParticipantSignature
NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE:
for (RuleParticipantSignature signature : ruleParticipantSignatures) {
if (signature instanceof RuleParticipantLongSignature && signature.getStructure() == struct && signature.compareByCriteria(node.getName(), GroupingCriteria.full)) {
obj = signature;
found = true;
break;
}
}
if (!found) {
orphansList.add(node);
}
break;
case NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE:
System.out.println("ReactionCartoonFull, RULE_PARTICIPANT_SIGNATURE_SHORT_NODE detected");
for (RuleParticipantSignature signature : ruleParticipantSignatures) {
if (signature instanceof RuleParticipantShortSignature && signature.getStructure() == struct && signature.compareByCriteria(node.getName(), GroupingCriteria.full)) {
obj = signature;
found = true;
break;
}
}
if (!found) {
orphansList.add(node);
}
break;
}
// -- switch
Shape shape = getShapeFromModelObject(obj);
if (shape != null) {
Point relPosOld = shape.getRelPos();
Point relPosNew = node.location;
// In old models, the same node can appear in multiple diagrams.
// Now, we have only one diagram, so if a node has multiple positions,
// some would overwrite others.
// This attempts to prevent overwriting a position with a worse one.
// if(relPosOld.x + relPosOld.y < relPosNew.x + relPosNew.y) {
shape.setRelPos(relPosNew);
// }
}
}
if (!orphansList.isEmpty()) {
diagram.removeNodeReferences(NodeReference.Mode.full, orphansList);
}
}
Aggregations