use of cbit.vcell.math.MemVariable in project vcell by virtualcell.
the class MathOverridesPanel 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> newConstantsV = new java.util.Vector<Expression>();
java.util.Vector<String> changedParameterNamesV = new java.util.Vector<String>();
try {
if (actionEvent.getSource().equals(getJMenuItemPaste()) || actionEvent.getSource().equals(getJMenuItemPasteAll())) {
int[] rows = null;
if (actionEvent.getSource() == getJMenuItemPasteAll()) {
rows = new int[getJTableFixed().getRowCount()];
for (int i = 0; i < rows.length; i += 1) {
rows[i] = i;
}
} else {
rows = getJTableFixed().getSelectedRows();
}
Object pasteThis = VCellTransferable.getFromClipboard(VCellTransferable.OBJECT_FLAVOR);
for (int i = 0; i < rows.length; i += 1) {
if (pasteThis instanceof VCellTransferable.ResolvedValuesSelection) {
VCellTransferable.ResolvedValuesSelection rvs = (VCellTransferable.ResolvedValuesSelection) pasteThis;
for (int j = 0; j < rvs.getPrimarySymbolTableEntries().length; j += 1) {
Constant pastedConstant = null;
if (rvs.getPrimarySymbolTableEntries()[j] instanceof Constant) {
pastedConstant = (Constant) rvs.getPrimarySymbolTableEntries()[j];
} else if (rvs.getAlternateSymbolTableEntries() != null && rvs.getAlternateSymbolTableEntries()[j] instanceof Constant) {
pastedConstant = (Constant) rvs.getAlternateSymbolTableEntries()[j];
}
//
if (pastedConstant == null && (rvs.getPrimarySymbolTableEntries()[j] instanceof Function) || (rvs.getPrimarySymbolTableEntries()[j] instanceof VolVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof VolumeRegionVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof MemVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof MembraneRegionVariable)) {
MathDescription mathDescription = getMathOverrides().getSimulation().getMathDescription();
Enumeration<Constant> constants = mathDescription.getConstants();
while (constants.hasMoreElements()) {
Constant constant = constants.nextElement();
if (constant.getName().startsWith(rvs.getPrimarySymbolTableEntries()[j].getName() + DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONC_UNIT_PREFIX)) {
pastedConstant = new Constant(constant.getName(), rvs.getExpressionValues()[j]);
}
}
}
//
// find row of math overrides table with the same name as the pastedConstant and propose to change that override to the pasted value
//
String rowName = (String) getJTableFixed().getValueAt(rows[i], MathOverridesTableModel.COLUMN_PARAMETER);
if (pastedConstant != null && pastedConstant.getName().equals(rowName)) {
changedParameterNamesV.add(rowName);
newConstantsV.add(rvs.getExpressionValues()[j]);
String originalValueDescription = null;
if (getMathOverrides().getConstantArraySpec(rowName) != null) {
originalValueDescription = getMathOverrides().getConstantArraySpec(rowName).toString();
} else if (getMathOverrides().getActualExpression(rowName, 0) != null) {
originalValueDescription = getMathOverrides().getActualExpression(rowName, 0).infix();
} else {
throw new Exception("MathOverridesPanel can't find value for '" + rowName + "'");
}
pasteDescriptionsV.add(VCellCopyPasteHelper.formatPasteList(rowName, pastedConstant.getName(), originalValueDescription, rvs.getExpressionValues()[j].infix() + ""));
}
}
}
}
}
} catch (Throwable e) {
PopupGenerator.showErrorDialog(this, "Paste failed during pre-check (no changes made).\n" + e.getClass().getName() + " " + e.getMessage(), e);
return;
}
// Do paste
try {
if (pasteDescriptionsV.size() > 0) {
String[] pasteDescriptionArr = new String[pasteDescriptionsV.size()];
pasteDescriptionsV.copyInto(pasteDescriptionArr);
String[] changedParameterNamesArr = new String[changedParameterNamesV.size()];
changedParameterNamesV.copyInto(changedParameterNamesArr);
VCellCopyPasteHelper.chooseApplyPaste(this, pasteDescriptionArr, getMathOverrides(), changedParameterNamesArr, newConstantsV);
} else {
PopupGenerator.showInfoDialog(this, "No paste items match the destination (no changes made).");
}
} catch (Throwable e) {
PopupGenerator.showErrorDialog(this, "Paste Error\n" + e.getClass().getName() + " " + e.getMessage(), e);
}
}
use of cbit.vcell.math.MemVariable in project vcell by virtualcell.
the class FastSystemAnalyzer method refreshFastVarList.
/**
* @return java.util.Vector
*/
private void refreshFastVarList() throws MathException, ExpressionException {
fastVarList.clear();
//
// get list of unique (VolVariables and MemVariables) in fastRate expressions
//
Enumeration<FastRate> fastRatesEnum = fastSystem.getFastRates();
while (fastRatesEnum.hasMoreElements()) {
FastRate fr = fastRatesEnum.nextElement();
Expression exp = fr.getFunction();
Enumeration<Variable> enum1 = MathUtilities.getRequiredVariables(exp, this);
while (enum1.hasMoreElements()) {
Variable var = enum1.nextElement();
if (var instanceof VolVariable || var instanceof MemVariable) {
if (!fastVarList.contains(var)) {
fastVarList.addElement(var);
// System.out.println("FastSystemImplicit.refreshFastVarList(), FAST RATE VARIABLE: "+var.getName());
}
}
}
}
//
// get list of all variables used in invariant expressions that are not used in fast rates
//
Enumeration<FastInvariant> fastInvariantsEnum = fastSystem.getFastInvariants();
while (fastInvariantsEnum.hasMoreElements()) {
FastInvariant fi = (FastInvariant) fastInvariantsEnum.nextElement();
Expression exp = fi.getFunction();
// System.out.println("FastSystemImplicit.refreshFastVarList(), ORIGINAL FAST INVARIANT: "+exp);
Enumeration<Variable> enum1 = MathUtilities.getRequiredVariables(exp, this);
while (enum1.hasMoreElements()) {
Variable var = enum1.nextElement();
if (var instanceof VolVariable || var instanceof MemVariable) {
if (!fastVarList.contains(var)) {
fastVarList.addElement(var);
}
}
}
}
//
// verify that there are N equations (rates+invariants) and N unknowns (fastVariables)
//
int numBoundFunctions = fastSystem.getNumFastInvariants() + fastSystem.getNumFastRates();
if (fastVarList.size() != numBoundFunctions) {
throw new MathException("FastSystem.checkDimension(), there are " + fastVarList.size() + " variables and " + numBoundFunctions + " FastInvariant's & FastRates");
}
}
use of cbit.vcell.math.MemVariable in project vcell by virtualcell.
the class MathMapping_4_8 method refreshVariables.
/**
* This method was created in VisualAge.
*/
private void refreshVariables() throws MappingException {
// System.out.println("MathMapping.refreshVariables()");
//
// non-constant dependent variables require a function
//
Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (scm.getDependencyExpression() != null && !scs.isConstant()) {
// scm.setVariable(new Function(scm.getSpeciesContext().getName(),scm.getDependencyExpression()));
scm.setVariable(null);
}
}
enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (getSimulationContext().hasEventAssignment(scs.getSpeciesContext())) {
scm.setDependencyExpression(null);
}
}
//
// non-constant independent variables require either a membrane or volume variable
//
enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (scm.getDependencyExpression() == null && (!scs.isConstant() || getSimulationContext().hasEventAssignment(scs.getSpeciesContext()))) {
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(scm.getSpeciesContext().getStructure());
Structure struct = scm.getSpeciesContext().getStructure();
if (struct instanceof Feature) {
if (getResolved(sm)) {
scm.setVariable(getResolvedVolVariable(scm.getSpeciesContext().getSpecies()));
} else {
scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), nullDomain));
}
} else if (struct instanceof Membrane) {
if (getResolved(sm)) {
scm.setVariable(new MemVariable(scm.getSpeciesContext().getName(), nullDomain));
} else {
scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), nullDomain));
}
} else {
throw new MappingException("class " + scm.getSpeciesContext().getStructure().getClass() + " not supported");
}
mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
}
}
}
use of cbit.vcell.math.MemVariable in project vcell by virtualcell.
the class XmlReader method getMemVariable.
/**
* This method returns a MemVariable object from a XML element.
* Creation date: (5/16/2001 3:17:18 PM)
* @return cbit.vcell.math.MemVariable
* @param param org.jdom.Element
*/
private MemVariable getMemVariable(Element param) {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
// Create new memVariable
MemVariable memVariable = new MemVariable(name, domain);
transcribeComments(param, memVariable);
return memVariable;
}
use of cbit.vcell.math.MemVariable in project vcell by virtualcell.
the class XmlReader method getComputeNormal.
private ComputeNormalComponentEquation getComputeNormal(Element param, MathDescription mathDesc) throws XmlParseException {
// get attributes
String varname = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
// find reference in the dictionnary
// try a MembraneRegionVariable
MemVariable varref = (MemVariable) mathDesc.getVariable(varname);
if (varref == null) {
throw new XmlParseException("The reference to the Membrane variable " + varname + " could not be resolved!");
}
NormalComponent normalComponent = null;
String normalComponentString = param.getAttributeValue(XMLTags.ComputeNormalComponentAttrTag);
if (normalComponentString.equals(XMLTags.ComputeNormalComponentAttrTagValue_X)) {
normalComponent = NormalComponent.X;
} else if (normalComponentString.equals(XMLTags.ComputeNormalComponentAttrTagValue_Y)) {
normalComponent = NormalComponent.Y;
} else if (normalComponentString.equals(XMLTags.ComputeNormalComponentAttrTagValue_Z)) {
normalComponent = NormalComponent.Z;
}
ComputeNormalComponentEquation computeNormal = new ComputeNormalComponentEquation(varref, normalComponent);
return computeNormal;
}
Aggregations