Search in sources :

Example 6 with VCUnitSystem

use of cbit.vcell.units.VCUnitSystem in project vcell by virtualcell.

the class SBMLUnitTranslatorTest method testSBMLtoVCell.

@Test
public void testSBMLtoVCell() throws XMLStreamException, IOException, SbmlException {
    File[] sbmlFiles = getBiomodelsCuratedSBMLFiles();
    // };
    for (File sbmlFile : sbmlFiles) {
        if (sbmlFile.getName().equals("BIOMD0000000539.xml")) {
            System.err.println("skipping this model, seems like a bug in jsbml  RenderParser.processEndDocument() ... line 403 ... wrong constant for extension name");
            continue;
        }
        SBMLDocument doc = SBMLReader.read(sbmlFile);
        BioModel bioModel = new BioModel(null);
        VCUnitSystem unitSystem = bioModel.getModel().getUnitSystem();
        Model sbmlModel = doc.getModel();
        ListOf<UnitDefinition> listOfUnitDefinitions = sbmlModel.getListOfUnitDefinitions();
        for (UnitDefinition sbmlUnitDef : listOfUnitDefinitions) {
            VCUnitDefinition vcUnit = SBMLUnitTranslator.getVCUnitDefinition(sbmlUnitDef, unitSystem);
            UnitDefinition new_sbmlUnitDef = SBMLUnitTranslator.getSBMLUnitDefinition(vcUnit, 3, 1, unitSystem);
            VCUnitDefinition new_vcUnit = SBMLUnitTranslator.getVCUnitDefinition(new_sbmlUnitDef, unitSystem);
            if (!vcUnit.getSymbol().equals(new_vcUnit.getSymbol())) {
                System.err.println("orig vcUnit '" + vcUnit.getSymbol() + "' doesn't match new vcUnit '" + new_vcUnit.getSymbol() + "'");
            }
            // System.out.println("sbmlUnit = "+sbmlUnitDef.toString()+", vcUnit = "+vcUnit.getSymbol());
            System.out.println("sbmlUnit(" + sbmlUnitDef.getClass().getName() + ", builtin=" + sbmlUnitDef.isVariantOfSubstance() + ") = " + sbmlUnitDef.toString() + ", id=" + sbmlUnitDef.getId() + ",  name=" + sbmlUnitDef.getName() + ",   vcUnit = " + vcUnit.getSymbol());
            if (sbmlUnitDef.getNumUnits() > 1) {
                System.out.println("vcUnit = " + vcUnit.getSymbol());
                for (Unit unit : sbmlUnitDef.getListOfUnits()) {
                    try {
                        // VCUnitDefinition vcUnit = unitSystem.getInstance(unit.getKind().getName());
                        System.out.println("    vcUnit = " + unit);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("found bigger unit, " + sbmlUnitDef);
            }
        }
        if (sbmlFile == sbmlFiles[0]) {
            System.out.println("sbml length unit = " + sbmlModel.getLengthUnitsInstance() + ", idref=" + sbmlModel.getLengthUnits());
            System.out.println("sbml area unit = " + sbmlModel.getAreaUnitsInstance() + ", idref=" + sbmlModel.getAreaUnits());
            System.out.println("sbml volume unit = " + sbmlModel.getVolumeUnitsInstance() + ", idref=" + sbmlModel.getVolumeUnits());
            System.out.println("sbml time unit = " + sbmlModel.getTimeUnitsInstance() + ", idref=" + sbmlModel.getTimeUnits());
            System.out.println("sbml extent unit = " + sbmlModel.getExtentUnitsInstance() + ", idref=" + sbmlModel.getExtentUnits());
            System.out.println("sbml substance unit = " + sbmlModel.getSubstanceUnitsInstance() + ", idref=" + sbmlModel.getSubstanceUnits());
            for (UnitDefinition sbmlUnitDef : sbmlModel.getListOfPredefinedUnitDefinitions()) {
                if (sbmlUnitDef.getNumUnits() == 1 && sbmlUnitDef.getUnit(0).isAvogadro()) {
                    continue;
                }
                if (sbmlUnitDef.getNumUnits() == 1 && sbmlUnitDef.getUnit(0).isKatal()) {
                    continue;
                }
                VCUnitDefinition vcUnit = SBMLUnitTranslator.getVCUnitDefinition(sbmlUnitDef, unitSystem);
                // System.out.println("sbmlUnit = "+sbmlUnitDef.toString()+", vcUnit = "+vcUnit.getSymbol());
                System.out.println("sbmlUnit(" + sbmlUnitDef.getClass().getName() + ", builtin=" + sbmlUnitDef.isVariantOfSubstance() + ") = " + sbmlUnitDef.toString() + ", id=" + sbmlUnitDef.getId() + ",  name=" + sbmlUnitDef.getName() + ",   vcUnit = " + vcUnit.getSymbol());
            // for (Unit unit : sbmlUnitDef.getListOfUnits()){
            // try {
            // VCUnitDefinition vcUnit = unitSystem.getInstance(unit.getKind().getName());
            // System.out.println("    vcUnit = "+vcUnit.getSymbol());
            // }catch (Exception e){
            // e.printStackTrace();
            // }
            // }
            }
        }
    }
}
Also used : VCUnitSystem(cbit.vcell.units.VCUnitSystem) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) SBMLDocument(org.sbml.jsbml.SBMLDocument) BioModel(cbit.vcell.biomodel.BioModel) Model(org.sbml.jsbml.Model) BioModel(cbit.vcell.biomodel.BioModel) Unit(org.sbml.jsbml.Unit) File(java.io.File) UnitDefinition(org.sbml.jsbml.UnitDefinition) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException) Test(org.junit.Test)

Aggregations

VCUnitSystem (cbit.vcell.units.VCUnitSystem)6 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)5 Expression (cbit.vcell.parser.Expression)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)2 VCUnitEvaluator (cbit.vcell.parser.VCUnitEvaluator)2 VCUnitException (cbit.vcell.units.VCUnitException)2 PropertyVetoException (java.beans.PropertyVetoException)2 UnitDefinition (org.sbml.jsbml.UnitDefinition)2 Issue (org.vcell.util.Issue)2 BioModel (cbit.vcell.biomodel.BioModel)1 FluxReaction (cbit.vcell.model.FluxReaction)1 SimpleBoundsIssue (cbit.vcell.model.SimpleBoundsIssue)1 SimpleReaction (cbit.vcell.model.SimpleReaction)1 Species (cbit.vcell.model.Species)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 File (java.io.File)1 IOException (java.io.IOException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 RealInterval (net.sourceforge.interval.ia_math.RealInterval)1