// ## operation Chemkin(double,double,String) public Chemkin(double p_rtol, double p_atol, String p_reactorType) { // #[ operation Chemkin(double,double,String) if (p_rtol < 0 || p_atol < 0) throw new InvalidChemkinParameterException("Negative rtol or atol!"); if (p_reactorType == null) throw new NullPointerException(); String dir = System.getProperty("RMG.workingDirectory"); // create the documentTypesDefinitions File docFile = new File("chemkin/documentTypeDefinitions"); docFile.mkdir(); copyFiles( dir + "/software/reactorModel/documentTypeDefinitions/reactorInput.dtd", "chemkin/documentTypeDefinitions/reactorInput.dtd"); copyFiles( dir + "/software/reactorModel/documentTypeDefinitions/reactorOutput.dtd", "chemkin/documentTypeDefinitions/reactorOutput.dtd"); rtol = p_rtol; atol = p_atol; reactorType = p_reactorType; }
/* * Carries out a number of tests, generates NEURON, GENESIS and NeuroML code etc. */ private static void doTests(neuronEditorFrame nef, String fileName) { System.out.println( "Testing Cvapp/NeuroMorpho.Org by generating NEURON, GENESIS and NeuroML files for " + fileName); File tempDir = new File("temp"); if (!tempDir.exists()) tempDir.mkdir(); neuronEditorPanel nep = nef.getNeuronEditorPanel(); String rootFileName = fileName; if (rootFileName.toLowerCase().endsWith(".swc")) { rootFileName = rootFileName.substring(0, rootFileName.length() - 4); } if (rootFileName.lastIndexOf(System.getProperty("file.separator")) > 0) { rootFileName = rootFileName.substring( rootFileName.lastIndexOf(System.getProperty("file.separator")) + 1); } // NEURON save... String neuronFileName = rootFileName + ".hoc"; File neuronFile = new File(tempDir, neuronFileName); File neuronTestFile = new File(tempDir, rootFileName + "_test.hoc"); nep.writeStringToFile(nep.getCell().HOCwriteNS(), neuronFile.getAbsolutePath()); StringBuilder sbNeuTest = new StringBuilder(); sbNeuTest.append("load_file(\"nrngui.hoc\")\n"); sbNeuTest.append("load_file(\"../neuronUtils/nCtools.hoc\")\n"); sbNeuTest.append("load_file(\"../neuronUtils/cellCheck.hoc\")\n"); sbNeuTest.append("load_file(\"nrngui.hoc\")\n"); sbNeuTest.append("load_file(\"" + neuronFileName + "\")\n\n"); sbNeuTest.append("forall morph()\n"); System.out.println("--------------------------------------------------------------"); nep.writeStringToFile(sbNeuTest.toString(), neuronTestFile.getAbsolutePath()); System.out.println( "Saved NEURON representation of the file to: " + neuronFile.getAbsolutePath() + ": " + neuronFile.exists()); System.out.println("--------------------------------------------------------------"); // GENESIS save... String genesisFileName = rootFileName + ".p"; File genesisFile = new File(tempDir, genesisFileName); File genesisTestFile = new File(tempDir, rootFileName + "_test.g"); nep.writeStringToFile(nep.getCell().GENESISwriteHR(), genesisFile.getAbsolutePath()); StringBuilder sbGenTest = new StringBuilder(); sbGenTest.append("include compartments \n"); sbGenTest.append("create neutral /library\n"); sbGenTest.append("disable /library\n"); sbGenTest.append("ce /library\n"); sbGenTest.append("make_cylind_compartment\n"); sbGenTest.append("make_cylind_symcompartment\n"); sbGenTest.append("make_sphere_compartment\n"); sbGenTest.append("ce /\n"); sbGenTest.append( "echo \"Prototype compartments created, reading cell from " + genesisFileName + "\"\n"); sbGenTest.append("readcell " + genesisFileName + " /mycell\n\n"); sbGenTest.append("create xform /form [0,0,400,400] -nolabel\n"); sbGenTest.append( "create xdraw /form/draw [0,0,100%,100%] -wx 0.002 -wy 0.002 -transform ortho3d -bg white\n"); sbGenTest.append( "setfield /form/draw xmin -3.0E-4 xmax 3.0E-4 ymin -3.0E-4 ymax 3.0E-4 vx 0.0 vy 0.0 vz -0.002\n"); sbGenTest.append( "create xcell /form/draw/cell -path \"/mycell/##[][TYPE=compartment],/mycell/##[][TYPE=symcompartment]\" -colfield Vm -colmin -0.07 -colmax 0.03 -diarange -5\n"); sbGenTest.append("xcolorscale hot\n"); sbGenTest.append("xshow /form\n\n"); sbGenTest.append("showfield /mycell/##[][TYPE=compartment] **\n\n"); nep.writeStringToFile(sbGenTest.toString(), genesisTestFile.getAbsolutePath()); System.out.println( "Saved GENESIS representation of the file to: " + genesisFile.getAbsolutePath() + ": " + genesisFile.exists()); System.out.println("--------------------------------------------------------------"); // NeuroML save... String nml1FileName = rootFileName + ".xml"; File nml1File = new File(tempDir, nml1FileName); nep.writeStringToFile(nep.getCell().writeNeuroML_v1_8_1(), nml1File.getAbsolutePath()); System.out.println( "Saved NeuroML representation of the file to: " + nml1File.getAbsolutePath() + ": " + nml1File.exists()); File v1schemaFile = new File("Schemas/v1.8.1/Level3/NeuroML_Level3_v1.8.1.xsd"); validateXML(nml1File, v1schemaFile); String nml2FileName = rootFileName + ".cell.nml"; if (Character.isDigit(nml2FileName.charAt(0))) { nml2FileName = "Cell_" + nml2FileName; } File nml2File = new File(tempDir, nml2FileName); nep.writeStringToFile(nep.getCell().writeNeuroML_v2beta(), nml2File.getAbsolutePath()); System.out.println( "Saved NeuroML representation of the file to: " + nml2File.getAbsolutePath() + ": " + nml2File.exists()); validateXMLWithURL(nml2File, "Schemas/v2/NeuroML_v2beta4.xsd"); }
public static boolean transform( File origXmlFileOrDir, File xslFile, File targetDir, String extension) { logger.logComment( "Going to transform " + origXmlFileOrDir + " into dir " + targetDir + " using: " + xslFile, true); if (!origXmlFileOrDir.exists()) { GuiUtils.showErrorMessage( logger, "Warning, XML file/directory: " + origXmlFileOrDir + " doesn't exist", null, null); return false; } if (!xslFile.exists()) { GuiUtils.showErrorMessage( logger, "Warning, XSL file: " + xslFile + " doesn't exist", null, null); return false; } if (!targetDir.exists()) { GuiUtils.showErrorMessage( logger, "Warning, target directory: " + targetDir + " doesn't exist", null, null); return false; } if (origXmlFileOrDir.isDirectory()) { logger.logComment("That file is a directory. Converting all of the XML files in it"); File[] files = origXmlFileOrDir.listFiles(); boolean totalSuccess = true; for (int i = 0; i < files.length; i++) { if (!files[i].isDirectory() && (files[i].getName().endsWith(".xml") || files[i].getName().endsWith(".XML"))) { boolean partialSuccess = transform(files[i], xslFile, targetDir, extension); totalSuccess = totalSuccess || partialSuccess; } else if (files[i].isDirectory() && !GeneralUtils.isVersionControlDir(files[i])) { File newFolder = new File(targetDir, files[i].getName()); newFolder.mkdir(); logger.logComment( "Found a sub folder. Going to convert all there into: " + newFolder + "..."); transform(files[i], xslFile, newFolder, extension); } } return totalSuccess; } String result = transform(origXmlFileOrDir, xslFile); String newName = origXmlFileOrDir.getName(); if (newName.endsWith(".xml") || newName.endsWith(".XML")) { newName = newName.substring(0, newName.length() - 4) + extension; } File targetFile = new File(targetDir, newName); try { FileWriter fw = new FileWriter(targetFile); fw.write(result); fw.close(); } catch (IOException ex) { GuiUtils.showErrorMessage(logger, "Exception writing to file: " + targetFile, ex, null); return false; } logger.logComment("The result is in " + targetFile + " *************"); return result != null; }