use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.
the class RbmNetworkGenerator method generateModel.
public static void generateModel(BioModel bioModel, String netfile) throws Exception {
Model model = bioModel.getModel();
Map<String, SpeciesContext> speciesMap = new HashMap<String, SpeciesContext>();
Map<String, ReactionStep> reactionMap = new HashMap<String, ReactionStep>();
List<ReactionLine> reactionLineList = new ArrayList<ReactionLine>();
BufferedReader br = new BufferedReader(new StringReader(netfile));
int reversibleCount = 0;
int reactionCount = 0;
while (true) {
String line = br.readLine();
if (line == null) {
break;
}
line = line.trim();
if (line.equals(BEGIN_PARAMETERS)) {
while (true) {
String line2 = br.readLine();
line2 = line2.trim();
if (line2.length() == 0) {
continue;
}
if (line2.equals(END_PARAMETERS)) {
break;
}
StringTokenizer st = new StringTokenizer(line2);
String token1 = st.nextToken();
String token2 = st.nextToken();
String token3 = st.nextToken();
ModelParameter mp = model.new ModelParameter(token2, new Expression(token3), Model.ROLE_UserDefined, bioModel.getModel().getUnitSystem().getInstance_TBD());
model.addModelParameter(mp);
}
} else if (line.equals(BEGIN_SPECIES)) {
while (true) {
String line2 = br.readLine();
line2 = line2.trim();
if (line2.length() == 0) {
continue;
}
if (line2.equals(END_SPECIES)) {
break;
}
StringTokenizer st = new StringTokenizer(line2);
// no
String token1 = st.nextToken();
// pattern
String token2 = st.nextToken();
// initial condition
String token3 = st.nextToken();
String newname = token2.replaceAll("\\.", "_");
newname = newname.replaceAll("[\\(,][a-zA-Z]\\w*", "");
newname = newname.replaceAll("~|!\\d*", "");
newname = newname.replaceAll("\\(\\)", "");
newname = newname.replaceAll("\\)", "");
SpeciesContext sc = model.createSpeciesContext(model.getStructure(0));
sc.setName(newname);
bioModel.getVCMetaData().setFreeTextAnnotation(sc, token2);
bioModel.getVCMetaData().setFreeTextAnnotation(sc.getSpecies(), token2);
speciesMap.put(token1, sc);
}
} else if (line.equals(BEGIN_REACTIONS)) {
while (true) {
String line2 = br.readLine();
line2 = line2.trim();
if (line2.length() == 0) {
continue;
}
if (line2.equals(END_REACTIONS)) {
break;
}
++reactionCount;
StringTokenizer st = new StringTokenizer(line2);
String token1 = st.nextToken();
// reactants
String token2 = st.nextToken();
// products
String token3 = st.nextToken();
// rate
String token4 = st.nextToken();
String token5 = st.nextToken();
boolean bFoundReversible = false;
Expression rate = new Expression(token4);
for (ReactionLine rl : reactionLineList) {
if (token2.equals(rl.products) && token3.equals(rl.reactants) && token5.equals(rl.ruleLabel + "r")) {
ReactionStep rs = reactionMap.get(rl.no);
((MassActionKinetics) rs.getKinetics()).getReverseRateParameter().setExpression(rate);
reactionLineList.remove(rl);
bFoundReversible = true;
break;
}
}
if (bFoundReversible) {
++reversibleCount;
continue;
}
ReactionLine rl = new ReactionLine(token1, token2, token3, token5);
reactionLineList.add(rl);
SimpleReaction reaction = model.createSimpleReaction(model.getStructure(0));
reactionMap.put(token1, reaction);
reaction.setModel(model);
bioModel.getVCMetaData().setFreeTextAnnotation(reaction, line2);
MassActionKinetics kinetics = new MassActionKinetics(reaction);
reaction.setKinetics(kinetics);
st = new StringTokenizer(token2, ",");
while (st.hasMoreTokens()) {
String t = st.nextToken();
SpeciesContext sc = speciesMap.get(t);
if (sc != null) {
boolean bExists = false;
for (ReactionParticipant rp : reaction.getReactionParticipants()) {
if (rp instanceof Reactant && rp.getSpeciesContext() == sc) {
rp.setStoichiometry(rp.getStoichiometry() + 1);
bExists = true;
break;
}
}
if (!bExists) {
reaction.addReactant(sc, 1);
}
}
}
st = new StringTokenizer(token3, ",");
while (st.hasMoreTokens()) {
String t = st.nextToken();
SpeciesContext sc = speciesMap.get(t);
if (sc != null) {
boolean bExists = false;
for (ReactionParticipant rp : reaction.getReactionParticipants()) {
if (rp instanceof Product && rp.getSpeciesContext() == sc) {
rp.setStoichiometry(rp.getStoichiometry() + 1);
bExists = true;
break;
}
}
if (!bExists) {
reaction.addProduct(sc, 1);
}
}
}
kinetics.getForwardRateParameter().setExpression(rate);
}
}
}
System.out.println(model.getNumSpecies() + " species added");
System.out.println(model.getNumReactions() + " reactions added");
System.out.println(reversibleCount + " reversible reactions found");
if (reactionCount != model.getNumReactions() + reversibleCount) {
throw new RuntimeException("Reactions are not imported correctly!");
}
}
use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.
the class BioModelEditorRightSideTableModel method bioModelChange.
protected void bioModelChange(java.beans.PropertyChangeEvent evt) {
BioModel oldValue = (BioModel) evt.getOldValue();
if (oldValue != null) {
oldValue.removePropertyChangeListener(this);
oldValue.getModel().removePropertyChangeListener(this);
}
BioModel newValue = (BioModel) evt.getNewValue();
refreshData();
if (newValue != null) {
newValue.addPropertyChangeListener(this);
newValue.getModel().addPropertyChangeListener(this);
}
}
use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.
the class BioModelEditorStructureTableModel method bioModelChange.
@Override
protected void bioModelChange(PropertyChangeEvent evt) {
super.bioModelChange(evt);
BioModel oldValue = (BioModel) evt.getOldValue();
if (oldValue != null) {
for (Structure s : oldValue.getModel().getStructures()) {
s.removePropertyChangeListener(this);
}
}
BioModel newValue = (BioModel) evt.getNewValue();
if (newValue != null) {
for (Structure s : newValue.getModel().getStructures()) {
s.addPropertyChangeListener(this);
}
}
}
use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.
the class BioModelParametersPanel method changeUnitsButtonPressed.
public void changeUnitsButtonPressed() {
UnitSystemSelectionPanel unitSystemSelectionPanel = new UnitSystemSelectionPanel();
unitSystemSelectionPanel.initialize(bioModel.getModel().getUnitSystem());
int retcode = DialogUtils.showComponentOKCancelDialog(this, unitSystemSelectionPanel, "select new unit system");
while (retcode == JOptionPane.OK_OPTION) {
ModelUnitSystem forcedModelUnitSystem;
try {
forcedModelUnitSystem = unitSystemSelectionPanel.createModelUnitSystem();
BioModel newBioModel = ModelUnitConverter.createBioModelWithNewUnitSystem(bioModel, forcedModelUnitSystem);
this.bioModelWindowManager.resetDocument(newBioModel);
break;
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(this, e.getMessage(), e);
retcode = DialogUtils.showComponentOKCancelDialog(this, unitSystemSelectionPanel, "select new unit system");
}
}
}
use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.
the class DocumentEditor method treeSelectionChanged0.
private void treeSelectionChanged0(TreeSelectionEvent treeSelectionEvent) {
try {
treeSelectionChanged();
Object selectedNode = documentEditorTree.getLastSelectedPathComponent();
if (selectedNode != null && (selectedNode instanceof BioModelNode)) {
Object selectedObject = ((BioModelNode) selectedNode).getUserObject();
DocumentEditorTreeFolderClass folderClass = null;
if (selectedObject instanceof DocumentEditorTreeFolderNode) {
folderClass = ((DocumentEditorTreeFolderNode) selectedObject).getFolderClass();
}
ActiveView activeView = new ActiveView(getSelectedSimulationContext(), folderClass, null);
selectionManager.setActiveView(activeView);
if (/*selectedObject instanceof SimulationContext
|| */
selectedObject instanceof BioModel || selectedObject instanceof MathModel) {
selectionManager.setSelectedObjects(new Object[] { selectedObject });
}
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
}
Aggregations