Skip to content

Commit

Permalink
improved ORB; compatible with atomistic_tools v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Aug 12, 2019
1 parent 1bd53e7 commit e62587b
Show file tree
Hide file tree
Showing 12 changed files with 1,504 additions and 174 deletions.
59 changes: 45 additions & 14 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,22 @@

workchain_preproc_and_viewer_info = {
'STMWorkChain': OrderedDict([
('stm', { # If no preprocess matches, error wrt first version is given
('stm2', { # If no preprocess matches, error wrt first version is given
'n_calls': 2,
'viewer_path': "scanning_probe/stm/view_stm.ipynb",
'retrieved_files': [(1, ["stm.npz"])], # [(step_index, list_of_retr_files), ...]
'struct_label': 'structure',
'req_param': ('stm_params', '--fwhms'), # required parameterdata input and a key in it
}),
('stm1', {
'n_calls': 2,
'viewer_path': "scanning_probe/stm/view_stm-v1.ipynb",
'retrieved_files': [(1, ["stm.npz"])],
'struct_label': 'structure',
}),
('stm0', {
'n_calls': 3,
'viewer_path': "scanning_probe/stm/view_stm-old.ipynb",
'viewer_path': "scanning_probe/stm/view_stm-v0.ipynb",
'retrieved_files': [(2, ["stm_ch.npz"])],
'struct_label': 'structure',
})
Expand All @@ -65,16 +72,23 @@
}),
]),
'OrbitalWorkChain': OrderedDict([
('orb', {
('orb1', {
'n_calls': 2,
'viewer_path': "scanning_probe/orb/view_orb.ipynb",
'retrieved_files': [(1, ["orb.npz"])],
'struct_label': 'structure',
'req_param': ('stm_params', '--orb_fwhms'),
}),
('orb0', {
'n_calls': 2,
'viewer_path': "scanning_probe/orb/view_orb-v0.ipynb",
'retrieved_files': [(1, ["orb.npz"])],
'struct_label': 'structure',
}),
]),
}

PREPROCESS_VERSION = 0.95
PREPROCESS_VERSION = 1.01

def preprocess_one(workcalc):
"""
Expand All @@ -87,18 +101,21 @@ def preprocess_one(workcalc):

prefix = None
reason = None

for prefix_version in version_preproc_dict:
n_calls = version_preproc_dict[prefix_version]['n_calls']
retr_list_per_step = version_preproc_dict[prefix_version]['retrieved_files']

success = True

# ---
# check if number of calls matches
if len(workcalc.get_outputs()) < n_calls:
if reason is None:
reason = "Not all calculations started."
success = False
break
continue

# ---
# check if all specified files are retrieved
success = True
for rlps in retr_list_per_step:
calc_step, retr_list = rlps
calc = workcalc.get_outputs()[calc_step]
Expand All @@ -108,17 +125,31 @@ def preprocess_one(workcalc):
reason = "Not all files were retrieved."
success = False
break
if success:
prefix = prefix_version
break
if not success:
continue

# ---
# check if the required parameter is there
if 'req_param' in version_preproc_dict[prefix_version]:
req_param, req_key = version_preproc_dict[prefix_version]['req_param']
inp_dict = workcalc.get_inputs_dict()
if not (req_param in inp_dict and req_key in inp_dict[req_param].dict):
if reason is None:
reason = "Required parameter not existing."
continue

# ---
# found match!
prefix = prefix_version
break

if prefix is None:
raise(Exception(reason))

structure = workcalc.get_inputs_dict()[version_preproc_dict[prefix]['struct_label']]
pk_numbers = [e for e in structure.get_extras() if e.startswith(prefix)]
pk_numbers = [e for e in structure.get_extras() if e.startswith(prefix[:-1])]
pk_numbers = [int(e.split('_')[1]) for e in pk_numbers if e.split('_')[1].isdigit()]
pks = [e[1] for e in structure.get_extras().items() if e[0].startswith(prefix)]
pks = [e[1] for e in structure.get_extras().items() if e[0].startswith(prefix[:-1])]
if workcalc.pk in pks:
return
nr = 1
Expand All @@ -139,7 +170,7 @@ def preprocess_spm_calcs(workchain_list = ['STMWorkChain', 'PdosWorkChain', 'Afm
{'extras.preprocess_version': {'<': PREPROCESS_VERSION}},
],
})
qb.order_by({WorkCalculation:{'ctime':'desc'}})
qb.order_by({WorkCalculation:{'ctime':'asc'}})

for m in qb.all():
n = m[0]
Expand Down
19 changes: 19 additions & 0 deletions manage_calcs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"from aiida.orm.calculation.work import WorkCalculation\n",
"from aiida.orm.calculation.job import JobCalculation\n",
"from aiida.orm import load_node\n",
"from aiida.orm.data.structure import StructureData\n",
"\n",
"\n",
"import ipywidgets as ipw\n",
Expand All @@ -38,6 +39,24 @@
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Delete all SPM extras:\n",
"\n",
"#qb = QueryBuilder()\n",
"#qb.append(StructureData)\n",
"#\n",
"#for struct_data in qb.all():\n",
"# extras = struct_data[0].get_extras()\n",
"# for key in extras.keys():\n",
"# if key.endswith('_pk') and key.split('_')[1].isdigit():\n",
"# struct_data[0].del_extra(key)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
12 changes: 8 additions & 4 deletions orb/misc/run_cube_from_wfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@

mkdir $DIR/cubes

$SCRIPT_PATH cube_from_wfn.py \
"$SCRIPT_PATH"cube_from_wfn.py \
--cp2k_input_file $DIR/aiida.inp \
--basis_set_file $DIR/BASIS_MOLOPT \
--xyz_file $DIR/geom.xyz \
--wfn_file $DIR/aiida-RESTART.wfn \
--output_dir $DIR/cubes/ \
--n_homo 5 \
--n_lumo 5 \
--n_homo 3 \
--n_lumo 3 \
--dx 0.2 \
# --gen_rho \
--eval_cutoff 14.0 \
# --orb_square \
# --charge_dens \
# --spin_dens \

2 changes: 1 addition & 1 deletion orb/orb_workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def define(cls, spec):
def run_scf_diag(self):
self.report("Running CP2K diagonalization SCF")

n_lumo = int(self.inputs.stm_params.get_dict()['--n_lumo_ch'])
n_lumo = int(self.inputs.stm_params.get_dict()['--n_lumo'])

inputs = self.build_cp2k_inputs(self.inputs.structure,
self.inputs.cp2k_code,
Expand Down
20 changes: 14 additions & 6 deletions orb/submit_orb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,24 @@
" value='3.0 5.0',\n",
" style=style, layout=layout)\n",
"\n",
"isovals_text = ipw.Text(description='Isovalues',\n",
" value='1e-7',\n",
" style=style, layout=layout)\n",
"\n",
"fwhms_text = ipw.Text(description='FWHMs (eV)',\n",
" value='0.02 0.10',\n",
" style=style, layout=layout)\n",
"\n",
"extrap_plane_floattext = ipw.BoundedFloatText(\n",
" description='Extrap plane (ang)',\n",
" min=1.0,\n",
" max=10.0,\n",
" step=0.1,\n",
" value=3.0,\n",
" value=3.5,\n",
" style=style, layout=layout_small)\n",
"\n",
"\n",
"display(n_homo_inttext, n_lumo_inttext, heights_text, extrap_plane_floattext)"
"display(n_homo_inttext, n_lumo_inttext, heights_text, isovals_text, fwhms_text, extrap_plane_floattext)"
]
},
{
Expand Down Expand Up @@ -342,15 +350,15 @@
" '--wfn_file': parent_dir+'aiida-RESTART.wfn',\n",
" '--hartree_file': parent_dir+'aiida-HART-v_hartree-1_0.cube',\n",
" '--orb_output_file': 'orb.npz',\n",
" '--emin': '-2.0',\n",
" '--emax': '2.0',\n",
" '--eval_region': ['G', 'G', 'G', 'G', 'n-1.0_C', 'p%.1f'%extrap_plane],\n",
" '--dx': '0.15',\n",
" '--eval_cutoff': '14.0',\n",
" '--extrap_extent': '5.0',\n",
" '--n_homo': str(n_homo_inttext.value),\n",
" '--n_lumo': str(n_lumo_inttext.value),\n",
" '--orb_heights': heights_text.value.split(),\n",
" '--n_homo_ch': str(n_homo_inttext.value),\n",
" '--n_lumo_ch': str(n_lumo_inttext.value),\n",
" '--orb_isovalues': isovals_text.value.split(),\n",
" '--orb_fwhms': fwhms_text.value.split(),\n",
" })\n",
" \n",
" cp2k_code = cp2k_codes[drop_cp2k.index]\n",
Expand Down
Loading

0 comments on commit e62587b

Please sign in to comment.