def main(): elements = Elements() fault_tolerance = 0 random.seed() probability3 = 0 probability4 = 0 # calculation in case of 1, 2 faults for i in range(1, 3): for j in itertools.combinations(elements.elements.keys(), i): if not elements.generate_vector(j): fault_tolerance += elements.probability # calculation in case of 3 faults (combinations without repetition - 680) max_3faults = 1539 for i in range(int(1540 / 2) + 1): rdm = random.randint(0, max_3faults - i) if not elements.generate_vector_by_index(rdm, 3): probability3 += elements.probability # calculation in case of 4 faults (combinations without repetition - 1428) max_4faults = 7314 for i in range(int(max_4faults / 10) + 1): rdm = random.randint(0, max_4faults - i) if not elements.generate_vector_by_index(rdm, 4): probability4 += elements.probability fault_tolerance += probability3 * 2 fault_tolerance += probability4 * 10 print("%.11f" % fault_tolerance) for i, k in sorted(elements.faults_statistic.items(), key=lambda x: x[1]): print(i, k)
def parse(self, mechanism, file): # Reset the token counts import pyre import fuego import journal from fuego.serialization.chemkin.unpickle.tokens.Token import Token Token._constructed = 0 Token._destructed = 0 self._mechanism = mechanism # prepare the parsing machinery scanner = fuego.serialization.chemkin.unpickle.scanners.sections() tokenizer = pyre.parsing.tokenizer(file) tokenizer._info = journal.debug("fuego") # section parsers from Elements import Elements self._elementParser = Elements(mechanism, tokenizer) from Species import Species self._speciesParser = Species(mechanism, tokenizer) from Thermo import Thermo self._thermoParser = Thermo(mechanism, tokenizer) from Reactions import Reactions self._reactionParser = Reactions(mechanism, tokenizer) # enter the parsing loop return BaseParser.parse(self, scanner, tokenizer)
def __init__(self, element_num, lattice_size): self.param = {} # default settings of the lattice # TODO finish the load param function #self.param = load_param(config_path) self.element_num = element_num self.lattice_size = lattice_size self.mol = Elements(self.element_num, 'TPyP') self.step_counter = 0
def __init__(self, element_num, lattice_size): self.param = {} # default settings of the lattice # TODO finish the load param function #self.param = load_param(config_path) self.element_num = element_num self.lattice_size = lattice_size self.mol = Elements(self.element_num,'TPyP') self.step_counter = 0
class Group(DoxTool): # reads groups and namespaces, equivalently def readXML(self, refid, filename, store): self.refid = refid self.store = store self.path = os.path.dirname(filename).replace(os.sep, "/") baum = ElementTree.parse(filename) ind = baum.getroot() self.el = Elements(self.store) # find class refid for cpdef in ind.getchildren(): cpname = cpdef.find("compoundname").text if cpdef.attrib["id"] == refid: # now we are in the right compound, search for sectiondefs for sdef in cpdef.findall("sectiondef"): skind = sdef.attrib["kind"] if skind == "enum": self.el.addEnum(sdef, cpname) elif skind == "typedef": self.el.addTypedef(sdef) elif skind == "func": self.el.addFunction(sdef)
class Helpers(unittest.TestCase): element = Elements() util = WebdriverUtilities() #driver = webdriver.Firefox() def setUtils(self,util): self.util = util def runTest(self): pass def GetTimeId(self): return strftime("_%Y_%m_%d_%H_%M_%S") def Login(self): self.assertTrue(self.util.isElementPresent(self.element.login_button), "can't see the login button") self.util.clickOnAndWaitFor(self.element.login_button, self.element.gmail_password_textfield) self.assertTrue(self.util.isElementPresent(self.element.gmail_password_textfield), "can't see the password textfield") self.util.inputTextIntoField(config.username, self.element.gmail_userid_textfield) self.assertTrue(self.util.isElementPresent(self.element.gmail_userid_textfield), "can't see the userid textfield") self.util.inputTextIntoField(config.password, self.element.gmail_password_textfield) self.util.clickOnAndWaitFor(self.element.gmail_submit_credentials_button, self.element.dashboard_title) def WaitForLeftNavToLoad(self): # temporary method that waits for the '...) to be replaced with numbers self.util.waitForElementNotToBePresent(self.element.left_nav_governance_controls_numbers_not_loaded) self.util.waitForElementNotToBePresent(self.element.left_nav_governance_contracts_numbers_not_loaded) self.util.waitForElementNotToBePresent(self.element.left_nav_governance_policies_numbers_not_loaded) self.util.waitForElementNotToBePresent(self.element.left_nav_governance_regulations_numbers_not_loaded) self.util.scroll() #temporary workaround to refresh the page which will make the title appear (known bug) def GenerateNameForTheObject(self,grc_object): random_number= self.GetTimeId() name = grc_object + "-auto-test"+random_number return name def ExpandLeftNavMenuForObject(self, grc_object): object_left_nav_section_object_link = self.element.left_nav_expand_object_section_link.replace("OBJECT", grc_object) object_left_nav_section_object_add_button = self.element.left_nav_object_section_add_button.replace("OBJECT", grc_object) #self.util.clickOnAndWaitFor(object_left_nav_section_object_link, object_left_nav_section_object_add_button) #self.util.clickOn(object_left_nav_section_object_link) #self.util.waitForElementToBeClickable(object_left_nav_section_object_link) self.util.waitForElementToBeVisible(object_left_nav_section_object_link) self.util.clickOn(object_left_nav_section_object_link) self.util.waitForElementToBeVisible(object_left_nav_section_object_add_button) #self.util.waitForElementToBeClickable(object_left_nav_section_object_add_button) def CreateObject(self, grc_object): self.assertTrue(self.util.isElementPresent(self.element.dashboard_title), "no dashboard page found") grc_object_name = self.GenerateNameForTheObject(grc_object) self.OpenCreateNewObjectWindow(grc_object) self.PopulateNewObjectData(grc_object_name) self.SaveObjectData() last_created_object_link = self.VerifyObjectIsCreated(grc_object, grc_object_name) return last_created_object_link def OpenCreateNewObjectWindow(self, grc_object): object_left_nav_section_object_link = self.element.left_nav_expand_object_section_link.replace("OBJECT", grc_object) object_left_nav_section_object_add_button = self.element.left_nav_object_section_add_button.replace("OBJECT", grc_object) self.util.waitForElementToBePresent(object_left_nav_section_object_link) self.assertTrue(self.util.isElementPresent(object_left_nav_section_object_link), "can't click on the object left nav link") self.util.clickOn(object_left_nav_section_object_link) self.util.waitForElementToBePresent(object_left_nav_section_object_add_button) self.assertTrue(self.util.isElementPresent(object_left_nav_section_object_add_button), "can't click on CreateNew link") #self.util.clickOnAndWaitFor(object_left_nav_section_object_link, object_left_nav_section_object_add_button) self.util.clickOn(object_left_nav_section_object_add_button) def PopulateNewObjectData(self, object_title): # Make sure window is there self.util.waitForElementToBeVisible(self.element.modal_window) #self.assertTrue(self.util.isElementPresent(self.element.modal), "can't see the modal body") # Populate title self.util.waitForElementToBeVisible(self.element.modal_window_title_textfield) self.assertTrue(self.util.isElementPresent(self.element.modal_window_title_textfield), "can't access the input textfield") self.util.inputTextIntoField(object_title, self.element.modal_window_title_textfield) self.util.inputTextIntoField("", self.element.modal_window_owner_textfield) #need this click to activate Save button # Populate Description #self.util.typeIntoFrame("description-"+object_title) def SaveObjectData(self): #self.util.inputTextIntoField("*****@*****.**", self.element.modal_owner_textfield) #need this click to activate Save button self.assertTrue(self.util.isElementPresent(self.element.modal_window_save_button), "do not see the Save button") self.util.clickOnSave(self.element.modal_window_save_button) self.util.waitForElementNotToBePresent(self.element.modal_window) self.WaitForLeftNavToLoad() def closeAndOpenObjectSection(self, link): self.util.clickOn(link) self.util.clickOn(link) def VerifyObjectIsCreated(self, widget, object_title): #this helper method is generic for any type # Refresh the page self.util.refreshPage() # Wait for the object section link to appear in the left nav (e.g. Programs, Products, Policies, etc.) object_left_nav_section_object_link = self.element.left_nav_expand_object_section_link.replace("OBJECT", widget) self.util.waitForElementToBePresent(object_left_nav_section_object_link) # Click on the object section link in the left nav self.util.clickOn(object_left_nav_section_object_link) # Wait for the newly-created object link to appear in the left nav (e.g. System-auto-test_2013_08_25_13_47_50) last_created_object_link = self.element.left_nav_last_created_object_link.replace("SECTION", widget).replace("OBJECT_TITLE", object_title) self.util.waitForElementToBePresent(last_created_object_link) self.assertTrue(self.util.isElementPresent(last_created_object_link), "do not see the newly created object in " + widget) #self.closeAndOpenObjectSection(object_left_nav_section_object_link) return last_created_object_link def NavigateToObjectAndOpenObjectEditWindow(self,widget,object_title_link): # Refresh the page self.util.refreshPage() # Wait for the object section link to appear in the left nav (e.g. Programs, Products, Policies, etc.) object_left_nav_section_object_link = self.element.left_nav_expand_object_section_link.replace("OBJECT", widget) self.util.waitForElementToBePresent(object_left_nav_section_object_link) # Click on the object section link in the left nav self.util.clickOn(object_left_nav_section_object_link) # Wait for the newly-edited object link to appear, then click on it self.util.waitForElementToBePresent(object_title_link) self.assertTrue(self.util.isElementPresent(object_title_link), "do not see the just edited object link " ) self.util.clickOn(object_title_link) # Wait for the object detail page info section on the right side to appear, then hover over it to enable the Edit button self.util.waitForElementToBePresent(self.element.object_detail_page_info_section) self.assertTrue(self.util.isElementPresent(self.element.object_detail_page_info_section), "do not see object info section") self.util.hoverOver(self.element.object_detail_page_info_section) # Wait for the Edit button in the object detail page info section, then click on it self.util.waitForElementToBePresent(self.element.object_info_page_edit_link) self.assertTrue(self.util.isElementPresent(self.element.object_info_page_edit_link), "do not see the Edit button") self.util.clickOn(self.element.object_info_page_edit_link) # Wait for the modal window to appear status=self.util.waitForElementToBePresent(self.element.modal_window) self.assertTrue(status,"Modal window does not become visible") # Wait for the field object title to appear self.util.waitForElementToBePresent(self.element.object_title) self.assertTrue(self.util.isElementPresent(self.element.object_title), "do not see field [title] in the edit window") def OpenObjectEditWindow(self): self.util.hoverOver(self.element.object_detail_page_info_section) self.util.waitForElementToBePresent(self.element.object_info_page_edit_link) self.assertTrue(self.util.isElementPresent(self.element.object_info_page_edit_link), "do not see the Edit button") self.util.clickOn(self.element.object_info_page_edit_link) self.util.waitForElementToBePresent(self.element.modal_window) self.util.waitForElementToBePresent(self.element.object_title) self.assertTrue(self.util.isElementPresent(self.element.object_title), "do not see object_title in the edit window") def ShowHiddenValues(self): self.util.clickOnAndWaitFor(self.element.modal_window_show_hidden_fields_link, self.element.object_code) def PopulateObjectInEditWindow(self, name, grcobject_elements,grcobject_values ): self.util.waitForElementToBeVisible(self.element.object_title) self.ShowHiddenValues() for key,xpath in grcobject_elements.iteritems(): #print key, xpath , grcobject_values[key] self.util.waitForElementToBeVisible(xpath) if key == "kind": option = self.util.getTextFromXpathString(self.element.object_kind + "/option[" + str(grcobject_values[key]) + "]") self.selectFromDropdownOption(self.element.object_kind, grcobject_values[key]) grcobject_values[key]=option if key=="code": grcobject_values[key] = self.util.getAnyAttribute(self.element.object_code, "value") + "_edited" self.util.inputTextIntoField(grcobject_values[key] ,xpath) if key == "title": grcobject_values[key] = name + "_edited" self.util.inputTextIntoField(grcobject_values[key] ,xpath) if key == "owner": grcobject_values[key] = "*****@*****.**" self.util.inputTextIntoField(grcobject_values[key] ,xpath) if key == "description": grcobject_values[key]=key+"_"+name+ "_edited" self.util.typeIntoFrame(grcobject_values[key], self.element.modal_window_description_frame) if key=="url": grcobject_values[key] = "http://www.google.com" self.util.inputTextIntoField(grcobject_values[key] ,xpath) self.util.inputTextIntoField("*****@*****.**" , self.element.modal_window_owner_textfield) self.assertTrue(self.util.isElementPresent(self.element.modal_window_save_button), "do not see the Save button") self.util.waitForElementToBeVisible(self.element.modal_window_save_button) # hack for make the Save button clickable self.SaveObjectData() def selectFromDropdownOption(self,select_element,option_number): self.assertTrue(self.util.isElementPresent(select_element), "do not see the dropdown") self.util.waitForElementToBeVisible(select_element) option_to_be_selected = self.util.getTextFromXpathString(select_element + "/option[" + str(option_number) + "]") #print option_to_be_selected self.util.selectFromDropdownUntilSelected(select_element, option_to_be_selected) time.sleep(3) def verifyObjectValues(self, grcobject_elements,grcobject_values): for key,xpath in grcobject_elements.iteritems(): #print "Inside verifyObjectValues, key=" + key + ", value="+grcobject_values[key] if key == "description": new_value = self.util.getTextFromFrame(self.element.modal_window_description_frame) #print "new_value for description=" + new_value #print "the value for description initially is " + grcobject_values[key] self.assertTrue(new_value == grcobject_values[key], "Verification ERROR: the value of " + key + " should be " + grcobject_values[key] + " but it is " + new_value ) elif key == "kind": self.util.waitForElementToBePresent(self.element.object_kind) self.util.waitForElementToBePresent(self.element.object_kind_selected_option) self.util.waitForElementValueToBePresent(self.element.object_kind_selected_option) new_value = self.util.getTextFromXpathString(self.element.object_kind_selected_option) self.assertTrue(new_value == grcobject_values[key], "Verification ERROR: the value of " + key + " should be " + grcobject_values[key] + " but it is " + new_value ) else: new_value = self.util.getAnyAttribute(xpath, "value") #print "new_value="+new_value self.assertTrue(new_value == grcobject_values[key], "Verification ERROR: the value of " + key + " should be " + grcobject_values[key] + " but it is " + new_value ) print "Verification OK: the value of " + key + " is "+grcobject_values[key] +", as expected." def deleteObject(self): self.assertTrue(self.util.isElementPresent(self.element.modal_window_delete_button), "ERROR in deleteObject(): Can not see the Delete button") status=self.util.clickOn(self.element.modal_window_delete_button) self.assertTrue(status, "ERROR in deleteObject(): Could not click on "+self.element.modal_window_delete_button) status=self.util.waitForElementToBePresent(self.element.modal_window_confirm_delete_button) self.assertTrue(status, "ERROR in deleteObject(): Could not find "+ self.element.modal_window_confirm_delete_button) self.assertTrue(self.util.isElementPresent(self.element.modal_window_confirm_delete_button), "Can not see the Confirm Delete button") status=self.util.clickOn(self.element.modal_window_confirm_delete_button) self.assertTrue(status, "ERROR in deleteObject(): Could not click on "+self.element.modal_window_confirm_delete_button) status=self.util.waitForElementNotToBePresent(self.element.modal_window) self.assertTrue(status, "ERROR in deleteObject(): Modal window " + self.element.modal_window + " is still present")
def elements(): from Elements import Elements return Elements()
else: energies[i] = energy_temp energy = energies.sum() return True, energy def fit_energy(conf, energy_table): #print conf.shape #print conf assert len(conf.shape) < 2 #x_ind = (np.floor((conf[0,0] - energy_table.x_min)/energy_table.x_step)).astype(int) #y_ind = (np.floor((conf[0,1] - energy_table.y_min)/energy_table.y_step)).astype(int) x_ind = int(np.floor((conf[0] - energy_table.x_min) / energy_table.x_step)) y_ind = int(np.floor((conf[1] - energy_table.y_min) / energy_table.y_step)) #print conf[0,0],x_ind,conf[0,1],y_ind,energy_table.table[x_ind,y_ind] return energy_table.table[x_ind, y_ind] if __name__ == "__main__": elem = Elements(3, 'C') elem.num_init = 3 elem.conf[0, :] = [3, 3, 0, 0] elem.conf[1, :] = [2, 5, 0, 0] elem.conf[2, :] = [7, 7, 0, 0] print elem.conf conf_1 = np.array([[3, 4, 0]]) conf_2 = np.array([[3, 3, 0], [3, 6, 0]]) energy_table = EnergyTable('./etables/inter.txt') e = inter_energy(-1, 8, 8, 0, elem, energy_table) print e
class Controler(object): def __init__(self): self.vue = None self.element = Elements() def run(self): self.vue.run() ## # Open an Open File Popup Window and load the selected image into the canvas def cmdImage(self): self.vue.openImage() ## # Open a Save File Popup Window to save the drawing def cmdSave(self): print "save" def cmdCut(self): print "cut" ## # Funcao copiar def cmdCopy(self): print "copy" ## # Funcao Colar def cmdPaste(self): print "paste" ## # Funcao Pesquisar def cmdFind(self): print "find" ## # Funcao Pintura def cmdDrawing(self): self.vue.toggleButtons("drawing") self.vue.drawDrawing() ## # Funcao Elipse def cmdElipse(self): self.vue.toggleButtons("elipse") self.vue.drawElipse() ## # Funcao Line def cmdLine(self): self.vue.toggleButtons("line") self.vue.drawLine() ## # Funcao Painting def cmdPainting(self): self.vue.toggleButtons("painting") self.vue.drawPainting() ## # Funcao Rectangulo def cmdRectangle(self): self.vue.toggleButtons("rectangle") self.vue.drawRectangle() ## # Funcao Selecao def cmdSelection(self): self.vue.toggleButtons("selection") self.vue.drawSelection() ## # Funcao texto def cmdText(self): self.vue.toggleButtons("text") self.vue.drawText() ## # Defini branco como current color def white(self): self.vue.setCurrentColor('white') ## # Defini preto como current color def black(self): self.vue.setCurrentColor('black') ## # Defini vermelho como current color def red(self): self.vue.setCurrentColor('red') ## # Defini verde como current color def green(self): self.vue.setCurrentColor('green') ## # Defini azul como current color def blue(self): self.vue.setCurrentColor('blue') ## # Defini ciano como current color def cyan(self): self.vue.setCurrentColor('cyan') ## # Defini amarelo como current color def yellow(self): self.vue.setCurrentColor('yellow') ## # Defini magenta como current color def magenta(self): self.vue.setCurrentColor('magenta') ## # cria um elemento def saveRectangle(self,rectangle): self.element.saveElement(rectangle)
def readXML(self, refid, filename, store): self.attributes = [] self.methods = [] self.refid = refid self.store = store self.el = Elements(store) self.path = os.path.dirname(filename).replace(os.sep, "/") baum = ElementTree.parse(filename) ind = baum.getroot() # find class refid for cpdef in ind.getchildren(): if cpdef.attrib["id"] == refid: # add class parameters cl = self.store.createItem(self.className) cl.name = cpdef.find("compoundname").text cl.id = refid cl.protection = cpdef.attrib["prot"] cl.brief = self.getAllText(cpdef.find("briefdescription")) cl.detail = self.getAllText(cpdef.find("detaileddescription")) cl.methods = self.store.getNewUuid() cl.attributes = self.store.getNewUuid() # check for subclasses for bases in cpdef.findall("basecompoundref"): classref = self.store.createItem("ClassRef") if "refid" in bases.attrib.keys(): classref.parent = bases.attrib["refid"] classref.child = cl.id self.store.appendHierarchyItem(classref) else: print "no refid found in basecompoundref", cl.name # check for template tl = cpdef.find("templateparamlist") if tl != None: params = [] cl.flagtemplate = True cl.templateparameters = self.store.getNewUuid() for p in tl.findall("param"): newp = self.store.createItem("Templateparameter") n = p.find("declname") if n != None: newp.name = n.text newp.type = self.getText(p.find("type")) params.append(newp) if self.storeKey == "/classes": self.store.addClassTemplateParameters(cl.templateparameters, params) elif self.storeKey == "/structs": self.store.addStructTemplateParameters(cl.templateparameters, params) else: print "Wrong key:", self.storeKey else: cl.flagtemplate = False # add methods and attributes for sec in cpdef.findall("sectiondef"): # read section kindsec = sec.attrib["kind"] if kindsec in ["public-type", "protected-type", "private-type"]: # add types self.el.addType(sec, cl.name) elif kindsec in ["public-attrib", "protected-attrib", "private-attrib"]: # add attributes self.el.addAttributes(sec, self.attributes) elif kindsec in ["public-func", "protected-func", "private-func"]: # add functions self.el.addMethods(sec, self.methods, self.storeKey) elif kindsec in ["public-static-func", "protected-static-func", "private-static-func"]: # add static functions self.el.addMethods(sec, self.methods, self.storeKey) else: pass # print "unknown kind in DoxyParser.Class:",kindsec # store all in storage if self.storeKey == "/classes": self.store.addClass(cl, self.attributes, self.methods) elif self.storeKey == "/structs": self.store.addStruct(cl, self.attributes, self.methods) else: print "Wrong key:", self.storeKey
def __init__(self): self.vue = None self.element = Elements()
class ChemkinParser(BaseParser): # the main parsing loop def parse(self, mechanism, file): # Reset the token counts import pyre import fuego import journal from fuego.serialization.chemkin.unpickle.tokens.Token import Token #print "JE PARSE" Token._constructed = 0 Token._destructed = 0 self._mechanism = mechanism # prepare the parsing machinery scanner = fuego.serialization.chemkin.unpickle.scanners.sections() tokenizer = pyre.parsing.tokenizer(file) tokenizer._info = journal.debug("fuego") # section parsers from Elements import Elements self._elementParser = Elements(mechanism, tokenizer) from Species import Species self._speciesParser = Species(mechanism, tokenizer) from Thermo import Thermo self._thermoParser = Thermo(mechanism, tokenizer) #if doTrans/='n': from Trans import Trans self._transParser = Trans(mechanism, tokenizer) from Reactions import Reactions self._reactionParser = Reactions(mechanism, tokenizer) # enter the parsing loop return BaseParser.parse(self, scanner, tokenizer) # handlers for the section headers def anElementSection(self, token): return self._elementParser.anElementSection(token) def aSpeciesSection(self, token): return self._speciesParser.aSpeciesSection(token) def aThermoSection(self, token): return self._thermoParser.aThermoSection(token) def aTransSection(self, token): return self._transParser.aTransSection(token) def aReactionSection(self, token): return self._reactionParser.aReactionSection(token) # end-of-file handler def onEndOfFile(self): self._elementParser.onEndOfFile() self._speciesParser.onEndOfFile() self._thermoParser.onEndOfFile() #if doTrans/='n': self._transParser.onEndOfFile() self._reactionParser.onEndOfFile() return # others def printStatistics(self): print "Chemkin input file: '%s'" % self._filename print " Tokens: %d-%d" % (Token._constructed, Token._destructed) return def __init__(self): #print " J'INITIALISE PARSER ..." BaseParser.__init__(self) # the table of declared species self._species = {} # section parsers self._elementParser = None self._speciesParser = None self._thermoParser = None self._transParser = None self._reactionParser = None return def _printScanners(self): elements = self._elementParser._scanner._pattern() print "Element parser (%d): %s" % (len(elements), elements) species = self._speciesParser._scanner._pattern() print "Species parser (%d): %s" % (len(species), species) thermo = self._thermoParser._scanner._pattern() print "Thermo parser (%d): %s" % (len(thermo), thermo) #if doTrans/='n': trans = self._transParser._scanner._pattern() print "Trans parser (%d): %s" % (len(trans), trans) reaction = self._reactionParser._scanner._pattern() print "Reaction parser (%d): %s" % (len(reaction), reaction) return
key = str(int(typ)) + str(int(typ)) else: key = str(int(typ)) + str(int(conf[-1])) #print key energy_table = e_tables.get_energy_table(key) if conf[0] > energy_table.x_range or conf[1] > energy_table.y_range: return 0 #x_ind = (np.floor((conf[0,0] - energy_table.x_min)/energy_table.x_step)).astype(int) #y_ind = (np.floor((conf[0,1] - energy_table.y_min)/energy_table.y_step)).astype(int) x_ind = int(np.floor((conf[0] - energy_table.x_min)/energy_table.x_step)) y_ind = int(np.floor((conf[1] - energy_table.y_min)/energy_table.y_step)) #print conf[0,0],x_ind,conf[0,1],y_ind,energy_table.table[x_ind,y_ind] return energy_table.table[x_ind,y_ind] if __name__ == "__main__": elem = Elements(3,'C') elem.num_init = 3 elem.conf[0,:] = [3,3,0,1] elem.conf[1,:] = [2,5,0,1] elem.conf[2,:] = [7,7,0,1] print elem.conf conf_1 = np.array([[3,4,0]]) conf_2 = np.array([[3,3,0],[3,6,0]]) e_tables = EnergyTables() e_tables.load_energy_table('11','./etables/inter_mol.txt') e_tables.load_energy_table('12','./etables/inter_mol_metal.txt') e_tables.load_energy_table('21','./etables/inter_metal_mol.txt') e_tables.load_energy_table('22','./etables/inter_metal.txt') #print e_tables.get_energy_table['11'] e = inter_energy_multi(-1,8,8,0,1,elem,e_tables) print e
class Solver(): def __init__(self, element_num, lattice_size): self.param = {} # default settings of the lattice # TODO finish the load param function #self.param = load_param(config_path) self.element_num = element_num self.lattice_size = lattice_size self.mol = Elements(self.element_num,'TPyP') self.step_counter = 0 def init_single(self): self.element_settings = [self.element_num] while self.mol.num_init < self.mol.num: ind,x,y,theta = self.get_new_conf() state, energy = inter_energy(self.mol.num_init,x,y,theta,self.mol,self.energy_table) if state: self.mol.update(self.mol.num_init,x,y,0) self.mol.num_init = self.mol.num_init + 1 #print x,y,theta,self.mol.conf #print state, energy #self.show() else: continue def init_multi(self,setting = None): if setting: self.element_settings = setting self.element_type_num = len(setting) while self.mol.num_init < self.mol.num: for typ,num in enumerate(self.element_settings): print "type # %d has %d element" % (typ, num) i = 0 while i < num: ind,x,y,theta = self.get_new_conf() state, energy = inter_energy_multi(self.mol.num_init,x,y,theta,typ+1,self.mol,self.e_tables) if state: self.mol.update(self.mol.num_init,x,y,0,typ+1) self.mol.num_init = self.mol.num_init + 1 i = i + 1 #print x,y,theta,self.mol.conf #print state, energy #self.show() else: continue def step_single(self, step_num, SHOW_MODE=0): step_to_go = step_num hundredth = step_num/100 if step_num <= 0: print "step number should be positve integer" else: while step_to_go > 0: # pick a molecule and its new random position and angle ind,x,y,theta = self.get_new_conf() # get its old position and angle x_old,y_old,theta_old = self.mol.conf[ind,:3] # compute the energy of the old and new configuration, # respectively state_old, energy_old = inter_energy(ind,x_old,y_old,theta_old,self.mol,self.energy_table) state_new, energy_new = inter_energy(-1,x,y,theta,self.mol,self.energy_table) if state_new: p = min(math.exp(-(energy_new-energy_old)),1) if p > rd.random(): # TODO: finish the metropolis part self.mol.update(ind,x,y,theta,1) step_to_go = step_to_go - 1 if step_to_go%hundredth == 0: if step_to_go != step_num: print "%d / %d done" % (100-step_to_go/hundredth,100) def step_multi(self, step_num, SHOW_MODE=0): step_to_go = step_num hundredth = step_num/100 if step_num <= 0: print "step number should be positve integer" else: while step_to_go > 0: # pick a molecule and its new random position and angle ind,x,y,theta = self.get_new_conf() # get its old position and angle x_old,y_old,theta_old,typ_old = self.mol.conf[ind,:] # compute the energy of the old and new configuration, # respectively state_old, energy_old = inter_energy_multi(ind,x_old,y_old,theta_old,typ_old,self.mol,self.e_tables) state_new, energy_new = inter_energy_multi(-1,x,y,theta,typ_old,self.mol,self.e_tables) if state_new: p = min(math.exp(-(energy_new-energy_old)),1) if p > rd.random(): # TODO: finish the metropolis part self.mol.update(ind,x,y,theta) step_to_go = step_to_go - 1 if step_to_go%hundredth == 0: if step_to_go != step_num: print "%d / %d done" % (100-step_to_go/hundredth,100) def load_inter_map(self, inter_map_path): # load intermolecular interaction energy map self.energy_table = EnergyTable(inter_map_path) def load_inter_maps(self): self.e_tables = EnergyTables() def load_surf_map(self, surf_map_path): # load surface interaction energy map pass def get_new_conf(self,INIT=False): ind_mol = rd.randint(0,self.element_num-1) x = rd.randint(0,self.lattice_size-1) y = rd.randint(0,self.lattice_size-1) theta = 0 return ind_mol,x,y,theta def show(self): #x = [-1.5,-0.5,-0.5,0.5,0.5,1.5,1.5,0.5,0.5,-0.5,-0.5,-1.5,-1.5] #y = [0.5,0.5,1.5,1.5,0.5,0.5,-0.5,-0.5,-1.5,-1.5,-0.5,-0.5,0.5] #xy1 = list(zip(x,y)) marker_options = ['+','.','o','1'] for typ,num in enumerate(self.element_settings): print typ, num print self.mol.conf conf = self.mol.conf[self.mol.conf[:,-1] == typ + 1] print conf plt.scatter(conf[:,0],conf[:,1],s=500,c='r',marker=marker_options[typ],linewidth=4) plt.xticks(range(0,self.lattice_size)) plt.yticks(range(0,self.lattice_size)) plt.grid(True) plt.hold(True) plt.show() def write_conf(self,path_to_write): np.savetxt(path_to_write,self.mol.conf,fmt='%0.1d',delimiter=',')
class Solver(): def __init__(self, element_num, lattice_size): self.param = {} # default settings of the lattice # TODO finish the load param function #self.param = load_param(config_path) self.element_num = element_num self.lattice_size = lattice_size self.mol = Elements(self.element_num, 'TPyP') self.step_counter = 0 def init_single(self): self.element_settings = [self.element_num] while self.mol.num_init < self.mol.num: ind, x, y, theta = self.get_new_conf() state, energy = inter_energy(self.mol.num_init, x, y, theta, self.mol, self.energy_table) if state: self.mol.update(self.mol.num_init, x, y, 0) self.mol.num_init = self.mol.num_init + 1 #print x,y,theta,self.mol.conf #print state, energy #self.show() else: continue def init_multi(self, setting=None): if setting: self.element_settings = setting self.element_type_num = len(setting) while self.mol.num_init < self.mol.num: for typ, num in enumerate(self.element_settings): print "type # %d has %d element" % (typ, num) i = 0 while i < num: ind, x, y, theta = self.get_new_conf() state, energy = inter_energy_multi(self.mol.num_init, x, y, theta, typ + 1, self.mol, self.e_tables) if state: self.mol.update(self.mol.num_init, x, y, 0, typ + 1) self.mol.num_init = self.mol.num_init + 1 i = i + 1 #print x,y,theta,self.mol.conf #print state, energy #self.show() else: continue def step_single(self, step_num, SHOW_MODE=0): step_to_go = step_num hundredth = step_num / 100 if step_num <= 0: print "step number should be positve integer" else: while step_to_go > 0: # pick a molecule and its new random position and angle ind, x, y, theta = self.get_new_conf() # get its old position and angle x_old, y_old, theta_old = self.mol.conf[ind, :3] # compute the energy of the old and new configuration, # respectively state_old, energy_old = inter_energy(ind, x_old, y_old, theta_old, self.mol, self.energy_table) state_new, energy_new = inter_energy(-1, x, y, theta, self.mol, self.energy_table) if state_new: p = min(math.exp(-(energy_new - energy_old)), 1) if p > rd.random(): # TODO: finish the metropolis part self.mol.update(ind, x, y, theta, 1) step_to_go = step_to_go - 1 if step_to_go % hundredth == 0: if step_to_go != step_num: print "%d / %d done" % (100 - step_to_go / hundredth, 100) def step_multi(self, step_num, SHOW_MODE=0): step_to_go = step_num hundredth = step_num / 100 if step_num <= 0: print "step number should be positve integer" else: while step_to_go > 0: # pick a molecule and its new random position and angle ind, x, y, theta = self.get_new_conf() # get its old position and angle x_old, y_old, theta_old, typ_old = self.mol.conf[ind, :] # compute the energy of the old and new configuration, # respectively state_old, energy_old = inter_energy_multi( ind, x_old, y_old, theta_old, typ_old, self.mol, self.e_tables) state_new, energy_new = inter_energy_multi( -1, x, y, theta, typ_old, self.mol, self.e_tables) if state_new: p = min(math.exp(-(energy_new - energy_old)), 1) if p > rd.random(): # TODO: finish the metropolis part self.mol.update(ind, x, y, theta) step_to_go = step_to_go - 1 if step_to_go % hundredth == 0: if step_to_go != step_num: print "%d / %d done" % (100 - step_to_go / hundredth, 100) def load_inter_map(self, inter_map_path): # load intermolecular interaction energy map self.energy_table = EnergyTable(inter_map_path) def load_inter_maps(self): self.e_tables = EnergyTables() def load_surf_map(self, surf_map_path): # load surface interaction energy map pass def get_new_conf(self, INIT=False): ind_mol = rd.randint(0, self.element_num - 1) x = rd.randint(0, self.lattice_size - 1) y = rd.randint(0, self.lattice_size - 1) theta = 0 return ind_mol, x, y, theta def show(self): #x = [-1.5,-0.5,-0.5,0.5,0.5,1.5,1.5,0.5,0.5,-0.5,-0.5,-1.5,-1.5] #y = [0.5,0.5,1.5,1.5,0.5,0.5,-0.5,-0.5,-1.5,-1.5,-0.5,-0.5,0.5] #xy1 = list(zip(x,y)) marker_options = ['+', '.', 'o', '1'] for typ, num in enumerate(self.element_settings): print typ, num print self.mol.conf conf = self.mol.conf[self.mol.conf[:, -1] == typ + 1] print conf plt.scatter(conf[:, 0], conf[:, 1], s=500, c='r', marker=marker_options[typ], linewidth=4) plt.xticks(range(0, self.lattice_size)) plt.yticks(range(0, self.lattice_size)) plt.grid(True) plt.hold(True) plt.show() def write_conf(self, path_to_write): np.savetxt(path_to_write, self.mol.conf, fmt='%0.1d', delimiter=',')
def options(self): return Elements(self.locator + "/option", self.name + "." + "options")
class GRCObject(object): elem = Elements() """ program_elements = { "title":elem.object_title, "owner":elem.object_owner, "url":elem.object_url, "code":elem.object_code, "organization":elem.object_organization, "scope":elem.object_scope} program_values = { 'title':"", 'owner':"*****@*****.**", 'url': "http://www.google.com", 'code':"PCI", 'organization': "ORG", 'scope': ""} """ #CONTRACT contract_elements = { "title":elem.object_title, #"owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } contract_values = { 'title':"", #'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } #CONTROL control_elements = { "title":elem.object_title, #"owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } control_values = { 'title':"", #'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } #DATA ASSET data_asset_elements = { "title":elem.object_title, #"owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } data_asset_values = { 'title':"", #'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } #FACITY facility_elements = { "title":elem.object_title, # "owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } facility_values = { 'title':"", # 'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } #MARKET market_elements = { "title":elem.object_title, # "owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } market_values = { 'title':"", # 'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } #ORGGROUPS org_group_elements = { "title":elem.object_title, # "owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } org_group_values = { 'title':"", # 'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } #POLICY policy_elements = { "title":elem.object_title, # "owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code, "kind":elem.object_kind } policy_values = { 'title':"", # 'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code", "kind":1 } #PROCESS process_elements = { "title":elem.object_title, # "owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } process_values = { 'title':"", # 'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } #POLICY product_elements = { "title":elem.object_title, # "owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code, "kind":elem.object_kind } product_values = { 'title':"", # 'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code", "kind":2 } #PROGRAM program_elements = { "title":elem.object_title, # "owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } program_values = { 'title':"", # 'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } #PROJECT project_elements = { "title":elem.object_title, # "owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } project_values = { 'title':"", # 'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } #REGULATION regulation_elements = { "title":elem.object_title, # "owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } regulation_values = { 'title':"", # 'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } #System system_elements = { "title":elem.object_title, # "owner":elem.object_owner, "description":elem.object_description, "url":elem.object_url, "code":elem.object_code } system_values = { 'title':"", # 'owner':"", "description":"", 'url': "http://www.google.com", "code":"auto-populated-code" } """