/** * @return */ public Model getModel() { SBMLDocument doc = getSBMLDocument(); return doc != null ? doc.getModel() : null; }
/** * Appends "_<number>" to a given String. <number> is being set to * the next free number, so that this sID is unique in this * {@link SBMLDocument}. Should only be called from {@link #nameToSId(String)}. * * @return */ private static String incrementSIdSuffix(String prefix, SBMLDocument doc) { int i = 1; String aktString = prefix + "_" + i; Model model = doc.getModel(); while (model.containsUniqueNamedSBase(aktString)) { aktString = prefix + "_" + (++i); } return aktString; }
/** * Validates the given {@link SBMLDocument} * * @param document - a document that needs to be validated * @return a list of {@link SBMLError}s */ public static List<SBMLError> validate(SBMLDocument document) { List<SBMLError> listOfErrors = new ArrayList<SBMLError>(); Enumeration<TreeNode> children = document.children(); while(children.hasMoreElements()) { TreeNode child = children.nextElement(); validate(document.getModel(), child, listOfErrors); } return listOfErrors; }
/** * * @return */ public Model getModel() { return doc.isSetModel() ? doc.getModel() : doc.createModel(); }
/** * Creates a new Model inside this {@link SBMLDocument}, and returns a * pointer to it. * In SBML Level 2, the use of an identifier on a {@link Model} object is * optional. This method takes an optional argument, sid, for setting the * identifier. If not supplied, the identifier attribute on the Model * instance is not set. * * @return the new {@link Model} instance. */ public Model createModel() { Model oldValue = getModel(); setModel(new Model(getLevel(), getVersion())); firePropertyChange(TreeNodeChangeEvent.model, oldValue, getModel()); return getModel(); }
@Override public TreeNode getChildAt(int index) { if (index < 0) { throw new IndexOutOfBoundsException(MessageFormat.format( resourceBundle.getString("IndexSurpassesBoundsException"), index, 0)); } int count = super.getChildCount(), pos = 0; if (index < count) { return super.getChildAt(index); } else { index -= count; } if (isSetModel()) { if (pos == index) { return getModel(); } } throw new IndexOutOfBoundsException(MessageFormat.format( resourceBundle.getString("IndexExceedsBoundsException"), index, Math.min(pos, 0))); }
setModel(sb.getModel().clone()); } else { model = null;
/** * This method flattens out arrays objects of a given {@link SBMLDocument}. * * @param document - the document you want to convert. * @return new Document that is not associated with the arrays package. */ public static SBMLDocument convert(SBMLDocument document) { try { SBMLDocument flattenedDoc = document.clone(); Model model = flattenedDoc.getModel(); Map<String, ASTNode> idToVector = new HashMap<String, ASTNode>(); getVectors(flattenedDoc.getModel(), idToVector); convert(flattenedDoc, model, new ArraysCompiler(), idToVector, new ArrayList<Integer>()); convertMath(flattenedDoc, model, idToVector); return flattenedDoc; } catch(SBMLException exception) { logger.error(exception.getMessage()); return null; } }
@Override public boolean check(ValidationContext ctx, SBMLDocument d) { // count the number of model xml element and check if it is not above 1 DuplicatedElementValidationFunction<SBMLDocument> duplicatedModelcheck = new DuplicatedElementValidationFunction<SBMLDocument>(TreeNodeChangeEvent.model); if (!duplicatedModelcheck.check(ctx, d)) { return false; } if (ctx.isLevelAndVersionLessThan(3, 2)) { return d.getModel() != null; } else { // from L3V2 the model element can be undefined return true; } } };
/** * Generates a valid SId from a given name. If the name already is a valid * SId, the name is returned. If the SId already exists in this document, * "_<number>" will be appended and the next free number is being assigned. * => See SBML L2V4 document for the Definition of SId. (Page 12/13) * * @param name * @return SId */ public static String nameToSId(String name, SBMLDocument doc) { /* * letter = a-z,A-Z; digit = 0-9; idChar = (letter | digit | _ ); * SId = ( letter | _ ) idChar* */ String ret; if ((name == null) || (name.trim().length() == 0)) { ret = incrementSIdSuffix("SId", doc); } else { // Make unique ret = toSId(name); Model model = doc.getModel(); if (model.containsUniqueNamedSBase(ret)) { ret = incrementSIdSuffix(ret, doc); } } return ret; }
/** * Creates a new instance of Model from id and the level and version of this * SBMLDocument. * * @param id * @return the new {@link Model} instance. */ public Model createModel(String id) { setModel(new Model(id, getLevel(), getVersion())); return getModel(); }
@Override public SBMLDocument convert(SBMLDocument doc) throws SBMLException { SBMLDocument resultdoc = doc; Model m = doc.getModel(); if (m == null || m.getFunctionDefinitionCount() == 0) { // In this case, we cannot do anything about the FunctionDefinition or there is nothing to do return doc; } try { resultdoc = doc.clone(); resultdoc.filter(new Filter() { @Override public boolean accepts(Object o) { if (o instanceof MathContainer) { // call an utility that will replace the FDs expandFunctionDefinition((MathContainer) o); } return false; } }); } catch (Exception e) { // something went wrong during cloning. It can happen with malformed FunctionDefinition math // just returning the original unmodified document } return resultdoc; }
Model model = document.getModel();
System.out.println("Model NoRDFAnnotation String = \n@" + testDocument.getModel().getAnnotation().getNonRDFannotation() + "@"); System.out.println("Model Annotation String = \n@" + testDocument.getModel().getAnnotationString() + "@"); for (Species species : testDocument.getModel().getListOfSpecies()) { species.getAnnotationString();
if (isSetModel() && getModel().getFunctionDefinitionCount() > 0) { ExpandFunctionDefinitionConverter converter = new ExpandFunctionDefinitionConverter(); docToValidate = converter.convert(this);
this.externalModelDefinitionListOf = compSBMLDocumentPlugin.getListOfExternalModelDefinitions(); if (document.isSetModel() && document.getModel().getExtension(CompConstants.shortLabel) != null) { CompModelPlugin compModelPlugin = (CompModelPlugin) document.getModel().getExtension(CompConstants.shortLabel); handlePorts(compModelPlugin, compModelPlugin.getListOfPorts()); replaceElementsInModelDefinition(compModelPlugin, null);
SBMLDocument doc = SBMLReader.readSBML(toLoad.getAbsolutePath()); model = doc.getModel();
model = doc.getModel();
private Model initSubModels(CompModelPlugin compModelPlugin) { ListOf<Submodel> subModelListOf = compModelPlugin.getListOfSubmodels().clone(); // TODO: replace elements replaceElementsInModelDefinition(compModelPlugin, null); // TODO: ports ListOf<Port> listOfPorts = compModelPlugin.getListOfPorts(); handlePorts(compModelPlugin, listOfPorts); for (Submodel submodel : subModelListOf) { this.listOfSubmodelsToFlatten.add(submodel); ModelDefinition modelDefinition = this.modelDefinitionListOf.get(submodel.getModelRef()); // TODO: how to initialize external model definitions? if (modelDefinition == null) { ExternalModelDefinition externalModelDefinition = this.externalModelDefinitionListOf.get(submodel.getModelRef()); try { SBMLDocument externalDocument = SBMLReader.read(externalModelDefinition.getSource()); Model flattendExternalModel = flatten(externalDocument).getModel(); //external model can also contain submodels etc. this.flattenedModel = mergeModels(this.flattenedModel, flattendExternalModel); } catch (XMLStreamException e) { e.printStackTrace(); } } if (modelDefinition != null && modelDefinition.getExtension(CompConstants.shortLabel) != null) { initSubModels((CompModelPlugin) modelDefinition.getExtension(CompConstants.shortLabel)); } else { LOGGER.info("No model definition found in " + submodel.getId() + ".") ; } } return flattenAndMergeModels(this.listOfSubmodelsToFlatten); }
Model model = doc.getModel();