1 /** 2 * @cond doxygenLibsbmlInternal 3 * 4 * @file ModelingPracticeConstraints.cpp 5 * @brief ModelingPractice check constraints. 6 * @author Sarah Keating 7 * 8 * <!-------------------------------------------------------------------------- 9 * This file is part of libSBML. Please visit http://sbml.org for more 10 * information about SBML, and the latest version of libSBML. 11 * 12 * Copyright (C) 2020 jointly by the following organizations: 13 * 1. California Institute of Technology, Pasadena, CA, USA 14 * 2. University of Heidelberg, Heidelberg, Germany 15 * 3. University College London, London, UK 16 * 17 * Copyright (C) 2019 jointly by the following organizations: 18 * 1. California Institute of Technology, Pasadena, CA, USA 19 * 2. University of Heidelberg, Heidelberg, Germany 20 * 21 * Copyright (C) 2013-2018 jointly by the following organizations: 22 * 1. California Institute of Technology, Pasadena, CA, USA 23 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK 24 * 3. University of Heidelberg, Heidelberg, Germany 25 * 26 * Copyright (C) 2009-2013 jointly by the following organizations: 27 * 1. California Institute of Technology, Pasadena, CA, USA 28 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK 29 * 30 * Copyright (C) 2006-2008 by the California Institute of Technology, 31 * Pasadena, CA, USA 32 * 33 * Copyright (C) 2002-2005 jointly by the following organizations: 34 * 1. California Institute of Technology, Pasadena, CA, USA 35 * 2. Japan Science and Technology Agency, Japan 36 * 37 * This library is free software; you can redistribute it and/or modify it 38 * under the terms of the GNU Lesser General Public License as published by 39 * the Free Software Foundation. A copy of the license agreement is provided 40 * in the file named "LICENSE.txt" included with this software distribution 41 * and also available online as http://sbml.org/software/libsbml/license.html 42 * ---------------------------------------------------------------------- -->*/ 43 44 #ifndef AddingConstraintsToValidator 45 #include <sbml/validator/VConstraint.h> 46 #endif 47 48 #include <sbml/validator/ConstraintMacros.h> 49 50 #include "LocalParameterShadowsIdInModel.h" 51 /** @cond doxygenIgnored */ 52 using namespace std; 53 /** @endcond */ 54 55 // Compartment validation 56 57 START_CONSTRAINT (80501, Compartment, c) 58 { 59 pre( c.getLevel() > 1); 60 pre( c.getSpatialDimensions() != 0 ); 61 62 //msg = 63 // "It is recommended that the size of a compartment is set."; 64 65 bool fail = true; 66 67 // is size set on the element 68 if (c.isSetSize() == true) 69 { 70 fail = false; 71 } 72 else if (c.isSetSpatialDimensions() && c.getSpatialDimensions()==0) { 73 //Compartments with spatialDimensions of 0 should 74 //(and, for some levels/versions, *must*) not have a 'size'. 75 fail = false; 76 } 77 else 78 { 79 pre (c.isSetId() == true); 80 // is there an initial assignment/assignment rule that would set the value 81 if (m.getInitialAssignmentBySymbol(c.getId()) != NULL) 82 { 83 fail = false; 84 } 85 else if (m.getAssignmentRuleByVariable(c.getId()) != NULL) 86 { 87 fail = false; 88 } 89 // Need something like the following to check if the initial value is 90 // set by an algebraic rule. However, there is no 'hasVariable' 91 // function for an ASTNode yet. 92 /* 93 else if (!c.getConstant()) 94 { 95 for (unsigned int alg=0; alg<m.getNumRules(); alg++) 96 { 97 const Rule* rule = m.getRule(alg); 98 if (rule->isAlgebraic() && rule->getMath()->hasVariable(c.getId())) 99 { 100 fail = false; 101 } 102 } 103 } 104 */ 105 else 106 { 107 msg = "The <compartment> with the id '" + c.getId(); 108 msg += "' does not have a 'size' attribute, nor is its initial value "; 109 msg += "set by an <initialAssignment> or <assignmentRule>."; 110 } 111 } 112 113 inv( fail == false); 114 } 115 END_CONSTRAINT 116 117 118 START_CONSTRAINT (80601, Species, s) 119 { 120 bool fail = true; 121 122 if (s.isSetInitialAmount() == true || s.isSetInitialConcentration() == true) 123 { 124 fail = false; 125 } 126 else 127 { 128 pre (s.isSetId() == true); 129 // is there an initial assignment/assignment rule that would set the value 130 if (m.getInitialAssignmentBySymbol(s.getId()) != NULL) 131 { 132 fail = false; 133 } 134 else if (m.getAssignmentRuleByVariable(s.getId()) != NULL) 135 { 136 fail = false; 137 } 138 // Need something like the following to check if the initial value is 139 // set by an algebraic rule. However, there is no 'hasVariable' function 140 // for an ASTNode yet. 141 /* 142 else if (!s.getConstant()) 143 { 144 for (unsigned int alg=0; alg<m.getNumRules(); alg++) 145 { 146 const Rule* rule = m.getRule(alg); 147 if (rule->isAlgebraic() && rule->getMath()->hasVariable(s.getId())) 148 { 149 fail = false; 150 } 151 } 152 } 153 */ 154 else 155 { 156 msg = "The <species> with the id '" + s.getId(); 157 msg += "' does not have an 'initialConcentration' or 'initialAmount' "; 158 msg += "attribute, nor is its initial value set by an <initialAssignment> "; 159 msg += "or <assignmentRule>."; 160 } 161 } 162 163 inv (fail == false); 164 } 165 END_CONSTRAINT 166 167 168 // Parameters 169 EXTERN_CONSTRAINT( 81121, LocalParameterShadowsIdInModel ) 170 171 172 START_CONSTRAINT (80701, Parameter, p) 173 { 174 if(p.isSetId()) 175 { 176 msg = "The <parameter> with the id '" + p.getId() + "' does not have a 'units' attribute."; 177 } 178 inv(p.isSetUnits() == true); 179 } 180 END_CONSTRAINT 181 182 183 START_CONSTRAINT (80701, LocalParameter, p) 184 { 185 if(p.isSetId()) 186 { 187 msg = "The <localParameter> with the id '" + p.getId() + "' does not have a 'units' attribute."; 188 } 189 inv(p.isSetUnits() == true); 190 } 191 END_CONSTRAINT 192 193 194 START_CONSTRAINT (80702, Parameter, p) 195 { 196 bool fail = true; 197 198 if (p.isSetValue() == true) 199 { 200 fail = false; 201 } 202 else 203 { 204 pre (p.isSetId() == true); 205 // is there an initial assignment/assignment rule that would set the value 206 if (m.getInitialAssignmentBySymbol(p.getId()) != NULL) 207 { 208 fail = false; 209 } 210 else if (m.getAssignmentRuleByVariable(p.getId()) != NULL) 211 { 212 fail = false; 213 } 214 // Need something like the following to check if the initial value is 215 // set by an algebraic rule. However, there is no 'hasVariable' function 216 // for an ASTNode yet. 217 /* 218 else if (!p.getConstant()) 219 { 220 for (unsigned int alg=0; alg<m.getNumRules(); alg++) 221 { 222 const Rule* rule = m.getRule(alg); 223 if (rule->isAlgebraic() && rule->getMath()->hasVariable(p.getId())) 224 { 225 fail = false; 226 } 227 } 228 } 229 */ 230 else 231 { 232 msg = "The <parameter> with the id '" + p.getId(); 233 msg += "' does not have 'value' "; 234 msg += "attribute, nor is its initial value set by an <initialAssignment> "; 235 msg += "or <assignmentRule>."; 236 } 237 } 238 239 inv (fail == false); 240 } 241 END_CONSTRAINT 242 243 244 START_CONSTRAINT (80702, LocalParameter, p) 245 { 246 if(p.isSetId()) 247 { 248 msg = "The <localParameter> with the id '" + p.getId() + "' does not have a 'value' attribute."; 249 } 250 inv(p.isSetValue() == true); 251 } 252 END_CONSTRAINT 253 254 /** @endcond */ 255 256