use of cbit.vcell.model.SpeciesContext in project vcell by virtualcell.
the class BioModelEditorReactionTableModel method setValueAt.
public void setValueAt(Object value, int row, int column) {
if (getModel() == null || value == null) {
return;
}
try {
ModelProcess modelProcess = getValueAt(row);
if (modelProcess != null) {
switch(column) {
case COLUMN_NAME:
{
String inputValue = ((String) value);
inputValue = inputValue.trim();
modelProcess.setName(inputValue);
break;
}
case COLUMN_EQUATION:
{
String inputValue = (String) value;
inputValue = inputValue.trim();
if (modelProcess instanceof ReactionStep) {
ReactionStep reactionStep = (ReactionStep) modelProcess;
ReactionParticipant[] rpArray = ModelProcessEquation.parseReaction(reactionStep, getModel(), inputValue);
for (ReactionParticipant rp : rpArray) {
SpeciesContext speciesContext = rp.getSpeciesContext();
if (bioModel.getModel().getSpeciesContext(speciesContext.getName()) == null) {
bioModel.getModel().addSpecies(speciesContext.getSpecies());
bioModel.getModel().addSpeciesContext(speciesContext);
}
}
reactionStep.setReactionParticipants(rpArray);
} else if (modelProcess instanceof ReactionRule) {
ReactionRule oldReactionRule = (ReactionRule) modelProcess;
// when editing an existing reaction rule
ReactionRule newReactionRule = (ReactionRule) RbmUtils.parseReactionRule(inputValue, oldReactionRule.getStructure(), bioModel);
if (newReactionRule != null) {
oldReactionRule.setProductPatterns(newReactionRule.getProductPatterns(), false, false);
oldReactionRule.setReactantPatterns(newReactionRule.getReactantPatterns(), false, false);
// String name = oldReactionRule.getName();
// RbmKineticLaw kl = oldReactionRule.getKineticLaw();
// Structure st = oldReactionRule.getStructure();
// getModel().getRbmModelContainer().removeReactionRule(oldReactionRule);
// newReactionRule.setName(name);
// newReactionRule.setKineticLaw(kl);
// newReactionRule.setStructure(st);
// getModel().getRbmModelContainer().addReactionRule(newReactionRule);
}
}
break;
}
case COLUMN_STRUCTURE:
{
Structure s = (Structure) value;
modelProcess.setStructure(s);
break;
}
}
} else {
switch(column) {
case COLUMN_EQUATION:
{
if (getModel().getNumStructures() == 1) {
String inputValue = ((String) value);
inputValue = inputValue.trim();
if (inputValue.contains("(") && inputValue.contains(")")) {
ReactionRule reactionRule = (ReactionRule) RbmUtils.parseReactionRule(inputValue, getModel().getStructure(0), bioModel);
getModel().getRbmModelContainer().addReactionRule(reactionRule);
} else {
if (BioModelEditorRightSideTableModel.ADD_NEW_HERE_REACTION_TEXT.equals(inputValue)) {
return;
}
ReactionStep reactionStep = getModel().createSimpleReaction(getModel().getStructure(0));
ReactionParticipant[] rpArray = ModelProcessEquation.parseReaction(reactionStep, getModel(), inputValue);
for (ReactionParticipant rp : rpArray) {
SpeciesContext speciesContext = rp.getSpeciesContext();
if (bioModel.getModel().getSpeciesContext(speciesContext.getName()) == null) {
bioModel.getModel().addSpecies(speciesContext.getSpecies());
bioModel.getModel().addSpeciesContext(speciesContext);
}
}
reactionStep.setReactionParticipants(rpArray);
}
}
break;
}
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(ownerTable, e.getMessage(), e);
}
}
use of cbit.vcell.model.SpeciesContext in project vcell by virtualcell.
the class BioModelEditorSpeciesTableModel method isCellEditable.
public boolean isCellEditable(int row, int column) {
switch(column) {
case COLUMN_NAME:
return true;
case COLUMN_DEFINITION:
SpeciesContext sc = getValueAt(row);
if (sc == null) {
return false;
}
SpeciesPattern sp = sc.getSpeciesPattern();
if (sp == null) {
// we can edit a species pattern if none is present
return true;
}
final List<MolecularTypePattern> mtpList = sp.getMolecularTypePatterns();
for (MolecularTypePattern mtp : mtpList) {
MolecularType mt = mtp.getMolecularType();
if (mt.getComponentList().size() != 0) {
return false;
}
}
return true;
default:
return false;
}
}
use of cbit.vcell.model.SpeciesContext in project vcell by virtualcell.
the class BioModelEditorSpeciesTableModel method getComparator.
@Override
public Comparator<SpeciesContext> getComparator(final int col, final boolean ascending) {
return new Comparator<SpeciesContext>() {
public int compare(SpeciesContext o1, SpeciesContext o2) {
int scale = ascending ? 1 : -1;
switch(col) {
case COLUMN_NAME:
return scale * o1.getName().compareTo(o2.getName());
case COLUMN_STRUCTURE:
return scale * o1.getStructure().getName().compareTo(o2.getStructure().getName());
case COLUMN_DEPICTION:
if (o1.hasSpeciesPattern() && o2.hasSpeciesPattern()) {
Integer i1 = o1.getSpeciesPattern().getMolecularTypePatterns().size();
Integer i2 = o2.getSpeciesPattern().getMolecularTypePatterns().size();
if (scale * i1.compareTo(i2) == 0) {
// if same number of molecule we try to sort by number of sites of the mt
i1 = 0;
i2 = 0;
for (MolecularTypePattern mtp : o1.getSpeciesPattern().getMolecularTypePatterns()) {
i1 += mtp.getMolecularType().getComponentList().size();
}
for (MolecularTypePattern mtp : o2.getSpeciesPattern().getMolecularTypePatterns()) {
i2 += mtp.getMolecularType().getComponentList().size();
}
if (i1 == i2) {
// equal number of molecules and sites, sort by name as a last resort
return scale * o1.getName().compareToIgnoreCase(o2.getName());
}
return scale * i1.compareTo(i2);
} else {
return scale * i1.compareTo(i2);
}
} else if (!o1.hasSpeciesPattern() && o2.hasSpeciesPattern()) {
return scale;
} else if (o1.hasSpeciesPattern() && !o2.hasSpeciesPattern()) {
return -scale;
} else {
// both species have null species pattern, just sort by name
return scale * o1.getName().compareToIgnoreCase(o2.getName());
}
case COLUMN_DEFINITION:
if (o1.hasSpeciesPattern() && o2.hasSpeciesPattern()) {
return scale * o1.getSpeciesPattern().toString().compareToIgnoreCase(o2.getSpeciesPattern().toString());
} else if (!o1.hasSpeciesPattern() && o2.hasSpeciesPattern()) {
return scale;
} else if (o1.hasSpeciesPattern() && !o2.hasSpeciesPattern()) {
return -scale;
} else {
// both species have null species pattern, just sort by name
return scale * o1.getName().compareToIgnoreCase(o2.getName());
}
default:
return 0;
}
}
};
}
use of cbit.vcell.model.SpeciesContext in project vcell by virtualcell.
the class BioModelEditorSpeciesTableModel method checkInputValue.
public String checkInputValue(String inputValue, int row, int column) {
SpeciesContext speciesContext = getValueAt(row);
String errMsg = null;
switch(column) {
case COLUMN_NAME:
if (speciesContext == null || !speciesContext.getName().equals(inputValue)) {
if (getModel().getSpeciesContext(inputValue) != null) {
errMsg = "Species '" + inputValue + "' already exists!";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
}
break;
case COLUMN_STRUCTURE:
if (getModel().getStructure(inputValue) == null) {
errMsg = "Structure '" + inputValue + "' does not exist!";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
break;
case COLUMN_DEFINITION:
try {
inputValue = inputValue.trim();
if (inputValue.length() > 0) {
// parsing will throw appropriate exception if molecular type or component don't exist
// our change
SpeciesPattern spThis = RbmUtils.parseSpeciesPattern(inputValue, bioModel.getModel());
// here we can restrict what the user can do
for (MolecularTypePattern mtpThis : spThis.getMolecularTypePatterns()) {
MolecularType mtThis = mtpThis.getMolecularType();
for (MolecularComponent mcThis : mtThis.getComponentList()) {
// we check that each component is present in the molecular type pattern (as component pattern)
if (mtpThis.getMolecularComponentPattern(mcThis) == null) {
// not found
errMsg = "All " + MolecularComponent.typeName + "s in the " + mtThis.getDisplayType() + " definition must be present. Missing: " + mcThis.getName();
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
} else if (mtpThis.getMolecularComponentPattern(mcThis).isImplied()) {
errMsg = "All " + MolecularComponent.typeName + "s in the " + mtThis.getDisplayType() + " definition must be present. Missing: " + mcThis.getName();
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
} else {
// now need to also check the states
if (mcThis.getComponentStateDefinitions().size() == 0) {
// nothing to do if the molecular component has no component state definition
continue;
// note that we raise exception in parseSpeciesPattern() if we attempt to use an undefined state
// so no need to check that here
}
boolean found = false;
for (ComponentStateDefinition csThis : mcThis.getComponentStateDefinitions()) {
MolecularComponentPattern mcpThis = mtpThis.getMolecularComponentPattern(mcThis);
if ((mcpThis.getComponentStatePattern() == null) || mcpThis.getComponentStatePattern().isAny()) {
// no component state pattern means no state, there's no point to check for this component again
break;
// we get out of the for and complain that we found no matching state
}
if (csThis.getName().equals(mcpThis.getComponentStatePattern().getComponentStateDefinition().getName())) {
found = true;
}
}
if (found == false) {
// we should have found a matching state for the molecular component pattern
errMsg = MolecularComponent.typeName + " " + mcThis.getDisplayName() + " of " + mtThis.getDisplayType() + " " + mtThis.getDisplayName() + " must be in one of the following states: ";
for (int i = 0; i < mcThis.getComponentStateDefinitions().size(); i++) {
ComponentStateDefinition csThis = mcThis.getComponentStateDefinitions().get(i);
errMsg += csThis.getName();
if (i < mcThis.getComponentStateDefinitions().size() - 1) {
errMsg += ", ";
}
}
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
}
}
}
}
} catch (Exception ex) {
errMsg = ex.getMessage();
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
break;
}
return null;
}
use of cbit.vcell.model.SpeciesContext 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);
// }
}
}
}
Aggregations