Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
danv61 committed Dec 16, 2024
1 parent 248a984 commit 7a79c1b
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package cbit.vcell.solver.ode.gui;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.*;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.*;
import javax.swing.border.Border;

import cbit.vcell.solver.NFsimSimulationOptions;
import org.vcell.util.gui.CollapsiblePanel;
import org.vcell.util.gui.DialogUtils;

import cbit.vcell.client.PopupGenerator;
import cbit.vcell.solver.LangevinSimulationOptions;
import cbit.vcell.solver.OutputTimeSpec;
import cbit.vcell.solver.SolverTaskDescription;
import org.vcell.util.gui.DialogUtils;

@SuppressWarnings("serial")
public class LangevinOptionsPanel extends CollapsiblePanel {
Expand All @@ -39,6 +35,11 @@ public class LangevinOptionsPanel extends CollapsiblePanel {
private JLabel numPartitionsZLabel = null;
private JLabel numPartitionsLabel = null;

private JCheckBox randomSeedCheckBox;
private JTextField randomSeedTextField;
private JButton randomSeedHelpButton = null;


// private int[] npart = {LangevinSimulationOptions.DefaultNPart[0], LangevinSimulationOptions.DefaultNPart[1], LangevinSimulationOptions.DefaultNPart[2]}; // number of partitions on each axis

private JTextField intervalImageTextField = null;
Expand Down Expand Up @@ -72,6 +73,21 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
getJTextFieldNumOfTrials().setEnabled(true);
getJTextFieldNumOfParallelLocalRuns().setEnabled(true);
setNewOptions();
} else if(e.getSource() == randomSeedCheckBox) {
randomSeedTextField.setEditable(randomSeedCheckBox.isSelected());
if(randomSeedCheckBox.isSelected()) {

Integer rs = solverTaskDescription.getLangevinSimulationOptions().getRandomSeed();
if(rs == null) {
rs = LangevinSimulationOptions.DefaultRandomSeed;
solverTaskDescription.getLangevinSimulationOptions().setRandomSeed(rs);
}
randomSeedTextField.setText(rs.toString());
} else {
solverTaskDescription.getLangevinSimulationOptions().setRandomSeed(null);
randomSeedTextField.setText("");
}

}
}

Expand Down Expand Up @@ -189,7 +205,6 @@ private void initialize() {
gbc.insets = new Insets(0,5,3,1);
trialPanel.add(getJTextFieldNumOfParallelLocalRuns(), gbc);

// ----- aici
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 3;
Expand Down Expand Up @@ -246,6 +261,14 @@ private void initialize() {
gbc.insets = new Insets(0,5,3,1);
trialPanel.add(getNumPartitionsZTextField(), gbc);

gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 6;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5,5,3,1);
trialPanel.add(getRandomSeedCheckBox(), gbc);


// gbc = new GridBagConstraints(); // --- empty panel (filler)
// gbc.gridx = 3;
Expand Down Expand Up @@ -311,6 +334,24 @@ private void initialize() {
gbc.weighty = 1.0;
centerPanel.add(new JLabel(""), gbc);

gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 3;
gbc.weightx = 1;
gbc.gridwidth = 2;
gbc.insets = new Insets(0, 0, 6, 6);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.LINE_START;
centerPanel.add(getRandomSeedTextField(), gbc);

gbc = new GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = 3;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(0, 0, 6, 6);
centerPanel.add(getRandomSeedHelpButton(), gbc);


// ----- rightPanel ----------------------------------------------------
gbc = new GridBagConstraints();
gbc.gridx = 3;
Expand Down Expand Up @@ -398,6 +439,34 @@ private javax.swing.JLabel getNumOfTrialsLabel() {
}
return numOfTrialsLabel;
}
private JCheckBox getRandomSeedCheckBox() {
if(randomSeedCheckBox == null) {
randomSeedCheckBox = new JCheckBox();
randomSeedCheckBox.setName("RandomSeedCheckBox");
randomSeedCheckBox.setText("Set a seed to Langevin random number generator.");
}
return randomSeedCheckBox;
}
private JTextField getRandomSeedTextField() {
if(randomSeedTextField == null) {
randomSeedTextField = new JTextField();
randomSeedTextField.setName("RandomSeedTextField");
randomSeedTextField.setText("");
}
return randomSeedTextField;
}
private JButton getRandomSeedHelpButton() {
if(randomSeedHelpButton == null) {
Border border = BorderFactory.createEmptyBorder(1, 1, 1, 1);
randomSeedHelpButton = new JButton();
Font font = randomSeedHelpButton.getFont().deriveFont(Font.BOLD);
randomSeedHelpButton.setName("RandomSeedHelpButton");
randomSeedHelpButton.setBorder(border);
randomSeedHelpButton.setFont(font);
randomSeedHelpButton.setText(" ? ");
}
return randomSeedHelpButton;
}

// ======================================================================= Number of Partitions
private javax.swing.JTextField getNumPartitionsXTextField() {
Expand Down Expand Up @@ -590,7 +659,7 @@ private void refresh() {
setVisible(true);

LangevinSimulationOptions lso = solverTaskDescription.getLangevinSimulationOptions();
int numTrials = lso.getNumOfTrials();
int numTrials = lso.getNumTrials();
int numOfParallelLocalRuns = lso.getNumOfParallelLocalRuns();
if(numTrials == 1) {
getTrajectoryButton().setSelected(true);
Expand Down Expand Up @@ -635,11 +704,22 @@ private void setNewOptions() {

if(getMultiRunButton().isSelected()) {
numTrials = Integer.parseInt(getJTextFieldNumOfTrials().getText());
sso.setNumOfTrials(numTrials);
numOfParallelLocalRuns = Integer.parseInt(getJTextFieldNumOfParallelLocalRuns().getText());
sso.setNumOfParallelLocalRuns(numOfParallelLocalRuns);
}


Integer randomSeed = null;
if (randomSeedCheckBox.isSelected()) {
try {
randomSeed = Integer.valueOf(randomSeedTextField.getText());
} catch (NumberFormatException ex) {
randomSeed = solverTaskDescription.getLangevinSimulationOptions().getRandomSeed();
if(randomSeed == null) {
randomSeed = LangevinSimulationOptions.DefaultRandomSeed;
}
randomSeedTextField.setText(randomSeed.toString());
}
}

intervalImage = Double.parseDouble(getJTextFieldIntervalImage().getText());
intervalSpring = Double.parseDouble(getJTextFieldIntervalSpring().getText());

Expand All @@ -649,6 +729,9 @@ private void setNewOptions() {

// make a copy
LangevinSimulationOptions lso = new LangevinSimulationOptions(sso);
lso.setNumTrials(numTrials);
lso.setNumOfParallelLocalRuns(numOfParallelLocalRuns);
lso.setRandomSeed(randomSeed);
lso.setIntervalImage(intervalImage);
lso.setIntervalSpring(intervalSpring);
lso.setNPart(npart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.Serializable;

import org.vcell.util.CommentStringTokenizer;
import org.vcell.util.Compare;
import org.vcell.util.DataAccessException;
import org.vcell.util.Matchable;

Expand All @@ -42,9 +41,13 @@ public class LangevinSimulationOptions implements Serializable, Matchable, Vetoa

public final static int[] DefaultNPart = { 10, 10, 10 };

protected int numOfTrials = 1; // how many runs of the solver for this simulation
public final static int DefaultRandomSeed = 1;
public final static int DefaultNumTrials = 1;

protected int numTrials = DefaultNumTrials; // how many runs of the solver for this simulation
protected int numOfParallelLocalRuns = 1; // how many instances of the solver run in parallel
protected int runIndex = 0; // run index, will result in Run0 (followed by Run1, 2,...)
protected Integer randomSeed = DefaultRandomSeed;

protected double intervalSpring = 1.00E-9; // default: dtspring: 1.00E-9 - from advanced
protected double intervalImage = 1.00E-4; // default: dtimage: 1.00E-4 - from advanced
Expand All @@ -62,7 +65,7 @@ public LangevinSimulationOptions(LangevinSimulationOptions langevinSimulationOpt
this(); // TODO: properly implement copy constructor
intervalSpring = langevinSimulationOptions.intervalSpring;
intervalImage = langevinSimulationOptions.intervalImage;
numOfTrials = langevinSimulationOptions.numOfTrials;
numTrials = langevinSimulationOptions.numTrials;
runIndex = langevinSimulationOptions.runIndex;
npart[0] = langevinSimulationOptions.npart[0];
npart[1] = langevinSimulationOptions.npart[1];
Expand All @@ -79,7 +82,7 @@ public boolean compareEqual(Matchable obj) {
return false;
}
LangevinSimulationOptions langevinSimulationOptions = (LangevinSimulationOptions)obj;
if(numOfTrials != langevinSimulationOptions.numOfTrials) {
if(numTrials != langevinSimulationOptions.numTrials) {
return false;
}
if(runIndex != langevinSimulationOptions.runIndex) {
Expand All @@ -102,15 +105,15 @@ public boolean compareEqual(Matchable obj) {

// can be between 0 and numOfTrials-1
public int getRunIndex() { // for multiple trials the runIndex must be incremented for each run, dynamically
if(runIndex > numOfTrials-1) {
if(runIndex > numTrials -1) {
throw new RuntimeException("Max run index must be smaller than the number of trials.");
}
int currentRunIndex = runIndex;
runIndex++;
return currentRunIndex;
}
public int getNumOfTrials() {
return numOfTrials;
public int getNumTrials() {
return numTrials;
}
public int getNumOfParallelLocalRuns() {
return numOfParallelLocalRuns;
Expand All @@ -127,12 +130,15 @@ public int getNPart(int index) {
public int[] getNPart() {
return npart;
}
public Integer getRandomSeed() {
return randomSeed;
}

public final void setRunIndex(int newValue) {
this.runIndex = newValue;
}
public final void setNumOfTrials(int newValue) {
this.numOfTrials = newValue;
public final void setNumTrials(int newValue) {
this.numTrials = newValue;
}
public final void setNumOfParallelLocalRuns(int newValue) {
this.numOfParallelLocalRuns = newValue;
Expand All @@ -151,6 +157,11 @@ public final void setNPart(int[] npart) {
public final void setNPart(int index, int npart) {
this.npart[index] = npart;
}
public void setRandomSeed(Integer randomSeed) {
this.randomSeed = randomSeed;
}

// ------------------------------------------------------------------------------------------

public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener listener) {
getPropertyChange().addPropertyChangeListener(listener);
Expand Down Expand Up @@ -186,7 +197,7 @@ private void fireVetoableChange(java.lang.String propertyName, java.lang.Object
public String getVCML() {
StringBuffer buffer = new StringBuffer();
buffer.append("\t" + VCML.LangevinSimulationOptions + " " + VCML.BeginBlock + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_numOfTrials + " " + numOfTrials + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_numOfTrials + " " + numTrials + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_runIndex + " " + runIndex + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_intervalSpring + " " + intervalSpring + "\n");
buffer.append("\t\t" + VCML.LangevinSimulationOptions_intervalImage + " " + intervalImage + "\n");
Expand Down Expand Up @@ -239,7 +250,7 @@ public void readVCML(CommentStringTokenizer tokens) throws DataAccessException {
if(val2 < 1 ) {
throw new DataAccessException("unexpected token " + token + ", num of trials is requied to be at least 1. ");
} else {
numOfTrials = val2;
numTrials = val2;
}
} else {
throw new DataAccessException("unexpected identifier " + token);
Expand All @@ -262,4 +273,5 @@ public void refreshDependencies() {
removeVetoableChangeListener(this);
addVetoableChangeListener(this);
}

}
4 changes: 1 addition & 3 deletions vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.vcell.pathway.persistence.RDFXMLContext;
import org.vcell.relationship.RelationshipModel;
import org.vcell.relationship.persistence.RelationshipReader;
import org.vcell.sbml.vcell.StructureSizeSolver;
import org.vcell.util.BeanUtils;
import org.vcell.util.Commented;
import org.vcell.util.Coordinate;
Expand Down Expand Up @@ -261,7 +260,6 @@
import cbit.vcell.parser.Expression;
import cbit.vcell.parser.ExpressionBindingException;
import cbit.vcell.parser.ExpressionException;
import cbit.vcell.parser.ParserException;
import cbit.vcell.parser.SymbolTableEntry;
import cbit.vcell.render.Vect3d;
import cbit.vcell.solver.AnnotatedFunction.FunctionCategory;
Expand Down Expand Up @@ -6700,7 +6698,7 @@ private LangevinSimulationOptions getLangevinSimulationOptions(Element langevinS
String temp = null;
temp = langevinSimulationOptionsElement.getChildText(XMLTags.LangevinSO_numOfTrials, vcNamespace);
if(temp != null){
lo.setNumOfTrials(Integer.parseInt(temp));
lo.setNumTrials(Integer.parseInt(temp));
}
temp = langevinSimulationOptionsElement.getChildText(XMLTags.LangevinSO_intervalSpring, vcNamespace);
if(temp != null){
Expand Down
2 changes: 1 addition & 1 deletion vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4807,7 +4807,7 @@ private Element getXML(LangevinSimulationOptions lso) {
Element lsoe = new Element(XMLTags.LangevinSimulationOptions);

e = new Element(XMLTags.LangevinSO_numOfTrials);
e.setText(String.valueOf(lso.getNumOfTrials()));
e.setText(String.valueOf(lso.getNumTrials()));
lsoe.addContent(e);

e = new Element(XMLTags.LangevinSO_intervalSpring);
Expand Down

0 comments on commit 7a79c1b

Please sign in to comment.