use of cbit.vcell.model.Model.RbmModelContainer in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* Outputs a XML version of a Model object
* Creation date: (2/15/2001 11:39:27 AM)
* @return Element
* @param param cbit.vcell.model.Model
*/
private Element getXML(Model param) throws XmlParseException /*, cbit.vcell.parser.ExpressionException */
{
Element modelnode = new Element(XMLTags.ModelTag);
String versionName = (param.getName() != null) ? mangle(param.getName()) : "unnamed_model";
// get Attributes
modelnode.setAttribute(XMLTags.NameAttrTag, versionName);
// modelnode.setAttribute(XMLTags.AnnotationAttrTag, this.mangle(param.getDescription()));
if (param.getDescription() != null && param.getDescription().length() > 0) {
Element annotationElem = new Element(XMLTags.AnnotationTag);
annotationElem.setText(mangle(param.getDescription()));
modelnode.addContent(annotationElem);
}
// get global parameters
ModelParameter[] modelGlobals = param.getModelParameters();
if (modelGlobals != null && modelGlobals.length > 0) {
modelnode.addContent(getXML(modelGlobals));
}
// Get Species
Species[] array = param.getSpecies();
for (int i = 0; i < array.length; i++) {
modelnode.addContent(getXML(array[i]));
}
// Get Structures(Features and Membranes). Add them in an ordered fashion, but it does not matter who comes first.
try {
ArrayList<Element> list = new ArrayList<Element>();
Structure[] structarray = param.getStructures();
for (int i = 0; i < structarray.length; i++) {
Element structure = getXML(structarray[i], param);
if (structarray[i] instanceof Feature)
modelnode.addContent(structure);
else
list.add(structure);
}
for (int i = 0; i < list.size(); i++) {
modelnode.addContent((Element) list.get(i));
}
} catch (XmlParseException e) {
e.printStackTrace();
throw new XmlParseException("An error occurred while procesing a Structure for the model " + versionName, e);
}
// Process SpeciesContexts
SpeciesContext[] specarray = param.getSpeciesContexts();
for (int i = 0; i < specarray.length; i++) {
modelnode.addContent(getXML(specarray[i]));
}
// Get reaction Steps(Simple Reactions and Fluxtep)
ReactionStep[] reactarray = param.getReactionSteps();
for (int i = 0; i < reactarray.length; i++) {
modelnode.addContent(getXML(reactarray[i]));
}
// add the rbmModelContainer elements
RbmModelContainer rbmModelContainer = param.getRbmModelContainer();
if (rbmModelContainer != null && !rbmModelContainer.isEmpty()) {
Element rbmModelContainerElement = getXML(rbmModelContainer);
{
// for testing purposes only
Document doc = new Document();
Element clone = (Element) rbmModelContainerElement.clone();
doc.setRootElement(clone);
String xmlString = XmlUtil.xmlToString(doc, false);
System.out.println(xmlString);
}
modelnode.addContent(rbmModelContainerElement);
}
// // Add rate rules
// if (param.getRateRuleVariables()!=null && param.getRateRuleVariables().length>0){
// modelnode.addContent( getXML(param.getRateRuleVariables()) );
// }
// Get Diagrams
Diagram[] diagarray = param.getDiagrams();
for (int i = 0; i < diagarray.length; i++) {
modelnode.addContent(getXML(diagarray[i]));
}
// Add Metadata information
if (param.getVersion() != null) {
modelnode.addContent(getXML(param.getVersion(), param));
}
// add model UnitSystem
ModelUnitSystem unitSystem = param.getUnitSystem();
if (unitSystem != null) {
modelnode.addContent(getXML(unitSystem));
}
return modelnode;
}
use of cbit.vcell.model.Model.RbmModelContainer in project vcell by virtualcell.
the class XmlReader method getRbmReactionRuleList.
private void getRbmReactionRuleList(Element param, Model newModel) throws XmlParseException {
RbmModelContainer mc = newModel.getRbmModelContainer();
List<ReactionRule> rrl = mc.getReactionRuleList();
List<Element> children = new ArrayList<Element>();
children = param.getChildren(XMLTags.RbmReactionRuleTag, vcNamespace);
for (Element element : children) {
ReactionRule r = getRbmReactionRule(element, newModel);
if (r != null) {
rrl.add(r);
}
}
}
use of cbit.vcell.model.Model.RbmModelContainer in project vcell by virtualcell.
the class ObservableTableModel method bioModelChange.
@Override
protected void bioModelChange(PropertyChangeEvent evt) {
super.bioModelChange(evt);
BioModel oldValue = (BioModel) evt.getOldValue();
if (oldValue != null) {
RbmModelContainer rbmModelContainer = (RbmModelContainer) (oldValue.getModel().getRbmModelContainer());
// TODO: listen to something ??? rbmModelContainer.removePropertyChangeListener(this);
for (RbmObservable observable : rbmModelContainer.getObservableList()) {
observable.removePropertyChangeListener(this);
for (SpeciesPattern speciesPattern : observable.getSpeciesPatternList()) {
RbmUtils.removePropertyChangeListener(speciesPattern, this);
}
}
}
BioModel newValue = (BioModel) evt.getNewValue();
if (newValue != null) {
RbmModelContainer rbmModelContainer = (RbmModelContainer) (newValue.getModel().getRbmModelContainer());
// TODO: rbmModelContainer.addPropertyChangeListener(this);
for (RbmObservable observable : rbmModelContainer.getObservableList()) {
observable.addPropertyChangeListener(this);
for (SpeciesPattern speciesPattern : observable.getSpeciesPatternList()) {
RbmUtils.addPropertyChangeListener(speciesPattern, this);
}
}
}
}
use of cbit.vcell.model.Model.RbmModelContainer in project vcell by virtualcell.
the class ClientRequestManager method createBioModelFromApplication.
public void createBioModelFromApplication(final BioModelWindowManager requester, final String name, final SimulationContext simContext) {
if (simContext == null) {
PopupGenerator.showErrorDialog(requester, "Selected Application is null, cannot generate corresponding bio model");
return;
}
if (simContext.isRuleBased()) {
createRuleBasedBioModelFromApplication(requester, name, simContext);
return;
}
AsynchClientTask task1 = new AsynchClientTask("Creating BioModel from BioModel Application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
MathMappingCallback dummyCallback = new MathMappingCallback() {
public void setProgressFraction(float percentDone) {
}
public void setMessage(String message) {
}
public boolean isInterrupted() {
return false;
}
};
MathMapping transformedMathMapping = simContext.createNewMathMapping(dummyCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
BioModel newBioModel = new BioModel(null);
SimulationContext transformedSimContext = transformedMathMapping.getTransformation().transformedSimContext;
Model newModel = transformedSimContext.getModel();
newBioModel.setModel(newModel);
RbmModelContainer rbmmc = newModel.getRbmModelContainer();
for (RbmObservable o : rbmmc.getObservableList()) {
rbmmc.removeObservable(o);
}
for (ReactionRule r : rbmmc.getReactionRuleList()) {
rbmmc.removeReactionRule(r);
}
for (ReactionStep rs : newModel.getReactionSteps()) {
String oldName = rs.getName();
if (oldName.startsWith("_reverse_")) {
String newName = newModel.getReactionName("rev", oldName.substring("_reverse_".length()));
rs.setName(newName);
}
}
hashTable.put("newBioModel", newBioModel);
}
};
AsynchClientTask task2 = new AsynchClientTask("Creating BioModel from BioModel Application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModel newBioModel = (BioModel) hashTable.get("newBioModel");
DocumentWindowManager windowManager = createDocumentWindowManager(newBioModel);
// if(simContext.getBioModel().getVersion() != null){
// ((BioModelWindowManager)windowManager). setCopyFromBioModelAppVersionableTypeVersion(
// new VersionableTypeVersion(VersionableType.BioModelMetaData, simContext.getBioModel().getVersion()));
// }
getMdiManager().createNewDocumentWindow(windowManager);
}
};
ClientTaskDispatcher.dispatch(requester.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
use of cbit.vcell.model.Model.RbmModelContainer in project vcell by virtualcell.
the class PathwayMapping method createMolecularTypeFromBioPaxObject.
// TODO: not in use
// public void createBioModelEntitiesFromBioPaxObjects(BioModel bioModel, Object[] selectedObjects) throws Exception
// {
// for(int i = 0; i < selectedObjects.length; i++) {
// if(selectedObjects[i] instanceof BioPaxObject) {
// BioPaxObject bioPaxObject = (BioPaxObject)selectedObjects[i];
// if(bioPaxObject instanceof PhysicalEntity && !(bioPaxObject instanceof Complex)) {
// createMolecularTypeFromBioPaxObject(bioModel, (PhysicalEntity)bioPaxObject);
// }
// } else if(selectedObjects[i] instanceof ConversionTableRow) {
// ConversionTableRow ctr = (ConversionTableRow)selectedObjects[i];
// if(ctr.getBioPaxObject() instanceof PhysicalEntity && !(ctr.getBioPaxObject() instanceof Complex)) {
// createMolecularTypeFromBioPaxObject(bioModel, (PhysicalEntity)ctr.getBioPaxObject());
// }
// }
// }
//
// for(int i = 0; i < selectedObjects.length; i++) {
// if(selectedObjects[i] instanceof BioPaxObject) {
// BioPaxObject bioPaxObject = (BioPaxObject)selectedObjects[i];
// if(bioPaxObject instanceof PhysicalEntity) {
// createSpeciesContextFromBioPaxObject(bioModel, (PhysicalEntity)bioPaxObject);
// } else if(bioPaxObject instanceof Conversion) {
// createReactionStepsFromBioPaxObject(bioModel, (Conversion)bioPaxObject);
// }
// } else if(selectedObjects[i] instanceof ConversionTableRow) {
// ConversionTableRow ctr = (ConversionTableRow)selectedObjects[i];
// if(ctr.getBioPaxObject() instanceof PhysicalEntity) {
// createSpeciesContextFromTableRow(bioModel, (PhysicalEntity)ctr.getBioPaxObject(), ctr.stoich(), ctr.id(), ctr.location());
// } else if(ctr.getBioPaxObject() instanceof Conversion) {
// createReactionStepsFromTableRow(bioModel, (Conversion)ctr.getBioPaxObject(), ctr.stoich(), ctr.id(), ctr.location());
// }
// }
// }
// }
private MolecularType createMolecularTypeFromBioPaxObject(BioModel bioModel, PhysicalEntity bioPaxObject, boolean addSubunits) {
String name;
if (bioPaxObject.getName().size() == 0) {
name = getSafetyName(bioPaxObject.getID());
} else {
name = getSafetyName(bioPaxObject.getName().get(0));
}
RbmModelContainer rbmmc = bioModel.getModel().getRbmModelContainer();
if (rbmmc.getMolecularType(name) != null) {
// already exists
MolecularType mt = rbmmc.getMolecularType(name);
// check whether it links to pathway object, create relationship object if not
if (!bioModel.getRelationshipModel().isRelationship(mt, bioPaxObject)) {
RelationshipObject ro = new RelationshipObject(mt, bioPaxObject);
bioModel.getRelationshipModel().addRelationshipObject(ro);
}
return mt;
}
int numSubunits = 0;
if (addSubunits) {
for (String comment : bioPaxObject.getComments()) {
numSubunits = StringUtils.countMatches(comment, "SUBUNIT:");
}
}
MolecularType mt = new MolecularType(name, bioModel.getModel());
try {
for (int i = 0; i < numSubunits; i++) {
MolecularComponent mc = new MolecularComponent("Subunit" + i);
mt.addMolecularComponent(mc);
}
rbmmc.addMolecularType(mt, true);
// we know for sure that a relationship can't exist, so we make one
RelationshipObject ro = new RelationshipObject(mt, bioPaxObject);
bioModel.getRelationshipModel().addRelationshipObject(ro);
} catch (ModelException | PropertyVetoException e) {
e.printStackTrace();
}
ArrayList<String> commentList = bioPaxObject.getComments();
final String htmlStart = "<html><font face = \"Arial\"><font size =\"-2\">";
final String htmlEnd = "</font></font></html>";
if (commentList != null && !commentList.isEmpty()) {
String comment = commentList.get(0);
if (!comment.isEmpty()) {
String text = FormatDetails(comment);
mt.setComment(htmlStart + text + htmlEnd);
}
} else {
mt.setComment("");
}
return mt;
}
Aggregations