use of org.vcell.util.document.Version in project vcell by virtualcell.
the class XmlReader method getBioModel.
/**
* This method returns a Biomodel object from a XML Element.
* Creation date: (3/13/2001 12:35:00 PM)
* @return cbit.vcell.biomodel.BioModel
* @param param org.jdom.Element
*/
public BioModel getBioModel(Element param, VCellSoftwareVersion docVcellSoftwareVersion) throws XmlParseException {
this.docVCellSoftwareVersion = docVcellSoftwareVersion;
// long l1 = System.currentTimeMillis();
// Get metadata information Version (if available)
Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// Create new biomodel
BioModel biomodel = new BioModel(version);
// Set name
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
try {
biomodel.setName(name);
// String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
// if (annotation!=null) {
// biomodel.setDescription(unMangle(annotation));
// }
// get annotation
String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotationText != null && annotationText.length() > 0) {
biomodel.setDescription(unMangle(annotationText));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
// long l2 = System.currentTimeMillis();
// System.out.println("biomodel-------- "+((double)(l2-l1))/1000);
// ***Add biomodel to the dictionnary***
// dictionnary.put(simcontext.getClass().getName()+":"+simcontext.getName(), simcontext);
// Set model
Model newmodel = getModel(param.getChild(XMLTags.ModelTag, vcNamespace));
biomodel.setModel(newmodel);
// Set simulation contexts
java.util.List<Element> children = param.getChildren(XMLTags.SimulationSpecTag, vcNamespace);
java.util.Iterator<Element> iterator = children.iterator();
// System.out.println("model-------- "+((double)(l3-l2))/1000);
while (iterator.hasNext()) {
// long l4 = System.currentTimeMillis();
Element tempElement = iterator.next();
SimulationContext simContext = getSimulationContext(tempElement, biomodel);
try {
biomodel.addSimulationContext(simContext);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("An error occurred while trying to add the SimContext " + simContext.getName() + " to the BioModel Object!", e);
}
// process the simulations within this Simspec
Iterator<Element> simIterator = tempElement.getChildren(XMLTags.SimulationTag, vcNamespace).iterator();
// System.out.println("simcontext-------- "+((double)(l5-l4))/1000);
while (simIterator.hasNext()) {
try {
biomodel.addSimulation(getSimulation((Element) simIterator.next(), simContext.getMathDescription()));
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException occurred when adding a Simulation entity to the BioModel " + name, e);
}
}
// long l6 = System.currentTimeMillis();
// System.out.println("sims-------- "+((double)(l6-l5))/1000);
}
// biomodel.getVCMetaData().setAnnotation(biomodel, param);
// biomodel.getVCMetaData().setNotes(biomodel, param);
boolean bMetaDataPopulated = false;
List<Element> elementsMetaData = param.getChildren(XMLMetaData.VCMETADATA_TAG, VCMetaData.nsVCML);
if (elementsMetaData != null && elementsMetaData.size() > 0) {
for (Element elementMetaData : elementsMetaData) {
XMLMetaDataReader.readFromElement(biomodel.getVCMetaData(), biomodel, elementMetaData);
}
bMetaDataPopulated = true;
} else {
// no metadata was found, populate vcMetaData from biomodel (mainly free text annotation for identifiables)
if (!bMetaDataPopulated) {
biomodel.populateVCMetadata(bMetaDataPopulated);
}
}
Element pathwayElement = param.getChild(XMLTags.PathwayModelTag, vcNamespace);
if (pathwayElement != null) {
Element rdfElement = pathwayElement.getChild(XMLRDF.tagRDF, XMLRDF.nsRDF);
if (rdfElement != null) {
PathwayReaderBiopax3 pathwayReader = new PathwayReaderBiopax3(new RDFXMLContext());
PathwayModel pathwayModel = pathwayReader.parse(rdfElement, false);
// ??? is this needed ???
pathwayModel.reconcileReferences(null);
// we keep as lvl 1 only the objects which we want to show in the diagram
pathwayModel.filterDiagramObjects();
biomodel.getPathwayModel().merge(pathwayModel);
} else {
throw new XmlParseException("expecting RDF element as child of pathwayModel within VCML document");
}
}
Element relationshipElement = param.getChild(XMLTags.RelationshipModelTag, vcNamespace);
if (relationshipElement != null) {
Element rmnsElement = relationshipElement.getChild("RMNS", vcNamespace);
if (rmnsElement != null) {
RelationshipReader relationshipReader = new RelationshipReader();
RelationshipModel relationshipModel = relationshipReader.parse(rmnsElement, biomodel);
biomodel.getRelationshipModel().merge(relationshipModel);
} else {
// throw new XmlParseException("expecting RMNS element as child of pathwayModel within VCML document");
}
}
return biomodel;
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class XmlReader method getModel.
/**
* This method creates a Model object from a XML element.
* Creation date: (3/14/2001 6:14:37 PM)
* @return cbit.vcell.model.Model
* @param param org.jdom.Element
*/
private Model getModel(Element param) throws XmlParseException {
if (param == null) {
throw new XmlParseException("Invalid 'NULL' XML 'model' element arrived!");
}
// Get version, if any
Model newmodel = null;
Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// if forcedModelUnitSystem has been set, ues that (could be overriding unit system for SBML export)
if (forcedModelUnitSystem != null) {
newmodel = new Model(version, forcedModelUnitSystem);
} else {
Element unitSystemNode = param.getChild(XMLTags.ModelUnitSystemTag, vcNamespace);
if (unitSystemNode != null) {
ModelUnitSystem modelUnitSystem = getUnitSystem(unitSystemNode);
newmodel = new Model(version, modelUnitSystem);
} else {
newmodel = new Model(version);
}
}
try {
// Set attributes
newmodel.setName(unMangle(param.getAttributeValue(XMLTags.NameAttrTag)));
// Add annotation
String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotationText != null && annotationText.length() > 0) {
newmodel.setDescription(unMangle(annotationText));
}
// Add global parameters
Element globalParamsElement = param.getChild(XMLTags.ModelParametersTag, vcNamespace);
if (globalParamsElement != null) {
ModelParameter[] modelParams = getModelParams(globalParamsElement, newmodel);
// add global/model param to model - done inside getModelParam by passing newModel
newmodel.setModelParameters(modelParams);
}
// Add Species (Compounds)
Iterator<Element> iterator = param.getChildren(XMLTags.SpeciesTag, vcNamespace).iterator();
ArrayList<Species> speciesList = new ArrayList<Species>();
while (iterator.hasNext()) {
org.jdom.Element temp = (Element) iterator.next();
speciesList.add(getSpecies(temp));
}
newmodel.setSpecies(speciesList.toArray(new Species[speciesList.size()]));
// Add Structures
LinkedList<Structure> newstructures = new LinkedList<Structure>();
// (features)
List<Element> children = param.getChildren(XMLTags.FeatureTag, vcNamespace);
for (Element featureElement : children) {
newstructures.add(getFeature(featureElement));
}
// (Membrane)
children = param.getChildren(XMLTags.MembraneTag, vcNamespace);
for (Element memElement : children) {
newstructures.add(getMembrane(newmodel, memElement, newstructures));
}
if (newstructures.size() > 0) {
Structure[] structarray = new Structure[newstructures.size()];
newstructures.toArray(structarray);
// Add all the retrieved structures
newmodel.setStructures(structarray);
}
// retrieve the RbmModelContainer, if present - must be done before we retrieve species context!
Element element = param.getChild(XMLTags.RbmModelContainerTag, vcNamespace);
if (element != null) {
getRbmModelContainer(element, newmodel);
} else {
lg.info("RbmModelContainer is missing.");
}
// Add SpeciesContexts
children = param.getChildren(XMLTags.SpeciesContextTag, vcNamespace);
SpeciesContext[] newspeccon = new SpeciesContext[children.size()];
int scCounter = 0;
for (Element scElement : children) {
newspeccon[scCounter] = getSpeciesContext(scElement, newmodel);
scCounter++;
}
newmodel.setSpeciesContexts(newspeccon);
// Retrieve rateRules and add to model
// Element rateRuleVarsElement = param.getChild(XMLTags.RateRuleVariablesTag, vcNamespace);
// if(rateRuleVarsElement != null){
// RateRuleVariable[] rateRuleVars = getRateRuleVariables(rateRuleVarsElement, newmodel);
// newmodel.setRateRuleVariables(rateRuleVars);
// }
// Add Reaction steps (if available)
// (Simplereaction)
// Create a varHash with reserved symbols and global parameters, if any, to pass on to Kinetics
// must create new hash for each reaction and flux, since each kinetics uses new variables hash
iterator = param.getChildren(XMLTags.SimpleReactionTag, vcNamespace).iterator();
ArrayList<ReactionStep> reactionStepList = new ArrayList<ReactionStep>();
while (iterator.hasNext()) {
org.jdom.Element temp = iterator.next();
reactionStepList.add(getSimpleReaction(temp, newmodel));
}
// (fluxStep)
iterator = param.getChildren(XMLTags.FluxStepTag, vcNamespace).iterator();
while (iterator.hasNext()) {
org.jdom.Element temp = iterator.next();
reactionStepList.add(getFluxReaction(temp, newmodel));
}
newmodel.setReactionSteps(reactionStepList.toArray(new ReactionStep[reactionStepList.size()]));
// Add Diagrams
children = param.getChildren(XMLTags.DiagramTag, vcNamespace);
if (children.size() > 0) {
Diagram[] newdiagrams = new Diagram[children.size()];
int diagramCounter = 0;
for (Element diagramElement : children) {
newdiagrams[diagramCounter] = getDiagram(diagramElement, newmodel);
diagramCounter++;
}
reorderDiagramsInPlace_UponRead(docVCellSoftwareVersion, newdiagrams, newmodel.getStructureTopology());
// if(docVCellSoftwareVersion != null && !docVCellSoftwareVersion.isValid() && docVCellSoftwareVersion.getMajorVersion()<=5 && docVCellSoftwareVersion.getMinorVersion() <=2){
// //In Vcell 5.2 and previous we need to order diagrams topologically, in 5.3 and later the diagrams are displayed as they are ordered when read from document
// final StructureTopology structureTopology = newmodel.getStructureTopology();
// Arrays.sort(newdiagrams, new Comparator<Diagram>() {
// @Override
// public int compare(Diagram o1, Diagram o2) {
// return getStructureLevel(o1.getStructure(), structureTopology) - getStructureLevel(o2.getStructure(), structureTopology);
// }
// });
// }
newmodel.setDiagrams(newdiagrams);
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException(e);
} catch (ModelException e) {
e.printStackTrace();
}
// model param expresions are not bound when they are read in, since they could be functions of each other or structures/speciesContexts.
// Hence bind the model param exprs at the end, after reading all model level quantities.
ModelParameter[] modelParameters = newmodel.getModelParameters();
for (int i = 0; modelParameters != null && i < modelParameters.length; i++) {
try {
modelParameters[i].getExpression().bindExpression(newmodel);
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error binding global parameter '" + modelParameters[i].getName() + "' to model." + e.getMessage());
}
}
return newmodel;
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class CheckBeforeDelete method run.
/**
* Insert the method's description here.
* Creation date: (5/31/2004 6:04:14 PM)
* @param hashTable java.util.Hashtable
* @param clientWorker cbit.vcell.desktop.controls.ClientWorker
*/
public void run(Hashtable<String, Object> hashTable) throws Exception {
DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
// JFrame currentDocumentWindow = (JFrame)hashTable.get("currentDocumentWindow");
VCDocument currentDocument = documentWindowManager.getVCDocument();
if (!hashTable.containsKey(SaveDocument.DOC_KEY)) {
throw new RuntimeException("CheckBeforeDelete task called although SaveDocument task did not complete - should have aborted!!");
}
// Don't delete ARCHIVE or PUBLISH documents
if (!currentDocument.getVersion().getFlag().compareEqual(VersionFlag.Current)) {
hashTable.put("conditionalSkip", new String[] { DeleteOldDocument.class.getName() });
return;
}
DocumentManager documentManager = (DocumentManager) hashTable.get(CommonTask.DOCUMENT_MANAGER.name);
Simulation[] simulations = (Simulation[]) hashTable.get("simulations");
VCDocument savedDocument = (VCDocument) hashTable.get(SaveDocument.DOC_KEY);
// just to make sure, verify that we actually did save a new edition
Version oldVersion = currentDocument.getVersion();
Version newVersion = savedDocument.getVersion();
if (newVersion.getVersionKey().compareEqual(oldVersion.getVersionKey())) {
// throw new DataAccessException("CheckBeforeDelete task called but saved document has same version with current document");
hashTable.put("conditionalSkip", new String[] { DeleteOldDocument.class.getName() });
return;
}
// we saved a new one, now check for lost simulation data and warn the user
Simulation[] simulationsWithLostResults = null;
switch(currentDocument.getDocumentType()) {
case BIOMODEL_DOC:
{
simulationsWithLostResults = checkLostResults((BioModel) currentDocument, (BioModel) savedDocument, documentManager, simulations);
break;
}
case MATHMODEL_DOC:
{
simulationsWithLostResults = checkLostResults((MathModel) currentDocument, (MathModel) savedDocument, documentManager, simulations);
break;
}
case GEOMETRY_DOC:
default:
// nothing to check for in this case
return;
}
boolean bLost = simulationsWithLostResults != null && simulationsWithLostResults.length > 0;
if (bLost) {
String choice = PopupGenerator.showWarningDialog(documentWindowManager, documentWindowManager.getUserPreferences(), UserMessage.question_LostResults, null);
if (choice.equals(UserMessage.OPTION_SAVE_AS_NEW_EDITION)) {
// user canceled deletion
throw UserCancelException.CANCEL_DELETE_OLD;
}
if (choice.equals(UserMessage.OPTION_CANCEL)) {
throw UserCancelException.CANCEL_GENERIC;
}
}
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class CheckUnchanged method run.
/**
* Insert the method's description here.
* Creation date: (5/31/2004 6:04:14 PM)
* @param hashTable java.util.Hashtable
* @param clientWorker cbit.vcell.desktop.controls.ClientWorker
*/
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
DocumentManager documentManager = (DocumentManager) hashTable.get(CommonTask.DOCUMENT_MANAGER.name);
// JFrame currentDocumentWindow = (JFrame)hashTable.get("currentDocumentWindow");
if (documentWindowManager.getVCDocument().getDocumentType() == VCDocumentType.MATHMODEL_DOC) {
if (((MathModelWindowManager) documentWindowManager).hasUnappliedChanges()) {
String msg = "Changes have been made in VCML Editor, please click \"Apply Changes\" or \"Cancel\" to proceed.";
PopupGenerator.showErrorDialog(documentWindowManager, msg);
throw UserCancelException.CANCEL_UNAPPLIED_CHANGES;
}
}
boolean isChanged = true;
Version v = documentWindowManager.getVCDocument().getVersion();
if (v == null || !v.getOwner().equals(documentManager.getSessionManager().getUser())) {
isChanged = true;
} else {
try {
isChanged = documentManager.isChanged(documentWindowManager.getVCDocument());
} catch (DataAccessException exc) {
String choice = PopupGenerator.showWarningDialog(documentWindowManager, documentWindowManager.getUserPreferences(), UserMessage.warn_UnableToCheckForChanges, null);
if (!choice.equals(UserMessage.OPTION_CONTINUE)) {
throw UserCancelException.WARN_UNABLE_CHECK;
}
}
}
if (!isChanged) {
if (whileSavingForRunningSims) {
// just skip the saves and go ahead
hashTable.put("conditionalSkip", new String[] { SaveDocument.class.getName(), CheckBeforeDelete.class.getName(), DeleteOldDocument.class.getName() });
} else {
String choice = PopupGenerator.showWarningDialog(documentWindowManager, documentWindowManager.getUserPreferences(), UserMessage.warn_UnchangedDocument, null);
if (choice.equals(UserMessage.OPTION_SAVE_AS_NEW)) {
// user chose to Save As
throw UserCancelException.CHOOSE_SAVE_AS;
} else {
// user canceled, just show existing document
throw UserCancelException.WARN_NO_CHANGES;
}
}
}
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class VCellBasicCellRenderer method setComponentProperties.
/**
* Insert the method's description here.
* Creation date: (5/8/01 8:35:45 AM)
* @return javax.swing.Icon
* @param nodeUserObject java.lang.Object
*/
protected void setComponentProperties(JLabel component, VCImageInfo imageInfo) {
// component.setIcon(new ImageIcon(imageInfo.getBrowseGif().getGifEncodedData()));
Version version = imageInfo.getVersion();
String access = (version.getGroupAccess().getDescription());
component.setToolTipText("Image");
ISize size = imageInfo.getISize();
String description = null;
if (size.getZ() > 1) {
description = "3D image (" + size.getX() + "," + size.getY() + "," + size.getZ() + ")";
} else if (size.getY() > 1) {
description = "2D image (" + size.getX() + "," + size.getY() + ")";
} else {
description = "1D image (" + size.getX() + ")";
}
component.setText(access + " " + description + " \"" + version.getName() + "\"" + " (" + version.getDate() + ")");
}
Aggregations