Skip to content

Commit

Permalink
Merge pull request #11 from shmarovfedor/master
Browse files Browse the repository at this point in the history
output to table, 2D plot, added time series
  • Loading branch information
Fedor Shmarov committed Apr 30, 2015
2 parents 38ff8ce + ffc194f commit 3a5b9f4
Show file tree
Hide file tree
Showing 29 changed files with 4,757 additions and 36 deletions.
Binary file modified BioPSy/bin/ParSyn
Binary file not shown.
2,528 changes: 2,528 additions & 0 deletions BioPSy/jsbml.log

Large diffs are not rendered by default.

105 changes: 74 additions & 31 deletions BioPSy/src/gui/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,29 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import parser.OutputParser;
import parser.SMT2SettingsParser;
import parser.TraceParser;
import util.BackgroundWorker;
import util.ModelSettings;
import util.SMT2Settings;
import util.Utility;
import util.*;
import util.Box;
import util.Utility.Tuple;

public class Gui implements ActionListener {
private JFrame gui;

private JTextArea outTextArea, timeSeriesTextArea, sbmlTextArea;

private BoxTable boxTable;

private Box domain;

private JTextField sbml, series, noise;

private JButton browseSBML, browseSeries, generateSMT2, run, advancedOptionsButton, stopButton, okButton;

private JScrollPane paramsScroll, speciesScroll, outputScroll, timeSeriesScroll, sbmlScroll;
private JScrollPane paramsScroll, speciesScroll, outputScroll, timeSeriesScroll, sbmlScroll, problemScroll, graphOutputScroll;

private PlotPanel plotPanel2D;

private JLabel sbmlLabel, seriesLabel, noiseLabel;

Expand Down Expand Up @@ -134,7 +139,7 @@ public Gui(){

// Create text area for program output
outTextArea = new JTextArea();
outTextArea.setText("Program output will be displayed here");
outTextArea.setText("Execution problems will be displayed here");
outTextArea.setEditable(false);
// Updating the text area
DefaultCaret caret = (DefaultCaret) outTextArea.getCaret();
Expand All @@ -156,6 +161,10 @@ public Gui(){
speciesScroll.setMinimumSize(new Dimension(600, 400));
speciesScroll.setPreferredSize(new Dimension(600, 400));

problemScroll = new JScrollPane();
problemScroll.setMinimumSize(new Dimension(600, 400));
problemScroll.setPreferredSize(new Dimension(600, 400));

outputScroll = new JScrollPane();
outputScroll.setMinimumSize(new Dimension(600, 400));
outputScroll.setPreferredSize(new Dimension(600, 400));
Expand All @@ -168,18 +177,28 @@ public Gui(){
timeSeriesScroll.setMinimumSize(new Dimension(600, 400));
timeSeriesScroll.setPreferredSize(new Dimension(600, 400));

outputScroll.setViewportView(outTextArea);
graphOutputScroll = new JScrollPane();
graphOutputScroll.setMinimumSize(new Dimension(600, 400));
graphOutputScroll.setPreferredSize(new Dimension(600, 400));


problemScroll.setViewportView(outTextArea);
paramsScroll.setViewportView(paramsPanel);
speciesScroll.setViewportView(speciesPanel);
sbmlScroll.setViewportView(sbmlTextArea);
timeSeriesScroll.setViewportView(timeSeriesTextArea);
boxTable = new BoxTable();
outputScroll.setViewportView(boxTable);

tabbedPane = new JTabbedPane();
tabbedPane.addTab("SBML", sbmlScroll);
tabbedPane.addTab("Time series", timeSeriesScroll);
tabbedPane.addTab("Parameters", paramsScroll);
tabbedPane.addTab("Variables", speciesScroll);
tabbedPane.addTab("Problems", problemScroll);
tabbedPane.addTab("Output", outputScroll);
tabbedPane.addTab("Plot(2D only)", graphOutputScroll);
tabbedPane.setEnabledAt(6, false);

topPanel.add(sbmlLabel);
topPanel.add(sbml);
Expand Down Expand Up @@ -403,18 +422,17 @@ public void actionPerformed(ActionEvent e) {
Map<String, Tuple<Double, Double>> variables = new HashMap<String, Tuple<Double, Double>>();
Map<String, ASTNode> odes = new HashMap<String, ASTNode>();
List<String> params = new ArrayList<String>();
domain = new Box(Box.BoxType.DOMAIN);
for (int i = 4; i < paramsPanel.getComponentCount(); i += 4) {
if (((JCheckBox) paramsPanel.getComponent(i)).isSelected()) {
variables.put(
((JLabel) paramsPanel.getComponent(i + 1))
.getText(),
new Tuple<Double, Double>(Double
.parseDouble(((JTextField) paramsPanel
.getComponent(i + 2)).getText()
.trim()), Double
.parseDouble(((JTextField) paramsPanel
.getComponent(i + 3)).getText()
.trim())));

String paramName = ((JLabel) paramsPanel.getComponent(i + 1)).getText();
double paramLeft = Double.parseDouble(((JTextField) paramsPanel.getComponent(i + 2)).getText().trim());
double paramRight = Double.parseDouble(((JTextField) paramsPanel.getComponent(i + 3)).getText().trim());

domain.addInterval(new Interval(paramLeft, paramRight, paramName));

variables.put(paramName, new Tuple<Double, Double>(paramLeft, paramRight));
params.add(((JLabel) paramsPanel.getComponent(i + 1))
.getText());
}
Expand All @@ -423,14 +441,14 @@ public void actionPerformed(ActionEvent e) {
.getText().trim())), params);
for (int i = 3; i < speciesPanel.getComponentCount(); i += 3) {
variables.put(
((JLabel) speciesPanel.getComponent(i)).getText(),
new Tuple<Double, Double>(Double
.parseDouble(((JTextField) speciesPanel
.getComponent(i + 1)).getText()
.trim()), Double
.parseDouble(((JTextField) speciesPanel
.getComponent(i + 2)).getText()
.trim())));
((JLabel) speciesPanel.getComponent(i)).getText(),
new Tuple<Double, Double>(Double
.parseDouble(((JTextField) speciesPanel
.getComponent(i + 1)).getText()
.trim()), Double
.parseDouble(((JTextField) speciesPanel
.getComponent(i + 2)).getText()
.trim())));
odes.put(
((JLabel) speciesPanel.getComponent(i)).getText(),
model.getODE(((JLabel) speciesPanel.getComponent(i))
Expand All @@ -443,6 +461,18 @@ public void actionPerformed(ActionEvent e) {
.trim())), Double.parseDouble(noise
.getText().trim())));

// creating a table
boxTable.setDomain(domain);

if(domain.getIntervals().size() == 2) {

tabbedPane.setEnabledAt(6, true);
plotPanel2D = new PlotPanel(domain);
graphOutputScroll.setViewportView(plotPanel2D);
} else {
tabbedPane.setEnabledAt(6, false);
}

// Creating a background worker
bgWorker = new BackgroundWorker(outTextArea);

Expand All @@ -451,7 +481,7 @@ public void actionPerformed(ActionEvent e) {
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getNewValue() == SwingWorker.StateValue.STARTED) {
tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 2);
run.setEnabled(false);
advancedOptionsButton.setEnabled(false);
stopButton.setEnabled(true);
Expand Down Expand Up @@ -484,12 +514,22 @@ public void propertyChange(PropertyChangeEvent evt) {

outputListener = new Thread() {

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();

@Override
public void run() {
while(!bgWorker.isDone()) {
try {
Thread.sleep(1000);
OutputParser.parse("model.xml.output");
boxTable.updateRows(OutputParser.getBoxes());
if(domain.getIntervals().size() == 2) {
plotPanel2D.updateBoxes(OutputParser.getBoxes());
}
progressBar.setValue((int) (OutputParser.getProgress() * 100));
} catch (Exception e1) {
e1.printStackTrace();
}

/*
File outputFile = new File("model.xml.output");
if(outputFile.exists()) {
try {
Expand All @@ -510,6 +550,7 @@ public void run() {
e1.printStackTrace();
}
}
*/
}
if (isStopped) {
outTextArea.append("\nComputation was stopped by the user\n");
Expand Down Expand Up @@ -537,7 +578,9 @@ public void run() {
} catch (TransformerException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
141 changes: 141 additions & 0 deletions BioPSy/src/gui/PlotPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package gui;

import model.TimeSeriesModel;
import util.*;
import util.Box;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
* Created by fedor on 24/04/15.
*/
public class PlotPanel extends JPanel {

private double xScale = 1;
private double yScale = 1;
private int panelWidth = 400;
private int panelHeight = 400;
private int panelLeft = 200;
private int panelTop = 50;
private int xGrid = 5;
private int yGrid = 5;
//private List<Box2D> boxes;
private List<Box> boxes = new ArrayList<Box>();
private double xMin;
private double xMax;
private double yMin;
private double yMax;
private List<String> params;
private Box domain;

private Color finalSatColor = new Color(255, 222, 6);
private Color satColor = new Color(0,0,0);
private Color unsatColor = new Color(255,255,255);
private Color undetColor = new Color(180,180,180);

public PlotPanel(Box domain) {
super();
this.domain = domain;
xScale = panelWidth / domain.getIntervals().get(0).getWidth();
yScale = panelHeight / domain.getIntervals().get(1).getWidth();
}

public PlotPanel() {
super();
}

public int xCoor(double x) {
return panelLeft + (int) Math.ceil(xScale * (x - domain.getIntervals().get(0).getLeft()));
}

public int yCoor(double y) {
return panelTop + panelHeight - (int) Math.ceil(yScale * (y - domain.getIntervals().get(1).getLeft()));
}

public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(new Color(200, 234, 255));
g2.fillRect(panelLeft, panelTop, panelWidth, panelHeight);
g2.setColor(new Color(0, 0, 0));
g2.drawRect(panelLeft, panelTop, panelWidth, panelHeight);

drawBoxes(g2);
drawNet(g2);
drawLabels(g2);
//repaint();
}

public void updateBoxes(List<Box> boxes) {
this.boxes = boxes;
repaint();
}

public void drawBoxes(Graphics2D g2) {
for(int i = 0; i < boxes.size(); i++) {
if(boxes.get(i).getType() == Box.BoxType.SAT) {
if(boxes.get(i).getTime() == TimeSeriesModel.getTimePoints().get(TimeSeriesModel.getTimePoints().size() - 1))
{
g2.setColor(finalSatColor);
} else {
g2.setColor(satColor);
}
}
if(boxes.get(i).getType() == Box.BoxType.UNSAT) {
g2.setColor(unsatColor);
}
if(boxes.get(i).getType() == Box.BoxType.UNDET) {
g2.setColor(undetColor);
}

if(boxes.get(i).getIntervals().get(0).getName().equals(domain.getIntervals().get(0).getName())) {
g2.fillRect(xCoor(boxes.get(i).getIntervals().get(0).getLeft()),
yCoor(boxes.get(i).getIntervals().get(1).getRight()),
(int) Math.ceil(xScale * boxes.get(i).getIntervals().get(0).getWidth()),
(int) Math.ceil(yScale * boxes.get(i).getIntervals().get(1).getWidth()));
//System.out.println("normal");
} else {
g2.fillRect(xCoor(boxes.get(i).getIntervals().get(1).getLeft()),
yCoor(boxes.get(i).getIntervals().get(0).getRight()),
(int) Math.ceil(xScale * boxes.get(i).getIntervals().get(1).getWidth()),
(int) Math.ceil(yScale * boxes.get(i).getIntervals().get(0).getWidth()));
//System.out.println("reversed");
}

}
}

public void drawNet(Graphics2D g2) {
g2.setFont(new Font(g2.getFont().getFontName(), Font.PLAIN, 18));
g2.setColor(new Color(0, 0, 0));
DecimalFormat df = new DecimalFormat();
// vertical lines and labels
for(int i = 0; i <= xGrid; i++) {
g2.drawLine(panelLeft + i * (panelWidth / xGrid), panelTop, panelLeft + i * (panelWidth / xGrid), panelTop + panelHeight);
g2.drawString(df.format(domain.getIntervals().get(0).getLeft() + i * domain.getIntervals().get(0).getWidth() / xGrid), panelLeft + i * (panelWidth / xGrid) - 30, panelTop + panelHeight + 40);
}
// horizontal lines and labels
for(int i = 0; i <= yGrid; i++) {
g2.drawLine(panelLeft, panelTop + i * (panelHeight / yGrid), panelLeft + panelWidth, panelTop + i * (panelHeight / yGrid));
g2.drawString(df.format(domain.getIntervals().get(1).getLeft() + i * domain.getIntervals().get(1).getWidth() / yGrid), panelLeft - 130, panelTop + panelHeight - i * (panelHeight / yGrid) + 10);
}
}

public void drawLabels(Graphics2D g2) {

g2.setFont(new Font(g2.getFont().getFontName(), Font.ITALIC, 36));
AffineTransform at = new AffineTransform();
g2.drawString(domain.getIntervals().get(0).getName(), panelLeft + panelWidth / 2, panelTop + panelHeight + 100);
at.rotate(-Math.PI / 2);
g2.setTransform(at);
g2.drawString(domain.getIntervals().get(1).getName(), -(panelTop + panelHeight / 2), 60);
at.rotate(Math.PI / 2);
g2.setTransform(at);
}

}
3 changes: 2 additions & 1 deletion BioPSy/src/main/BioPSy.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main;

import gui.Gui;
import model.AdvancedOptionsModel;

/**
*
Expand All @@ -20,7 +21,7 @@ public class BioPSy {
* - the program arguments
*/
public static void main(String[] args) {
new Gui();
new Gui();
// if (args.length > 2) {
// try {
// String prop = args[2];
Expand Down
8 changes: 5 additions & 3 deletions BioPSy/src/model/AdvancedOptionsModel.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package model;

import main.BioPSy;

/**
* Created by Fedor Shmarov on 23/03/15.
*/
public class AdvancedOptionsModel {

private static String drealBinPath = "/usr/bin/dReal";
private static String drealBinPath = "./dReal";

private static String drealOptions = "-precision=1e-3";

private static String parsynBinPath = "/usr/bin/ParSyn";
private static String parsynBinPath = "./ParSyn";

private static String parsynOptions = "-e 1e-3 --output";
private static String parsynOptions = "-e 1e-3";

private static int parsynPID = -1;

Expand Down
Loading

0 comments on commit 3a5b9f4

Please sign in to comment.