Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 6, 2024
1 parent a2ebf5f commit 41d0639
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 98 deletions.
81 changes: 41 additions & 40 deletions aiida_fleur/cmdline/launch/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def launch_fleur(fleurinp, fleur, parent_folder, settings, daemon, max_num_machi


@click.command('scf')
@options.STRUCTURE_OR_FILE(default="inp.xml", show_default=True)
@options.STRUCTURE_OR_FILE(default='inp.xml', show_default=True)
@options.INPGEN()
@options.CALC_PARAMETERS()
@options.SETTINGS()
Expand All @@ -171,13 +171,13 @@ def launch_scf(structure, inpgen, calc_parameters, fleurinp, fleur, wf_parameter
"""
Launch a scf workchain
"""
fleurinp=None
fleurinp = None

if isinstance(structure, FleurinpData):
fleurinp=structure
structure=None
inpgen=None
fleurinp = structure
structure = None
inpgen = None

workchain_class = WorkflowFactory('fleur.scf')
inputs = {
'inpgen': inpgen,
Expand All @@ -194,26 +194,27 @@ def launch_scf(structure, inpgen, calc_parameters, fleurinp, fleur, wf_parameter
inputs = clean_nones(inputs)
builder = workchain_class.get_builder()
builder.update(inputs)
pk=utils.launch_process(builder, daemon)
pk = utils.launch_process(builder, daemon)

#Now create output files
if fleurinp and not daemon:
from aiida.orm import load_node
wf=load_node(pk)
scf_output=wf.outputs.output_scf_wc_para.get_dict()
wf = load_node(pk)
scf_output = wf.outputs.output_scf_wc_para.get_dict()
#json with dict
import json
with open("scf.json","w") as file:
json.dump(scf_output,file,indent=2)
with open('scf.json', 'w') as file:
json.dump(scf_output, file, indent=2)
#plot
from aiida_fleur.tools.plot.fleur import plot_fleur
plot_fleur(wf,save=True,show=False)
plot_fleur(wf, save=True, show=False)

#store files
for file in ["out.xml","cdn1","cdn_last.hdf"]:
for file in ['out.xml', 'cdn1', 'cdn_last.hdf']:
if file in wf.outputs.last_calc.retrieved.list_object_names():
with open(file,"wb") as f:
f.write(wf.outputs.last_calc.retrieved.get_object_content(file,"rb"))
with open(file, 'wb') as f:
f.write(wf.outputs.last_calc.retrieved.get_object_content(file, 'rb'))


@click.command('relax')
@options.STRUCTURE_OR_FILE(default=defaults.get_si_bulk_structure, show_default=True)
Expand Down Expand Up @@ -251,7 +252,7 @@ def launch_relax(structure, inpgen, calc_parameters, fleur, wf_parameters, scf_p


@click.command('eos')
@options.STRUCTURE_OR_FILE(default="inp.xml", show_default=True)
@options.STRUCTURE_OR_FILE(default='inp.xml', show_default=True)
@options.INPGEN()
@options.CALC_PARAMETERS()
@options.FLEUR()
Expand All @@ -266,13 +267,13 @@ def launch_eos(structure, inpgen, calc_parameters, fleur, wf_parameters, scf_par
"""

workchain_class = WorkflowFactory('fleur.eos')
fleurinp=None

fleurinp = None

if isinstance(structure, FleurinpData):
fleurinp=structure
structure=None
fleurinp = structure
structure = None

inputs = {
'scf': {
'wf_parameters': scf_parameters,
Expand All @@ -288,34 +289,34 @@ def launch_eos(structure, inpgen, calc_parameters, fleur, wf_parameters, scf_par
inputs = clean_nones(inputs)
builder = workchain_class.get_builder()
builder.update(inputs)
pk=utils.launch_process(builder, daemon)
pk = utils.launch_process(builder, daemon)

#Now create output files
if fleurinp and not daemon:
from aiida.orm import load_node
wf=load_node(pk)
eos_output=wf.outputs.output_eos_wc_para.get_dict()
wf = load_node(pk)
eos_output = wf.outputs.output_eos_wc_para.get_dict()
#json with dict
import json
with open("eos.json","w") as file:
json.dump(eos_output,file,indent=2)
with open('eos.json', 'w') as file:
json.dump(eos_output, file, indent=2)
#cif file
if "output_eos_wc_structure" in wf.outputs:
if 'output_eos_wc_structure' in wf.outputs:
import os.path
if os.path.isfile("opt_struct.cif"): os.remove("opt_struct.cif")
cif_struct=wf.outputs.output_eos_wc_structure.get_cif()
cif_struct.export("opt_struct.cif")
if os.path.isfile('opt_struct.cif'):
os.remove('opt_struct.cif')
cif_struct = wf.outputs.output_eos_wc_structure.get_cif()
cif_struct.export('opt_struct.cif')
#plot
if eos_output["volume_gs"] >0 :
if eos_output['volume_gs'] > 0:
from aiida_fleur.tools.plot.fleur import plot_fleur
plot_fleur(wf,save=True,show=False)

for i,uuid in enumerate(eos_output["calculations"]):
scf=load_node(uuid)
scale=eos_output["scaling"][i]
with open(f"out_{scale}.xml","w") as f:
f.write(scf.outputs.last_calc.retrieved.get_object_content("out.xml"))
plot_fleur(wf, save=True, show=False)

for i, uuid in enumerate(eos_output['calculations']):
scf = load_node(uuid)
scale = eos_output['scaling'][i]
with open(f"out_{scale}.xml", 'w') as f:
f.write(scf.outputs.last_calc.retrieved.get_object_content('out.xml'))


@click.command('banddos')
Expand Down
6 changes: 3 additions & 3 deletions aiida_fleur/cmdline/util/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def convert(self, value, param, ctx):
# aiida allows also for shorten uuids
from aiida.orm import StructureData, QueryBuilder

if value in ["inp.xml",".",'./']:
if value in ['inp.xml', '.', './']:
from aiida_fleur.data.fleurinp import FleurinpData
inp_files=["inp.xml"]
inp_files = ['inp.xml']
#check if there are included files in this dir
for file in ["kpts.xml","sym.xml","relax.xml"]:
for file in ['kpts.xml', 'sym.xml', 'relax.xml']:
import os.path
if os.path.isfile(file):
inp_files.append(file)
Expand Down
2 changes: 1 addition & 1 deletion aiida_fleur/cmdline/util/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ def launch_process(process, daemon, **inputs):
_, node = launch.run_get_node(process, **inputs)
echo_process_results(node)

return node.pk
return node.pk
10 changes: 6 additions & 4 deletions aiida_fleur/cmdline/workflows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def cmd_workflow():


@cmd_workflow.command('res')
@arguments.PROCESS('process', type=ProcessParamType()
) #, type=WorkflowParamType(sub_classes=('aiida.node:process.workflow.workchain',)))
@arguments.PROCESS(
'process',
type=ProcessParamType()) #, type=WorkflowParamType(sub_classes=('aiida.node:process.workflow.workchain',)))
@click.option('--info/--no-info', default=False, help='Print an info header above each node.')
@click.option('-l', '--label', 'label', type=str, help='Print only output dicts with a certain link_label.')
@options_fl.SHOW()
Expand Down Expand Up @@ -69,8 +70,9 @@ def workchain_res(process, info, label, show, keys, fmt):


@cmd_workflow.command('inputdict')
@arguments.PROCESS('process', type=ProcessParamType()
) #, type=WorkflowParamType(sub_classes=('aiida.node:process.workflow.workchain',)))
@arguments.PROCESS(
'process',
type=ProcessParamType()) #, type=WorkflowParamType(sub_classes=('aiida.node:process.workflow.workchain',)))
@click.option('--info/--no-info', default=False, help='Print an info header above each node.')
@click.option('-l', '--label', 'label', type=str, help='Print only output dicts with a certain link_label.')
@options_fl.SHOW()
Expand Down
13 changes: 6 additions & 7 deletions aiida_fleur/parsers/fleur.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,23 @@ def parse(self, **kwargs):

# Open log-file as well
try:
run_was_successful="finished successfully" in error_file_lines
run_was_successful = 'finished successfully' in error_file_lines
except:
run_was_successful=False
run_was_successful = False
if FleurCalculation._LOG_FILE_NAME in list_of_files:
logfile = FleurCalculation._LOG_FILE_NAME
# read
import json
try:
with output_folder.open(logfile, 'r') as efile:
log_file_entries = json.load(efile)
run_was_successful="Success" in log_file_entries[-1]
run_was_successful = 'Success' in log_file_entries[-1]
except OSError:
self.logger.error(f'Failed to open log file: {logfile}.')
return self.exit_codes.ERROR_OPENING_OUTPUTS
except json.JSONDecodeError:
self.logger.error("logfile not correctly formatted")
self.logger.error('logfile not correctly formatted')

#Now check for different kind of errors
if not run_was_successful:
self.logger.warning('The following was written into std error and piped to {}'
Expand All @@ -159,8 +159,7 @@ def parse(self, **kwargs):

kb_used = 0.0
if has_xml_outfile:
with output_folder.open(FleurCalculation._OUTXML_FILE_NAME,
'r') as out_file: # lazy out.xml parsing
with output_folder.open(FleurCalculation._OUTXML_FILE_NAME, 'r') as out_file: # lazy out.xml parsing
outlines = out_file.read()
try:
line_avail = re.findall(r'<mem memoryPerNode="\d+', outlines)[0]
Expand Down
2 changes: 1 addition & 1 deletion aiida_fleur/tools/StructureData_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ def request_average_bond_length(first_bin, second_bin, user_api_key, ignore_seco
from collections import defaultdict
from copy import deepcopy

bond_data = defaultdict(lambda: defaultdict(lambda: 0.0))
bond_data = defaultdict(lambda: defaultdict(float))
if ignore_second_bin:
symbols = first_bin
second_bin_calculate = first_bin
Expand Down
Loading

0 comments on commit 41d0639

Please sign in to comment.