diff --git a/python/converters/vasp/python/inpconf.py b/python/converters/vasp/python/inpconf.py index c783261b..7713d18b 100644 --- a/python/converters/vasp/python/inpconf.py +++ b/python/converters/vasp/python/inpconf.py @@ -65,9 +65,8 @@ class ConfigParameters: 'emax': ('emax', float)} self.gr_optional = { - 'normalize' : ('normalize', self.parse_string_logical), - 'normion' : ('normion', self.parse_string_logical)} - + 'normalize' : ('normalize', self.parse_string_logical, True), + 'normion' : ('normion', self.parse_string_logical, False)} # @@ -168,13 +167,14 @@ class ConfigParameters: # parse_parameter_set() # ################################################################################ - def parse_parameter_set(self, section, param_set, exception=False): + def parse_parameter_set(self, section, param_set, exception=False, defaults=True): """ Parses required or optional parameter set from a section. For required parameters `exception=True` must be set. """ parsed = {} for par in param_set.keys(): + key = param_set[par][0] try: par_str = self.cp.get(section, par) except ConfigParser.NoOptionError: @@ -182,12 +182,14 @@ class ConfigParameters: message = "Required parameter '%s' not found in section [%s]"%(par, section) raise Exception(message) else: +# Use the default value if there is one + if defaults and len(param_set[par]) > 2: + parsed[key] = param_set[par][2] continue if self.verbosity > 0: print " %s = %s"%(par, par_str) - key = param_set[par][0] parse_fun = param_set[par][1] parsed[key] = parse_fun(par_str) @@ -267,7 +269,7 @@ class ConfigParameters: shell.update(parsed) # Group optional parameters - parsed = self.parse_parameter_set(section, self.gr_optional, exception=False) + parsed = self.parse_parameter_set(section, self.gr_optional, exception=False, defaults=False) shell.update(parsed) self.shells.append(shell) diff --git a/python/converters/vasp/test/inpconf/test_groups.py b/python/converters/vasp/test/inpconf/test_groups.py index 6c36e420..ed3f209d 100644 --- a/python/converters/vasp/test/inpconf/test_groups.py +++ b/python/converters/vasp/test/inpconf/test_groups.py @@ -34,8 +34,10 @@ class TestParseGroups(arraytest.ArrayTestCase): conf_pars = ConfigParameters('example.cfg') conf_pars.parse_groups() res = conf_pars.groups - expected = [{'index': 1, 'shells': [1, 2], 'emin': -7.6, 'emax': 3.0}, - {'index': 2, 'shells': [3], 'emin': -1.6, 'emax': 2.0}] + expected = [{'index': 1, 'shells': [1, 2], 'emin': -7.6, 'emax': 3.0, + 'normalize': True, 'normion': False}, + {'index': 2, 'shells': [3], 'emin': -1.6, 'emax': 2.0, + 'normalize': True, 'normion': False}] self.assertListEqual(res, expected) diff --git a/python/converters/vasp/test/inpconf/test_input.py b/python/converters/vasp/test/inpconf/test_input.py index f1311aa1..46b5507f 100644 --- a/python/converters/vasp/test/inpconf/test_input.py +++ b/python/converters/vasp/test/inpconf/test_input.py @@ -77,7 +77,7 @@ class TestParseInput(arraytest.ArrayTestCase): [ 0., 0., 1.]]), 'ion_list': array([0, 1, 2, 3]), 'user_index': 2, 'lshell': 1}, {'ion_list': array([0, 1, 2, 3]), 'user_index': 3, 'lshell': 3}] Groups: -[{'index': 1, 'shells': [0, 1], 'emin': -7.6, 'emax': 3.0}, {'index': 2, 'shells': [2], 'emin': -1.6, 'emax': 2.0}]""" +[{'normalize': True, 'index': 1, 'shells': [0, 1], 'normion': False, 'emax': 3.0, 'emin': -7.6}, {'normalize': True, 'index': 2, 'shells': [2], 'normion': False, 'emax': 2.0, 'emin': -1.6}]""" self.assertEqual(res, expected)