use of cbit.vcell.model.Reactant in project vcell by virtualcell.
the class PathwayMapping method createReactionStep.
/*
* for reaction:
* 1. annotate the selected vcell object using linked pathway conversion
* 2. add non-existing speciesContexts from linked pathway conversion
* 3. add links between relative vcell objects and pathway objects
* Questions:
* - how to deal with the case that the reaction is existing in the model?
* + add it in no matter what?
* (this is the version we have now:
* add the duplicated reactions in without name changing,
* all duplicated reactions share the same participant objects)
* + just modify the existing one?
*/
private void createReactionStep(BioModel bioModel, Process process, ReactionStep reactionStep, RelationshipObject relationshipObject, ArrayList<ConversionTableRow> participants, boolean addSubunits) throws Exception {
if (reactionStep == null || bioModel == null || bioModel.getRelationshipModel() == null || participants.size() < 1) {
return;
}
ArrayList<ReactionParticipant> rplist = new ArrayList<ReactionParticipant>();
// create and add reaction participants to list
for (ConversionTableRow ctr : participants) {
if (ctr.getBioPaxObject() instanceof Conversion)
continue;
int stoich = ctr.stoich().intValue();
String safeId = getSafetyName(ctr.id());
// get speciesContext object based on its name
// if the speciesContext is not existed, create a new one
createSpeciesContextFromTableRow(bioModel, (PhysicalEntity) ctr.getBioPaxObject(), ctr.stoich(), ctr.id(), ctr.location(), addSubunits);
// add the existed speciesContext objects or new speciesContext objects to reaction participant list
if (ctr.participantType().equals("Reactant")) {
if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
rplist.add(new Reactant(null, reactionStep, bioModel.getModel().getSpeciesContext(safeId), stoich));
}
} else if (ctr.participantType().equals("Product")) {
if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
rplist.add(new Product(null, reactionStep, bioModel.getModel().getSpeciesContext(safeId), stoich));
}
}
// we do not add catalysts
}
ReactionParticipant[] rpArray = rplist.toArray(new ReactionParticipant[0]);
reactionStep.setReactionParticipants(rpArray);
// add Controls to the reaction
Set<PhysicalEntity> controllers = process.getControllers();
for (ConversionTableRow ctr : participants) {
if (controllers.contains(ctr.getBioPaxObject())) {
if (ctr.participantType().equals("Catalyst")) {
String safeId = getSafetyName(ctr.id());
/*
* using addCatalyst() to create catalyst in reaction:
* this function cannot allow an object to be catalyst and (reactant/product) in the same reaction
*/
// reactionStep.addCatalyst(bioModel.getModel().getSpeciesContext(safeId));
/* However, in pathway interaction object, an physicalEntity can be catalyst and (reactant/product) in the same reaction
* So we just call create catalyst for the reaction no matter what rolls the object is playing in the reaction
* Switch back to the addCatalyst() function when it is necessary, but exceptions make be reported for some reactions
*/
reactionStep.addReactionParticipant(new Catalyst(null, reactionStep, bioModel.getModel().getSpeciesContext(safeId)));
} else if (ctr.participantType().equals("Control")) {
String safeId = getSafetyName(ctr.id());
// reactionStep.addCatalyst(bioModel.getModel().getSpeciesContext(safeId));
reactionStep.addReactionParticipant(new Catalyst(null, reactionStep, bioModel.getModel().getSpeciesContext(safeId)));
}
}
}
}
use of cbit.vcell.model.Reactant in project vcell by virtualcell.
the class PathwayMapping method parseReaction.
private ReactionParticipant[] parseReaction(ReactionStep reactionStep, BioModel bioModel, RelationshipObject relationshipObject) throws ExpressionException, PropertyVetoException {
if (reactionStep == null || bioModel == null || bioModel.getRelationshipModel() == null) {
return null;
}
// create the reaction equation string
String leftHand = getParticipantsString(((Conversion) relationshipObject.getBioPaxObject()).getLeft());
String rightHand = getParticipantsString(((Conversion) relationshipObject.getBioPaxObject()).getRight());
StringTokenizer st = new StringTokenizer(leftHand, "+");
HashMap<String, SpeciesContext> speciesContextMap = new HashMap<String, SpeciesContext>();
ArrayList<ReactionParticipant> rplist = new ArrayList<ReactionParticipant>();
// create and add reaction participants to list for left-hand side of equation
Model model = bioModel.getModel();
Structure structure = reactionStep.getStructure();
while (st.hasMoreElements()) {
String nextToken = st.nextToken().trim();
if (nextToken.length() == 0) {
continue;
}
int stoichiIndex = 0;
while (true) {
if (Character.isDigit(nextToken.charAt(stoichiIndex))) {
stoichiIndex++;
} else {
break;
}
}
int stoichi = 1;
String tmp = nextToken.substring(0, stoichiIndex);
if (tmp.length() > 0) {
stoichi = Integer.parseInt(tmp);
}
String var = nextToken.substring(stoichiIndex).trim();
// get speciesContext object based on its name
// if the speciesContext is not existed, create a new one
SpeciesContext sc = model.getSpeciesContext(var);
if (sc == null) {
sc = speciesContextMap.get(var);
if (sc == null) {
// get species object based on its name
// if the species is not existed, create a new one
Species species = model.getSpecies(var);
if (species == null) {
species = new Species(var, null);
}
sc = new SpeciesContext(species, structure);
sc.setName(var);
speciesContextMap.put(var, sc);
}
}
// add the existed speciesContext objects or new speciesContext objects to reaction participant list
if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
rplist.add(new Reactant(null, (SimpleReaction) reactionStep, sc, stoichi));
}
}
// create and add reaction participants to list for right-hand side of equation
st = new StringTokenizer(rightHand, "+");
while (st.hasMoreElements()) {
String nextToken = st.nextToken().trim();
if (nextToken.length() == 0) {
continue;
}
int stoichiIndex = 0;
while (true) {
if (Character.isDigit(nextToken.charAt(stoichiIndex))) {
stoichiIndex++;
} else {
break;
}
}
int stoichi = 1;
String tmp = nextToken.substring(0, stoichiIndex);
if (tmp.length() > 0) {
stoichi = Integer.parseInt(tmp);
}
String var = nextToken.substring(stoichiIndex);
SpeciesContext sc = model.getSpeciesContext(var);
if (sc == null) {
sc = speciesContextMap.get(var);
if (sc == null) {
Species species = model.getSpecies(var);
if (species == null) {
species = new Species(var, null);
}
sc = new SpeciesContext(species, structure);
sc.setName(var);
speciesContextMap.put(var, sc);
}
}
if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
rplist.add(new Product(null, (SimpleReaction) reactionStep, sc, stoichi));
}
}
return rplist.toArray(new ReactionParticipant[0]);
}
use of cbit.vcell.model.Reactant 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.Reactant in project vcell by virtualcell.
the class SpeciesContextSpec method gatherIssues.
/**
* Insert the method's description here.
* Creation date: (11/1/2005 10:03:46 AM)
* @param issueVector java.util.Vector
*/
public void gatherIssues(IssueContext issueContext, List<Issue> issueVector) {
issueContext = issueContext.newChildContext(ContextType.SpeciesContextSpec, this);
//
for (int i = 0; i < fieldParameters.length; i++) {
RealInterval simpleBounds = parameterBounds[fieldParameters[i].getRole()];
if (simpleBounds != null) {
String parmName = fieldParameters[i].getNameScope().getName() + "." + fieldParameters[i].getName();
issueVector.add(new SimpleBoundsIssue(fieldParameters[i], issueContext, simpleBounds, "parameter " + parmName + ": must be within " + simpleBounds.toString()));
}
}
if (bForceContinuous && !bConstant && getSimulationContext().isStoch() && (getSimulationContext().getGeometry().getDimension() > 0)) {
// if it's particle or constant we're good
SpeciesContext sc = getSpeciesContext();
ReactionContext rc = getSimulationContext().getReactionContext();
ReactionSpec[] rsArray = rc.getReactionSpecs();
for (ReactionSpec rs : rsArray) {
if (!rs.isExcluded()) {
// we only care about reactions which are not excluded
// true if "this" is part of current reaction
boolean iAmParticipant = false;
// true if current reaction has at least a particle participant
boolean haveParticle = false;
ReactionStep step = rs.getReactionStep();
for (ReactionParticipant p : step.getReactionParticipants()) {
if (p instanceof Product || p instanceof Reactant) {
SpeciesContextSpec candidate = rc.getSpeciesContextSpec(p.getSpeciesContext());
if (candidate == this) {
iAmParticipant = true;
} else if (!candidate.isForceContinuous() && !candidate.isConstant()) {
haveParticle = true;
}
}
}
if (iAmParticipant && haveParticle) {
String msg = "Continuous Species won't conserve mass in particle reaction " + rs.getReactionStep().getName() + ".";
String tip = "Mass conservation for reactions of binding between discrete and continuous species is handled approximately. <br>" + "To avoid any algorithmic approximation, which may produce undesired results, the user is advised to indicate <br>" + "the continuous species in those reactions as modifiers (i.e. 'catalysts') in the physiology.";
issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, tip, Issue.SEVERITY_WARNING));
// we issue warning as soon as we found the first reaction which satisfies criteria
break;
}
}
}
}
if (!bForceContinuous && bConstant) {
if (getSimulationContext().isStoch() && (getSimulationContext().getGeometry().getDimension() > 0)) {
String msg = "Clamped Species must be continuous rather than particles.";
String tip = "If choose 'clamped', must also choose 'forceContinuous'";
issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, tip, Issue.SEVERITY_ERROR));
}
}
if (bForceContinuous && !bConstant) {
if (getSimulationContext().isStoch() && (getSimulationContext().getGeometry().getDimension() == 0)) {
String msg = "Non-constant species is forced continuous, not supported for nonspatial stochastic applications.";
issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_ERROR));
}
}
if (getSimulationContext().getAssignmentRules() != null && getSimulationContext().getAssignmentRules().length > 0) {
for (AssignmentRule ar : getSimulationContext().getAssignmentRules()) {
if (ar.getAssignmentRuleVar() == null) {
// some assignment rule variable may be still not initialized
continue;
}
SpeciesContext sc = getSpeciesContext();
if (sc.getName().equals(ar.getAssignmentRuleVar().getName())) {
if (!bConstant) {
// the assignment rule variables must be clamped
String msg = "Assignment rule species variables must be Clamped";
String tip = "Used in " + AssignmentRule.typeName + " '" + ar.getDisplayName() + "'";
issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, tip, Issue.Severity.ERROR));
}
}
}
}
if (getSimulationContext().getRateRules() != null && getSimulationContext().getRateRules().length > 0) {
for (RateRule ar : getSimulationContext().getRateRules()) {
if (ar.getRateRuleVar() == null) {
// some rate rule variable may be still not initialized
continue;
}
SpeciesContext sc = getSpeciesContext();
if (sc.getName().equals(ar.getRateRuleVar().getName())) {
if (!bConstant) {
// the rate rule variables must be clamped
String msg = "Rate rule species variables must be Clamped";
String tip = "Used in " + RateRule.typeName + " '" + ar.getDisplayName() + "'";
issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, tip, Issue.Severity.ERROR));
}
}
}
}
}
use of cbit.vcell.model.Reactant in project vcell by virtualcell.
the class MembraneStructureAnalyzer method refreshResolvedFluxes.
/**
* This method was created in VisualAge.
*/
private void refreshResolvedFluxes() throws Exception {
// System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes()");
ModelUnitSystem unitSystem = mathMapping.getSimulationContext().getModel().getUnitSystem();
GeometryContext geoContext = mathMapping.getSimulationContext().getGeometryContext();
Vector<ResolvedFlux> resolvedFluxList = new Vector<ResolvedFlux>();
//
// for each reaction, get all fluxReactions associated with this membrane
//
Vector<FluxReaction> fluxList = new Vector<FluxReaction>();
ReactionSpec[] reactionSpecs = mathMapping.getSimulationContext().getReactionContext().getReactionSpecs();
for (int j = 0; j < reactionSpecs.length; j++) {
if (reactionSpecs[j].isExcluded()) {
continue;
}
ReactionStep rs = reactionSpecs[j].getReactionStep();
if (rs.getStructure() != null && geoContext.getStructureMapping(rs.getStructure()).getGeometryClass() == surfaceClass) {
if (rs instanceof FluxReaction) {
fluxList.addElement((FluxReaction) rs);
}
}
}
//
for (int i = 0; i < fluxList.size(); i++) {
FluxReaction fr = fluxList.elementAt(i);
ReactionParticipant[] reactionParticipants = fr.getReactionParticipants();
for (int j = 0; j < reactionParticipants.length; j++) {
if (!(reactionParticipants[j] instanceof Reactant) && !(reactionParticipants[j] instanceof Product)) {
continue;
}
ResolvedFlux rf = null;
SpeciesContext speciesContext = reactionParticipants[j].getSpeciesContext();
for (int k = 0; k < resolvedFluxList.size(); k++) {
ResolvedFlux rf_tmp = resolvedFluxList.elementAt(k);
if (rf_tmp.getSpeciesContext() == reactionParticipants[j].getSpeciesContext()) {
rf = rf_tmp;
}
}
//
// if speciesContext is not "fixed" and is mapped to a volume, add flux to ResolvedFlux
//
StructureMapping structureMapping = mathMapping.getSimulationContext().getGeometryContext().getStructureMapping(reactionParticipants[j].getStructure());
if (structureMapping.getGeometryClass() == surfaceClass) {
// flux within surface
continue;
}
if (structureMapping.getGeometryClass() instanceof SubVolume && surfaceClass.isAdjacentTo((SubVolume) structureMapping.getGeometryClass())) {
SpeciesContextSpec speciesContextSpec = mathMapping.getSimulationContext().getReactionContext().getSpeciesContextSpec(speciesContext);
if (!speciesContextSpec.isConstant()) {
if (rf == null) {
VCUnitDefinition speciesFluxUnit = speciesContext.getUnitDefinition().multiplyBy(unitSystem.getLengthUnit()).divideBy(unitSystem.getTimeUnit());
rf = new ResolvedFlux(speciesContext, speciesFluxUnit);
resolvedFluxList.addElement(rf);
}
FeatureMapping featureMapping = (FeatureMapping) structureMapping;
Expression insideFluxCorrection = Expression.invert(new Expression(featureMapping.getVolumePerUnitVolumeParameter(), mathMapping.getNameScope()));
//
if (fr.getKinetics() instanceof DistributedKinetics) {
KineticsParameter reactionRateParameter = ((DistributedKinetics) fr.getKinetics()).getReactionRateParameter();
Expression correctedReactionRate = Expression.mult(new Expression(reactionRateParameter, mathMapping.getNameScope()), insideFluxCorrection);
if (reactionParticipants[j] instanceof Product) {
if (rf.getFluxExpression().isZero()) {
rf.setFluxExpression(correctedReactionRate.flatten());
} else {
rf.setFluxExpression(Expression.add(rf.getFluxExpression(), correctedReactionRate.flatten()));
}
} else if (reactionParticipants[j] instanceof Reactant) {
if (rf.getFluxExpression().isZero()) {
rf.setFluxExpression(Expression.negate(correctedReactionRate).flatten());
} else {
rf.setFluxExpression(Expression.add(rf.getFluxExpression(), Expression.negate(correctedReactionRate).flatten()));
}
} else {
throw new RuntimeException("expected either FluxReactant or FluxProduct");
}
} else if (fr.getKinetics() instanceof LumpedKinetics) {
throw new RuntimeException("Lumped Kinetics for fluxes not yet supported");
} else {
throw new RuntimeException("unexpected Kinetic type in MembraneStructureAnalyzer.refreshResolvedFluxes()");
}
rf.getFluxExpression().bindExpression(mathMapping);
}
}
}
}
//
for (int i = 0; i < reactionSpecs.length; i++) {
if (reactionSpecs[i].isExcluded()) {
continue;
}
ReactionStep rs = reactionSpecs[i].getReactionStep();
if (rs.getStructure() != null && geoContext.getStructureMapping(rs.getStructure()).getGeometryClass() == surfaceClass) {
if (rs instanceof SimpleReaction) {
SimpleReaction sr = (SimpleReaction) rs;
ReactionParticipant[] rp_Array = sr.getReactionParticipants();
for (int k = 0; k < rp_Array.length; k++) {
if (rp_Array[k] instanceof Reactant || rp_Array[k] instanceof Product) {
SpeciesContextSpec rpSCS = mathMapping.getSimulationContext().getReactionContext().getSpeciesContextSpec(rp_Array[k].getSpeciesContext());
StructureMapping rpSM = mathMapping.getSimulationContext().getGeometryContext().getStructureMapping(rp_Array[k].getStructure());
if (rpSM.getGeometryClass() instanceof SubVolume && !rpSCS.isConstant()) {
//
// get ResolvedFlux for this species
//
ResolvedFlux rf = null;
for (int j = 0; j < resolvedFluxList.size(); j++) {
ResolvedFlux rf_tmp = (ResolvedFlux) resolvedFluxList.elementAt(j);
if (rf_tmp.getSpeciesContext() == rp_Array[k].getSpeciesContext()) {
rf = rf_tmp;
}
}
if (rf == null) {
VCUnitDefinition speciesFluxUnit = rp_Array[k].getSpeciesContext().getUnitDefinition().multiplyBy(unitSystem.getLengthUnit()).divideBy(unitSystem.getTimeUnit());
rf = new ResolvedFlux(rp_Array[k].getSpeciesContext(), speciesFluxUnit);
resolvedFluxList.addElement(rf);
}
if (rpSM.getGeometryClass() instanceof SubVolume && surfaceClass.isAdjacentTo((SubVolume) rpSM.getGeometryClass())) {
//
// for binding on inside or outside, add to ResolvedFlux.flux
//
Expression fluxRateExpression = getCorrectedRateExpression(sr, rp_Array[k], RateType.ResolvedFluxRate).renameBoundSymbols(mathMapping.getNameScope());
if (rf.getFluxExpression().isZero()) {
rf.setFluxExpression(fluxRateExpression);
} else {
rf.setFluxExpression(Expression.add(rf.getFluxExpression(), fluxRateExpression));
}
rf.getFluxExpression().bindExpression(mathMapping);
} else {
String structureName = ((rs.getStructure() != null) ? (rs.getStructure().getName()) : ("<null>"));
throw new Exception("In Application '" + mathMapping.getSimulationContext().getName() + "', SpeciesContext '" + rp_Array[k].getSpeciesContext().getName() + "' is not mapped adjacent to structure '" + structureName + "' but reacts there");
}
}
}
}
}
}
}
//
if (resolvedFluxList.size() > 0) {
resolvedFluxes = new ResolvedFlux[resolvedFluxList.size()];
resolvedFluxList.copyInto(resolvedFluxes);
} else {
resolvedFluxes = null;
}
}
Aggregations