Skip to content

Commit

Permalink
NeuGen's pseudo-backend: Improved comments - the pseudo-backend can b…
Browse files Browse the repository at this point in the history
…e used to generate networks and export them. Anything further has to be implemented if necessary.
  • Loading branch information
stephanmg committed Jul 29, 2016
1 parent 92a5812 commit 2985046
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 76 deletions.
52 changes: 43 additions & 9 deletions NeuGen/nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,60 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1">
<file>
<url>src/org/neugen/gui/NeuGenView.java</url>
<line>1615</line>
<line>1628</line>
</file>
</editor-bookmarks>
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/HocWriterTask.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/TXT/WriteToTXT.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroMLWriter.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLSynapse.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/visual/NeuGenDensityVisualization.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/TXT/TXTWriterTask.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/SimpleHocWriterTask.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuGenWriterTask.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/datastructures/Net.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/backend/main/EnhancedCLI.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/TXT/TXTAlphaSynapse.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/SimpleHocWriter.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLSynapseUnilateral.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/SectionLengthWarningDocumentListener.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/vrl/VRLDensityVisualization.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLSynapseBilateral.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/NeuGenApp.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NetworkMLElement.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/GlobalParameterDialog.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLPopulations.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/TXT/TXTWriter.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/HocWriter.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/datastructures/NetHippocampus.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/NeuGenLibTask.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/NeuGenLib.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLProjection.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NetworkMLValidationUtility.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/build.xml</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/datastructures/NetNeocortex.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/datastructures/NetBase.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/NeuroMLLevelSelector.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/backend/NGBackend.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/NeuGenView.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/visual/NeuGenVisualization.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroMLWriterTask.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/build.properties</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/TXT/WriteToTXT.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLProjections.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/datastructures/xml/XMLObject.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/OBJReader.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLInstance.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/NeuGenProject.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/backend/NGBackendUtil.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/foo.txt</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLNetwork.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/backend/main/SimpleCLI.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLPopulation.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/HocDialog.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLConnections.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLLocation.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLSynapseProperty.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/NewSingleton.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/datastructures/NetHippocampus.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/parsers/NeuroML/NetworkML/NeuroMLInstances.java</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/nbproject/build-impl.xml</file>
<file>file:/Users/stephan/Code/git/NeuGen_source/NeuGen/src/org/neugen/gui/NeuGenConstants.java</file>
</group>
</open-files>
</project-private>
97 changes: 40 additions & 57 deletions NeuGen/src/org/neugen/backend/NGBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@
import org.neugen.utils.Utils;

/**
* @brief provide some backend functionality
* @brief NeuGen's backend
* Note: This pseudo-backend attempts to disentangle the interweaved
* GUI and backend components of NeuGen. Therefore this pseudo-backend
* may be considered as a hack. Some functionality is available, cf.
* below, however this backend needs to be enhanced for desired functionality.
* @author stephanmg <[email protected]>
*
* @note maybe a configuration builder (SettingsBuilder) is a good choice
*/
public final class NGBackend {
/// public static members
Expand Down Expand Up @@ -119,8 +121,7 @@ public NGBackend(boolean with_gui) {
}

/**
* @brief executes just the project
*
* @brief executes the project
* @param projectType
*/
public void execute(String projectType) {
Expand All @@ -129,12 +130,11 @@ public void execute(String projectType) {

/**
* @brief loads the initial parameters from project directory
*
* @param file
* @param root
* @return
* @return parameter list
*/
@SuppressWarnings("CallToPrintStackTrace")
@SuppressWarnings({"CallToPrintStackTrace", "CallToThreadDumpStack"})
private XMLObject loadParam(File file) {
XMLObject root = null;
try {
Expand All @@ -150,10 +150,10 @@ private XMLObject loadParam(File file) {
}

/**
* @brief get's the project property
*
* @brief get the project property
* @param projectPath
* @param projectType
* @return list of properties
*/
private Properties getProjectProp(String projectPath, String projectType) {
Properties prop = new Properties();
Expand All @@ -177,13 +177,12 @@ private Properties getProjectProp(String projectPath, String projectType) {
}

/**
* @brief creates a project
*
* @brief creates a NeuGen project
* @param projectPath
* @param projectType
* @param force
* @param open_only - if specified opens only the project
* @return
* @return parameters as a map
*/
@SuppressWarnings("NestedAssignment")
public Map<String, XMLObject> create_and_open_project(String projectPath, String projectType, boolean force, boolean open_only) {
Expand Down Expand Up @@ -309,8 +308,7 @@ public Map<String, XMLObject> create_and_open_project(String projectPath, String
}

/**
* @brief saves the PARAM parameters
*
* @brief saves the PARAM parameters (NeuGen parameters)
* @param currentRoot
* @param projectDirPath
*/
Expand All @@ -319,8 +317,7 @@ private void save_param(XMLNode currentRoot, String projectDirPath) {
}

/**
* @brief saves the INTERNA parameters
*
* @brief saves the INTERNA parameters (NeuGen parameters)
* @param currentRoot
* @param projectDirPath
*/
Expand All @@ -330,7 +327,6 @@ private void save_interna(XMLNode currentRoot, String projectDirPath) {

/**
* @brief save all params
*
* @param paramTrees
* @param projectDirPath
*/
Expand All @@ -340,8 +336,7 @@ public void save(Map<String, XMLObject> paramTrees, String projectDirPath) {
}

/**
* @brief saves INTERNA or PARAM parameters
*
* @brief saves INTERNA or PARAM parameters (NeuGen parameters)
* @param currentRoot
* @param projectDirPath
* @param param
Expand All @@ -350,7 +345,7 @@ private void save(XMLNode currentRoot, String projectDirPath, String param) {
logger.info("leaf count: " + currentRoot.getLeafCount());

/**
* @todo brief: tied to GUI!
* @todo brief: tied to GUI! (implement the pseudocode below - more reasonable)
* workaround: 1) alter parameters in project file before generating the net
* 2) generate net
* 3) save the file in a gui-independent way (i. e.
Expand Down Expand Up @@ -378,56 +373,52 @@ private void save(XMLNode currentRoot, String projectDirPath, String param) {
}

/**
* @brief init param table
*
* @brief inits param table
* @param paramTrees
* @param paramPath
* @param internaPath
* @return map of parameters
*/
private Map<String, XMLObject> initParamTable(Map<String, XMLObject> paramTrees, String paramPath, String internaPath) {
XMLObject param = paramTrees.get(NeuGenConstants.PARAM);
XMLObject interna = paramTrees.get(NeuGenConstants.INTERNA);
Map<String, XMLObject> allParam = new HashMap<String, XMLObject>();

allParam.put(paramPath, param);
allParam.put(internaPath, interna);
return allParam;
}

/**
* @brief init all parameters
*
* @brief inits all parameters
* @param dirPath
* @param projectType
* @return map of all parameters
*/
private Map<String, XMLObject> initProjectParam(String dirPath, String projectType) {
File param = new File(dirPath + System.getProperty("file.separator") + NeuGenConstants.PARAM_FNAME);
File interna = new File(dirPath + System.getProperty("file.separator") + NeuGenConstants.INTERNA_FNAME);

Map<String, XMLObject> paramTrees = new HashMap<String, XMLObject>();
XMLObject paramRoot = loadParam(param);
XMLObject internaRoot = loadParam(interna);
paramTrees.put(NeuGenConstants.PARAM, paramRoot);
paramTrees.put(NeuGenConstants.INTERNA, internaRoot);

NeuGenLib.initParamData(initParamTable(paramTrees, param.getPath(), interna.getPath()), projectType);

return paramTrees;
}

/**
* @brief generates the net actually
*
* @brief generates the NeuGen net
* @param projectType
*/
public void generate_network(String projectType) {
ngLib.run(projectType);
/// not necessary:
/// ngLib.getNet().destroy();
/// ngLib.destroy();
}

/**
* @brief saves and closes project
* @brief saves and closes the NeuGen project
* @param paramTrees
* @param projectDirPath
*/
Expand All @@ -446,12 +437,10 @@ public void save_and_close_project(Map<String, XMLObject> paramTrees, String pro
}

/**
* @brief exports a network
*
* @brief exports the NeuGen network
* Note: Enhance this function by needs, i. e. if you
* need another exporter, like HOC or something else, you
* may add it here
*
* @param type
* @param file
* @param withCellType
Expand All @@ -476,7 +465,6 @@ public void export_network(String type, String file, boolean withCellType) {

/**
* @brief modify the project params and set them
*
* @param paramTrees;
* @param projectDirPath
*/
Expand All @@ -492,8 +480,7 @@ public void modifyProject(Map<String, XMLObject> paramTrees, String projectDirPa
}

/**
* @brief modifies n parts density
*
* @brief modifies n parts density (NeuGen property)
* @param paramTrees
* @param projectDirPath
* @param density
Expand Down Expand Up @@ -578,8 +565,7 @@ public void modifyNPartsDensity(Map<String, XMLObject> paramTrees, String projec
}

/**
* @brief correct synapse dist to custom value
*
* @brief correct synapse dist to custom value (NeuGen property)
* @param paramTrees
* @param projectDirPath
* @param dist_synapse
Expand Down Expand Up @@ -609,7 +595,7 @@ public void modifySynapseDistance(Map<String, XMLObject> paramTrees, String proj


/**
* @brief modifies a Neuron and Interna parameter
* @brief modifies a Neuron and INTERNA parameter
* @param paramTrees
* @param projectDirPath
* @param param
Expand All @@ -623,7 +609,7 @@ public void modifyAllParameter(Map<String, XMLObject> paramTrees, String project
}

/**
* @brief modifies a Neuron or Interna parameter
* @brief modifies a Neuron or INTERNA parameter
* @param paramTrees
* @param projectDirPath
* @param param
Expand All @@ -642,7 +628,7 @@ private void modifyParameter(Map<String, XMLObject> paramTrees, String projectDi
}

/**
* @brief modify's an Interna parameter
* @brief modifies an INTERNA parameter (NeuGen parameter)
* @param paramTrees
* @param projectDirPath
* @param param
Expand All @@ -653,7 +639,7 @@ public void modifyInternaParameter(Map<String, XMLObject> paramTrees, String pro
}

/**
* @brief modify's a Neuron parameter
* @brief modifies a Neuron parameter (NeuGen parameter)
* @param paramTrees
* @param projectDirPath
* @param param
Expand All @@ -664,7 +650,7 @@ public void modifyNeuronParameter(Map<String, XMLObject> paramTrees, String proj
}

/**
* @brief modifies some NEURON parameter recursively
* @brief modifies some Neuron parameter recursively (NeuGen parameter)
* @param paramTree
* @param projectDirPath
* @param param
Expand Down Expand Up @@ -693,7 +679,7 @@ private void modifyParameter(XMLObject paramTree, String projectDirPath, double
}

/**
* @brief modifies some NEURON parameter recursively
* @brief modifies some Neuron parameter recursively (NeuGen parameter)
* @param root
* @param param
* @param identifier
Expand All @@ -718,10 +704,9 @@ private void modifyParameter_rec(XMLNode root, double param, ArrayList<String> i
}

/**
* @brief replaces content of a given node specified by identifier with
* replacement
* @brief replaces content of a given node.
* The replacement is specified by identifier.
* @author stephanmg <[email protected]>
*
* @param child
* @param identifier
* @param replacement
Expand Down Expand Up @@ -752,7 +737,7 @@ private void correct_siblings(XMLNode child, String identifier, double replaceme

/**
* @brief returns the project type
* @return
* @return project type
*/
public String getProjectType() {
if (Region.isCa1Region()) {
Expand All @@ -765,22 +750,20 @@ public String getProjectType() {
}

/**
* @brief test
*
* @brief main method
* @param args
*/
@SuppressWarnings("CallToPrintStackTrace")
@SuppressWarnings({"CallToPrintStackTrace", "CallToThreadDumpStack"})
public static void main(String... args) {
/**
* @brief todo works - test remaining functionality...
*/
try {
NGBackend back = new NGBackend();
Map<String, XMLObject> params = back.create_and_open_project("foo24", NeuGenConstants.NEOCORTEX_PROJECT, true, false);
back.modifyNPartsDensity(params, "foo24/Neocortex", 0.1);
back.generate_network(NeuGenConstants.NEOCORTEX_PROJECT);
back.export_network("NGX", "foo24.ngx", false);
back.save_and_close_project(params, "foo26");
/// TODO: fix for save_and_close_project necessary
/// back.save_and_close_project(params, "foo26");

} catch (Exception e) {
logger.fatal("Make sure you selected a valid project directory: " + e);
e.printStackTrace();
Expand Down
Loading

0 comments on commit 2985046

Please sign in to comment.