use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class ReactStepDbDriver method populateStructureAndElectricalTopology.
public static void populateStructureAndElectricalTopology(Model model, HashMap<KeyValue, StructureKeys> structureKeysMap) throws DataAccessException {
//
for (Structure structure : model.getStructures()) {
// get parent struct
KeyValue parentKey = structureKeysMap.get(structure.getKey()).parentKey;
Structure parentStructure = null;
if (parentKey != null) {
for (Structure struct1 : model.getStructures()) {
if (struct1.getKey().equals(parentKey)) {
parentStructure = struct1;
break;
}
}
}
if (parentStructure != null) {
StructureTopology structureTopology = model.getStructureTopology();
if (structure instanceof Feature) {
Feature feature = (Feature) structure;
if (parentStructure instanceof Feature) {
// feature.setParentFeature((Feature)parent);
throw new DataAccessException("Feature is not permitted to be the parent of another feature");
} else if (parentStructure instanceof Membrane) {
structureTopology.setInsideFeature((Membrane) parentStructure, feature);
}
} else if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
if (parentStructure instanceof Feature) {
structureTopology.setOutsideFeature(membrane, (Feature) parentStructure);
} else {
throw new DataAccessException("Membrane '" + membrane.getName() + "' is not permitted to be the parent of another membrane '" + parentStructure.getName());
}
}
}
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
KeyValue negKey = structureKeysMap.get(structure.getKey()).negKey;
if (negKey != null) {
for (Structure struct : model.getStructures()) {
if (struct instanceof Feature && struct.getKey().equals(negKey)) {
Feature feature = (Feature) struct;
model.getElectricalTopology().setNegativeFeature(membrane, feature);
break;
}
}
}
KeyValue posKey = structureKeysMap.get(structure.getKey()).posKey;
if (posKey != null) {
for (Structure struct : model.getStructures()) {
if (struct instanceof Feature && struct.getKey().equals(posKey)) {
Feature feature = (Feature) struct;
model.getElectricalTopology().setPositiveFeature(membrane, feature);
break;
}
}
}
}
}
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class ReactionCartoonTool method lineActon.
private void lineActon(Structure startStructure, ReactionStep reactionEnd) throws Exception {
Structure endStructure = reactionEnd.getStructure();
if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
// if reactionStart is a SimpleRxn OR FluxRxn without a product, add speciesContext as reactant
if ((reactionEnd instanceof SimpleReaction) || ((reactionEnd instanceof FluxReaction) && !reactionEnd.hasReactant())) {
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(startStructure);
reactionEnd.addReactant(speciesContext, 1);
positionShapeForObject(startStructure, speciesContext, edgeShape.getStart());
}
if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
// ============ change kinetics to lumped or warn user ?????????
// simpleReaction.setKinetics(new GeneralLumpedKinetics(simpleReaction));
}
getReactionCartoon().notifyChangeEvent();
}
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class ReactionCartoonTool method updateRXContainerDropTargetInfoMap.
private HashMap<RXContainerDropTargetInfo, Boolean> updateRXContainerDropTargetInfoMap(Point pointWorld) {
HashMap<RXContainerDropTargetInfo, Boolean> rxContainerDropTargetInfoMap = null;
if (rxContainerDropTargetInfoMap == null) {
// System.out.println("-----redoing map...");
AllStructureSuite allStructureSuite = (getReactionCartoon().getStructureSuite() instanceof AllStructureSuite ? (AllStructureSuite) getReactionCartoon().getStructureSuite() : null);
if (allStructureSuite == null) {
throw new RuntimeException("Expecting " + AllStructureSuite.class.getName());
}
rxContainerDropTargetInfoMap = new HashMap<ReactionCartoonTool.RXContainerDropTargetInfo, Boolean>();
Structure[] originalOrderedStructArr = allStructureSuite.getStructures().toArray(new Structure[0]);
for (int i = 0; i < originalOrderedStructArr.length; i++) {
Shape currentRXContainerShape = getReactionCartoon().getShapeFromModelObject(originalOrderedStructArr[i]);
if (i == 0) {
rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, null, RXContainerDropTargetInfo.INSERT_BEGINNING), false);
} else {
rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, (ReactionContainerShape) getReactionCartoon().getShapeFromModelObject(originalOrderedStructArr[i - 1]), null), false);
}
if (i == (originalOrderedStructArr.length - 1)) {
rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, null, RXContainerDropTargetInfo.INSERT_END), false);
}
}
}
// System.out.println("-----Starting to update selection..."+pointWorld);
for (RXContainerDropTargetInfo rxcContainerDropTargetInfo : rxContainerDropTargetInfoMap.keySet()) {
if (rxcContainerDropTargetInfo.absoluteRectangle.contains(pointWorld)) {
// System.out.println(rxcContainerDropTargetInfo.dropShape.getLabel()+" "+rxcContainerDropTargetInfo.closestNeighborShape);
rxContainerDropTargetInfoMap.put(rxcContainerDropTargetInfo, true);
} else {
rxContainerDropTargetInfoMap.put(rxcContainerDropTargetInfo, false);
}
}
return rxContainerDropTargetInfoMap;
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class ReactionCartoonTool method lineAction.
private void lineAction(SpeciesContext speciesContextStart, SpeciesContext speciesContextEnd) throws Exception {
Structure endStructure = speciesContextEnd.getStructure();
Structure startStructure = speciesContextStart.getStructure();
Model model = getModel();
ReactionStep reaction = null;
Point startPos = edgeShape.getStart();
Point endPos = edgeShape.getEnd();
Structure reactionStructure = null;
boolean bLumpedKinetics = false;
if (startStructure != endStructure) {
if (startStructure instanceof Feature && endStructure instanceof Feature) {
// Feature-speciesContext ==> Feature-speciesContext
Membrane membraneBetween = model.getStructureTopology().getMembrane((Feature) startStructure, (Feature) endStructure);
// Feature-speciesContext ==> Feature-speciesContext with membrane in between : add reaction in Membrane (scStart : reactant; scEnd : pdt)
if (membraneBetween != null) {
reactionStructure = membraneBetween;
} else {
// Feature-speciesContext ==> Feature-speciesContext with no membrane between : create a lumped reaction in startFeature
reactionStructure = startStructure;
bLumpedKinetics = true;
}
} else if (startStructure instanceof Feature && endStructure instanceof Membrane) {
// Feature-speciesContext ==> Membrane-speciesContext : create membrane reaction ; add scStart : reactant and scEnd : pdt.
reactionStructure = endStructure;
} else if (startStructure instanceof Membrane && endStructure instanceof Feature) {
// Membrane-speciesContext ==> Feature-speciesContext : create reaction in membrane; scStart : reactant, scEnd : pdt.
reactionStructure = startStructure;
} else if (startStructure instanceof Membrane && endStructure instanceof Membrane) {
// Membrane-speciesContext ==> Membrane-speciesContext : the 2 membranes are different : create lumped reaction in endMembrane
reactionStructure = endStructure;
bLumpedKinetics = true;
}
} else {
// startStructure == endStructure : create reaction in structure
reactionStructure = startStructure;
}
reaction = model.createSimpleReaction(reactionStructure);
if (bLumpedKinetics) {
reaction.setKinetics(new GeneralLumpedKinetics(reaction));
}
reaction.addReactant(speciesContextStart, 1);
reaction.addProduct(speciesContextEnd, 1);
positionShapeForObject(reactionStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
getReactionCartoon().notifyChangeEvent();
getGraphModel().clearSelection();
getGraphModel().select(reaction);
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class ReactionCartoonTool method addStructure.
private void addStructure(boolean bMembrane, RXContainerDropTargetInfo selectedContainerDropTargetInfo) {
Integer insertFlag = selectedContainerDropTargetInfo.insertFlag;
try {
Structure myStructure = null;
if (bMembrane) {
myStructure = ReactionCartoonTool.this.getModel().createMembrane();
} else {
myStructure = ReactionCartoonTool.this.getModel().createFeature();
}
ArrayList<Structure> diagramStructures = new ArrayList<Structure>(ReactionCartoonTool.this.getReactionCartoon().getStructureSuite().getStructures());
diagramStructures.remove(myStructure);
if (new Integer(RXContainerDropTargetInfo.INSERT_BEGINNING).equals(insertFlag)) {
diagramStructures.add(0, myStructure);
} else if (new Integer(RXContainerDropTargetInfo.INSERT_END).equals(insertFlag)) {
diagramStructures.add(myStructure);
} else {
diagramStructures.add(diagramStructures.indexOf(selectedContainerDropTargetInfo.dropShape.getStructure()), myStructure);
}
((AllStructureSuite) getReactionCartoon().getStructureSuite()).setModelStructureOrder(true);
// ReactionCartoonTool.this.getModel().setStructures(structures.toArray(new Structure[0]));
ArrayList<Diagram> newDiagramOrderList = new ArrayList<Diagram>();
for (Structure structure : diagramStructures) {
newDiagramOrderList.add(getModel().getDiagram(structure));
}
getModel().setDiagrams(newDiagramOrderList.toArray(new Diagram[0]));
lastRXContainerDropTargetInfoMap = updateRXContainerDropTargetInfoMap(new Point(-1, -1));
resetDropTargets(false, mode == Mode.STRUCTURE);
getGraphPane().repaint();
} catch (Exception e2) {
e2.printStackTrace();
DialogUtils.showErrorDialog(getGraphPane(), "Error adding structure: " + e2.getMessage());
}
}
Aggregations