use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.
the class ViewGeneratedSpeciesPanel method initialize.
private void initialize() {
try {
setName("ViewGeneratedSpeciesPanel");
setLayout(new GridBagLayout());
shapePanel = new LargeShapePanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (spls != null) {
spls.paintSelf(g);
}
}
@Override
public DisplayMode getDisplayMode() {
return DisplayMode.other;
}
@Override
public RuleAnalysisChanged hasStateChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasStateChanged(MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasBondChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasBondChanged(MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasNoMatch(String reactionRuleName, MolecularTypePattern mtp) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasNoMatch(MolecularTypePattern molecularTypePattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleParticipantSignature getSignature() {
return null;
}
@Override
public GroupingCriteria getCriteria() {
return null;
}
@Override
public boolean isViewSingleRow() {
return true;
}
};
Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
shapePanel.setLayout(new GridBagLayout());
shapePanel.setBackground(Color.white);
// not really editable but we don't want the brown contours here
shapePanel.setEditable(true);
shapePanel.setShowMoleculeColor(true);
shapePanel.setShowNonTrivialOnly(true);
JScrollPane scrollPane = new JScrollPane(shapePanel);
scrollPane.setBorder(loweredBevelBorder);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
JPanel optionsPanel = new JPanel();
optionsPanel.setLayout(new GridBagLayout());
getZoomSmallerButton().setEnabled(true);
getZoomLargerButton().setEnabled(false);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(0, 0, 0, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanel.add(getZoomLargerButton(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(2, 0, 4, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanel.add(getZoomSmallerButton(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.weightx = 1;
// fake cell used for filling all the vertical empty space
gbc.weighty = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(4, 4, 4, 10);
optionsPanel.add(new JLabel(""), gbc);
JPanel containerOfScrollPanel = new JPanel();
containerOfScrollPanel.setLayout(new BorderLayout());
containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);
Dimension dim = new Dimension(500, 135);
// dimension of shape panel
containerOfScrollPanel.setPreferredSize(dim);
containerOfScrollPanel.setMinimumSize(dim);
containerOfScrollPanel.setMaximumSize(dim);
// ------------------------------------------------------------------------
table = new EditorScrollTable();
tableModel = new GeneratedSpeciesTableModel(table, owner);
table.setModel(tableModel);
table.getSelectionModel().addListSelectionListener(eventHandler);
table.getModel().addTableModelListener(eventHandler);
DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
int gridy = 0;
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridwidth = 8;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
table.setPreferredScrollableViewportSize(new Dimension(400, 200));
add(table.getEnclosingScrollPane(), gbc);
// gbc = new java.awt.GridBagConstraints();
// gbc.gridx = 9;
// gbc.gridy = gridy;
// add toolTipText for each table cell
table.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
int row = table.rowAtPoint(p);
int column = table.columnAtPoint(p);
table.setToolTipText(String.valueOf(table.getValueAt(row, column)));
}
});
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(4, 4, 4, 4);
add(new JLabel("Search "), gbc);
textFieldSearch = new JTextField(70);
textFieldSearch.addActionListener(eventHandler);
textFieldSearch.getDocument().addDocumentListener(eventHandler);
textFieldSearch.putClientProperty("JTextField.variant", "search");
gbc = new java.awt.GridBagConstraints();
gbc.weightx = 1.0;
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.gridwidth = 3;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 0, 4, 4);
add(textFieldSearch, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 4;
gbc.gridy = gridy;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 10);
add(totalSpeciesLabel, gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
// gbc.weightx = 1.0;
gbc.gridwidth = 8;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
add(containerOfScrollPanel, gbc);
// rendering the small shapes of the flattened species in the Depiction column of this viewer table)
// TODO: this renderer is almost identical with the one in BioModelEditorModelPanel (which paints the small shapes
// of a species context in the Depiction column of the species table)
DefaultScrollTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof GeneratedSpeciesTableRow) {
SpeciesContext sc = ((GeneratedSpeciesTableRow) selectedObject).getSpecies();
// sp cannot be null
SpeciesPattern sp = sc.getSpeciesPattern();
Graphics panelContext = table.getGraphics();
spss = new SpeciesPatternSmallShape(4, 2, sp, panelContext, sc, isSelected, issueManager);
}
} else {
spss = null;
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (spss != null) {
spss.paintSelf(g);
}
}
};
table.getColumnModel().getColumn(GeneratedSpeciesTableModel.iColDepiction).setCellRenderer(rbmSpeciesShapeDepictionCellRenderer);
table.getColumnModel().getColumn(GeneratedSpeciesTableModel.iColDepiction).setPreferredWidth(400);
table.getColumnModel().getColumn(GeneratedSpeciesTableModel.iColDepiction).setMinWidth(400);
table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDefinition).setPreferredWidth(30);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.
the class ViewObservablesMapPanel method updateShapeSpecies.
public void updateShapeSpecies(int selectedRow) {
GeneratedSpeciesTableRow speciesTableRow = speciesTableModel.getValueAt(selectedRow);
String inputString = speciesTableRow.getExpression();
// System.out.println(selectedRows[0] + ": " + inputString);
Model tempModel = null;
try {
tempModel = new Model("MyTempModel");
tempModel.addFeature("c0");
} catch (ModelException | PropertyVetoException e1) {
e1.printStackTrace();
}
if (owner != null && owner.getSimulationContext() != null) {
List<MolecularType> mtList = owner.getSimulationContext().getModel().getRbmModelContainer().getMolecularTypeList();
try {
tempModel.getRbmModelContainer().setMolecularTypeList(mtList);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
throw new RuntimeException("Unexpected exception setting " + MolecularType.typeName + " list: " + e1.getMessage(), e1);
}
} else {
System.out.println("something is wrong, we just do nothing rather than crash");
return;
}
try {
String strStructure = null;
if (inputString.contains(RbmUtils.SiteStruct)) {
// we are in the mode where we emulate compartments by adding the compartment name as a fake site
Pair<List<String>, String> p = RbmUtils.extractCompartment(inputString);
// we'll just assume there's only one, may want to throw exception if more
strStructure = p.one.get(0);
inputString = p.two;
} else {
// should be the normal @comp:expression format - if it's not it will return null
strStructure = RbmUtils.parseCompartment(inputString, tempModel);
}
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
if (owner.getSimulationContext().getModel().getStructure(strStructure).getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
tempModel.addMembrane(strStructure);
} else {
tempModel.addFeature(strStructure);
}
}
structure = tempModel.getStructure(strStructure);
} else {
structure = tempModel.getStructure(0);
}
SpeciesPattern sp = (SpeciesPattern) RbmUtils.parseSpeciesPattern(inputString, tempModel);
sp.resolveBonds();
SpeciesContext sc = new SpeciesContext(new Species("a", ""), structure, sp);
spls = new SpeciesPatternLargeShape(20, 20, -1, sp, shapePanelSpecies, sc, issueManager);
} catch (ParseException | PropertyVetoException | ModelException e1) {
e1.printStackTrace();
// error (red circle)
spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanelSpecies, true, issueManager);
shapePanelSpecies.repaint();
}
int xOffset = spls.getRightEnd() + 45;
Dimension preferredSize = new Dimension(xOffset + 90, 50);
shapePanelSpecies.setPreferredSize(preferredSize);
shapePanelSpecies.repaint();
}
use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.
the class RulebasedMathMapping method addObservables.
private List<ParticleObservable> addObservables(GeometryClass geometryClass, Domain domain, HashMap<SpeciesPattern, VolumeParticleSpeciesPattern> speciesPatternMap) throws MappingException, MathException {
ArrayList<ParticleObservable> observables = new ArrayList<>();
//
for (MathMappingParameter mathMappingParameter : getMathMappingParameters()) {
if (mathMappingParameter instanceof ObservableCountParameter) {
ObservableCountParameter observableCountParameter = (ObservableCountParameter) mathMappingParameter;
RbmObservable rbmObservable = observableCountParameter.getObservable();
ParticleObservable.ObservableType particleObservableType = null;
if (rbmObservable.getType() == RbmObservable.ObservableType.Molecules) {
particleObservableType = ParticleObservable.ObservableType.Molecules;
} else {
particleObservableType = ParticleObservable.ObservableType.Species;
}
ParticleObservable particleObservable = new VolumeParticleObservable(getMathSymbol(observableCountParameter, geometryClass), domain, particleObservableType);
switch(rbmObservable.getSequence()) {
case Multimolecular:
{
particleObservable.setSequence(Sequence.Multimolecular);
break;
}
case PolymerLengthEqual:
{
particleObservable.setSequence(Sequence.PolymerLengthEqual);
particleObservable.setQuantity(rbmObservable.getSequenceLength());
break;
}
case PolymerLengthGreater:
{
particleObservable.setSequence(Sequence.PolymerLengthGreater);
particleObservable.setQuantity(rbmObservable.getSequenceLength());
break;
}
default:
{
throw new RuntimeException("unexpected sequence " + rbmObservable.getSequence());
}
}
for (SpeciesPattern speciesPattern : rbmObservable.getSpeciesPatternList()) {
VolumeParticleSpeciesPattern vpsp = speciesPatternMap.get(speciesPattern);
particleObservable.addParticleSpeciesPattern(vpsp);
}
observables.add(particleObservable);
}
if (mathMappingParameter instanceof SpeciesCountParameter) {
SpeciesCountParameter speciesCountParameter = (SpeciesCountParameter) mathMappingParameter;
ParticleObservable.ObservableType particleObservableType = ParticleObservable.ObservableType.Species;
ParticleObservable particleObservable = new VolumeParticleObservable(getMathSymbol(speciesCountParameter, geometryClass), domain, particleObservableType);
particleObservable.setSequence(Sequence.Multimolecular);
SpeciesPattern speciesPattern = speciesCountParameter.getSpeciesContext().getSpeciesPattern();
VolumeParticleSpeciesPattern vpsp = speciesPatternMap.get(speciesPattern);
particleObservable.addParticleSpeciesPattern(vpsp);
observables.add(particleObservable);
}
}
return observables;
}
use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.
the class BioModelEditorModelPanel method newButtonPressed.
private void newButtonPressed() throws ModelException, PropertyVetoException {
newObject = null;
computeCurrentSelectedTable();
if (currentSelectedTable == speciesTable) {
if (bioModel.getModel().getNumStructures() == 1) {
newObject = bioModel.getModel().createSpeciesContext(bioModel.getModel().getStructures()[0]);
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
Structure s = bioModel.getModel().getStructure(i);
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
newObject = bioModel.getModel().createSpeciesContext(s);
}
});
}
menu.show(newButton, 0, newButton.getHeight());
}
} else if (currentSelectedTable == molecularTypeTable) {
if (bioModel.getModel().getRbmModelContainer() != null) {
MolecularType mt = bioModel.getModel().getRbmModelContainer().createMolecularType();
bioModel.getModel().getRbmModelContainer().addMolecularType(mt, true);
newObject = mt;
}
} else if (currentSelectedTable == observablesTable) {
if (bioModel.getModel().getRbmModelContainer() != null) {
if (bioModel.getModel().getRbmModelContainer().getMolecularTypeList().isEmpty()) {
PopupGenerator.showInfoDialog(this, VCellErrorMessages.MustBeRuleBased);
return;
}
if (bioModel.getModel().getNumStructures() == 1) {
RbmObservable o = bioModel.getModel().getRbmModelContainer().createObservable(RbmObservable.ObservableType.Molecules);
bioModel.getModel().getRbmModelContainer().addObservable(o);
SpeciesPattern sp = new SpeciesPattern();
o.addSpeciesPattern(sp);
newObject = o;
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
Structure s = bioModel.getModel().getStructure(i);
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
RbmObservable o = bioModel.getModel().getRbmModelContainer().createObservable(RbmObservable.ObservableType.Molecules, null, s);
o.setStructure(s);
try {
bioModel.getModel().getRbmModelContainer().addObservable(o);
} catch (ModelException | PropertyVetoException e1) {
e1.printStackTrace();
throw new RuntimeException(e1.getMessage(), e1);
}
SpeciesPattern sp = new SpeciesPattern();
o.addSpeciesPattern(sp);
newObject = o;
if (newObject != null) {
for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
if (currentSelectedTableModel.getValueAt(i) == newObject) {
currentSelectedTable.setRowSelectionInterval(i, i);
break;
}
}
}
}
});
}
menu.show(newButton, 0, newButton.getHeight());
}
}
} else if (currentSelectedTable == structuresTable) {
try {
Feature feature = bioModel.getModel().createFeature();
newObject = feature;
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, e.getMessage(), e);
}
} else if (currentSelectedTable == reactionsTable) {
if (bioModel.getModel().getNumStructures() == 1) {
SimpleReaction reactionStep = bioModel.getModel().createSimpleReaction(bioModel.getModel().getStructures()[0]);
newObject = reactionStep;
} else {
addNewReaction();
}
}
if (newObject != null) {
for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
if (currentSelectedTableModel.getValueAt(i) == newObject) {
currentSelectedTable.setRowSelectionInterval(i, i);
break;
}
}
}
}
use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.
the class BioModelEditorSpeciesTableModel method setValueAt.
public void setValueAt(Object value, int row, int column) {
if (getModel() == null || value == null) {
return;
}
try {
SpeciesContext speciesContext = getValueAt(row);
if (speciesContext != null) {
// row with existing species
switch(column) {
case COLUMN_NAME:
{
String inputValue = ((String) value);
inputValue = inputValue.trim();
if (inputValue.length() == 0) {
return;
}
speciesContext.setName(inputValue);
break;
}
case COLUMN_STRUCTURE:
{
// value might be null because no popup in JCombo editor ui.
// the first time.
Structure structure = (Structure) value;
speciesContext.setStructure(structure);
break;
}
case COLUMN_DEFINITION:
String inputValue = ((String) value);
inputValue = inputValue.trim();
if (inputValue.length() == 0) {
speciesContext.setSpeciesPattern(null);
return;
}
SpeciesPattern sp = RbmUtils.parseSpeciesPattern(inputValue, bioModel.getModel());
speciesContext.setSpeciesPattern(sp);
break;
}
} else {
// empty row being edited - Deprecated, we now must use the "New Species" button
switch(column) {
case // only "name" column is editable
COLUMN_NAME:
String inputValue = ((String) value);
if (inputValue.length() == 0 || inputValue.equals(ADD_NEW_HERE_TEXT)) {
return;
}
inputValue = inputValue.trim();
SpeciesContext freeSpeciesContext = getModel().createSpeciesContext(getModel().getStructures()[0]);
freeSpeciesContext.setName(inputValue);
break;
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(ownerTable, e.getMessage(), e);
}
}
Aggregations