use of cbit.vcell.model.Feature 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.Feature 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.Feature in project vcell by virtualcell.
the class ElectricalStimulusPanel method newStimulus.
/**
* Comment
*/
private void newStimulus() {
try {
SimulationContext simContext = getSimulationContext();
if (simContext == null) {
return;
}
//
// When the voltage and current clamp radio buttons is deselected within the same simulation context (application),
// display a warning saying that the present clamp settings will be lost (not applicable when the 'no clamp'
// radiobutton is deselected.
//
ElectricalStimulus currElectricalStimulus = null;
if (simContext.getElectricalStimuli() != null && simContext.getElectricalStimuli().length > 0) {
currElectricalStimulus = simContext.getElectricalStimuli()[0];
}
//
// ignore selection if already selected
// warn upon deselect if about to loose edits
//
Clamp selectedClamp = (Clamp) clampComboBox.getSelectedItem();
if (currElectricalStimulus instanceof VoltageClampStimulus) {
if (selectedClamp == Clamp.Voltage_Clamp) {
return;
}
String response = PopupGenerator.showWarningDialog(this, "warning: the present voltage clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
// revert back to Voltage Clamp
clampComboBox.setSelectedItem(Clamp.Voltage_Clamp);
return;
}
}
if (currElectricalStimulus instanceof TotalCurrentClampStimulus) {
if (selectedClamp == Clamp.Total_Current_Clamp) {
return;
}
String response = PopupGenerator.showWarningDialog(this, "warning: the present current clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
// revert back to Current Clamp
clampComboBox.setSelectedItem(Clamp.Total_Current_Clamp);
return;
}
}
if (currElectricalStimulus instanceof CurrentDensityClampStimulus) {
if (selectedClamp == Clamp.Current_Density_Clamp) {
return;
}
String response = PopupGenerator.showWarningDialog(this, "warning: the present current clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
// revert back to Current Clamp
clampComboBox.setSelectedItem(Clamp.Current_Density_Clamp);
return;
}
}
if (currElectricalStimulus == null && selectedClamp == Clamp.No_Clamp) {
return;
}
StructureTopology structTopology = getSimulationContext().getModel().getStructureTopology();
Structure[] structures = getSimulationContext().getModel().getStructures();
ArrayList<Feature> features = new ArrayList<Feature>();
for (Structure structure : structures) {
if (structure instanceof Feature) {
features.add((Feature) structure);
}
}
if (features.size() < 2) {
PopupGenerator.showErrorDialog(this, "error: electrodes must be placed in distinct volumetric structures, found " + features.size() + " volumetric structures in model");
return;
}
Feature groundFeature = features.get(0);
Feature clampedFeature = features.get(1);
//
if (selectedClamp == Clamp.Total_Current_Clamp) {
if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof TotalCurrentClampStimulus)) {
Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
TotalCurrentClampStimulus ccStimulus = new TotalCurrentClampStimulus(probeElectrode, "ccElectrode", new Expression(0.0), simContext);
System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
simContext.setElectricalStimuli(new ElectricalStimulus[] { ccStimulus });
simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
}
}
//
if (selectedClamp == Clamp.Current_Density_Clamp) {
if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof CurrentDensityClampStimulus)) {
Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
CurrentDensityClampStimulus ccStimulus = new CurrentDensityClampStimulus(probeElectrode, "ccElectrode", new Expression(0.0), simContext);
System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
simContext.setElectricalStimuli(new ElectricalStimulus[] { ccStimulus });
simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
}
}
//
if (selectedClamp == Clamp.No_Clamp) {
if (simContext.getElectricalStimuli().length > 0) {
simContext.setElectricalStimuli(new ElectricalStimulus[0]);
}
}
//
if (selectedClamp == Clamp.Voltage_Clamp) {
if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof VoltageClampStimulus)) {
Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
VoltageClampStimulus vcStimulus = new VoltageClampStimulus(probeElectrode, "vcElectrode", new Expression(0.0), simContext);
System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
simContext.setElectricalStimuli(new ElectricalStimulus[] { vcStimulus });
simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
}
}
} catch (java.beans.PropertyVetoException e) {
PopupGenerator.showErrorDialog(this, "Error setting electrical stimulus: " + e.getMessage());
}
}
use of cbit.vcell.model.Feature in project vcell by virtualcell.
the class ElectrodePanel method selectFeature.
/**
* Comment
*/
private void selectFeature() {
Feature[] features = (electrodeFeatureListProvider != null ? electrodeFeatureListProvider.getFeatures(this) : new Feature[0]);
if (features == null || features.length == 0) {
PopupGenerator.showErrorDialog(this, "No defined feature present !");
return;
}
String[] featureNames = new String[features.length];
for (int i = 0; i < featureNames.length; i++) {
featureNames[i] = features[i].getName();
}
String selection = (String) PopupGenerator.showListDialog(this, featureNames, "Select feature for electrode:");
if (selection == null) {
return;
}
Feature feature = null;
for (int i = 0; i < features.length; i++) {
if (features[i].getName().equals(selection)) {
feature = features[i];
break;
}
}
try {
if (feature == null) {
throw new Exception("Couldn't find Structure for selected name '" + selection + "'");
}
getelectrode1().setFeature(feature);
} catch (Exception e) {
handleException(e);
PopupGenerator.showErrorDialog(this, "Error changing feature for electrode", e);
}
}
use of cbit.vcell.model.Feature in project vcell by virtualcell.
the class SimulationContext method refreshElectrodes.
/**
* This method was created by a SmartGuide.
*/
private void refreshElectrodes() {
//
// step through all stimuli
//
// if any are added or removed, then create new array
ElectricalStimulus[] newStimuli = fieldElectricalStimuli;
Structure[] modelStructures = getModel().getStructures();
for (int i = 0; i < newStimuli.length; i++) {
ElectricalStimulus stimulus = newStimuli[i];
Electrode electrode = stimulus.getElectrode();
Feature feature = electrode.getFeature();
Feature newFeature = null;
//
for (int j = 0; j < modelStructures.length; j++) {
Structure modelStructure = modelStructures[j];
if (modelStructure.compareEqual(feature)) {
newFeature = (Feature) modelStructure;
}
}
//
if (newFeature != null) {
try {
electrode.setFeature(newFeature);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
}
} else {
newStimuli = (ElectricalStimulus[]) BeanUtils.removeElement(newStimuli, stimulus);
i--;
}
}
if (newStimuli != fieldElectricalStimuli) {
try {
setElectricalStimuli(newStimuli);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
//
if (getGroundElectrode() != null) {
Feature feature = getGroundElectrode().getFeature();
Feature newFeature = null;
//
for (int j = 0; j < modelStructures.length; j++) {
Structure modelStructure = modelStructures[j];
if (modelStructure.compareEqual(feature)) {
newFeature = (Feature) modelStructure;
}
}
//
if (newFeature != null) {
try {
getGroundElectrode().setFeature(newFeature);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
}
} else {
try {
setGroundElectrode(null);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
}
}
}
}
Aggregations