Search in sources :

Example 66 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class BioModelEditorModelPanel method setBioModel.

public void setBioModel(BioModel newValue) {
    BioModel oldValue = bioModel;
    bioModel = newValue;
    firePropertyChange(PROPERTY_NAME_BIO_MODEL, oldValue, newValue);
    if (oldValue != null && oldValue.getModel() != null) {
        oldValue.getModel().removePropertyChangeListener(eventHandler);
    }
    if (bioModel != null && bioModel.getModel() != null) {
        bioModel.getModel().addPropertyChangeListener(eventHandler);
    }
    SortPreference sp = new SortPreference(true, BioModelEditorReactionTableModel.COLUMN_NAME);
    reactionTableModel.setSortPreference(sp);
}
Also used : BioModel(cbit.vcell.biomodel.BioModel) SortPreference(org.vcell.util.gui.sorttable.SortPreference)

Example 67 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class VCellSBMLSolver method importSBML.

private BioModel importSBML(String filename, VCLogger logger, boolean isSpatial) throws ClassNotFoundException, IOException, ExecutableException, XmlParseException, XMLStreamException {
    org.vcell.sbml.vcell.SBMLImporter sbmlImporter = new org.vcell.sbml.vcell.SBMLImporter(filename, logger, false);
    BioModel bioModel = sbmlImporter.getBioModel();
    return bioModel;
}
Also used : SBMLImporter(org.vcell.sbml.vcell.SBMLImporter) BioModel(cbit.vcell.biomodel.BioModel) SBMLImporter(org.vcell.sbml.vcell.SBMLImporter)

Example 68 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class RestDatabaseService method query.

public SimulationRepresentation query(BiomodelSimulationServerResource resource, User vcellUser) throws SQLException, DataAccessException, ExpressionException, XmlParseException, MappingException, MathException, MatrixException, ModelException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    ArrayList<String> conditions = new ArrayList<String>();
    String bioModelID = (String) resource.getRequestAttributes().get(VCellApiApplication.BIOMODELID);
    if (bioModelID != null) {
        conditions.add("(" + BioModelTable.table.id.getQualifiedColName() + " = " + bioModelID + ")");
    } else {
        throw new RuntimeException(VCellApiApplication.BIOMODELID + " not specified");
    }
    StringBuffer conditionsBuffer = new StringBuffer();
    for (String condition : conditions) {
        if (conditionsBuffer.length() > 0) {
            conditionsBuffer.append(" AND ");
        }
        conditionsBuffer.append(condition);
    }
    int startRow = 1;
    int maxRows = 1;
    BioModelRep[] bioModelReps = databaseServerImpl.getBioModelReps(vcellUser, conditionsBuffer.toString(), null, startRow, maxRows);
    for (BioModelRep bioModelRep : bioModelReps) {
        KeyValue[] simContextKeys = bioModelRep.getSimContextKeyList();
        for (KeyValue scKey : simContextKeys) {
            SimContextRep scRep = getSimContextRep(scKey);
            if (scRep != null) {
                bioModelRep.addSimContextRep(scRep);
            }
        }
        KeyValue[] simulationKeys = bioModelRep.getSimKeyList();
        for (KeyValue simKey : simulationKeys) {
            SimulationRep simulationRep = getSimulationRep(simKey);
            if (simulationRep != null) {
                bioModelRep.addSimulationRep(simulationRep);
            }
        }
    }
    if (bioModelReps == null || bioModelReps.length != 1) {
        // 
        // try to determine if the current credentials are insufficient, try to fetch BioModel again with administrator privilege.
        // 
        User adminUser = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
        BioModelRep[] allBioModelReps = databaseServerImpl.getBioModelReps(adminUser, conditionsBuffer.toString(), null, startRow, 1);
        if (allBioModelReps != null && allBioModelReps.length >= 0) {
            throw new PermissionException("insufficient privilege to retrive BioModel " + bioModelID);
        } else {
            throw new RuntimeException("failed to get biomodel");
        }
    }
    String simulationId = (String) resource.getRequestAttributes().get(VCellApiApplication.SIMULATIONID);
    if (simulationId == null) {
        throw new RuntimeException(VCellApiApplication.SIMULATIONID + " not specified");
    }
    SimulationRep simRep = getSimulationRep(new KeyValue(simulationId));
    BigString bioModelXML = databaseServerImpl.getBioModelXML(vcellUser, bioModelReps[0].getBmKey());
    BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
    return new SimulationRepresentation(simRep, bioModel);
}
Also used : PermissionException(org.vcell.util.PermissionException) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) ArrayList(java.util.ArrayList) BioModelRep(cbit.vcell.modeldb.BioModelRep) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource) SimContextRep(cbit.vcell.modeldb.SimContextRep) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 69 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class BNGWindowManager method importSbml.

/**
 * Comment
 */
public void importSbml(String bngSbmlStr) {
    if (bngSbmlStr == null || bngSbmlStr.length() == 0) {
        throw new RuntimeException("SBMl string is empty, cannot import into VCell.");
    }
    // 
    // 1. Convert SBML string from BNG to SBML model, add unitDefintions to SBML model using VCell sbml compatible unit system
    // 2. Import unit modified SBML model into VCell as biomodel
    // 3. Enforce "cleaner" (looking) units on this imported biomodel (can use the units added to the sbml model above)
    // 4. Convert all LumpedKinetics reactions into DistributedKinetics.
    // 4. Convert this biomodel into vcml string and pass it into XMLInfo and then to RequestManager to open document.
    // 
    ModelUnitSystem mus = ModelUnitSystem.createDefaultVCModelUnitSystem();
    ModelUnitSystem sbmlCompatibleVCModelUnitSystem = ModelUnitSystem.createSBMLUnitSystem(mus.getVolumeSubstanceUnit(), mus.getVolumeUnit(), mus.getAreaUnit(), mus.getLengthUnit(), mus.getTimeUnit());
    // display to user to change units if desired.
    UnitSystemSelectionPanel unitSystemSelectionPanel = new UnitSystemSelectionPanel(true);
    unitSystemSelectionPanel.initialize(sbmlCompatibleVCModelUnitSystem);
    int retcode = DialogUtils.showComponentOKCancelDialog(getBngOutputPanel(), unitSystemSelectionPanel, "Select new unit system to import into VCell");
    ModelUnitSystem forcedModelUnitSystem = null;
    while (retcode == JOptionPane.OK_OPTION) {
        try {
            forcedModelUnitSystem = unitSystemSelectionPanel.createModelUnitSystem();
            break;
        } catch (Exception e) {
            e.printStackTrace(System.out);
            DialogUtils.showErrorDialog(getBngOutputPanel(), e.getMessage(), e);
            retcode = DialogUtils.showComponentOKCancelDialog(getBngOutputPanel(), unitSystemSelectionPanel, "Select new unit system to import into VCell");
        }
    }
    if (forcedModelUnitSystem == null) {
        DialogUtils.showErrorDialog(getBngOutputPanel(), "Units are required for import into Virtual Cell.");
    }
    try {
        // SBMLUnitTranslator.addUnitDefinitionsToSbmlModel(bngSbmlStr, forcedModelUnitSystem);
        String modifiedSbmlStr = bngSbmlStr;
        // Create a default VCLogger - SBMLImporter needs it
        cbit.util.xml.VCLogger logger = new cbit.util.xml.VCLogger() {

            @Override
            public void sendMessage(Priority p, ErrorType et, String message) throws Exception {
                System.err.println("LOGGER: msgLevel=" + p + ", msgType=" + et + ", " + message);
                if (p == VCLogger.Priority.HighPriority) {
                    throw new RuntimeException("Import failed : " + message);
                }
            }

            public void sendAllMessages() {
            }

            public boolean hasMessages() {
                return false;
            }
        };
        // import sbml String into VCell biomodel
        File sbmlFile = File.createTempFile("temp", ".xml");
        sbmlFile.deleteOnExit();
        XmlUtil.writeXMLStringToFile(modifiedSbmlStr, sbmlFile.getAbsolutePath(), true);
        org.vcell.sbml.vcell.SBMLImporter sbmlImporter = new SBMLImporter(sbmlFile.getAbsolutePath(), logger, false);
        BioModel bioModel = sbmlImporter.getBioModel();
        // enforce 'cleaner looking' units on vc biomodel (the process of adding unit defintion to sbml model messes up the units, though they are correct units (eg., 1e-6m for um).
        BioModel modifiedBiomodel = ModelUnitConverter.createBioModelWithNewUnitSystem(bioModel, forcedModelUnitSystem);
        // convert any reaction that has GeneralLumpedKinetics to GeneralKinetics
        for (ReactionStep rs : modifiedBiomodel.getModel().getReactionSteps()) {
            Kinetics kinetics = rs.getKinetics();
            if (kinetics instanceof LumpedKinetics) {
                rs.setKinetics(DistributedKinetics.toDistributedKinetics((LumpedKinetics) kinetics));
            }
        }
        // convert biomodel to vcml string
        String vcmlString = XmlHelper.bioModelToXML(modifiedBiomodel);
        ExternalDocInfo externalDocInfo = new ExternalDocInfo(vcmlString);
        if (externalDocInfo != null) {
            getRequestManager().openDocument(externalDocInfo, this, true);
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw new RuntimeException("Cound not convert BNG sbml string to VCell biomodel : ", e);
    }
}
Also used : SBMLImporter(org.vcell.sbml.vcell.SBMLImporter) LumpedKinetics(cbit.vcell.model.LumpedKinetics) UnitSystemSelectionPanel(cbit.vcell.client.desktop.biomodel.UnitSystemSelectionPanel) VCLogger(cbit.util.xml.VCLogger) SBMLImporter(org.vcell.sbml.vcell.SBMLImporter) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException) ExternalDocInfo(cbit.vcell.xml.ExternalDocInfo) BioModel(cbit.vcell.biomodel.BioModel) ReactionStep(cbit.vcell.model.ReactionStep) DistributedKinetics(cbit.vcell.model.DistributedKinetics) LumpedKinetics(cbit.vcell.model.LumpedKinetics) Kinetics(cbit.vcell.model.Kinetics) File(java.io.File) VCLogger(cbit.util.xml.VCLogger) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 70 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class VCellClientDataServiceImpl method createSimulationDataSetRef.

public static SimulationDataSetRef createSimulationDataSetRef(Simulation simulation, VCDocument modelDocument, int jobIndex, boolean isLocal) {
    SimulationDataSetRef simulationDataSetReference = new SimulationDataSetRef();
    Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
    Extent extent = simulation.getMathDescription().getGeometry().getExtent();
    SimulationInfo simInfo = simulation.getSimulationInfo();
    simulationDataSetReference.setSimName(simInfo.getName());
    // String simName = simInfo.getName();
    // if (jobIndex!=0){
    // simName = simName + " job#"+String.valueOf(jobIndex);
    // }
    final String modelId;
    final boolean isMathModel;
    final String modelName;
    final String simContextName;
    if (modelDocument != null) {
        modelId = modelDocument.getVersion().getVersionKey().toString();
        isMathModel = (modelDocument instanceof MathModel);
        modelName = modelDocument.getName();
        if (modelDocument instanceof BioModel && simulation.getSimulationOwner() != null) {
            simContextName = simulation.getSimulationOwner().getName();
        } else {
            simContextName = null;
        }
    } else {
        modelId = "no id";
        isMathModel = false;
        modelName = "no model";
        simContextName = null;
    }
    simulationDataSetReference.setSimId(simInfo.getAuthoritativeVCSimulationIdentifier().getSimulationKey().toString());
    simulationDataSetReference.setModelId(modelId);
    simulationDataSetReference.setUsername(simInfo.getVersion().getOwner().getName());
    simulationDataSetReference.setUserkey(simInfo.getVersion().getOwner().getID().toString());
    simulationDataSetReference.setIsMathModel(isMathModel);
    simulationDataSetReference.setJobIndex(jobIndex);
    simulationDataSetReference.setModelName(modelName);
    simulationDataSetReference.setOriginXYZ(Arrays.asList(new Double[] { origin.getX(), origin.getY(), origin.getZ() }));
    simulationDataSetReference.setExtentXYZ(Arrays.asList(new Double[] { extent.getX(), extent.getY(), extent.getZ() }));
    if (simContextName != null) {
        simulationDataSetReference.setSimulationContextName(simContextName);
    }
    simulationDataSetReference.setSimName(simInfo.getName());
    boolean movingBoundarySolver = simulation.getSolverTaskDescription().getSolverDescription().isMovingBoundarySolver();
    simulationDataSetReference.setIsTimeVaryingMesh(movingBoundarySolver);
    simulationDataSetReference.setIsLocal(isLocal);
    return simulationDataSetReference;
}
Also used : Origin(org.vcell.util.Origin) MathModel(cbit.vcell.mathmodel.MathModel) Extent(org.vcell.util.Extent) BioModel(cbit.vcell.biomodel.BioModel) SimulationDataSetRef(cbit.vcell.client.pyvcellproxy.SimulationDataSetRef) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Aggregations

BioModel (cbit.vcell.biomodel.BioModel)158 SimulationContext (cbit.vcell.mapping.SimulationContext)72 Simulation (cbit.vcell.solver.Simulation)53 XMLSource (cbit.vcell.xml.XMLSource)37 KeyValue (org.vcell.util.document.KeyValue)36 MathModel (cbit.vcell.mathmodel.MathModel)33 DataAccessException (org.vcell.util.DataAccessException)29 XmlParseException (cbit.vcell.xml.XmlParseException)28 File (java.io.File)28 Model (cbit.vcell.model.Model)27 BioModelInfo (org.vcell.util.document.BioModelInfo)25 MathDescription (cbit.vcell.math.MathDescription)24 IOException (java.io.IOException)24 BigString (org.vcell.util.BigString)22 Geometry (cbit.vcell.geometry.Geometry)21 UserCancelException (org.vcell.util.UserCancelException)20 User (org.vcell.util.document.User)20 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)19 SpeciesContext (cbit.vcell.model.SpeciesContext)17 VCDocument (org.vcell.util.document.VCDocument)16