use of cbit.vcell.model.Structure 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.Structure in project vcell by virtualcell.
the class BioCartoonTool method pasteReactionSteps.
/**
* pasteReactionSteps : this method clones the model argument and calls the private pasteReationSteps0 method with the cloned model to see if
* there are any issues with the paste operation. If so, the issue list is popped up in a warning dialog, and user is given the option of proceeding
* with the paste or cancelling the operation.
*
* @param reactionStepsArr : reactions to be pasted
* @param model : model where reactions are to be pasted
* @param struct : strucure in 'model' where the reactions should be pasted
* @param bNew : is it 'paste' or 'paste new' reaction (new reaction Participants are created if 'bNew' is <true>).
* @param guiRequestComponent : the parent component for the warning dialog that pops up the issues, if any, encountered in the pasting process
* @throws Exception
*/
public static final void pasteReactionSteps(Component requester, ReactionStep[] reactionStepsArrOrig, Model pasteModel, Structure struct, boolean bNew, /*boolean bUseDBSpecies,*/
UserResolvedRxElements userResolvedRxElements, RXPasteInterface rxPasteInterface) {
PasteHelper[] pasteHelper = new PasteHelper[1];
AsynchClientTask issueTask = new AsynchClientTask("Checking Issues...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Model clonedModel = (Model) org.vcell.util.BeanUtils.cloneSerializable(pasteModel);
clonedModel.refreshDependencies();
IssueContext issueContext = new IssueContext(ContextType.Model, clonedModel, null);
pasteHelper[0] = pasteReactionSteps0(null, requester, issueContext, reactionStepsArrOrig, clonedModel, clonedModel.getStructure(struct.getName()), bNew, /*bUseDBSpecies,*/
UserResolvedRxElements.createCompatibleUserResolvedRxElements(userResolvedRxElements, clonedModel));
if (pasteHelper[0].issues.size() != 0) {
if (!printIssues(pasteHelper[0].issues, requester)) {
throw UserCancelException.CANCEL_GENERIC;
}
}
if (pasteHelper[0].rxPartMapStruct != null) {
// Convert rxPartMapStruct instances from cloned to pasteModel
HashMap<String, HashMap<ReactionParticipant, Structure>> new_rxPartMapStruct = new HashMap<>();
for (int i = 0; reactionStepsArrOrig != null && i < reactionStepsArrOrig.length; i++) {
new_rxPartMapStruct.put(reactionStepsArrOrig[i].getName(), new HashMap<ReactionParticipant, Structure>());
for (ReactionParticipant rxPart : pasteHelper[0].rxPartMapStruct.get(reactionStepsArrOrig[i].getName()).keySet()) {
ReactionParticipant[] origRXParts = reactionStepsArrOrig[i].getReactionParticipants();
for (int j = 0; j < origRXParts.length; j++) {
if (origRXParts[j].getName().equals(rxPart.getName())) {
new_rxPartMapStruct.get(reactionStepsArrOrig[i].getName()).put(origRXParts[j], pasteModel.getStructure(pasteHelper[0].rxPartMapStruct.get(reactionStepsArrOrig[i].getName()).get(rxPart).getName()));
}
}
}
}
pasteHelper[0].rxPartMapStruct = new_rxPartMapStruct;
}
}
};
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);
pasteHelper[0] = pasteReactionSteps0(pasteHelper[0].rxPartMapStruct, requester, issueContext, reactionStepsArrOrig, pasteModel, struct, bNew, /*bUseDBSpecies,*/
userResolvedRxElements);
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.Structure in project vcell by virtualcell.
the class BioCartoonTool method pasteSpecies.
/**
* Insert the method's description here.
* Creation date: (5/10/2003 3:55:25 PM)
* @param pasteToModel cbit.vcell.model.Model
* @param pasteToStruct cbit.vcell.model.Structure
* @param bNew boolean
*/
protected static final SpeciesContext pasteSpecies(Component parent, Species copyFromSpecies, String useThisSpeciesContextRootName, Model pasteToModel, Structure pasteToStruct0, boolean bNew, /*boolean bUseDBSpecies, */
IdentityHashMap<Species, Species> speciesHash, HashMap<Structure, Species> userPreferredToTarget) {
Structure preferredToStructure = (userPreferredToTarget != null ? userPreferredToTarget.keySet().iterator().next() : pasteToStruct0);
if (!pasteToModel.contains(preferredToStructure)) {
throw new IllegalArgumentException("CartoonTool.pasteSpecies model '" + pasteToModel.getName() + "' does not contain structure " + (preferredToStructure == null ? null : "'" + preferredToStructure.getName() + "'"));
}
Species newSpecies = null;
if (copyFromSpecies != null) {
try {
newSpecies = getNewSpecies(speciesHash, copyFromSpecies, pasteToModel, bNew, preferredToStructure, userPreferredToTarget);
// see if we have SpeciesContext
SpeciesContext speciesContext = pasteToModel.getSpeciesContext(newSpecies, preferredToStructure);
if (speciesContext == null) {
// Has Species but not SpeciesContext
speciesContext = pasteToModel.addSpeciesContext(newSpecies, preferredToStructure);
String newSpeciesContextName = newSpecies.getCommonName();
if (useThisSpeciesContextRootName != null) {
newSpeciesContextName = useThisSpeciesContextRootName + "_" + speciesContext.getStructure().getName();
while (pasteToModel.getSpeciesContext(newSpeciesContextName) != null) {
newSpeciesContextName = TokenMangler.getNextEnumeratedToken(newSpeciesContextName);
}
}
speciesContext.setName(newSpeciesContextName);
}
} catch (Exception e) {
DialogUtils.showErrorDialog(parent, e.getMessage(), e);
}
}
return pasteToModel.getSpeciesContext(newSpecies, preferredToStructure);
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class BioCartoonTool method checkStructuresCompatibility.
// --------------------------------------------------------------------------------------------------------------------------------------
private static void checkStructuresCompatibility(ReactionSpeciesCopy rsCopy, Model modelTo, Structure structTo, Vector<Issue> issueVector, IssueContext issueContext) {
Structure fromStruct = rsCopy.getFromStructure();
if (rsCopy.getFromStructure().getDimension() != structTo.getDimension()) {
// the source and destination structures need to have the same dimension, can't paste from compartment to membrane or vice-versa
String msg = "Unable to paste from a " + fromStruct.getTypeName() + " to a " + structTo.getTypeName();
msg += ". Both source and destination Structures need to have the same dimension.";
Issue issue = new Issue(fromStruct, issueContext, IssueCategory.CopyPaste, msg, Issue.Severity.ERROR);
issueVector.add(issue);
}
for (Structure from : rsCopy.getStructuresArr()) {
Structure to = modelTo.getStructure(from.getName());
if (to != null && from.getDimension() != to.getDimension()) {
String msg = "Unable to paste " + from.getTypeName() + " " + from.getName();
msg += " because a " + to.getTypeName() + " with the same name already exists.";
Issue issue = new Issue(from, issueContext, IssueCategory.CopyPaste, msg, Issue.Severity.ERROR);
issueVector.add(issue);
}
}
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class BioCartoonTool method mapStructures.
// map the structures to be pasted to existing structures in the cloned model
// we may need to generate some name iteratively until we solve all naming conflicts
private static Map<Structure, String> mapStructures(Component requester, ReactionSpeciesCopy rsCopy, Model modelTo, Structure structTo, IssueContext issueContext) {
// use internally only; we exit the dialog when there are no issues left
Vector<Issue> issueVector = new Vector<>();
Structure structFrom = rsCopy.getFromStructure();
Map<Structure, String> fullyMappedStructures = new LinkedHashMap<>();
fullyMappedStructures.put(structFrom, structTo.getName());
StructurePasteMappingPanel structureMappingPanel = null;
do {
issueVector.clear();
if (structureMappingPanel == null) {
structureMappingPanel = new StructurePasteMappingPanel(rsCopy, modelTo, structTo, issueVector, issueContext);
structureMappingPanel.setPreferredSize(new Dimension(400, 220));
}
int result = DialogUtils.showComponentOKCancelDialog(requester, structureMappingPanel, "Assign 'From' structures to 'To' structures");
if (result != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
} while (structureMappingPanel.hasErrors());
for (Map.Entry<Structure, JComboBox<String>> entry : structureMappingPanel.getStructureMap().entrySet()) {
if (entry.getValue().getSelectedItem().equals(StructurePasteMappingPanel.MAKE_NEW)) {
// we generate a "to" structure name based on the "from" name
String newNameTo = entry.getKey().getName();
while (modelTo.getStructure(newNameTo) != null) {
newNameTo = org.vcell.util.TokenMangler.getNextEnumeratedToken(newNameTo);
for (Structure sFrom : rsCopy.getStructuresArr()) {
if (newNameTo.equals(sFrom.getName())) {
// the new name must not match any existing "from" name either
newNameTo = org.vcell.util.TokenMangler.getNextEnumeratedToken(newNameTo);
break;
}
}
}
try {
// as to avoid risk of duplicates / conflicting names
if (entry.getKey() instanceof Membrane) {
modelTo.addMembrane(newNameTo);
} else {
modelTo.addFeature(newNameTo);
}
} catch (ModelException | PropertyVetoException e) {
throw new RuntimeException("Failed to generate the missing 'from' Structures in the cloned model, " + e.getMessage());
}
fullyMappedStructures.put(entry.getKey(), newNameTo);
} else {
// name of an existing "to" structure
fullyMappedStructures.put(entry.getKey(), (String) entry.getValue().getSelectedItem());
}
}
return fullyMappedStructures;
}
Aggregations