use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class ReactStepDbDriver method getReactionParticipant.
/**
* This method was created in VisualAge.
* @return cbit.vcell.model.ReactionParticipant
* @param rset java.sql.ResultSet
* @exception java.sql.SQLException The exception description.
*/
private ReactionParticipant getReactionParticipant(QueryHashtable dbc, Connection con, ResultSet rset, ReactionStep rs) throws SQLException, DataAccessException {
//
// try to get ReactionParticipant from object cache
//
KeyValue rpKey = new KeyValue(rset.getBigDecimal(ReactPartTable.table.id.toString()));
ReactionParticipant rp = (ReactionParticipant) dbc.get(rpKey);
if (rp != null) {
return rp;
}
//
// get foreign keys
//
KeyValue speciesContextKey = new KeyValue(rset.getBigDecimal(ReactPartTable.table.scRef.toString()));
//
// get ReactionParticipant
//
rp = reactPartTable.getReactionParticipant(rpKey, rset);
//
// get referenced Objects (Species and Structure)
//
SpeciesContext speciesContext = modelDB.getSpeciesContext(dbc, con, speciesContextKey);
try {
rp.setSpeciesContext(speciesContext);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new DataAccessException("PropertyVetoException: " + e.getMessage());
}
rp.setReactionStep(rs);
// ========== Since there is no flux carrier in fluxReaction, this is not required?? ===========
// if (rp instanceof Flux && rs instanceof FluxReaction) {
// try {
// ((FluxReaction) rs).setFluxCarrier(speciesContext.getSpecies(), null);
// }catch (ModelException e){
// e.printStackTrace(System.out);
// throw new DataAccessException("ModelException: "+e.getMessage());
// }catch (PropertyVetoException e){
// e.printStackTrace(System.out);
// throw new DataAccessException("PropertyVetoException: "+e.getMessage());
// }
// }
//
// stick ReactionParticipant in object cache
//
dbc.put(rpKey, rp);
return rp;
}
use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class ReactStepDbDriver method getReactionParticipants.
/**
* getModel method comment.
*/
private ReactionParticipant[] getReactionParticipants(QueryHashtable dbc, Connection con, KeyValue reactStepID, ReactionStep rs) throws SQLException, DataAccessException, ObjectNotFoundException {
if (reactStepID == null) {
throw new IllegalArgumentException("Improper parameters for getReactionParticipants");
}
// log.print("ModelDbDriver.getReactionParticipants(reactStepID=" + reactStepID + ")");
String sql;
sql = " SELECT * " + " FROM " + reactPartTable.getTableName() + " WHERE " + reactPartTable.reactStepRef + " = " + reactStepID;
// System.out.println(sql);
java.util.Vector rpList = new java.util.Vector();
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
//
while (rset.next()) {
ReactionParticipant rp = getReactionParticipant(dbc, con, rset, rs);
rpList.addElement(rp);
}
//
if (rpList.size() == 0) {
System.out.println("WARNING:::::ReactionParticipants for reactionStep(id=" + reactStepID + ") not found");
}
} finally {
// Release resources include resultset
stmt.close();
}
ReactionParticipant[] reactionParticipants = new ReactionParticipant[rpList.size()];
rpList.copyInto(reactionParticipants);
return reactionParticipants;
}
use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class ReactionCartoonTool method getLineTypeFromDirection.
private LineType getLineTypeFromDirection(Shape startingShape, Point worldPoint) throws Exception {
Shape mouseOverShape = getReactionCartoon().pickWorld(worldPoint);
if (mouseOverShape instanceof ReactionStepShape) {
if (startingShape instanceof SpeciesContextShape) {
SpeciesContext speciesContext = (SpeciesContext) startingShape.getModelObject();
// check if the ReactionStep already has a Product for this SpeciesContext
ReactionStep reactionStep = (ReactionStep) mouseOverShape.getModelObject();
ReactionParticipant[] rps = reactionStep.getReactionParticipants();
if ((mouseOverShape instanceof SimpleReactionShape) || (mouseOverShape instanceof FluxReactionShape)) {
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.REACTANT;
}
// else if (mouseOverShape instanceof FluxReactionShape){
// for (int i = 0; i < rps.length; i++){
// if ((rps[i] instanceof Reactant || rps[i] instanceof Product) && rps[i].getSpeciesContext() == speciesContext) {
// return LineType.NULL;
// }
// }
// return LineType.FLUX;
// }
}
} else if (mouseOverShape instanceof SpeciesContextShape) {
SpeciesContext speciesContext = (SpeciesContext) mouseOverShape.getModelObject();
if (startingShape instanceof SpeciesContextShape) {
// straight from one species to another ... will create a reaction upon release
return LineType.PRODUCT;
} else if (startingShape instanceof ReactionStepShape) {
ReactionStep reactionStep = (ReactionStep) startingShape.getModelObject();
ReactionParticipant[] rps = reactionStep.getReactionParticipants();
// } else
if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.REACTANT;
}
}
}
return LineType.NULL;
}
use of cbit.vcell.model.ReactionParticipant 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.ReactionParticipant in project vcell by virtualcell.
the class ReactionCartoonTool method deleteReactionsAndSpecies.
public static void deleteReactionsAndSpecies(Component requester, ReactionStep[] reactionStepArr, SpeciesContext[] speciesContextArr) throws Exception, UserCancelException {
if ((speciesContextArr == null && reactionStepArr == null) || (reactionStepArr == null && speciesContextArr != null && speciesContextArr.length == 0) || (speciesContextArr == null && reactionStepArr != null && reactionStepArr.length == 0) || (speciesContextArr != null && speciesContextArr.length == 0 && reactionStepArr != null && reactionStepArr.length == 0)) {
return;
}
int rxCount = (reactionStepArr != null ? reactionStepArr.length : 0);
int speciesCount = (speciesContextArr != null ? speciesContextArr.length : 0);
boolean bHasBoth = speciesCount > 0 && rxCount > 0;
ReactionCartoon rxCartoon = null;
if (requester instanceof GraphPane && ((GraphPane) requester).getGraphModel() instanceof ReactionCartoon) {
rxCartoon = (ReactionCartoon) (((GraphPane) requester).getGraphModel());
} else if (requester instanceof ReactionCartoonEditorPanel) {
rxCartoon = ((ReactionCartoonEditorPanel) requester).getReactionCartoon();
} else {
throw new IllegalArgumentException("ReactionCartoonTool.deleteSpeciesContext not implemented for type '" + requester.getClass().getName() + "'");
}
DeleteSpeciesInfo deleteSpeciesInfo = null;
final String DETAILS = "Details...";
while (true) {
String response = DialogUtils.showWarningDialog(requester, RXSPECIES_DELETE + " " + (bHasBoth ? "Reactions and Species." : (rxCount > 0 ? "Reactions." : (speciesCount > 0 ? "Species." : ""))), RXSPECIES_DELETE + " " + (bHasBoth ? rxCount + " Reactions and " + speciesCount + " Species." : (rxCount > 0 ? rxCount + " Reactions." : (speciesCount > 0 ? speciesCount + " Species." : ""))), new String[] { RXSPECIES_DELETE, DETAILS, RXSPECIES_CANCEL }, RXSPECIES_DELETE);
if (response == null || response.equals(RXSPECIES_CANCEL)) {
throw UserCancelException.CANCEL_GENERIC;
}
deleteSpeciesInfo = (deleteSpeciesInfo == null ? detailsDeleteSpecies(requester, speciesContextArr, reactionStepArr, rxCartoon) : deleteSpeciesInfo);
if (response.equals(DETAILS)) {
TableListResult tableListResult = showDeleteDetails(requester, deleteSpeciesInfo, reactionStepArr, false);
// if(!tableListResult.selectedOption.equals(RXSPECIES_BACK)){
// //if(!tableListResult.selectedOption.equals((bCut?RXSPECIES_CUT:RXSPECIES_DELETE))){
// throw UserCancelException.CANCEL_GENERIC;
// }
} else {
break;
}
}
if (deleteSpeciesInfo != null) {
for (Boolean errors : deleteSpeciesInfo.getbUnresolvableHashMap().values()) {
if (errors) {
while (true) {
String response = DialogUtils.showWarningDialog(requester, "Error warning.", "Warning: 1 or more SpeciesContexts have Model references that could cause Model corruption if " + RXSPECIES_DELETE + ".", new String[] { DETAILS, RXSPECIES_CANCEL }, DETAILS);
if (response == null || response.equals(RXSPECIES_CANCEL)) {
throw UserCancelException.CANCEL_GENERIC;
}
showDeleteDetails(requester, deleteSpeciesInfo, reactionStepArr, true);
}
}
}
}
if (reactionStepArr != null) {
for (int i = 0; i < reactionStepArr.length; i += 1) {
rxCartoon.getModel().removeReactionStep(reactionStepArr[i]);
}
}
if (deleteSpeciesInfo != null) {
// remove all ReactionParticipants ("lines" between reaction and species in "Reaction Diagram") that have this speciesContext before deleting SpeciesContext
for (SpeciesContext objSpeciesContext : deleteSpeciesInfo.getRxPartHashMap().keySet()) {
if (deleteSpeciesInfo.getbUnresolvableHashMap().get(objSpeciesContext)) {
continue;
}
Iterator<ReactionParticipant> iterRxPart = deleteSpeciesInfo.getRxPartHashMap().get(objSpeciesContext).iterator();
while (iterRxPart.hasNext()) {
ReactionParticipant objRxPart = iterRxPart.next();
if (rxCartoon.getObjects().contains(objRxPart)) {
// Reaction delete may have already removed
objRxPart.getReactionStep().removeReactionParticipant(objRxPart);
}
}
}
// remove the SpeciesContext
for (int i = 0; i < speciesContextArr.length; i++) {
if (deleteSpeciesInfo.getbUnresolvableHashMap().get(speciesContextArr[i])) {
continue;
}
if (rxCartoon.getObjects().contains(speciesContextArr[i])) {
// Reaction delete may have already removed
rxCartoon.getModel().removeSpeciesContext(speciesContextArr[i]);
}
}
}
}
Aggregations