use of cbit.vcell.model.ReactionRule in project vcell by virtualcell.
the class ParticipantSignatureShapePanel method refreshRuleAnalysis.
private void refreshRuleAnalysis() {
reportMap.clear();
modelRuleEntryMap.clear();
bRuleAnalysisFailedMap.clear();
if (reactionRuleMap == null || reactionRuleMap.isEmpty()) {
return;
}
for (Map.Entry<String, ReactionRule> entry : reactionRuleMap.entrySet()) {
String key = entry.getKey();
ReactionRule rr = entry.getValue();
ModelRuleFactory factory = new ModelRuleFactory();
ModelRuleEntry modelRuleEntry = factory.createRuleEntry(rr, 0, ReactionRuleDirection.forward);
try {
RuleAnalysisReport report = RuleAnalysis.analyze(modelRuleEntry, false);
reportMap.put(key, report);
modelRuleEntryMap.put(key, modelRuleEntry);
bRuleAnalysisFailedMap.put(key, false);
} catch (Exception e) {
e.printStackTrace();
System.err.println("exception computing RuleAnalysis report for " + key + ": " + e.getMessage());
bRuleAnalysisFailedMap.put(key, true);
bRuleAnalysisFailed = true;
}
}
}
use of cbit.vcell.model.ReactionRule in project vcell by virtualcell.
the class BioCartoonTool method pasteReactionsAndRules.
public static final void pasteReactionsAndRules(Component requester, ReactionSpeciesCopy rsCopy, Model pasteModel, Structure structTo, RXPasteInterface rxPasteInterface) {
PasteHelper[] pasteHelper = new PasteHelper[1];
AsynchClientTask issueTask = new AsynchClientTask("Checking Issues...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Model clonedModel = (Model) org.vcell.util.BeanUtils.cloneSerializable(pasteModel);
clonedModel.refreshDependencies();
// Model clonedModel = pasteModel;
IssueContext issueContext = new IssueContext(ContextType.Model, clonedModel, null);
Vector<Issue> issues = new Vector<>();
checkStructuresCompatibility(rsCopy, clonedModel, structTo, issues, issueContext);
Set<MolecularType> mtFromListStrict = getMoleculesFromStrict(rsCopy, clonedModel, issues, issueContext);
if (issues.size() != 0) {
// at this point we can only have fatal error issues or no issues at all
if (!printIssues(issues, requester)) {
throw UserCancelException.CANCEL_GENERIC;
}
}
// map all the structures of the reactions, rules and their participants to existing structures, at need make new structures
// key is the "from" structure, value is the name of the equivalent "to" structure
// on the first position we have the struct from where we copy (key) and the struct where we paste (value)
Map<Structure, String> structuresMap;
if (rsCopy.getStructuresArr().length > 1) {
// throws CANCEL_GENERIC if the user cancels
structuresMap = mapStructures(requester, rsCopy, clonedModel, structTo, issueContext);
} else {
// if length == 1 it's just structFrom which automatically maps to structTo
structuresMap = new LinkedHashMap<>();
structuresMap.put(rsCopy.getFromStructure(), structTo.getName());
}
pasteMolecules(mtFromListStrict, clonedModel, structuresMap);
List<ReactionRule> rulesTo = pasteRules(rsCopy, clonedModel, structTo, issues, issueContext, structuresMap);
// for(ReactionRule rr : rulesTo) {
// clonedModel.getRbmModelContainer().addReactionRule(rr);
// }
clonedModel.getRbmModelContainer().addReactionRules(rulesTo);
// TODO: make any final verifications in the cloned model here
// if anything is wrong exit here with some helpful message
// .....
// otherwise go directly to populating the real model
mapStructures(structuresMap, pasteModel);
pasteMolecules(mtFromListStrict, pasteModel, structuresMap);
// we repeat all the steps to paste the rules in the real model instead of the clone
rulesTo = pasteRules(rsCopy, pasteModel, structTo, issues, issueContext, structuresMap);
// for(ReactionRule rr : rulesTo) {
// pasteModel.getRbmModelContainer().addReactionRule(rr);
// }
pasteModel.getRbmModelContainer().addReactionRules(rulesTo);
System.out.println("done");
}
};
AsynchClientTask pasteRXTask = new AsynchClientTask("Pasting Reaction...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
IssueContext issueContext = new IssueContext(ContextType.Model, pasteModel, null);
// if (pasteHelper[0].issues.size() != 0) {
// printIssues(pasteHelper[0].issues, requester);
// }
// if(rxPasteInterface != null){
// for(BioModelEntityObject newBioModelEntityObject:pasteHelper[0].reactionsAndSpeciesContexts.keySet()) {
// ReactionCartoonTool.copyRelativePosition(rxPasteInterface.getGraphPane().getGraphModel(), pasteHelper[0].reactionsAndSpeciesContexts.get(newBioModelEntityObject), newBioModelEntityObject);
// }
// ReactionCartoonTool.selectAndSaveDiagram(rxPasteInterface, new ArrayList<BioModelEntityObject>(pasteHelper[0].reactionsAndSpeciesContexts.keySet()));
// // //Setup to allow dispatcher to set focus on a specified component after it closes the ProgressPopup
// setFinalWindow(hashTable, rxPasteInterface.getGraphPane());
// }
}
};
ClientTaskDispatcher.dispatch(requester, new Hashtable<>(), new AsynchClientTask[] { issueTask, pasteRXTask }, false);
}
use of cbit.vcell.model.ReactionRule in project vcell by virtualcell.
the class ParticipantSignatureShapePanel method hasBondChanged.
public RuleAnalysisChanged hasBondChanged(String key, MolecularComponentPattern molecularComponentPattern) {
ReactionRule reactionRule = reactionRuleMap.get(key);
if (reactionRule == null) {
return RuleAnalysisChanged.ANALYSISFAILED;
}
ModelRuleEntry modelRuleEntry = modelRuleEntryMap.get(key);
RuleAnalysisReport report = reportMap.get(key);
if (modelRuleEntry == null || report == null) {
System.out.println("modelRuleEntry == null || report == null, NOT GOOD!");
// refreshRuleAnalysis();
}
if (!bRuleAnalysisFailed && report != null) {
MolecularComponentEntry molecularComponentEntry = modelRuleEntry.findMolecularComponentEntry(molecularComponentPattern);
if (report.hasBondChanged(molecularComponentEntry)) {
return RuleAnalysisChanged.CHANGED;
} else {
return RuleAnalysisChanged.UNCHANGED;
}
} else {
return RuleAnalysisChanged.ANALYSISFAILED;
}
}
use of cbit.vcell.model.ReactionRule in project vcell by virtualcell.
the class ParticipantSignatureShapePanel method hasStateChanged.
public RuleAnalysisChanged hasStateChanged(String key, MolecularComponentPattern molecularComponentPattern) {
ReactionRule reactionRule = reactionRuleMap.get(key);
if (reactionRule == null) {
return RuleAnalysisChanged.ANALYSISFAILED;
}
ModelRuleEntry modelRuleEntry = modelRuleEntryMap.get(key);
RuleAnalysisReport report = reportMap.get(key);
if (modelRuleEntry == null || report == null) {
System.out.println("modelRuleEntry == null || report == null, NOT GOOD!");
// refreshRuleAnalysis();
}
if (!bRuleAnalysisFailed && report != null) {
MolecularComponentEntry molecularComponentEntry = modelRuleEntry.findMolecularComponentEntry(molecularComponentPattern);
if (report.hasStateChanged(molecularComponentEntry)) {
return RuleAnalysisChanged.CHANGED;
} else {
return RuleAnalysisChanged.UNCHANGED;
}
} else {
return RuleAnalysisChanged.ANALYSISFAILED;
}
}
use of cbit.vcell.model.ReactionRule in project vcell by virtualcell.
the class ParticipantSignatureShapePanel method hasNoMatch.
public RuleAnalysisChanged hasNoMatch(String key, MolecularTypePattern molecularTypePattern) {
ReactionRule reactionRule = reactionRuleMap.get(key);
if (reactionRule == null) {
return RuleAnalysisChanged.ANALYSISFAILED;
}
ModelRuleEntry modelRuleEntry = modelRuleEntryMap.get(key);
RuleAnalysisReport report = reportMap.get(key);
if (modelRuleEntry == null || report == null) {
System.out.println("modelRuleEntry == null || report == null, NOT GOOD!");
// refreshRuleAnalysis();
}
if (!bRuleAnalysisFailed && report != null) {
MolecularTypeEntry molecularTypeEntry = modelRuleEntry.findMolecularTypeEntry(molecularTypePattern);
if (report.hasNoMatch(molecularTypeEntry)) {
return RuleAnalysisChanged.CHANGED;
} else {
return RuleAnalysisChanged.UNCHANGED;
}
} else {
return RuleAnalysisChanged.ANALYSISFAILED;
}
}
Aggregations