def some_opts_extr(self): try: names = np.sort(listdir(self.frm.folder_name)) except TypeError: self.frm.status.set('it seems you should show me the folder, Doc') return False for name in names: if fnmatch(name, '*.in'): inputname = self.frm.folder_name + '/' + name No_ion = int( Namelist(inputname).get('ions').get('par')[0].get('no_ion')[0]) self.frm.n_nod = int( Namelist(inputname).get('option').get('par')[0].get('nd_para') [0]) - 1 return No_ion
def _convertNamelists(self, namelists): for name in namelists.keys(): nl = Namelist(name) for p in namelists[name]: nl.add(p[0], p[1]) self.namelists[name] = nl
def setNamelist(self, namelist): """ Sets namelist as dictionaty: namelist: (dict) -- Dictionary of namelist Format: {"name": <namelist name>, "params": {param1: value1, param2: value2, ...}} Example: {"name": "control", "params": {calculation: 'scf', restart_mode: 'from_scratch', tprnfor: .true.}} """ if not namelist: # Ignore empty card return self._checkDictFormat(namelist, NAMELIST_KEYS, NAMELIST_REQ) nl = Namelist(namelist["name"]) if namelist.has_key("params"): for p in namelist["params"].keys(): value = namelist["params"][p] nl.set(p, value) self._fnamelists.append(nl)
def _convertNamelists(self, namelists): """Converts dictionary to Namelist""" for name in namelists.keys(): nl = Namelist(name) for p in namelists[name]: nl.add(p[0], p[1]) self.namelists[name] = nl
def test_namelist_remove_exists(self): nl = Namelist("control") nl.set("title", "hello") self.assertTrue(nl.exists("title")) self.assertTrue(nl.exists("Title")) nl.remove("title") self.assertFalse(nl.exists("title"))
def test_qeinput_namelist(self): input = QEInput() nl = Namelist("control") nl.set("title", "'Ni'") input.addNamelist(nl) nl2 = input.namelist("phonon") self.assertEqual(input.toString(), fixtures.assertNewNamelist) input.removeNamelist("control") self.assertEqual(input.toString(), fixtures.assertNewNamelist2)
def test_namelist_set_get(self): nl = Namelist("control") self.assertEqual(nl.get("title"), None) nl.set("title", "hello") self.assertEqual(nl.get("title"), "hello") self.assertEqual(nl.get("title", quotes=True), "hello") # should not add quotes nl.set("Title", "'hello'") self.assertEqual(nl.get("titlE", quotes=False), "hello") self.assertEqual(nl.get("title"), "'hello'")
def _createNamelist(self, name): """ Creates namelist specified by name name: (str) -- Name of the namelist """ if not name in self.namelistRef: # If not standard card, ignore it return None # Otherwise create a new namelist nl = Namelist(name) self.namelists[name] = nl return nl
def testCreateConfig(): print "Testing creation of config file" qe = QEInput() nl = Namelist('control') nl.add('title', "'Ni'") nl.add('restart_mode', "'from_scratch'") print "Adding parameters to namelist:\n%s" % nl.toString() nl.set('title', "'Fe'") qe.addNamelist(nl) print "Adding namelist to QEInput:\n%s" % qe.toString() c = Card('atomic_species') c.addLine('Ni 26.98 Ni.pbe-nd-rrkjus.UPF') print "Adding line to card:\n%s" % c.toString() qe.addCard(c) print "Adding card to QEInput:\n%s" % qe.toString()
def setParam(self, namelist, param, value=""): """ Set parameter of the namelist. If the parameter or namelist do not exist, it creates them. namelist: (str) -- Name of the namelist param: (str) -- Name of the parameter value: (str) -- Valur of the parameter """ for nl in self._fnamelists: if nl.name() == namelist: nl.set(param, value) return # namelist doesn't exists nl = Namelist(namelist) nl.set(param, value) self._fnamelists.append(nl)
def get_pv(forcing, output, n1=0, n2=10000, option="timeseries"): """ forcing : nc file assumed to be located in Forcings/ e.g. "SIRTA_all" output : name of output file containing PV production, stored in PV_Outputs directory n1 and n2 : left and right indicess for partial computations along timeseries option : specify the type of forcing to optimize vectorial computations """ print("----------Namelist loading----------------") nam = Namelist( ) # all options should be hardcoded in the Namelist() attributes print("----------Atmosphere loading----------------") # build an Atmosphere object from an nc file. Such object can be built directly from np.arrays atm = Atmosphere(*tools.get_atm_from_ncfile( forcing=forcing, albedo=nam.albedo, n1=n1, n2=n2)) atm.compute_sun() # to compute the full series of sza, saa, sw_toa # define PV panel from information contained in Namelist print("----------Module initialization----------------") panel = Panel( name=nam.panel_name, technology=nam.panel_technology, beta=nam.panel_beta, gamma=nam.panel_gamma, method_FF=nam.method_FF, SR_method=nam.SR_method, namelist=nam ) # get physical characteristics of the panel from a description file - here SIRTA panel used for consistency # call pv_interface to handle large arrays and successive (and possibly multi-thread) calls to pv_production t1 = time.time() if option == "timeseries": power_simul = pv_interface_timeseries(nam, atm, panel) elif option == "atlas": power_simul = pv_interface_atlas(nam, atm, panel) # save PV outputs np.savetxt("PV_Outputs/%s.dat" % output, power_simul) t2 = time.time() print("Time to run the PV code = %s seconds" % (t2 - t1)) return atm.dates, power_simul, atm.lat, atm.lon
def createNamelist(self, name): """Creates namelist and adds to QEInput. """ nl = Namelist(name) self.namelists[name] = nl
#!/usr/bin/env python3 from namelist import Namelist control = Namelist(name="CONTROL") control.set_val("calculation", 'scf') control.set_val("prefix", "scf.pbe.ecut-80") control.set_val("outdir", "./scratch/") control.set_val("pseudo_dir", "/home/altoidnerd/.data/PSEUDOPOTENTIALS/") control.set_val("verbosity", "high") control.set_val("title", "p-dichlorobenzene-efg") control.set_val("restart_mode", "from_scratch") control.set_val("forc_conv_thr", 1.0e-4) control.set_val("disk_io", "low") control.set_val("wfcollect", ".false.") for key in ["tstress", "tprnfor", "lorbm", "lberry", "ikpoint_dir"]: control.set_val(key, ".true.") system = Namelist("SYSTEM") key_value_pairs = [("ibrav", 0), ('a', 9.558), ('c', "8.981"), ("ecutwfc", 60), ("ecutrho", 600), ("occupations", 'smearing'), ('smearing', 'fermi-dirac'), ('degauss', .00367), ('nat', 70), ('ntyp', '6')] for (key, value) in key_value_pairs: system.set_val(key, value) electrons_dict = { "conv_thr": 1e-7, "diago_thr_init": 1e-4,
def p_subroutine_statement_namelist(p): 'subroutine_statement : NAMELIST SLASH ID SLASH namelist_variables' p[0] = Namelist(p[3], p[5])
def test_namelist_tostring(self): nl = Namelist("control") nl.set("title", "hello") self.assertEqual(nl.toString(), fixtures.assertNL) self.assertEqual(nl.toString(indent=3), fixtures.assertNL_space_3)
def test_namelist_name(self): nl = Namelist("Control") self.assertEqual(nl.name(), "control") nl.setName("SyStem") self.assertEqual(nl.name(), "system")