use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.
the class BiomodelVCMLModelInfoResource method createHtml.
public static StringBuffer createHtml(BioModel bm) {
final SpeciesContext[] speciesContexts = bm.getModel().getSpeciesContexts();
final ReactionStep[] reactionSteps = bm.getModel().getReactionSteps();
// This contains a structure name mapped to Species and ReactionSteps
TreeMap<String, ArrayList<Object>[]> structName_Species_Reactions_TS = new TreeMap<String, ArrayList<Object>[]>();
// Store SpeciesContexts belonging to each Structure
for (int i = 0; i < speciesContexts.length; i++) {
final String name = speciesContexts[i].getStructure().getName();
ArrayList<Object>[] items = structName_Species_Reactions_TS.get(name);
if (items == null) {
items = new ArrayList[] { new ArrayList<Structure>(), new ArrayList<SpeciesContext>(), new ArrayList<ReactionStep>() };
items[ITEM_NAMES.structure.ordinal()].add(speciesContexts[i].getStructure());
structName_Species_Reactions_TS.put(name, items);
}
items[ITEM_NAMES.species.ordinal()].add(speciesContexts[i]);
}
// Store ReactionStep belonging to each structure
for (int i = 0; i < reactionSteps.length; i++) {
final String name = reactionSteps[i].getStructure().getName();
ArrayList<Object>[] items = structName_Species_Reactions_TS.get(name);
if (items == null) {
items = new ArrayList[] { new ArrayList<Structure>(), new ArrayList<SpeciesContext>(), new ArrayList<ReactionStep>() };
items[ITEM_NAMES.structure.ordinal()].add(reactionSteps[i].getStructure());
structName_Species_Reactions_TS.put(name, items);
}
items[ITEM_NAMES.reactions.ordinal()].add(reactionSteps[i]);
}
// Create html
StringBuffer sb = new StringBuffer();
sb.append("<strong>Compartments, Species, Reactions</strong><br/>");
// iterate through all the structures and get the stored SpeciesContexts and ReactionSteps
final Iterator<String> iterator = structName_Species_Reactions_TS.keySet().iterator();
while (iterator.hasNext()) {
// Get the structure name
final String structName = iterator.next();
// Get the stored items for the structure
final ArrayList<Object>[] items = structName_Species_Reactions_TS.get(structName);
sb.append("<ul><li> Compartment <strong>\"" + structName + "\"</strong>. (type: " + ((Structure) items[ITEM_NAMES.structure.ordinal()].get(0)).getTypeName() + ")<ul>");
// Add html for SpeciesContexts
for (int i = 0; i < items[ITEM_NAMES.species.ordinal()].size(); i++) {
sb.append("<li>Species <strong>\"" + StringEscapeUtils.escapeHtml(((SpeciesContext) items[ITEM_NAMES.species.ordinal()].get(i)).getName()) + "\"</strong></li>");
}
// Add html for ReactionSteps
for (int i = 0; i < items[ITEM_NAMES.reactions.ordinal()].size(); i++) {
final ReactionStep rxStep = (ReactionStep) items[ITEM_NAMES.reactions.ordinal()].get(i);
ReactionDescription reactionDescription = createReactionDescription(rxStep, bm.getVersion().getVersionKey(), ((Structure) items[ITEM_NAMES.structure.ordinal()].get(0)).getKey());
sb.append("<li>Reaction <strong>\"" + rxStep.getName() + "\"</strong> " + rxStep.getClass().getSimpleName() + " (" + StringEscapeUtils.escapeHtml(reactionDescription.toString()) + ")</li>");
}
sb.append("</ul></li></ul>");
}
return sb;
}
use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.
the class BNGOutputPanel method getCollapsedReactionSteps.
private ReactionStep[] getCollapsedReactionSteps(ReactionStep[] reactionSteps) {
Vector<ReactionStep> collapsedRxnStepsVector = new Vector<ReactionStep>();
Vector<ReactionStep> rxnStepsVector = new Vector<ReactionStep>();
for (int i = 0; i < reactionSteps.length; i++) {
rxnStepsVector.addElement(reactionSteps[i]);
}
for (int i = 0; i < rxnStepsVector.size(); i++) {
ReactionStep fwdRStep = rxnStepsVector.elementAt(i);
// Get the reactionParticipants and the corresponding reactants and products in an array
ReactionParticipant[] rps = fwdRStep.getReactionParticipants();
Vector<SpeciesContext> fwdReactantsVector = new Vector<SpeciesContext>();
Vector<SpeciesContext> fwdProductsVector = new Vector<SpeciesContext>();
for (int j = 0; j < rps.length; j++) {
if (rps[j] instanceof Reactant) {
fwdReactantsVector.addElement(rps[j].getSpeciesContext());
} else if (rps[j] instanceof Product) {
fwdProductsVector.addElement(rps[j].getSpeciesContext());
}
}
SpeciesContext[] fwdReactants = (SpeciesContext[]) BeanUtils.getArray(fwdReactantsVector, SpeciesContext.class);
SpeciesContext[] fwdProducts = (SpeciesContext[]) BeanUtils.getArray(fwdProductsVector, SpeciesContext.class);
boolean bReverseReactionFound = false;
// Loop through all the reactions to find the corresponding reverse reaction
for (int ii = 0; ii < reactionSteps.length; ii++) {
ReactionStep revRStep = reactionSteps[ii];
// Get the reactionParticipants and the corresponding reactants and products in an array
ReactionParticipant[] revRps = revRStep.getReactionParticipants();
Vector<SpeciesContext> revReactantsVector = new Vector<SpeciesContext>();
Vector<SpeciesContext> revProductsVector = new Vector<SpeciesContext>();
for (int j = 0; j < revRps.length; j++) {
if (revRps[j] instanceof Reactant) {
revReactantsVector.addElement(revRps[j].getSpeciesContext());
} else if (revRps[j] instanceof Product) {
revProductsVector.addElement(revRps[j].getSpeciesContext());
}
}
SpeciesContext[] revReactants = (SpeciesContext[]) BeanUtils.getArray(revReactantsVector, SpeciesContext.class);
SpeciesContext[] revProducts = (SpeciesContext[]) BeanUtils.getArray(revProductsVector, SpeciesContext.class);
// Check if reactants of reaction in outer 'for' loop match products in inner 'for' loop and vice versa.
if (BeanUtils.arrayEquals(fwdReactants, revProducts) && BeanUtils.arrayEquals(fwdProducts, revReactants)) {
// Set the reverse kinetic rate expression for the reaction in outer loop with the forward rate from reactionStep in inner loop
// inner 'for' loop
MassActionKinetics revMAKinetics = (MassActionKinetics) revRStep.getKinetics();
// outer 'for' loop
MassActionKinetics fwdMAKinetics = (MassActionKinetics) fwdRStep.getKinetics();
try {
fwdMAKinetics.setParameterValue(fwdMAKinetics.getReverseRateParameter(), revMAKinetics.getForwardRateParameter().getExpression());
Kinetics.KineticsParameter param = revMAKinetics.getKineticsParameter(revMAKinetics.getForwardRateParameter().getExpression().infix());
fwdMAKinetics.setParameterValue(param, param.getExpression());
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
// Add this to the collapsedRxnStepsVector
collapsedRxnStepsVector.addElement(fwdRStep);
rxnStepsVector.removeElement(revRStep);
bReverseReactionFound = true;
break;
}
}
// Add it as is to the 'collapsedRxnStepsVector'
if (!bReverseReactionFound) {
collapsedRxnStepsVector.addElement(fwdRStep);
}
}
// Convert the vector into an array of reactionSteps and return
ReactionStep[] collapsedRxnSteps = (ReactionStep[]) BeanUtils.getArray(collapsedRxnStepsVector, ReactionStep.class);
return collapsedRxnSteps;
}
use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.
the class ClientRequestManager method idToNameConversion.
public static void idToNameConversion(VCDocument vcDoc) {
if (!(vcDoc instanceof BioModel)) {
return;
}
BioModel vcBioModel = (BioModel) vcDoc;
vcBioModel.getSimulationContext(0).setbIgnoreEvents(true);
Map<String, String> entitiesToRename = new LinkedHashMap<>();
for (SpeciesContext sc : vcBioModel.getModel().getSpeciesContexts()) {
String id = sc.getName();
String name = sc.getSbmlName();
if (name == null || name.isEmpty()) {
continue;
}
if (isRestrictedXYZT(name, vcBioModel)) {
continue;
}
name = TokenMangler.fixTokenStrict(name, 60);
while (true) {
if (cbit.vcell.model.Model.isNameUnused(name, vcBioModel.getModel())) {
break;
}
name = TokenMangler.getNextEnumeratedToken(name);
}
if (id.equals(name)) {
continue;
}
try {
System.out.println(name + " <-- " + id);
sc.setName(name);
} catch (PropertyVetoException e) {
// we just keep the id rather than abort
e.printStackTrace();
}
entitiesToRename.put(id, name);
}
for (ModelParameter mp : vcBioModel.getModel().getModelParameters()) {
String id = mp.getName();
String name = mp.getSbmlName();
if (name == null || name.isEmpty()) {
continue;
}
if (isRestrictedXYZT(name, vcBioModel)) {
continue;
}
name = TokenMangler.fixTokenStrict(name, 60);
while (true) {
if (cbit.vcell.model.Model.isNameUnused(name, vcBioModel.getModel())) {
break;
}
name = TokenMangler.getNextEnumeratedToken(name);
}
if (id.equals(name)) {
continue;
}
try {
System.out.println(name + " <-- " + id);
mp.setName(name);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
entitiesToRename.put(id, name);
}
for (Structure struct : vcBioModel.getModel().getStructures()) {
String id = struct.getName();
String name = struct.getSbmlName();
if (name == null || name.isEmpty()) {
continue;
}
if (isRestrictedXYZT(name, vcBioModel)) {
continue;
}
name = TokenMangler.fixTokenStrict(name, 60);
while (true) {
if (cbit.vcell.model.Model.isNameUnused(name, vcBioModel.getModel())) {
break;
}
name = TokenMangler.getNextEnumeratedToken(name);
}
if (id.equals(name)) {
continue;
}
try {
System.out.println(name + " <-- " + id);
struct.setName(name, true);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
entitiesToRename.put(id, name);
}
vcBioModel.getSimulationContext(0).substituteChangedNamesInExpressions(entitiesToRename);
for (ReactionStep rs : vcBioModel.getModel().getReactionSteps()) {
String id = rs.getName();
String name = rs.getSbmlName();
if (name == null || name.isEmpty()) {
continue;
}
if (isRestrictedXYZT(name, vcBioModel)) {
continue;
}
// name = TokenMangler.fixTokenStrict(name, 60);
while (true) {
if (cbit.vcell.model.Model.isNameUnused(name, vcBioModel.getModel())) {
break;
}
name = TokenMangler.getNextEnumeratedToken(name);
}
if (id.equals(name)) {
continue;
}
try {
System.out.println(name + " <-- " + id);
rs.setName(name);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
vcBioModel.getSimulationContext(0).setbIgnoreEvents(false);
}
use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.
the class ClientRequestManager method createBioModelFromApplication.
public void createBioModelFromApplication(final BioModelWindowManager requester, final String name, final SimulationContext simContext) {
if (simContext == null) {
PopupGenerator.showErrorDialog(requester, "Selected Application is null, cannot generate corresponding bio model");
return;
}
if (simContext.isRuleBased()) {
createRuleBasedBioModelFromApplication(requester, name, simContext);
return;
}
AsynchClientTask task1 = new AsynchClientTask("Creating BioModel from BioModel Application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
MathMappingCallback dummyCallback = new MathMappingCallback() {
public void setProgressFraction(float percentDone) {
}
public void setMessage(String message) {
}
public boolean isInterrupted() {
return false;
}
};
MathMapping transformedMathMapping = simContext.createNewMathMapping(dummyCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
BioModel newBioModel = new BioModel(null);
SimulationContext transformedSimContext = transformedMathMapping.getTransformation().transformedSimContext;
Model newModel = transformedSimContext.getModel();
newBioModel.setModel(newModel);
RbmModelContainer rbmmc = newModel.getRbmModelContainer();
for (RbmObservable o : rbmmc.getObservableList()) {
rbmmc.removeObservable(o);
}
for (ReactionRule r : rbmmc.getReactionRuleList()) {
rbmmc.removeReactionRule(r);
}
for (ReactionStep rs : newModel.getReactionSteps()) {
String oldName = rs.getName();
if (oldName.startsWith("_reverse_")) {
String newName = newModel.getReactionName("rev", oldName.substring("_reverse_".length()));
rs.setName(newName);
}
}
hashTable.put("newBioModel", newBioModel);
}
};
AsynchClientTask task2 = new AsynchClientTask("Creating BioModel from BioModel Application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModel newBioModel = (BioModel) hashTable.get("newBioModel");
DocumentWindowManager windowManager = createDocumentWindowManager(newBioModel);
// if(simContext.getBioModel().getVersion() != null){
// ((BioModelWindowManager)windowManager). setCopyFromBioModelAppVersionableTypeVersion(
// new VersionableTypeVersion(VersionableType.BioModelMetaData, simContext.getBioModel().getVersion()));
// }
getMdiManager().createNewDocumentWindow(windowManager);
}
};
ClientTaskDispatcher.dispatch(requester.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.
the class ReactionPropertiesPanel method setReactionStep.
/**
* Sets the kinetics property (cbit.vcell.model.Kinetics) value.
* @param kinetics The new value for the property.
* @see #getKinetics
*/
private void setReactionStep(ReactionStep newValue) {
if (reactionStep == newValue) {
return;
}
ReactionStep oldValue = reactionStep;
if (oldValue != null) {
oldValue.removePropertyChangeListener(eventHandler);
}
// commit the changes before switch to another reaction step
changeName();
changeSbmlName();
reactionStep = newValue;
if (newValue != null) {
newValue.addPropertyChangeListener(eventHandler);
}
getParameterTableModel().setReactionStep(reactionStep);
updateInterface();
}
Aggregations