use of cbit.vcell.model.Model in project vcell by virtualcell.
the class StructureAnalyzer method refreshTotalSpeciesContextMappings.
/**
* This method was created in VisualAge.
*/
private void refreshTotalSpeciesContextMappings() throws java.beans.PropertyVetoException {
if (structures == null) {
return;
}
// System.out.println("StructureAnalyzer.refreshSpeciesContextMappings()");
// GeometryContext geoContext = mathMapping.getSimulationContext().getGeometryContext();
Model model = mathMapping_4_8.getSimulationContext().getReactionContext().getModel();
//
// note, the order of species is specified such that the first species have priority
// when the null space is solved for dependent variables. So the order of priority
// for elimination are as follows:
//
// 1) Species involved with fast reactions.
// 2) Species not involved with fast reactions.
//
Vector<SpeciesContextMapping> scmList = new Vector<SpeciesContextMapping>();
//
for (int i = 0; i < structures.length; i++) {
SpeciesContext[] speciesContexts = model.getSpeciesContexts(structures[i]);
for (int j = 0; j < speciesContexts.length; j++) {
SpeciesContext sc = speciesContexts[j];
SpeciesContextMapping scm = mathMapping_4_8.getSpeciesContextMapping(sc);
SpeciesContextSpec scs = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(sc);
if (scm.isFastParticipant() && !scs.isConstant()) {
scmList.addElement(scm);
}
}
}
//
for (int i = 0; i < structures.length; i++) {
SpeciesContext[] speciesContexts = model.getSpeciesContexts(structures[i]);
for (int j = 0; j < speciesContexts.length; j++) {
SpeciesContext sc = speciesContexts[j];
SpeciesContextMapping scm = mathMapping_4_8.getSpeciesContextMapping(sc);
SpeciesContextSpec scs = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(sc);
if (!scm.isFastParticipant() && !scs.isConstant()) {
scmList.addElement(scm);
}
}
}
if (scmList.size() > 0) {
speciesContextMappings = new SpeciesContextMapping[scmList.size()];
scmList.copyInto(speciesContextMappings);
for (int i = 0; i < speciesContextMappings.length; i++) {
speciesContextMappings[i].setRate(new Expression(0.0));
// System.out.println("speciesContextMappings["+i+"] = "+speciesContextMappings[i].getSpeciesContext().getName());
}
} else {
speciesContextMappings = null;
}
// System.out.println("StructureAnalyzer.refreshTotalSpeciesContextMapping(), speciesContextMappings.length = "+scmList.size());
//
// get all reactionSteps associated with these structures
//
Vector<ReactionStep> rsList = new Vector<ReactionStep>();
ReactionSpec[] allReactionSpecs = mathMapping_4_8.getSimulationContext().getReactionContext().getReactionSpecs();
for (int i = 0; i < allReactionSpecs.length; i++) {
if (allReactionSpecs[i].isExcluded()) {
continue;
}
ReactionStep rs = allReactionSpecs[i].getReactionStep();
for (int j = 0; j < structures.length; j++) {
if (rs.getStructure() == structures[j]) {
rsList.addElement(rs);
}
}
}
//
for (int i = 0; i < scmList.size(); i++) {
SpeciesContextMapping scm = (SpeciesContextMapping) scmList.elementAt(i);
if (scm.isPDERequired()) {
rsList.addElement(new DiffusionDummyReactionStep("DiffusionDummyReactionStep" + i, model, scm.getSpeciesContext().getStructure(), scm.getSpeciesContext()));
}
if (scm.hasEventAssignment()) {
rsList.addElement(new EventDummyReactionStep("EventDummyReactionStep" + i, model, scm.getSpeciesContext().getStructure(), scm.getSpeciesContext()));
}
if (scm.hasHybridReaction()) {
rsList.addElement(new HybridDummyReactionStep("HybridDummyReactionStep" + i, model, scm.getSpeciesContext().getStructure(), scm.getSpeciesContext()));
}
SimulationContext simContext = mathMapping_4_8.getSimulationContext();
if (simContext.isStoch() && simContext.getGeometry().getDimension() > 0 && !simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext()).isForceContinuous()) {
rsList.addElement(new ParticleDummyReactionStep("ParticleDummyReactionStep" + i, model, scm.getSpeciesContext().getStructure(), scm.getSpeciesContext()));
}
}
if (rsList.size() > 0) {
reactionSteps = new ReactionStep[rsList.size()];
rsList.copyInto(reactionSteps);
} else {
reactionSteps = null;
}
// System.out.println("StructureAnalyzer.refreshTotalSpeciesContextMapping(), reactionSteps.length = "+scmList.size());
}
use of cbit.vcell.model.Model in project vcell by virtualcell.
the class GeometryContext method setModel.
/**
* Sets the model property (cbit.vcell.model.Model) value.
* @param model The new value for the property.
* @see #getModel
*/
public void setModel(Model model) throws MappingException {
Model oldValue = fieldModel;
fieldModel = model;
try {
refreshStructureMappings();
refreshDependencies();
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new MappingException(e.getMessage());
}
firePropertyChange("model", oldValue, model);
}
use of cbit.vcell.model.Model in project vcell by virtualcell.
the class ReactionContext method setModel.
/**
* Sets the model property (cbit.vcell.model.Model) value.
* @param model The new value for the property.
* @see #getModel
*/
public void setModel(Model model) throws MappingException, java.beans.PropertyVetoException {
Model oldValue = fieldModel;
fieldModel = model;
if (oldValue != null) {
oldValue.removePropertyChangeListener(this);
oldValue.removeVetoableChangeListener(this);
}
if (fieldModel != null) {
fieldModel.addPropertyChangeListener(this);
fieldModel.addVetoableChangeListener(this);
}
refreshSpeciesContextSpecs();
refreshReactionSpecs();
refreshReactionRuleSpecs();
firePropertyChange("model", oldValue, model);
}
use of cbit.vcell.model.Model in project vcell by virtualcell.
the class RulebasedTransformer method transform.
@Override
public final RulebasedTransformation transform(SimulationContext originalSimContext, MathMappingCallback mathMappingCallback, NetworkGenerationRequirements netGenReq_NOT_USED) {
SimulationContext transformedSimContext;
keyMap.clear();
try {
transformedSimContext = (SimulationContext) BeanUtils.cloneSerializable(originalSimContext);
transformedSimContext.getModel().refreshDependencies();
transformedSimContext.refreshDependencies();
transformedSimContext.compareEqual(originalSimContext);
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
throw new RuntimeException("Unexpected transform exception: " + e.getMessage());
}
final Model transformedModel = transformedSimContext.getModel();
transformedModel.refreshDependencies();
transformedSimContext.refreshDependencies1(false);
ArrayList<ModelEntityMapping> entityMappings = new ArrayList<ModelEntityMapping>();
try {
transform(originalSimContext, transformedSimContext, entityMappings, mathMappingCallback);
} catch (PropertyVetoException e) {
e.printStackTrace();
throw new RuntimeException("Unexpected transform exception: " + e.getMessage());
}
ModelEntityMapping[] modelEntityMappings = entityMappings.toArray(new ModelEntityMapping[0]);
return new RulebasedTransformation(originalSimContext, transformedSimContext, modelEntityMappings, ruleElementMap, rulesForwardMap, rulesReverseMap);
}
use of cbit.vcell.model.Model in project vcell by virtualcell.
the class BioModelEditorModelPanel method addNewReaction.
private void addNewReaction() {
if (reactionEditorPanel == null) {
reactionEditorPanel = new ReactionEditorPanel();
}
Model model = getModel();
reactionEditorPanel.setModel(model);
while (true) {
int confirm = DialogUtils.showComponentOKCancelDialog(this, reactionEditorPanel, "New Reaction");
if (confirm == javax.swing.JOptionPane.OK_OPTION) {
Structure reactionStructure = reactionEditorPanel.getStructure();
String reactionName = reactionEditorPanel.getReactionName();
String equationString = reactionEditorPanel.getEquationString();
try {
if (reactionName == null || reactionName.trim().length() == 0 || equationString == null || equationString.trim().length() == 0) {
throw new RuntimeException("Reaction name or equation cannot be empty.");
}
if (getModel().getReactionStep(reactionName) != null) {
throw new RuntimeException("Reaction '" + reactionName + "' already exists.");
}
ReactionStep simpleReaction = new SimpleReaction(model, reactionStructure, "dummy", true);
ReactionParticipant[] rpArray = ModelProcessEquation.parseReaction(simpleReaction, getModel(), equationString);
// StructureTopology structTopology = getModel().getStructureTopology();
// for (ReactionParticipant reactionParticipant : rpArray) {
// if (reactionParticipant.getStructure() == reactionStructure) {
// continue;
// }
// if (reactionStructure instanceof Feature) {
// throw new RuntimeException("Species '" + reactionParticipant.getSpeciesContext().getName() + "' must be in the same volume compartment as reaction.");
// } else if (reactionStructure instanceof Membrane) {
// if (structTopology.getInsideFeature((Membrane)reactionStructure) != reactionParticipant.getStructure()
// && (structTopology.getOutsideFeature((Membrane)reactionStructure)) != reactionParticipant.getStructure()) {
// throw new RuntimeException("Species '" + reactionParticipant.getSpeciesContext().getName() + "' must be adjacent to " +
// "or within reaction's structure '" + reactionStructure.getName() + "'.");
// }
// }
// }
simpleReaction = getModel().createSimpleReaction(reactionStructure);
for (ReactionParticipant rp : rpArray) {
SpeciesContext speciesContext = rp.getSpeciesContext();
if (bioModel.getModel().getSpeciesContext(speciesContext.getName()) == null) {
bioModel.getModel().addSpecies(speciesContext.getSpecies());
bioModel.getModel().addSpeciesContext(speciesContext);
}
}
simpleReaction.setReactionParticipants(rpArray);
simpleReaction.setName(reactionName);
setSelectedObjects(new Object[] { simpleReaction });
break;
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, e.getMessage());
}
} else {
break;
}
}
}
Aggregations