Search in sources :

Example 21 with RbmModelContainer

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;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) Document(org.jdom.Document) Feature(cbit.vcell.model.Feature) Diagram(cbit.vcell.model.Diagram) ModelParameter(cbit.vcell.model.Model.ModelParameter) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) ReactionStep(cbit.vcell.model.ReactionStep) Structure(cbit.vcell.model.Structure) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 22 with RbmModelContainer

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);
        }
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) Element(org.jdom.Element) ArrayList(java.util.ArrayList)

Example 23 with RbmModelContainer

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);
            }
        }
    }
}
Also used : RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) BioModel(cbit.vcell.biomodel.BioModel) RbmObservable(cbit.vcell.model.RbmObservable) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 24 with RbmModelContainer

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) ReactionRule(cbit.vcell.model.ReactionRule) Hashtable(java.util.Hashtable) RbmObservable(cbit.vcell.model.RbmObservable) SimulationContext(cbit.vcell.mapping.SimulationContext) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) BioModel(cbit.vcell.biomodel.BioModel) ReactionStep(cbit.vcell.model.ReactionStep) MathMapping(cbit.vcell.mapping.MathMapping) ASTModel(org.vcell.model.bngl.ASTModel) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) ListSelectionModel(javax.swing.ListSelectionModel) BioModel(cbit.vcell.biomodel.BioModel) CSGObject(cbit.vcell.geometry.CSGObject)

Example 25 with RbmModelContainer

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;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) PropertyVetoException(java.beans.PropertyVetoException) ModelException(cbit.vcell.model.ModelException) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) MolecularComponent(org.vcell.model.rbm.MolecularComponent)

Aggregations

RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)26 MolecularType (org.vcell.model.rbm.MolecularType)12 Element (org.jdom.Element)10 BioModel (cbit.vcell.biomodel.BioModel)9 ArrayList (java.util.ArrayList)9 Model (cbit.vcell.model.Model)8 ReactionRule (cbit.vcell.model.ReactionRule)7 SimulationContext (cbit.vcell.mapping.SimulationContext)5 RbmObservable (cbit.vcell.model.RbmObservable)5 ReactionStep (cbit.vcell.model.ReactionStep)5 Structure (cbit.vcell.model.Structure)5 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)4 ParticleMolecularType (cbit.vcell.math.ParticleMolecularType)4 SpeciesContext (cbit.vcell.model.SpeciesContext)4 MathModel (cbit.vcell.mathmodel.MathModel)3 Expression (cbit.vcell.parser.Expression)3 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)3 Geometry (cbit.vcell.geometry.Geometry)2 BioEvent (cbit.vcell.mapping.BioEvent)2 GeometryContext (cbit.vcell.mapping.GeometryContext)2