public static void main(String[] args) {
    new ExampleProjects();

    try {

      File exsDir = new File("osb/showcase/neuroConstructShowcase");

      File mainFile = new File("docs/XML/xmlForHtml/samples/index.xml");

      logger.logComment("Going to create docs at: " + mainFile.getCanonicalPath(), true);

      generateMainPage(mainFile, exsDir);

      logger.logComment("Created doc at: " + mainFile.getCanonicalPath(), true);
      /*
      File modelsDir = new File("nCmodels");
      mainFile = new File("docs/XML/xmlForHtml/models/index.xml");


      generateMainPage(mainFile, modelsDir);

      logger.logComment("Created doc at: "+ mainFile.getCanonicalPath(), true);

       */
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    try {
      Project p =
          Project.loadProject(
              new File(ProjectStructure.getnCExamplesDir(), "Ex5_Networks/Ex5_Networks.ncx"), null);

      GeneratedElecInputs gei = new GeneratedElecInputs(p);

      System.out.println("Internal info: \n" + gei.toString());

      // IClamp ic = new IClamp(2,3,4, true);

      gei.addSingleInput("Input_0", "IClamp", "cg1", 3, 3, 3, null);
      gei.addSingleInput("Input_0", "IClamp", "cg1", 38, 3, 3, null);
      gei.addSingleInput("Input_2", "IClamp", "cg3", 3, 38, 39, null);

      System.out.println("Internal info: \n" + gei.toString());

      File f = new File("../temp/tempp.txt");

      gei.saveToFile(f);

      GeneratedElecInputs cpr2 = new GeneratedElecInputs(null);

      System.out.println(
          "----  v1.8.1: \n"
              + gei.getNetworkMLElement(UnitConverter.GENESIS_SI_UNITS)
                  .getXMLString("    ", false));

      ArrayList<SimpleXMLEntity> els =
          gei.getNetworkMLEntities(
              UnitConverter.GENESIS_SI_UNITS,
              NeuroMLConstants.NeuroMLVersion.NEUROML_VERSION_2_ALPHA,
              null);

      System.out.println("----  v2.0 alpha: ");
      for (SimpleXMLEntity el : els) System.out.println(el.getXMLString("    ", false));

      els =
          gei.getNetworkMLEntities(
              UnitConverter.GENESIS_SI_UNITS,
              NeuroMLConstants.NeuroMLVersion.getLatestVersion(),
              null);

      System.out.println("----  v2.0 beta: ");
      for (SimpleXMLEntity el : els) System.out.println(el.getXMLString("    ", false));

      System.out.println("-------------- ");

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  public SynapticPropertiesDialog(Dialog dlg, SynapticProperties synProps, Project project) {
    super(dlg, "Synaptic Properties", false);

    logger.logComment("Starting with: " + synProps);

    this.mySynProps = synProps;
    this.project = project;

    try {
      jbInit();
      extraInit();
      pack();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Example #4
0
  public static void main(String args[]) {

    try {

      logger.logComment("Sys prop: " + System.getProperty("java.library.path"), true);

      // File projFile = new File("../copyNcModels/NewGranCellLayer/NewGranCellLayer.neuro.xml");

      // File projFile = new File("../nC_projects/Bignet/Bignet.neuro.xml");
      File projFile = new File("testProjects/TestNetworkML/TestNetworkML.neuro.xml");

      // Project testProj = Project.loadProject(new File("projects/Parall/Parall.neuro.xml"),null);
      // Project testProj = Project.loadProject(new
      // File("examples/Ex5-Networks/Ex5-Networks.neuro.xml"),null);
      Project testProj = Project.loadProject(projFile, null);

      // File h5File = new File(projFile.getParentFile().getAbsolutePath()+
      // "/savedNetworks/hhh.h5");
      // File h5File = new File(projFile.getParentFile().getAbsolutePath()+
      // "/savedNetworks/nnnn.h5");

      File h5File = new File("testProjects/TestNetworkML/savedNetworks/small.h5");

      // logger.logComment("Loading netml cell from "+ h5File.getAbsolutePath(), true);

      NetworkMLReader nmlReader = new NetworkMLReader(testProj);

      nmlReader.parse(h5File);

      logger.logComment("Contents: " + testProj.generatedCellPositions);
      logger.logComment("Net conns: " + testProj.generatedNetworkConnections);
      logger.logComment("Inputs: " + testProj.generatedElecInputs.details(false));

    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
    }
  }
  public ArrayList<SimpleXMLEntity> getNetworkMLEntities(
      int unitSystem, NeuroMLConstants.NeuroMLVersion version, SimpleXMLElement topLevelCompElement)
      throws NeuroMLException {
    ArrayList<SimpleXMLEntity> entities = new ArrayList<SimpleXMLEntity>();

    Units timeUnits = UnitConverter.timeUnits[unitSystem];
    Units currentUnits = UnitConverter.currentUnits[unitSystem];

    SimpleXMLElement inputsElement = null;
    try {
      logger.logComment(
          "Going to save file in NeuroML format: "
              + this.getNumberSingleInputs()
              + " inputs in total");

      if (getNumberSingleInputs() == 0) {
        SimpleXMLComment comm =
            new SimpleXMLComment("There are no electrical inputs present in the network");
        entities.add(comm);
        return entities;
      }

      boolean nml2 = version.isVersion2();
      boolean nml2alpha = version.isVersion2alpha();

      if (!nml2) {
        inputsElement = new SimpleXMLElement(NetworkMLConstants.INPUTS_ELEMENT);
        entities.add(inputsElement);

        if (unitSystem == UnitConverter.GENESIS_PHYSIOLOGICAL_UNITS) {
          inputsElement.addAttribute(
              new SimpleXMLAttribute(
                  NetworkMLConstants.UNITS_ATTR, NetworkMLConstants.UNITS_PHYSIOLOGICAL));
        } else if (unitSystem == UnitConverter.GENESIS_SI_UNITS) {
          inputsElement.addAttribute(
              new SimpleXMLAttribute(NetworkMLConstants.UNITS_ATTR, NetworkMLConstants.UNITS_SI));
        }
      }

      Enumeration keys = myElecInputs.keys();

      while (keys.hasMoreElements()) {
        String inputReference = (String) keys.nextElement();
        ArrayList<SingleElectricalInput> inputsHere = getInputLocations(inputReference);

        logger.logComment("Adding " + inputsHere.size() + " inputs");

        StimulationSettings nextStim = project.elecInputInfo.getStim(inputReference);

        ElectricalInput myElectricalInput = nextStim.getElectricalInput();

        SimpleXMLElement inputElement = new SimpleXMLElement(NetworkMLConstants.INPUT_ELEMENT);

        inputElement.addAttribute(
            new SimpleXMLAttribute(NetworkMLConstants.INPUT_NAME_ATTR, inputReference));

        if (myElectricalInput instanceof IClamp) {
          IClamp ic = (IClamp) myElectricalInput;

          float delay = ic.getDel().getNominalNumber();
          float duration = ic.getDur().getNominalNumber();
          float amplitude = ic.getAmp().getNominalNumber();

          SimpleXMLElement inputTypeElement =
              new SimpleXMLElement(NetworkMLConstants.PULSEINPUT_ELEMENT);

          float del =
              (float) UnitConverter.getTime(delay, UnitConverter.NEUROCONSTRUCT_UNITS, unitSystem);
          float dur =
              (float)
                  UnitConverter.getTime(duration, UnitConverter.NEUROCONSTRUCT_UNITS, unitSystem);
          float amp =
              (float)
                  UnitConverter.getCurrent(
                      amplitude, UnitConverter.NEUROCONSTRUCT_UNITS, unitSystem);

          inputTypeElement.addAttribute(
              new SimpleXMLAttribute(NetworkMLConstants.INPUT_DELAY_ATTR, del + ""));

          inputTypeElement.addAttribute(
              new SimpleXMLAttribute(NetworkMLConstants.INPUT_DUR_ATTR, dur + ""));

          inputTypeElement.addAttribute(
              new SimpleXMLAttribute(NetworkMLConstants.INPUT_AMP_ATTR, amp + ""));

          inputElement.addChildElement(inputTypeElement);

          inputElement.addContent("\n        ");

          if (nml2) {
            SimpleXMLElement pulseGenElement =
                new SimpleXMLElement(NetworkMLConstants.NEUROML2_PULSE_GEN_ELEMENT);
            pulseGenElement.addAttribute(NeuroMLConstants.NEUROML_ID_V2, inputReference);
            pulseGenElement.addAttribute(
                NetworkMLConstants.INPUT_DELAY_ATTR, del + timeUnits.getNeuroML2Symbol());
            pulseGenElement.addAttribute(
                NetworkMLConstants.INPUT_DUR_ATTR, dur + timeUnits.getNeuroML2Symbol());
            pulseGenElement.addAttribute(
                NetworkMLConstants.INPUT_AMP_ATTR, amp + currentUnits.getNeuroML2Symbol());

            topLevelCompElement.addContent("\n\n    ");
            topLevelCompElement.addChildElement(pulseGenElement);
            topLevelCompElement.addContent("\n\n    ");
          }

        } else if (myElectricalInput instanceof RandomSpikeTrain) {
          RandomSpikeTrain rst = (RandomSpikeTrain) myElectricalInput;

          float stimFreq = rst.getRate().getNominalNumber();
          String stimMech = rst.getSynapseType();

          SimpleXMLElement inputTypeElement =
              new SimpleXMLElement(NetworkMLConstants.RANDOMSTIM_ELEMENT);
          float rate =
              (float)
                  UnitConverter.getRate(stimFreq, UnitConverter.NEUROCONSTRUCT_UNITS, unitSystem);
          inputTypeElement.addAttribute(
              new SimpleXMLAttribute(
                  NetworkMLConstants.RND_STIM_FREQ_ATTR,
                  (float)
                          UnitConverter.getRate(
                              stimFreq, UnitConverter.NEUROCONSTRUCT_UNITS, unitSystem)
                      + ""));

          inputTypeElement.addAttribute(
              new SimpleXMLAttribute(NetworkMLConstants.RND_STIM_MECH_ATTR, stimMech));
          inputElement.addChildElement(inputTypeElement);
          inputElement.addContent("\n        ");

          if (nml2 && !nml2alpha) {
            SimpleXMLElement spikeGenElement =
                new SimpleXMLElement(NetworkMLConstants.NEUROML2_SPIKE_GEN_POISSON_ELEMENT);
            spikeGenElement.addAttribute(NeuroMLConstants.NEUROML_ID_V2, inputReference);
            spikeGenElement.addAttribute(
                NetworkMLConstants.NEUROML2_SPIKE_GEN_POISSON_RATE_ATTR,
                rate
                    + " "
                    + UnitConverter.rateUnits[UnitConverter.NEUROCONSTRUCT_UNITS]
                        .getNeuroML2Symbol()
                    + "");

            topLevelCompElement.addContent("\n\n    ");
            topLevelCompElement.addChildElement(spikeGenElement);
            topLevelCompElement.addContent("\n\n    ");
          }
        } else {
          throw new NeuroMLException(
              "Error trying to save input "
                  + inputReference
                  + ". Cannot save in NeuroML an input of type: "
                  + myElectricalInput.getType());
        }

        SimpleXMLElement inputTargetElement =
            new SimpleXMLElement(NetworkMLConstants.INPUT_TARGET_ELEMENT);

        inputTargetElement.addAttribute(
            new SimpleXMLAttribute(
                NetworkMLConstants.INPUT_TARGET_POPULATION_ATTR, nextStim.getCellGroup()));

        inputElement.addChildElement(inputTargetElement);
        inputTargetElement.addContent("\n            ");

        SimpleXMLElement inputTargetSitesElement =
            new SimpleXMLElement(NetworkMLConstants.INPUT_TARGET_SITES_ELEMENT);

        inputTargetSitesElement.addAttribute(
            new SimpleXMLAttribute(
                NetworkMLConstants.INPUT_SITES_SIZE_ATTR, inputsHere.size() + ""));

        inputTargetElement.addChildElement(inputTargetSitesElement);

        SimpleXMLElement stimProjElement = null;

        if (version.isVersion2betaOrLater()) {

          if (myElectricalInput instanceof IClamp) {
            SimpleXMLElement inputListElement =
                new SimpleXMLElement(NetworkMLConstants.NEUROML2_INPUT_LIST_ELEMENT);
            entities.add(inputListElement);
            inputListElement.addAttribute(NeuroMLConstants.NEUROML_ID_V2, nextStim.getReference());
            inputListElement.addAttribute(
                NetworkMLConstants.NEUROML2_INPUT_COMPONENT, inputReference);
            inputListElement.addAttribute(
                NetworkMLConstants.NEUROML2_INPUT_POPULATION, nextStim.getCellGroup());

            // inputElement.addContent("\n    ");
            inputTargetSitesElement = inputListElement;

          } else if (myElectricalInput instanceof RandomSpikeTrain) {
            SimpleXMLElement popElement =
                new SimpleXMLElement(NetworkMLConstants.POPULATION_ELEMENT);
            entities.add(0, popElement);
            popElement.addAttribute(
                NeuroMLConstants.NEUROML_ID_V2, nextStim.getReference() + "_population");
            popElement.addAttribute(
                NetworkMLConstants.NEUROML2_POPULATION_COMPONENT,
                nextStim.getReference() + "_population");
            popElement.addAttribute(
                NetworkMLConstants.NEUROML2_POPULATION_SIZE, inputsHere.size() + "");

            stimProjElement = new SimpleXMLElement(NetworkMLConstants.PROJECTION_ELEMENT);
            stimProjElement.addAttribute(
                NeuroMLConstants.NEUROML_ID_V2, nextStim.getReference() + "_projection");
            entities.add(stimProjElement);
          }
        }

        // Iterate around the list of sites
        for (int i = 0; i < inputsHere.size(); i++) {
          inputTargetSitesElement.addContent("\n                ");

          SingleElectricalInput sei = inputsHere.get(i);

          SimpleXMLElement inputTargetSiteElement =
              new SimpleXMLElement(NetworkMLConstants.INPUT_TARGET_SITE_ELEMENT);

          inputTargetSiteElement.addAttribute(
              new SimpleXMLAttribute(
                  NetworkMLConstants.INPUT_SITE_CELLID_ATTR, sei.getCellNumber() + ""));
          inputTargetSiteElement.addAttribute(
              new SimpleXMLAttribute(
                  NetworkMLConstants.INPUT_SITE_SEGID_ATTR, sei.getSegmentId() + ""));
          inputTargetSiteElement.addAttribute(
              new SimpleXMLAttribute(
                  NetworkMLConstants.INPUT_SITE_FRAC_ATTR, sei.getFractionAlong() + ""));

          if (!nml2) inputTargetSitesElement.addChildElement(inputTargetSiteElement);

          if (nml2 && !nml2alpha) {
            if (myElectricalInput instanceof RandomSpikeTrain) {
              String connElName = NetworkMLConstants.CONNECTION_ELEMENT;

              SimpleXMLElement connElement = new SimpleXMLElement(connElName);

              connElement.addAttribute(
                  new SimpleXMLAttribute(NetworkMLConstants.CONNECTION_ID_ATTR, i + ""));
              stimProjElement.addContent("\n    ");
              stimProjElement.addChildElement(connElement);
              stimProjElement.addContent("\n    ");
            }
          }

          if (sei.getInstanceProps() != null) {
            inputTargetSiteElement.addContent("\n                ");
            inputTargetSiteElement.addComment("Adding the site specific props");

            if (sei.getInstanceProps() instanceof IClampInstanceProps) {
              IClampInstanceProps ic = (IClampInstanceProps) sei.getInstanceProps();

              float delay =
                  (float)
                      UnitConverter.getTime(
                          ic.getDelay(), UnitConverter.NEUROCONSTRUCT_UNITS, unitSystem);
              float duration =
                  (float)
                      UnitConverter.getTime(
                          ic.getDuration(), UnitConverter.NEUROCONSTRUCT_UNITS, unitSystem);
              float amp =
                  (float)
                      UnitConverter.getCurrent(
                          ic.getAmplitude(), UnitConverter.NEUROCONSTRUCT_UNITS, unitSystem);

              if (!nml2) {
                SimpleXMLElement inputTypeElement =
                    new SimpleXMLElement(NetworkMLConstants.PULSEINPUT_INSTANCE_ELEMENT);

                inputTypeElement.addAttribute(
                    new SimpleXMLAttribute(NetworkMLConstants.INPUT_DELAY_ATTR, delay + ""));

                inputTypeElement.addAttribute(
                    new SimpleXMLAttribute(NetworkMLConstants.INPUT_DUR_ATTR, duration + ""));

                // System.out.println("Converted "+amp+" to "+ a);
                inputTypeElement.addAttribute(
                    new SimpleXMLAttribute(NetworkMLConstants.INPUT_AMP_ATTR, amp + ""));

                inputTargetSiteElement.addContent("                    ");
                inputTargetSiteElement.addChildElement(inputTypeElement);

                inputTargetSiteElement.addContent("\n                ");
              } else {
                SimpleXMLElement pulseGenElement =
                    new SimpleXMLElement(NetworkMLConstants.NEUROML2_PULSE_GEN_ELEMENT);
                pulseGenElement.addAttribute(
                    NeuroMLConstants.NEUROML_ID_V2, inputReference + "__" + i);
                pulseGenElement.addAttribute(
                    NetworkMLConstants.INPUT_DELAY_ATTR, delay + timeUnits.getNeuroML2Symbol());
                pulseGenElement.addAttribute(
                    NetworkMLConstants.INPUT_DUR_ATTR, duration + timeUnits.getNeuroML2Symbol());
                pulseGenElement.addAttribute(
                    NetworkMLConstants.INPUT_AMP_ATTR, amp + currentUnits.getNeuroML2Symbol());

                topLevelCompElement.addContent("\n\n    ");
                topLevelCompElement.addChildElement(pulseGenElement);
                topLevelCompElement.addContent("\n\n    ");

                if (version.isVersion2alpha()) {
                  String target = nextStim.getCellGroup() + "[" + sei.getCellNumber() + "]";
                  SimpleXMLElement expInputElement =
                      new SimpleXMLElement(NetworkMLConstants.NEUROML2_EXP_INPUT_ELEMENT);
                  expInputElement.addAttribute(
                      NetworkMLConstants.NEUROML2_EXP_INPUT_TARGET_ATTR, target);
                  expInputElement.addAttribute(
                      NetworkMLConstants.NEUROML2_EXP_INPUT_INPUT_ATTR, inputReference + "__" + i);

                  entities.add(expInputElement);
                } else {
                  String target =
                      "../"
                          + nextStim.getCellGroup()
                          + "/"
                          + sei.getCellNumber()
                          + "/"
                          + project.cellGroupsInfo.getCellType(nextStim.getCellGroup());
                  SimpleXMLElement expInputElement =
                      new SimpleXMLElement(NetworkMLConstants.NEUROML2_INPUT_LIST_ELEMENT);
                  expInputElement.addAttribute(
                      NetworkMLConstants.NEUROML2_EXP_INPUT_TARGET_ATTR, target);
                  expInputElement.addAttribute(
                      NetworkMLConstants.NEUROML2_EXP_INPUT_INPUT_ATTR, inputReference + "__" + i);

                  entities.add(expInputElement);
                }
              }
            } else if (sei.getInstanceProps() instanceof RandomSpikeTrainInstanceProps) {
              RandomSpikeTrainInstanceProps rst =
                  (RandomSpikeTrainInstanceProps) sei.getInstanceProps();

              float stimFreq = rst.getRate();
              // String stimMech = rst.get;

              SimpleXMLElement inputTypeElement =
                  new SimpleXMLElement(NetworkMLConstants.RANDOMSTIM_INSTANCE_ELEMENT);

              inputTypeElement.addAttribute(
                  new SimpleXMLAttribute(
                      NetworkMLConstants.RND_STIM_FREQ_ATTR,
                      (float)
                              UnitConverter.getRate(
                                  stimFreq, UnitConverter.NEUROCONSTRUCT_UNITS, unitSystem)
                          + ""));

              // inputTypeElement.addAttribute(new
              // SimpleXMLAttribute(NetworkMLConstants.RND_STIM_MECH_ATTR, stimMech));

              inputTargetSiteElement.addContent("                    ");
              inputTargetSiteElement.addChildElement(inputTypeElement);
              inputTargetSiteElement.addContent("\n                ");

            } else {
              throw new NeuroMLException(
                  "Error trying to save input "
                      + inputReference
                      + ". Cannot save in NeuroML an input of type: "
                      + myElectricalInput.getType());
            }
          } else {
            if (nml2) {
              if (version.isVersion2alpha()) {
                String target = nextStim.getCellGroup() + "[" + sei.getCellNumber() + "]";
                SimpleXMLElement expInputElement =
                    new SimpleXMLElement(NetworkMLConstants.NEUROML2_EXP_INPUT_ELEMENT);
                expInputElement.addAttribute(
                    NetworkMLConstants.NEUROML2_EXP_INPUT_TARGET_ATTR, target);
                expInputElement.addAttribute(
                    NetworkMLConstants.NEUROML2_EXP_INPUT_INPUT_ATTR, inputReference);

                entities.add(expInputElement);
              } else {
                String target =
                    "../"
                        + nextStim.getCellGroup()
                        + "/"
                        + sei.getCellNumber()
                        + "/"
                        + project.cellGroupsInfo.getCellType(nextStim.getCellGroup());
                SimpleXMLElement expInputElement =
                    new SimpleXMLElement(NetworkMLConstants.NEUROML2_INPUT_ELEMENT);
                expInputElement.addAttribute(NeuroMLConstants.NEUROML_ID_V2, i + "");
                expInputElement.addAttribute(
                    NetworkMLConstants.NEUROML2_EXP_INPUT_TARGET_ATTR, target);
                expInputElement.addAttribute(
                    NetworkMLConstants.NEUROML2_INPUT_DESTINATION,
                    NetworkMLConstants.NEUROML2_INPUT_DESTINATION_DEFAULT);

                inputTargetSitesElement.addChildElement(expInputElement);
              }
            }
          }

          if (i == inputsHere.size() - 1) inputTargetSitesElement.addContent("\n            ");

          // Next Site
        }
        inputTargetElement.addContent("\n        ");

        if (!nml2) {
          inputsElement.addChildElement(inputElement);
          inputElement.addContent("\n    ");
        }
      }
      logger.logComment("Finished saving data to inputs element");

    } catch (Exception ex) {
      ex.printStackTrace();
      throw new NeuroMLException("Problem creating inputs element file", ex);
    }
    return entities;
  }