use of cbit.vcell.modelopt.ParameterMappingSpec in project vcell by virtualcell.
the class ParameterMappingPanel method deleteParameter.
public void deleteParameter() {
ArrayList<ParameterMappingSpec> list = new ArrayList<ParameterMappingSpec>();
for (int row : getScrollPaneTable().getSelectedRows()) {
ParameterMappingSpec pms = parameterMappingTableModel.getValueAt(row);
list.add(pms);
}
for (ParameterMappingSpec pms : list) {
pms.setSelected(false);
}
}
use of cbit.vcell.modelopt.ParameterMappingSpec in project vcell by virtualcell.
the class ParameterMappingPanel method addParameter.
public void addParameter() {
JPanel panel = new JPanel(new BorderLayout());
ArrayList<ParameterMappingSpec> dataList = new ArrayList<ParameterMappingSpec>();
if (getParameterEstimationTask() != null) {
for (ParameterMappingSpec pms : getParameterEstimationTask().getModelOptimizationSpec().getParameterMappingSpecs()) {
if (!pms.isSelected()) {
dataList.add(pms);
}
}
}
ScrollTable table = new ScrollTable();
SelectParameterTableModel model = new SelectParameterTableModel(table, getParameterEstimationTask());
table.setModel(model);
model.refreshData();
panel.add(new JScrollPane(table), BorderLayout.CENTER);
panel.setPreferredSize(new Dimension(400, 300));
int returnCode = DialogUtils.showComponentOKCancelDialog(this, panel, "Select Parameters");
if (returnCode == JOptionPane.OK_OPTION) {
for (int row : table.getSelectedRows()) {
ParameterMappingSpec pms = model.getValueAt(row);
pms.setSelected(true);
}
}
}
use of cbit.vcell.modelopt.ParameterMappingSpec in project vcell by virtualcell.
the class ParameterMappingPanel method jMenuItemPaste_ActionPerformed.
/**
* Comment
*/
private void jMenuItemPaste_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
java.util.Vector<String> pasteDescriptionsV = new java.util.Vector<String>();
java.util.Vector<Expression> newExpressionsV = new java.util.Vector<Expression>();
java.util.Vector<ParameterMappingSpec> changedParametersV = new java.util.Vector<ParameterMappingSpec>();
try {
if (actionEvent.getSource() == getJMenuItemPaste() || actionEvent.getSource() == getJMenuItemPasteAll()) {
Object pasteThis = VCellTransferable.getFromClipboard(VCellTransferable.OBJECT_FLAVOR);
SimulationContext sc = getParameterEstimationTask().getModelOptimizationSpec().getSimulationContext();
MathSymbolMapping msm = null;
Exception mathMappingException = null;
try {
MathMapping mm = sc.createNewMathMapping();
msm = mm.getMathSymbolMapping();
} catch (Exception e) {
mathMappingException = e;
e.printStackTrace(System.out);
}
// if(msm == null){
// try{
// getParameterEstimationTask().refreshMappings();
// msm = getParameterEstimationTask().getMathSymbolMapping();
// }catch(Exception e){
// e.printStackTrace();
// }
// }
int[] rows = null;
if (actionEvent.getSource() == getJMenuItemPasteAll()) {
rows = new int[getScrollPaneTable().getRowCount()];
for (int i = 0; i < rows.length; i += 1) {
rows[i] = i;
}
} else {
rows = getScrollPaneTable().getSelectedRows();
}
//
// Check paste
//
StringBuffer errors = null;
for (int i = 0; i < rows.length; i += 1) {
ParameterMappingSpec pms = parameterMappingTableModel.getValueAt(rows[i]);
try {
if (pasteThis instanceof VCellTransferable.ResolvedValuesSelection) {
VCellTransferable.ResolvedValuesSelection rvs = (VCellTransferable.ResolvedValuesSelection) pasteThis;
for (int j = 0; j < rvs.getPrimarySymbolTableEntries().length; j += 1) {
ParameterMappingSpec pasteDestination = null;
Parameter clipboardBiologicalParameter = null;
if (rvs.getPrimarySymbolTableEntries()[j] instanceof Parameter) {
clipboardBiologicalParameter = (Parameter) rvs.getPrimarySymbolTableEntries()[j];
} else if (rvs.getAlternateSymbolTableEntries() != null && rvs.getAlternateSymbolTableEntries()[j] instanceof Parameter) {
clipboardBiologicalParameter = (Parameter) rvs.getAlternateSymbolTableEntries()[j];
}
if (clipboardBiologicalParameter == null) {
Variable pastedMathVariable = null;
if (rvs.getPrimarySymbolTableEntries()[j] instanceof Variable) {
pastedMathVariable = (Variable) rvs.getPrimarySymbolTableEntries()[j];
} else if (rvs.getAlternateSymbolTableEntries() != null && rvs.getAlternateSymbolTableEntries()[j] instanceof Variable) {
pastedMathVariable = (Variable) rvs.getAlternateSymbolTableEntries()[j];
}
if (pastedMathVariable != null) {
if (msm == null) {
throw mathMappingException;
}
Variable localMathVariable = msm.findVariableByName(pastedMathVariable.getName());
if (localMathVariable != null) {
SymbolTableEntry[] localBiologicalSymbolArr = msm.getBiologicalSymbol(localMathVariable);
for (int k = 0; k < localBiologicalSymbolArr.length; k += 1) {
if (localBiologicalSymbolArr[k] == pms.getModelParameter()) {
pasteDestination = pms;
break;
}
}
}
}
} else {
if (pms.getModelParameter().getName().equals(clipboardBiologicalParameter.getName()) && pms.getModelParameter().getClass().equals(clipboardBiologicalParameter.getClass()) && pms.getModelParameter().getNameScope().getName().equals(clipboardBiologicalParameter.getNameScope().getName())) {
pasteDestination = pms;
}
}
if (pasteDestination != null) {
changedParametersV.add(pasteDestination);
newExpressionsV.add(rvs.getExpressionValues()[j]);
pasteDescriptionsV.add(VCellCopyPasteHelper.formatPasteList(pms.getModelParameter().getNameScope().getName(), pms.getModelParameter().getName(), pasteDestination.getCurrent() + "", rvs.getExpressionValues()[j].infix()));
}
}
}
} catch (Throwable e) {
if (errors == null) {
errors = new StringBuffer();
}
errors.append(pms.getModelParameter().getName() + " (" + e.getClass().getName() + ") " + e.getMessage() + "\n");
}
}
if (errors != null) {
throw new Exception(errors.toString());
}
}
} catch (Throwable e) {
PopupGenerator.showErrorDialog(this, "Paste failed during pre-check (no changes made).\n" + e.getMessage(), e);
return;
}
// Do paste
try {
if (pasteDescriptionsV.size() > 0) {
String[] pasteDescriptionArr = new String[pasteDescriptionsV.size()];
pasteDescriptionsV.copyInto(pasteDescriptionArr);
ParameterMappingSpec[] changedParametersArr = new ParameterMappingSpec[changedParametersV.size()];
changedParametersV.copyInto(changedParametersArr);
Expression[] newExpressionsArr = new Expression[newExpressionsV.size()];
newExpressionsV.copyInto(newExpressionsArr);
VCellCopyPasteHelper.chooseApplyPaste(this, pasteDescriptionArr, changedParametersArr, newExpressionsArr);
} else {
PopupGenerator.showInfoDialog(this, "No paste items match the destination (no changes made).");
}
} catch (Throwable e) {
PopupGenerator.showErrorDialog(this, "Paste Error\n" + e.getMessage(), e);
}
}
use of cbit.vcell.modelopt.ParameterMappingSpec in project vcell by virtualcell.
the class ParameterMappingTableModel method refreshData.
/**
* Insert the method's description here.
* Creation date: (9/23/2003 1:24:52 PM)
* @return cbit.vcell.model.Parameter
* @param row int
*/
private void refreshData() {
ArrayList<ParameterMappingSpec> list = new ArrayList<ParameterMappingSpec>();
if (getParameterEstimationTask() != null) {
for (ParameterMappingSpec pms : getParameterEstimationTask().getModelOptimizationSpec().getParameterMappingSpecs()) {
if (pms.isSelected()) {
list.add(pms);
}
}
}
setData(list);
}
use of cbit.vcell.modelopt.ParameterMappingSpec in project vcell by virtualcell.
the class ParameterMappingPanel method jMenuItemCopy_ActionPerformed.
/**
* Comment
*/
private void jMenuItemCopy_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
if (actionEvent.getSource() == getJMenuItemCopy() || actionEvent.getSource() == getJMenuItemCopyAll()) {
try {
//
// Copy Optimization Parameters (Initial Guess or Solution)
//
int[] rows = null;
if (actionEvent.getSource() == getJMenuItemCopyAll()) {
rows = new int[getScrollPaneTable().getRowCount()];
for (int i = 0; i < rows.length; i += 1) {
rows[i] = i;
}
} else {
rows = getScrollPaneTable().getSelectedRows();
}
SimulationContext sc = getParameterEstimationTask().getModelOptimizationSpec().getSimulationContext();
MathSymbolMapping msm = null;
try {
MathMapping mm = sc.createNewMathMapping();
msm = mm.getMathSymbolMapping();
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showWarningDialog(this, "current math not valid, some paste operations will be limited\n\nreason: " + e.getMessage());
}
boolean bInitialGuess = (getScrollPaneTable().getSelectedColumn() == ParameterMappingTableModel.COLUMN_CURRENTVALUE);
ParameterMappingSpec[] parameterMappingSpecs = new ParameterMappingSpec[rows.length];
java.util.Vector<SymbolTableEntry> primarySymbolTableEntriesV = new java.util.Vector<SymbolTableEntry>();
java.util.Vector<SymbolTableEntry> alternateSymbolTableEntriesV = new java.util.Vector<SymbolTableEntry>();
java.util.Vector<Expression> resolvedValuesV = new java.util.Vector<Expression>();
//
// Create formatted string for text/spreadsheet pasting.
//
StringBuffer sb = new StringBuffer();
sb.append("\"Parameters for (Optimization Task)" + getParameterEstimationTask().getName() + " -> " + "(BioModel)" + getParameterEstimationTask().getModelOptimizationSpec().getSimulationContext().getBioModel().getName() + " -> " + "(App)" + getParameterEstimationTask().getModelOptimizationSpec().getSimulationContext().getName() + "\"\n");
sb.append("\"Parameter Name\"\t\"" + (bInitialGuess ? "Initial Guess" : "Solution") + "\"\n");
for (int i = 0; i < rows.length; i += 1) {
ParameterMappingSpec pms = parameterMappingTableModel.getValueAt(rows[i]);
parameterMappingSpecs[i] = pms;
primarySymbolTableEntriesV.add(pms.getModelParameter());
if (msm != null) {
alternateSymbolTableEntriesV.add(msm.getVariable(pms.getModelParameter()));
} else {
alternateSymbolTableEntriesV.add(null);
}
Double resolvedValue = null;
if (!bInitialGuess) {
resolvedValue = getParameterEstimationTask().getCurrentSolution(pms);
}
if (resolvedValue == null) {
resolvedValue = new Double(pms.getCurrent());
}
resolvedValuesV.add(new Expression(resolvedValue.doubleValue()));
sb.append("\"" + parameterMappingSpecs[i].getModelParameter().getName() + "\"\t" + resolvedValue + "\n");
}
//
// Send to clipboard
//
VCellTransferable.ResolvedValuesSelection rvs = new VCellTransferable.ResolvedValuesSelection((SymbolTableEntry[]) BeanUtils.getArray(primarySymbolTableEntriesV, SymbolTableEntry.class), (SymbolTableEntry[]) BeanUtils.getArray(alternateSymbolTableEntriesV, SymbolTableEntry.class), (Expression[]) BeanUtils.getArray(resolvedValuesV, Expression.class), sb.toString());
VCellTransferable.sendToClipboard(rvs);
} catch (Throwable e) {
PopupGenerator.showErrorDialog(this, "ParameterMappingPanel copy failed. " + e.getMessage(), e);
}
}
}
Aggregations