本文整理汇总了Java中org.sbml.jsbml.UnitDefinition.createUnit方法的典型用法代码示例。如果您正苦于以下问题:Java UnitDefinition.createUnit方法的具体用法?Java UnitDefinition.createUnit怎么用?Java UnitDefinition.createUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sbml.jsbml.UnitDefinition
的用法示例。
在下文中一共展示了UnitDefinition.createUnit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addUnits
import org.sbml.jsbml.UnitDefinition; //导入方法依赖的package包/类
/**
* Adds the units.
*/
public void addUnits(){
if(unit == null)
return;
UnitDefinition ud = model.createUnitDefinition();
ud.setId("length");
Unit u = ud.createUnit();
u.setKind(Kind.METRE);
u.setExponent(1d);
u.setScale(0);
u.setMultiplier(getUnitMultiplier(unit));
ud = model.createUnitDefinition();
ud.setId("area");
u = ud.createUnit();
u.setKind(Kind.METRE);
u.setExponent(2d);
u.setScale(0);
u.setMultiplier(getUnitMultiplier(unit));
ud = model.createUnitDefinition();
ud.setId("volume");
u = ud.createUnit();
u.setKind(Kind.METRE);
u.setExponent(3d);
u.setScale(0);
u.setMultiplier(getUnitMultiplier(unit));
}
示例2: createGridDegradationReaction
import org.sbml.jsbml.UnitDefinition; //导入方法依赖的package包/类
public void createGridDegradationReaction(Species species) {
String speciesID = species.getId();
Boolean speciesDegrades = false;
//Reaction degradation = BioModel.getDegradationReaction(speciesID, compModel);
//fix the sbo term/annotation stuff if it's not correct
//if (degradation != null)
speciesDegrades = true;
//only make grid degradation reactions if the species is degradable
if (speciesDegrades) {
//create array of grid degradation reactions
String decayString = GlobalConstants.KECDECAY_STRING;
double decayRate = sbml.getModel().getParameter("kecd").getValue();
String decayUnitString = "u_1_second_n1";
if (sbml.getModel().getUnitDefinition(decayUnitString) == null) {
UnitDefinition ud = sbml.getModel().createUnitDefinition();
Unit unit = ud.createUnit();
unit.setExponent(-1.0);
unit.setKind(Unit.Kind.valueOf("second".toUpperCase()));
unit.setScale(0);
unit.setMultiplier(1);
ud.setId(decayUnitString);
}
Reaction r = sbml.getModel().createReaction();
r.setId(GlobalConstants.DEGRADATION + "_" + speciesID);
SBMLutilities.setMetaId(r, r.getId());
r.setCompartment(sbml.getModel().getCompartment(0).getId());
SBMLutilities.cloneDimensionAddIndex(sbml.getModel().getCompartment(r.getCompartment()),r,"compartment");
r.setReversible(false);
//r.setFast(false);
r.setSBOTerm(GlobalConstants.SBO_DEGRADATION);
AnnotationUtility.setGridAnnotation(r, gridTable.getNumRows(), gridTable.getNumCols());
KineticLaw kl = r.createKineticLaw();
if (decayRate > 0) {
//this is the mathematical expression for the decay
String decayExpression = decayString + "* get2DArrayElement(" + speciesID + ", i, j)";
SpeciesReference reactant = r.createReactant();
reactant.setSpecies(speciesID);
reactant.setStoichiometry(1);
reactant.setConstant(false);
LocalParameter i = kl.createLocalParameter();
LocalParameter j = kl.createLocalParameter();
AnnotationUtility.setArraySizeAnnotation(i, gridTable.getNumRows());
AnnotationUtility.setArraySizeAnnotation(j, gridTable.getNumCols());
i.setId("i");
j.setId("j");
//parameter: id="kecd" value=(usually 0.005) units="u_1_second_n1" (inverse seconds)
Utility.Parameter(kl, decayString, decayRate, decayUnitString);
//formula: kecd * species
kl.setMath(SBMLutilities.myParseFormula(decayExpression));
Utility.addReaction(sbml, r);
}
}
}
示例3: getUnitString
import org.sbml.jsbml.UnitDefinition; //导入方法依赖的package包/类
public static String getUnitString(ArrayList<String> unitNames,
ArrayList<Integer> exponents, ArrayList<Integer> multiplier,
Model model) {
// First build the name of the unit and see if it exists, start by
// sorting the units to build a unique string
for (int i = 0; i < unitNames.size(); i++) {
for (int j = i; j > 0; j--) {
if (unitNames.get(j - 1).compareTo(unitNames.get(i)) > 0) {
Integer tempD = multiplier.get(j);
Integer tempI = exponents.get(j);
String tempS = unitNames.get(j);
multiplier.set(j, multiplier.get(j - 1));
unitNames.set(j, unitNames.get(j - 1));
exponents.set(j, exponents.get(j - 1));
multiplier.set(j - 1, tempD);
unitNames.set(j - 1, tempS);
exponents.set(j - 1, tempI);
}
}
}
UnitDefinition t = new UnitDefinition(GlobalConstants.SBML_LEVEL, GlobalConstants.SBML_VERSION);
String name = "u_";
for (int i = 0; i < unitNames.size(); i++) {
String sign = "";
if (exponents.get(i).intValue() < 0) {
sign = "n";
}
name = name + multiplier.get(i) + "_" + unitNames.get(i) + "_"
+ sign + Math.abs(exponents.get(i)) + "_";
Unit u = t.createUnit();
u.setKind(Kind.valueOf(unitNames.get(i).toUpperCase()));
u.setExponent(exponents.get(i).intValue()*1.0);
u.setMultiplier(multiplier.get(i).intValue());
u.setScale(0);
}
name = name.substring(0, name.length() - 1);
t.setId(name);
if (model.getUnitDefinition(name) == null) {
model.addUnitDefinition(t);
}
return name;
}
示例4: checkUnitsInRateRule
import org.sbml.jsbml.UnitDefinition; //导入方法依赖的package包/类
public static boolean checkUnitsInRateRule(SBMLDocument document, Rule rule)
{
UnitDefinition unitDef = rule.getDerivedUnitDefinition();
UnitDefinition unitDefVar;
Species species = document.getModel().getSpecies(getVariable(rule));
Compartment compartment = document.getModel().getCompartment(getVariable(rule));
Parameter parameter = document.getModel().getParameter(getVariable(rule));
if (species != null)
{
unitDefVar = species.getDerivedUnitDefinition();
}
else if (compartment != null)
{
unitDefVar = compartment.getDerivedUnitDefinition();
}
else
{
unitDefVar = parameter.getDerivedUnitDefinition();
}
if (document.getModel().getUnitDefinition("time") != null)
{
UnitDefinition timeUnitDef = document.getModel().getUnitDefinition("time");
for (int i = 0; i < timeUnitDef.getUnitCount(); i++)
{
Unit timeUnit = timeUnitDef.getUnit(i);
Unit recTimeUnit = unitDefVar.createUnit();
recTimeUnit.setKind(timeUnit.getKind());
if (document.getLevel() < 3)
{
recTimeUnit.setExponent(timeUnit.getExponent() * (-1));
}
else
{
recTimeUnit.setExponent(timeUnit.getExponent() * (-1));
}
recTimeUnit.setScale(timeUnit.getScale());
recTimeUnit.setMultiplier(timeUnit.getMultiplier());
}
}
else
{
Unit unit = unitDefVar.createUnit();
unit.setKind(Unit.Kind.valueOf("second".toUpperCase()));
unit.setExponent(-1.0);
unit.setScale(0);
unit.setMultiplier(1.0);
}
if (!UnitDefinition.areEquivalent(unitDef, unitDefVar))
{
return true;
}
return false;
}