Esempio n. 1
0
def parseXML( xml_fname):
    """

    :param xml_fname:
    :return:
    """

    cc3dXML2ObjConverter = XMLUtils.Xml2Obj()
    root_element = cc3dXML2ObjConverter.Parse(xml_fname)
    return cc3dXML2ObjConverter
    def __init__(self, lds_file: str):
        self.lds_file = os.path.abspath(lds_file)
        assert os.path.isfile(self.lds_file)

        self.xml2_obj_converter = XMLUtils.Xml2Obj()
        self.root_element = self.xml2_obj_converter.Parse(lds_file)
        self.dim_element = self.root_element.getFirstElement("Dimensions")
        self.output_element = self.root_element.getFirstElement("Output")
        self.lattice_element = self.root_element.getFirstElement("Lattice")
        self.cell_types_elements = self.root_element.getElements("CellType")
        self.fields_element = self.root_element.getFirstElement("Fields")
Esempio n. 3
0
    def extractCurrentModule(
        self, _editor, _moduleType, _moduleName
    ):  # editor,_moduleType='Plugin',_moduleName=['Name','Contact']

        moduleName = []

        try:

            if _moduleName[0] == '' and _moduleName[1] == '':

                moduleName = []

            else:

                moduleName = _moduleName

        except:

            moduleName = _moduleName

        # print 'ecm _moduleType,moduleName=',(_moduleType,moduleName)

        moduleBegin, moduleEnd = self.cc3dmlHelper.findModuleLine(
            _editor=_editor, _moduleType=_moduleType, _moduleName=moduleName)

        # moduleBegin,moduleEnd=self.cc3dmlHelper.findModuleLine(_editor=_editor,_moduleType=_moduleType,_moduleName=_moduleName)

        # print 'ecm moduleBegin,moduleEnd=',(moduleBegin,moduleEnd)

        snippet = self.extractSnippet(_editor, moduleBegin, moduleEnd)

        # print 'EXTRACT moduleBegin,moduleEnd=',(moduleBegin,moduleEnd)

        if moduleBegin < 0 and moduleEnd < 0:
            return None, moduleBegin, moduleEnd

        cc3dXML2ObjConverter = XMLUtils.Xml2Obj()

        try:

            root_element = cc3dXML2ObjConverter.ParseString(snippet)

        except xml.parsers.expat.ExpatError as e:

            QMessageBox.critical(self.__ui, "Error Parsing CC3DML String ",
                                 e.__str__())

            raise UserWarning(e.__str__())

        # return root_element,moduleBegin,moduleEnd

        return cc3dXML2ObjConverter, moduleBegin, moduleEnd  # have to return cc3dXML2ObjConverter instead of root_element because if we return root_element then cc3dXML2ObjConverter
Esempio n. 4
0
def get_results_reader_no_ui(lds_file):
    """
    Generate CML Results Reader instance for a results lattice description file
    :param lds_file: Path to lattice description file
    :return: CMLResultsReader instance
    """
    xml2_obj_converter = XMLUtils.Xml2Obj()
    root_element = xml2_obj_converter.Parse(lds_file)
    dim_element = root_element.getFirstElement("Dimensions")
    field_dim = Dim3D()
    field_dim.x = int(dim_element.getAttribute("x"))
    field_dim.y = int(dim_element.getAttribute("y"))
    field_dim.z = int(dim_element.getAttribute("z"))

    ui_dummy = CC3DUIDummy(field_dim)

    return CMLResultReader(ui_dummy), ui_dummy
Esempio n. 5
0
    def extract_lattice_description_info(self, file_name: str) -> None:
        """
        Reads the xml that summarizes serialized simulation files
        :param file_name:{str} xml metadata file name
        :return: None
        """

        # lattice data simulation file
        lds_file = os.path.abspath(file_name)
        self.ldsDir = os.path.dirname(lds_file)

        xml2_obj_converter = XMLUtils.Xml2Obj()
        root_element = xml2_obj_converter.Parse(lds_file)
        dim_element = root_element.getFirstElement("Dimensions")
        self.fieldDim = CompuCell.Dim3D()
        self.fieldDim.x = int(dim_element.getAttribute("x"))
        self.fieldDim.y = int(dim_element.getAttribute("y"))
        self.fieldDim.z = int(dim_element.getAttribute("z"))
        output_element = root_element.getFirstElement("Output")
        self.ldsCoreFileName = output_element.getAttribute("CoreFileName")
        self.frequency = int(output_element.getAttribute("Frequency"))
        self.numberOfSteps = int(output_element.getAttribute("NumberOfSteps"))

        # obtaining list of files in the ldsDir
        lattice_element = root_element.getFirstElement("Lattice")
        self.latticeType = lattice_element.getAttribute("Type")

        # getting information about cell type names and cell ids.
        # It is necessary during generation of the PIF files from VTK output
        cell_types_elements = root_element.getElements("CellType")
        list_cell_type_elements = CC3DXMLListPy(cell_types_elements)
        for cell_type_element in list_cell_type_elements:
            type_name = cell_type_element.getAttribute("TypeName")
            type_id = cell_type_element.getAttributeAsInt("TypeId")
            self.typeIdTypeNameDict[type_id] = type_name

        # now will convert python dictionary into C++ map<int, string>

        self.typeIdTypeNameCppMap = CC3DXML.MapIntStr()
        for type_id in list(self.typeIdTypeNameDict.keys()):
            self.typeIdTypeNameCppMap[int(
                type_id)] = self.typeIdTypeNameDict[type_id]

        lds_file_list = os.listdir(self.ldsDir)

        for fName in lds_file_list:
            if re.match(".*\.vtk$", fName):
                self.ldsFileList.append(fName)

        self.ldsFileList.sort()

        # extracting information about fields in the lds file
        fields_element = root_element.getFirstElement("Fields")
        if fields_element:
            field_list = XMLUtils.CC3DXMLListPy(
                fields_element.getElements("Field"))

            for field_elem in field_list:

                field_name = field_elem.getAttribute("Name")
                self.fieldsUsed[field_elem.getAttribute(
                    "Name")] = field_elem.getAttribute("Type")
                if field_elem.findAttribute(
                        "Script"):  # True or False if present
                    # ToDo:  if a "CustomVis" Type was provided,
                    #  require that a "Script" was also provided; else warn user
                    custom_vis_script = field_elem.getAttribute("Script")

                    self.customVis = CompuCellSetup.createCustomVisPy(
                        field_name)
                    self.customVis.registerVisCallbackFunction(
                        CompuCellSetup.vtkScriptCallback)

                    self.customVis.addActor(field_name, "vtkActor")
                    # we'll piggyback off the actorsDict
                    self.customVis.addActor("customVTKScript",
                                            custom_vis_script)
    def __insertSnippet(self, _snippetName):

        # print "GOT REQUEST FOR SNIPPET ",_snippetName

        snippetNameStr = str(_snippetName)

        self.handlerDict = self.snippetUtils.getHandlersDict()

        text = self.snippetDictionary[str(_snippetName)]

        editor = self.__ui.getCurrentEditor()

        curFileName = str(self.__ui.getCurrentDocumentName())

        basename, ext = os.path.splitext(curFileName)

        if ext != ".xml" and ext != ".cc3dml":
            QMessageBox.warning(self.__ui, "CC3DML files only", "CC3DML code snippets work only for xml/cc3dml files")

            return

        # here we parse cell type plugin if found

        cc3dXML2ObjConverter = XMLUtils.Xml2Obj()

        # root_element=cc3dXML2ObjConverter.ParseString(str(editor.text()))

        # print 'root_element=',root_element

        cellTypeData = self.getCellTypeData()

        gpd = self.getPottsData()

        print('cellTypeData=', cellTypeData)

        # self.findModuleLine(editor,_moduleType='Plugin',_moduleName=['Name','CellType'])

        # self.findModuleLine(editor,_moduleType='Steppable',_moduleName=['Type','PIFInitializer'])

        # self.findModuleLine(editor,_moduleType='Potts',_moduleName=[])

        # self.findModuleLine(editor,_moduleType='Plugin',_moduleName=['Name','CenterOfMass'])

        if cellTypeData is None:  # could not obtain data by parsing xml file - most likely due to parsing error

            return

        hiding_comments = self.configuration.setting("SkipCommentsInXMLSnippets")

        if not len(cellTypeData):

            print('self.handlerDict=', self.handlerDict)

            print('self.handlerDict[str(_snippetName)]=', self.handlerDict["Plugins CellType"])

            pottsBegin, pottsEnd = self.findModuleLine(editor, _moduleType='Potts', _moduleName=[])

            if pottsEnd < 0:

                editor.setCursorPosition(0, 0)

            else:

                editor.setCursorPosition(pottsEnd + 1, 0)

            self.handlerDict["Plugins CellType"](data=cellTypeData, editor=editor, generalPropertiesData=gpd,
                                                 hiding_comments=hiding_comments)

            QMessageBox.warning(self.__ui, "Fresh Cell Type Plugin",

                                "Please check newly inserted code and call %s again" % snippetNameStr)

            return

            # read freshly inseerted cell type plugin

        else:

            self.handlerDict[snippetNameStr](data=cellTypeData, editor=editor, generalPropertiesData=gpd,
                                             hiding_comments=hiding_comments)

        return
    def getCellTypeData(self):

        editor = self.__ui.getCurrentEditor()

        cc3dXML2ObjConverter = XMLUtils.Xml2Obj()

        try:

            root_element = cc3dXML2ObjConverter.ParseString(str(editor.text()))

        except xml.parsers.expat.ExpatError as e:

            QMessageBox.critical(self.__ui, "Error Parsing CC3DML file", e.__str__())

            print('GOT PARSING ERROR:', e)

            return

        root_element.getFirstElement('Plugin')

        # print('root_element=', root_element)

        cellTypeElement = root_element.getFirstElement("Plugin", d2mss({"Name": "CellType"}))

        cellTypeDict = {}

        if not cellTypeElement or cellTypeElement is None:
            return cellTypeDict

        cellTypeElementVec = cellTypeElement.getElements("CellType")

        cellTypeElementVec = CC3DXMLListPy(cellTypeElement.getElements("CellType"))

        for element in cellTypeElementVec:

            typeName = ''

            typeId = -1

            typeFreeze = False

            if element.findAttribute('TypeName'):

                typeName = element.getAttribute('TypeName')

            else:

                continue

            if element.findAttribute('TypeId'):

                typeId = element.getAttributeAsInt('TypeId')

            else:

                continue

            if element.findAttribute('Freeze'):
                typeFreeze = True

            cellTypeDict[typeId] = [typeName, typeFreeze]

        return cellTypeDict

        print('cellTypeElementVec=', cellTypeElementVec)

        print('cellTypeElement=', dir(cellTypeElement))
    def getPottsData(self):

        editor = self.__ui.getCurrentEditor()

        gpd = {}

        # default values

        gpd['Dim'] = [0, 0, 0]

        gpd['Temperature'] = 0

        gpd['NeighborOrder'] = 3

        gpd['MCS'] = 10000

        gpd['SimulationName'] = 'PLEASE_PUT_SIMULATION_FILE_NAME_HERE'

        gpd['LatticeType'] = 'Square'

        cc3dXML2ObjConverter = XMLUtils.Xml2Obj()

        try:

            root_element = cc3dXML2ObjConverter.ParseString(str(editor.text()))

        except xml.parsers.expat.ExpatError as e:

            QMessageBox.critical(self.__ui, "Error Parsing CC3DML file", e.__str__())

            print('GOT PARSING ERROR:', e)

            return gpd

        root_element.getFirstElement('Plugin')

        # print('root_element=', root_element)

        pottsElement = root_element.getFirstElement('Potts')

        if not pottsElement or pottsElement is None:
            return gpd

        # extract dimension

        dimElement = pottsElement.getFirstElement('Dimensions')

        if dimElement:

            if dimElement.findAttribute('x'):
                gpd['Dim'][0] = dimElement.getAttributeAsUInt('x')

            if dimElement.findAttribute('y'):
                gpd['Dim'][1] = dimElement.getAttributeAsUInt('y')

            if dimElement.findAttribute('z'):
                gpd['Dim'][2] = dimElement.getAttributeAsUInt('z')

        tempElement = pottsElement.getFirstElement('Temperature')

        if tempElement:
            gpd['MembraneFluctuations'] = float(tempElement.getText())

        nElement = pottsElement.getFirstElement('NeighborOrder')

        if nElement:
            gpd['NeighborOrder'] = float(nElement.getText())

        sElement = pottsElement.getFirstElement('Steps')

        if sElement:
            gpd['MCS'] = float(sElement.getText())

        return gpd
from cc3d.twedit5.twedit.utils.global_imports import *
Esempio n. 10
0
# Start-Of-Header