Skip to content

Commit

Permalink
Add batch and uep plot tests #48
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Apr 17, 2023
1 parent 632b05b commit c3f3081
Show file tree
Hide file tree
Showing 19 changed files with 47,926 additions and 139 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
coverage
*.cover
.hypothesis/
.pytest_cache/
Expand Down
6 changes: 2 additions & 4 deletions pymuonsuite/muairss.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,12 @@ def muairss_batch_io(args, global_params, save=False):

for path in structure_files:
name = parse_structure_name(path)
parameter_file = os.path.join(structures_path, "{}.yaml".format(name))
if not os.path.isfile(parameter_file):
parameter_file = None
with silence_stdio():
struct = io.read(path)
params = dict(global_params) # Copy
params["name"] = name
if parameter_file is not None:
parameter_file = os.path.join(structures_path, "{}.yaml".format(name))
if os.path.isfile(parameter_file):
params = load_input_file(parameter_file, MuAirssSchema, merge=params)
params["out_folder"] = params["name"]

Expand Down
11 changes: 6 additions & 5 deletions pymuonsuite/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,22 @@ def validate_save_min(value):
return isinstance(value, bool)


def load_input_file(fname, param_schema, merge=None):
def load_input_file(fname, param_schema: Schema, merge: dict = None):
"""Load a given input YAML file and validate it with a schema."""

if merge is None:
with open(fname, "r") as params_file:
params = yaml.safe_load(params_file)
else:
try:
param_schema.validate(merge)
existing_params = {k: v for k, v in merge.items() if v is not None}
param_schema.validate(existing_params)
except SchemaError as e:
message = "Invalid merge params passed to" " load_input_file\n{0}".format(e)
raise RuntimeError(message)
message = "Invalid merge params passed to load_input_file"
raise RuntimeError(message) from e
with open(fname, "r") as params_file:
new_params = yaml.safe_load(params_file)
params = dict(merge)
params = dict(existing_params)
params.update(new_params)

if params is None:
Expand Down
16 changes: 16 additions & 0 deletions pymuonsuite/test/test_data/Si2/Si2-muairss-all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
poisson_r: 1.0
name: Si2
charged: true
geom_steps: 300
vdw_scale: 0.25
calculator: all
uep_gw_factor: 4.0
uep_chden: Si2.den_fmt
geom_force_tol: 0.05
clustering_method: kmeans
clustering_kmeans_k: 2
dftb_set: pbc-0-3
out_folder: muon-airss-out-all
castep_param: Si2.param
script_file: submit.sh
uep_save_structs: False
16 changes: 16 additions & 0 deletions pymuonsuite/test/test_data/Si2/batch/Si2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
poisson_r: 1.0
name: Si2
charged: true
geom_steps: 300
vdw_scale: 0.25
calculator: all
uep_gw_factor: 4.0
uep_chden: Si2.den_fmt
geom_force_tol: 0.05
clustering_method: kmeans
clustering_kmeans_k: 2
dftb_set: pbc-0-3
out_folder: muon-airss-out-all
castep_param: Si2.param
script_file: submit.sh
uep_save_structs: true
3 changes: 1 addition & 2 deletions pymuonsuite/test/test_data/Si2/script-dftb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
target="muon-airss-out-dftb/dftb+/"
for folder in "$target"*
for folder in "$1"/*
do
cd $folder
dftb+
Expand Down
3 changes: 1 addition & 2 deletions pymuonsuite/test/test_data/Si2/script-uep
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
target=$1
for folder in "$target"*
for folder in "$1"/*
do
pm-uep-opt $folder/$(basename $folder).yaml
done
2 changes: 1 addition & 1 deletion pymuonsuite/test/test_data/Si2/script-uep-windows.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$Target="muon-airss-out-uep/uep"
$Target=$args[0]

$SubFolders = Get-ChildItem -Path $Target -Directory

Expand Down
2 changes: 2 additions & 0 deletions pymuonsuite/test/test_data/Si8/Si8-invalid-line.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
chden_seed: Si8
line_plots: [[0, 1, 5, 0]]
2 changes: 2 additions & 0 deletions pymuonsuite/test/test_data/Si8/Si8-invalid-plane.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
chden_seed: Si8
plane_plots: [[0, 1, 2, 5, 5, 0]]
Loading

0 comments on commit c3f3081

Please sign in to comment.