def configure_simulation(): from cc3d.core.XMLUtils import ElementCC3D dim = 300 cc3d = ElementCC3D("CompuCell3D") metadata = cc3d.ElementCC3D("Metadata") metadata.ElementCC3D("NumberOfProcessors", {}, 4) potts = cc3d.ElementCC3D("Potts") potts.ElementCC3D("Dimensions", {"x": dim, "y": dim, "z": dim}) potts.ElementCC3D("Steps", {}, 100) potts.ElementCC3D("Temperature", {}, 0) potts.ElementCC3D("Flip2DimRatio", {}, 0.0) cellType = cc3d.ElementCC3D("Plugin", {"Name": "CellType"}) cellType.ElementCC3D("CellType", {"TypeName": "Medium", "TypeId": "0"}) flexDiffSolver = cc3d.ElementCC3D("Steppable", {"Type": "DiffusionSolverFE"}) diffusionField = flexDiffSolver.ElementCC3D("DiffusionField") diffusionData = diffusionField.ElementCC3D("DiffusionData") diffusionData.ElementCC3D("FieldName", {}, "FGF") diffusionData.ElementCC3D("DiffusionConstant", {}, 0.10) diffusionData.ElementCC3D("DecayConstant", {}, 0.0) diffusionData.ElementCC3D("ConcentrationFileName", {}, "Simulation/diffusion_3D.pulse.txt") CompuCellSetup.setSimulationXMLDescription(cc3d)
def configure_simulation(): from cc3d.core.XMLUtils import ElementCC3D cc3d = ElementCC3D("CompuCell3D") potts = cc3d.ElementCC3D("Potts") potts.ElementCC3D("Dimensions", {"x": 100, "y": 100, "z": 1}) potts.ElementCC3D("Steps", {}, 1000) potts.ElementCC3D("Anneal", {}, 10) potts.ElementCC3D("Temperature", {}, 10) potts.ElementCC3D("Flip2DimRatio", {}, 1) potts.ElementCC3D("NeighborOrder", {}, 2) cellType = cc3d.ElementCC3D("Plugin", {"Name": "CellType"}) cellType.ElementCC3D("CellType", {"TypeName": "Medium", "TypeId": "0"}) cellType.ElementCC3D("CellType", {"TypeName": "Condensing", "TypeId": "1"}) cellType.ElementCC3D("CellType", { "TypeName": "NonCondensing", "TypeId": "2" }) volume = cc3d.ElementCC3D("Plugin", {"Name": "Volume"}) volume.ElementCC3D("TargetVolume", {}, 25) volume.ElementCC3D("LambdaVolume", {}, 2.0) contact = cc3d.ElementCC3D("Plugin", {"Name": "Contact"}) contact.ElementCC3D("Energy", {"Type1": "Medium", "Type2": "Medium"}, 0) contact.ElementCC3D("Energy", { "Type1": "NonCondensing", "Type2": "NonCondensing" }, 16) contact.ElementCC3D("Energy", { "Type1": "Condensing", "Type2": "Condensing" }, 2) contact.ElementCC3D("Energy", { "Type1": "NonCondensing", "Type2": "Condensing" }, 11) contact.ElementCC3D("Energy", { "Type1": "NonCondensing", "Type2": "Medium" }, 16) contact.ElementCC3D("Energy", { "Type1": "Condensing", "Type2": "Medium" }, 16) contact.ElementCC3D("NeighborOrder", {}, 2) blobInitializer = cc3d.ElementCC3D("Steppable", {"Type": "BlobInitializer"}) blobInitializer.ElementCC3D("Gap", {}, 0) blobInitializer.ElementCC3D("Width", {}, 5) blobInitializer.ElementCC3D("CellSortInit", {}, "yes") blobInitializer.ElementCC3D("Radius", {}, 40) CompuCellSetup.setSimulationXMLDescription(cc3d)
def write_cc3d_file_format(self, file_name): csd = self.cc3dSimulationData simulation_element = ElementCC3D("Simulation", {"version": csd.version}) if csd.xmlScriptResource.path != "": el_name, attribute_dict, path = self.format_resource_element(csd.xmlScriptResource, "XMLScript") simulation_element.ElementCC3D(el_name, attribute_dict, path) if csd.pythonScriptResource.path != "": el_name, attribute_dict, path = self.format_resource_element(csd.pythonScriptResource, "PythonScript") simulation_element.ElementCC3D(el_name, attribute_dict, path) if csd.pifFileResource.path != "": el_name, attribute_dict, path = self.format_resource_element(csd.pifFileResource, "PIFFile") simulation_element.ElementCC3D(el_name, attribute_dict, path) if csd.windowScriptResource.path != "": el_name, attribute_dict, path = self.format_resource_element(csd.windowScriptResource, "WindowScript") simulation_element.ElementCC3D(el_name, attribute_dict, path) resources_dict = {} # storing resources in a dictionary using resource type as a key for resource_key, resource in csd.resources.items(): if resource.type == "PIFFile" and csd.pifFileResource.path == resource.path: print(MODULENAME, "IGNORING RESOURCE =", resource.path) continue try: resources_dict[resource.type].append(resource) except LookupError: resources_dict[resource.type] = [resource] # sort resources according to path name for resource_type, resource_list in resources_dict.items(): resource_list = sorted(resource_list, key=lambda x: x.path) # after sorting have to reinsert list into dictionary to have it available later resources_dict[resource_type] = resource_list sorted_resource_type_names = list(resources_dict.keys()) sorted_resource_type_names.sort() for resource_type in sorted_resource_type_names: for resource in resources_dict[resource_type]: el_name, attribute_dict, path = self.format_resource_element(resource) simulation_element.ElementCC3D(el_name, attribute_dict, path) if csd.serializerResource: csd.serializerResource.append_xml_stub(simulation_element) if csd.parameterScanResource: el_name, attribute_dict, path = self.format_resource_element(csd.parameterScanResource, 'ParameterScan') simulation_element.ElementCC3D(el_name, attribute_dict, path) simulation_element.CC3DXMLElement.saveXML(str(file_name))
def configure_simulation(): from cc3d.core.XMLUtils import ElementCC3D cc3d = ElementCC3D("CompuCell3D") potts = cc3d.ElementCC3D("Potts") potts.ElementCC3D("Dimensions", {"x": 100, "y": 100, "z": 1}) potts.ElementCC3D("Steps", {}, 10000) potts.ElementCC3D("Temperature", {}, 5) potts.ElementCC3D("NeighborOrder", {}, 2) potts.ElementCC3D("Boundary_x", {}, "Periodic") cell_type = cc3d.ElementCC3D("Plugin", {"Name": "CellType"}) cell_type.ElementCC3D("CellType", {"TypeName": "Medium", "TypeId": "0"}) cell_type.ElementCC3D("CellType", {"TypeName": "Body1", "TypeId": "1"}) cell_type.ElementCC3D("CellType", {"TypeName": "Body2", "TypeId": "2"}) cell_type.ElementCC3D("CellType", {"TypeName": "Body3", "TypeId": "3"}) volume = cc3d.ElementCC3D("Plugin", {"Name": "Volume"}) volume.ElementCC3D("TargetVolume", {}, 25) volume.ElementCC3D("LambdaVolume", {}, 4.0) contact = cc3d.ElementCC3D("Plugin", {"Name": "Contact"}) contact.ElementCC3D("Energy", {"Type1": "Medium", "Type2": "Medium"}, 0) contact.ElementCC3D("Energy", {"Type1": "Body1", "Type2": "Body1"}, 16) contact.ElementCC3D("Energy", {"Type1": "Body1", "Type2": "Medium"}, 4) contact.ElementCC3D("Energy", {"Type1": "Body2", "Type2": "Body2"}, 16) contact.ElementCC3D("Energy", {"Type1": "Body2", "Type2": "Medium"}, 4) contact.ElementCC3D("Energy", {"Type1": "Body3", "Type2": "Body3"}, 16) contact.ElementCC3D("Energy", {"Type1": "Body3", "Type2": "Medium"}, 4) contact.ElementCC3D("Energy", {"Type1": "Body1", "Type2": "Body2"}, 16) contact.ElementCC3D("Energy", {"Type1": "Body1", "Type2": "Body3"}, 16) contact.ElementCC3D("Energy", {"Type1": "Body2", "Type2": "Body3"}, 16) contact.ElementCC3D("neighborOrder", {}, 2) center_of_mass = cc3d.ElementCC3D("Plugin", {"Name": "CenterOfMass"}) elasticity_tracker = cc3d.ElementCC3D("Plugin", {"Name": "ElasticityTracker"}) elasticity_tracker.ElementCC3D("IncludeType", {}, "Body1") elasticity_tracker.ElementCC3D("IncludeType", {}, "Body2") elasticity_tracker.ElementCC3D("IncludeType", {}, "Body3") elasticity_energy = cc3d.ElementCC3D("Plugin", {"Name": "ElasticityEnergy"}) elasticity_energy.ElementCC3D("Local", {}) # elasticity_energy.ElementCC3D("LambdaElasticity",{},200.0) # elasticity_energy.ElementCC3D("TargetLengthElasticity",{},6) external_potential = cc3d.ElementCC3D("Plugin", {"Name": "ExternalPotential"}) external_potential.ElementCC3D("Lambda", {"x": -10, "y": 0, "z": 0}) pif_initializer = cc3d.ElementCC3D("Steppable", {"Type": "PIFInitializer"}) pif_initializer.ElementCC3D("PIFName", {}, "Simulation/elasticitytest.piff") CompuCellSetup.setSimulationXMLDescription(cc3d)
def generateXML(self): mElement = ElementCC3D('Potts') mElement.addComment("newline") mElement.addComment("Basic properties of CPM (GGH) algorithm") mElement.ElementCC3D( "Dimensions", { "x": self.xDimSB.value(), "y": self.yDimSB.value(), "z": self.zDimSB.value() }) mElement.ElementCC3D("Steps", {}, self.mcsSB.value()) if self.anneal_mcsSB.value() != 0: mElement.ElementCC3D("Anneal", {}, self.anneal_mcsSB.value()) mElement.ElementCC3D("Temperature", {}, float(str(self.membraneFluctuationsLE.text()))) mElement.ElementCC3D("NeighborOrder", {}, self.neighborOrderSB.value()) if str(self.latticeTypeCB.currentText()) != "Square": mElement.ElementCC3D("LatticeType", {}, str(self.latticeTypeCB.currentText())) for dim_name_bc_widget, dim_name in [(self.xbcCB, 'x'), (self.ybcCB, 'y'), (self.zbcCB, 'z')]: try: if str(dim_name_bc_widget.currentText()) == 'Periodic': mElement.ElementCC3D('Boundary_' + dim_name, {}, 'Periodic') except KeyError: pass # mElement.ElementCC3D('Boundary_' + dim_name, {}, 'NoFlux') if self.auto_gen_rand_seed_CB.isChecked(): mElement.ElementCC3D('RandomSeed', {}, randint(0, sys.maxsize)) return mElement
def __init__(self, simulation_dir, simulation_name): self.simulationDir = simulation_dir self.simulationName = simulation_name self.fileName = os.path.join(str(self.simulationDir), str(self.simulationName) + ".xml") self.generalPropertiesDict = {} self.cellTypeTable = [["Medium", False]] self.cc3d = ElementCC3D("CompuCell3D", {"version": cc3d.__version__}) self.afMolecules = [] self.afFormula = 'min(Molecule1,Molecule2)' self.cmcCadherins = [] self.chemFieldsTable = [] self.secretionTable = {} self.chemotaxisTable = {}
def configure_simulation(): from cc3d.core.XMLUtils import ElementCC3D cc3d = ElementCC3D("CompuCell3D") potts = cc3d.ElementCC3D("Potts") potts.ElementCC3D("Dimensions", {"x": 42, "y": 42, "z": 1}) potts.ElementCC3D("Steps", {}, 10000) potts.ElementCC3D("Anneal", {}, 10) potts.ElementCC3D("Temperature", {}, 10) potts.ElementCC3D("NeighborOrder", {}, 2) potts.ElementCC3D("Boundary_x", {}, "Periodic") potts.ElementCC3D("Boundary_y", {}, "Periodic") cellType = cc3d.ElementCC3D("Plugin", {"Name": "CellType"}) cellType.ElementCC3D("CellType", {"TypeName": "Medium", "TypeId": "0"}) cellType.ElementCC3D("CellType", {"TypeName": "TypeA", "TypeId": "1"}) contact = cc3d.ElementCC3D("Plugin", {"Name": "Contact"}) contact.ElementCC3D("Energy", {"Type1": "Medium", "Type2": "Medium"}, 0) contact.ElementCC3D("Energy", {"Type1": "Medium", "Type2": "TypeA"}, 5) contact.ElementCC3D("Energy", {"Type1": "TypeA", "Type2": "TypeA"}, 5) contact.ElementCC3D("NeighborOrder", {}, 4) vp = cc3d.ElementCC3D("Plugin", {"Name": "Volume"}) vp.ElementCC3D("TargetVolume", {}, 49) vp.ElementCC3D("LambdaVolume", {}, 5) ntp = cc3d.ElementCC3D("Plugin", {"Name": "NeighborTracker"}) uipd = cc3d.ElementCC3D("Steppable", {"Type": "UniformInitializer"}) region = uipd.ElementCC3D("Region") region.ElementCC3D("BoxMin", {"x": 0, "y": 0, "z": 0}) region.ElementCC3D("BoxMax", {"x": 42, "y": 42, "z": 1}) region.ElementCC3D("Types", {}, "TypeA") region.ElementCC3D("Width", {}, 7) CompuCellSetup.setSimulationXMLDescription(cc3d)
def configure_simulation(): from cc3d.core.XMLUtils import ElementCC3D cc3d = ElementCC3D("CompuCell3D") potts = cc3d.ElementCC3D("Potts") potts.ElementCC3D("Dimensions", {"x": 55, "y": 55, "z": 1}) potts.ElementCC3D("Steps", {}, 1000) potts.ElementCC3D("Temperature", {}, 15) potts.ElementCC3D("Boundary_y", {}, "Periodic") cellType = cc3d.ElementCC3D("Plugin", {"Name": "CellType"}) cellType.ElementCC3D("CellType", {"TypeName": "Medium", "TypeId": "0"}) cellType.ElementCC3D("CellType", {"TypeName": "Amoeba", "TypeId": "1"}) cellType.ElementCC3D("CellType", {"TypeName": "Bacteria", "TypeId": "2"}) volume = cc3d.ElementCC3D("Plugin", {"Name": "Volume"}) volume.ElementCC3D("TargetVolume", {}, 25) volume.ElementCC3D("LambdaVolume", {}, 15.0) surface = cc3d.ElementCC3D("Plugin", {"Name": "Surface"}) surface.ElementCC3D("TargetSurface", {}, 25) surface.ElementCC3D("LambdaSurface", {}, 2.0) contact = cc3d.ElementCC3D("Plugin", {"Name": "Contact"}) contact.ElementCC3D("Energy", {"Type1": "Medium", "Type2": "Medium"}, 0) contact.ElementCC3D("Energy", {"Type1": "Amoeba", "Type2": "Amoeba"}, 15) contact.ElementCC3D("Energy", {"Type1": "Amoeba", "Type2": "Medium"}, 8) contact.ElementCC3D("Energy", { "Type1": "Bacteria", "Type2": "Bacteria" }, 15) contact.ElementCC3D("Energy", {"Type1": "Bacteria", "Type2": "Amoeba"}, 15) contact.ElementCC3D("Energy", {"Type1": "Bacteria", "Type2": "Medium"}, 8) contact.ElementCC3D("NeighborOrder", {}, 2) chemotaxis = cc3d.ElementCC3D("Plugin", {"Name": "Chemotaxis"}) chemicalField = chemotaxis.ElementCC3D("ChemicalField", { "Source": "DiffusionSolverFE", "Name": "FGF" }) chemicalField.ElementCC3D("ChemotaxisByType", { "Type": "Amoeba", "Lambda": 3 }) chemicalField.ElementCC3D("ChemotaxisByType", { "Type": "Bacteria", "Lambda": 2 }) flexDiffSolver = cc3d.ElementCC3D("Steppable", {"Type": "DiffusionSolverFE"}) diffusionField = flexDiffSolver.ElementCC3D("DiffusionField") diffusionData = diffusionField.ElementCC3D("DiffusionData") diffusionData.ElementCC3D("FieldName", {}, "FGF") diffusionData.ElementCC3D("DiffusionConstant", {}, 0.0) diffusionData.ElementCC3D("DecayConstant", {}, 0.0) diffusionData.ElementCC3D("ConcentrationFileName", {}, "Simulation/amoebaConcentrationField_2D.txt") pifInitializer = cc3d.ElementCC3D("Steppable", {"Type": "PIFInitializer"}) pifInitializer.ElementCC3D("PIFName", {}, "Simulation/amoebae_2D.piff") CompuCellSetup.setSimulationXMLDescription(cc3d)
def configure_simulation(): from cc3d.core.XMLUtils import ElementCC3D CompuCell3DElmnt = ElementCC3D("CompuCell3D", {"version": "3.6.0"}) # Basic properties of CPM (GGH) algorithm potts_el = CompuCell3DElmnt.ElementCC3D("Potts") potts_el.ElementCC3D("Dimensions", {"x": "50", "y": "50", "z": "50"}) potts_el.ElementCC3D("Steps", {}, "10000") potts_el.ElementCC3D("Temperature", {}, "20.0") potts_el.ElementCC3D("NeighborOrder", {}, "3") potts_el.ElementCC3D("Boundary_x", {}, "Periodic") potts_el.ElementCC3D("Boundary_y", {}, "Periodic") potts_el.ElementCC3D("Boundary_z", {}, "Periodic") # Listing all cell types in the simulation cell_type_el = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "CellType"}) cell_type_el.ElementCC3D("CellType", {"TypeId": "0", "TypeName": "Medium"}) cell_type_el.ElementCC3D("CellType", {"TypeId": "1", "TypeName": "Endothelial"}) # Constraint on cell volume. Each cell type has different constraint. # For more flexible specification of the constraint (done in Python) please use VolumeLocalFlex plugin vol_plug_elem = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Volume"}) vol_plug_elem.ElementCC3D("VolumeEnergyParameters", {"CellType": "Endothelial", "LambdaVolume": "20.0", "TargetVolume": "74"}) # Specification of adhesion energies contact_plug_el = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Contact"}) contact_plug_el.ElementCC3D("Energy", {"Type1": "Medium", "Type2": "Medium"}, "0") contact_plug_el.ElementCC3D("Energy", {"Type1": "Medium", "Type2": "Endothelial"}, "12") contact_plug_el.ElementCC3D("Energy", {"Type1": "Endothelial", "Type2": "Endothelial"}, "5") contact_plug_el.ElementCC3D("NeighborOrder", {}, "4") # Specification of chemotaxis properties of select cell types. chem_plug_el = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Chemotaxis"}) chemical_field_el = chem_plug_el.ElementCC3D("ChemicalField", {"Name": "VEGF", "Source": "FlexibleDiffusionSolverFE"}) chemical_field_el.ElementCC3D("ChemotaxisByType", {"ChemotactTowards": "Medium", "Lambda": "6000.0", "Type": "Endothelial"}) # Specification of secretion properties of select cell types. # Specification of secretion properties of individual cells can be done in Python secr_plug_el = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Secretion"}) field_el = secr_plug_el.ElementCC3D("Field", {"Name": "VEGF"}) field_el.ElementCC3D("Secretion", {"Type": "Endothelial"}, "0.013") # Module allowing multiple calls of the PDE solver. By default number of extra calls is set to 0. # Change these settings to desired values after consulting CC3D manual on how to work with large diffusion constants # (>0.16 in 3D with DeltaX=1.0 and DeltaT=1.0) pde_solv_call_plug_el = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "PDESolverCaller"}) pde_solv_call_plug_el.ElementCC3D("CallPDE", {"ExtraTimesPerMC": "0", "PDESolverName": "FlexibleDiffusionSolverFE"}) # Specification of PDE solvers flex_diff_solv_el = CompuCell3DElmnt.ElementCC3D("Steppable", {"Type": "FlexibleDiffusionSolverFE"}) diff_field_elmnt = flex_diff_solv_el.ElementCC3D("DiffusionField") diff_data_el = diff_field_elmnt.ElementCC3D("DiffusionData") diff_data_el.ElementCC3D("FieldName", {}, "VEGF") diff_data_el.ElementCC3D("DiffusionConstant", {}, "0.16") diff_data_el.ElementCC3D("DecayConstant", {}, "0.016") # Additional options are: # DiffusionDataElmnt.ElementCC3D("DoNotDiffuseTo",{},"LIST YOUR CELL TYPES HERE") diff_data_el.ElementCC3D("DoNotDecayIn", {}, "Endothelial") # DiffusionDataElmnt.ElementCC3D("ConcentrationFileName",{},"INITIAL CONCENTRATION FIELD - typically a file with # path Simulation/NAME_OF_THE_FILE.txt") # To run solver for large diffusion constants you typically call solver multiple times - ExtraTimesPerMCS # to specify additional calls to the solver in each MCS # IMPORTANT: make sure not to mix this setting with the PDESolverCaller module! See manual for more information # DiffusionDataElmnt.ElementCC3D("ExtraTimesPerMCS",{},"0") diff_data_el.ElementCC3D("DeltaX", {}, "1.0") diff_data_el.ElementCC3D("DeltaT", {}, "1.0") # Initial layout of cells in the form of rectangular slab uni_init_el = CompuCell3DElmnt.ElementCC3D("Steppable", {"Type": "UniformInitializer"}) region_el = uni_init_el.ElementCC3D("Region") region_el.ElementCC3D("BoxMin", {"x": "15", "y": "15", "z": "15"}) # region_el.ElementCC3D("BoxMax", {"x": "19", "y": "19", "z": "19"}) region_el.ElementCC3D("BoxMax", {"x": "35", "y": "35", "z": "35"}) region_el.ElementCC3D("Gap", {}, "0") region_el.ElementCC3D("Width", {}, "4") region_el.ElementCC3D("Types", {}, "Endothelial") CompuCellSetup.set_simulation_xml_description(CompuCell3DElmnt)
def configure_simulation(): from cc3d.core.XMLUtils import ElementCC3D cc3d = ElementCC3D("CompuCell3D") potts = cc3d.ElementCC3D("Potts") potts.ElementCC3D("Dimensions", {"x": 100, "y": 100, "z": 1}) potts.ElementCC3D("Steps", {}, 10000) potts.ElementCC3D("Temperature", {}, 15) potts.ElementCC3D("NeighborOrder", {}, 2) cellType = cc3d.ElementCC3D("Plugin", {"Name": "CellType"}) cellType.ElementCC3D("CellType", {"TypeName": "Medium", "TypeId": "0"}) cellType.ElementCC3D("CellType", {"TypeName": "Bacterium", "TypeId": "1"}) cellType.ElementCC3D("CellType", {"TypeName": "Macrophage", "TypeId": "2"}) cellType.ElementCC3D("CellType", { "TypeName": "Wall", "TypeId": "3", "Freeze": "" }) volume = cc3d.ElementCC3D("Plugin", {"Name": "Volume"}) volume.ElementCC3D("TargetVolume", {}, 25) volume.ElementCC3D("LambdaVolume", {}, 15.0) surface = cc3d.ElementCC3D("Plugin", {"Name": "Surface"}) surface.ElementCC3D("TargetSurface", {}, 20) surface.ElementCC3D("LambdaSurface", {}, 4.0) contact = cc3d.ElementCC3D("Plugin", {"Name": "Contact"}) contact.ElementCC3D("Energy", {"Type1": "Medium", "Type2": "Medium"}, 0) contact.ElementCC3D("Energy", { "Type1": "Macrophage", "Type2": "Macrophage" }, 15) contact.ElementCC3D("Energy", { "Type1": "Macrophage", "Type2": "Medium" }, 8) contact.ElementCC3D("Energy", { "Type1": "Bacterium", "Type2": "Bacterium" }, 15) contact.ElementCC3D("Energy", { "Type1": "Bacterium", "Type2": "Macrophage" }, 15) contact.ElementCC3D("Energy", {"Type1": "Bacterium", "Type2": "Medium"}, 8) contact.ElementCC3D("Energy", {"Type1": "Wall", "Type2": "Wall"}, 0) contact.ElementCC3D("Energy", {"Type1": "Wall", "Type2": "Medium"}, 0) contact.ElementCC3D("Energy", {"Type1": "Wall", "Type2": "Bacterium"}, 50) contact.ElementCC3D("Energy", {"Type1": "Wall", "Type2": "Macrophage"}, 50) chemotaxis = cc3d.ElementCC3D("Plugin", {"Name": "Chemotaxis"}) chemicalField = chemotaxis.ElementCC3D("ChemicalField", { "Source": "DiffusionSolverFE", "Name": "ATTR" }) chemicalField.ElementCC3D("ChemotaxisByType", { "Type": "Macrophage", "Lambda": 200 }) flexDiffSolver = cc3d.ElementCC3D("Steppable", {"Type": "DiffusionSolverFE"}) diffusionField = flexDiffSolver.ElementCC3D("DiffusionField") diffusionData = diffusionField.ElementCC3D("DiffusionData") diffusionData.ElementCC3D("FieldName", {}, "ATTR") diffusionData.ElementCC3D("DiffusionConstant", {}, 0.10) diffusionData.ElementCC3D("DecayConstant", {}, 0.0) diffusionData.ElementCC3D("DoNotDiffuseTo", {}, "Wall") secretionData = diffusionField.ElementCC3D("SecretionData") secretionData.ElementCC3D("Secretion", {"Type": "Bacterium"}, 200) pifInitializer = cc3d.ElementCC3D("Steppable", {"Type": "PIFInitializer"}) pifInitializer.ElementCC3D("PIFName", {}, "Simulation/bacterium_macrophage_2D_wall.piff") CompuCellSetup.setSimulationXMLDescription(cc3d)
def configure_simulation(): from cc3d.core.XMLUtils import ElementCC3D from numpy import sqrt as nsqrt CompuCell3DElmnt = ElementCC3D("CompuCell3D", { "Revision": "20190906", "Version": "4.1.0" }) MetadataElmnt = CompuCell3DElmnt.ElementCC3D("Metadata") # Basic properties simulation MetadataElmnt.ElementCC3D("NumberOfProcessors", {}, "1") MetadataElmnt.ElementCC3D("DebugOutputFrequency", {}, "100") # MetadataElmnt.ElementCC3D("NonParallelModule",{"Name":"Potts"}) PottsElmnt = CompuCell3DElmnt.ElementCC3D("Potts") # Basic properties of CPM (GGH) algorithm PottsElmnt.ElementCC3D("Dimensions", {"x": "256", "y": "256", "z": "1"}) PottsElmnt.ElementCC3D("Steps", {}, "10001") PottsElmnt.ElementCC3D("Temperature", {}, "10.0") PottsElmnt.ElementCC3D("NeighborOrder", {}, str(G_interact_range_G)) PluginElmnt = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "CellType"}) # Listing all cell types in the simulation PluginElmnt.ElementCC3D("CellType", {"TypeId": "0", "TypeName": "Medium"}) PluginElmnt.ElementCC3D("CellType", {"TypeId": "1", "TypeName": "dark"}) PluginElmnt.ElementCC3D("CellType", {"TypeId": "2", "TypeName": "light"}) # PluginElmnt_1=CompuCell3DElmnt.ElementCC3D("Plugin",{"Name":"Volume"}) # PluginElmnt_1.ElementCC3D("VolumeEnergyParameters",{"CellType":"dark","LambdaVolume":"2.0","TargetVolume":"50"}) # PluginElmnt_1.ElementCC3D("VolumeEnergyParameters",{"CellType":"light","LambdaVolume":"2.0","TargetVolume":"50"}) PluginElmnt_1 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Volume"}) PluginElmnt_1.ElementCC3D( "VolumeEnergyParameters", { "CellType": "dark", "LambdaVolume": str(G_lambdaVol_dark_G), "TargetVolume": str(G_targetVol_dark_G) }) PluginElmnt_1.ElementCC3D( "VolumeEnergyParameters", { "CellType": "light", "LambdaVolume": str(G_lambdaVol_light_G), "TargetVolume": str(G_targetVol_light_G) }) PluginElmnt_2 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "CenterOfMass"}) PluginElmnt_4 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "NeighborTracker"}) # Module tracking center of mass of each cell PluginElmnt_3 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Contact"}) # Specification of adhesion energies # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"Medium","Type2":"Medium"},"10.0") # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"Medium","Type2":"dark"},"10.0") # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"Medium","Type2":"light"},"10.0") # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"dark","Type2":"dark"},"10.0") # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"dark","Type2":"light"},"10.0") # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"light","Type2":"light"},"10.0") # PluginElmnt_3.ElementCC3D("NeighborOrder",{},"4") PluginElmnt_3.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "Medium" }, "10.0") PluginElmnt_3.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "dark" }, str(G_J_dm_G)) PluginElmnt_3.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "light" }, str(G_J_lm_G)) PluginElmnt_3.ElementCC3D("Energy", { "Type1": "dark", "Type2": "dark" }, str(G_J_dd_G)) PluginElmnt_3.ElementCC3D("Energy", { "Type1": "dark", "Type2": "light" }, str(G_J_dl_G)) PluginElmnt_3.ElementCC3D("Energy", { "Type1": "light", "Type2": "light" }, str(G_J_ll_G)) PluginElmnt_3.ElementCC3D("NeighborOrder", {}, str(G_interact_range_G)) SteppableElmnt = CompuCell3DElmnt.ElementCC3D("Steppable", {"Type": "BlobInitializer"}) # Initial layout of cells in the form of spherical (circular in 2D) blob RegionElmnt = SteppableElmnt.ElementCC3D("Region") # RegionElmnt.ElementCC3D("Center",{"x":"128","y":"128","z":"0"}) # RegionElmnt.ElementCC3D("Radius",{},"51") # RegionElmnt.ElementCC3D("Gap",{},"0") # RegionElmnt.ElementCC3D("Width",{},"7") # RegionElmnt.ElementCC3D("Types",{},"dark,light") RegionElmnt.ElementCC3D("Center", {"x": "128", "y": "128", "z": "0"}) RegionElmnt.ElementCC3D("Radius", {}, "112") RegionElmnt.ElementCC3D("Gap", {}, "0") RegionElmnt.ElementCC3D( "Width", {}, str(int(round(nsqrt(G_targetVol_light_G)))) ) #this way they will be about the right size to begin with RegionElmnt.ElementCC3D("Types", {}, "dark,light") CompuCellSetup.setSimulationXMLDescription(CompuCell3DElmnt) CompuCellSetup.setSimulationXMLDescription(CompuCell3DElmnt)
def write_xml_description_file(self, file_name: str = "") -> None: """ This function will write XML description of the stored fields. It has to be called after initialization of theCMLFieldHandler is completed :param file_name: :return: """ persistent_globals = cc3d.CompuCellSetup.persistent_globals simulator = persistent_globals.simulator lattice_type_str = extract_lattice_type() if lattice_type_str == '': lattice_type_str = 'Square' type_id_type_name_dict = extract_type_names_and_ids() dim = simulator.getPotts().getCellFieldG().getDim() number_of_steps = simulator.getNumSteps() lattice_data_xml_element = ElementCC3D("CompuCell3DLatticeData", {"Version": "1.0"}) lattice_data_xml_element.ElementCC3D("Dimensions", { "x": str(dim.x), "y": str(dim.y), "z": str(dim.z) }) lattice_data_xml_element.ElementCC3D("Lattice", {"Type": lattice_type_str}) lattice_data_xml_element.ElementCC3D( "Output", { "Frequency": str(self.output_freq), "NumberOfSteps": str(number_of_steps), "CoreFileName": self.output_file_core_name, "Directory": self.output_dir_name }) # output information about cell type names and cell ids. # It is necessary during generation of the PIF files from VTK output for typeId in type_id_type_name_dict.keys(): lattice_data_xml_element.ElementCC3D( "CellType", { "TypeName": str(type_id_type_name_dict[typeId]), "TypeId": str(typeId) }) fields_xml_element = lattice_data_xml_element.ElementCC3D("Fields") for fieldName in self.field_types.keys(): fields_xml_element.ElementCC3D("Field", { "Name": fieldName, "Type": self.field_types[fieldName] }) # writing XML description to the disk if file_name != "": lattice_data_xml_element.CC3DXMLElement.saveXML(str(file_name)) else: lattice_data_file_name = join( self.output_dir_name, self.output_file_core_name + "LDF.dml") lattice_data_xml_element.CC3DXMLElement.saveXML( str(lattice_data_file_name))
def generateNewProject(self): directory = str(self.dirLE.text()).strip() directory = os.path.abspath(directory) name = str(self.nameLE.text()).strip() self.makeProjectDirectories(directory, name) self.generalPropertiesDict = {} self.generalPropertiesDict["Dim"] = [self.xDimSB.value(), self.yDimSB.value(), self.zDimSB.value()] self.generalPropertiesDict["MembraneFluctuations"] = float(str(self.membraneFluctuationsLE.text())) self.generalPropertiesDict["NeighborOrder"] = self.neighborOrderSB.value() self.generalPropertiesDict["MCS"] = self.mcsSB.value() self.generalPropertiesDict["LatticeType"] = str(self.latticeTypeCB.currentText()) self.generalPropertiesDict["SimulationName"] = name self.generalPropertiesDict["BoundaryConditions"] = OrderedDict() self.generalPropertiesDict["BoundaryConditions"]['x'] = self.xbcCB.currentText() self.generalPropertiesDict["BoundaryConditions"]['y'] = self.ybcCB.currentText() self.generalPropertiesDict["BoundaryConditions"]['z'] = self.zbcCB.currentText() self.generalPropertiesDict["Initializer"] = ["uniform", None] if self.blobRB.isChecked(): self.generalPropertiesDict["Initializer"] = ["blob", None] elif self.piffRB.isChecked(): piff_path = str(self.piffLE.text()).strip() self.generalPropertiesDict["Initializer"] = ["piff", piff_path] # trying to copy piff file into simulation dir of the project directory try: shutil.copy(piff_path, self.simulationFilesDir) base_piff_path = os.path.basename(piff_path) relative_piff_path = os.path.join(self.simulationFilesDir, base_piff_path) self.generalPropertiesDict["Initializer"][1] = self.getRelativePathWRTProjectDir(relative_piff_path) print("relativePathOF PIFF=", self.generalPropertiesDict["Initializer"][1]) except shutil.Error: QMessageBox.warning(self, "Cannot copy PIFF file", "Cannot copy PIFF file into project directory. " "Please check if the file exists and that you have necessary write permissions", QMessageBox.Ok) except IOError as e: QMessageBox.warning(self, "IO Error", e.__str__(), QMessageBox.Ok) self.cellTypeData = {} # extract cell type information form the table for row in range(self.cellTypeTable.rowCount()): cell_type = str(self.cellTypeTable.item(row, 0).text()) freeze = False if self.cellTypeTable.item(row, 1).checkState() == Qt.Checked: print("self.cellTypeTable.item(row,1).checkState()=", self.cellTypeTable.item(row, 1).checkState()) freeze = True self.cellTypeData[row] = [cell_type, freeze] self.af_data = {} for row in range(self.afTable.rowCount()): molecule = str(self.afTable.item(row, 0).text()) self.af_data[row] = molecule self.af_formula = str(self.bindingFormulaLE.text()).strip() cmc_table = [] for row in range(self.cmcTable.rowCount()): cadherin = str(self.cmcTable.item(row, 0).text()) cmc_table.append(cadherin) self.pde_field_data = {} for row in range(self.fieldTable.rowCount()): chem_field_name = str(self.fieldTable.item(row, 0).text()) solver_name = str(self.fieldTable.item(row, 1).text()) self.pde_field_data[chem_field_name] = solver_name self.secretion_data = {} # format {field:[secrDict1,secrDict2,...]} for row in range(self.secretionTable.rowCount()): secr_field_name = str(self.secretionTable.item(row, 0).text()) cell_type = str(self.secretionTable.item(row, 1).text()) try: rate = float(str(self.secretionTable.item(row, 2).text())) except Exception: rate = 0.0 on_contact_with = str(self.secretionTable.item(row, 3).text()) secretion_type = str(self.secretionTable.item(row, 4).text()) secr_dict = {} secr_dict["CellType"] = cell_type secr_dict["Rate"] = rate secr_dict["OnContactWith"] = on_contact_with secr_dict["SecretionType"] = secretion_type try: self.secretion_data[secr_field_name].append(secr_dict) except LookupError: self.secretion_data[secr_field_name] = [secr_dict] self.chemotaxisData = {} # format {field:[chemDict1,chemDict2,...]} for row in range(self.chamotaxisTable.rowCount()): chem_field_name = str(self.chamotaxisTable.item(row, 0).text()) cell_type = str(self.chamotaxisTable.item(row, 1).text()) try: lambda_ = float(str(self.chamotaxisTable.item(row, 2).text())) except Exception: lambda_ = 0.0 chemotax_towards = str(self.chamotaxisTable.item(row, 3).text()) try: sat_coef = float(str(self.chamotaxisTable.item(row, 4).text())) except Exception: sat_coef = 0.0 chemotaxis_type = str(self.chamotaxisTable.item(row, 5).text()) chem_dict = {} chem_dict["CellType"] = cell_type chem_dict["Lambda"] = lambda_ chem_dict["ChemotaxTowards"] = chemotax_towards chem_dict["SatCoef"] = sat_coef chem_dict["ChemotaxisType"] = chemotaxis_type try: self.chemotaxisData[chem_field_name].append(chem_dict) except LookupError: self.chemotaxisData[chem_field_name] = [chem_dict] # constructing Project XMl Element simulation_element = ElementCC3D("Simulation", {"version": cc3d.__version__}) xml_generator = CC3DMLGeneratorBase(self.simulationFilesDir, name) self.generateXML(xml_generator) # end of generate XML ------------------------------------------------------------------------------------ if self.pythonXMLRB.isChecked(): xml_file_name = os.path.join(self.simulationFilesDir, name + ".xml") xml_generator.saveCC3DXML(xml_file_name) simulation_element.ElementCC3D("XMLScript", {"Type": "XMLScript"}, self.getRelativePathWRTProjectDir(xml_file_name)) # end of generate XML ------------------------------------------------------------------------------------ if self.pythonXMLRB.isChecked() or self.pythonOnlyRB.isChecked(): # generate Python ------------------------------------------------------------------------------------ python_generator = CC3DPythonGenerator(xml_generator) python_generator.set_python_only_flag(self.pythonOnlyRB.isChecked()) self.generateSteppablesCode(python_generator) # before calling generateMainPythonScript we have to call generateSteppablesCode # that generates also steppable registration lines python_generator.generate_main_python_script() simulation_element.ElementCC3D("PythonScript", {"Type": "PythonScript"}, self.getRelativePathWRTProjectDir(python_generator.mainPythonFileName)) simulation_element.ElementCC3D("Resource", {"Type": "Python"}, self.getRelativePathWRTProjectDir(python_generator.steppablesPythonFileName)) # end of generate Python --------------------------------------------------------------------------------- # including PIFFile in the .cc3d project description if self.generalPropertiesDict["Initializer"][0] == "piff": simulation_element.ElementCC3D("PIFFile", {}, self.generalPropertiesDict["Initializer"][1]) # save Project file proj_file_name = os.path.join(self.mainProjDir, name + ".cc3d") # simulationElement.CC3DXMLElement.saveXML(projFileName) proj_file = open(proj_file_name, 'w') proj_file.write('%s' % simulation_element.CC3DXMLElement.getCC3DXMLElementString()) proj_file.close() # open newly created project in the ProjectEditor self.plugin.openCC3Dproject(proj_file_name)
def configure_simulation(): import pandas as pd variables_file_path = r'C:/CompuCell3D-py3-64bit/lib/site-packages/ProtocellSimulator/ProtoCellularSim/variables.csv' variables = pd.read_csv(variables_file_path) cell_diam = variables['Value'][variables['Name'] == 'cell diam'].values[0] # actuate_scale = variables['Value'][variables['Name'] == 'actuate scale'] # actuate_period = None # num_active_types = variables['Value'][variables['Name'] == 'num active types'] max_mcs = variables['Value'][variables['Name'] == 'max mcs'].values[0] work_nodes = variables['Value'][variables['Name'] == 'work nodes'].values[0] sim_dim = variables['Value'][variables['Name'] == 'sim dim'].values[0] from cc3d.core.XMLUtils import ElementCC3D CompuCell3DElmnt = ElementCC3D("CompuCell3D", { "Revision": "20200518", "Version": "4.2.1" }) MetadataElmnt = CompuCell3DElmnt.ElementCC3D("Metadata") MetadataElmnt.ElementCC3D("NumberOfProcessors", {}, str(work_nodes)) # str(work_nodes) MetadataElmnt.ElementCC3D("DebugOutputFrequency", {}, "10") PottsElmnt = CompuCell3DElmnt.ElementCC3D("Potts") PottsElmnt.ElementCC3D("Dimensions", { "x": str(sim_dim), "y": str(sim_dim), "z": "1" }) PottsElmnt.ElementCC3D("Steps", {}, str(max_mcs)) PottsElmnt.ElementCC3D("Temperature", {}, "3.0") PottsElmnt.ElementCC3D("NeighborOrder", {}, "1") PottsElmnt.ElementCC3D("Boundary_x", {}, "NoFlux") # Periodic PottsElmnt.ElementCC3D("Boundary_y", {}, "NoFlux") # Periodic PluginElmnt = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "CellType"}) PluginElmnt.ElementCC3D("CellType", {"TypeId": "0", "TypeName": "Medium"}) PluginElmnt.ElementCC3D("CellType", { "Freeze": "", "TypeId": "1", "TypeName": "Wall" }) PluginElmnt.ElementCC3D("CellType", { "TypeId": "2", "TypeName": "Protocell" }) PluginElmnt.ElementCC3D("CellType", { "TypeId": "3", "TypeName": "ProtocellPassive" }) PluginElmnt.ElementCC3D("CellType", { "TypeId": "4", "TypeName": "ProtocellActiveA" }) PluginElmnt.ElementCC3D("CellType", { "TypeId": "5", "TypeName": "ProtocellActiveB" }) CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Volume"}) CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Surface"}) PluginElmnt_1 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "ExternalPotential"}) PluginElmnt_1.ElementCC3D("Algorithm", {"id": "Ext Pot Alg"}, "PixelBased") CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "CenterOfMass"}) CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "NeighborTracker"}) CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "PixelTracker"}) PluginElmnt_2 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Contact"}) PluginElmnt_2.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "Medium" }, "0.0") PluginElmnt_2.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "Wall" }, "0.0") PluginElmnt_2.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "Protocell" }, "50.0") #20 PluginElmnt_2.ElementCC3D("Energy", { "Type1": "Wall", "Type2": "Wall" }, "10.0") PluginElmnt_2.ElementCC3D("Energy", { "Type1": "Wall", "Type2": "Protocell" }, "30.0") PluginElmnt_2.ElementCC3D("Energy", { "Type1": "Protocell", "Type2": "Protocell" }, "200.0") #50 PluginElmnt_2.ElementCC3D("NeighborOrder", {}, "1") # 2 PluginElmnt_3 = CompuCell3DElmnt.ElementCC3D( "Plugin", {"Name": "FocalPointPlasticity"}) PluginElmnt_3.ElementCC3D("Local") ParametersElmnt = PluginElmnt_3.ElementCC3D("Parameters", { "Type1": "Protocell", "Type2": "Protocell" }) ParametersElmnt.ElementCC3D("Lambda", {}, "500") #100 ParametersElmnt.ElementCC3D("ActivationEnergy", {"id": "link energy"}, "-0") ParametersElmnt.ElementCC3D("TargetDistance", {"id": "protocell diameter"}, str(cell_diam)) ParametersElmnt.ElementCC3D("MaxDistance", {}, "100") ParametersElmnt.ElementCC3D("MaxNumberOfJunctions", {}, "10") PluginElmnt_3.ElementCC3D("NeighborOrder", {}, "1") CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "LengthConstraint"}) PluginElmnt_4 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Connectivity"}) PluginElmnt_4.ElementCC3D("Penalty", {}, "100000") CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Secretion"}) SteppableElmnt = CompuCell3DElmnt.ElementCC3D("Steppable", {"Type": "PIFInitializer"}) SteppableElmnt.ElementCC3D("PIFName", {}, "init_cell_field.piff") CompuCellSetup.setSimulationXMLDescription(CompuCell3DElmnt)
from cc3d.twedit5.twedit.utils.global_imports import *
import errno