use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.
the class BioCartoonTool method pasteMolecules.
// private static void pasteMolecules(Set<MolecularType> mtFromListStrict, Model modelTo, Map<Structure, String> structuresMap) {
// for(MolecularType mtFrom : mtFromListStrict) {
// try {
// MolecularType mtTo = new MolecularType(mtFrom, modelTo, structuresMap);
// modelTo.getRbmModelContainer().addMolecularType(mtTo, false);
// } catch (ModelException | PropertyVetoException e) {
// e.printStackTrace();
// throw new RuntimeException(e.getMessage());
// }
// }
// }
private static void pasteMolecules(Set<MolecularType> mtFromListStrict, Model modelTo, Map<Structure, String> structuresMap) {
List<MolecularType> listOfMoleculesToAdd = new ArrayList<>();
try {
for (MolecularType mtFrom : mtFromListStrict) {
MolecularType mtTo = new MolecularType(mtFrom, modelTo, structuresMap);
listOfMoleculesToAdd.add(mtTo);
}
modelTo.getRbmModelContainer().addMolecularTypes(listOfMoleculesToAdd);
} catch (ModelException | PropertyVetoException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.
the class GeneratedReactionTableRow method deriveRule.
private void deriveRule(String inputString, Model tempModel) {
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 {
// This should not be possible
throw new RuntimeException("Owner or SimulationContext are null.");
}
int arrowIndex = inputString.indexOf("<->");
boolean bReversible = true;
if (arrowIndex < 0) {
arrowIndex = inputString.indexOf("->");
bReversible = false;
}
String left = inputString.substring(0, arrowIndex).trim();
String right = inputString.substring(arrowIndex + (bReversible ? 3 : 2)).trim();
if (left.length() == 0 && right.length() == 0) {
return;
}
String name = reactionObject.getRuleName();
if (name.contains(GeneratedReactionTableModel.reverse)) {
name = name.substring(GeneratedReactionTableModel.reverse.length());
}
if (name.endsWith(ReactionRule.DirectHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.DirectHalf));
}
if (name.endsWith(ReactionRule.InverseHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.InverseHalf));
}
// try to get the name of the original structure from the original rule and make here another structure with the same name
String strStructure = null;
Structure ruleStructure;
SimulationContext sc = owner.getSimulationContext();
ReactionRule rr = sc.getModel().getRbmModelContainer().getReactionRule(name);
if (rr != null && rr.getStructure() != null) {
strStructure = rr.getStructure().getName();
}
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
try {
tempModel.addFeature(strStructure);
} catch (ModelException | PropertyVetoException e) {
e.printStackTrace();
}
}
ruleStructure = tempModel.getStructure(strStructure);
} else {
throw new RuntimeException("Failed to recover a Structure name from the Reaction Rule: " + name);
}
// making the fake rules just for display purpose, actually they are the flattened reactions resulted from bngl
// the name is probably not unique, it's likely that many flattened reactions are derived from the same rule
reactionRule = tempModel.getRbmModelContainer().createReactionRule(name, ruleStructure, bReversible);
String regex = "[^!]\\+";
String[] patterns = left.split(regex);
for (String spString : patterns) {
try {
spString = spString.trim();
// if compartments are present, we're making some fake compartments in the tempModel just for compartment name display purposes
SpeciesPattern speciesPattern = (SpeciesPattern) RbmUtils.parseSpeciesPattern(spString, tempModel);
strStructure = RbmUtils.parseCompartment(spString, tempModel);
speciesPattern.resolveBonds();
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
tempModel.addFeature(strStructure);
}
structure = tempModel.getStructure(strStructure);
} else {
// if nothing explicit for a participant, we use by default the structure of the rule
structure = ruleStructure;
}
reactionRule.addReactant(new ReactantPattern(speciesPattern, structure));
} catch (Throwable ex) {
ex.printStackTrace();
return;
}
}
patterns = right.split(regex);
for (String spString : patterns) {
try {
spString = spString.trim();
SpeciesPattern speciesPattern = (SpeciesPattern) RbmUtils.parseSpeciesPattern(spString, tempModel);
strStructure = RbmUtils.parseCompartment(spString, tempModel);
speciesPattern.resolveBonds();
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
tempModel.addFeature(strStructure);
}
structure = tempModel.getStructure(strStructure);
} else {
structure = ruleStructure;
}
reactionRule.addProduct(new ProductPattern(speciesPattern, structure));
} catch (Throwable ex) {
ex.printStackTrace();
return;
}
}
}
use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.
the class GeneratedSpeciesTableRow method deriveSpecies.
private void deriveSpecies(String inputString, Model tempModel) {
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);
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) {
tempModel.addFeature(strStructure);
}
structure = tempModel.getStructure(strStructure);
} else {
structure = tempModel.getStructure(0);
}
SpeciesPattern sp = (SpeciesPattern) RbmUtils.parseSpeciesPattern(inputString, tempModel);
sp.resolveBonds();
// System.out.println(sp.toString());
species = new SpeciesContext(new Species("a", ""), structure, sp);
} catch (ParseException | PropertyVetoException | ModelException e1) {
e1.printStackTrace();
}
}
use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.
the class ViewGeneratedSpeciesPanel method updateShape.
public void updateShape(int selectedRow) {
GeneratedSpeciesTableRow speciesTableRow = tableModel.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, shapePanel, sc, issueManager);
} catch (ParseException | PropertyVetoException | ModelException e1) {
e1.printStackTrace();
// error (red circle)
spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanel, true, issueManager);
shapePanel.repaint();
}
int xOffset = spls.getRightEnd() + 45;
Dimension preferredSize = new Dimension(xOffset + 90, 50);
shapePanel.setPreferredSize(preferredSize);
shapePanel.repaint();
}
use of org.vcell.model.rbm.MolecularType 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();
}
Aggregations