# Path: pymicro/external/StarFile.py
# class StarList(list):
#     def __getitem__(self,args):
#         if isinstance(args,(int,slice)):
#             return super(StarList,self).__getitem__(args)
#         elif isinstance(args,tuple) and len(args)>1:   #extended comma notation
#             return super(StarList,self).__getitem__(args[0]).__getitem__(args[1:])
#         else:
#             return super(StarList,self).__getitem__(args[0])
# 
#     def __str__(self):
#         return "SL("+super(StarList,self).__str__() + ")"


    from cStringIO import StringIO
    from io import StringIO
    from urllib import urlopen         # for arbitrary opening
    from urlparse import urlparse, urljoin
    from urllib.request import urlopen
    from urllib.parse import urlparse, urljoin
from . import StarFile
from .StarFile import StarList  #put in global scope for exec statement
    from .drel import drel_runtime  #put in global scope for exec statement
from copy import copy          #must be in global scope for exec statement
        from .drel import drel_ast_yacc
        from .drel import py_from_ast
        from .drel import drel_ast_yacc
        from .drel import py_from_ast
    from . import TypeContentsParser as t
import re,sys
    import numpy                   #put in global scope for exec statement
        import traceback
        import numpy
                  def conv_from_numpy(one_elem):
                      if not hasattr(one_elem,'dtype'):
                         if isinstance(one_elem,(list,tuple)):
                            return StarFile.StarList([conv_from_numpy(a) for a in one_elem])
                         return one_elem
                      if one_elem.size > 1:   #so is not a float
                         return StarFile.StarList([conv_from_numpy(a) for a in one_elem.tolist()])
                      else:
                          try:
                            return one_elem.item(0)
                          except:
                            return one_elem
                  out_result = [conv_from_numpy(a) for a in result]
          # so out_result now contains a value suitable for storage
          cat_names = [a for a in self.keys() if self[a].get("_name.category_id",None)==the_category]
          has_cat_names = [a for a in cat_names if a in cifdata]
          print('Adding {}, found pre-existing names: '.format(key) + repr(has_cat_names))
          if len(has_cat_names)>0:   #this category already exists
              cifdata[key] = out_result      #lengths must match or else!!
              cifdata.AddLoopName(has_cat_names[0],key)
          else:
              cifdata[key] = out_result
              cifdata.CreateLoop([key])
          print('Loop info:' + repr(cifdata.loops))
          return out_result

    def store_new_unlooped_value(self,key,cifdata,result):
          """Store a single value from the dREL system"""
          if result is not None and hasattr(result,'dtype'):
              if result.size > 1:

# Path: pymicro/external/StarFile.py
# class StarList(list):
#     def __getitem__(self,args):
#         if isinstance(args,(int,slice)):
#             return super(StarList,self).__getitem__(args)
#         elif isinstance(args,tuple) and len(args)>1:   #extended comma notation
#             return super(StarList,self).__getitem__(args[0]).__getitem__(args[1:])
#         else:
#             return super(StarList,self).__getitem__(args[0])
# 
#     def __str__(self):
#         return "SL("+super(StarList,self).__str__() + ")"


# Path: pymicro/external/CifFile_module.py
    from cStringIO import StringIO
    from io import StringIO
    from urllib import urlopen         # for arbitrary opening
    from urlparse import urlparse, urljoin
    from urllib.request import urlopen
    from urllib.parse import urlparse, urljoin
from . import StarFile
from .StarFile import StarList  #put in global scope for exec statement
    from .drel import drel_runtime  #put in global scope for exec statement
from copy import copy          #must be in global scope for exec statement
        from .drel import drel_ast_yacc
        from .drel import py_from_ast
        from .drel import drel_ast_yacc
        from .drel import py_from_ast
    from . import TypeContentsParser as t
import re,sys
    import numpy                   #put in global scope for exec statement
        import traceback
        import numpy

                  def conv_from_numpy(one_elem):
                      if not hasattr(one_elem,'dtype'):
                         if isinstance(one_elem,(list,tuple)):
                            return StarFile.StarList([conv_from_numpy(a) for a in one_elem])
                         return one_elem
                      if one_elem.size > 1:   #so is not a float
                         return StarFile.StarList([conv_from_numpy(a) for a in one_elem.tolist()])
                      else:
                          try:
                            return one_elem.item(0)
                          except:
                            return one_elem
                  out_result = [conv_from_numpy(a) for a in result]
          # so out_result now contains a value suitable for storage
          cat_names = [a for a in self.keys() if self[a].get("_name.category_id",None)==the_category]
          has_cat_names = [a for a in cat_names if a in cifdata]
          print('Adding {}, found pre-existing names: '.format(key) + repr(has_cat_names))
          if len(has_cat_names)>0:   #this category already exists
              cifdata[key] = out_result      #lengths must match or else!!
              cifdata.AddLoopName(has_cat_names[0],key)
          else:
              cifdata[key] = out_result
              cifdata.CreateLoop([key])
          print('Loop info:' + repr(cifdata.loops))
          return out_result

    def store_new_unlooped_value(self,key,cifdata,result):
          """Store a single value from the dREL system"""
          if result is not None and hasattr(result,'dtype'):
              if result.size > 1:

                  out_result = StarFile.StarList(result.tolist())