use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class ReactionCartoonTool method resetDropTargets.
private void resetDropTargets(Boolean bDropTargetFlag, Boolean bStructureMode) {
Structure[] structures = getModel().getStructures();
for (int i = 0; i < structures.length; i++) {
((ReactionContainerShape) getGraphModel().getShapeFromModelObject(structures[i])).setDropTargetEnableLow(bDropTargetFlag, bStructureMode);
((ReactionContainerShape) getGraphModel().getShapeFromModelObject(structures[i])).setDropTargetEnableHigh(bDropTargetFlag, bStructureMode);
}
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class ReactionCartoonTool method mouseClicked.
@Override
public void mouseClicked(MouseEvent event) {
Point screenPoint = new Point(event.getX(), event.getY());
Point worldPoint = screenToWorld(screenPoint);
try {
if (event.getButton() != MouseEvent.BUTTON1) {
return;
}
switch(mode) {
case SELECT:
{
if (event.getClickCount() == 2) {
final Shape selectedShape = getReactionCartoon().getSelectedShape();
if (selectedShape instanceof ReactionContainerShape || selectedShape instanceof SpeciesContextShape || selectedShape instanceof SimpleReactionShape || selectedShape instanceof FluxReactionShape || selectedShape instanceof ReactionRuleDiagramShape || selectedShape instanceof RuleParticipantSignatureDiagramShape) {
editInPlace(selectedShape, worldPoint);
}
if (selectedShape != null) {
menuAction(selectedShape, CartoonToolMiscActions.Properties.MENU_ACTION);
}
}
break;
}
case STEP:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
if (getReactionCartoon().getStructureSuite().areReactionsShownFor(structure)) {
ReactionStep reactionStep = getReactionCartoon().getModel().createSimpleReaction(structure);
positionShapeForObject(structure, reactionStep, worldPoint);
saveDiagram();
}
}
break;
}
case FLUX:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
FluxReaction fluxReaction = getReactionCartoon().getModel().createFluxReaction(membrane);
ReactionStepShape frShape = (ReactionStepShape) getReactionCartoon().getShapeFromModelObject(fluxReaction);
Point parentLocation = frShape.getParent().getSpaceManager().getAbsLoc();
frShape.getSpaceManager().setRelPos(worldPoint.x - parentLocation.x, worldPoint.y - parentLocation.y);
saveDiagram();
// setMode(SELECT_MODE);
} else {
// setMode(SELECT_MODE);
// throw new Exception("fluxes only applicable to membranes");
}
}
break;
}
case SPECIES:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) pickedShape).getStructure());
reactionCartoon.clearSelection();
getGraphModel().select(speciesContext);
positionShapeForObject(speciesContext.getStructure(), speciesContext, worldPoint);
// showCreateSpeciesContextDialog(getGraphPane(), getReactionCartoon().getModel(), ((ReactionContainerShape) pickedShape).getStructure(), scShapeLocation);
saveDiagram();
}
}
default:
break;
}
} catch (Exception e) {
System.out.println("CartoonTool.mouseClicked: uncaught exception");
e.printStackTrace(System.out);
Point canvasLoc = getGraphPane().getLocationOnScreen();
canvasLoc.x += screenPoint.x;
canvasLoc.y += screenPoint.y;
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
}
use of cbit.vcell.model.Structure 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.Structure 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.Structure in project vcell by virtualcell.
the class GeneratedReactionTableRow method deriveRule.
private void deriveRule(String inputString, Model tempModel) {
if (owner != null && owner.getSimulationContext() != null) {
List<MolecularType> mtList = owner.getSimulationContext().getModel().getRbmModelContainer().getMolecularTypeList();
try {
tempModel.getRbmModelContainer().setMolecularTypeList(mtList);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
throw new RuntimeException("Unexpected exception setting " + MolecularType.typeName + " list: " + e1.getMessage(), e1);
}
} else {
// This should not be possible
throw new RuntimeException("Owner or SimulationContext are null.");
}
int arrowIndex = inputString.indexOf("<->");
boolean bReversible = true;
if (arrowIndex < 0) {
arrowIndex = inputString.indexOf("->");
bReversible = false;
}
String left = inputString.substring(0, arrowIndex).trim();
String right = inputString.substring(arrowIndex + (bReversible ? 3 : 2)).trim();
if (left.length() == 0 && right.length() == 0) {
return;
}
String name = reactionObject.getRuleName();
if (name.contains(GeneratedReactionTableModel.reverse)) {
name = name.substring(GeneratedReactionTableModel.reverse.length());
}
if (name.endsWith(ReactionRule.DirectHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.DirectHalf));
}
if (name.endsWith(ReactionRule.InverseHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.InverseHalf));
}
// try to get the name of the original structure from the original rule and make here another structure with the same name
String strStructure = null;
Structure ruleStructure;
SimulationContext sc = owner.getSimulationContext();
ReactionRule rr = sc.getModel().getRbmModelContainer().getReactionRule(name);
if (rr != null && rr.getStructure() != null) {
strStructure = rr.getStructure().getName();
}
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
try {
tempModel.addFeature(strStructure);
} catch (ModelException | PropertyVetoException e) {
e.printStackTrace();
}
}
ruleStructure = tempModel.getStructure(strStructure);
} else {
throw new RuntimeException("Failed to recover a Structure name from the Reaction Rule: " + name);
}
// making the fake rules just for display purpose, actually they are the flattened reactions resulted from bngl
// the name is probably not unique, it's likely that many flattened reactions are derived from the same rule
reactionRule = tempModel.getRbmModelContainer().createReactionRule(name, ruleStructure, bReversible);
String regex = "[^!]\\+";
String[] patterns = left.split(regex);
for (String spString : patterns) {
try {
spString = spString.trim();
// if compartments are present, we're making some fake compartments in the tempModel just for compartment name display purposes
SpeciesPattern speciesPattern = (SpeciesPattern) RbmUtils.parseSpeciesPattern(spString, tempModel);
strStructure = RbmUtils.parseCompartment(spString, tempModel);
speciesPattern.resolveBonds();
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
tempModel.addFeature(strStructure);
}
structure = tempModel.getStructure(strStructure);
} else {
// if nothing explicit for a participant, we use by default the structure of the rule
structure = ruleStructure;
}
reactionRule.addReactant(new ReactantPattern(speciesPattern, structure));
} catch (Throwable ex) {
ex.printStackTrace();
return;
}
}
patterns = right.split(regex);
for (String spString : patterns) {
try {
spString = spString.trim();
SpeciesPattern speciesPattern = (SpeciesPattern) RbmUtils.parseSpeciesPattern(spString, tempModel);
strStructure = RbmUtils.parseCompartment(spString, tempModel);
speciesPattern.resolveBonds();
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
tempModel.addFeature(strStructure);
}
structure = tempModel.getStructure(strStructure);
} else {
structure = ruleStructure;
}
reactionRule.addProduct(new ProductPattern(speciesPattern, structure));
} catch (Throwable ex) {
ex.printStackTrace();
return;
}
}
}
Aggregations