Example #1
0
 def ions(self):
     """Dictionary of the ions involved in this mechanism"""
     if self.__ions is None:
         nmodl = _nmodl()
         lookup_visitor = nmodl.visitor.AstLookupVisitor()
         ions = lookup_visitor.lookup(self.ast,
                                      nmodl.ast.AstNodeType.USEION)
         result = {}
         for ion in ions:
             name = nmodl.to_nmodl(ion.name)
             read = [nmodl.to_nmodl(item) for item in ion.readlist]
             write = [nmodl.to_nmodl(item) for item in ion.writelist]
             if ion.valence:
                 valence = int(nmodl.to_nmodl(ion.valence.value))
             else:
                 valence = None
             ontology_id = None
             try:
                 ontology_id = ion.ontology_id
             except:
                 # older versions of the NMODL library didn't support .ontology_id
                 pass
             result[name] = {
                 'read': read,
                 'write': write,
                 'charge': valence,
                 'ontology_id': ontology_id
             }
         self.__ions = result
     # return a copy
     return dict(self.__ions)
Example #2
0
    def test_ast_construction(self):
        string = ast.String("tau")
        name = ast.Name(string)
        assert nmodl.to_nmodl(name) == 'tau'

        int_macro = nmodl.ast.Integer(1, ast.Name(ast.String("x")))
        assert nmodl.to_nmodl(int_macro) == 'x'

        statements = []
        block = ast.StatementBlock(statements)
        neuron_block = ast.NeuronBlock(block)
        assert nmodl.to_nmodl(neuron_block) == 'NEURON {\n}'
Example #3
0
 def test_set_parent(self):
     x_name = ast.Name(ast.String("x"))
     y_name = ast.Name(ast.String("y"))
     int_macro = nmodl.ast.Integer(1, x_name)
     y_name.parent = int_macro  # setting the parent
     int_macro.macro = y_name
     assert nmodl.to_nmodl(int_macro) == 'y'
Example #4
0
  def ontology_ids(self):
    nmodl = _nmodl()
    lookup_visitor = nmodl.visitor.AstLookupVisitor()

    try:
      onts = lookup_visitor.lookup(self.ast, nmodl.ast.AstNodeType.ONTOLOGY_STATEMENT)
    except AttributeError:
      raise Exception("nmodl module out of date; missing support for ontology declarations")

    return [nmodl.to_nmodl(ont.ontology_id) for ont in onts]
Example #5
0
 def test_ast_node_str(self):
     string = ast.String("tau")
     name = ast.Name(string)
     assert str(name) == nmodl.to_nmodl(name)