@Override
  public String getMainScript() throws GenerationException {

    StringBuilder sb = new StringBuilder();

    addComment(
        sb, FORMAT + " simulator compliant export for:\n\n" + lems.textSummary(false, false));

    Velocity.init();

    VelocityContext context = new VelocityContext();

    DLemsWriter writer = new DLemsWriter(lems, new MatlabVisitors());

    try {
      String som = writer.getMainScript();

      DLemsWriter.putIntoVelocityContext(som, context);

      Properties props = new Properties();
      props.put("resource.loader", "class");
      props.put(
          "class.resource.loader.class",
          "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
      VelocityEngine ve = new VelocityEngine();
      ve.init(props);
      Template template = ve.getTemplate(method.getFilename());

      StringWriter sw = new StringWriter();

      template.merge(context, sw);

      sb.append(sw);
    } catch (IOException e1) {
      throw new GenerationException("Problem converting LEMS to SOM", e1);
    } catch (ResourceNotFoundException e) {
      throw new GenerationException("Problem finding template", e);
    } catch (ParseErrorException e) {
      throw new GenerationException("Problem parsing", e);
    } catch (MethodInvocationException e) {
      throw new GenerationException("Problem finding template", e);
    } catch (Exception e) {
      throw new GenerationException("Problem using template", e);
    }

    return sb.toString();
  }
 public VertexWriter(Lems lems, File outputFolder, String outputFileName)
     throws ModelFeatureSupportException, NeuroMLException, LEMSException {
   super(lems, Format.VERTEX, outputFolder, outputFileName);
   mainDlemsFile = outputFileName + "_main.json";
   dlemsw = new DLemsWriter(lems, outputFolder, mainDlemsFile, null, false);
   dlemsw.setPopulationMode(true);
   initializeWriter();
 }
  public String getMainScript() throws GenerationException, IOException {
    StringBuilder mainRunScript = new StringBuilder();

    addComment(
        mainRunScript,
        format + " simulator compliant export for:\n\n" + lems.textSummary(false, false));

    try {
      List<File> files = dlemsw.convert();

      for (File file : files) {

        E.info("Writing " + format + " files to: " + this.getOutputFolder());
        if (file.getName().equals(mainDlemsFile)) {

          VelocityUtils.initializeVelocity();
          VelocityContext context = new VelocityContext();
          VelocityEngine ve = VelocityUtils.getVelocityEngine();
          String dlems = FileUtil.readStringFromFile(file);
          DLemsWriter.putIntoVelocityContext(dlems, context);

          addComment(
              mainRunScript,
              "Using the following distilled version of the LEMS model description for the script below:\n\n"
                  + dlems);

          StringWriter sw1 = new StringWriter();
          boolean generationStatus =
              ve.evaluate(
                  context,
                  sw1,
                  "LOG",
                  VelocityUtils.getTemplateAsReader(VelocityUtils.vertexRunTemplateFile));
          mainRunScript.append(sw1);
        } else if (file.getName().indexOf(".synapse.") > 0) {

          StringBuilder synapseScript = new StringBuilder();
          addComment(
              synapseScript,
              format + " simulator compliant export for:\n\n" + lems.textSummary(false, false));
          E.info(" ====  Handling DLEMS file: " + file.getAbsolutePath());

          VelocityUtils.initializeVelocity();
          VelocityContext context = new VelocityContext();
          VelocityEngine ve = VelocityUtils.getVelocityEngine();
          String dlems = FileUtil.readStringFromFile(file);
          DLemsWriter.putIntoVelocityContext(dlems, context);

          StringWriter sw2 = new StringWriter();
          boolean generationStatus2 =
              ve.evaluate(
                  context,
                  sw2,
                  "LOG",
                  VelocityUtils.getTemplateAsReader(VelocityUtils.vertexSynapseTemplateFile));

          addComment(
              synapseScript,
              "Using the following distilled version of the LEMS model description for the script below:\n\n"
                  + dlems);
          synapseScript.append(sw2);

          String name = (String) context.internalGet(DLemsKeywords.NAME.get());
          E.info("Name: " + name);

          File synapseScriptFile =
              new File(this.getOutputFolder(), "SynapseModel_" + name.toLowerCase() + ".m");

          FileUtil.writeStringToFile(synapseScript.toString(), synapseScriptFile);
          outputFiles.add(synapseScriptFile);

        } else {

          StringBuilder cellScript = new StringBuilder();
          addComment(
              cellScript,
              format + " simulator compliant export for:\n\n" + lems.textSummary(false, false));
          E.info(" ====  Handling DLEMS file: " + file.getAbsolutePath());

          VelocityUtils.initializeVelocity();
          VelocityContext context = new VelocityContext();
          VelocityEngine ve = VelocityUtils.getVelocityEngine();
          String dlems = FileUtil.readStringFromFile(file);
          DLemsWriter.putIntoVelocityContext(dlems, context);

          StringWriter sw2 = new StringWriter();
          boolean generationStatus2 =
              ve.evaluate(
                  context,
                  sw2,
                  "LOG",
                  VelocityUtils.getTemplateAsReader(VelocityUtils.vertexCellTemplateFile));

          addComment(
              cellScript,
              "Using the following distilled version of the LEMS model description for the script below:\n\n"
                  + dlems);
          cellScript.append(sw2);

          String name = (String) context.internalGet(DLemsKeywords.NAME.get());
          E.info("Name: " + name);

          File cellScriptFile =
              new File(this.getOutputFolder(), "PointNeuronModel_" + name.toLowerCase() + ".m");

          FileUtil.writeStringToFile(cellScript.toString(), cellScriptFile);
          outputFiles.add(cellScriptFile);
        }
      }

    } catch (IOException e1) {
      throw new GenerationException("Problem converting LEMS to dLEMS", e1);
    } catch (VelocityException e) {
      throw new GenerationException("Problem using Velocity template", e);
    }

    return mainRunScript.toString();
  }