use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.
the class PathwayMapping method createReactionStepsFromTableRow.
private void createReactionStepsFromTableRow(BioModel bioModel, ComplexAssembly bioPaxObject, double stoich, String id, String location, ArrayList<ConversionTableRow> conversionTableRows, boolean addSubunits) throws Exception {
// get participants from table rows
if (bioModel == null) {
return;
}
// there is just one "normal" reaction but it is possible to have controls associated to it, we take them too
for (Process process : BioPAXUtil.getAllProcesses(bioModel.getPathwayModel(), bioPaxObject)) {
ArrayList<ConversionTableRow> participants = new ArrayList<ConversionTableRow>();
for (ConversionTableRow ctr : conversionTableRows) {
// find the participants of this process
if (ctr.interactionId() == null) {
// proteins that are brought in as molecular type only have interaction id == null
continue;
// because they don't participate to the interaction
}
if (ctr.interactionId().equals(bioPaxObject.getID())) {
participants.add(ctr);
}
}
// create reaction object
String name = getSafetyName(process.getName() + "_" + location);
ReactionStep reactionStep = bioModel.getModel().getReactionStep(name);
if (reactionStep == null) {
// create a new reactionStep object
ReactionStep simpleReactionStep = bioModel.getModel().createSimpleReaction(bioModel.getModel().getStructure(location));
simpleReactionStep.setName(name);
RelationshipObject newRelationship = new RelationshipObject(simpleReactionStep, bioPaxObject);
bioModel.getRelationshipModel().addRelationshipObject(newRelationship);
createReactionStep(bioModel, process, simpleReactionStep, newRelationship, participants, addSubunits);
addKinetics(simpleReactionStep, process);
} else {
// bioModel.getModel().getReactionStep(safeId).setStructure(bioModel.getModel().getStructure(location));
// add missing parts for the existing reactionStep
RelationshipObject newRelationship = new RelationshipObject(reactionStep, bioPaxObject);
bioModel.getRelationshipModel().addRelationshipObject(newRelationship);
createReactionStep(bioModel, process, reactionStep, newRelationship, participants, addSubunits);
addKinetics(reactionStep, process);
}
}
}
use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.
the class ReactionParticipantShape method getCurve.
@Override
protected final CubicCurve2D.Double getCurve() {
// TODO is this the best place for layout?
refreshLayoutSelf();
// default behavior of control points is for direction at ends to follow secant between end-points.
if (lastCurve_Start == null || !lastCurve_Start.equals(start) || lastCurve_End == null || !lastCurve_End.equals(end)) {
lastp1ctrl = new Point2D.Double((1.0 - FRACT_WEIGHT) * start.getX() + FRACT_WEIGHT * end.getX(), (1.0 - FRACT_WEIGHT) * start.getY() + FRACT_WEIGHT * end.getY());
}
Point2D.Double p2ctrl = new Point2D.Double(FRACT_WEIGHT * start.getX() + (1.0 - FRACT_WEIGHT) * end.getX(), FRACT_WEIGHT * start.getY() + (1.0 - FRACT_WEIGHT) * end.getY());
// check for siblings in the reaction (like a+a-> or a->a) and calculate a correction factor
// so that the edges won't overlap
correctionFactor = 0;
if (endShape instanceof ReactionStepShape) {
// index in the array of siblings
int myPosition = 0;
// including myself
int numSiblingsReactant = 0;
int numSiblingsProduct = 0;
// in total
int numSiblings = 0;
int numOthers = 0;
ReactionStepShape reactionStepShape = (ReactionStepShape) endShape;
ReactionStep rs = reactionStepShape.getReactionStep();
for (ReactionParticipant rp : rs.getReactionParticipants()) {
if (rp == reactionParticipant) {
// myself
if (rp instanceof Reactant) {
myPosition = numSiblings;
numSiblingsReactant++;
numSiblings++;
} else {
myPosition = numSiblings;
numSiblingsProduct++;
numSiblings++;
}
} else if (rp.getSpeciesContext().getName().equals(reactionParticipant.getSpeciesContext().getName())) {
if (rp instanceof Reactant) {
numSiblingsReactant++;
numSiblings++;
} else {
numSiblingsProduct++;
numSiblings++;
}
} else {
numOthers++;
}
}
if (numSiblings > 1) {
if (!(numSiblingsReactant == 1 && numSiblingsProduct == 1 && numOthers >= 1)) {
double offset = numSiblings / 2 - 0.5;
correctionFactor = (myPosition - offset) * 0.08;
} else {
// TODO: comment out the next 2 lines to have the "old style" behavior for a+b->a
double offset = numSiblings / 2 - 0.5;
correctionFactor = (myPosition - offset) * 0.08;
}
}
}
// calculate tangent direction at "reactionStep"
double tangentX = 0.0;
double tangentY = 0.0;
if (endShape instanceof ReactionStepShape) {
ReactionStepShape reactionStepShape = (ReactionStepShape) endShape;
for (Shape shape : graphModel.getShapes()) {
if (shape instanceof ReactionParticipantShape && ((ReactionParticipantShape) shape).endShape == reactionStepShape) {
ReactionParticipantShape rpShape = (ReactionParticipantShape) shape;
double dx = rpShape.start.getX() - rpShape.end.getX();
double dy = rpShape.start.getY() - rpShape.end.getY();
double len = dx * dx + dy * dy;
if (shape instanceof ProductShape) {
ProductShape ps = (ProductShape) shape;
tangentX += (ps.start.getX() - ps.end.getX()) / len;
tangentY += (ps.start.getY() - ps.end.getY()) / len;
} else if (shape instanceof ReactantShape) {
ReactantShape rs = (ReactantShape) shape;
tangentX -= (rs.start.getX() - rs.end.getX()) / len;
tangentY -= (rs.start.getY() - rs.end.getY()) / len;
}
}
}
}
double tangentLength = Math.sqrt(tangentX * tangentX + tangentY * tangentY);
if (tangentLength != 0) {
tangentX = tangentX * CONTROL_WEIGHT / tangentLength;
tangentY = tangentY * CONTROL_WEIGHT / tangentLength;
}
// tangentY = 0.0;
if (this instanceof CatalystShape) {
// choose side based on inner product with displacement vector between catalyst and reactionStep
if (((start.getX() - end.getX()) * tangentY - (start.getY() - end.getY()) * tangentX) > 0) {
p2ctrl.setLocation(end.getX() + tangentY, end.getY() - tangentX);
} else {
p2ctrl.setLocation(end.getX() - tangentY, end.getY() + tangentX);
}
} else if (this instanceof ProductShape) {
p2ctrl.setLocation(end.getX() + tangentX, end.getY() + tangentY);
} else if (this instanceof ReactantShape) {
p2ctrl.setLocation(end.getX() - tangentX, end.getY() - tangentY);
}
if (lastCurve != null && lastCurve_Start != null && lastCurve_Start.equals(start) && lastCurve_End != null && lastCurve_End.equals(end) && lastp2ctrl != null && lastp2ctrl.equals(p2ctrl)) {
// Do Nothing
} else {
lastCurve = new CubicCurve2D.Double(start.getX(), start.getY(), lastp1ctrl.getX() * (1 + correctionFactor), lastp1ctrl.getY() * (1 + correctionFactor), p2ctrl.getX(), p2ctrl.getY(), end.getX(), end.getY());
lastCurve_Start = new Point(start);
lastCurve_End = new Point(end);
lastp2ctrl = p2ctrl;
}
return lastCurve;
}
use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.
the class ReactStepDbDriver method getReactionStepArray.
/**
* getModels method comment.
*/
private ReactionStep[] getReactionStepArray(QueryHashtable dbc, Connection con, Model model, String sql) throws SQLException, DataAccessException, PropertyVetoException {
Vector reactStepList = new Vector();
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
//
while (rset.next()) {
ReactionStep reactionStep = getReactionStep(dbc, con, rset, model);
reactStepList.addElement(reactionStep);
}
} finally {
// Release resources include resultset
stmt.close();
}
//
for (int i = 0; i < reactStepList.size(); i++) {
ReactionStep rs1 = (ReactionStep) reactStepList.elementAt(i);
for (int j = i + 1; j < reactStepList.size(); j++) {
ReactionStep rs2 = (ReactionStep) reactStepList.elementAt(j);
if (rs1.compareEqual(rs2)) {
if (lg.isWarnEnabled())
lg.warn("ReactStepDbDriver.getReactionStepArray, detected duplicate reactionStep id=" + rs2.getKey() + " name='" + rs2.getName() + "', should be removed and proper SQL constraint added to schema");
}
}
}
// put results in an array
if (reactStepList.size() > 0) {
ReactionStep[] reactStepArray = new ReactionStep[reactStepList.size()];
reactStepList.copyInto(reactStepArray);
return reactStepArray;
} else {
return null;
}
}
use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.
the class SimulationContext method checkValidity.
public void checkValidity() throws MappingException {
// spatial
if (getGeometry().getDimension() > 0) {
//
// fail if any enabled Reactions have LumpedKinetics.
//
// StringBuffer buffer = new StringBuffer();
// ReactionSpec[] reactionSpecs = getReactionContext().getReactionSpecs();
// for (int i = 0; i < reactionSpecs.length; i++) {
// if (!reactionSpecs[i].isExcluded() && reactionSpecs[i].getReactionStep().getKinetics() instanceof LumpedKinetics){
// buffer.append("reaction \""+reactionSpecs[i].getReactionStep().getName()+"\" in compartment \""+reactionSpecs[i].getReactionStep().getStructure().getName()+"\"\n");
// }
// }
// if (buffer.length()>0){
// throw new MappingException("Spatial application \""+getName()+"\" cannot process reactions with spatially lumped kinetics, see kinetics for :\n"+buffer.toString());
//
// }
} else {
// old-style ODE models should still work
if (applicationType == Application.NETWORK_DETERMINISTIC && getGeometryContext().isAllVolFracAndSurfVolSpecified() && getGeometryContext().isAllSizeSpecifiedNull()) {
// old style ODE models
return;
}
// otherwise, all sizes should be present and positive.
if (!getGeometryContext().isAllSizeSpecifiedPositive()) {
throw new MappingException("Application " + getName() + ":\nAll structure sizes must be assigned positive values.\nPlease go to StructureMapping tab to check the sizes.");
}
// if rate rules are present, if any species has a rate rules, it should not be a reaction participant in any reaction.
RateRule[] rateRules = getRateRules();
if (rateRules != null && rateRules.length > 0) {
if (getModel() != null) {
ReactionStep[] reactionSteps = getModel().getReactionSteps();
ReactionParticipant[] reactionParticipants = null;
for (ReactionStep rs : reactionSteps) {
reactionParticipants = rs.getReactionParticipants();
for (ReactionParticipant rp : reactionParticipants) {
if (rp instanceof Reactant || rp instanceof Product) {
if (getRateRule(rp.getSpeciesContext()) != null) {
throw new RuntimeException("Species '" + rp.getSpeciesContext().getName() + "' is a reactant/product in reaction '" + rs.getName() + "' ; cannot also have a rate rule.");
}
}
}
}
}
}
}
}
use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.
the class ModelProcessEquation method computeEquationString.
private void computeEquationString() {
if (modelProcess instanceof ReactionStep) {
ReactionStep reactionStep = (ReactionStep) modelProcess;
ReactionParticipant[] reactantParticipants = reactionStep.getReactionParticipants();
ArrayList<ReactionParticipant> reactantList = new ArrayList<ReactionParticipant>();
ArrayList<ReactionParticipant> productList = new ArrayList<ReactionParticipant>();
// if (reactionStep instanceof SimpleReaction) {
for (ReactionParticipant rp : reactantParticipants) {
if (rp instanceof Reactant) {
reactantList.add(rp);
} else if (rp instanceof Product) {
productList.add(rp);
}
}
// } else {
// Membrane membrane = (Membrane) ((FluxReaction)reactionStep).getStructure();
// StructureTopology structTopology = reactionStep.getModel().getStructureTopology();
// for (ReactionParticipant rp : reactantParticipants) {
// if (rp instanceof Flux) {
// Flux flux = (Flux)rp;
// Feature scf = (Feature) flux.getSpeciesContext().getStructure();
// if (structTopology.getInsideFeature(membrane) == scf) {
// productList.add(rp);
// } else {
// reactantList.add(rp);
// }
// }
// }
// }
StringBuffer sb = new StringBuffer();
for (ReactionParticipant r : reactantList) {
if (sb.length() > 0) {
sb.append(" + ");
}
int stoichiometry = r.getStoichiometry();
sb.append((stoichiometry > 1 ? stoichiometry : "") + r.getName());
}
equationleftHand = sb.toString();
sb = new StringBuffer();
for (ReactionParticipant p : productList) {
if (sb.length() > 0) {
sb.append(" + ");
}
int stoichiometry = p.getStoichiometry();
sb.append((stoichiometry > 1 ? stoichiometry : "") + p.getName());
}
equationRightHand = sb.toString();
equationString = equationleftHand + " " + REACTION_GOESTO + " " + equationRightHand;
} else if (modelProcess instanceof ReactionRule) {
ReactionRule reactionRuleEmbedded = (ReactionRule) modelProcess;
equationString = RbmUtils.toBnglStringShort(reactionRuleEmbedded, CompartmentMode.hide);
}
}
Aggregations