private void CompleteReaction(CReaction reaction, int numSubst, int numProd) { reaction.setReversible(false); // we need to get the function from the function database CFunctionDB funcDB = CCopasiRootContainer.getFunctionList(); // it should be in the list of suitable functions // lets get all suitable functions for an irreversible reaction with numSubst substrates and // numProd products CFunctionStdVector suitableFunctions = funcDB.suitableFunctions(numSubst, numProd, COPASI.TriFalse); int i; int iMax = (int) suitableFunctions.size(); for (i = 0; i < iMax; ++i) { // we just assume that the only suitable function with Constant in // it's name is the one we want // if (suitableFunctions.get(i).getObjectName().indexOf("Constant") != -1) { if (suitableFunctions .get(i) .getObjectName() .contains("Mass action (irreversible)")) { // "Mass action (irreversible)" // // "Michaelis-Menten" break; } } System.out.println(" Function: " + i + "/" + iMax); if (i < iMax) { // we set the function. // => the method should be smart enough to associate the reaction entities with the correct // function parameters reaction.setFunction(suitableFunctions.get(i)); // TaskVectorN taskVector = dataModel.getTaskList(); // dataModel.getTask(0).getProblem(); CCopasiParameterGroup parameterGroup = reaction.getParameters(); CCopasiParameter parameter; // "Mass action (irreversible)" function has only one parameter k1 parameter = parameterGroup.getParameter("k1"); parameter.setDblValue(0.1); // michaelis-Menten /* parameter= parameterGroup.getParameter("V"); // Michaelis-Menten has 2 parameters: V and Km parameter.setDblValue(20); parameter= parameterGroup.getParameter("Km"); // "Mass action (irreversible)" function has only one parameter k1 parameter.setDblValue(10); */ // for (i = 0; i < parameterGroup.size(); i++) { // // //System.out.println(parameterGroup.getParameter(i).getObjectName()); // parameterGroup.removeParameter(i); // } // String paramName; // i=0; // //for (i = 0; i < numSubst; i++) { // paramName = "k"+(i+1); //metabolite_"+i+"_K"; // parameterGroup.addParameter(paramName, CCopasiParameter.DOUBLE); // CCopasiParameter parameter=parameterGroup.getParameter(paramName); // parameter.setDblValue(0.1); // changedObjects.add(parameter.getValueReference()); // //} } else { System.err.println("Error. Could not find suitable function."); System.exit(1); } }
public static CSteadyStateTask runSteadyStateCalculation( CCopasiDataModel dataModel, HashMap<String, Object> problemParameters, HashMap<String, Object> methodParameters) { CSteadyStateTask steadyStateTask = (CSteadyStateTask) dataModel.addTask(CCopasiTask.steadyState); if (steadyStateTask == null) return null; CSteadyStateProblem steadyStateProblem = (CSteadyStateProblem) steadyStateTask.getProblem(); if (steadyStateProblem == null) return null; Set<String> keySet = problemParameters.keySet(); for (Iterator<String> it = keySet.iterator(); it.hasNext(); ) { String key = (String) it.next(); CCopasiParameter param = steadyStateProblem.getParameter(key); if (param == null) { return null; } Object o = problemParameters.get(key); if (o instanceof Double) { param.setDblValue(((Double) o).doubleValue()); } else if (o instanceof Integer) { param.setIntValue(((Integer) o).intValue()); } else if (o instanceof Boolean) { param.setBoolValue(((Boolean) o).booleanValue()); } else if (o instanceof String) { param.setStringValue(((String) o)); } else { System.err.println("Error. Unknown parameter type."); } } CNewtonMethod newtonMethod = (CNewtonMethod) steadyStateTask.getMethod(); if (newtonMethod == null) { return null; } keySet = methodParameters.keySet(); for (Iterator<String> it = keySet.iterator(); it.hasNext(); ) { String key = (String) it.next(); CCopasiParameter param = newtonMethod.getParameter(key); if (param == null) { return null; } Object o = methodParameters.get(key); if (o instanceof Double) { param.setDblValue(((Double) o).doubleValue()); } else if (o instanceof Integer) { param.setIntValue(((Integer) o).intValue()); } else if (o instanceof Boolean) { param.setBoolValue(((Boolean) o).booleanValue()); } else if (o instanceof String) { param.setStringValue(((String) o)); } else { System.err.println("Error. Unknown parameter type."); } } boolean result = false; try { result = steadyStateTask.process(true); } catch (Exception e) { System.err.println("ERROR: " + e.getMessage()); } if (!result) { return null; } return steadyStateTask; }