Commit 378d392b authored by Niccolo.Ricardi's avatar Niccolo.Ricardi
Browse files

minor changes to get_nbas

parent 109b23d8
...@@ -276,30 +276,27 @@ def get_nbas(filepath, with_ccp=False, json_file="", log_file="", index=[2,3,4]) ...@@ -276,30 +276,27 @@ def get_nbas(filepath, with_ccp=False, json_file="", log_file="", index=[2,3,4])
json_file=os.path.join(dir_, json_file) json_file=os.path.join(dir_, json_file)
else: else:
json_files = gl.glob(os.path.join(dir_,"*.json")) json_files = gl.glob(os.path.join(dir_,"*.json"))
if len(json_files) == 1: kwargs = dict(to_console=False, to_file=True, to_json=True)
json_file=json_files[0] if json_file:
else: kwargs.update(dict(json_file=json_file))
kwargs = dict(to_console=False, to_file=True, to_json=True) if log_file:
if json_file: kwargs.update(dict(log_file=log_file))
kwargs.update(dict(json_file=json_file)) out = ccp.Parser(filepath, **kwargs)
if log_file: try:
kwargs.update(dict(log_file=log_file)) json_file = [i for i in gl.glob(os.path.join(dir_,"*.json")) if i not in json_files][0]
out = ccp.Parser(filepath, **kwargs) assert json_file == default_ccpjson
try: except IndexError:
json_file = [i for i in gl.glob(os.path.join(dir_,"*.json")) if i not in json_files][0] ccjlog.critical("The json file was already there. Will use default name: {}".format(default_ccpjson))
assert json_file == default_ccpjson except AssertionError:
except IndexError: ccjlog.critical("CCParser's default seems to be \"{}\" change default_ccpjson in this function!!".format(json_file))
ccjlog.critical("The json file was already there. Will use default name: {}".format(default_ccpjson)) default_ccpjson = json_file
except AssertionError:
ccjlog.critical("CCParser's default seems to be \"{}\" change default_ccpjson in this function!!".format(json_file))
default_ccpjson = json_file
parsed = ut.load_js(json_file) parsed = ut.load_js(json_file)
nbas["nbasAB"] = parsed["nbas"][index[0]][0] nbas["nbasAB"] = parsed["nbas"][index[0]][0]
nbas["nbasA"] = parsed["nbas"][index[1]][0] nbas["nbasA"] = parsed["nbas"][index[1]][0]
nbas["nbasB"] = parsed["nbas"][index[2]][0] nbas["nbasB"] = parsed["nbas"][index[2]][0]
else: else:
with open(file) as f: with open(filepath) as f:
r = f.read() r = f.read()
pattern = r"There are (?P<shells>\d+) shells and (?P<bsf>\d+) basis functions" pattern = r"There are (?P<shells>\d+) shells and (?P<bsf>\d+) basis functions"
parsed = re.findall(pattern, r) parsed = re.findall(pattern, r)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment