use of cbit.vcell.mapping.GeometryContext in project vcell by virtualcell.
the class BioModelParametersTableModel method propertyChange.
@Override
public void propertyChange(java.beans.PropertyChangeEvent evt) {
super.propertyChange(evt);
if (evt.getSource() instanceof EditableSymbolTableEntry) {
int changeRow = getRowIndex((EditableSymbolTableEntry) evt.getSource());
if (changeRow >= 0) {
fireTableRowsUpdated(changeRow, changeRow);
}
} else {
String propertyName = evt.getPropertyName();
if (evt.getSource() == bioModel.getModel()) {
if (propertyName.equals(Model.PROPERTY_NAME_MODEL_PARAMETERS)) {
ModelParameter[] oldValue = (ModelParameter[]) evt.getOldValue();
if (oldValue != null) {
for (EditableSymbolTableEntry parameter : oldValue) {
parameter.removePropertyChangeListener(this);
}
}
ModelParameter[] newValue = (ModelParameter[]) evt.getNewValue();
if (newValue != null) {
for (EditableSymbolTableEntry parameter : newValue) {
parameter.addPropertyChangeListener(this);
}
}
refreshData();
} else if (propertyName.equals(Model.PROPERTY_NAME_SPECIES_CONTEXTS)) {
SpeciesContext[] oldValue = (SpeciesContext[]) evt.getOldValue();
if (oldValue != null) {
for (SpeciesContext sc : oldValue) {
sc.removePropertyChangeListener(this);
}
}
SpeciesContext[] newValue = (SpeciesContext[]) evt.getNewValue();
if (newValue != null) {
for (SpeciesContext sc : newValue) {
sc.addPropertyChangeListener(this);
}
}
refreshData();
} else if (propertyName.equals(Model.PROPERTY_NAME_REACTION_STEPS)) {
ReactionStep[] oldValue = (ReactionStep[]) evt.getOldValue();
if (oldValue != null) {
for (ReactionStep reactionStep : oldValue) {
reactionStep.removePropertyChangeListener(this);
reactionStep.getKinetics().removePropertyChangeListener(this);
for (KineticsParameter kineticsEditableSymbolTableEntry : reactionStep.getKinetics().getKineticsParameters()) {
kineticsEditableSymbolTableEntry.removePropertyChangeListener(this);
}
for (ProxyParameter proxyEditableSymbolTableEntry : reactionStep.getKinetics().getProxyParameters()) {
proxyEditableSymbolTableEntry.removePropertyChangeListener(this);
}
for (UnresolvedParameter unresolvedEditableSymbolTableEntry : reactionStep.getKinetics().getUnresolvedParameters()) {
unresolvedEditableSymbolTableEntry.removePropertyChangeListener(this);
}
}
}
ReactionStep[] newValue = (ReactionStep[]) evt.getNewValue();
if (newValue != null) {
for (ReactionStep reactionStep : newValue) {
reactionStep.addPropertyChangeListener(this);
reactionStep.getKinetics().addPropertyChangeListener(this);
for (KineticsParameter kineticsEditableSymbolTableEntry : reactionStep.getKinetics().getKineticsParameters()) {
kineticsEditableSymbolTableEntry.addPropertyChangeListener(this);
}
for (ProxyParameter proxyEditableSymbolTableEntry : reactionStep.getKinetics().getProxyParameters()) {
proxyEditableSymbolTableEntry.addPropertyChangeListener(this);
}
for (UnresolvedParameter unresolvedEditableSymbolTableEntry : reactionStep.getKinetics().getUnresolvedParameters()) {
unresolvedEditableSymbolTableEntry.addPropertyChangeListener(this);
}
}
}
refreshData();
} else if (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_REACTION_RULE_LIST)) {
List<ReactionRule> oldValue = (List<ReactionRule>) evt.getOldValue();
if (oldValue != null) {
for (ReactionRule rs : oldValue) {
rs.removePropertyChangeListener(this);
}
}
List<ReactionRule> newValue = (List<ReactionRule>) evt.getNewValue();
if (newValue != null) {
for (ReactionRule rs : newValue) {
rs.addPropertyChangeListener(this);
}
}
refreshData();
}
} else if (evt.getSource() == bioModel) {
if (propertyName.equals(BioModel.PROPERTY_NAME_SIMULATION_CONTEXTS)) {
SimulationContext[] oldValue = (SimulationContext[]) evt.getOldValue();
for (SimulationContext simulationContext : oldValue) {
simulationContext.removePropertyChangeListener(this);
simulationContext.getGeometryContext().removePropertyChangeListener(this);
for (StructureMapping mapping : simulationContext.getGeometryContext().getStructureMappings()) {
mapping.removePropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : mapping.getParameters()) {
parameter.removePropertyChangeListener(this);
}
}
simulationContext.getReactionContext().removePropertyChangeListener(this);
for (SpeciesContextSpec spec : simulationContext.getReactionContext().getSpeciesContextSpecs()) {
spec.removePropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : spec.getParameters()) {
parameter.removePropertyChangeListener(this);
}
}
for (ElectricalStimulus elect : simulationContext.getElectricalStimuli()) {
elect.removePropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : elect.getParameters()) {
parameter.removePropertyChangeListener(this);
}
}
for (SpatialObject spatialObject : simulationContext.getSpatialObjects()) {
spatialObject.removePropertyChangeListener(this);
}
for (SpatialProcess spatialProcess : simulationContext.getSpatialProcesses()) {
spatialProcess.removePropertyChangeListener(this);
for (LocalParameter p : spatialProcess.getParameters()) {
p.removePropertyChangeListener(this);
}
}
for (SimulationContextParameter p : simulationContext.getSimulationContextParameters()) {
p.removePropertyChangeListener(this);
}
}
SimulationContext[] newValue = (SimulationContext[]) evt.getNewValue();
for (SimulationContext simulationContext : newValue) {
simulationContext.addPropertyChangeListener(this);
simulationContext.getGeometryContext().addPropertyChangeListener(this);
for (StructureMapping mapping : simulationContext.getGeometryContext().getStructureMappings()) {
mapping.addPropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : mapping.getParameters()) {
parameter.addPropertyChangeListener(this);
}
}
simulationContext.getReactionContext().addPropertyChangeListener(this);
for (SpeciesContextSpec spec : simulationContext.getReactionContext().getSpeciesContextSpecs()) {
spec.addPropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : spec.getParameters()) {
parameter.addPropertyChangeListener(this);
}
}
for (ElectricalStimulus elect : simulationContext.getElectricalStimuli()) {
elect.addPropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : elect.getParameters()) {
parameter.addPropertyChangeListener(this);
}
}
for (SpatialObject spatialObject : simulationContext.getSpatialObjects()) {
spatialObject.addPropertyChangeListener(this);
}
for (SpatialProcess spatialProcess : simulationContext.getSpatialProcesses()) {
spatialProcess.addPropertyChangeListener(this);
for (LocalParameter p : spatialProcess.getParameters()) {
p.addPropertyChangeListener(this);
}
}
for (SimulationContextParameter p : simulationContext.getSimulationContextParameters()) {
p.addPropertyChangeListener(this);
}
}
refreshData();
}
} else if (evt.getSource() instanceof GeometryContext && evt.getPropertyName().equals(GeometryContext.PROPERTY_STRUCTURE_MAPPINGS)) {
StructureMapping[] oldValue = (StructureMapping[]) evt.getOldValue();
if (oldValue != null) {
for (StructureMapping mapping : oldValue) {
mapping.removePropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : mapping.getParameters()) {
parameter.removePropertyChangeListener(this);
}
}
}
StructureMapping[] newValue = (StructureMapping[]) evt.getNewValue();
if (newValue != null) {
for (StructureMapping mapping : newValue) {
mapping.addPropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : mapping.getParameters()) {
parameter.addPropertyChangeListener(this);
}
}
}
refreshData();
} else if (evt.getSource() instanceof ReactionStep && (evt.getPropertyName().equals(ReactionStep.PROPERTY_NAME_KINETICS))) {
Kinetics oldValue = (Kinetics) evt.getOldValue();
if (oldValue != null) {
oldValue.removePropertyChangeListener(this);
for (KineticsParameter kineticsEditableSymbolTableEntry : oldValue.getKineticsParameters()) {
kineticsEditableSymbolTableEntry.removePropertyChangeListener(this);
}
for (ProxyParameter proxyEditableSymbolTableEntry : oldValue.getProxyParameters()) {
proxyEditableSymbolTableEntry.removePropertyChangeListener(this);
}
for (UnresolvedParameter unresolvedEditableSymbolTableEntry : oldValue.getUnresolvedParameters()) {
unresolvedEditableSymbolTableEntry.removePropertyChangeListener(this);
}
}
Kinetics newValue = (Kinetics) evt.getNewValue();
if (newValue != null) {
newValue.addPropertyChangeListener(this);
for (KineticsParameter kineticsEditableSymbolTableEntry : newValue.getKineticsParameters()) {
kineticsEditableSymbolTableEntry.addPropertyChangeListener(this);
}
for (ProxyParameter proxyEditableSymbolTableEntry : newValue.getProxyParameters()) {
proxyEditableSymbolTableEntry.addPropertyChangeListener(this);
}
for (UnresolvedParameter unresolvedEditableSymbolTableEntry : newValue.getUnresolvedParameters()) {
unresolvedEditableSymbolTableEntry.addPropertyChangeListener(this);
}
}
refreshData();
} else if (evt.getSource() instanceof SimulationContext && evt.getPropertyName().equals(SimulationContext.PROPERTY_NAME_SPATIALPROCESSES)) {
SpatialProcess[] oldValue = (SpatialProcess[]) evt.getOldValue();
if (oldValue != null) {
for (SpatialProcess process : oldValue) {
process.removePropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : process.getParameters()) {
parameter.removePropertyChangeListener(this);
}
}
}
SpatialProcess[] newValue = (SpatialProcess[]) evt.getNewValue();
if (newValue != null) {
for (SpatialProcess process : newValue) {
process.addPropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : process.getParameters()) {
parameter.addPropertyChangeListener(this);
}
}
}
refreshData();
} else if (evt.getSource() instanceof SimulationContext && evt.getPropertyName().equals(SimulationContext.PROPERTY_NAME_SPATIALOBJECTS)) {
SpatialObject[] oldValue = (SpatialObject[]) evt.getOldValue();
if (oldValue != null) {
for (SpatialObject spatialObject : oldValue) {
spatialObject.removePropertyChangeListener(this);
}
}
SpatialObject[] newValue = (SpatialObject[]) evt.getNewValue();
if (newValue != null) {
for (SpatialObject spatialObject : newValue) {
spatialObject.addPropertyChangeListener(this);
}
}
refreshData();
} else if (evt.getSource() instanceof SpatialObject && evt.getPropertyName().equals(SpatialObject.PROPERTY_NAME_QUANTITYCATEGORIESENABLED)) {
refreshData();
} else if (evt.getSource() instanceof SimulationContext && evt.getPropertyName().equals(SimulationContext.PROPERTY_NAME_SIMULATIONCONTEXTPARAMETERS)) {
SimulationContextParameter[] oldValue = (SimulationContextParameter[]) evt.getOldValue();
if (oldValue != null) {
for (SimulationContextParameter param : oldValue) {
param.removePropertyChangeListener(this);
}
}
SimulationContextParameter[] newValue = (SimulationContextParameter[]) evt.getNewValue();
if (newValue != null) {
for (SimulationContextParameter param : newValue) {
param.addPropertyChangeListener(this);
}
}
refreshData();
} else if (evt.getSource() instanceof Kinetics && (evt.getPropertyName().equals(Kinetics.PROPERTY_NAME_KINETICS_PARAMETERS))) {
EditableSymbolTableEntry[] oldValue = (EditableSymbolTableEntry[]) evt.getOldValue();
if (oldValue != null) {
for (int i = 0; i < oldValue.length; i++) {
oldValue[i].removePropertyChangeListener(this);
}
}
EditableSymbolTableEntry[] newValue = (EditableSymbolTableEntry[]) evt.getNewValue();
if (newValue != null) {
for (int i = 0; i < newValue.length; i++) {
newValue[i].addPropertyChangeListener(this);
}
}
refreshData();
// } else if(evt.getSource() instanceof ReactionRuleEmbedded) {
// ReactionRuleEmbedded reactionRule = (ReactionRuleEmbedded) evt.getSource();
// int changeRow = getRowIndex(reactionRule);
// if (changeRow >= 0) {
// fireTableRowsUpdated(changeRow, changeRow);
// }
}
}
}
use of cbit.vcell.mapping.GeometryContext in project vcell by virtualcell.
the class TestingFrameworkWindowManager method addTestCases.
/**
* Insert the method's description here.
* Creation date: (4/10/2003 11:27:32 AM)
* @param testCase cbit.vcell.numericstestingframework.TestCase
*/
public String addTestCases(final TestSuiteInfoNew tsInfo, final TestCaseNew[] testCaseArray, int regrRefFlag, ClientTaskStatusSupport pp) {
if (tsInfo == null) {
throw new IllegalArgumentException("TestSuiteInfo cannot be null");
}
if (testCaseArray == null || testCaseArray.length == 0) {
throw new IllegalArgumentException("TestCases cannot be null / empty");
}
// make modifiable list
List<TestCaseNew> testCases = new ArrayList<>(Arrays.asList(testCaseArray));
StringBuffer errors = new StringBuffer();
// When a testCase (mathmodel/biomodel) is added to a testSuite, a new version of the mathModel/biomodel should be created.
// Also, the simulations in the original mathmodel/biomodel should be rid of their parent simulation reference.
pp.setMessage("Getting testSuite");
pp.setProgress(1);
TestSuiteNew testSuite = null;
try {
testSuite = getRequestManager().getDocumentManager().getTestSuite(tsInfo.getTSKey());
} catch (Throwable e) {
throw new RuntimeException("couldn't get test suite " + tsInfo.getTSID() + "\n" + e.getClass().getName() + " mesg=" + e.getMessage() + "\n");
}
if (testSuite != null && testSuite.getTSInfoNew().isLocked()) {
throw new RuntimeException("Cannot addTestCases to locked table");
}
if (testSuite != null) {
// Saving BioModels
TestCaseNew[] existingTestCases = testSuite.getTestCases();
java.util.HashMap<KeyValue, BioModel> bioModelHashMap = new java.util.HashMap<KeyValue, BioModel>();
// if(existingTestCases != null){
// Find BioModels, Using the same BM reference for sibling Applications
int pcounter = 0;
// use iterator to allow removal of test case from collection if exception
Iterator<TestCaseNew> iter = testCases.iterator();
while (iter.hasNext()) {
TestCaseNew testCase = iter.next();
pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
pp.setMessage("Checking " + testCase.getVersion().getName());
try {
if (testCase instanceof TestCaseNewBioModel) {
TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
//
if (bioModelHashMap.get(bioTestCase.getBioModelInfo().getVersion().getVersionKey()) == null) {
pp.setMessage("Getting BM " + testCase.getVersion().getName());
BioModel bioModel = getRequestManager().getDocumentManager().getBioModel(bioTestCase.getBioModelInfo().getVersion().getVersionKey());
if (!bioModel.getVersion().getOwner().equals(getRequestManager().getDocumentManager().getUser())) {
throw new Exception("BioModel does not belong to VCELLTESTACCOUNT, cannot proceed with test!");
}
//
// if biomodel already exists in same testsuite, then use this BioModel edition
//
BioModel newBioModel = null;
if (existingTestCases != null) {
for (int j = 0; newBioModel == null && j < existingTestCases.length; j++) {
if (existingTestCases[j] instanceof TestCaseNewBioModel) {
TestCaseNewBioModel existingTestCaseBioModel = (TestCaseNewBioModel) existingTestCases[j];
//
if (existingTestCaseBioModel.getBioModelInfo().getVersion().getBranchID().equals(bioTestCase.getBioModelInfo().getVersion().getBranchID())) {
//
if (existingTestCaseBioModel.getBioModelInfo().getVersion().getVersionKey().equals(bioTestCase.getBioModelInfo().getVersion().getVersionKey())) {
//
// same, store this "unchanged" in bioModelHashMap
//
newBioModel = bioModel;
} else {
//
throw new Exception("can't add new test case using (" + bioTestCase.getBioModelInfo().getVersion().getName() + " " + bioTestCase.getBioModelInfo().getVersion().getDate() + ")\n" + "a test case already exists with different edition of same BioModel dated " + existingTestCaseBioModel.getBioModelInfo().getVersion().getDate());
}
}
}
}
}
if (newBioModel == null) {
pp.setMessage("Saving BM " + testCase.getVersion().getName());
//
// some older models have membrane voltage variable names which are not unique
// (e.g. membranes 'pm' and 'nm' both have membrane voltage variables named 'Voltage_Membrane0')
//
// if this is the case, we will try to repair the conflict (for math testing purposes only) by renaming the voltage variables to their default values.
//
// Ordinarily, the conflict will be identified as an "Error" issue and the user will be prompted to repair before saving or math generation.
//
bioModel.refreshDependencies();
boolean bFoundIdentifierConflictUponLoading = hasDuplicateIdentifiers(bioModel);
if (bFoundIdentifierConflictUponLoading) {
//
// look for two MembraneVoltage instances with same variable name, rename all
//
HashSet<String> membraneVoltageVarNames = new HashSet<String>();
ArrayList<MembraneVoltage> membraneVoltageVars = new ArrayList<MembraneVoltage>();
for (Structure struct : bioModel.getModel().getStructures()) {
if (struct instanceof Membrane) {
MembraneVoltage membraneVoltage = ((Membrane) struct).getMembraneVoltage();
if (membraneVoltage != null) {
membraneVoltageVars.add(membraneVoltage);
membraneVoltageVarNames.add(membraneVoltage.getName());
}
}
}
if (membraneVoltageVars.size() != membraneVoltageVarNames.size()) {
// rename them all to the default names
for (MembraneVoltage memVoltage : membraneVoltageVars) {
memVoltage.setName(Membrane.getDefaultMembraneVoltageName(memVoltage.getMembrane().getName()));
}
}
}
SimulationContext[] simContexts = bioModel.getSimulationContexts();
for (int j = 0; j < simContexts.length; j++) {
simContexts[j].clearVersion();
GeometrySurfaceDescription gsd = simContexts[j].getGeometry().getGeometrySurfaceDescription();
if (gsd != null) {
GeometricRegion[] grArr = gsd.getGeometricRegions();
if (grArr == null) {
gsd.updateAll();
}
}
MathMapping mathMapping = simContexts[j].createNewMathMapping();
// for older models that do not have absolute compartment sizes set, but have relative sizes (SVR/VF); or if there is only one compartment with size not set,
// compute absolute compartment sizes using relative sizes and assuming a default value of '1' for one of the compartments.
// Otherwise, the math generation will fail, since for the relaxed topology (VCell 5.3 and later) absolute compartment sizes are required.
GeometryContext gc = simContexts[j].getGeometryContext();
if (simContexts[j].getGeometry().getDimension() == 0 && ((gc.isAllSizeSpecifiedNull() && !gc.isAllVolFracAndSurfVolSpecifiedNull()) || (gc.getModel().getStructures().length == 1 && gc.isAllSizeSpecifiedNull()))) {
// choose the first structure in model and set its size to '1'.
Structure struct = simContexts[j].getModel().getStructure(0);
double structSize = 1.0;
StructureSizeSolver.updateAbsoluteStructureSizes(simContexts[j], struct, structSize, struct.getStructureSize().getUnitDefinition());
}
simContexts[j].setMathDescription(mathMapping.getMathDescription());
}
Simulation[] sims = bioModel.getSimulations();
String[] simNames = new String[sims.length];
for (int j = 0; j < sims.length; j++) {
// prevents parent simulation (from the original mathmodel) reference connection
// Otherwise it will refer to data from previous (parent) simulation.
sims[j].clearVersion();
simNames[j] = sims[j].getName();
// if(sims[j].getSolverTaskDescription().getSolverDescription().equals(SolverDescription.FiniteVolume)){
// sims[j].getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
// }
}
newBioModel = getRequestManager().getDocumentManager().save(bioModel, simNames);
}
bioModelHashMap.put(bioTestCase.getBioModelInfo().getVersion().getVersionKey(), newBioModel);
}
}
} catch (Throwable e) {
String identifier = testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey();
if (lg.isInfoEnabled()) {
lg.info(identifier, e);
}
errors.append("Error collecting BioModel for TestCase " + identifier + '\n' + e.getClass().getName() + " " + e.getMessage() + '\n');
// remove to avoid further processing attempts
iter.remove();
}
}
// }
// then process each BioModelTestCase individually
// if(bioModelHashMap != null){
pcounter = 0;
for (TestCaseNew testCase : testCases) {
pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
pp.setMessage("Checking " + testCase.getVersion().getName());
try {
AddTestCasesOP testCaseOP = null;
if (testCase instanceof TestCaseNewBioModel) {
pp.setMessage("Processing BM " + testCase.getVersion().getName());
TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
BioModel newBioModel = (BioModel) bioModelHashMap.get(bioTestCase.getBioModelInfo().getVersion().getVersionKey());
if (newBioModel == null) {
throw new Exception("BioModel not found");
}
SimulationContext simContext = null;
for (int j = 0; j < newBioModel.getSimulationContexts().length; j++) {
if (newBioModel.getSimulationContext(j).getName().equals(bioTestCase.getSimContextName())) {
simContext = newBioModel.getSimulationContext(j);
}
}
Simulation[] newSimulations = simContext.getSimulations();
AddTestCriteriaOPBioModel[] testCriteriaOPs = new AddTestCriteriaOPBioModel[newSimulations.length];
for (int j = 0; j < newSimulations.length; j++) {
TestCriteriaNewBioModel tcritOrigForSimName = null;
for (int k = 0; bioTestCase.getTestCriterias() != null && k < bioTestCase.getTestCriterias().length; k += 1) {
if (bioTestCase.getTestCriterias()[k].getSimInfo().getName().equals(newSimulations[j].getName())) {
tcritOrigForSimName = (TestCriteriaNewBioModel) bioTestCase.getTestCriterias()[k];
break;
}
}
KeyValue regressionBioModelKey = null;
KeyValue regressionBioModelSimKey = null;
if (bioTestCase.getType().equals(TestCaseNew.REGRESSION)) {
if (regrRefFlag == TestingFrameworkWindowManager.COPY_REGRREF) {
regressionBioModelKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionBioModelInfo() != null ? tcritOrigForSimName.getRegressionBioModelInfo().getVersion().getVersionKey() : null);
regressionBioModelSimKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionSimInfo() != null ? tcritOrigForSimName.getRegressionSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNORIGINAL_REGRREF) {
regressionBioModelKey = (tcritOrigForSimName != null ? bioTestCase.getBioModelInfo().getVersion().getVersionKey() : null);
regressionBioModelSimKey = (tcritOrigForSimName != null ? tcritOrigForSimName.getSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNNEW_REGRREF) {
regressionBioModelKey = newBioModel.getVersion().getVersionKey();
regressionBioModelSimKey = newSimulations[j].getVersion().getVersionKey();
} else {
throw new IllegalArgumentException(this.getClass().getName() + ".addTestCases(...) BIOMODEL Unknown Regression Operation Flag");
}
}
testCriteriaOPs[j] = new AddTestCriteriaOPBioModel(testCase.getTCKey(), newSimulations[j].getVersion().getVersionKey(), regressionBioModelKey, regressionBioModelSimKey, (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxAbsError() : new Double(1e-16)), (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxRelError() : new Double(1e-9)), null);
}
testCaseOP = new AddTestCasesOPBioModel(new BigDecimal(tsInfo.getTSKey().toString()), newBioModel.getVersion().getVersionKey(), simContext.getKey(), bioTestCase.getType(), bioTestCase.getAnnotation(), testCriteriaOPs);
getRequestManager().getDocumentManager().doTestSuiteOP(testCaseOP);
}
} catch (Throwable e) {
errors.append("Error processing Biomodel for TestCase " + (testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey()) + "\n" + e.getClass().getName() + " " + e.getMessage() + "\n");
}
}
// }
// Process MathModels
pcounter = 0;
for (TestCaseNew testCase : testCases) {
pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
pp.setMessage("Checking " + testCase.getVersion().getName());
try {
AddTestCasesOP testCaseOP = null;
if (testCase instanceof TestCaseNewMathModel) {
TestCaseNewMathModel mathTestCase = (TestCaseNewMathModel) testCase;
pp.setMessage("Getting MathModel " + testCase.getVersion().getName());
MathModel mathModel = getRequestManager().getDocumentManager().getMathModel(mathTestCase.getMathModelInfo().getVersion().getVersionKey());
if (!mathModel.getVersion().getOwner().equals(getRequestManager().getDocumentManager().getUser())) {
throw new Exception("MathModel does not belong to VCELLTESTACCOUNT, cannot proceed with test!");
}
Simulation[] sims = mathModel.getSimulations();
String[] simNames = new String[sims.length];
for (int j = 0; j < sims.length; j++) {
// prevents parent simulation (from the original mathmodel) reference connection
// Otherwise it will refer to data from previous (parent) simulation.
sims[j].clearVersion();
simNames[j] = sims[j].getName();
// if(sims[j].getSolverTaskDescription().getSolverDescription().equals(SolverDescription.FiniteVolume)){
// sims[j].getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
// }
}
pp.setMessage("Saving MathModel " + testCase.getVersion().getName());
MathModel newMathModel = getRequestManager().getDocumentManager().save(mathModel, simNames);
Simulation[] newSimulations = newMathModel.getSimulations();
AddTestCriteriaOPMathModel[] testCriteriaOPs = new AddTestCriteriaOPMathModel[newSimulations.length];
for (int j = 0; j < newSimulations.length; j++) {
TestCriteriaNewMathModel tcritOrigForSimName = null;
for (int k = 0; mathTestCase.getTestCriterias() != null && k < mathTestCase.getTestCriterias().length; k += 1) {
if (mathTestCase.getTestCriterias()[k].getSimInfo().getName().equals(newSimulations[j].getName())) {
tcritOrigForSimName = (TestCriteriaNewMathModel) mathTestCase.getTestCriterias()[k];
break;
}
}
KeyValue regressionMathModelKey = null;
KeyValue regressionMathModelSimKey = null;
if (mathTestCase.getType().equals(TestCaseNew.REGRESSION)) {
if (regrRefFlag == TestingFrameworkWindowManager.COPY_REGRREF) {
regressionMathModelKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionMathModelInfo() != null ? tcritOrigForSimName.getRegressionMathModelInfo().getVersion().getVersionKey() : null);
regressionMathModelSimKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionSimInfo() != null ? tcritOrigForSimName.getRegressionSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNORIGINAL_REGRREF) {
regressionMathModelKey = (tcritOrigForSimName != null ? mathTestCase.getMathModelInfo().getVersion().getVersionKey() : null);
regressionMathModelSimKey = (tcritOrigForSimName != null ? tcritOrigForSimName.getSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNNEW_REGRREF) {
regressionMathModelKey = newMathModel.getVersion().getVersionKey();
regressionMathModelSimKey = newSimulations[j].getVersion().getVersionKey();
} else {
throw new IllegalArgumentException(this.getClass().getName() + ".addTestCases(...) MATHMODEL Unknown Regression Operation Flag");
}
}
testCriteriaOPs[j] = new AddTestCriteriaOPMathModel(testCase.getTCKey(), newSimulations[j].getVersion().getVersionKey(), regressionMathModelKey, regressionMathModelSimKey, (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxAbsError() : new Double(1e-16)), (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxRelError() : new Double(1e-9)), null);
}
testCaseOP = new AddTestCasesOPMathModel(new BigDecimal(tsInfo.getTSKey().toString()), newMathModel.getVersion().getVersionKey(), mathTestCase.getType(), mathTestCase.getAnnotation(), testCriteriaOPs);
getRequestManager().getDocumentManager().doTestSuiteOP(testCaseOP);
}
} catch (Throwable e) {
errors.append("Error processing MathModel for TestCase " + (testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey()) + "\n" + e.getClass().getName() + " " + e.getMessage() + "\n");
}
}
}
if (errors.length() > 0) {
return errors.toString();
}
return null;
}
use of cbit.vcell.mapping.GeometryContext in project vcell by virtualcell.
the class IssueTableModel method getSourceObjectPathDescription.
private String getSourceObjectPathDescription(VCDocument vcDocument, Issue issue) {
VCAssert.assertValid(issue);
Object source = issue.getSource();
{
IssueOrigin io = BeanUtils.downcast(IssueOrigin.class, source);
if (io != null) {
return io.getDescription();
}
}
if (vcDocument instanceof BioModel) {
BioModel bioModel = (BioModel) vcDocument;
String description = "";
if (source instanceof SymbolTableEntry) {
if (source instanceof SpeciesContext) {
description = "Model / Species";
} else if (source instanceof RbmObservable) {
description = "Model / Observables";
} else {
description = ((SymbolTableEntry) source).getNameScope().getPathDescription();
}
} else if (source instanceof MolecularType) {
description = "Model / Molecules";
} else if (source instanceof ReactionStep) {
ReactionStep reactionStep = (ReactionStep) source;
description = ((ReactionNameScope) reactionStep.getNameScope()).getPathDescription();
} else if (source instanceof ReactionRule) {
ReactionRule reactionRule = (ReactionRule) source;
description = ((ReactionRuleNameScope) reactionRule.getNameScope()).getPathDescription();
} else if (source instanceof SpeciesPattern) {
// if (issue.getIssueContext().hasContextType(ContextType.SpeciesContext)){
// description = "Model / Species";
// }else if(issue.getIssueContext().hasContextType(ContextType.ReactionRule)) {
// ReactionRule thing = (ReactionRule)issue.getIssueContext().getContextObject(ContextType.ReactionRule);
// description = ((ReactionRuleNameScope)thing.getNameScope()).getPathDescription();
// }else if(issue.getIssueContext().hasContextType(ContextType.RbmObservable)) {
// description = "Model / Observables";
// } else {
System.err.println("Bad issue context for " + ((SpeciesPattern) source).toString());
description = ((SpeciesPattern) source).toString();
// }
} else if (source instanceof Structure) {
Structure structure = (Structure) source;
description = "Model / " + structure.getTypeName() + "(" + structure.getName() + ")";
} else if (source instanceof StructureMapping) {
StructureMapping structureMapping = (StructureMapping) source;
description = ((StructureMappingNameScope) structureMapping.getNameScope()).getPathDescription();
} else if (source instanceof OutputFunctionIssueSource) {
SimulationContext simulationContext = (SimulationContext) ((OutputFunctionIssueSource) source).getOutputFunctionContext().getSimulationOwner();
description = "App(" + simulationContext.getName() + ") / " + "Simulations" + " / " + "Output Functions";
} else if (source instanceof Simulation) {
Simulation simulation = (Simulation) source;
try {
SimulationContext simulationContext = bioModel.getSimulationContext(simulation);
description = "App(" + simulationContext.getName() + ") / Simulations";
} catch (ObjectNotFoundException e) {
e.printStackTrace();
description = "App(" + "unknown" + ") / Simulations";
}
} else if (source instanceof UnmappedGeometryClass) {
UnmappedGeometryClass unmappedGC = (UnmappedGeometryClass) source;
description = "App(" + unmappedGC.getSimulationContext().getName() + ") / Subdomain(" + unmappedGC.getGeometryClass().getName() + ")";
} else if (source instanceof GeometryContext) {
description = "App(" + ((GeometryContext) source).getSimulationContext().getName() + ")";
} else if (source instanceof ModelOptimizationSpec) {
description = "App(" + ((ModelOptimizationSpec) source).getSimulationContext().getName() + ") / Parameter Estimation";
} else if (source instanceof MicroscopeMeasurement) {
description = "App(" + ((MicroscopeMeasurement) source).getSimulationContext().getName() + ") / Microscope Measurements";
} else if (source instanceof SpatialObject) {
description = "App(" + ((SpatialObject) source).getSimulationContext().getName() + ") / Spatial Objects";
} else if (source instanceof SpatialProcess) {
description = "App(" + ((SpatialProcess) source).getSimulationContext().getName() + ") / Spatial Processes";
} else if (source instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) source;
description = "App(" + scs.getSimulationContext().getName() + ") / Specifications / Species";
} else if (source instanceof ReactionCombo) {
ReactionCombo rc = (ReactionCombo) source;
description = "App(" + rc.getReactionContext().getSimulationContext().getName() + ") / Specifications / Reactions";
} else if (source instanceof RbmModelContainer) {
IssueCategory ic = issue.getCategory();
switch(ic) {
case RbmMolecularTypesTableBad:
description = "Model / " + MolecularType.typeName + "s";
break;
case RbmReactionRulesTableBad:
description = "Model / Reactions";
break;
case RbmObservablesTableBad:
description = "Model / Observables";
break;
case RbmNetworkConstraintsBad:
description = "Network Constrains";
break;
default:
description = "Model";
break;
}
} else if (source instanceof SimulationContext) {
SimulationContext sc = (SimulationContext) source;
IssueCategory ic = issue.getCategory();
switch(ic) {
case RbmNetworkConstraintsBad:
description = "Specifications / Network";
break;
default:
description = "Application";
break;
}
} else if (source instanceof Model) {
description = "Model";
} else if (source instanceof BioEvent) {
return "Protocols / Events";
} else if (source instanceof MathDescription) {
return "Math Description";
} else {
System.err.println("unknown source type in IssueTableModel.getSourceObjectPathDescription(): " + source.getClass());
}
return description;
} else if (vcDocument instanceof MathModel) {
if (source instanceof Geometry) {
return GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_MATH_GEOMETRY;
} else if (source instanceof OutputFunctionIssueSource) {
return GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_MATH_OUTPUTFUNCTIONS;
} else if (source instanceof Simulation) {
return "Simulation(" + ((Simulation) source).getName() + ")";
} else {
return GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_MATH_VCML;
}
} else {
System.err.println("unknown document type in IssueTableModel.getSourceObjectPathDescription()");
return "";
}
}
use of cbit.vcell.mapping.GeometryContext in project vcell by virtualcell.
the class IssueTableModel method getSourceObjectDescription.
private String getSourceObjectDescription(VCDocument vcDocument, Issue issue) {
if (vcDocument instanceof BioModel) {
Object object = issue.getSource();
{
DecoratedIssueSource dis = BeanUtils.downcast(DecoratedIssueSource.class, object);
if (dis != null) {
return dis.getSourcePath();
}
}
String description = "";
if (object instanceof SymbolTableEntry) {
description = ((SymbolTableEntry) object).getName();
} else if (object instanceof ReactionStep) {
description = ((ReactionStep) object).getName();
} else if (object instanceof ReactionRule) {
description = ((ReactionRule) object).getName();
} else if (object instanceof SpeciesPattern) {
// Object parent = issue.getIssueContext().getContextObject();
// if (parent instanceof SpeciesContext){
// description = ((SpeciesContext)parent).getName();
// }
// if (issue.getIssueContext().hasContextType(ContextType.SpeciesContext)){
// SpeciesContext thing = (SpeciesContext)issue.getIssueContext().getContextObject(ContextType.SpeciesContext);
// description = thing.getName();
// }else if(issue.getIssueContext().hasContextType(ContextType.ReactionRule)) {
// ReactionRule thing = (ReactionRule)issue.getIssueContext().getContextObject(ContextType.ReactionRule);
// description = thing.getName();
// }else if(issue.getIssueContext().hasContextType(ContextType.RbmObservable)) {
// RbmObservable thing = (RbmObservable)issue.getIssueContext().getContextObject(ContextType.RbmObservable);
// description = thing.getName();
// } else {
System.err.println("Bad issue context for " + ((SpeciesPattern) object).toString());
description = ((SpeciesPattern) object).toString();
// }
} else if (object instanceof MolecularType) {
description = ((MolecularType) object).getName();
} else if (object instanceof MolecularComponent) {
description = ((MolecularComponent) object).getName();
} else if (object instanceof ComponentStateDefinition) {
description = ((ComponentStateDefinition) object).getName();
} else if (object instanceof Structure) {
description = ((Structure) object).getName();
} else if (object instanceof SubDomain) {
description = ((SubDomain) object).getName();
} else if (object instanceof Geometry) {
description = ((Geometry) object).getName();
} else if (object instanceof StructureMapping) {
description = ((StructureMapping) object).getStructure().getName();
} else if (object instanceof OutputFunctionIssueSource) {
description = ((OutputFunctionIssueSource) object).getAnnotatedFunction().getName();
} else if (object instanceof UnmappedGeometryClass) {
description = ((UnmappedGeometryClass) object).getGeometryClass().getName();
} else if (object instanceof MicroscopeMeasurement) {
description = ((MicroscopeMeasurement) object).getName();
} else if (object instanceof SpatialObject) {
description = ((SpatialObject) object).getName();
} else if (object instanceof SpatialProcess) {
description = ((SpatialProcess) object).getName();
} else if (object instanceof GeometryContext) {
description = "Geometry";
} else if (object instanceof ModelOptimizationSpec) {
description = ((ModelOptimizationSpec) object).getParameterEstimationTask().getName();
} else if (object instanceof Simulation) {
description = ((Simulation) object).getName();
} else if (object instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) object;
description = scs.getSpeciesContext().getName();
} else if (object instanceof ReactionCombo) {
ReactionSpec rs = ((ReactionCombo) object).getReactionSpec();
description = rs.getReactionStep().getName();
} else if (object instanceof RbmModelContainer) {
// RbmModelContainer mc = (RbmModelContainer)object;
description = "Rules validator";
} else if (object instanceof SimulationContext) {
SimulationContext sc = (SimulationContext) object;
description = sc.getName();
} else if (object instanceof Model) {
Model m = (Model) object;
description = m.getName();
} else if (object instanceof BioEvent) {
return ((BioEvent) object).getName() + "";
} else if (object instanceof MathDescription) {
return ((MathDescription) object).getName() + "";
} else {
System.err.println("unknown object type in IssueTableModel.getSourceObjectDescription(): " + object.getClass());
}
return description;
} else if (vcDocument instanceof MathModel) {
Object object = issue.getSource();
String description = "";
if (object instanceof Variable) {
description = ((Variable) object).getName();
} else if (object instanceof SubDomain) {
description = ((SubDomain) object).getName();
} else if (object instanceof Geometry) {
description = "Geometry";
} else if (object instanceof OutputFunctionIssueSource) {
description = ((OutputFunctionIssueSource) object).getAnnotatedFunction().getName();
} else if (object instanceof MathDescription) {
return "math";
} else if (object instanceof Simulation) {
return "Simulation " + ((Simulation) object).getName() + "";
}
return description;
} else {
System.err.println("unknown document type in IssueTableModel.getSourceObjectDescription()");
return "";
}
}
use of cbit.vcell.mapping.GeometryContext in project vcell by virtualcell.
the class SbmlExtensionFilter method askUser.
@Override
public void askUser(ChooseContext c) throws UserCancelException {
BioModel bioModel = c.chosenContext.getBioModel();
JFrame currentWindow = c.currentWindow;
selectedSimWOSBE = null;
selectedSimContext = c.chosenContext;
// get user choice of structure and its size and computes absolute sizes of compartments using the StructureSizeSolver.
Structure[] structures = bioModel.getModel().getStructures();
// get the nonspatial simulationContexts corresponding to names in applicableAppNameList
// This is needed in ApplnSelectionAndStructureSizeInputPanel
String strucName = null;
double structSize = 1.0;
int structSelection = -1;
int option = JOptionPane.CANCEL_OPTION;
ApplnSelectionAndStructureSizeInputPanel applnStructInputPanel = null;
while (structSelection < 0) {
applnStructInputPanel = new ApplnSelectionAndStructureSizeInputPanel();
applnStructInputPanel.setSimContext(c.chosenContext);
applnStructInputPanel.setStructures(structures);
if (applnStructInputPanel.isNeedStructureSizes()) {
applnStructInputPanel.setPreferredSize(new java.awt.Dimension(350, 400));
applnStructInputPanel.setMaximumSize(new java.awt.Dimension(350, 400));
option = DialogUtils.showComponentOKCancelDialog(currentWindow, applnStructInputPanel, "Specify Structure Size to Export:");
structSelection = applnStructInputPanel.getStructSelectionIndex();
if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
break;
} else if (option == JOptionPane.OK_OPTION && structSelection < 0) {
DialogUtils.showErrorDialog(currentWindow, "Please select a structure and set its size");
}
} else {
// adapt to legacy logic ...
structSelection = 0;
option = JOptionPane.OK_OPTION;
}
}
if (option == JOptionPane.OK_OPTION) {
applnStructInputPanel.applyStructureNameAndSizeValues();
strucName = applnStructInputPanel.getSelectedStructureName();
selectedSimContext = applnStructInputPanel.getSelectedSimContext();
GeometryContext geoContext = selectedSimContext.getGeometryContext();
if (!isSpatial) {
// calculate structure Sizes only if appln is not spatial
structSize = applnStructInputPanel.getStructureSize();
// Invoke StructureSizeEvaluator to compute absolute sizes of compartments if all sizes are not set
if ((geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) || ((strucName == null || structSize <= 0.0) && (geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecified())) || (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) || (!geoContext.isAllSizeSpecifiedPositive() && !geoContext.isAllVolFracAndSurfVolSpecified()) || (geoContext.isAllSizeSpecifiedNull() && !geoContext.isAllVolFracAndSurfVolSpecified())) {
DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment sizes being set. This can be automatically " + " computed if the absolute size of at least one compartment and the relative sizes (Surface-to-volume-ratio/Volume-fraction) " + " of all compartments are known. Sufficient information is not available to perform this computation." + "\n\nThis can be fixed by going back to the application '" + selectedSimContext.getName() + "' and setting structure sizes in the 'StructureMapping' tab.");
throw UserCancelException.CANCEL_XML_TRANSLATION;
}
if (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecified()) {
Structure chosenStructure = selectedSimContext.getModel().getStructure(strucName);
StructureMapping chosenStructMapping = selectedSimContext.getGeometryContext().getStructureMapping(chosenStructure);
try {
StructureSizeSolver.updateAbsoluteStructureSizes(selectedSimContext, chosenStructure, structSize, chosenStructMapping.getSizeParameter().getUnitDefinition());
} catch (Exception e) {
throw new ProgrammingException("exception updating sizes", e);
}
}
} else {
if (!geoContext.isAllUnitSizeParameterSetForSpatial()) {
DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment size ratios being set." + "\n\nThis can be fixed by going back to the application '" + selectedSimContext.getName() + "' and setting structure" + " size ratios in the 'StructureMapping' tab.");
throw UserCancelException.CANCEL_XML_TRANSLATION;
}
}
// Select simulation whose overrides need to be exported
// If simContext doesn't have simulations, don't pop up simulationSelectionPanel
Simulation[] sims = bioModel.getSimulations(selectedSimContext);
// display only those simulations that have overrides in the simulationSelectionPanel.
Vector<Simulation> orSims = new Vector<Simulation>();
for (int s = 0; (sims != null) && (s < sims.length); s++) {
if (sims[s].getMathOverrides().hasOverrides()) {
orSims.addElement(sims[s]);
}
}
Simulation[] overriddenSims = orSims.toArray(new Simulation[orSims.size()]);
if (overriddenSims.length > 0) {
SimulationSelectionPanel simSelectionPanel = new SimulationSelectionPanel();
simSelectionPanel.setPreferredSize(new java.awt.Dimension(600, 400));
simSelectionPanel.setMaximumSize(new java.awt.Dimension(600, 400));
simSelectionPanel.setSimulations(overriddenSims);
int simOption = DialogUtils.showComponentOKCancelDialog(currentWindow, simSelectionPanel, "Select Simulation whose overrides should be exported:");
if (simOption == JOptionPane.OK_OPTION) {
selectedSimWOSBE = simSelectionPanel.getSelectedSimulation();
// if (chosenSimulation != null) {
// CARRY hashTable.put("selectedSimulation", chosenSimulation);
// }
} else if (simOption == JOptionPane.CANCEL_OPTION || simOption == JOptionPane.CLOSED_OPTION) {
// Hence canceling the entire export to SBML operation.
throw UserCancelException.CANCEL_XML_TRANSLATION;
}
}
} else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
// Hence canceling the entire export to SBML operation.
throw UserCancelException.CANCEL_XML_TRANSLATION;
}
if (selectedSimWOSBE != null) {
String selectedFileName = c.filename;
// rename file to contain exported simulation.
String ext = FilenameUtils.getExtension(selectedFileName);
String base = FilenameUtils.getBaseName(selectedFileName);
String path = FilenameUtils.getPath(selectedFileName);
base += "_" + TokenMangler.mangleToSName(selectedSimWOSBE.getName());
selectedFileName = path + base + ext;
c.selectedFile.renameTo(new File(selectedFileName));
}
}
Aggregations